diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-12-13 01:17:08 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-13 01:17:08 +0100 |
| commit | 6dbaf86672397081f4b946b18acc37d1a27611d8 (patch) | |
| tree | a58b5b14ca77b02bd777172563ff3c79d301340e /compiler | |
| parent | ed9749324aed9e97741abf569a022353e269a9df (diff) | |
| parent | 68ea51602a492a02ed5d23580ac06f9c4cc830f5 (diff) | |
| download | rust-6dbaf86672397081f4b946b18acc37d1a27611d8.tar.gz rust-6dbaf86672397081f4b946b18acc37d1a27611d8.zip | |
Rollup merge of #104864 - chenyukang:yukang/fix-104700-binding, r=estebank
Account for item-local in inner scope for E0425 Fixes #104700
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_resolve/src/late.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/late/diagnostics.rs | 16 |
2 files changed, 23 insertions, 1 deletions
diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index cf3e5946053..5b7a00101e9 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>>, @@ -873,6 +876,8 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> { // Ignore errors in function bodies if this is rustdoc // Be sure not to set this until the function signature has been resolved. let previous_state = replace(&mut this.in_func_body, true); + // We only care block in the same function + this.last_block_rib = None; // Resolve the function body, potentially inside the body of an async closure this.with_lifetime_rib( LifetimeRibKind::Elided(LifetimeRes::Infer), @@ -1168,6 +1173,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, @@ -3769,7 +3775,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 d43983ea815..49bbe37ee43 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -623,6 +623,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 && let RibKind::NormalRibKind = rib.kind { + 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); } |
