diff options
| author | Jan Verbeek <jan.verbeek@posteo.nl> | 2020-10-17 13:36:59 +0200 |
|---|---|---|
| committer | Jan Verbeek <jan.verbeek@posteo.nl> | 2020-10-17 13:36:59 +0200 |
| commit | e701ae376a040d9f5614cda3be6fabffe884b432 (patch) | |
| tree | e1a396230ff695c232c17614df18e8e8762788a2 /compiler/rustc_resolve/src | |
| parent | 03687f8ffaf5ff03f6bedbe77752b9f930c7efeb (diff) | |
| download | rust-e701ae376a040d9f5614cda3be6fabffe884b432.tar.gz rust-e701ae376a040d9f5614cda3be6fabffe884b432.zip | |
Suggest correct place to add `self` parameter when inside closure
It would incorrectly suggest adding it as a parameter to the closure instead of the containing function.
Diffstat (limited to 'compiler/rustc_resolve/src')
| -rw-r--r-- | compiler/rustc_resolve/src/late.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 219517b4ab2..7517ab66170 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -369,7 +369,7 @@ struct DiagnosticMetadata<'ast> { /// param. currently_processing_generics: bool, - /// The current enclosing function (used for better errors). + /// The current enclosing (non-closure) function (used for better errors). current_function: Option<(FnKind<'ast>, Span)>, /// A list of labels as of yet unused. Labels will be removed from this map when @@ -515,8 +515,10 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> { FnKind::Fn(FnCtxt::Assoc(_), ..) => NormalRibKind, FnKind::Closure(..) => ClosureOrAsyncRibKind, }; - let previous_value = - replace(&mut self.diagnostic_metadata.current_function, Some((fn_kind, sp))); + let previous_value = self.diagnostic_metadata.current_function; + if matches!(fn_kind, FnKind::Fn(..)) { + self.diagnostic_metadata.current_function = Some((fn_kind, sp)); + } debug!("(resolving function) entering function"); let declaration = fn_kind.decl(); |
