Skip to content

Commit ec9a1bd

Browse files
committed
Auto merge of #88914 - GuillaumeGomez:rollup-h5svc6w, r=GuillaumeGomez
Rollup of 7 pull requests Successful merges: - #88033 (Add links for primitives in "jump to definition" feature) - #88722 (Make `UnsafeCell::get_mut` const) - #88851 (Fix duplicate bounds for const_trait_impl) - #88859 (interpreter PointerArithmetic: use new Size helper methods) - #88885 (Fix jump def background) - #88894 (Improve error message for missing trait in trait impl) - #88896 (Reduce possibility of flaky tests) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9f85cd6 + fb673bf commit ec9a1bd

File tree

19 files changed

+165
-25
lines changed

19 files changed

+165
-25
lines changed

compiler/rustc_middle/src/mir/interpret/pointer.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::{AllocId, InterpResult};
33
use rustc_macros::HashStable;
44
use rustc_target::abi::{HasDataLayout, Size};
55

6-
use std::convert::TryFrom;
6+
use std::convert::{TryFrom, TryInto};
77
use std::fmt;
88

99
////////////////////////////////////////////////////////////////////////////////
@@ -20,29 +20,27 @@ pub trait PointerArithmetic: HasDataLayout {
2020

2121
#[inline]
2222
fn machine_usize_max(&self) -> u64 {
23-
let max_usize_plus_1 = 1u128 << self.pointer_size().bits();
24-
u64::try_from(max_usize_plus_1 - 1).unwrap()
23+
self.pointer_size().unsigned_int_max().try_into().unwrap()
2524
}
2625

2726
#[inline]
2827
fn machine_isize_min(&self) -> i64 {
29-
let max_isize_plus_1 = 1i128 << (self.pointer_size().bits() - 1);
30-
i64::try_from(-max_isize_plus_1).unwrap()
28+
self.pointer_size().signed_int_min().try_into().unwrap()
3129
}
3230

3331
#[inline]
3432
fn machine_isize_max(&self) -> i64 {
35-
let max_isize_plus_1 = 1u128 << (self.pointer_size().bits() - 1);
36-
i64::try_from(max_isize_plus_1 - 1).unwrap()
33+
self.pointer_size().signed_int_max().try_into().unwrap()
3734
}
3835

3936
#[inline]
4037
fn machine_usize_to_isize(&self, val: u64) -> i64 {
4138
let val = val as i64;
42-
// Now clamp into the machine_isize range.
39+
// Now wrap-around into the machine_isize range.
4340
if val > self.machine_isize_max() {
4441
// This can only happen the the ptr size is < 64, so we know max_usize_plus_1 fits into
4542
// i64.
43+
debug_assert!(self.pointer_size().bits() < 64);
4644
let max_usize_plus_1 = 1u128 << self.pointer_size().bits();
4745
val - i64::try_from(max_usize_plus_1).unwrap()
4846
} else {

compiler/rustc_parse/src/parser/item.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,20 @@ impl<'a> Parser<'a> {
493493
let ty_first = if self.token.is_keyword(kw::For) && self.look_ahead(1, |t| t != &token::Lt)
494494
{
495495
let span = self.prev_token.span.between(self.token.span);
496-
self.struct_span_err(span, "missing trait in a trait impl").emit();
496+
self.struct_span_err(span, "missing trait in a trait impl")
497+
.span_suggestion(
498+
span,
499+
"add a trait here",
500+
" Trait ".into(),
501+
Applicability::HasPlaceholders,
502+
)
503+
.span_suggestion(
504+
span.to(self.token.span),
505+
"for an inherent impl, drop this `for`",
506+
"".into(),
507+
Applicability::MaybeIncorrect,
508+
)
509+
.emit();
497510
P(Ty {
498511
kind: TyKind::Path(None, err_path(span)),
499512
span,

compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,10 +1487,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
14871487
) => false,
14881488

14891489
(ParamCandidate(other), ParamCandidate(victim)) => {
1490-
let value_same_except_bound_vars = other.value.skip_binder()
1490+
let same_except_bound_vars = other.value.skip_binder()
14911491
== victim.value.skip_binder()
1492+
&& other.constness == victim.constness
14921493
&& !other.value.skip_binder().has_escaping_bound_vars();
1493-
if value_same_except_bound_vars {
1494+
if same_except_bound_vars {
14941495
// See issue #84398. In short, we can generate multiple ParamCandidates which are
14951496
// the same except for unused bound vars. Just pick the one with the fewest bound vars
14961497
// or the current one if tied (they should both evaluate to the same answer). This is

library/core/src/cell.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1916,7 +1916,8 @@ impl<T: ?Sized> UnsafeCell<T> {
19161916
/// ```
19171917
#[inline(always)]
19181918
#[stable(feature = "unsafe_cell_get_mut", since = "1.50.0")]
1919-
pub fn get_mut(&mut self) -> &mut T {
1919+
#[rustc_const_unstable(feature = "const_unsafecell_get_mut", issue = "88836")]
1920+
pub const fn get_mut(&mut self) -> &mut T {
19201921
&mut self.value
19211922
}
19221923

src/bootstrap/test.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,11 @@ impl Step for RustdocGUI {
925925
.env("RUSTDOC", builder.rustdoc(self.compiler))
926926
.env("RUSTC", builder.rustc(self.compiler))
927927
.current_dir(path);
928+
// FIXME: implement a `// compile-flags` command or similar
929+
// instead of hard-coding this test
930+
if entry.file_name() == "link_to_definition" {
931+
cargo.env("RUSTDOCFLAGS", "-Zunstable-options --generate-link-to-definition");
932+
}
928933
builder.run(&mut cargo);
929934
}
930935
}

src/librustdoc/html/highlight.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//!
66
//! Use the `render_with_highlighting` to highlight some rust code.
77
8+
use crate::clean::PrimitiveType;
89
use crate::html::escape::Escape;
910
use crate::html::render::Context;
1011

@@ -584,6 +585,13 @@ fn string<T: Display>(
584585
.ok()
585586
.map(|(url, _, _)| url)
586587
}
588+
LinkFromSrc::Primitive(prim) => format::href_with_root_path(
589+
PrimitiveType::primitive_locations(context.tcx())[&prim],
590+
context,
591+
Some(context_info.root_path),
592+
)
593+
.ok()
594+
.map(|(url, _, _)| url),
587595
}
588596
})
589597
{

src/librustdoc/html/render/span_map.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::clean;
1+
use crate::clean::{self, PrimitiveType};
22
use crate::html::sources;
33

44
use rustc_data_structures::fx::FxHashMap;
@@ -22,6 +22,7 @@ use std::path::{Path, PathBuf};
2222
crate enum LinkFromSrc {
2323
Local(clean::Span),
2424
External(DefId),
25+
Primitive(PrimitiveType),
2526
}
2627

2728
/// This function will do at most two things:
@@ -73,17 +74,20 @@ impl<'tcx> SpanMapVisitor<'tcx> {
7374
Some(def_id)
7475
}
7576
Res::Local(_) => None,
77+
Res::PrimTy(p) => {
78+
// FIXME: Doesn't handle "path-like" primitives like arrays or tuples.
79+
let span = path_span.unwrap_or(path.span);
80+
self.matches.insert(span, LinkFromSrc::Primitive(PrimitiveType::from(p)));
81+
return;
82+
}
7683
Res::Err => return,
7784
_ => return,
7885
};
7986
if let Some(span) = self.tcx.hir().res_span(path.res) {
80-
self.matches.insert(
81-
path_span.unwrap_or_else(|| path.span),
82-
LinkFromSrc::Local(clean::Span::new(span)),
83-
);
84-
} else if let Some(def_id) = info {
8587
self.matches
86-
.insert(path_span.unwrap_or_else(|| path.span), LinkFromSrc::External(def_id));
88+
.insert(path_span.unwrap_or(path.span), LinkFromSrc::Local(clean::Span::new(span)));
89+
} else if let Some(def_id) = info {
90+
self.matches.insert(path_span.unwrap_or(path.span), LinkFromSrc::External(def_id));
8791
}
8892
}
8993
}

src/librustdoc/html/static/css/themes/ayu.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ a {
217217
color: #c5c5c5;
218218
}
219219
body.source .example-wrap pre.rust a {
220-
background: #c5c5c5;
220+
background: #333;
221221
}
222222

223223
.docblock:not(.type-decl) a:not(.srclink):not(.test-arrow),

src/test/rustdoc-gui/code-sidebar-toggle.goml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
goto: file://|DOC_PATH|/test_docs/index.html
22
click: ".srclink"
3+
wait-for: "#sidebar-toggle"
34
click: "#sidebar-toggle"
45
wait-for: 500
56
fail: true
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// We check the background color on the jump to definition links in the source code page.
2+
goto: file://|DOC_PATH|/src/link_to_definition/lib.rs.html
3+
4+
// Set the theme to dark.
5+
local-storage: {"rustdoc-theme": "dark", "rustdoc-preferred-dark-theme": "dark", "rustdoc-use-system-theme": "false"}
6+
// We reload the page so the local storage settings are being used.
7+
reload:
8+
9+
assert-css: ("body.source .example-wrap pre.rust a", {"background-color": "rgb(51, 51, 51)"}, ALL)
10+
11+
// Set the theme to ayu.
12+
local-storage: {"rustdoc-theme": "ayu", "rustdoc-preferred-dark-theme": "ayu", "rustdoc-use-system-theme": "false"}
13+
// We reload the page so the local storage settings are being used.
14+
reload:
15+
16+
assert-css: ("body.source .example-wrap pre.rust a", {"background-color": "rgb(51, 51, 51)"}, ALL)
17+
18+
// Set the theme to light.
19+
local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"}
20+
// We reload the page so the local storage settings are being used.
21+
reload:
22+
23+
assert-css: ("body.source .example-wrap pre.rust a", {"background-color": "rgb(238, 238, 238)"}, ALL)

0 commit comments

Comments
 (0)