From 7bc8577d99d521ea600ede94f2a8ed3bcd6eb4fb Mon Sep 17 00:00:00 2001 From: Alexis Bourget Date: Tue, 10 Aug 2021 02:00:25 +0200 Subject: [PATCH] Fix broken span and related tests --- compiler/rustc_parse/src/parser/item.rs | 2 +- src/test/ui/parser/duplicate-visibility.rs | 7 +++++-- src/test/ui/parser/duplicate-visibility.stderr | 10 ++++++++-- src/test/ui/parser/issue-87694-misplaced-pub.stderr | 5 +++-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index ece0e6da331..46da8ead549 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1987,7 +1987,7 @@ impl<'a> Parser<'a> { // There was no explicit visibility if matches!(orig_vis.kind, VisibilityKind::Inherited) { err.span_suggestion( - sp, + sp_start.to(self.prev_token.span), &format!("visibility `{}` must come before `{}`", vs, snippet), format!("{} {}", vs, snippet), Applicability::MachineApplicable, diff --git a/src/test/ui/parser/duplicate-visibility.rs b/src/test/ui/parser/duplicate-visibility.rs index 87ba230eab5..3da4dd28b6d 100644 --- a/src/test/ui/parser/duplicate-visibility.rs +++ b/src/test/ui/parser/duplicate-visibility.rs @@ -1,6 +1,9 @@ fn main() {} -extern "C" { +extern "C" { //~ NOTE while parsing this item list starting here pub pub fn foo(); //~^ ERROR expected one of `(`, `async`, `const`, `default`, `extern`, `fn`, `pub`, `unsafe`, or `use`, found keyword `pub` -} + //~| NOTE expected one of 9 possible tokens + //~| HELP there is already a visibility, remove this one + //~| NOTE explicit visibility first seen here +} //~ NOTE the item list ends here diff --git a/src/test/ui/parser/duplicate-visibility.stderr b/src/test/ui/parser/duplicate-visibility.stderr index d9815fc7395..b289f2d0adc 100644 --- a/src/test/ui/parser/duplicate-visibility.stderr +++ b/src/test/ui/parser/duplicate-visibility.stderr @@ -7,10 +7,16 @@ LL | pub pub fn foo(); | ^^^ | | | expected one of 9 possible tokens - | help: visibility `pub` must come before `pub pub`: `pub pub pub` -LL | + | help: there is already a visibility, remove this one +... LL | } | - the item list ends here + | +note: explicit visibility first seen here + --> $DIR/duplicate-visibility.rs:4:5 + | +LL | pub pub fn foo(); + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/parser/issue-87694-misplaced-pub.stderr b/src/test/ui/parser/issue-87694-misplaced-pub.stderr index ac588ad5a77..94c6a29efcb 100644 --- a/src/test/ui/parser/issue-87694-misplaced-pub.stderr +++ b/src/test/ui/parser/issue-87694-misplaced-pub.stderr @@ -2,8 +2,9 @@ error: expected one of `async`, `extern`, `fn`, or `unsafe`, found keyword `pub` --> $DIR/issue-87694-misplaced-pub.rs:1:7 | LL | const pub fn test() {} - | ----- ^^^ expected one of `async`, `extern`, `fn`, or `unsafe` - | | + | ------^^^ + | | | + | | expected one of `async`, `extern`, `fn`, or `unsafe` | help: visibility `pub` must come before `const`: `pub const` error: aborting due to previous error