diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 7c6718f3d065e..a4592d9482f6a 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -564,6 +564,20 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { } } + fn visit_expr(&mut self, expr: &'tcx hir::Expr) { + if let hir::ExprCall(_, ref arguments) = expr.node { + // Avoid traversing into a call expression's callee specifically to avoid + // triggering a false positive for the invisible-lifetimes-in-type-paths lint. (The + // motivating examples were `Ref::map` and `Ref::clone`.) + // FIXME: is there a more elegant way of doing this?! + // + // But do visit the arguments + walk_list!(self, visit_expr, arguments); + } else { + intravisit::walk_expr(self, expr); + } + } + fn visit_ty(&mut self, ty: &'tcx hir::Ty) { debug!("visit_ty: id={:?} ty={:?}", ty.id, ty); match ty.node { @@ -2136,9 +2150,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { err.span_suggestion_with_applicability( replace_span, "indicate the anonymous lifetime", - suggestion.to_owned(), - // false positives observed with macros, `Ref::map` (tracking issue #52041) - Applicability::MaybeIncorrect + suggestion, + Applicability::MachineApplicable ); } err.emit(); diff --git a/src/test/ui/in-band-lifetimes/elided-lifetimes.fixed b/src/test/ui/in-band-lifetimes/elided-lifetimes.fixed index 24df541b08fe0..5d82cc8fd939a 100644 --- a/src/test/ui/in-band-lifetimes/elided-lifetimes.fixed +++ b/src/test/ui/in-band-lifetimes/elided-lifetimes.fixed @@ -51,4 +51,5 @@ fn main() { let loyalty: Ref<'_, (u32, char)> = honesty.borrow(); //~^ ERROR implicit lifetime parameters in types are deprecated //~| HELP indicate the anonymous lifetime + let generosity = Ref::map(loyalty, |t| &t.0); } diff --git a/src/test/ui/in-band-lifetimes/elided-lifetimes.rs b/src/test/ui/in-band-lifetimes/elided-lifetimes.rs index 661dd7530b723..b0158b8b3f484 100644 --- a/src/test/ui/in-band-lifetimes/elided-lifetimes.rs +++ b/src/test/ui/in-band-lifetimes/elided-lifetimes.rs @@ -51,4 +51,5 @@ fn main() { let loyalty: Ref<(u32, char)> = honesty.borrow(); //~^ ERROR implicit lifetime parameters in types are deprecated //~| HELP indicate the anonymous lifetime + let generosity = Ref::map(loyalty, |t| &t.0); }