about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-07-07 13:02:05 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-07-11 00:12:57 +0300
commitdcd30a4b175364ca1ee1efdcae701a23c5ff7d0b (patch)
treebda92f926da4cad9671855d921e773b6aef7225e
parent99c7432896bbfdab1f7f70f8d763cab5f3efe64a (diff)
downloadrust-dcd30a4b175364ca1ee1efdcae701a23c5ff7d0b.tar.gz
rust-dcd30a4b175364ca1ee1efdcae701a23c5ff7d0b.zip
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.
-rw-r--r--src/doc/unstable-book/src/language-features/on-unimplemented.md3
-rw-r--r--src/libcore/ops/try.rs4
-rw-r--r--src/librustc/traits/error_reporting.rs2
-rw-r--r--src/libsyntax_pos/hygiene.rs17
-rw-r--r--src/libsyntax_pos/lib.rs2
5 files changed, 15 insertions, 13 deletions
diff --git a/src/doc/unstable-book/src/language-features/on-unimplemented.md b/src/doc/unstable-book/src/language-features/on-unimplemented.md
index a770ab65c26..8db241e4b4e 100644
--- a/src/doc/unstable-book/src/language-features/on-unimplemented.md
+++ b/src/doc/unstable-book/src/language-features/on-unimplemented.md
@@ -98,7 +98,8 @@ application of these fields based on a variety of attributes when using
    `crate_local`) or matching against a particular method. Currently used
    for `try`.
  - `from_desugaring`: usable both as boolean (whether the flag is present)
-   or matching against a particular desugaring.
+   or matching against a particular desugaring. The desugaring is identified
+   with its variant name in the `DesugaringKind` enum.
 
 For example, the `Iterator` trait can be annotated in the following way:
 
diff --git a/src/libcore/ops/try.rs b/src/libcore/ops/try.rs
index 9fa2c81954e..76fec1020f1 100644
--- a/src/libcore/ops/try.rs
+++ b/src/libcore/ops/try.rs
@@ -8,12 +8,12 @@
 #[rustc_on_unimplemented(
    on(all(
        any(from_method="from_error", from_method="from_ok"),
-       from_desugaring="?"),
+       from_desugaring="QuestionMark"),
       message="the `?` operator can only be used in a \
                function that returns `Result` or `Option` \
                (or another type that implements `{Try}`)",
       label="cannot use the `?` operator in a function that returns `{Self}`"),
-   on(all(from_method="into_result", from_desugaring="?"),
+   on(all(from_method="into_result", from_desugaring="QuestionMark"),
       message="the `?` operator can only be applied to values \
                that implement `{Try}`",
       label="the `?` operator cannot be applied to type `{Self}`")
diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs
index a7dfbd688c1..352d318ba79 100644
--- a/src/librustc/traits/error_reporting.rs
+++ b/src/librustc/traits/error_reporting.rs
@@ -372,7 +372,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
 
         if let Some(k) = obligation.cause.span.desugaring_kind() {
             flags.push((sym::from_desugaring, None));
-            flags.push((sym::from_desugaring, Some(k.descr().to_string())));
+            flags.push((sym::from_desugaring, Some(format!("{:?}", k))));
         }
         let generics = self.tcx.generics_of(def_id);
         let self_ty = trait_ref.self_ty();
diff --git a/src/libsyntax_pos/hygiene.rs b/src/libsyntax_pos/hygiene.rs
index f060bf356f6..b72da042d04 100644
--- a/src/libsyntax_pos/hygiene.rs
+++ b/src/libsyntax_pos/hygiene.rs
@@ -734,15 +734,16 @@ pub enum DesugaringKind {
 }
 
 impl DesugaringKind {
-    pub fn descr(self) -> &'static str {
+    /// The description wording should combine well with "desugaring of {}".
+    fn descr(self) -> &'static str {
         match self {
-            DesugaringKind::CondTemporary => "if and while condition",
-            DesugaringKind::Async => "async",
-            DesugaringKind::Await => "await",
-            DesugaringKind::QuestionMark => "?",
-            DesugaringKind::TryBlock => "try block",
-            DesugaringKind::ExistentialType => "existential type",
-            DesugaringKind::ForLoop => "for loop",
+            DesugaringKind::CondTemporary => "`if` or `while` condition",
+            DesugaringKind::Async => "`async` block or function",
+            DesugaringKind::Await => "`await` expression",
+            DesugaringKind::QuestionMark => "operator `?`",
+            DesugaringKind::TryBlock => "`try` block",
+            DesugaringKind::ExistentialType => "`existential type`",
+            DesugaringKind::ForLoop => "`for` loop",
         }
     }
 }
diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs
index 4fd27ce4f96..9258b71518f 100644
--- a/src/libsyntax_pos/lib.rs
+++ b/src/libsyntax_pos/lib.rs
@@ -442,7 +442,7 @@ impl Span {
             // Don't print recursive invocations.
             if !info.call_site.source_equal(&prev_span) {
                 let (pre, post) = match info.kind {
-                    ExpnKind::Desugaring(..) => ("desugaring of `", "`"),
+                    ExpnKind::Desugaring(..) => ("desugaring of ", ""),
                     ExpnKind::Macro(macro_kind, _) => match macro_kind {
                         MacroKind::Bang => ("", "!"),
                         MacroKind::Attr => ("#[", "]"),