Force warnings even when can_emit_warnings == false
This commit is contained in:
parent
e98897e5dc
commit
a3d6905053
8 changed files with 54 additions and 8 deletions
|
@ -145,8 +145,9 @@ impl AnnotateSnippetEmitterWriter {
|
||||||
title: Some(Annotation {
|
title: Some(Annotation {
|
||||||
label: Some(&message),
|
label: Some(&message),
|
||||||
id: code.as_ref().map(|c| match c {
|
id: code.as_ref().map(|c| match c {
|
||||||
DiagnosticId::Error(val)
|
DiagnosticId::Error(val) | DiagnosticId::Lint { name: val, .. } => {
|
||||||
| DiagnosticId::Lint { name: val, has_future_breakage: _ } => val.as_str(),
|
val.as_str()
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
annotation_type: annotation_type_for_level(*level),
|
annotation_type: annotation_type_for_level(*level),
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -29,7 +29,7 @@ pub struct Diagnostic {
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)]
|
||||||
pub enum DiagnosticId {
|
pub enum DiagnosticId {
|
||||||
Error(String),
|
Error(String),
|
||||||
Lint { name: String, has_future_breakage: bool },
|
Lint { name: String, has_future_breakage: bool, is_force_warn: bool },
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A "sub"-diagnostic attached to a parent diagnostic.
|
/// A "sub"-diagnostic attached to a parent diagnostic.
|
||||||
|
@ -109,6 +109,13 @@ impl Diagnostic {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_force_warn(&self) -> bool {
|
||||||
|
match self.code {
|
||||||
|
Some(DiagnosticId::Lint { is_force_warn, .. }) => is_force_warn,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Cancel the diagnostic (a structured diagnostic must either be emitted or
|
/// Cancel the diagnostic (a structured diagnostic must either be emitted or
|
||||||
/// canceled or it will panic when dropped).
|
/// canceled or it will panic when dropped).
|
||||||
pub fn cancel(&mut self) {
|
pub fn cancel(&mut self) {
|
||||||
|
|
|
@ -559,7 +559,7 @@ impl DiagnosticCode {
|
||||||
s.map(|s| {
|
s.map(|s| {
|
||||||
let s = match s {
|
let s = match s {
|
||||||
DiagnosticId::Error(s) => s,
|
DiagnosticId::Error(s) => s,
|
||||||
DiagnosticId::Lint { name, has_future_breakage: _ } => name,
|
DiagnosticId::Lint { name, .. } => name,
|
||||||
};
|
};
|
||||||
let je_result =
|
let je_result =
|
||||||
je.registry.as_ref().map(|registry| registry.try_find_description(&s)).unwrap();
|
je.registry.as_ref().map(|registry| registry.try_find_description(&s)).unwrap();
|
||||||
|
|
|
@ -802,7 +802,10 @@ impl HandlerInner {
|
||||||
self.future_breakage_diagnostics.push(diagnostic.clone());
|
self.future_breakage_diagnostics.push(diagnostic.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
if diagnostic.level == Warning && !self.flags.can_emit_warnings {
|
if diagnostic.level == Warning
|
||||||
|
&& !self.flags.can_emit_warnings
|
||||||
|
&& !diagnostic.is_force_warn()
|
||||||
|
{
|
||||||
if diagnostic.has_future_breakage() {
|
if diagnostic.has_future_breakage() {
|
||||||
(*TRACK_DIAGNOSTICS)(diagnostic);
|
(*TRACK_DIAGNOSTICS)(diagnostic);
|
||||||
}
|
}
|
||||||
|
@ -874,7 +877,7 @@ impl HandlerInner {
|
||||||
|
|
||||||
match (errors.len(), warnings.len()) {
|
match (errors.len(), warnings.len()) {
|
||||||
(0, 0) => return,
|
(0, 0) => return,
|
||||||
(0, _) => self.emit_diagnostic(&Diagnostic::new(Level::Warning, &warnings)),
|
(0, _) => self.emitter.emit_diagnostic(&Diagnostic::new(Level::Warning, &warnings)),
|
||||||
(_, 0) => {
|
(_, 0) => {
|
||||||
let _ = self.fatal(&errors);
|
let _ = self.fatal(&errors);
|
||||||
}
|
}
|
||||||
|
|
|
@ -246,6 +246,9 @@ pub fn struct_lint_level<'s, 'd>(
|
||||||
let has_future_breakage =
|
let has_future_breakage =
|
||||||
future_incompatible.map_or(false, |incompat| incompat.future_breakage.is_some());
|
future_incompatible.map_or(false, |incompat| incompat.future_breakage.is_some());
|
||||||
|
|
||||||
|
let is_force_warn = matches!(level, Level::ForceWarn)
|
||||||
|
|| matches!(src, LintLevelSource::CommandLine(_, Level::ForceWarn));
|
||||||
|
|
||||||
let mut err = match (level, span) {
|
let mut err = match (level, span) {
|
||||||
(Level::Allow, span) => {
|
(Level::Allow, span) => {
|
||||||
if has_future_breakage {
|
if has_future_breakage {
|
||||||
|
@ -254,6 +257,16 @@ pub fn struct_lint_level<'s, 'd>(
|
||||||
} else {
|
} else {
|
||||||
sess.struct_allow("")
|
sess.struct_allow("")
|
||||||
}
|
}
|
||||||
|
} else if is_force_warn {
|
||||||
|
let mut err = if let Some(span) = span {
|
||||||
|
sess.struct_span_warn(span, "")
|
||||||
|
} else {
|
||||||
|
sess.struct_warn("")
|
||||||
|
};
|
||||||
|
// Ensure force-warn warns even if the diagnostic has
|
||||||
|
// been canceled for reasons like `--cap-lints`
|
||||||
|
err.level = rustc_errors::Level::Warning;
|
||||||
|
err
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -349,7 +362,7 @@ pub fn struct_lint_level<'s, 'd>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err.code(DiagnosticId::Lint { name, has_future_breakage });
|
err.code(DiagnosticId::Lint { name, has_future_breakage, is_force_warn });
|
||||||
|
|
||||||
if let Some(future_incompatible) = future_incompatible {
|
if let Some(future_incompatible) = future_incompatible {
|
||||||
let explanation = if lint_id == LintId::of(builtin::UNSTABLE_NAME_COLLISIONS) {
|
let explanation = if lint_id == LintId::of(builtin::UNSTABLE_NAME_COLLISIONS) {
|
||||||
|
|
|
@ -323,7 +323,7 @@ impl Session {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|diag| {
|
.map(|diag| {
|
||||||
let lint_name = match &diag.code {
|
let lint_name = match &diag.code {
|
||||||
Some(DiagnosticId::Lint { name, has_future_breakage: true }) => name,
|
Some(DiagnosticId::Lint { name, has_future_breakage: true, .. }) => name,
|
||||||
_ => panic!("Unexpected code in diagnostic {:?}", diag),
|
_ => panic!("Unexpected code in diagnostic {:?}", diag),
|
||||||
};
|
};
|
||||||
let lint = lint_store.name_to_lint(&lint_name);
|
let lint = lint_store.name_to_lint(&lint_name);
|
||||||
|
|
10
src/test/ui/lint/force-warn/force-warns-cap-lints.rs
Normal file
10
src/test/ui/lint/force-warn/force-warns-cap-lints.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
// compile-flags: --cap-lints allow --force-warns bare_trait_objects -Zunstable-options
|
||||||
|
// check-pass
|
||||||
|
|
||||||
|
pub trait SomeTrait {}
|
||||||
|
|
||||||
|
pub fn function(_x: Box<SomeTrait>) {}
|
||||||
|
//~^ WARN trait objects without an explicit `dyn` are deprecated
|
||||||
|
//~| WARN this is accepted in the current edition
|
||||||
|
|
||||||
|
fn main() {}
|
12
src/test/ui/lint/force-warn/force-warns-cap-lints.stderr
Normal file
12
src/test/ui/lint/force-warn/force-warns-cap-lints.stderr
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
warning: trait objects without an explicit `dyn` are deprecated
|
||||||
|
--> $DIR/force-warns-cap-lints.rs:6:25
|
||||||
|
|
|
||||||
|
LL | pub fn function(_x: Box<SomeTrait>) {}
|
||||||
|
| ^^^^^^^^^ help: use `dyn`: `dyn SomeTrait`
|
||||||
|
|
|
||||||
|
= note: requested on the command line with `--force-warns bare-trait-objects`
|
||||||
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
|
||||||
|
= note: for more information, see issue #80165 <https://github.com/rust-lang/rust/issues/80165>
|
||||||
|
|
||||||
|
warning: 1 warning emitted
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue