]> git.lizzy.rs Git - rust.git/commit - src/tools/rust-analyzer
Rollup merge of #85478 - FabianWolff:issue-85348, r=petrochenkov
authorDylan DPC <dylan.dpc@gmail.com>
Wed, 26 May 2021 11:32:05 +0000 (13:32 +0200)
committerGitHub <noreply@github.com>
Wed, 26 May 2021 11:32:05 +0000 (13:32 +0200)
commit69c78a98ee2fb1e96675beb50115495bffca9777
treeac28a84e42696c8a28fb697d671a10d03fb95f0f
parent1969c2e312303faa458cf19dad9783165e3c72c8
parentf749d88ae7574aa18aa527ad4d6345e98ea00a82
Rollup merge of #85478 - FabianWolff:issue-85348, r=petrochenkov

Disallow shadowing const parameters

This pull request fixes #85348. Trying to shadow a `const` parameter as follows:
```rust
fn foo<const N: i32>() {
    let N @ _ = 0;
}
```
currently causes an ICE. With my changes, I get:
```
error[E0530]: let bindings cannot shadow const parameters
 --> test.rs:2:9
  |
1 | fn foo<const N: i32>() {
  |              - the const parameter `N` is defined here
2 |     let N @ _ = 0;
  |         ^ cannot be named the same as a const parameter

error: aborting due to previous error
```
This is the same error you get when trying to shadow a constant:
```rust
const N: i32 = 0;
let N @ _ = 0;
```
```
error[E0530]: let bindings cannot shadow constants
 --> src/lib.rs:3:5
  |
2 | const N: i32 = 0;
  | ----------------- the constant `N` is defined here
3 | let N @ _ = 0;
  |     ^ cannot be named the same as a constant

error: aborting due to previous error
```
The reason for disallowing shadowing in both cases is described [here](https://github.com/rust-lang/rust/issues/33118#issuecomment-233962221) (the comment there only talks about constants, but the same reasoning applies to `const` parameters).
compiler/rustc_resolve/src/lib.rs