diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index b47f0c0978381..2a8512acf8cfa 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -397,10 +397,13 @@ impl<'a> Parser<'a> { fn parse_ty_ptr(&mut self) -> PResult<'a, TyKind> { let mutbl = self.parse_const_or_mut().unwrap_or_else(|| { let span = self.prev_token.span; - let msg = "expected mut or const in raw pointer type"; - self.struct_span_err(span, msg) - .span_label(span, msg) - .help("use `*mut T` or `*const T` as appropriate") + self.struct_span_err(span, "expected `mut` or `const` keyword in raw pointer type") + .span_suggestions( + span.shrink_to_hi(), + "add `mut` or `const` here", + ["mut ".to_string(), "const ".to_string()].into_iter(), + Applicability::HasPlaceholders, + ) .emit(); Mutability::Not }); diff --git a/src/test/ui/parser/bad-pointer-type.rs b/src/test/ui/parser/bad-pointer-type.rs index 59e5e0c5d31db..6a82acb4cd6b5 100644 --- a/src/test/ui/parser/bad-pointer-type.rs +++ b/src/test/ui/parser/bad-pointer-type.rs @@ -1,5 +1,5 @@ fn foo(_: *()) { - //~^ ERROR expected mut or const in raw pointer type + //~^ ERROR expected `mut` or `const` keyword in raw pointer type } fn main() {} diff --git a/src/test/ui/parser/bad-pointer-type.stderr b/src/test/ui/parser/bad-pointer-type.stderr index e18c220affe6e..b7225ca887dd4 100644 --- a/src/test/ui/parser/bad-pointer-type.stderr +++ b/src/test/ui/parser/bad-pointer-type.stderr @@ -1,10 +1,15 @@ -error: expected mut or const in raw pointer type +error: expected `mut` or `const` keyword in raw pointer type --> $DIR/bad-pointer-type.rs:1:11 | LL | fn foo(_: *()) { - | ^ expected mut or const in raw pointer type + | ^ | - = help: use `*mut T` or `*const T` as appropriate +help: add `mut` or `const` here + | +LL | fn foo(_: *const ()) { + | +++++ +LL | fn foo(_: *mut ()) { + | +++ error: aborting due to previous error diff --git a/src/test/ui/parser/double-pointer.rs b/src/test/ui/parser/double-pointer.rs new file mode 100644 index 0000000000000..54d34db4a50f4 --- /dev/null +++ b/src/test/ui/parser/double-pointer.rs @@ -0,0 +1,7 @@ +fn main() { + let x: i32 = 5; + let ptr: *const i32 = &x; + let dptr: **const i32 = &ptr; + //~^ ERROR expected `mut` or `const` keyword in raw pointer type + //~| HELP add `mut` or `const` here +} diff --git a/src/test/ui/parser/double-pointer.stderr b/src/test/ui/parser/double-pointer.stderr new file mode 100644 index 0000000000000..28037f9326552 --- /dev/null +++ b/src/test/ui/parser/double-pointer.stderr @@ -0,0 +1,15 @@ +error: expected `mut` or `const` keyword in raw pointer type + --> $DIR/double-pointer.rs:4:15 + | +LL | let dptr: **const i32 = &ptr; + | ^ + | +help: add `mut` or `const` here + | +LL | let dptr: *const *const i32 = &ptr; + | +++++ +LL | let dptr: *mut *const i32 = &ptr; + | +++ + +error: aborting due to previous error +