Skip to content

error parsing lifetime following by Sized and message + between them #103020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2449,7 +2449,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