-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
22 changed files
with
194 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,53 @@ | ||
An associated const has been referenced in a pattern. | ||
An associated `const`, `const` parameter or `static` has been referenced | ||
in a pattern. | ||
|
||
Erroneous code example: | ||
|
||
```compile_fail,E0158 | ||
enum EFoo { A, B, C, D } | ||
enum Foo { | ||
One, | ||
Two | ||
} | ||
trait Foo { | ||
const X: EFoo; | ||
trait Bar { | ||
const X: Foo; | ||
} | ||
fn test<A: Foo>(arg: EFoo) { | ||
fn test<A: Bar>(arg: Foo) { | ||
match arg { | ||
A::X => { // error! | ||
println!("A::X"); | ||
} | ||
A::X => println!("A::X"), // error: E0158: associated consts cannot be | ||
// referenced in patterns | ||
Foo::Two => println!("Two") | ||
} | ||
} | ||
``` | ||
|
||
`const` and `static` mean different things. A `const` is a compile-time | ||
constant, an alias for a literal value. This property means you can match it | ||
directly within a pattern. | ||
Associated `const`s cannot be referenced in patterns because it is impossible | ||
for the compiler to prove exhaustiveness (that some pattern will always match). | ||
Take the above example, because Rust does type checking in the *generic* | ||
method, not the *monomorphized* specific instance. So because `Bar` could have | ||
theoretically infinite implementations, there's no way to always be sure that | ||
`A::X` is `Foo::One`. So this code must be rejected. Even if code can be | ||
proven exhaustive by a programmer, the compiler cannot currently prove this. | ||
|
||
The `static` keyword, on the other hand, guarantees a fixed location in memory. | ||
This does not always mean that the value is constant. For example, a global | ||
mutex can be declared `static` as well. | ||
The same holds true of `const` parameters and `static`s. | ||
|
||
If you want to match against a `static`, consider using a guard instead: | ||
If you want to match against an associated `const`, `const` parameter or | ||
`static` consider using a guard instead: | ||
|
||
``` | ||
static FORTY_TWO: i32 = 42; | ||
trait Trait { | ||
const X: char; | ||
} | ||
static FOO: char = 'j'; | ||
match Some(42) { | ||
Some(x) if x == FORTY_TWO => {} | ||
_ => {} | ||
fn test<A: Trait, const Y: char>(arg: char) { | ||
match arg { | ||
c if c == A::X => println!("A::X"), | ||
c if c == Y => println!("Y"), | ||
c if c == FOO => println!("FOO"), | ||
_ => () | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// This test checks that the source code pages sidebar toggle is working as expected. | ||
goto: "file://" + |DOC_PATH| + "/test_docs/index.html" | ||
click: ".srclink" | ||
wait-for: "#sidebar-toggle" | ||
click: "#sidebar-toggle" | ||
wait-for: "#src-sidebar-toggle" | ||
click: "#src-sidebar-toggle" | ||
fail: true | ||
assert-css: ("#source-sidebar", { "left": "-300px" }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.