From 5d5e451618d3f364ce4a19d1d2c4f8903bc30dde Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Sun, 21 Aug 2022 14:58:42 +0400 Subject: [PATCH] recover `const Tr` bounds (no `~`) --- compiler/rustc_parse/src/parser/ty.rs | 14 ++++++++++++++ .../ui/rfc-2632-const-trait-impl/without-tilde.rs | 3 +-- .../rfc-2632-const-trait-impl/without-tilde.stderr | 14 +++++--------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index b76ba8ff2d9..298198f2cf7 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -809,6 +809,20 @@ impl<'a> Parser<'a> { self.expect_keyword(kw::Const)?; let span = tilde.to(self.prev_token.span); self.sess.gated_spans.gate(sym::const_trait_impl, span); + Some(span) + } else if self.eat_keyword(kw::Const) { + let span = self.prev_token.span; + self.sess.gated_spans.gate(sym::const_trait_impl, span); + + self.struct_span_err(span, "const bounds must start with `~`") + .span_suggestion( + span.shrink_to_lo(), + "add `~`", + "~", + Applicability::MachineApplicable, + ) + .emit(); + Some(span) } else { None diff --git a/src/test/ui/rfc-2632-const-trait-impl/without-tilde.rs b/src/test/ui/rfc-2632-const-trait-impl/without-tilde.rs index e0d3e0b497b..d63381b5f2c 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/without-tilde.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/without-tilde.rs @@ -3,5 +3,4 @@ #![feature(const_trait_impl)] struct S; -//~^ ERROR expected identifier, found keyword `const` -//~| ERROR expected one of `(`, `+`, `,`, `::`, `<`, `=`, or `>`, found `Tr` +//~^ ERROR const bounds must start with `~` diff --git a/src/test/ui/rfc-2632-const-trait-impl/without-tilde.stderr b/src/test/ui/rfc-2632-const-trait-impl/without-tilde.stderr index 243f0979509..31300354a57 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/without-tilde.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/without-tilde.stderr @@ -1,14 +1,10 @@ -error: expected identifier, found keyword `const` +error: const bounds must start with `~` --> $DIR/without-tilde.rs:5:13 | LL | struct S; - | ^^^^^ expected identifier, found keyword + | -^^^^ + | | + | help: add `~`: `~` -error: expected one of `(`, `+`, `,`, `::`, `<`, `=`, or `>`, found `Tr` - --> $DIR/without-tilde.rs:5:19 - | -LL | struct S; - | ^^ expected one of 7 possible tokens - -error: aborting due to 2 previous errors +error: aborting due to previous error