Raise errors on bad rustc_on_unimplemented format strings again
This commit is contained in:
parent
9abaa9d4df
commit
10ec5cbe96
3 changed files with 41 additions and 13 deletions
|
@ -18,7 +18,9 @@ use {rustc_attr_parsing as attr, rustc_hir as hir};
|
|||
use super::{ObligationCauseCode, PredicateObligation};
|
||||
use crate::error_reporting::TypeErrCtxt;
|
||||
use crate::error_reporting::traits::on_unimplemented_condition::{Condition, ConditionOptions};
|
||||
use crate::error_reporting::traits::on_unimplemented_format::{Ctx, FormatArgs, FormatString};
|
||||
use crate::error_reporting::traits::on_unimplemented_format::{
|
||||
Ctx, FormatArgs, FormatString, FormatWarning,
|
||||
};
|
||||
use crate::errors::{
|
||||
EmptyOnClauseInOnUnimplemented, InvalidOnClauseInOnUnimplemented, NoValueInOnUnimplemented,
|
||||
};
|
||||
|
@ -806,9 +808,39 @@ impl<'tcx> OnUnimplementedFormatString {
|
|||
// Warnings about format specifiers, deprecated parameters, wrong parameters etc.
|
||||
// In other words we'd like to let the author know, but we can still try to format the string later
|
||||
Ok(FormatString { warnings, .. }) => {
|
||||
if self.is_diagnostic_namespace_variant {
|
||||
for w in warnings {
|
||||
w.emit_warning(tcx, trait_def_id)
|
||||
}
|
||||
} else {
|
||||
for w in warnings {
|
||||
match w {
|
||||
FormatWarning::UnknownParam { argument_name, span } => {
|
||||
let reported = struct_span_code_err!(
|
||||
tcx.dcx(),
|
||||
span,
|
||||
E0230,
|
||||
"cannot find parameter {} on this trait",
|
||||
argument_name,
|
||||
)
|
||||
.emit();
|
||||
result = Err(reported);
|
||||
}
|
||||
FormatWarning::PositionalArgument { span, .. } => {
|
||||
let reported = struct_span_code_err!(
|
||||
tcx.dcx(),
|
||||
span,
|
||||
E0231,
|
||||
"positional format arguments are not allowed here"
|
||||
)
|
||||
.emit();
|
||||
result = Err(reported);
|
||||
}
|
||||
FormatWarning::InvalidSpecifier { .. }
|
||||
| FormatWarning::FutureIncompat { .. } => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Errors from the underlying `rustc_parse_format::Parser`
|
||||
Err(errors) => {
|
||||
|
|
|
@ -20,7 +20,7 @@ trait BadAnnotation1
|
|||
{}
|
||||
|
||||
#[rustc_on_unimplemented = "Unimplemented trait error on `{Self}` with params `<{A},{B},{C}>`"]
|
||||
//~^ WARNING there is no parameter `C` on trait `BadAnnotation2`
|
||||
//~^ ERROR cannot find parameter C on this trait
|
||||
trait BadAnnotation2<A,B>
|
||||
{}
|
||||
|
||||
|
|
|
@ -11,22 +11,17 @@ LL | #[rustc_on_unimplemented = "message"]
|
|||
LL | #[rustc_on_unimplemented(/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...")]
|
||||
| ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
warning: there is no parameter `C` on trait `BadAnnotation2`
|
||||
error[E0230]: cannot find parameter C on this trait
|
||||
--> $DIR/bad-annotation.rs:22:90
|
||||
|
|
||||
LL | #[rustc_on_unimplemented = "Unimplemented trait error on `{Self}` with params `<{A},{B},{C}>`"]
|
||||
| ^
|
||||
|
|
||||
= help: expect either a generic argument name or `{Self}` as format argument
|
||||
= note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default
|
||||
|
||||
warning: positional format arguments are not allowed here
|
||||
error[E0231]: positional format arguments are not allowed here
|
||||
--> $DIR/bad-annotation.rs:27:90
|
||||
|
|
||||
LL | #[rustc_on_unimplemented = "Unimplemented trait error on `{Self}` with params `<{A},{B},{}>`"]
|
||||
| ^
|
||||
|
|
||||
= help: only named format arguments with the name of one of the generic types are allowed in this context
|
||||
|
||||
error[E0232]: this attribute must have a valid value
|
||||
--> $DIR/bad-annotation.rs:32:26
|
||||
|
@ -82,6 +77,7 @@ LL | #[rustc_on_unimplemented(on(desugared, on(desugared, message="x")), message
|
|||
|
|
||||
= note: eg `#[rustc_on_unimplemented(message="foo")]`
|
||||
|
||||
error: aborting due to 8 previous errors; 2 warnings emitted
|
||||
error: aborting due to 10 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0232`.
|
||||
Some errors have detailed explanations: E0230, E0231, E0232.
|
||||
For more information about an error, try `rustc --explain E0230`.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue