Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow shadowing const parameters #85478

Merged
merged 1 commit into from
May 26, 2021
Merged

Conversation

FabianWolff
Copy link
Contributor

This pull request fixes #85348. Trying to shadow a const parameter as follows:

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:

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 (the comment there only talks about constants, but the same reasoning applies to const parameters).

@rust-highfive
Copy link
Collaborator

r? @petrochenkov

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 19, 2021
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented May 25, 2021

📌 Commit f749d88 has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 25, 2021
@bors
Copy link
Contributor

bors commented May 25, 2021

⌛ Testing commit f749d88 with merge 863653d8b770162da5f63592bc8cbbcbc88b5154...

@bors
Copy link
Contributor

bors commented May 26, 2021

💥 Test timed out

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 26, 2021
@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@petrochenkov
Copy link
Contributor

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 26, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request May 26, 2021
Rollup of 8 pull requests

Successful merges:

 - rust-lang#85478 (Disallow shadowing const parameters)
 - rust-lang#85625 (Prevent double drop in `Vec::dedup_by` if a destructor panics)
 - rust-lang#85627 (Fix a few details in THIR unsafeck)
 - rust-lang#85633 (Post-monomorphization errors traces MVP)
 - rust-lang#85670 (Remove arrays/IntoIterator message from Iterator trait.)
 - rust-lang#85678 (fix `matches!` and `assert_matches!` on edition 2021)
 - rust-lang#85679 (Remove num_as_ne_bytes feature)
 - rust-lang#85712 (Fix typo in core::array::IntoIter comment)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 69c78a9 into rust-lang:master May 26, 2021
@rustbot rustbot added this to the 1.54.0 milestone May 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
6 participants