diff options
| author | yukang <moorekang@gmail.com> | 2022-11-25 13:19:21 +0800 |
|---|---|---|
| committer | yukang <moorekang@gmail.com> | 2022-11-25 13:19:21 +0800 |
| commit | 7cd4b673d050508544f0b200ab6a840bebc38f0f (patch) | |
| tree | 6f3a1b897d2f4999d214f004276a74d28010f53d /compiler/rustc_resolve | |
| parent | 1dda298ad39a64e019a3511139c5b13ac0a18e54 (diff) | |
| download | rust-7cd4b673d050508544f0b200ab6a840bebc38f0f.tar.gz rust-7cd4b673d050508544f0b200ab6a840bebc38f0f.zip | |
fix #104700, account for item-local in inner scope for E0425
Diffstat (limited to 'compiler/rustc_resolve')
| -rw-r--r-- | compiler/rustc_resolve/src/late.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/late/diagnostics.rs | 16 |
2 files changed, 21 insertions, 1 deletions
diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 93b0f5814de..8faef4c6374 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -566,6 +566,9 @@ struct LateResolutionVisitor<'a, 'b, 'ast> { /// FIXME #4948: Reuse ribs to avoid allocation. ribs: PerNS<Vec<Rib<'a>>>, + /// Previous poped `rib`, only used for diagnostic. + last_block_rib: Option<Rib<'a>>, + /// The current set of local scopes, for labels. label_ribs: Vec<Rib<'a, NodeId>>, @@ -1168,6 +1171,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { type_ns: vec![Rib::new(start_rib_kind)], macro_ns: vec![Rib::new(start_rib_kind)], }, + last_block_rib: None, label_ribs: Vec::new(), lifetime_ribs: Vec::new(), lifetime_elision_candidates: None, @@ -3756,7 +3760,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { self.ribs[ValueNS].pop(); self.label_ribs.pop(); } - self.ribs[ValueNS].pop(); + self.last_block_rib = self.ribs[ValueNS].pop(); if anonymous_module.is_some() { self.ribs[TypeNS].pop(); } diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index b340bee28c3..b3dd5bb28a7 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -614,6 +614,22 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { return (true, candidates); } } + + // Try to find in last block rib + if let Some(rib) = &self.last_block_rib { + for (ident, &res) in &rib.bindings { + if let Res::Local(_) = res && path.len() == 1 && + ident.span.eq_ctxt(path[0].ident.span) && + ident.name == path[0].ident.name { + err.span_help( + ident.span, + &format!("the binding `{}` is available in a different scope in the same function", path_str), + ); + return (true, candidates); + } + } + } + return (false, candidates); } |
