unknown unstable lint command line
fix ##113702 fix #113702 unknown unstable lint command lint improve impelementation
This commit is contained in:
parent
95305899b8
commit
d2744175ac
@ -289,6 +289,7 @@ fn default_body_is_unstable(
|
|||||||
&tcx.sess.parse_sess,
|
&tcx.sess.parse_sess,
|
||||||
feature,
|
feature,
|
||||||
rustc_feature::GateIssue::Library(issue),
|
rustc_feature::GateIssue::Library(issue),
|
||||||
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
err.emit();
|
err.emit();
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_errors::{DecorateLint, DiagnosticBuilder, DiagnosticMessage, MultiSpan};
|
use rustc_errors::{DecorateLint, DiagnosticBuilder, DiagnosticMessage, MultiSpan};
|
||||||
use rustc_feature::Features;
|
use rustc_feature::{Features, GateIssue};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::intravisit::{self, Visitor};
|
use rustc_hir::intravisit::{self, Visitor};
|
||||||
use rustc_hir::HirId;
|
use rustc_hir::HirId;
|
||||||
@ -24,12 +24,14 @@
|
|||||||
};
|
};
|
||||||
use rustc_middle::query::Providers;
|
use rustc_middle::query::Providers;
|
||||||
use rustc_middle::ty::{RegisteredTools, TyCtxt};
|
use rustc_middle::ty::{RegisteredTools, TyCtxt};
|
||||||
use rustc_session::lint::builtin::{RENAMED_AND_REMOVED_LINTS, UNKNOWN_LINTS, UNUSED_ATTRIBUTES};
|
|
||||||
use rustc_session::lint::{
|
use rustc_session::lint::{
|
||||||
builtin::{self, FORBIDDEN_LINT_GROUPS, SINGLE_USE_LIFETIMES, UNFULFILLED_LINT_EXPECTATIONS},
|
builtin::{
|
||||||
|
self, FORBIDDEN_LINT_GROUPS, RENAMED_AND_REMOVED_LINTS, SINGLE_USE_LIFETIMES,
|
||||||
|
UNFULFILLED_LINT_EXPECTATIONS, UNKNOWN_LINTS, UNUSED_ATTRIBUTES,
|
||||||
|
},
|
||||||
Level, Lint, LintExpectationId, LintId,
|
Level, Lint, LintExpectationId, LintId,
|
||||||
};
|
};
|
||||||
use rustc_session::parse::{add_feature_diagnostics, feature_err};
|
use rustc_session::parse::feature_err;
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
use rustc_span::symbol::{sym, Symbol};
|
use rustc_span::symbol::{sym, Symbol};
|
||||||
use rustc_span::{Span, DUMMY_SP};
|
use rustc_span::{Span, DUMMY_SP};
|
||||||
@ -566,7 +568,7 @@ fn add_command_line(&mut self) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.check_gated_lint(id, DUMMY_SP) {
|
if self.check_gated_lint(id, DUMMY_SP, true) {
|
||||||
let src = LintLevelSource::CommandLine(lint_flag_val, orig_level);
|
let src = LintLevelSource::CommandLine(lint_flag_val, orig_level);
|
||||||
self.insert(id, (level, src));
|
self.insert(id, (level, src));
|
||||||
}
|
}
|
||||||
@ -837,7 +839,7 @@ fn add(&mut self, attrs: &[ast::Attribute], is_crate_node: bool, source_hir_id:
|
|||||||
reason,
|
reason,
|
||||||
};
|
};
|
||||||
for &id in *ids {
|
for &id in *ids {
|
||||||
if self.check_gated_lint(id, attr.span) {
|
if self.check_gated_lint(id, attr.span, false) {
|
||||||
self.insert_spec(id, (level, src));
|
self.insert_spec(id, (level, src));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -854,7 +856,7 @@ fn add(&mut self, attrs: &[ast::Attribute], is_crate_node: bool, source_hir_id:
|
|||||||
reason,
|
reason,
|
||||||
};
|
};
|
||||||
for &id in ids {
|
for &id in ids {
|
||||||
if self.check_gated_lint(id, attr.span) {
|
if self.check_gated_lint(id, attr.span, false) {
|
||||||
self.insert_spec(id, (level, src));
|
self.insert_spec(id, (level, src));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -955,7 +957,7 @@ fn add(&mut self, attrs: &[ast::Attribute], is_crate_node: bool, source_hir_id:
|
|||||||
reason,
|
reason,
|
||||||
};
|
};
|
||||||
for &id in ids {
|
for &id in ids {
|
||||||
if self.check_gated_lint(id, attr.span) {
|
if self.check_gated_lint(id, attr.span, false) {
|
||||||
self.insert_spec(id, (level, src));
|
self.insert_spec(id, (level, src));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1000,7 +1002,7 @@ fn add(&mut self, attrs: &[ast::Attribute], is_crate_node: bool, source_hir_id:
|
|||||||
// FIXME only emit this once for each attribute, instead of repeating it 4 times for
|
// FIXME only emit this once for each attribute, instead of repeating it 4 times for
|
||||||
// pre-expansion lints, post-expansion lints, `shallow_lint_levels_on` and `lint_expectations`.
|
// pre-expansion lints, post-expansion lints, `shallow_lint_levels_on` and `lint_expectations`.
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn check_gated_lint(&self, lint_id: LintId, span: Span) -> bool {
|
fn check_gated_lint(&self, lint_id: LintId, span: Span, lint_from_cli: bool) -> bool {
|
||||||
if let Some(feature) = lint_id.lint.feature_gate {
|
if let Some(feature) = lint_id.lint.feature_gate {
|
||||||
if !self.features.enabled(feature) {
|
if !self.features.enabled(feature) {
|
||||||
let lint = builtin::UNKNOWN_LINTS;
|
let lint = builtin::UNKNOWN_LINTS;
|
||||||
@ -1015,7 +1017,13 @@ fn check_gated_lint(&self, lint_id: LintId, span: Span) -> bool {
|
|||||||
|lint| {
|
|lint| {
|
||||||
lint.set_arg("name", lint_id.lint.name_lower());
|
lint.set_arg("name", lint_id.lint.name_lower());
|
||||||
lint.note(fluent::lint_note);
|
lint.note(fluent::lint_note);
|
||||||
add_feature_diagnostics(lint, &self.sess.parse_sess, feature);
|
rustc_session::parse::add_feature_diagnostics_for_issue(
|
||||||
|
lint,
|
||||||
|
&self.sess.parse_sess,
|
||||||
|
feature,
|
||||||
|
GateIssue::Language,
|
||||||
|
lint_from_cli,
|
||||||
|
);
|
||||||
lint
|
lint
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -8,6 +8,9 @@ session_cannot_mix_and_match_sanitizers = `-Zsanitizer={$first}` is incompatible
|
|||||||
session_cgu_not_recorded =
|
session_cgu_not_recorded =
|
||||||
CGU-reuse for `{$cgu_user_name}` is (mangled: `{$cgu_name}`) was not recorded
|
CGU-reuse for `{$cgu_user_name}` is (mangled: `{$cgu_name}`) was not recorded
|
||||||
|
|
||||||
|
session_cli_feature_diagnostic_help =
|
||||||
|
add `-Zcrate-attr="feature({$feature})"` to the command-line options to enable
|
||||||
|
|
||||||
session_crate_name_does_not_match = `--crate-name` and `#[crate_name]` are required to match, but `{$s}` != `{$name}`
|
session_crate_name_does_not_match = `--crate-name` and `#[crate_name]` are required to match, but `{$s}` != `{$name}`
|
||||||
|
|
||||||
session_crate_name_empty = crate name must not be empty
|
session_crate_name_empty = crate name must not be empty
|
||||||
|
@ -57,6 +57,12 @@ pub struct FeatureDiagnosticHelp {
|
|||||||
pub feature: Symbol,
|
pub feature: Symbol,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Subdiagnostic)]
|
||||||
|
#[help(session_cli_feature_diagnostic_help)]
|
||||||
|
pub struct CliFeatureDiagnosticHelp {
|
||||||
|
pub feature: Symbol,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(session_not_circumvent_feature)]
|
#[diag(session_not_circumvent_feature)]
|
||||||
pub struct NotCircumventFeature;
|
pub struct NotCircumventFeature;
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
//! It also serves as an input to the parser itself.
|
//! It also serves as an input to the parser itself.
|
||||||
|
|
||||||
use crate::config::CheckCfg;
|
use crate::config::CheckCfg;
|
||||||
use crate::errors::{FeatureDiagnosticForIssue, FeatureDiagnosticHelp, FeatureGateError};
|
use crate::errors::{
|
||||||
|
CliFeatureDiagnosticHelp, FeatureDiagnosticForIssue, FeatureDiagnosticHelp, FeatureGateError,
|
||||||
|
};
|
||||||
use crate::lint::{
|
use crate::lint::{
|
||||||
builtin::UNSTABLE_SYNTAX_PRE_EXPANSION, BufferedEarlyLint, BuiltinLintDiagnostics, Lint, LintId,
|
builtin::UNSTABLE_SYNTAX_PRE_EXPANSION, BufferedEarlyLint, BuiltinLintDiagnostics, Lint, LintId,
|
||||||
};
|
};
|
||||||
@ -110,7 +112,7 @@ pub fn feature_err_issue(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut err = sess.create_err(FeatureGateError { span, explain: explain.into() });
|
let mut err = sess.create_err(FeatureGateError { span, explain: explain.into() });
|
||||||
add_feature_diagnostics_for_issue(&mut err, sess, feature, issue);
|
add_feature_diagnostics_for_issue(&mut err, sess, feature, issue, false);
|
||||||
err
|
err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +141,7 @@ pub fn feature_warn_issue(
|
|||||||
explain: &'static str,
|
explain: &'static str,
|
||||||
) {
|
) {
|
||||||
let mut err = sess.span_diagnostic.struct_span_warn(span, explain);
|
let mut err = sess.span_diagnostic.struct_span_warn(span, explain);
|
||||||
add_feature_diagnostics_for_issue(&mut err, sess, feature, issue);
|
add_feature_diagnostics_for_issue(&mut err, sess, feature, issue, false);
|
||||||
|
|
||||||
// Decorate this as a future-incompatibility lint as in rustc_middle::lint::struct_lint_level
|
// Decorate this as a future-incompatibility lint as in rustc_middle::lint::struct_lint_level
|
||||||
let lint = UNSTABLE_SYNTAX_PRE_EXPANSION;
|
let lint = UNSTABLE_SYNTAX_PRE_EXPANSION;
|
||||||
@ -158,7 +160,7 @@ pub fn feature_warn_issue(
|
|||||||
|
|
||||||
/// Adds the diagnostics for a feature to an existing error.
|
/// Adds the diagnostics for a feature to an existing error.
|
||||||
pub fn add_feature_diagnostics(err: &mut Diagnostic, sess: &ParseSess, feature: Symbol) {
|
pub fn add_feature_diagnostics(err: &mut Diagnostic, sess: &ParseSess, feature: Symbol) {
|
||||||
add_feature_diagnostics_for_issue(err, sess, feature, GateIssue::Language);
|
add_feature_diagnostics_for_issue(err, sess, feature, GateIssue::Language, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds the diagnostics for a feature to an existing error.
|
/// Adds the diagnostics for a feature to an existing error.
|
||||||
@ -171,6 +173,7 @@ pub fn add_feature_diagnostics_for_issue(
|
|||||||
sess: &ParseSess,
|
sess: &ParseSess,
|
||||||
feature: Symbol,
|
feature: Symbol,
|
||||||
issue: GateIssue,
|
issue: GateIssue,
|
||||||
|
feature_from_cli: bool,
|
||||||
) {
|
) {
|
||||||
if let Some(n) = find_feature_issue(feature, issue) {
|
if let Some(n) = find_feature_issue(feature, issue) {
|
||||||
err.subdiagnostic(FeatureDiagnosticForIssue { n });
|
err.subdiagnostic(FeatureDiagnosticForIssue { n });
|
||||||
@ -178,7 +181,11 @@ pub fn add_feature_diagnostics_for_issue(
|
|||||||
|
|
||||||
// #23973: do not suggest `#![feature(...)]` if we are in beta/stable
|
// #23973: do not suggest `#![feature(...)]` if we are in beta/stable
|
||||||
if sess.unstable_features.is_nightly_build() {
|
if sess.unstable_features.is_nightly_build() {
|
||||||
err.subdiagnostic(FeatureDiagnosticHelp { feature });
|
if feature_from_cli {
|
||||||
|
err.subdiagnostic(CliFeatureDiagnosticHelp { feature });
|
||||||
|
} else {
|
||||||
|
err.subdiagnostic(FeatureDiagnosticHelp { feature });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
error: unknown lint: `test_unstable_lint`
|
error: unknown lint: `test_unstable_lint`
|
||||||
|
|
|
|
||||||
= note: the `test_unstable_lint` lint is unstable
|
= note: the `test_unstable_lint` lint is unstable
|
||||||
= help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable
|
= help: add `-Zcrate-attr="feature(test_unstable_lint)"` to the command-line options to enable
|
||||||
= note: requested on the command line with `-D unknown-lints`
|
= note: requested on the command line with `-D unknown-lints`
|
||||||
|
|
||||||
error: unknown lint: `test_unstable_lint`
|
error: unknown lint: `test_unstable_lint`
|
||||||
|
|
|
|
||||||
= note: the `test_unstable_lint` lint is unstable
|
= note: the `test_unstable_lint` lint is unstable
|
||||||
= help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable
|
= help: add `-Zcrate-attr="feature(test_unstable_lint)"` to the command-line options to enable
|
||||||
|
|
||||||
error: unknown lint: `test_unstable_lint`
|
error: unknown lint: `test_unstable_lint`
|
||||||
|
|
|
|
||||||
= note: the `test_unstable_lint` lint is unstable
|
= note: the `test_unstable_lint` lint is unstable
|
||||||
= help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable
|
= help: add `-Zcrate-attr="feature(test_unstable_lint)"` to the command-line options to enable
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
warning: unknown lint: `test_unstable_lint`
|
warning: unknown lint: `test_unstable_lint`
|
||||||
|
|
|
|
||||||
= note: the `test_unstable_lint` lint is unstable
|
= note: the `test_unstable_lint` lint is unstable
|
||||||
= help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable
|
= help: add `-Zcrate-attr="feature(test_unstable_lint)"` to the command-line options to enable
|
||||||
= note: requested on the command line with `-W unknown-lints`
|
= note: requested on the command line with `-W unknown-lints`
|
||||||
|
|
||||||
warning: unknown lint: `test_unstable_lint`
|
warning: unknown lint: `test_unstable_lint`
|
||||||
|
|
|
|
||||||
= note: the `test_unstable_lint` lint is unstable
|
= note: the `test_unstable_lint` lint is unstable
|
||||||
= help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable
|
= help: add `-Zcrate-attr="feature(test_unstable_lint)"` to the command-line options to enable
|
||||||
|
|
||||||
warning: unknown lint: `test_unstable_lint`
|
warning: unknown lint: `test_unstable_lint`
|
||||||
|
|
|
|
||||||
= note: the `test_unstable_lint` lint is unstable
|
= note: the `test_unstable_lint` lint is unstable
|
||||||
= help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable
|
= help: add `-Zcrate-attr="feature(test_unstable_lint)"` to the command-line options to enable
|
||||||
|
|
||||||
warning: 3 warnings emitted
|
warning: 3 warnings emitted
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user