From 6a8da716ad468f9fb75ceffef4b8c63484105d03 Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Sat, 7 Apr 2018 15:50:36 +0530 Subject: [PATCH 1/5] added function to check if lints belong to an external macro --- src/librustc/lint/context.rs | 4 ++- src/librustc/lint/mod.rs | 29 +++++++++++++++++++ .../ellided-lifetimes-macro-checks.rs | 15 ++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/in-band-lifetimes/ellided-lifetimes-macro-checks.rs diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 9f8cc2f86992f..f5ce77b245d01 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -466,7 +466,9 @@ pub trait LintContext<'tcx>: Sized { /// Emit a lint at the appropriate level, for a particular span. fn span_lint>(&self, lint: &'static Lint, span: S, msg: &str) { - self.lookup_and_emit(lint, Some(span), msg); + if !lint::in_external_macro(lint, span) { + self.lookup_and_emit(lint, Some(span), msg); + } } fn struct_span_lint>(&self, diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 89a9f3034787b..ee40bec599212 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -54,6 +54,8 @@ pub use lint::context::{LateContext, EarlyContext, LintContext, LintStore, check_crate, check_ast_crate, FutureIncompatibleInfo, BufferedEarlyLint}; +use codemap::{ExpnFormat, ExpnInfo, Span }; + /// Specification of a single lint. #[derive(Copy, Clone, Debug)] pub struct Lint { @@ -618,3 +620,30 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for LintLevelMapBuilder<'a, 'tcx> { pub fn provide(providers: &mut Providers) { providers.lint_levels = lint_levels; } + +pub fn in_external_macro<'a, T: LintContext<'a>>(cx: &T, span: Span) -> bool { + /// Invokes `in_macro` with the expansion info of the given span slightly + /// heavy, try to use + /// this after other checks have already happened. + fn in_macro_ext<'a, T: LintContext<'a>>(cx: &T, info: &ExpnInfo) -> bool { + // no ExpnInfo = no macro + if let ExpnFormat::MacroAttribute(..) = info.callee.format { + // these are all plugins + return true; + } + // no span for the callee = external macro + info.callee.span.map_or(true, |span| { + // no snippet = external macro or compiler-builtin expansion + cx.sess() + .codemap() + .span_to_snippet(span) + .ok() + .map_or(true, |code| !code.starts_with("macro_rules")) + }) + } + + span.ctxt() + .outer() + .expn_info() + .map_or(false, |info| in_macro_ext(cx, &info)) +} \ No newline at end of file diff --git a/src/test/ui/in-band-lifetimes/ellided-lifetimes-macro-checks.rs b/src/test/ui/in-band-lifetimes/ellided-lifetimes-macro-checks.rs new file mode 100644 index 0000000000000..29680ad2aaea2 --- /dev/null +++ b/src/test/ui/in-band-lifetimes/ellided-lifetimes-macro-checks.rs @@ -0,0 +1,15 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. +#![feature(nll)] +#![deny(elided_lifetime_in_path)] + +fn main() { + format!("foo {}", 22) +} \ No newline at end of file From b1f31d983c6e84f40cf6fa24b5e4c1abbdda5a2d Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Sat, 7 Apr 2018 16:50:14 +0530 Subject: [PATCH 2/5] add newline --- src/test/ui/in-band-lifetimes/ellided-lifetimes-macro-checks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/in-band-lifetimes/ellided-lifetimes-macro-checks.rs b/src/test/ui/in-band-lifetimes/ellided-lifetimes-macro-checks.rs index 29680ad2aaea2..9e53cbfb3adbe 100644 --- a/src/test/ui/in-band-lifetimes/ellided-lifetimes-macro-checks.rs +++ b/src/test/ui/in-band-lifetimes/ellided-lifetimes-macro-checks.rs @@ -12,4 +12,4 @@ fn main() { format!("foo {}", 22) -} \ No newline at end of file +} From 11adeb349633ce1fc2c082d0c607b927bcce8185 Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Sat, 7 Apr 2018 17:36:36 +0530 Subject: [PATCH 3/5] add newline --- src/librustc/lint/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index ee40bec599212..b5ca403eaf5dc 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -646,4 +646,4 @@ pub fn in_external_macro<'a, T: LintContext<'a>>(cx: &T, span: Span) -> bool { .outer() .expn_info() .map_or(false, |info| in_macro_ext(cx, &info)) -} \ No newline at end of file +} From a198b40643bd32627e0011c0004f09f824052bef Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Tue, 24 Apr 2018 00:26:04 +0530 Subject: [PATCH 4/5] add check for future incompatible links --- src/librustc/lint/context.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index f5ce77b245d01..f7affa208629b 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -466,8 +466,13 @@ pub trait LintContext<'tcx>: Sized { /// Emit a lint at the appropriate level, for a particular span. fn span_lint>(&self, lint: &'static Lint, span: S, msg: &str) { - if !lint::in_external_macro(lint, span) { - self.lookup_and_emit(lint, Some(span), msg); + match self.lints().future_incompatible(LintId::of(lint)) { + Some(_) => self.lookup_and_emit(lint, Some(span), msg), + None => { + if !lint::in_external_macro(lint, span) { + self.lookup_and_emit(lint, Some(span), msg); + } + } } } From bd85b634087f4d624153fb9a015c724c72ccf02f Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Sat, 5 May 2018 21:03:04 +0530 Subject: [PATCH 5/5] import fixed --- src/librustc/lint/context.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index f7affa208629b..101e5ee85f2c8 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -28,7 +28,7 @@ use self::TargetLint::*; use std::slice; use lint::{EarlyLintPassObject, LateLintPassObject}; -use lint::{Level, Lint, LintId, LintPass, LintBuffer}; +use lint::{self, Level, Lint, LintId, LintPass, LintBuffer}; use lint::builtin::BuiltinLintDiagnostics; use lint::levels::{LintLevelSets, LintLevelsBuilder}; use middle::privacy::AccessLevels;