Disallow shadowing const parameters
This commit is contained in:
parent
3e827cc21e
commit
f749d88ae7
7 changed files with 124 additions and 15 deletions
12
src/test/ui/resolve/issue-85348.rs
Normal file
12
src/test/ui/resolve/issue-85348.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
// Checks whether shadowing a const parameter leads to an ICE (#85348).
|
||||
|
||||
impl<const N: usize> ArrayWindowsExample {
|
||||
//~^ ERROR: cannot find type `ArrayWindowsExample` in this scope [E0412]
|
||||
fn next() {
|
||||
let mut N;
|
||||
//~^ ERROR: let bindings cannot shadow const parameters [E0530]
|
||||
//~| ERROR: type annotations needed [E0282]
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
25
src/test/ui/resolve/issue-85348.stderr
Normal file
25
src/test/ui/resolve/issue-85348.stderr
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
error[E0530]: let bindings cannot shadow const parameters
|
||||
--> $DIR/issue-85348.rs:6:17
|
||||
|
|
||||
LL | impl<const N: usize> ArrayWindowsExample {
|
||||
| - the const parameter `N` is defined here
|
||||
...
|
||||
LL | let mut N;
|
||||
| ^ cannot be named the same as a const parameter
|
||||
|
||||
error[E0412]: cannot find type `ArrayWindowsExample` in this scope
|
||||
--> $DIR/issue-85348.rs:3:22
|
||||
|
|
||||
LL | impl<const N: usize> ArrayWindowsExample {
|
||||
| ^^^^^^^^^^^^^^^^^^^ not found in this scope
|
||||
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/issue-85348.rs:6:13
|
||||
|
|
||||
LL | let mut N;
|
||||
| ^^^^^ consider giving `N` a type
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0282, E0412, E0530.
|
||||
For more information about an error, try `rustc --explain E0282`.
|
||||
20
src/test/ui/resolve/shadow-const-param.rs
Normal file
20
src/test/ui/resolve/shadow-const-param.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// Checks that const parameters cannot be shadowed with fresh bindings
|
||||
// even in syntactically unambiguous contexts. See
|
||||
// https://github.com/rust-lang/rust/issues/33118#issuecomment-233962221
|
||||
|
||||
fn foo<const N: i32>(i: i32) -> bool {
|
||||
match i {
|
||||
N @ _ => true,
|
||||
//~^ ERROR: match bindings cannot shadow const parameters [E0530]
|
||||
}
|
||||
}
|
||||
|
||||
fn bar<const N: i32>(i: i32) -> bool {
|
||||
let N @ _ = 0;
|
||||
//~^ ERROR: let bindings cannot shadow const parameters [E0530]
|
||||
match i {
|
||||
N @ _ => true,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
20
src/test/ui/resolve/shadow-const-param.stderr
Normal file
20
src/test/ui/resolve/shadow-const-param.stderr
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
error[E0530]: match bindings cannot shadow const parameters
|
||||
--> $DIR/shadow-const-param.rs:7:9
|
||||
|
|
||||
LL | fn foo<const N: i32>(i: i32) -> bool {
|
||||
| - the const parameter `N` is defined here
|
||||
LL | match i {
|
||||
LL | N @ _ => true,
|
||||
| ^ cannot be named the same as a const parameter
|
||||
|
||||
error[E0530]: let bindings cannot shadow const parameters
|
||||
--> $DIR/shadow-const-param.rs:13:9
|
||||
|
|
||||
LL | fn bar<const N: i32>(i: i32) -> bool {
|
||||
| - the const parameter `N` is defined here
|
||||
LL | let N @ _ = 0;
|
||||
| ^ cannot be named the same as a const parameter
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0530`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue