Skip to content

Commit aad59a3

Browse files
authored
Rollup merge of rust-lang#139091 - mejrs:format, r=compiler-errors
Rewrite on_unimplemented format string parser. This PR rewrites the format string parser for `rustc_on_unimplemented` and `diagnostic::on_unimplemented`. I plan on moving this code (and more) into the new attribute parsing system soon and wanted to PR it separately. This PR introduces some minor differences though: - `rustc_on_unimplemented` on trait *implementations* is no longer checked/used - this is actually never used (outside of some tests) so I plan on removing it in the future. - for `rustc_on_unimplemented`, it introduces the `{This}` argument in favor of `{ThisTraitname}` (to be removed later). It'll be easier to parse. - for `rustc_on_unimplemented`, `Self` can now consistently be used as a filter, rather than just `_Self`. It used to not match correctly on for example `Self = "[{integer}]"` - Some error messages now have better spans. Fixes rust-lang#130627
2 parents 237064a + 4a5369b commit aad59a3

25 files changed

+962
-685
lines changed

Diff for: compiler/rustc_span/src/hygiene.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,25 @@ impl DesugaringKind {
12321232
DesugaringKind::PatTyRange => "pattern type",
12331233
}
12341234
}
1235+
1236+
/// For use with `rustc_unimplemented` to support conditions
1237+
/// like `from_desugaring = "QuestionMark"`
1238+
pub fn matches(&self, value: &str) -> bool {
1239+
match self {
1240+
DesugaringKind::CondTemporary => value == "CondTemporary",
1241+
DesugaringKind::Async => value == "Async",
1242+
DesugaringKind::Await => value == "Await",
1243+
DesugaringKind::QuestionMark => value == "QuestionMark",
1244+
DesugaringKind::TryBlock => value == "TryBlock",
1245+
DesugaringKind::YeetExpr => value == "YeetExpr",
1246+
DesugaringKind::OpaqueTy => value == "OpaqueTy",
1247+
DesugaringKind::ForLoop => value == "ForLoop",
1248+
DesugaringKind::WhileLoop => value == "WhileLoop",
1249+
DesugaringKind::BoundModifier => value == "BoundModifier",
1250+
DesugaringKind::Contract => value == "Contract",
1251+
DesugaringKind::PatTyRange => value == "PatTyRange",
1252+
}
1253+
}
12351254
}
12361255

12371256
#[derive(Default)]

Diff for: compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ symbols! {
372372
SyncUnsafeCell,
373373
T,
374374
Target,
375+
This,
375376
ToOwned,
376377
ToString,
377378
TokenStream,

Diff for: compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ pub mod ambiguity;
22
pub mod call_kind;
33
mod fulfillment_errors;
44
pub mod on_unimplemented;
5+
pub mod on_unimplemented_condition;
6+
pub mod on_unimplemented_format;
57
mod overflow;
68
pub mod suggestions;
79

0 commit comments

Comments
 (0)