Skip to content

Commit 63b3bac

Browse files
committed
Auto merge of #105775 - matthiaskrgr:rollup-2o8qn7e, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #105725 (Allow `impl ~const Trait` opaque types) - #105744 (Rewrite `E0158` error-code docs for clarity) - #105747 (Fix ICE calling method on auto trait) - #105748 (doc: Fix a few small issues) - #105756 (rustdoc: simplify CSS for codeblock tooltips) - #105757 (rustdoc: remove unused CSS `.sub-settings`) - #105764 (rustdoc: name the source page sidebar-toggle `#src-sidebar-toggle`) - #105774 (Remove unused stderr files) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 03770f0 + 8e35aad commit 63b3bac

File tree

22 files changed

+194
-156
lines changed

22 files changed

+194
-156
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ enum SelfSemantic {
4242
/// What is the context that prevents using `~const`?
4343
enum DisallowTildeConstContext<'a> {
4444
TraitObject,
45-
ImplTrait,
4645
Fn(FnKind<'a>),
4746
}
4847

@@ -187,11 +186,7 @@ impl<'a> AstValidator<'a> {
187186

188187
fn with_impl_trait(&mut self, outer: Option<Span>, f: impl FnOnce(&mut Self)) {
189188
let old = mem::replace(&mut self.outer_impl_trait, outer);
190-
if outer.is_some() {
191-
self.with_banned_tilde_const(DisallowTildeConstContext::ImplTrait, f);
192-
} else {
193-
f(self);
194-
}
189+
f(self);
195190
self.outer_impl_trait = old;
196191
}
197192

@@ -1384,7 +1379,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13841379
let mut err = self.err_handler().struct_span_err(bound.span(), "`~const` is not allowed here");
13851380
match reason {
13861381
DisallowTildeConstContext::TraitObject => err.note("trait objects cannot have `~const` trait bounds"),
1387-
DisallowTildeConstContext::ImplTrait => err.note("`impl Trait`s cannot have `~const` trait bounds"),
13881382
DisallowTildeConstContext::Fn(FnKind::Closure(..)) => err.note("closures cannot have `~const` trait bounds"),
13891383
DisallowTildeConstContext::Fn(FnKind::Fn(_, ident, ..)) => err.span_note(ident.span, "this function is not `const`, so it cannot have `~const` trait bounds"),
13901384
};
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,53 @@
1-
An associated const has been referenced in a pattern.
1+
An associated `const`, `const` parameter or `static` has been referenced
2+
in a pattern.
23

34
Erroneous code example:
45

56
```compile_fail,E0158
6-
enum EFoo { A, B, C, D }
7+
enum Foo {
8+
One,
9+
Two
10+
}
711
8-
trait Foo {
9-
const X: EFoo;
12+
trait Bar {
13+
const X: Foo;
1014
}
1115
12-
fn test<A: Foo>(arg: EFoo) {
16+
fn test<A: Bar>(arg: Foo) {
1317
match arg {
14-
A::X => { // error!
15-
println!("A::X");
16-
}
18+
A::X => println!("A::X"), // error: E0158: associated consts cannot be
19+
// referenced in patterns
20+
Foo::Two => println!("Two")
1721
}
1822
}
1923
```
2024

21-
`const` and `static` mean different things. A `const` is a compile-time
22-
constant, an alias for a literal value. This property means you can match it
23-
directly within a pattern.
25+
Associated `const`s cannot be referenced in patterns because it is impossible
26+
for the compiler to prove exhaustiveness (that some pattern will always match).
27+
Take the above example, because Rust does type checking in the *generic*
28+
method, not the *monomorphized* specific instance. So because `Bar` could have
29+
theoretically infinite implementations, there's no way to always be sure that
30+
`A::X` is `Foo::One`. So this code must be rejected. Even if code can be
31+
proven exhaustive by a programmer, the compiler cannot currently prove this.
2432

25-
The `static` keyword, on the other hand, guarantees a fixed location in memory.
26-
This does not always mean that the value is constant. For example, a global
27-
mutex can be declared `static` as well.
33+
The same holds true of `const` parameters and `static`s.
2834

29-
If you want to match against a `static`, consider using a guard instead:
35+
If you want to match against an associated `const`, `const` parameter or
36+
`static` consider using a guard instead:
3037

3138
```
32-
static FORTY_TWO: i32 = 42;
39+
trait Trait {
40+
const X: char;
41+
}
42+
43+
static FOO: char = 'j';
3344
34-
match Some(42) {
35-
Some(x) if x == FORTY_TWO => {}
36-
_ => {}
45+
fn test<A: Trait, const Y: char>(arg: char) {
46+
match arg {
47+
c if c == A::X => println!("A::X"),
48+
c if c == Y => println!("Y"),
49+
c if c == FOO => println!("FOO"),
50+
_ => ()
51+
}
3752
}
3853
```

compiler/rustc_hir_typeck/src/method/suggest.rs

+10
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
689689
let entry = spanned_predicates.entry(spans);
690690
entry.or_insert_with(|| (path, tr_self_ty, Vec::new())).2.push(p);
691691
}
692+
Some(Node::Item(hir::Item {
693+
kind: hir::ItemKind::Trait(rustc_ast::ast::IsAuto::Yes, ..),
694+
span: item_span,
695+
..
696+
})) => {
697+
tcx.sess.delay_span_bug(
698+
*item_span,
699+
"auto trait is invoked with no method error, but no error reported?",
700+
);
701+
}
692702
Some(_) => unreachable!(),
693703
None => (),
694704
}

library/alloc/src/collections/vec_deque/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2541,7 +2541,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
25412541
/// The deque is assumed to be partitioned according to the given predicate.
25422542
/// This means that all elements for which the predicate returns true are at the start of the deque
25432543
/// and all elements for which the predicate returns false are at the end.
2544-
/// For example, [7, 15, 3, 5, 4, 12, 6] is a partitioned under the predicate x % 2 != 0
2544+
/// For example, `[7, 15, 3, 5, 4, 12, 6]` is partitioned under the predicate `x % 2 != 0`
25452545
/// (all odd numbers are at the start, all even at the end).
25462546
///
25472547
/// If the deque is not partitioned, the returned result is unspecified and meaningless,

library/core/src/array/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ where
6969
/// if any element creation was unsuccessful.
7070
///
7171
/// The return type of this function depends on the return type of the closure.
72-
/// If you return `Result<T, E>` from the closure, you'll get a `Result<[T; N]; E>`.
72+
/// If you return `Result<T, E>` from the closure, you'll get a `Result<[T; N], E>`.
7373
/// If you return `Option<T>` from the closure, you'll get an `Option<[T; N]>`.
7474
///
7575
/// # Arguments
@@ -522,7 +522,7 @@ impl<T, const N: usize> [T; N] {
522522
/// return an array the same size as `self` or the first error encountered.
523523
///
524524
/// The return type of this function depends on the return type of the closure.
525-
/// If you return `Result<T, E>` from the closure, you'll get a `Result<[T; N]; E>`.
525+
/// If you return `Result<T, E>` from the closure, you'll get a `Result<[T; N], E>`.
526526
/// If you return `Option<T>` from the closure, you'll get an `Option<[T; N]>`.
527527
///
528528
/// # Examples

library/core/src/iter/traits/iterator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2734,7 +2734,7 @@ pub trait Iterator {
27342734
/// the first true result or the first error.
27352735
///
27362736
/// The return type of this method depends on the return type of the closure.
2737-
/// If you return `Result<bool, E>` from the closure, you'll get a `Result<Option<Self::Item>; E>`.
2737+
/// If you return `Result<bool, E>` from the closure, you'll get a `Result<Option<Self::Item>, E>`.
27382738
/// If you return `Option<bool>` from the closure, you'll get an `Option<Option<Self::Item>>`.
27392739
///
27402740
/// # Examples

library/core/src/slice/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3795,7 +3795,7 @@ impl<T> [T] {
37953795
/// The slice is assumed to be partitioned according to the given predicate.
37963796
/// This means that all elements for which the predicate returns true are at the start of the slice
37973797
/// and all elements for which the predicate returns false are at the end.
3798-
/// For example, [7, 15, 3, 5, 4, 12, 6] is a partitioned under the predicate x % 2 != 0
3798+
/// For example, `[7, 15, 3, 5, 4, 12, 6]` is partitioned under the predicate `x % 2 != 0`
37993799
/// (all odd numbers are at the start, all even at the end).
38003800
///
38013801
/// If this slice is not partitioned, the returned result is unspecified and meaningless,

src/librustdoc/html/static/css/rustdoc.css

+16-22
Original file line numberDiff line numberDiff line change
@@ -396,15 +396,15 @@ img {
396396
overflow-y: hidden;
397397
}
398398

399-
.source .sidebar, #sidebar-toggle, #source-sidebar {
399+
.source .sidebar, #src-sidebar-toggle, #source-sidebar {
400400
background-color: var(--sidebar-background-color);
401401
}
402402

403-
#sidebar-toggle > button:hover, #sidebar-toggle > button:focus {
403+
#src-sidebar-toggle > button:hover, #src-sidebar-toggle > button:focus {
404404
background-color: var(--sidebar-background-color-hover);
405405
}
406406

407-
.source .sidebar > *:not(#sidebar-toggle) {
407+
.source .sidebar > *:not(#src-sidebar-toggle) {
408408
visibility: hidden;
409409
}
410410

@@ -413,7 +413,7 @@ img {
413413
flex-basis: 300px;
414414
}
415415

416-
.source-sidebar-expanded .source .sidebar > *:not(#sidebar-toggle) {
416+
.source-sidebar-expanded .source .sidebar > *:not(#src-sidebar-toggle) {
417417
visibility: visible;
418418
}
419419

@@ -1118,8 +1118,7 @@ pre.rust .doccomment {
11181118
top: 5px;
11191119
}
11201120

1121-
.example-wrap .tooltip::after {
1122-
display: none;
1121+
.example-wrap .tooltip:hover::after {
11231122
text-align: center;
11241123
padding: 5px 3px 3px 3px;
11251124
border-radius: 6px;
@@ -1134,35 +1133,30 @@ pre.rust .doccomment {
11341133
color: var(--tooltip-color);
11351134
}
11361135

1137-
.example-wrap .tooltip::before {
1136+
.example-wrap .tooltip:hover::before {
11381137
content: " ";
11391138
position: absolute;
11401139
top: 50%;
11411140
left: 16px;
11421141
margin-top: -5px;
1143-
display: none;
11441142
z-index: 1;
11451143
border: 5px solid transparent;
11461144
border-right-color: var(--tooltip-background-color);
11471145
}
11481146

1149-
.example-wrap.ignore .tooltip::after {
1147+
.example-wrap.ignore .tooltip:hover::after {
11501148
content: "This example is not tested";
11511149
}
1152-
.example-wrap.compile_fail .tooltip::after {
1150+
.example-wrap.compile_fail .tooltip:hover::after {
11531151
content: "This example deliberately fails to compile";
11541152
}
1155-
.example-wrap.should_panic .tooltip::after {
1153+
.example-wrap.should_panic .tooltip:hover::after {
11561154
content: "This example panics";
11571155
}
1158-
.example-wrap.edition .tooltip::after {
1156+
.example-wrap.edition .tooltip:hover::after {
11591157
content: "This code runs with edition " attr(data-edition);
11601158
}
11611159

1162-
.example-wrap .tooltip:hover::before, .example-wrap .tooltip:hover::after {
1163-
display: inline;
1164-
}
1165-
11661160
.example-wrap.compile_fail .tooltip,
11671161
.example-wrap.should_panic .tooltip,
11681162
.example-wrap.ignore .tooltip {
@@ -1295,7 +1289,7 @@ a.test-arrow:hover {
12951289
font-size: 1rem;
12961290
}
12971291

1298-
#sidebar-toggle {
1292+
#src-sidebar-toggle {
12991293
position: sticky;
13001294
top: 0;
13011295
left: 0;
@@ -1324,7 +1318,7 @@ a.test-arrow:hover {
13241318
#source-sidebar div.files > a.selected {
13251319
background-color: var(--source-sidebar-background-selected);
13261320
}
1327-
#sidebar-toggle > button {
1321+
#src-sidebar-toggle > button {
13281322
font-size: inherit;
13291323
font-weight: bold;
13301324
background: none;
@@ -1726,7 +1720,7 @@ in storage.js
17261720
left: -11px;
17271721
}
17281722

1729-
#sidebar-toggle {
1723+
#src-sidebar-toggle {
17301724
position: fixed;
17311725
left: 1px;
17321726
top: 100px;
@@ -1740,7 +1734,7 @@ in storage.js
17401734
border-left: 0;
17411735
}
17421736

1743-
.source-sidebar-expanded #sidebar-toggle {
1737+
.source-sidebar-expanded #src-sidebar-toggle {
17441738
left: unset;
17451739
top: unset;
17461740
width: unset;
@@ -1851,10 +1845,10 @@ in storage.js
18511845
width: 35px;
18521846
}
18531847

1854-
#sidebar-toggle {
1848+
#src-sidebar-toggle {
18551849
top: 10px;
18561850
}
1857-
.source-sidebar-expanded #sidebar-toggle {
1851+
.source-sidebar-expanded #src-sidebar-toggle {
18581852
top: unset;
18591853
}
18601854
}

src/librustdoc/html/static/css/settings.css

-6
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,6 @@
5959
cursor: pointer;
6060
}
6161

62-
.setting-line > .sub-settings {
63-
padding-left: 42px;
64-
width: 100%;
65-
display: block;
66-
}
67-
6862
#settings .setting-line {
6963
margin: 1.2em 0.6em;
7064
}

src/librustdoc/html/static/js/source-script.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function toggleSidebar() {
8383

8484
function createSidebarToggle() {
8585
const sidebarToggle = document.createElement("div");
86-
sidebarToggle.id = "sidebar-toggle";
86+
sidebarToggle.id = "src-sidebar-toggle";
8787

8888
const inner = document.createElement("button");
8989

Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This test checks that the source code pages sidebar toggle is working as expected.
22
goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
33
click: ".srclink"
4-
wait-for: "#sidebar-toggle"
5-
click: "#sidebar-toggle"
4+
wait-for: "#src-sidebar-toggle"
5+
click: "#src-sidebar-toggle"
66
fail: true
77
assert-css: ("#source-sidebar", { "left": "-300px" })

src/test/rustdoc-gui/codeblock-tooltip.goml

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ define-function: (
2020
{"border-left": "2px solid rgba(255, 0, 0, 0.5)"},
2121
)),
2222

23-
("move-cursor-to", ".docblock .example-wrap.compile_fail"),
23+
("move-cursor-to", ".docblock .example-wrap.compile_fail .tooltip"),
2424

2525
("assert-css", (
2626
".docblock .example-wrap.compile_fail .tooltip",
@@ -60,7 +60,7 @@ define-function: (
6060
{"border-left": "2px solid rgba(255, 0, 0, 0.5)"},
6161
)),
6262

63-
("move-cursor-to", ".docblock .example-wrap.should_panic"),
63+
("move-cursor-to", ".docblock .example-wrap.should_panic .tooltip"),
6464

6565
("assert-css", (
6666
".docblock .example-wrap.should_panic .tooltip",
@@ -100,7 +100,7 @@ define-function: (
100100
{"border-left": "2px solid rgba(255, 142, 0, 0.6)"},
101101
)),
102102

103-
("move-cursor-to", ".docblock .example-wrap.ignore"),
103+
("move-cursor-to", ".docblock .example-wrap.ignore .tooltip"),
104104

105105
("assert-css", (
106106
".docblock .example-wrap.ignore .tooltip",

src/test/rustdoc-gui/cursor.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ assert-css: (".sidebar-menu-toggle", {"cursor": "pointer"})
2121

2222
// the sidebar toggle button on the source code pages
2323
goto: "file://" + |DOC_PATH| + "/src/lib2/lib.rs.html"
24-
assert-css: ("#sidebar-toggle > button", {"cursor": "pointer"})
24+
assert-css: ("#src-sidebar-toggle > button", {"cursor": "pointer"})

0 commit comments

Comments
 (0)