diff options
| author | Zack M. Davis <code@zackmdavis.net> | 2016-06-12 17:46:43 -0700 |
|---|---|---|
| committer | Zack M. Davis <code@zackmdavis.net> | 2016-07-30 15:18:07 -0700 |
| commit | 661b4f09fb8d765292521f618bcb8d79da544154 (patch) | |
| tree | d0e325cf13a44d111f8255b5792435eab1e43da7 | |
| parent | 7f7969ef44af9e7f060e7a505366a7925e4470c2 (diff) | |
| download | rust-661b4f09fb8d765292521f618bcb8d79da544154.tar.gz rust-661b4f09fb8d765292521f618bcb8d79da544154.zip | |
diagnostically note source of overruling outer forbid
When we emit E0453 (lint level attribute overruled by outer `forbid` lint level), it could be helpful to note where the `forbid` level was set, for the convenience of users who, e.g., believe that the correct fix is to weaken the `forbid` to `deny`.
| -rw-r--r-- | src/librustc/lint/context.rs | 22 | ||||
| -rw-r--r-- | src/test/compile-fail-fulldeps/lint-plugin-forbid-attrs.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/lint-forbid-attr.rs | 1 |
3 files changed, 19 insertions, 6 deletions
diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 357276e31f5..daac315e14d 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -29,7 +29,7 @@ use dep_graph::DepNode; use middle::privacy::AccessLevels; use ty::TyCtxt; use session::{config, early_error, Session}; -use lint::{Level, LevelSource, Lint, LintId, LintPass}; +use lint::{Level, LevelSource, Lint, LintId, LintPass, LintSource}; use lint::{EarlyLintPassObject, LateLintPassObject}; use lint::{Default, CommandLine, Node, Allow, Warn, Deny, Forbid}; use lint::builtin; @@ -599,13 +599,23 @@ pub trait LintContext: Sized { }; for (lint_id, level, span) in v { - let now = self.lints().get_level_source(lint_id).0; + let (now, now_source) = self.lints().get_level_source(lint_id); if now == Forbid && level != Forbid { let lint_name = lint_id.as_str(); - span_err!(self.sess(), span, E0453, - "{}({}) overruled by outer forbid({})", - level.as_str(), lint_name, - lint_name); + let mut diag_builder = struct_span_err!(self.sess(), span, E0453, + "{}({}) overruled by outer forbid({})", + level.as_str(), lint_name, + lint_name); + match now_source { + LintSource::Default => &mut diag_builder, + LintSource::Node(forbid_source_span) => { + diag_builder.span_note(forbid_source_span, + "`forbid` lint level set here") + }, + LintSource::CommandLine => { + diag_builder.note("`forbid` lint level was set on command line") + } + }.emit() } else if now != level { let src = self.lints().get_level_source(lint_id).1; self.level_stack().push((lint_id, (now, src))); diff --git a/src/test/compile-fail-fulldeps/lint-plugin-forbid-attrs.rs b/src/test/compile-fail-fulldeps/lint-plugin-forbid-attrs.rs index 83c845bfdf9..61a8ee88a70 100644 --- a/src/test/compile-fail-fulldeps/lint-plugin-forbid-attrs.rs +++ b/src/test/compile-fail-fulldeps/lint-plugin-forbid-attrs.rs @@ -14,6 +14,8 @@ #![feature(plugin)] #![plugin(lint_plugin_test)] #![forbid(test_lint)] +//~^ NOTE lint level defined here +//~| NOTE `forbid` lint level set here fn lintme() { } //~ ERROR item is named 'lintme' diff --git a/src/test/compile-fail/lint-forbid-attr.rs b/src/test/compile-fail/lint-forbid-attr.rs index fcc8fb6f933..fd2513c5a06 100644 --- a/src/test/compile-fail/lint-forbid-attr.rs +++ b/src/test/compile-fail/lint-forbid-attr.rs @@ -9,6 +9,7 @@ // except according to those terms. #![forbid(deprecated)] +//~^ NOTE `forbid` lint level set here #[allow(deprecated)] //~ ERROR allow(deprecated) overruled by outer forbid(deprecated) fn main() { |
