From 5294992984678d7e77889d9fb5f3a6004359da02 Mon Sep 17 00:00:00 2001 From: Camelid Date: Tue, 20 Oct 2020 16:48:04 -0700 Subject: [PATCH 1/9] Suggest adding missing braces in `const` block pattern Previously it would only suggest wrapping the code in braces in regular expressions; now it does it in patterns too. --- compiler/rustc_parse/src/parser/expr.rs | 2 +- compiler/rustc_parse/src/parser/mod.rs | 13 +--- compiler/rustc_parse/src/parser/pat.rs | 4 +- compiler/rustc_parse/src/parser/stmt.rs | 11 +++- .../parser/inline-const-without-block.fixed | 61 +++++++++++++++++++ .../ui/parser/inline-const-without-block.rs | 61 +++++++++++++++++++ .../parser/inline-const-without-block.stderr | 47 ++++++++++++++ .../parser/keyword-const-as-identifier.stderr | 11 +--- 8 files changed, 184 insertions(+), 26 deletions(-) create mode 100644 src/test/ui/parser/inline-const-without-block.fixed create mode 100644 src/test/ui/parser/inline-const-without-block.rs create mode 100644 src/test/ui/parser/inline-const-without-block.stderr diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index b147f42fada25..d96de066f58c0 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1074,7 +1074,7 @@ impl<'a> Parser<'a> { }) } else if self.eat_keyword(kw::Unsafe) { self.parse_block_expr(None, lo, BlockCheckMode::Unsafe(ast::UserProvided), attrs) - } else if self.check_inline_const(0) { + } else if self.eat_keyword(kw::Const) { self.parse_const_block(lo.to(self.token.span)) } else if self.is_do_catch_block() { self.recover_do_catch(attrs) diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 1062000fede9b..f9a7c7363934f 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -552,15 +552,6 @@ impl<'a> Parser<'a> { self.check_or_expected(self.token.can_begin_const_arg(), TokenType::Const) } - fn check_inline_const(&self, dist: usize) -> bool { - self.is_keyword_ahead(dist, &[kw::Const]) - && self.look_ahead(dist + 1, |t| match t.kind { - token::Interpolated(ref nt) => matches!(**nt, token::NtBlock(..)), - token::OpenDelim(DelimToken::Brace) => true, - _ => false, - }) - } - /// Checks to see if the next token is either `+` or `+=`. /// Otherwise returns `false`. fn check_plus(&mut self) -> bool { @@ -897,10 +888,8 @@ impl<'a> Parser<'a> { } } - /// Parses inline const expressions. + /// Parses inline const expressions. The `const` keyword was already eaten. fn parse_const_block(&mut self, span: Span) -> PResult<'a, P> { - self.sess.gated_spans.gate(sym::inline_const, span); - self.eat_keyword(kw::Const); let blk = self.parse_block()?; let anon_const = AnonConst { id: DUMMY_NODE_ID, diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 1da371e0b7294..bb444b93f6738 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -337,8 +337,8 @@ impl<'a> Parser<'a> { let pat = self.parse_pat_with_range_pat(false, None)?; self.sess.gated_spans.gate(sym::box_patterns, lo.to(self.prev_token.span)); PatKind::Box(pat) - } else if self.check_inline_const(0) { - // Parse `const pat` + } else if self.eat_keyword(kw::Const) { + // Parse `const { pat }` let const_expr = self.parse_const_block(lo.to(self.token.span))?; if let Some(re) = self.parse_range_end() { diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 2942747991a1d..ff2f30870962a 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -303,9 +303,14 @@ impl<'a> Parser<'a> { match self.parse_stmt_without_recovery() { // If the next token is an open brace (e.g., `if a b {`), the place- // inside-a-block suggestion would be more likely wrong than right. + // + // But we don't want to trigger this if we just parsed a pattern, + // so this only triggers if the current token is neither `=>` nor `=`. Ok(Some(_)) - if self.look_ahead(1, |t| t == &token::OpenDelim(token::Brace)) - || do_not_suggest_help => {} + if do_not_suggest_help + || (self.token != token::FatArrow + && self.token != token::Eq + && self.look_ahead(1, |t| t == &token::OpenDelim(token::Brace))) => {} Ok(Some(stmt)) => { let stmt_own_line = self.sess.source_map().is_line_before_span_empty(sp); let stmt_span = if stmt_own_line && self.eat(&token::Semi) { @@ -319,7 +324,7 @@ impl<'a> Parser<'a> { stmt_span, "try placing this code inside a block", format!("{{ {} }}", snippet), - // Speculative; has been misleading in the past (#46836). + // Speculative; has been misleading in the past (see #46836). Applicability::MaybeIncorrect, ); } diff --git a/src/test/ui/parser/inline-const-without-block.fixed b/src/test/ui/parser/inline-const-without-block.fixed new file mode 100644 index 0000000000000..c70dde0311a1f --- /dev/null +++ b/src/test/ui/parser/inline-const-without-block.fixed @@ -0,0 +1,61 @@ +// run-rustfix + +// See issue #78168. + +#![allow(incomplete_features)] +#![feature(inline_const)] + +// FIXME(#78171): the lint has to be allowed because of a bug +#[allow(dead_code)] +const fn one() -> i32 { + 1 +} + +fn foo() -> i32 { + let x = 2; + + match x { + const { 2 } => {} + //~^ ERROR expected `{`, found `2` + //~| HELP try placing this code inside a block + _ => {} + } + + match x { + const { 1 + 2 * 3 / 4 } => {} + //~^ ERROR expected `{`, found `1` + //~| HELP try placing this code inside a block + _ => {} + } + + match x { + const { one() } => {} + //~^ ERROR expected `{`, found `one` + //~| HELP try placing this code inside a block + _ => {} + } + + x +} + +fn bar() -> i32 { + let x = const { 2 }; + //~^ ERROR expected `{`, found `2` + //~| HELP try placing this code inside a block + + x +} + +fn baz() -> i32 { + let y = const { 1 + 2 * 3 / 4 }; + //~^ ERROR expected `{`, found `1` + //~| HELP try placing this code inside a block + + y +} + +fn main() { + foo(); + bar(); + baz(); +} diff --git a/src/test/ui/parser/inline-const-without-block.rs b/src/test/ui/parser/inline-const-without-block.rs new file mode 100644 index 0000000000000..74ed866cc4bc3 --- /dev/null +++ b/src/test/ui/parser/inline-const-without-block.rs @@ -0,0 +1,61 @@ +// run-rustfix + +// See issue #78168. + +#![allow(incomplete_features)] +#![feature(inline_const)] + +// FIXME(#78171): the lint has to be allowed because of a bug +#[allow(dead_code)] +const fn one() -> i32 { + 1 +} + +fn foo() -> i32 { + let x = 2; + + match x { + const 2 => {} + //~^ ERROR expected `{`, found `2` + //~| HELP try placing this code inside a block + _ => {} + } + + match x { + const 1 + 2 * 3 / 4 => {} + //~^ ERROR expected `{`, found `1` + //~| HELP try placing this code inside a block + _ => {} + } + + match x { + const one() => {} + //~^ ERROR expected `{`, found `one` + //~| HELP try placing this code inside a block + _ => {} + } + + x +} + +fn bar() -> i32 { + let x = const 2; + //~^ ERROR expected `{`, found `2` + //~| HELP try placing this code inside a block + + x +} + +fn baz() -> i32 { + let y = const 1 + 2 * 3 / 4; + //~^ ERROR expected `{`, found `1` + //~| HELP try placing this code inside a block + + y +} + +fn main() { + foo(); + bar(); + baz(); +} diff --git a/src/test/ui/parser/inline-const-without-block.stderr b/src/test/ui/parser/inline-const-without-block.stderr new file mode 100644 index 0000000000000..e418af966023f --- /dev/null +++ b/src/test/ui/parser/inline-const-without-block.stderr @@ -0,0 +1,47 @@ +error: expected `{`, found `2` + --> $DIR/inline-const-without-block.rs:18:15 + | +LL | const 2 => {} + | ^ + | | + | expected `{` + | help: try placing this code inside a block: `{ 2 }` + +error: expected `{`, found `1` + --> $DIR/inline-const-without-block.rs:25:15 + | +LL | const 1 + 2 * 3 / 4 => {} + | ^------------ + | | + | expected `{` + | help: try placing this code inside a block: `{ 1 + 2 * 3 / 4 }` + +error: expected `{`, found `one` + --> $DIR/inline-const-without-block.rs:32:15 + | +LL | const one() => {} + | ^^^-- + | | + | expected `{` + | help: try placing this code inside a block: `{ one() }` + +error: expected `{`, found `2` + --> $DIR/inline-const-without-block.rs:42:19 + | +LL | let x = const 2; + | ^ + | | + | expected `{` + | help: try placing this code inside a block: `{ 2 }` + +error: expected `{`, found `1` + --> $DIR/inline-const-without-block.rs:50:19 + | +LL | let y = const 1 + 2 * 3 / 4; + | ^------------ + | | + | expected `{` + | help: try placing this code inside a block: `{ 1 + 2 * 3 / 4 }` + +error: aborting due to 5 previous errors + diff --git a/src/test/ui/parser/keyword-const-as-identifier.stderr b/src/test/ui/parser/keyword-const-as-identifier.stderr index 45c129960ecef..ad0c9ef422c01 100644 --- a/src/test/ui/parser/keyword-const-as-identifier.stderr +++ b/src/test/ui/parser/keyword-const-as-identifier.stderr @@ -1,13 +1,8 @@ -error: expected identifier, found keyword `const` - --> $DIR/keyword-const-as-identifier.rs:4:9 +error: expected `{`, found `=` + --> $DIR/keyword-const-as-identifier.rs:4:15 | LL | let const = "foo"; - | ^^^^^ expected identifier, found keyword - | -help: you can escape reserved keywords to use them as identifiers - | -LL | let r#const = "foo"; - | ^^^^^^^ + | ^ expected `{` error: aborting due to previous error From f19fc4970172ebb1cc399e5beaad20d3aa93af5f Mon Sep 17 00:00:00 2001 From: Camelid Date: Tue, 20 Oct 2020 19:36:34 -0700 Subject: [PATCH 2/9] Add run-pass test and fix failing test --- src/test/ui/parser/inline-const-pat-let.rs | 30 +++++++++++++++++++ .../ui/parser/keyword-const-as-identifier.rs | 4 +-- .../parser/keyword-const-as-identifier.stderr | 2 +- 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/parser/inline-const-pat-let.rs diff --git a/src/test/ui/parser/inline-const-pat-let.rs b/src/test/ui/parser/inline-const-pat-let.rs new file mode 100644 index 0000000000000..d2a79749d5913 --- /dev/null +++ b/src/test/ui/parser/inline-const-pat-let.rs @@ -0,0 +1,30 @@ +// run-pass + +#![allow(incomplete_features)] +#![feature(inline_const)] + +fn if_let_1() -> i32 { + let x = 2; + const Y: i32 = 3; + + if let const { (Y + 1) / 2 } = x { + x + } else { + 0 + } +} + +fn if_let_2() -> i32 { + let x = 2; + + if let const { 1 + 2 } = x { + const { 1 + 2 } + } else { + 0 + } +} + +fn main() { + assert_eq!(if_let_1(), 2); + assert_eq!(if_let_2(), 0); +} diff --git a/src/test/ui/parser/keyword-const-as-identifier.rs b/src/test/ui/parser/keyword-const-as-identifier.rs index 6a2d926bf5796..27a632a5e78d3 100644 --- a/src/test/ui/parser/keyword-const-as-identifier.rs +++ b/src/test/ui/parser/keyword-const-as-identifier.rs @@ -1,5 +1,3 @@ -// This file was auto-generated using 'src/etc/generate-keyword-tests.py const' - fn main() { - let const = "foo"; //~ error: expected identifier, found keyword `const` + let const = "foo"; //~ ERROR expected `{`, found `=` } diff --git a/src/test/ui/parser/keyword-const-as-identifier.stderr b/src/test/ui/parser/keyword-const-as-identifier.stderr index ad0c9ef422c01..d10a435231548 100644 --- a/src/test/ui/parser/keyword-const-as-identifier.stderr +++ b/src/test/ui/parser/keyword-const-as-identifier.stderr @@ -1,5 +1,5 @@ error: expected `{`, found `=` - --> $DIR/keyword-const-as-identifier.rs:4:15 + --> $DIR/keyword-const-as-identifier.rs:2:15 | LL | let const = "foo"; | ^ expected `{` From 4dbe2ac038d33bfe561e86058ffe1b7629da52a7 Mon Sep 17 00:00:00 2001 From: Camelid Date: Wed, 21 Oct 2020 15:52:38 -0700 Subject: [PATCH 3/9] Re-add mistakenly removed code --- compiler/rustc_parse/src/parser/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index f9a7c7363934f..e0b0d284135eb 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -890,6 +890,8 @@ impl<'a> Parser<'a> { /// Parses inline const expressions. The `const` keyword was already eaten. fn parse_const_block(&mut self, span: Span) -> PResult<'a, P> { + self.sess.gated_spans.gate(sym::inline_const, span); + let blk = self.parse_block()?; let anon_const = AnonConst { id: DUMMY_NODE_ID, From 24fa10f30ba7f7611c91037d49e5ba1cfb222583 Mon Sep 17 00:00:00 2001 From: Camelid Date: Thu, 22 Oct 2020 13:04:59 -0700 Subject: [PATCH 4/9] Update tests --- src/test/ui/parser/keyword-const-as-identifier.rs | 4 +++- .../ui/parser/keyword-const-as-identifier.stderr | 12 +++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/test/ui/parser/keyword-const-as-identifier.rs b/src/test/ui/parser/keyword-const-as-identifier.rs index 27a632a5e78d3..530b0b329084a 100644 --- a/src/test/ui/parser/keyword-const-as-identifier.rs +++ b/src/test/ui/parser/keyword-const-as-identifier.rs @@ -1,3 +1,5 @@ fn main() { - let const = "foo"; //~ ERROR expected `{`, found `=` + let const = "foo"; + //~^ ERROR expected `{`, found `=` + //~| ERROR inline-const is experimental [E0658] } diff --git a/src/test/ui/parser/keyword-const-as-identifier.stderr b/src/test/ui/parser/keyword-const-as-identifier.stderr index d10a435231548..66faae461974e 100644 --- a/src/test/ui/parser/keyword-const-as-identifier.stderr +++ b/src/test/ui/parser/keyword-const-as-identifier.stderr @@ -4,5 +4,15 @@ error: expected `{`, found `=` LL | let const = "foo"; | ^ expected `{` -error: aborting due to previous error +error[E0658]: inline-const is experimental + --> $DIR/keyword-const-as-identifier.rs:2:9 + | +LL | let const = "foo"; + | ^^^^^ + | + = note: see issue #76001 for more information + = help: add `#![feature(inline_const)]` to the crate attributes to enable + +error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0658`. From 4315b853830cbf58f9177c38be22c7f6860dcbcc Mon Sep 17 00:00:00 2001 From: Camelid Date: Sat, 24 Oct 2020 10:46:56 -0700 Subject: [PATCH 5/9] Add back `check_inline_const` Needed for range pattern parsing. --- compiler/rustc_parse/src/parser/mod.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index e0b0d284135eb..c815fa1b2d81a 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -552,6 +552,15 @@ impl<'a> Parser<'a> { self.check_or_expected(self.token.can_begin_const_arg(), TokenType::Const) } + fn check_inline_const(&self, dist: usize) -> bool { + self.is_keyword_ahead(dist, &[kw::Const]) + && self.look_ahead(dist + 1, |t| match t.kind { + token::Interpolated(ref nt) => matches!(**nt, token::NtBlock(..)), + token::OpenDelim(DelimToken::Brace) => true, + _ => false, + }) + } + /// Checks to see if the next token is either `+` or `+=`. /// Otherwise returns `false`. fn check_plus(&mut self) -> bool { From 854f207fa7e8f8d0491f9c4b856a5105fe7144fe Mon Sep 17 00:00:00 2001 From: Camelid Date: Sat, 24 Oct 2020 11:17:31 -0700 Subject: [PATCH 6/9] Update tests --- src/test/ui/parser/issue-66357-unexpected-unreachable.rs | 2 +- src/test/ui/parser/issue-66357-unexpected-unreachable.stderr | 2 +- src/test/ui/parser/keyword-const-as-identifier.stderr | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/ui/parser/issue-66357-unexpected-unreachable.rs b/src/test/ui/parser/issue-66357-unexpected-unreachable.rs index 5ec143fae2344..7b95bc775ba91 100644 --- a/src/test/ui/parser/issue-66357-unexpected-unreachable.rs +++ b/src/test/ui/parser/issue-66357-unexpected-unreachable.rs @@ -13,4 +13,4 @@ fn f() { |[](* } //~^ ERROR expected one of `,` or `:`, found `(` -//~| ERROR expected one of `&`, `(`, `)`, `-`, `...`, `..=`, `..`, `[`, `_`, `box`, `mut`, `ref`, `|`, identifier, or path, found `*` +//~| ERROR expected one of `&`, `(`, `)`, `-`, `...`, `..=`, `..`, `[`, `_`, `box`, `const`, `mut`, `ref`, `|`, identifier, or path, found `*` diff --git a/src/test/ui/parser/issue-66357-unexpected-unreachable.stderr b/src/test/ui/parser/issue-66357-unexpected-unreachable.stderr index c3810999d2395..5549f73920d4f 100644 --- a/src/test/ui/parser/issue-66357-unexpected-unreachable.stderr +++ b/src/test/ui/parser/issue-66357-unexpected-unreachable.stderr @@ -4,7 +4,7 @@ error: expected one of `,` or `:`, found `(` LL | fn f() { |[](* } | ^ expected one of `,` or `:` -error: expected one of `&`, `(`, `)`, `-`, `...`, `..=`, `..`, `[`, `_`, `box`, `mut`, `ref`, `|`, identifier, or path, found `*` +error: expected one of `&`, `(`, `)`, `-`, `...`, `..=`, `..`, `[`, `_`, `box`, `const`, `mut`, `ref`, `|`, identifier, or path, found `*` --> $DIR/issue-66357-unexpected-unreachable.rs:14:14 | LL | fn f() { |[](* } diff --git a/src/test/ui/parser/keyword-const-as-identifier.stderr b/src/test/ui/parser/keyword-const-as-identifier.stderr index 66faae461974e..9cef72fa8f38b 100644 --- a/src/test/ui/parser/keyword-const-as-identifier.stderr +++ b/src/test/ui/parser/keyword-const-as-identifier.stderr @@ -8,7 +8,7 @@ error[E0658]: inline-const is experimental --> $DIR/keyword-const-as-identifier.rs:2:9 | LL | let const = "foo"; - | ^^^^^ + | ^^^^^^^ | = note: see issue #76001 for more information = help: add `#![feature(inline_const)]` to the crate attributes to enable From d6d30cc5824c393f6d8f9409907e99731fbec0fd Mon Sep 17 00:00:00 2001 From: Camelid Date: Sat, 24 Oct 2020 11:47:17 -0700 Subject: [PATCH 7/9] Update another test --- src/test/ui/feature-gate-inline_const.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/feature-gate-inline_const.stderr b/src/test/ui/feature-gate-inline_const.stderr index be2f567155c3d..123b30c84abd5 100644 --- a/src/test/ui/feature-gate-inline_const.stderr +++ b/src/test/ui/feature-gate-inline_const.stderr @@ -2,7 +2,7 @@ error[E0658]: inline-const is experimental --> $DIR/feature-gate-inline_const.rs:2:13 | LL | let _ = const { - | ^^^^^ + | ^^^^^^^ | = note: see issue #76001 for more information = help: add `#![feature(inline_const)]` to the crate attributes to enable From a72f39f4cef671fe651723d13a06898070184d85 Mon Sep 17 00:00:00 2001 From: Camelid Date: Sat, 24 Oct 2020 11:48:36 -0700 Subject: [PATCH 8/9] Fix bug --- compiler/rustc_parse/src/parser/pat.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index bb444b93f6738..a23e5c264e72e 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -754,6 +754,7 @@ impl<'a> Parser<'a> { fn parse_pat_range_end(&mut self) -> PResult<'a, P> { if self.check_inline_const(0) { + self.eat_keyword(kw::Const); self.parse_const_block(self.token.span) } else if self.check_path() { let lo = self.token.span; From d9dfa8978290acd16c5f6ec9a40b6ba9e6d5058f Mon Sep 17 00:00:00 2001 From: Camelid Date: Sat, 24 Oct 2020 12:04:35 -0700 Subject: [PATCH 9/9] Fix span bug --- compiler/rustc_parse/src/parser/expr.rs | 2 +- compiler/rustc_parse/src/parser/pat.rs | 4 ++-- src/test/ui/feature-gate-inline_const.stderr | 2 +- src/test/ui/parser/keyword-const-as-identifier.stderr | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index d96de066f58c0..702aba411c026 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1075,7 +1075,7 @@ impl<'a> Parser<'a> { } else if self.eat_keyword(kw::Unsafe) { self.parse_block_expr(None, lo, BlockCheckMode::Unsafe(ast::UserProvided), attrs) } else if self.eat_keyword(kw::Const) { - self.parse_const_block(lo.to(self.token.span)) + self.parse_const_block(lo.to(self.prev_token.span)) } else if self.is_do_catch_block() { self.recover_do_catch(attrs) } else if self.is_try_block() { diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index a23e5c264e72e..c5303ddcddfe9 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -339,7 +339,7 @@ impl<'a> Parser<'a> { PatKind::Box(pat) } else if self.eat_keyword(kw::Const) { // Parse `const { pat }` - let const_expr = self.parse_const_block(lo.to(self.token.span))?; + let const_expr = self.parse_const_block(lo.to(self.prev_token.span))?; if let Some(re) = self.parse_range_end() { self.parse_pat_range_begin_with(const_expr, re)? @@ -755,7 +755,7 @@ impl<'a> Parser<'a> { fn parse_pat_range_end(&mut self) -> PResult<'a, P> { if self.check_inline_const(0) { self.eat_keyword(kw::Const); - self.parse_const_block(self.token.span) + self.parse_const_block(self.prev_token.span) } else if self.check_path() { let lo = self.token.span; let (qself, path) = if self.eat_lt() { diff --git a/src/test/ui/feature-gate-inline_const.stderr b/src/test/ui/feature-gate-inline_const.stderr index 123b30c84abd5..be2f567155c3d 100644 --- a/src/test/ui/feature-gate-inline_const.stderr +++ b/src/test/ui/feature-gate-inline_const.stderr @@ -2,7 +2,7 @@ error[E0658]: inline-const is experimental --> $DIR/feature-gate-inline_const.rs:2:13 | LL | let _ = const { - | ^^^^^^^ + | ^^^^^ | = note: see issue #76001 for more information = help: add `#![feature(inline_const)]` to the crate attributes to enable diff --git a/src/test/ui/parser/keyword-const-as-identifier.stderr b/src/test/ui/parser/keyword-const-as-identifier.stderr index 9cef72fa8f38b..66faae461974e 100644 --- a/src/test/ui/parser/keyword-const-as-identifier.stderr +++ b/src/test/ui/parser/keyword-const-as-identifier.stderr @@ -8,7 +8,7 @@ error[E0658]: inline-const is experimental --> $DIR/keyword-const-as-identifier.rs:2:9 | LL | let const = "foo"; - | ^^^^^^^ + | ^^^^^ | = note: see issue #76001 for more information = help: add `#![feature(inline_const)]` to the crate attributes to enable