Skip to content
Permalink
Browse files

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.
  • Loading branch information...
petrochenkov committed Jul 7, 2019
1 parent 99c7432 commit dcd30a4b175364ca1ee1efdcae701a23c5ff7d0b
@@ -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:
@@ -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}`")
@@ -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();
@@ -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",
}
}
}
@@ -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 => ("#[", "]"),

0 comments on commit dcd30a4

Please sign in to comment.
You can’t perform that action at this time.