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

Diff for: compiler/rustc_middle/src/mir/interpret/pointer.rs

+6-8
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 {

Diff for: compiler/rustc_parse/src/parser/item.rs

+14-1
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,

Diff for: compiler/rustc_trait_selection/src/traits/select/mod.rs

+3-2
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

Diff for: library/core/src/cell.rs

+2-1
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

Diff for: src/bootstrap/test.rs

+5
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
}

Diff for: src/librustdoc/html/highlight.rs

+8
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
{

Diff for: src/librustdoc/html/render/span_map.rs

+11-7
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
}

Diff for: src/librustdoc/html/static/css/themes/ayu.css

+1-1
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),

Diff for: src/test/rustdoc-gui/code-sidebar-toggle.goml

+1
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

Diff for: src/test/rustdoc-gui/jump-to-def-background.goml

+23
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)
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file is automatically @generated by Cargo.
2+
# It is not intended for manual editing.
3+
version = 3
4+
5+
[[package]]
6+
name = "link_to_definition"
7+
version = "0.1.0"
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "link_to_definition"
3+
version = "0.1.0"
4+
edition = "2018"
5+
6+
[lib]
7+
path = "lib.rs"

Diff for: src/test/rustdoc-gui/src/link_to_definition/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pub struct Bar {
2+
pub a: String,
3+
pub b: u32,
4+
}
5+
6+
pub fn foo(_b: &Bar) {}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// compile-flags: -Zunstable-options --generate-link-to-definition
2+
3+
#![crate_name = "foo"]
4+
5+
// @has 'src/foo/check-source-code-urls-to-def-std.rs.html'
6+
7+
fn babar() {}
8+
9+
// @has - '//a[@href="{{channel}}/std/primitive.u32.html"]' 'u32'
10+
// @has - '//a[@href="{{channel}}/std/primitive.str.html"]' 'str'
11+
// @has - '//a[@href="{{channel}}/std/primitive.bool.html"]' 'bool'
12+
// @has - '//a[@href="../../src/foo/check-source-code-urls-to-def-std.rs.html#7"]' 'babar'
13+
pub fn foo(a: u32, b: &str, c: String) {
14+
let x = 12;
15+
let y: bool = true;
16+
babar();
17+
}

Diff for: src/test/rustdoc/check-source-code-urls-to-def.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ impl Foo {
2727
fn babar() {}
2828

2929
// @has - '//a/@href' '/struct.String.html'
30+
// @has - '//a/@href' '/primitive.u32.html'
31+
// @has - '//a/@href' '/primitive.str.html'
3032
// @count - '//a[@href="../../src/foo/check-source-code-urls-to-def.rs.html#21"]' 5
3133
// @has - '//a[@href="../../source_code/struct.SourceCode.html"]' 'source_code::SourceCode'
3234
pub fn foo(a: u32, b: &str, c: String, d: Foo, e: bar::Bar, f: source_code::SourceCode) {
@@ -40,5 +42,9 @@ pub fn foo(a: u32, b: &str, c: String, d: Foo, e: bar::Bar, f: source_code::Sour
4042

4143
// @has - '//a[@href="../../src/foo/auxiliary/source-code-bar.rs.html#14-16"]' 'bar::sub::Trait'
4244
// @has - '//a[@href="../../src/foo/auxiliary/source-code-bar.rs.html#14-16"]' 'Trait'
43-
pub fn foo2<T: bar::sub::Trait, V: Trait>(t: &T, v: &V) {
45+
pub fn foo2<T: bar::sub::Trait, V: Trait>(t: &T, v: &V, b: bool) {
4446
}
47+
48+
// @has - '//a[@href="../../foo/primitive.bool.html"]' 'bool'
49+
#[doc(primitive = "bool")]
50+
mod whatever {}

Diff for: src/test/ui/issues/issue-56031.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ error: missing trait in a trait impl
33
|
44
LL | impl for T {}
55
| ^
6+
|
7+
help: add a trait here
8+
|
9+
LL | impl Trait for T {}
10+
| +++++
11+
help: for an inherent impl, drop this `for`
12+
|
13+
LL - impl for T {}
14+
LL + impl T {}
15+
|
616

717
error: aborting due to previous error
818

Diff for: src/test/ui/parser/issue-88818.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Regression test for #88818 (improve error message for missing trait
2+
// in `impl for X`).
3+
4+
struct S { }
5+
impl for S { }
6+
//~^ ERROR: missing trait in a trait impl
7+
//~| HELP: add a trait here
8+
//~| HELP: for an inherent impl, drop this `for`
9+
10+
fn main() {}

Diff for: src/test/ui/parser/issue-88818.stderr

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: missing trait in a trait impl
2+
--> $DIR/issue-88818.rs:5:5
3+
|
4+
LL | impl for S { }
5+
| ^
6+
|
7+
help: add a trait here
8+
|
9+
LL | impl Trait for S { }
10+
| +++++
11+
help: for an inherent impl, drop this `for`
12+
|
13+
LL - impl for S { }
14+
LL + impl S { }
15+
|
16+
17+
error: aborting due to previous error
18+

Diff for: src/test/ui/rfc-2632-const-trait-impl/call-generic-method-dup-bound.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@ impl const PartialEq for S {
1616

1717
// This duplicate bound should not result in ambiguities. It should be equivalent to a single ~const
1818
// bound.
19-
// const fn equals_self<T: PartialEq + ~const PartialEq>(t: &T) -> bool {
20-
// FIXME(fee1-dead)^ why should the order matter here?
21-
const fn equals_self<T: ~const PartialEq + PartialEq>(t: &T) -> bool {
19+
const fn equals_self<T: PartialEq + ~const PartialEq>(t: &T) -> bool {
2220
*t == *t
2321
}
2422

25-
pub const EQ: bool = equals_self(&S);
23+
trait A: PartialEq {}
24+
impl<T: PartialEq> A for T {}
25+
26+
const fn equals_self2<T: A + ~const PartialEq>(t: &T) -> bool {
27+
*t == *t
28+
}
29+
30+
pub const EQ: bool = equals_self(&S) && equals_self2(&S);
2631

2732
fn main() {}

0 commit comments

Comments
 (0)