From 27d6b9d215f95f1013b102f241524f63330c60a3 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 5 Jan 2016 13:43:57 -0500 Subject: [PATCH] improve visibility of future-incompatibilities (mildly, at least) --- src/librustc/lint/builtin.rs | 3 +++ src/librustc/lint/context.rs | 20 +++++++++++++++++--- src/librustc_trans/trans/base.rs | 1 + 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 2c5c664566a3..26c38a863e22 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -16,6 +16,9 @@ use lint::{LintPass, LateLintPass, LintArray}; +// name of the future-incompatible group +pub const FUTURE_INCOMPATIBLE: &'static str = "future_incompatible"; + declare_lint! { pub CONST_ERR, Warn, diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 464f29a33937..a4af12bcc7c9 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -364,14 +364,16 @@ pub fn gather_attrs(attrs: &[ast::Attribute]) /// lints elsewhere in the compiler should call /// `Session::add_lint()` instead. pub fn raw_emit_lint(sess: &Session, + lints: &LintStore, lint: &'static Lint, lvlsrc: LevelSource, span: Option, msg: &str) { - raw_struct_lint(sess, lint, lvlsrc, span, msg).emit(); + raw_struct_lint(sess, lints, lint, lvlsrc, span, msg).emit(); } pub fn raw_struct_lint<'a>(sess: &'a Session, + lints: &LintStore, lint: &'static Lint, lvlsrc: LevelSource, span: Option, @@ -413,6 +415,18 @@ pub fn raw_struct_lint<'a>(sess: &'a Session, _ => sess.bug("impossible level in raw_emit_lint"), }; + // Check for future incompatibility lints and issue a stronger warning. + let future_incompat_lints = &lints.lint_groups[builtin::FUTURE_INCOMPATIBLE]; + let this_id = LintId::of(lint); + if future_incompat_lints.0.iter().any(|&id| id == this_id) { + let msg = "this lint will become a HARD ERROR in a future release!"; + if let Some(sp) = span { + err.span_note(sp, msg); + } else { + err.note(msg); + } + } + if let Some(span) = def { err.span_note(span, "lint level defined here"); } @@ -450,7 +464,7 @@ pub trait LintContext: Sized { Some(pair) => pair, }; - raw_emit_lint(&self.sess(), lint, (level, src), span, msg); + raw_emit_lint(&self.sess(), self.lints(), lint, (level, src), span, msg); } fn lookup(&self, @@ -463,7 +477,7 @@ pub trait LintContext: Sized { Some(pair) => pair, }; - raw_struct_lint(&self.sess(), lint, (level, src), span, msg) + raw_struct_lint(&self.sess(), self.lints(), lint, (level, src), span, msg) } /// Emit a lint at the appropriate level, for a particular span. diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index 4197f80cb5ea..67f26595a369 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -2208,6 +2208,7 @@ fn enum_variant_size_lint(ccx: &CrateContext, enum_def: &hir::EnumDef, sp: Span, // Use lint::raw_emit_lint rather than sess.add_lint because the lint-printing // pass for the latter already ran. lint::raw_struct_lint(&ccx.tcx().sess, + &ccx.tcx().sess.lint_store.borrow(), lint::builtin::VARIANT_SIZE_DIFFERENCES, *lvlsrc.unwrap(), Some(sp),