Skip to content
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

Rollup of 5 pull requests #100868

Merged
merged 28 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
85a9c74
Add tests that check `Vec::retain` predicate execution order.
AngelicosPhosphoros Jul 17, 2022
c6558c0
Recover keywords in bounds
WaffleLapkin Jul 29, 2022
798016c
add a silly test for keywords in trait bounds recovery
WaffleLapkin Jul 29, 2022
c198a20
Catch overflow early
ouz-a Aug 19, 2022
4b47686
Update issue-83150.stderr
ouz-a Aug 19, 2022
17ddcb4
Improve primitive/std docs separation and headers
camsteffen Apr 30, 2022
5d5e451
recover `const Tr` bounds (no `~`)
WaffleLapkin Aug 21, 2022
d6fdf14
Migrate forbidden_let
finalchild Aug 17, 2022
80451de
Use DiagnosticMessage for BufferedEarlyLint.msg
finalchild Aug 17, 2022
e144a23
Migrate deprecated_where_clause_location, forbidden_assoc_constraint,…
finalchild Aug 17, 2022
88afae5
Tidy
finalchild Aug 18, 2022
e3d4c40
Migrate trait_fn_async
finalchild Aug 18, 2022
8d042f4
Migrate trait_fn_const
finalchild Aug 18, 2022
269c853
Migrate forbidden_lifetime_bound, forbidden_non_lifetime_param, too_m…
finalchild Aug 18, 2022
c6903c0
Migrate doc_comment_on_fn_param, forbidden_attr_on_fn_param
finalchild Aug 18, 2022
07e0bc9
Rename c_var_args_without_named_arg to c_var_args_is_sole_param
finalchild Aug 18, 2022
bfefefb
Migrate fn_param_forbidden_self and rename others to have prefix fn_p…
finalchild Aug 18, 2022
b28cc09
Support #[fatal(..)]
finalchild Aug 18, 2022
8ed8aac
Fix `build_format` not unescaping braces properly
finalchild Aug 18, 2022
e331ae5
Migrate forbidden_default and *_without_body
finalchild Aug 18, 2022
6a34074
Remove redundant clone
finalchild Aug 18, 2022
70e0af6
Fix incorrect return type of emit_fatal
finalchild Aug 20, 2022
09d495c
Replace #[error(..)] etc. to #[diag(..)]
finalchild Aug 21, 2022
a4950ef
Rollup merge of #93162 - camsteffen:std-prim-docs, r=Mark-Simulacrum
Dylan-DPC Aug 22, 2022
33b5ce6
Rollup merge of #99386 - AngelicosPhosphoros:add_retain_test_maybeuni…
Dylan-DPC Aug 22, 2022
3842117
Rollup merge of #99915 - WaffleLapkin:recover_keyword_bounds, r=compi…
Dylan-DPC Aug 22, 2022
57e521e
Rollup merge of #100694 - finalchild:ast-passes-diag, r=TaKO8Ki
Dylan-DPC Aug 22, 2022
88e39b2
Rollup merge of #100757 - ouz-a:issue-95134, r=jackh726
Dylan-DPC Aug 22, 2022
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
22 changes: 21 additions & 1 deletion compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,13 @@ impl<'a> Parser<'a> {
let mut bounds = Vec::new();
let mut negative_bounds = Vec::new();

while self.can_begin_bound() || self.token.is_keyword(kw::Dyn) {
while self.can_begin_bound()
// Continue even if we find a keyword.
// This is necessary for error recover on, for example, `impl fn()`.
//
// The only keyword that can go after generic bounds is `where`, so stop if it's it.
|| (self.token.is_reserved_ident() && !self.token.is_keyword(kw::Where))
{
if self.token.is_keyword(kw::Dyn) {
// Account for `&dyn Trait + dyn Other`.
self.struct_span_err(self.token.span, "invalid `dyn` keyword")
Expand Down Expand Up @@ -803,6 +809,20 @@ impl<'a> Parser<'a> {
self.expect_keyword(kw::Const)?;
let span = tilde.to(self.prev_token.span);
self.sess.gated_spans.gate(sym::const_trait_impl, span);
Some(span)
} else if self.eat_keyword(kw::Const) {
let span = self.prev_token.span;
self.sess.gated_spans.gate(sym::const_trait_impl, span);

self.struct_span_err(span, "const bounds must start with `~`")
.span_suggestion(
span.shrink_to_lo(),
"add `~`",
"~",
Applicability::MachineApplicable,
)
.emit();

Some(span)
} else {
None
Expand Down
47 changes: 47 additions & 0 deletions src/test/ui/parser/kw-in-trait-bounds.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// edition:2018

fn _f<F: fn(), G>(_: impl fn(), _: &dyn fn())
//~^ ERROR expected identifier, found keyword `fn`
//~| ERROR expected identifier, found keyword `fn`
//~| ERROR expected identifier, found keyword `fn`
//~| ERROR cannot find trait `r#fn` in this scope
//~| ERROR cannot find trait `r#fn` in this scope
//~| ERROR cannot find trait `r#fn` in this scope
//~| HELP a trait with a similar name exists
//~| HELP a trait with a similar name exists
//~| HELP a trait with a similar name exists
//~| HELP escape `fn` to use it as an identifier
//~| HELP escape `fn` to use it as an identifier
//~| HELP escape `fn` to use it as an identifier
where
G: fn(),
//~^ ERROR expected identifier, found keyword `fn`
//~| ERROR cannot find trait `r#fn` in this scope
//~| HELP a trait with a similar name exists
//~| HELP escape `fn` to use it as an identifier
{}

fn _g<A: struct, B>(_: impl struct, _: &dyn struct)
//~^ ERROR expected identifier, found keyword `struct`
//~| ERROR expected identifier, found keyword `struct`
//~| ERROR expected identifier, found keyword `struct`
//~| ERROR cannot find trait `r#struct` in this scope
//~| ERROR cannot find trait `r#struct` in this scope
//~| ERROR cannot find trait `r#struct` in this scope
//~| HELP a trait with a similar name exists
//~| HELP a trait with a similar name exists
//~| HELP a trait with a similar name exists
//~| HELP escape `struct` to use it as an identifier
//~| HELP escape `struct` to use it as an identifier
//~| HELP escape `struct` to use it as an identifier
where
B: struct,
//~^ ERROR expected identifier, found keyword `struct`
//~| ERROR cannot find trait `r#struct` in this scope
//~| HELP a trait with a similar name exists
//~| HELP escape `struct` to use it as an identifier
{}

trait Struct {}

fn main() {}
171 changes: 171 additions & 0 deletions src/test/ui/parser/kw-in-trait-bounds.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
error: expected identifier, found keyword `fn`
--> $DIR/kw-in-trait-bounds.rs:3:10
|
LL | fn _f<F: fn(), G>(_: impl fn(), _: &dyn fn())
| ^^ expected identifier, found keyword
|
help: escape `fn` to use it as an identifier
|
LL | fn _f<F: r#fn(), G>(_: impl fn(), _: &dyn fn())
| ++

error: expected identifier, found keyword `fn`
--> $DIR/kw-in-trait-bounds.rs:3:27
|
LL | fn _f<F: fn(), G>(_: impl fn(), _: &dyn fn())
| ^^ expected identifier, found keyword
|
help: escape `fn` to use it as an identifier
|
LL | fn _f<F: fn(), G>(_: impl r#fn(), _: &dyn fn())
| ++

error: expected identifier, found keyword `fn`
--> $DIR/kw-in-trait-bounds.rs:3:41
|
LL | fn _f<F: fn(), G>(_: impl fn(), _: &dyn fn())
| ^^ expected identifier, found keyword
|
help: escape `fn` to use it as an identifier
|
LL | fn _f<F: fn(), G>(_: impl fn(), _: &dyn r#fn())
| ++

error: expected identifier, found keyword `fn`
--> $DIR/kw-in-trait-bounds.rs:17:4
|
LL | G: fn(),
| ^^ expected identifier, found keyword
|
help: escape `fn` to use it as an identifier
|
LL | G: r#fn(),
| ++

error: expected identifier, found keyword `struct`
--> $DIR/kw-in-trait-bounds.rs:24:10
|
LL | fn _g<A: struct, B>(_: impl struct, _: &dyn struct)
| ^^^^^^ expected identifier, found keyword
|
help: escape `struct` to use it as an identifier
|
LL | fn _g<A: r#struct, B>(_: impl struct, _: &dyn struct)
| ++

error: expected identifier, found keyword `struct`
--> $DIR/kw-in-trait-bounds.rs:24:29
|
LL | fn _g<A: struct, B>(_: impl struct, _: &dyn struct)
| ^^^^^^ expected identifier, found keyword
|
help: escape `struct` to use it as an identifier
|
LL | fn _g<A: struct, B>(_: impl r#struct, _: &dyn struct)
| ++

error: expected identifier, found keyword `struct`
--> $DIR/kw-in-trait-bounds.rs:24:45
|
LL | fn _g<A: struct, B>(_: impl struct, _: &dyn struct)
| ^^^^^^ expected identifier, found keyword
|
help: escape `struct` to use it as an identifier
|
LL | fn _g<A: struct, B>(_: impl struct, _: &dyn r#struct)
| ++

error: expected identifier, found keyword `struct`
--> $DIR/kw-in-trait-bounds.rs:38:8
|
LL | B: struct,
| ^^^^^^ expected identifier, found keyword
|
help: escape `struct` to use it as an identifier
|
LL | B: r#struct,
| ++

error[E0405]: cannot find trait `r#fn` in this scope
--> $DIR/kw-in-trait-bounds.rs:3:10
|
LL | fn _f<F: fn(), G>(_: impl fn(), _: &dyn fn())
| ^^ help: a trait with a similar name exists (notice the capitalization): `Fn`
|
::: $SRC_DIR/core/src/ops/function.rs:LL:COL
|
LL | pub trait Fn<Args>: FnMut<Args> {
| ------------------------------- similarly named trait `Fn` defined here

error[E0405]: cannot find trait `r#fn` in this scope
--> $DIR/kw-in-trait-bounds.rs:17:4
|
LL | G: fn(),
| ^^ help: a trait with a similar name exists (notice the capitalization): `Fn`
|
::: $SRC_DIR/core/src/ops/function.rs:LL:COL
|
LL | pub trait Fn<Args>: FnMut<Args> {
| ------------------------------- similarly named trait `Fn` defined here

error[E0405]: cannot find trait `r#fn` in this scope
--> $DIR/kw-in-trait-bounds.rs:3:27
|
LL | fn _f<F: fn(), G>(_: impl fn(), _: &dyn fn())
| ^^ help: a trait with a similar name exists (notice the capitalization): `Fn`
|
::: $SRC_DIR/core/src/ops/function.rs:LL:COL
|
LL | pub trait Fn<Args>: FnMut<Args> {
| ------------------------------- similarly named trait `Fn` defined here

error[E0405]: cannot find trait `r#fn` in this scope
--> $DIR/kw-in-trait-bounds.rs:3:41
|
LL | fn _f<F: fn(), G>(_: impl fn(), _: &dyn fn())
| ^^ help: a trait with a similar name exists (notice the capitalization): `Fn`
|
::: $SRC_DIR/core/src/ops/function.rs:LL:COL
|
LL | pub trait Fn<Args>: FnMut<Args> {
| ------------------------------- similarly named trait `Fn` defined here

error[E0405]: cannot find trait `r#struct` in this scope
--> $DIR/kw-in-trait-bounds.rs:24:10
|
LL | fn _g<A: struct, B>(_: impl struct, _: &dyn struct)
| ^^^^^^ help: a trait with a similar name exists (notice the capitalization): `Struct`
...
LL | trait Struct {}
| ------------ similarly named trait `Struct` defined here

error[E0405]: cannot find trait `r#struct` in this scope
--> $DIR/kw-in-trait-bounds.rs:38:8
|
LL | B: struct,
| ^^^^^^ help: a trait with a similar name exists (notice the capitalization): `Struct`
...
LL | trait Struct {}
| ------------ similarly named trait `Struct` defined here

error[E0405]: cannot find trait `r#struct` in this scope
--> $DIR/kw-in-trait-bounds.rs:24:29
|
LL | fn _g<A: struct, B>(_: impl struct, _: &dyn struct)
| ^^^^^^ help: a trait with a similar name exists (notice the capitalization): `Struct`
...
LL | trait Struct {}
| ------------ similarly named trait `Struct` defined here

error[E0405]: cannot find trait `r#struct` in this scope
--> $DIR/kw-in-trait-bounds.rs:24:45
|
LL | fn _g<A: struct, B>(_: impl struct, _: &dyn struct)
| ^^^^^^ help: a trait with a similar name exists (notice the capitalization): `Struct`
...
LL | trait Struct {}
| ------------ similarly named trait `Struct` defined here

error: aborting due to 16 previous errors

For more information about this error, try `rustc --explain E0405`.
2 changes: 1 addition & 1 deletion src/test/ui/rfc-2632-const-trait-impl/without-tilde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
#![feature(const_trait_impl)]

struct S<T: const Tr>;
//~^ ERROR expected one of `!`, `(`, `,`, `=`, `>`, `?`, `for`, `~`, lifetime, or path
//~^ ERROR const bounds must start with `~`
6 changes: 4 additions & 2 deletions src/test/ui/rfc-2632-const-trait-impl/without-tilde.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
error: expected one of `!`, `(`, `,`, `=`, `>`, `?`, `for`, `~`, lifetime, or path, found keyword `const`
error: const bounds must start with `~`
--> $DIR/without-tilde.rs:5:13
|
LL | struct S<T: const Tr>;
| ^^^^^ expected one of 10 possible tokens
| -^^^^
| |
| help: add `~`: `~`

error: aborting due to previous error