Skip to content

Commit dcd30a4

Browse files
committed
hygiene: Fix wording of desugaring descriptions
Use variant names rather than descriptions for identifying desugarings in `#[rustc_on_unimplemented]`. Both are highly unstable, but variant name is at least a single identifier.
1 parent 99c7432 commit dcd30a4

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

src/doc/unstable-book/src/language-features/on-unimplemented.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ application of these fields based on a variety of attributes when using
9898
`crate_local`) or matching against a particular method. Currently used
9999
for `try`.
100100
- `from_desugaring`: usable both as boolean (whether the flag is present)
101-
or matching against a particular desugaring.
101+
or matching against a particular desugaring. The desugaring is identified
102+
with its variant name in the `DesugaringKind` enum.
102103

103104
For example, the `Iterator` trait can be annotated in the following way:
104105

src/libcore/ops/try.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
#[rustc_on_unimplemented(
99
on(all(
1010
any(from_method="from_error", from_method="from_ok"),
11-
from_desugaring="?"),
11+
from_desugaring="QuestionMark"),
1212
message="the `?` operator can only be used in a \
1313
function that returns `Result` or `Option` \
1414
(or another type that implements `{Try}`)",
1515
label="cannot use the `?` operator in a function that returns `{Self}`"),
16-
on(all(from_method="into_result", from_desugaring="?"),
16+
on(all(from_method="into_result", from_desugaring="QuestionMark"),
1717
message="the `?` operator can only be applied to values \
1818
that implement `{Try}`",
1919
label="the `?` operator cannot be applied to type `{Self}`")

src/librustc/traits/error_reporting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
372372

373373
if let Some(k) = obligation.cause.span.desugaring_kind() {
374374
flags.push((sym::from_desugaring, None));
375-
flags.push((sym::from_desugaring, Some(k.descr().to_string())));
375+
flags.push((sym::from_desugaring, Some(format!("{:?}", k))));
376376
}
377377
let generics = self.tcx.generics_of(def_id);
378378
let self_ty = trait_ref.self_ty();

src/libsyntax_pos/hygiene.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -734,15 +734,16 @@ pub enum DesugaringKind {
734734
}
735735

736736
impl DesugaringKind {
737-
pub fn descr(self) -> &'static str {
737+
/// The description wording should combine well with "desugaring of {}".
738+
fn descr(self) -> &'static str {
738739
match self {
739-
DesugaringKind::CondTemporary => "if and while condition",
740-
DesugaringKind::Async => "async",
741-
DesugaringKind::Await => "await",
742-
DesugaringKind::QuestionMark => "?",
743-
DesugaringKind::TryBlock => "try block",
744-
DesugaringKind::ExistentialType => "existential type",
745-
DesugaringKind::ForLoop => "for loop",
740+
DesugaringKind::CondTemporary => "`if` or `while` condition",
741+
DesugaringKind::Async => "`async` block or function",
742+
DesugaringKind::Await => "`await` expression",
743+
DesugaringKind::QuestionMark => "operator `?`",
744+
DesugaringKind::TryBlock => "`try` block",
745+
DesugaringKind::ExistentialType => "`existential type`",
746+
DesugaringKind::ForLoop => "`for` loop",
746747
}
747748
}
748749
}

src/libsyntax_pos/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ impl Span {
442442
// Don't print recursive invocations.
443443
if !info.call_site.source_equal(&prev_span) {
444444
let (pre, post) = match info.kind {
445-
ExpnKind::Desugaring(..) => ("desugaring of `", "`"),
445+
ExpnKind::Desugaring(..) => ("desugaring of ", ""),
446446
ExpnKind::Macro(macro_kind, _) => match macro_kind {
447447
MacroKind::Bang => ("", "!"),
448448
MacroKind::Attr => ("#[", "]"),

0 commit comments

Comments
 (0)