diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2019-10-17 20:26:21 -0700 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2019-10-17 20:26:21 -0700 |
| commit | f65a492afcd9cd892a1a5591f938efd41b5e0d24 (patch) | |
| tree | 546101f39f5a3ea68986c042d91f86e3f8fc1eb4 /src/librustc_resolve | |
| parent | 11011013f2b609b6cf58c96555b9e31dfd19d7ee (diff) | |
| download | rust-f65a492afcd9cd892a1a5591f938efd41b5e0d24.tar.gz rust-f65a492afcd9cd892a1a5591f938efd41b5e0d24.zip | |
Point at enclosing function without `self` receiver
Diffstat (limited to 'src/librustc_resolve')
| -rw-r--r-- | src/librustc_resolve/late.rs | 8 | ||||
| -rw-r--r-- | src/librustc_resolve/late/diagnostics.rs | 3 |
2 files changed, 10 insertions, 1 deletions
diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index bb9f895c5f3..73a282b1a0e 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -345,6 +345,9 @@ struct LateResolutionVisitor<'a, 'b> { /// The current self item if inside an ADT (used for better errors). current_self_item: Option<NodeId>, + /// The current enclosing funciton (used for better errors). + current_function: Option<Span>, + /// A list of labels as of yet unused. Labels will be removed from this map when /// they are used (in a `break` or `continue` statement) unused_labels: FxHashMap<NodeId, Span>, @@ -415,7 +418,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LateResolutionVisitor<'a, '_> { } } } - fn visit_fn(&mut self, fn_kind: FnKind<'tcx>, declaration: &'tcx FnDecl, _: Span, _: NodeId) { + fn visit_fn(&mut self, fn_kind: FnKind<'tcx>, declaration: &'tcx FnDecl, sp: Span, _: NodeId) { + let previous_value = replace(&mut self.current_function, Some(sp)); debug!("(resolving function) entering function"); let rib_kind = match fn_kind { FnKind::ItemFn(..) => FnItemRibKind, @@ -441,6 +445,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LateResolutionVisitor<'a, '_> { debug!("(resolving function) leaving function"); }) }); + self.current_function = previous_value; } fn visit_generics(&mut self, generics: &'tcx Generics) { @@ -546,6 +551,7 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> { current_trait_assoc_types: Vec::new(), current_self_type: None, current_self_item: None, + current_function: None, unused_labels: Default::default(), current_type_ascription: Vec::new(), } diff --git a/src/librustc_resolve/late/diagnostics.rs b/src/librustc_resolve/late/diagnostics.rs index dba4226e983..2721df4c687 100644 --- a/src/librustc_resolve/late/diagnostics.rs +++ b/src/librustc_resolve/late/diagnostics.rs @@ -134,6 +134,9 @@ impl<'a> LateResolutionVisitor<'a, '_> { "`self` value is a keyword only available in methods with a `self` parameter", ), }); + if let Some(span) = &self.current_function { + err.span_label(*span, "this function doesn't have a `self` parameter"); + } return (err, Vec::new()); } |
