Skip to content

Commit

Permalink
Auto merge of #103020 - lyming2007:issue-102598-fix, r=jackh726
Browse files Browse the repository at this point in the history
error parsing lifetime following by Sized and message + between them

Fixes #102598
  • Loading branch information
bors committed Dec 26, 2022
2 parents 88c58e3 + 419df5f commit 58f5a01
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
1 change: 0 additions & 1 deletion compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2464,7 +2464,6 @@ impl<'a> Parser<'a> {
};
let (pat, ty) = if is_name_required || this.is_named_param() {
debug!("parse_param_general parse_pat (is_name_required:{})", is_name_required);

let (pat, colon) = this.parse_fn_param_pat_colon()?;
if !colon {
let mut err = this.unexpected::<()>().unwrap_err();
Expand Down
19 changes: 19 additions & 0 deletions compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,25 @@ impl<'a> Parser<'a> {
/// Parses an `impl B0 + ... + Bn` type.
fn parse_impl_ty(&mut self, impl_dyn_multi: &mut bool) -> PResult<'a, TyKind> {
// 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)?;
*impl_dyn_multi = bounds.len() > 1 || self.prev_token.kind == TokenKind::BinOp(token::Plus);
Ok(TyKind::ImplTrait(ast::DUMMY_NODE_ID, bounds))
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/type/issue-102598.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 43 additions & 0 deletions src/test/ui/type/issue-102598.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 58f5a01

Please sign in to comment.