error parsing lifetime following by Sized and message + between them
detect the pattern at the general site parse_impl_ty() this will fix #102598
This commit is contained in:
parent
37d7de3379
commit
419df5f4a0
4 changed files with 70 additions and 1 deletions
|
@ -2449,7 +2449,6 @@ impl<'a> Parser<'a> {
|
||||||
};
|
};
|
||||||
let (pat, ty) = if is_name_required || this.is_named_param() {
|
let (pat, ty) = if is_name_required || this.is_named_param() {
|
||||||
debug!("parse_param_general parse_pat (is_name_required:{})", is_name_required);
|
debug!("parse_param_general parse_pat (is_name_required:{})", is_name_required);
|
||||||
|
|
||||||
let (pat, colon) = this.parse_fn_param_pat_colon()?;
|
let (pat, colon) = this.parse_fn_param_pat_colon()?;
|
||||||
if !colon {
|
if !colon {
|
||||||
let mut err = this.unexpected::<()>().unwrap_err();
|
let mut err = this.unexpected::<()>().unwrap_err();
|
||||||
|
|
|
@ -613,6 +613,25 @@ impl<'a> Parser<'a> {
|
||||||
/// Parses an `impl B0 + ... + Bn` type.
|
/// Parses an `impl B0 + ... + Bn` type.
|
||||||
fn parse_impl_ty(&mut self, impl_dyn_multi: &mut bool) -> PResult<'a, TyKind> {
|
fn parse_impl_ty(&mut self, impl_dyn_multi: &mut bool) -> PResult<'a, TyKind> {
|
||||||
// Always parse bounds greedily for better error recovery.
|
// Always parse bounds greedily for better error recovery.
|
||||||
|
if self.token.is_lifetime() {
|
||||||
|
self.look_ahead(1, |t| {
|
||||||
|
if let token::Ident(symname, _) = t.kind {
|
||||||
|
// parse pattern with "'a Sized" we're supposed to give suggestion like
|
||||||
|
// "'a + Sized"
|
||||||
|
self.struct_span_err(
|
||||||
|
self.token.span,
|
||||||
|
&format!("expected `+` between lifetime and {}", symname),
|
||||||
|
)
|
||||||
|
.span_suggestion_verbose(
|
||||||
|
self.token.span.shrink_to_hi(),
|
||||||
|
"add `+`",
|
||||||
|
" +",
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
)
|
||||||
|
.emit();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
let bounds = self.parse_generic_bounds(None)?;
|
let bounds = self.parse_generic_bounds(None)?;
|
||||||
*impl_dyn_multi = bounds.len() > 1 || self.prev_token.kind == TokenKind::BinOp(token::Plus);
|
*impl_dyn_multi = bounds.len() > 1 || self.prev_token.kind == TokenKind::BinOp(token::Plus);
|
||||||
Ok(TyKind::ImplTrait(ast::DUMMY_NODE_ID, bounds))
|
Ok(TyKind::ImplTrait(ast::DUMMY_NODE_ID, bounds))
|
||||||
|
|
8
src/test/ui/type/issue-102598.rs
Normal file
8
src/test/ui/type/issue-102598.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
fn foo<'a>(_: impl 'a Sized) {}
|
||||||
|
//~^ ERROR: expected `+` between lifetime and Sized
|
||||||
|
//~| ERROR: expected one of `:`, `@`, or `|`, found `)`
|
||||||
|
//~| ERROR: expected one of `)`, `+`, or `,`, found `Sized`
|
||||||
|
//~| ERROR: at least one trait must be specified
|
||||||
|
|
||||||
|
fn main(){
|
||||||
|
}
|
43
src/test/ui/type/issue-102598.stderr
Normal file
43
src/test/ui/type/issue-102598.stderr
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
error: expected `+` between lifetime and Sized
|
||||||
|
--> $DIR/issue-102598.rs:1:20
|
||||||
|
|
|
||||||
|
LL | fn foo<'a>(_: impl 'a Sized) {}
|
||||||
|
| ^^
|
||||||
|
|
|
||||||
|
help: add `+`
|
||||||
|
|
|
||||||
|
LL | fn foo<'a>(_: impl 'a + Sized) {}
|
||||||
|
| +
|
||||||
|
|
||||||
|
error: expected one of `:`, `@`, or `|`, found `)`
|
||||||
|
--> $DIR/issue-102598.rs:1:28
|
||||||
|
|
|
||||||
|
LL | fn foo<'a>(_: impl 'a Sized) {}
|
||||||
|
| ^ expected one of `:`, `@`, or `|`
|
||||||
|
|
|
||||||
|
= note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
|
||||||
|
help: if this is a parameter name, give it a type
|
||||||
|
|
|
||||||
|
LL | fn foo<'a>(_: impl 'a Sized: TypeName) {}
|
||||||
|
| ++++++++++
|
||||||
|
help: if this is a type, explicitly ignore the parameter name
|
||||||
|
|
|
||||||
|
LL | fn foo<'a>(_: impl 'a _: Sized) {}
|
||||||
|
| ++
|
||||||
|
|
||||||
|
error: expected one of `)`, `+`, or `,`, found `Sized`
|
||||||
|
--> $DIR/issue-102598.rs:1:23
|
||||||
|
|
|
||||||
|
LL | fn foo<'a>(_: impl 'a Sized) {}
|
||||||
|
| -^^^^^ expected one of `)`, `+`, or `,`
|
||||||
|
| |
|
||||||
|
| help: missing `,`
|
||||||
|
|
||||||
|
error: at least one trait must be specified
|
||||||
|
--> $DIR/issue-102598.rs:1:15
|
||||||
|
|
|
||||||
|
LL | fn foo<'a>(_: impl 'a Sized) {}
|
||||||
|
| ^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 4 previous errors
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue