From a9e13fa5533df7fc004aeab00d45822eacb8461e Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 10 Mar 2022 23:12:35 +0100 Subject: Lint elided lifetimes in path on the AST. --- compiler/rustc_lint/src/context.rs | 18 +++++++++++++++++- compiler/rustc_lint/src/early.rs | 5 +++++ 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'compiler/rustc_lint/src') diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 3600b6ad212..152c53dac7f 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -21,7 +21,8 @@ use crate::passes::{EarlyLintPassObject, LateLintPassObject}; use rustc_ast::util::unicode::TEXT_FLOW_CONTROL_CHARS; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync; -use rustc_errors::{struct_span_err, Applicability, MultiSpan, SuggestionStyle}; +use rustc_errors::{add_elided_lifetime_in_path_suggestion, struct_span_err}; +use rustc_errors::{Applicability, MultiSpan, SuggestionStyle}; use rustc_hir as hir; use rustc_hir::def::Res; use rustc_hir::def_id::{CrateNum, DefId}; @@ -665,6 +666,21 @@ pub trait LintContext: Sized { ) => { db.span_note(span_def, "the macro is defined here"); } + BuiltinLintDiagnostics::ElidedLifetimesInPaths( + n, + path_span, + incl_angl_brckt, + insertion_span, + ) => { + add_elided_lifetime_in_path_suggestion( + sess.source_map(), + &mut db, + n, + path_span, + incl_angl_brckt, + insertion_span, + ); + } BuiltinLintDiagnostics::UnknownCrateTypes(span, note, sugg) => { db.span_suggestion(span, ¬e, sugg, Applicability::MaybeIncorrect); } diff --git a/compiler/rustc_lint/src/early.rs b/compiler/rustc_lint/src/early.rs index e7855f8057c..b4262f184c8 100644 --- a/compiler/rustc_lint/src/early.rs +++ b/compiler/rustc_lint/src/early.rs @@ -284,6 +284,11 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T> ast_visit::walk_path(self, p); } + fn visit_path_segment(&mut self, path_span: Span, s: &'a ast::PathSegment) { + self.check_id(s.id); + ast_visit::walk_path_segment(self, path_span, s); + } + fn visit_attribute(&mut self, attr: &'a ast::Attribute) { run_early_pass!(self, check_attribute, attr); } -- cgit 1.4.1-3-g733a5