Skip to content

Commit 58f5a01

Browse files
committed
Auto merge of #103020 - lyming2007:issue-102598-fix, r=jackh726
error parsing lifetime following by Sized and message + between them Fixes #102598
2 parents 88c58e3 + 419df5f commit 58f5a01

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

compiler/rustc_parse/src/parser/item.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2464,7 +2464,6 @@ impl<'a> Parser<'a> {
24642464
};
24652465
let (pat, ty) = if is_name_required || this.is_named_param() {
24662466
debug!("parse_param_general parse_pat (is_name_required:{})", is_name_required);
2467-
24682467
let (pat, colon) = this.parse_fn_param_pat_colon()?;
24692468
if !colon {
24702469
let mut err = this.unexpected::<()>().unwrap_err();

compiler/rustc_parse/src/parser/ty.rs

+19
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,25 @@ impl<'a> Parser<'a> {
613613
/// Parses an `impl B0 + ... + Bn` type.
614614
fn parse_impl_ty(&mut self, impl_dyn_multi: &mut bool) -> PResult<'a, TyKind> {
615615
// Always parse bounds greedily for better error recovery.
616+
if self.token.is_lifetime() {
617+
self.look_ahead(1, |t| {
618+
if let token::Ident(symname, _) = t.kind {
619+
// parse pattern with "'a Sized" we're supposed to give suggestion like
620+
// "'a + Sized"
621+
self.struct_span_err(
622+
self.token.span,
623+
&format!("expected `+` between lifetime and {}", symname),
624+
)
625+
.span_suggestion_verbose(
626+
self.token.span.shrink_to_hi(),
627+
"add `+`",
628+
" +",
629+
Applicability::MaybeIncorrect,
630+
)
631+
.emit();
632+
}
633+
})
634+
}
616635
let bounds = self.parse_generic_bounds(None)?;
617636
*impl_dyn_multi = bounds.len() > 1 || self.prev_token.kind == TokenKind::BinOp(token::Plus);
618637
Ok(TyKind::ImplTrait(ast::DUMMY_NODE_ID, bounds))

src/test/ui/type/issue-102598.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn foo<'a>(_: impl 'a Sized) {}
2+
//~^ ERROR: expected `+` between lifetime and Sized
3+
//~| ERROR: expected one of `:`, `@`, or `|`, found `)`
4+
//~| ERROR: expected one of `)`, `+`, or `,`, found `Sized`
5+
//~| ERROR: at least one trait must be specified
6+
7+
fn main(){
8+
}

src/test/ui/type/issue-102598.stderr

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
error: expected `+` between lifetime and Sized
2+
--> $DIR/issue-102598.rs:1:20
3+
|
4+
LL | fn foo<'a>(_: impl 'a Sized) {}
5+
| ^^
6+
|
7+
help: add `+`
8+
|
9+
LL | fn foo<'a>(_: impl 'a + Sized) {}
10+
| +
11+
12+
error: expected one of `:`, `@`, or `|`, found `)`
13+
--> $DIR/issue-102598.rs:1:28
14+
|
15+
LL | fn foo<'a>(_: impl 'a Sized) {}
16+
| ^ expected one of `:`, `@`, or `|`
17+
|
18+
= note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
19+
help: if this is a parameter name, give it a type
20+
|
21+
LL | fn foo<'a>(_: impl 'a Sized: TypeName) {}
22+
| ++++++++++
23+
help: if this is a type, explicitly ignore the parameter name
24+
|
25+
LL | fn foo<'a>(_: impl 'a _: Sized) {}
26+
| ++
27+
28+
error: expected one of `)`, `+`, or `,`, found `Sized`
29+
--> $DIR/issue-102598.rs:1:23
30+
|
31+
LL | fn foo<'a>(_: impl 'a Sized) {}
32+
| -^^^^^ expected one of `)`, `+`, or `,`
33+
| |
34+
| help: missing `,`
35+
36+
error: at least one trait must be specified
37+
--> $DIR/issue-102598.rs:1:15
38+
|
39+
LL | fn foo<'a>(_: impl 'a Sized) {}
40+
| ^^^^^^^
41+
42+
error: aborting due to 4 previous errors
43+

0 commit comments

Comments
 (0)