Skip to content

Commit f67a1ac

Browse files
committed
Auto merge of rust-lang#125863 - fmease:rej-CVarArgs-in-parse_ty_for_where_clause, r=compiler-errors
Reject `CVarArgs` in `parse_ty_for_where_clause` Fixes rust-lang#125847. This regressed in rust-lang#77035 where the `parse_ty` inside `parse_ty_where_predicate` was replaced with the at the time new `parse_ty_for_where_clause` which incorrectly stated it would permit CVarArgs (maybe a copy/paste error). r? parser
2 parents 0038c02 + 8938609 commit f67a1ac

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

compiler/rustc_parse/src/parser/ty.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl<'a> Parser<'a> {
194194
pub(super) fn parse_ty_for_where_clause(&mut self) -> PResult<'a, P<Ty>> {
195195
self.parse_ty_common(
196196
AllowPlus::Yes,
197-
AllowCVariadic::Yes,
197+
AllowCVariadic::No,
198198
RecoverQPath::Yes,
199199
RecoverReturnSign::OnlyFatArrow,
200200
None,
@@ -344,8 +344,9 @@ impl<'a> Parser<'a> {
344344
match allow_c_variadic {
345345
AllowCVariadic::Yes => TyKind::CVarArgs,
346346
AllowCVariadic::No => {
347-
// FIXME(Centril): Should we just allow `...` syntactically
347+
// FIXME(c_variadic): Should we just allow `...` syntactically
348348
// anywhere in a type and use semantic restrictions instead?
349+
// NOTE: This may regress certain MBE calls if done incorrectly.
349350
let guar = self
350351
.dcx()
351352
.emit_err(NestedCVariadicType { span: lo.to(self.prev_token.span) });
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// A bare `...` represents `CVarArgs` (`VaListImpl<'_>`) in function argument type
2+
// position without being a proper type syntactically.
3+
// This test ensures that we do not regress certain MBE calls would we ever promote
4+
// `...` to a proper type syntactically.
5+
6+
//@ check-pass
7+
8+
macro_rules! ck { ($ty:ty) => { compile_error!(""); }; (...) => {}; }
9+
ck!(...);
10+
11+
fn main() {}

tests/ui/parser/variadic-ffi-nested-syntactic-fail.rs

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ fn f1<'a>(x: u8, y: &'a ...) {}
44
fn f2<'a>(x: u8, y: Vec<&'a ...>) {}
55
//~^ ERROR C-variadic type `...` may not be nested inside another type
66

7+
// Regression test for issue #125847.
8+
fn f3() where for<> ...: {}
9+
//~^ ERROR C-variadic type `...` may not be nested inside another type
10+
711
fn main() {
812
let _recovery_witness: () = 0;
913
//~^ ERROR: mismatched types

tests/ui/parser/variadic-ffi-nested-syntactic-fail.stderr

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@ error[E0743]: C-variadic type `...` may not be nested inside another type
1010
LL | fn f2<'a>(x: u8, y: Vec<&'a ...>) {}
1111
| ^^^
1212

13+
error[E0743]: C-variadic type `...` may not be nested inside another type
14+
--> $DIR/variadic-ffi-nested-syntactic-fail.rs:8:21
15+
|
16+
LL | fn f3() where for<> ...: {}
17+
| ^^^
18+
1319
error[E0308]: mismatched types
14-
--> $DIR/variadic-ffi-nested-syntactic-fail.rs:8:33
20+
--> $DIR/variadic-ffi-nested-syntactic-fail.rs:12:33
1521
|
1622
LL | let _recovery_witness: () = 0;
1723
| -- ^ expected `()`, found integer
1824
| |
1925
| expected due to this
2026

21-
error: aborting due to 3 previous errors
27+
error: aborting due to 4 previous errors
2228

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

0 commit comments

Comments
 (0)