Skip to content
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
36 changes: 26 additions & 10 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2140,16 +2140,32 @@ impl<'a> Parser<'a> {
let pat = self.parse_pat_no_top_alt(Some(Expected::ArgumentName), None)?;
self.expect(exp!(Colon))?;
let ty = self.parse_ty()?;
self.dcx().emit_err(PatternMethodParamWithoutBody {
span: pat.span,
target: match context {
FnContext::Trait => "methods without bodies",
FnContext::FunctionPtrType => "function pointer types",
FnContext::ParenthesizedArgumentList => "parenthesized argument list",
FnContext::Free => unreachable!("This method is not called in free functions, as patterns are always allowed there"),
FnContext::Impl => unreachable!("This method is not called in impls, as patterns are always allowed there"),
},
});
match context {
FnContext::Trait
| FnContext::FunctionPtrType
| FnContext::ParenthesizedArgumentList => {
self.dcx().emit_err(PatternMethodParamWithoutBody {
span: pat.span,
target: if context == FnContext::Trait {
"methods without bodies"
} else if context == FnContext::FunctionPtrType {
"function pointer types"
} else {
"parenthesized argument list"
},
});
}
FnContext::Free | FnContext::Impl => {
self.dcx().span_delayed_bug(
pat.span,
if context == FnContext::Free {
"This method is not called in free functions, as patterns are always allowed there"
} else {
"This method is not called in impls, as patterns are always allowed there"
},
);
}
}

// Pretend the pattern is `_`, to avoid duplicate errors from AST validation.
let pat = Box::new(Pat { kind: PatKind::Wild, span: pat.span, id: ast::DUMMY_NODE_ID });
Expand Down
2 changes: 0 additions & 2 deletions tests/crashes/160490.rs

This file was deleted.

5 changes: 5 additions & 0 deletions tests/ui/parser/recover-invalid-fn-trait-bound-pattern.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Regression test for https://github.com/rust-lang/rust/issues/160337.

struct Baz where U : fn(() : bool)
//~^ ERROR expected identifier, found keyword `fn`
//~| ERROR expected `{` after struct name, found `<eof>`
20 changes: 20 additions & 0 deletions tests/ui/parser/recover-invalid-fn-trait-bound-pattern.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error: expected identifier, found keyword `fn`
--> $DIR/recover-invalid-fn-trait-bound-pattern.rs:3:22
|
LL | struct Baz where U : fn(() : bool)
| ^^
|
help: use `Fn` to refer to the trait (notice the capitalization)
|
LL - struct Baz where U : fn(() : bool)
LL + struct Baz where U : Fn(() : bool)
|

error: expected `{` after struct name, found `<eof>`
--> $DIR/recover-invalid-fn-trait-bound-pattern.rs:3:34
|
LL | struct Baz where U : fn(() : bool)
| ^ expected `{` after struct name

error: aborting due to 2 previous errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Regression test for https://github.com/rust-lang/rust/issues/160337.

fn main(... : ...)
//~^ ERROR unexpected `...`
//~| ERROR unexpected `...`
//~| ERROR expected one of `->`, `where`, or `{`, found `<eof>`
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
error: unexpected `...`
--> $DIR/recover-invalid-function-parameter-pattern-1.rs:3:9
|
LL | fn main(... : ...)
| ^^^ not a valid pattern
|
help: for a rest pattern, use `..` instead of `...`
|
LL - fn main(... : ...)
LL + fn main(.. : ...)
|

error: unexpected `...`
--> $DIR/recover-invalid-function-parameter-pattern-1.rs:3:15
|
LL | fn main(... : ...)
| ^^^
|
= note: only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list

error: expected one of `->`, `where`, or `{`, found `<eof>`
--> $DIR/recover-invalid-function-parameter-pattern-1.rs:3:18
|
LL | fn main(... : ...)
| ^ expected one of `->`, `where`, or `{`

error: aborting due to 3 previous errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Regression test for https://github.com/rust-lang/rust/issues/160490.

fn f(...: u8) {}
//~^ ERROR unexpected `...`
//~| ERROR missing pattern for `...` argument
//~| WARN this was previously accepted by the compiler

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
error: unexpected `...`
--> $DIR/recover-invalid-function-parameter-pattern-2.rs:3:6
|
LL | fn f(...: u8) {}
| ^^^ not a valid pattern
|
help: for a rest pattern, use `..` instead of `...`
|
LL - fn f(...: u8) {}
LL + fn f(..: u8) {}
|

error: missing pattern for `...` argument
--> $DIR/recover-invalid-function-parameter-pattern-2.rs:3:6
|
LL | fn f(...: u8) {}
| ^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #145544 <https://github.com/rust-lang/rust/issues/145544>
= note: `#[deny(varargs_without_pattern)]` (part of `#[deny(future_incompatible)]`) on by default
help: name the argument, or use `_` to continue ignoring it
|
LL | fn f(_: ...: u8) {}
| ++

error: aborting due to 2 previous errors

Future incompatibility report: Future breakage diagnostic:
error: missing pattern for `...` argument
--> $DIR/recover-invalid-function-parameter-pattern-2.rs:3:6
|
LL | fn f(...: u8) {}
| ^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #145544 <https://github.com/rust-lang/rust/issues/145544>
= note: `#[deny(varargs_without_pattern)]` (part of `#[deny(future_incompatible)]`) on by default
help: name the argument, or use `_` to continue ignoring it
|
LL | fn f(_: ...: u8) {}
| ++

Loading