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

Reject CVarArgs in parse_ty_for_where_clause #125863

Merged
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
5 changes: 3 additions & 2 deletions compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl<'a> Parser<'a> {
pub(super) fn parse_ty_for_where_clause(&mut self) -> PResult<'a, P<Ty>> {
self.parse_ty_common(
AllowPlus::Yes,
AllowCVariadic::Yes,
AllowCVariadic::No,
RecoverQPath::Yes,
RecoverReturnSign::OnlyFatArrow,
None,
Expand Down Expand Up @@ -344,8 +344,9 @@ impl<'a> Parser<'a> {
match allow_c_variadic {
AllowCVariadic::Yes => TyKind::CVarArgs,
AllowCVariadic::No => {
// FIXME(Centril): Should we just allow `...` syntactically
// FIXME(c_variadic): Should we just allow `...` syntactically
// anywhere in a type and use semantic restrictions instead?
// NOTE: This may regress certain MBE calls if done incorrectly.
fmease marked this conversation as resolved.
Show resolved Hide resolved
let guar = self
.dcx()
.emit_err(NestedCVariadicType { span: lo.to(self.prev_token.span) });
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/parser/macro/mbe-dotdotdot-may-not-begin-a-type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// A bare `...` represents `CVarArgs` (`VaListImpl<'_>`) in function argument type
// position without being a proper type syntactically.
// This test ensures that we do not regress certain MBE calls would we ever promote
// `...` to a proper type syntactically.

//@ check-pass

macro_rules! ck { ($ty:ty) => { compile_error!(""); }; (...) => {}; }
ck!(...);

fn main() {}
4 changes: 4 additions & 0 deletions tests/ui/parser/variadic-ffi-nested-syntactic-fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ fn f1<'a>(x: u8, y: &'a ...) {}
fn f2<'a>(x: u8, y: Vec<&'a ...>) {}
//~^ ERROR C-variadic type `...` may not be nested inside another type

// Regression test for issue #125847.
fn f3() where for<> ...: {}
//~^ ERROR C-variadic type `...` may not be nested inside another type

fn main() {
let _recovery_witness: () = 0;
//~^ ERROR: mismatched types
Expand Down
10 changes: 8 additions & 2 deletions tests/ui/parser/variadic-ffi-nested-syntactic-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ error[E0743]: C-variadic type `...` may not be nested inside another type
LL | fn f2<'a>(x: u8, y: Vec<&'a ...>) {}
| ^^^

error[E0743]: C-variadic type `...` may not be nested inside another type
--> $DIR/variadic-ffi-nested-syntactic-fail.rs:8:21
|
LL | fn f3() where for<> ...: {}
| ^^^

error[E0308]: mismatched types
--> $DIR/variadic-ffi-nested-syntactic-fail.rs:8:33
--> $DIR/variadic-ffi-nested-syntactic-fail.rs:12:33
|
LL | let _recovery_witness: () = 0;
| -- ^ expected `()`, found integer
| |
| expected due to this

error: aborting due to 3 previous errors
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0308, E0743.
For more information about an error, try `rustc --explain E0308`.
Loading