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

Account for item-local, out of scope bindings, in E0425 #104700

Closed
estebank opened this issue Nov 22, 2022 · 3 comments · Fixed by #104864
Closed

Account for item-local, out of scope bindings, in E0425 #104700

estebank opened this issue Nov 22, 2022 · 3 comments · Fixed by #104864
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically D-papercut Diagnostics: An error or lint that needs small tweaks. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

estebank commented Nov 22, 2022

When encountering a binding that is not available

     let foo = 1;
    {
        let bar = 2;
    }
    println!("{foo} {bar}");

the error should mention bindings that are outside of the scope but within the same item

error[E0425]: cannot find value `bar` in this scope
 --> src/main.rs:6:22
  |
6 |     println!("{foo} {bar}");
  |                      ^^^ not found in this scope
note: the binding `bar` is available in a different scope in the same function
 --> src/main.rs:4:8
  |
4 |         let bar = 2;
  |             ^^^
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-papercut Diagnostics: An error or lint that needs small tweaks. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. labels Nov 22, 2022
@chenyukang
Copy link
Member

@rustbot claim

@chenyukang
Copy link
Member

chenyukang commented Nov 25, 2022

Do you think we should suggest in this scenario?

#![feature(if_let_guard)]

fn main() {
    match Some(None) {
        Some(x) if let Some(y) = x => (x, y),
        _ => y, //~ ERROR cannot find value `y`
    }
    y //~ ERROR cannot find value `y`
}

My local dev branch will suggest:

error[E0425]: cannot find value `y` in this scope
 --> src/test/ui/rfc-2294-if-let-guard/bindings.rs:6:14
  |
6 |         _ => y, //~ ERROR cannot find value `y`
  |              ^
  |
help: the binding `y` is available in a different scope in the same function
 --> src/test/ui/rfc-2294-if-let-guard/bindings.rs:5:29
  |
5 |         Some(x) if let Some(y) = x => (x, y),
  |                             ^

error[E0425]: cannot find value `y` in this scope
 --> src/test/ui/rfc-2294-if-let-guard/bindings.rs:8:5
  |
8 |     y //~ ERROR cannot find value `y`
  |     ^ not found in this scope

error: aborting due to 2 previous errors

@chenyukang
Copy link
Member

I removed it.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 13, 2022
…ng, r=estebank

Account for item-local in inner scope for E0425

Fixes rust-lang#104700
@bors bors closed this as completed in 7cd4b67 Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically D-papercut Diagnostics: An error or lint that needs small tweaks. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants