Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 32e389c

Browse files
committedMay 1, 2025
Improve coverage of HIR pretty printing.
By taking the existing `expanded-exhaustive.rs` test and running it with both `Zunpretty=expanded` *and* `Zunpretty=hir`.
1 parent 251cda5 commit 32e389c

File tree

4 files changed

+933
-75
lines changed

4 files changed

+933
-75
lines changed
 

‎tests/ui/unpretty/expanded-exhaustive.stdout renamed to ‎tests/ui/unpretty/expanded-exhaustive.expanded.stdout

Lines changed: 16 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
#![feature(prelude_import)]
2-
//@ compile-flags: -Zunpretty=expanded
2+
//@ revisions: expanded hir
3+
//@[expanded]compile-flags: -Zunpretty=expanded
4+
//@[expanded]check-pass
5+
//@[hir]compile-flags: -Zunpretty=hir
6+
//@[hir]check-fail
37
//@ edition:2024
4-
//@ check-pass
8+
//@ only-x86_64-unknown-linux-gnu because of asm!/global_asm! code
9+
10+
// Note: the HIR revision includes a `.stderr` file because there are some
11+
// errors that only occur once we get past the AST.
512

613
#![feature(auto_traits)]
714
#![feature(box_patterns)]
@@ -211,7 +218,10 @@ mod expressions {
211218
}
212219

213220
/// ExprKind::Await
214-
fn expr_await() { let fut; fut.await; }
221+
fn expr_await() {
222+
let fut;
223+
fut.await;
224+
}
215225

216226
/// ExprKind::TryBlock
217227
fn expr_try_block() { try {} try { return; } }
@@ -242,7 +252,9 @@ mod expressions {
242252
}
243253

244254
/// ExprKind::Underscore
245-
fn expr_underscore() { _; }
255+
fn expr_underscore() {
256+
_;
257+
}
246258

247259
/// ExprKind::Path
248260
fn expr_path() {
@@ -300,65 +312,12 @@ mod expressions {
300312

301313

302314

303-
304-
305-
306-
307-
308-
309315
// ...
310316

311317

312318

313319

314320

315-
316-
317-
318-
319-
320-
321-
322-
323-
324-
325-
326-
327-
328-
329-
330-
331-
332-
333-
334-
335-
336-
337-
338-
339-
340-
341-
342-
343-
344-
345-
346-
347-
348-
349-
350-
351-
352-
353-
354-
355-
356-
357-
358-
359-
360-
361-
362321
// concat_idents is deprecated
363322

364323

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
error[E0697]: closures cannot be static
2+
--> $DIR/expanded-exhaustive.rs:212:9
3+
|
4+
LL | static || value;
5+
| ^^^^^^^^^
6+
7+
error[E0697]: closures cannot be static
8+
--> $DIR/expanded-exhaustive.rs:213:9
9+
|
10+
LL | static move || value;
11+
| ^^^^^^^^^^^^^^
12+
13+
error[E0728]: `await` is only allowed inside `async` functions and blocks
14+
--> $DIR/expanded-exhaustive.rs:242:13
15+
|
16+
LL | fn expr_await() {
17+
| --------------- this is not `async`
18+
LL | let fut;
19+
LL | fut.await;
20+
| ^^^^^ only allowed inside `async` functions and blocks
21+
22+
error: in expressions, `_` can only be used on the left-hand side of an assignment
23+
--> $DIR/expanded-exhaustive.rs:291:9
24+
|
25+
LL | _;
26+
| ^ `_` not allowed here
27+
28+
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
29+
--> $DIR/expanded-exhaustive.rs:301:9
30+
|
31+
LL | x::();
32+
| ^^^^^ only `Fn` traits may use parentheses
33+
34+
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
35+
--> $DIR/expanded-exhaustive.rs:302:9
36+
|
37+
LL | x::(T, T) -> T;
38+
| ^^^^^^^^^^^^^^ only `Fn` traits may use parentheses
39+
|
40+
help: use angle brackets instead
41+
|
42+
LL - x::(T, T) -> T;
43+
LL + x::<T, T> -> T;
44+
|
45+
46+
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
47+
--> $DIR/expanded-exhaustive.rs:303:9
48+
|
49+
LL | crate::() -> ()::expressions::() -> ()::expr_path;
50+
| ^^^^^^^^^^^^^^^ only `Fn` traits may use parentheses
51+
52+
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
53+
--> $DIR/expanded-exhaustive.rs:303:26
54+
|
55+
LL | crate::() -> ()::expressions::() -> ()::expr_path;
56+
| ^^^^^^^^^^^^^^^^^^^^^ only `Fn` traits may use parentheses
57+
58+
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
59+
--> $DIR/expanded-exhaustive.rs:306:9
60+
|
61+
LL | core::()::marker::()::PhantomData;
62+
| ^^^^^^^^ only `Fn` traits may use parentheses
63+
64+
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
65+
--> $DIR/expanded-exhaustive.rs:306:19
66+
|
67+
LL | core::()::marker::()::PhantomData;
68+
| ^^^^^^^^^^ only `Fn` traits may use parentheses
69+
70+
error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks
71+
--> $DIR/expanded-exhaustive.rs:404:9
72+
|
73+
LL | yield;
74+
| ^^^^^
75+
|
76+
help: use `#[coroutine]` to make this closure a coroutine
77+
|
78+
LL | #[coroutine] fn expr_yield() {
79+
| ++++++++++++
80+
81+
error[E0703]: invalid ABI: found `C++`
82+
--> $DIR/expanded-exhaustive.rs:484:23
83+
|
84+
LL | unsafe extern "C++" {}
85+
| ^^^^^ invalid ABI
86+
|
87+
= note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions
88+
89+
error: `..` patterns are not allowed here
90+
--> $DIR/expanded-exhaustive.rs:694:13
91+
|
92+
LL | let ..;
93+
| ^^
94+
|
95+
= note: only allowed in tuple, tuple struct, and slice patterns
96+
97+
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
98+
--> $DIR/expanded-exhaustive.rs:809:16
99+
|
100+
LL | let _: T() -> !;
101+
| ^^^^^^^^ only `Fn` traits may use parentheses
102+
103+
error[E0562]: `impl Trait` is not allowed in the type of variable bindings
104+
--> $DIR/expanded-exhaustive.rs:824:16
105+
|
106+
LL | let _: impl Send;
107+
| ^^^^^^^^^
108+
|
109+
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
110+
= note: see issue #63065 <https://github.com/rust-lang/rust/issues/63065> for more information
111+
= help: add `#![feature(impl_trait_in_bindings)]` to the crate attributes to enable
112+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
113+
114+
error[E0562]: `impl Trait` is not allowed in the type of variable bindings
115+
--> $DIR/expanded-exhaustive.rs:825:16
116+
|
117+
LL | let _: impl Send + 'static;
118+
| ^^^^^^^^^^^^^^^^^^^
119+
|
120+
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
121+
= note: see issue #63065 <https://github.com/rust-lang/rust/issues/63065> for more information
122+
= help: add `#![feature(impl_trait_in_bindings)]` to the crate attributes to enable
123+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
124+
125+
error[E0562]: `impl Trait` is not allowed in the type of variable bindings
126+
--> $DIR/expanded-exhaustive.rs:826:16
127+
|
128+
LL | let _: impl 'static + Send;
129+
| ^^^^^^^^^^^^^^^^^^^
130+
|
131+
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
132+
= note: see issue #63065 <https://github.com/rust-lang/rust/issues/63065> for more information
133+
= help: add `#![feature(impl_trait_in_bindings)]` to the crate attributes to enable
134+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
135+
136+
error[E0562]: `impl Trait` is not allowed in the type of variable bindings
137+
--> $DIR/expanded-exhaustive.rs:827:16
138+
|
139+
LL | let _: impl ?Sized;
140+
| ^^^^^^^^^^^
141+
|
142+
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
143+
= note: see issue #63065 <https://github.com/rust-lang/rust/issues/63065> for more information
144+
= help: add `#![feature(impl_trait_in_bindings)]` to the crate attributes to enable
145+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
146+
147+
error[E0562]: `impl Trait` is not allowed in the type of variable bindings
148+
--> $DIR/expanded-exhaustive.rs:828:16
149+
|
150+
LL | let _: impl ~const Clone;
151+
| ^^^^^^^^^^^^^^^^^
152+
|
153+
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
154+
= note: see issue #63065 <https://github.com/rust-lang/rust/issues/63065> for more information
155+
= help: add `#![feature(impl_trait_in_bindings)]` to the crate attributes to enable
156+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
157+
158+
error[E0562]: `impl Trait` is not allowed in the type of variable bindings
159+
--> $DIR/expanded-exhaustive.rs:829:16
160+
|
161+
LL | let _: impl for<'a> Send;
162+
| ^^^^^^^^^^^^^^^^^
163+
|
164+
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
165+
= note: see issue #63065 <https://github.com/rust-lang/rust/issues/63065> for more information
166+
= help: add `#![feature(impl_trait_in_bindings)]` to the crate attributes to enable
167+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
168+
169+
error: aborting due to 20 previous errors
170+
171+
Some errors have detailed explanations: E0214, E0562, E0697, E0703, E0728.
172+
For more information about an error, try `rustc --explain E0214`.
Lines changed: 716 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,716 @@
1+
//@ revisions: expanded hir
2+
//@[expanded]compile-flags: -Zunpretty=expanded
3+
//@[expanded]check-pass
4+
//@[hir]compile-flags: -Zunpretty=hir
5+
//@[hir]check-fail
6+
//@ edition:2024
7+
//@ only-x86_64-unknown-linux-gnu because of asm!/global_asm! code
8+
9+
// Note: the HIR revision includes a `.stderr` file because there are some
10+
// errors that only occur once we get past the AST.
11+
12+
#![feature(auto_traits)]#![feature(box_patterns)]#![feature(builtin_syntax)]#![feature(concat_idents)]#![feature(const_trait_impl)]#![feature(decl_macro)]#![feature(deref_patterns)]#![feature(dyn_star)]#![feature(explicit_tail_calls)]#![feature(gen_blocks)]#![feature(more_qualified_paths)]#![feature(never_patterns)]#![feature(never_type)]#![feature(pattern_types)]#![feature(pattern_type_macro)]#![feature(prelude_import)]#![feature(specialization)]#![feature(trace_macros)]#![feature(trait_alias)]#![feature(try_blocks)]#![feature(yeet_expr)]#![allow(incomplete_features)]
13+
#[prelude_import]
14+
use std::prelude::rust_2024::*;
15+
#[macro_use]
16+
extern crate std;
17+
18+
#[prelude_import]
19+
use self::prelude::*;
20+
21+
mod prelude {
22+
use std::prelude::rust_2024::*;
23+
24+
type T = _;
25+
26+
trait Trait {
27+
const
28+
CONST:
29+
();
30+
}
31+
}
32+
33+
//! inner single-line doc comment
34+
/*!
35+
* inner multi-line doc comment
36+
*/
37+
#[doc = "inner doc attribute"]#[allow(dead_code, unused_variables)]#[no_std]
38+
mod attributes {//! inner single-line doc comment
39+
/*!
40+
* inner multi-line doc comment
41+
*/
42+
#![doc =
43+
"inner doc attribute"]#![allow(dead_code, unused_variables)]#![no_std]
44+
45+
/// outer single-line doc comment
46+
/**
47+
* outer multi-line doc comment
48+
*/
49+
#[doc =
50+
"outer doc attribute"]#[doc = "macro"]#[allow()]#[attr = Repr([ReprC])]
51+
struct Struct;
52+
}
53+
54+
mod expressions {
55+
/// ExprKind::Array
56+
fn expr_array() {
57+
[];
58+
[true];
59+
[true];
60+
[true, true];
61+
["long........................................................................"];
62+
["long............................................................",
63+
true];
64+
}
65+
66+
/// ExprKind::ConstBlock
67+
fn expr_const_block() {
68+
const { };
69+
const { 1 };
70+
const
71+
{
72+
struct S;
73+
};
74+
}
75+
76+
/// ExprKind::Call
77+
fn expr_call() {
78+
let f;
79+
f();
80+
f::<u8>();
81+
f::<1>();
82+
f::<'static, u8, 1>();
83+
f(true);
84+
f(true);
85+
()();
86+
}
87+
88+
/// ExprKind::MethodCall
89+
fn expr_method_call() {
90+
let x;
91+
x.f();
92+
x.f::<u8>();
93+
x.collect::<Vec<_>>();
94+
}
95+
96+
/// ExprKind::Tup
97+
fn expr_tup() { (); (true,); (true, false); (true, false); }
98+
99+
/// ExprKind::Binary
100+
fn expr_binary() {
101+
let (a, b, c, d, x, y);
102+
true || false;
103+
true || false && false;
104+
a < 1 && 2 < b && c > 3 && 4 > d;
105+
a & b & !c;
106+
a + b * c - d + -1 * -2 - -3;
107+
x = !y;
108+
}
109+
110+
/// ExprKind::Unary
111+
fn expr_unary() { let expr; *expr; !expr; -expr; }
112+
113+
/// ExprKind::Lit
114+
fn expr_lit() { 'x'; 1000i8; 1.00000000000000000000001; }
115+
116+
/// ExprKind::Cast
117+
fn expr_cast() { let expr; expr as T; expr as T<u8>; }
118+
119+
/// ExprKind::Type
120+
fn expr_type() { let expr; type_ascribe!(expr, T); }
121+
122+
/// ExprKind::Let
123+
fn expr_let() {
124+
let b;
125+
if let Some(a) = b { }
126+
if let _ = true && false { }
127+
if let _ = (true && false) { }
128+
}
129+
130+
/// ExprKind::If
131+
fn expr_if() {
132+
if true { }
133+
if !true { }
134+
if let true = true { } else { }
135+
if true { } else if false { }
136+
if true { } else if false { } else { }
137+
if true { return; } else if false { 0 } else { 0 }
138+
}
139+
140+
/// ExprKind::While
141+
fn expr_while() {
142+
loop { if false { } else { break; } }
143+
'a: loop { if false { } else { break; } }
144+
loop { if let true = true { } else { break; } }
145+
}
146+
147+
/// ExprKind::ForLoop
148+
fn expr_for_loop() {
149+
let x;
150+
{
151+
let _t =
152+
match #[lang = "into_iter"](x) {
153+
mut iter =>
154+
loop {
155+
match #[lang = "next"](&mut iter) {
156+
#[lang = "None"] {} => break,
157+
#[lang = "Some"] { 0: _ } => { }
158+
}
159+
},
160+
};
161+
_t
162+
};
163+
{
164+
let _t =
165+
match #[lang = "into_iter"](x) {
166+
mut iter =>
167+
'a:
168+
loop {
169+
match #[lang = "next"](&mut iter) {
170+
#[lang = "None"] {} => break,
171+
#[lang = "Some"] { 0: _ } => { }
172+
}
173+
},
174+
};
175+
_t
176+
}
177+
}
178+
179+
/// ExprKind::Loop
180+
fn expr_loop() { loop { } 'a: loop { } }
181+
182+
/// ExprKind::Match
183+
fn expr_match() {
184+
let value;
185+
match value { }
186+
match value { ok => 1, }
187+
match value { ok => 1, err => 0, }
188+
}
189+
190+
/// ExprKind::Closure
191+
fn expr_closure() {
192+
let value;
193+
|| { };
194+
|x| { };
195+
|x: u8| { };
196+
|| ();
197+
move || value;
198+
|| |mut _task_context: ResumeTy| { { let _t = value; _t } };
199+
move || |mut _task_context: ResumeTy| { { let _t = value; _t } };
200+
|| value;
201+
move || value;
202+
|| |mut _task_context: ResumeTy| { { let _t = value; _t } };
203+
move || |mut _task_context: ResumeTy| { { let _t = value; _t } };
204+
|| -> u8 { value };
205+
1 + (|| { });
206+
}
207+
208+
/// ExprKind::Block
209+
fn expr_block() {
210+
{ }
211+
unsafe { }
212+
'a: { }
213+
#[allow()]
214+
{ }
215+
#[allow()]
216+
{ }
217+
}
218+
219+
/// ExprKind::Gen
220+
fn expr_gen() {
221+
|mut _task_context: ResumeTy| { };
222+
move |mut _task_context: ResumeTy| { };
223+
|| { };
224+
move || { };
225+
|mut _task_context: ResumeTy| { };
226+
move |mut _task_context: ResumeTy| { };
227+
}
228+
229+
/// ExprKind::Await
230+
fn expr_await() {
231+
let fut;
232+
{
233+
fut;
234+
(/*ERROR*/)
235+
};
236+
}
237+
238+
/// ExprKind::TryBlock
239+
fn expr_try_block() {
240+
{ #[lang = "from_output"](()) }
241+
{ return; #[lang = "from_output"](()) }
242+
}
243+
244+
/// ExprKind::Assign
245+
fn expr_assign() { let expr; expr = true; }
246+
247+
/// ExprKind::AssignOp
248+
fn expr_assign_op() { let expr; expr += true; }
249+
250+
/// ExprKind::Field
251+
fn expr_field() { let expr; expr.field; expr.0; }
252+
253+
/// ExprKind::Index
254+
fn expr_index() { let expr; expr[true]; }
255+
256+
/// ExprKind::Range
257+
fn expr_range() {
258+
let (lo, hi);
259+
#[lang = "RangeFull"] { };
260+
#[lang = "RangeTo"] { end: hi };
261+
#[lang = "RangeFrom"] { start: lo };
262+
#[lang = "Range"] { start: lo, end: hi };
263+
#[lang = "Range"] { start: lo, end: hi };
264+
#[lang = "RangeToInclusive"] { end: hi };
265+
#[lang = "range_inclusive_new"](lo, hi);
266+
#[lang = "range_inclusive_new"](-2, -1);
267+
}
268+
269+
/// ExprKind::Underscore
270+
fn expr_underscore() {
271+
(/*ERROR*/);
272+
}
273+
274+
/// ExprKind::Path
275+
fn expr_path() {
276+
let x;
277+
crate::expressions::expr_path;
278+
crate::expressions::expr_path::<'static>;
279+
<T as Default>::default;
280+
<T as ::core::default::Default>::default;
281+
x;
282+
x::<T, T>;
283+
crate::expressions::expr_path;
284+
core::marker::PhantomData;
285+
}
286+
287+
/// ExprKind::AddrOf
288+
fn expr_addr_of() {
289+
let expr;
290+
&expr;
291+
&mut expr;
292+
&raw const expr;
293+
&raw mut expr;
294+
}
295+
296+
/// ExprKind::Break
297+
fn expr_break() { 'a: { break; break 'a; break true; break 'a true; } }
298+
299+
/// ExprKind::Continue
300+
fn expr_continue() { 'a: { continue; continue 'a; } }
301+
302+
/// ExprKind::Ret
303+
fn expr_ret() { return; return true; }
304+
305+
/// ExprKind::InlineAsm
306+
fn expr_inline_asm() {
307+
let x;
308+
asm!("mov {1}, {0}\nshl {1}, 1\nshl {0}, 2\nadd {0}, {1}",
309+
inout(reg)
310+
x,
311+
out(reg)
312+
_);
313+
}
314+
315+
/// ExprKind::OffsetOf
316+
fn expr_offset_of() {
317+
318+
319+
320+
321+
322+
323+
324+
325+
326+
327+
328+
329+
330+
// ...
331+
332+
333+
334+
335+
336+
// concat_idents is deprecated
337+
338+
339+
340+
341+
{ offset_of!(T, field) };
342+
}
343+
/// ExprKind::MacCall
344+
fn expr_mac_call() { "..."; "..."; "..."; }
345+
/// ExprKind::Struct
346+
fn expr_struct() {
347+
struct Struct {
348+
}
349+
let (x, base);
350+
Struct { };
351+
<Struct as ToOwned>::Owned { };
352+
Struct { .. };
353+
Struct { ..base };
354+
Struct { x };
355+
Struct { x, ..base };
356+
Struct { x: true };
357+
Struct { x: true, .. };
358+
Struct { x: true, ..base };
359+
Struct { 0: true, ..base };
360+
}
361+
/// ExprKind::Repeat
362+
fn expr_repeat() { [(); 0]; }
363+
/// ExprKind::Paren
364+
fn expr_paren() { let expr; expr; }
365+
/// ExprKind::Try
366+
fn expr_try() {
367+
let expr;
368+
match #[lang = "branch"](expr) {
369+
#[lang = "Break"] { 0: residual } =>
370+
#[allow(unreachable_code)]
371+
return #[lang = "from_residual"](residual),
372+
#[lang = "Continue"] { 0: val } => #[allow(unreachable_code)]
373+
val,
374+
};
375+
}
376+
/// ExprKind::Yield
377+
fn expr_yield() { yield (); yield true; }
378+
/// ExprKind::Yeet
379+
fn expr_yeet() {
380+
return #[lang = "from_yeet"](());
381+
return #[lang = "from_yeet"](0);
382+
}
383+
/// ExprKind::Become
384+
fn expr_become() { become true; }
385+
/// ExprKind::IncludedBytes
386+
fn expr_include_bytes() {
387+
b"data for include_bytes in ../expanded-exhaustive.rs\n";
388+
}
389+
/// ExprKind::FormatArgs
390+
fn expr_format_args() {
391+
let expr;
392+
format_arguments::new_const(&[]);
393+
format_arguments::new_v1(&[""],
394+
&[format_argument::new_display(&expr)]);
395+
}
396+
}
397+
mod items {
398+
/// ItemKind::ExternCrate
399+
mod item_extern_crate {/// ItemKind::ExternCrate
400+
extern crate core;
401+
extern crate self as unpretty;
402+
extern crate core as _;
403+
}
404+
/// ItemKind::Use
405+
mod item_use {/// ItemKind::Use
406+
use ::{};
407+
use crate::expressions;
408+
use crate::items::item_use;
409+
use core::*;
410+
}
411+
/// ItemKind::Static
412+
mod item_static {/// ItemKind::Static
413+
static A: () = { };
414+
static mut B: () = { };
415+
}
416+
/// ItemKind::Const
417+
mod item_const {/// ItemKind::Const
418+
const A: () = { };
419+
trait TraitItems {
420+
const
421+
B:
422+
();
423+
const
424+
C:
425+
()
426+
=
427+
{ };
428+
}
429+
}
430+
/// ItemKind::Fn
431+
mod item_fn {/// ItemKind::Fn
432+
const unsafe extern "C" fn f() { }
433+
async unsafe extern "C" fn g()
434+
->
435+
/*impl Trait*/ |mut _task_context: ResumeTy|
436+
{ { let _t = { }; _t } }
437+
fn h<'a, T>() where T: 'a { }
438+
trait TraitItems {
439+
unsafe extern "C" fn f();
440+
}
441+
impl TraitItems for _ {
442+
unsafe extern "C" fn f() { }
443+
}
444+
}
445+
/// ItemKind::Mod
446+
mod item_mod {/// ItemKind::Mod
447+
}
448+
/// ItemKind::ForeignMod
449+
mod item_foreign_mod {/// ItemKind::ForeignMod
450+
extern "Rust" { }
451+
extern "C" { }
452+
}
453+
/// ItemKind::GlobalAsm
454+
mod item_global_asm {/// ItemKind::GlobalAsm
455+
global_asm! (".globl my_asm_func") }
456+
/// ItemKind::TyAlias
457+
mod item_ty_alias {/// ItemKind::TyAlias
458+
type Type<'a> where T: 'a = T;
459+
}
460+
/// ItemKind::Enum
461+
mod item_enum {/// ItemKind::Enum
462+
enum Void { }
463+
enum Empty {
464+
Unit,
465+
Tuple(),
466+
Struct {
467+
},
468+
}
469+
enum Generic<'a, T> where T: 'a {
470+
Tuple(T),
471+
Struct {
472+
t: T,
473+
},
474+
}
475+
}
476+
/// ItemKind::Struct
477+
mod item_struct {/// ItemKind::Struct
478+
struct Unit;
479+
struct Tuple();
480+
struct Newtype(Unit);
481+
struct Struct {
482+
}
483+
struct Generic<'a, T> where T: 'a {
484+
t: T,
485+
}
486+
}
487+
/// ItemKind::Union
488+
mod item_union {/// ItemKind::Union
489+
union Generic<'a, T> where T: 'a {
490+
t: T,
491+
}
492+
}
493+
/// ItemKind::Trait
494+
mod item_trait {/// ItemKind::Trait
495+
auto unsafe trait Send { }
496+
trait Trait<'a>: Sized where Self: 'a { }
497+
}
498+
/// ItemKind::TraitAlias
499+
mod item_trait_alias {/// ItemKind::TraitAlias
500+
trait Trait<T> = Sized where for<'a> T: 'a;
501+
}
502+
/// ItemKind::Impl
503+
mod item_impl {/// ItemKind::Impl
504+
impl () { }
505+
impl <T> () { }
506+
impl Default for () { }
507+
impl const <T> Default for () { }
508+
}
509+
/// ItemKind::MacCall
510+
mod item_mac_call {/// ItemKind::MacCall
511+
}
512+
/// ItemKind::MacroDef
513+
mod item_macro_def {/// ItemKind::MacroDef
514+
macro_rules! mac { () => {...}; }
515+
macro stringify { () => {} }
516+
}
517+
/// ItemKind::Delegation
518+
/*! FIXME: todo */
519+
mod item_delegation {/// ItemKind::Delegation
520+
/*! FIXME: todo */
521+
}
522+
/// ItemKind::DelegationMac
523+
/*! FIXME: todo */
524+
mod item_delegation_mac {/// ItemKind::DelegationMac
525+
/*! FIXME: todo */
526+
}
527+
}
528+
mod patterns {
529+
/// PatKind::Missing
530+
fn pat_missing() { let _: for fn(u32, T, &'_ str); }
531+
/// PatKind::Wild
532+
fn pat_wild() { let _; }
533+
/// PatKind::Ident
534+
fn pat_ident() {
535+
let x;
536+
let ref x;
537+
let mut x;
538+
let ref mut x;
539+
let ref mut x@_;
540+
}
541+
/// PatKind::Struct
542+
fn pat_struct() {
543+
let T {};
544+
let T::<T> {};
545+
let T::<'static> {};
546+
let T { x };
547+
let T { x: _x };
548+
let T { .. };
549+
let T { x, .. };
550+
let T { x: _x, .. };
551+
let T { 0: _x, .. };
552+
let <T as ToOwned>::Owned {};
553+
}
554+
/// PatKind::TupleStruct
555+
fn pat_tuple_struct() {
556+
struct Tuple();
557+
let Tuple();
558+
let Tuple::<T>();
559+
let Tuple::<'static>();
560+
let Tuple(x);
561+
let Tuple(..);
562+
let Tuple(x, ..);
563+
}
564+
/// PatKind::Or
565+
fn pat_or() { let true | false; let true; let true | false; }
566+
/// PatKind::Path
567+
fn pat_path() {
568+
let core::marker::PhantomData;
569+
let core::marker::PhantomData::<T>;
570+
let core::marker::PhantomData::<'static>;
571+
let <T as Trait>::CONST;
572+
}
573+
/// PatKind::Tuple
574+
fn pat_tuple() { let (); let (true,); let (true, false); }
575+
/// PatKind::Box
576+
fn pat_box() { let box pat; }
577+
/// PatKind::Deref
578+
fn pat_deref() { let deref!(pat); }
579+
/// PatKind::Ref
580+
fn pat_ref() { let &pat; let &mut pat; }
581+
/// PatKind::Expr
582+
fn pat_expr() { let 1000i8; let -""; }
583+
/// PatKind::Range
584+
fn pat_range() {
585+
let ..1;
586+
let 0...;
587+
let 0..1;
588+
let 0...1;
589+
let -2...-1;
590+
}
591+
/// PatKind::Slice
592+
fn pat_slice() { let []; let [true]; let [true]; let [true, false]; }
593+
/// PatKind::Rest
594+
fn pat_rest() { let _; }
595+
/// PatKind::Never
596+
fn pat_never() { let !; let Some(!); }
597+
/// PatKind::Paren
598+
fn pat_paren() { let pat; }
599+
/// PatKind::MacCall
600+
fn pat_mac_call() { let ""; let ""; let ""; }
601+
}
602+
mod statements {
603+
/// StmtKind::Let
604+
fn stmt_let() {
605+
let _;
606+
let _ = true;
607+
let _: T = true;
608+
let _ = true else { return; };
609+
}
610+
/// StmtKind::Item
611+
fn stmt_item() {
612+
struct Struct {
613+
}
614+
struct Unit;
615+
}
616+
/// StmtKind::Expr
617+
fn stmt_expr() { () }
618+
/// StmtKind::Semi
619+
fn stmt_semi() { 1 + 1; }
620+
/// StmtKind::Empty
621+
fn stmt_empty() { }
622+
/// StmtKind::MacCall
623+
fn stmt_mac_call() { "..."; "..."; "..."; }
624+
}
625+
mod types {
626+
/// TyKind::Slice
627+
fn ty_slice() { let _: [T]; }
628+
/// TyKind::Array
629+
fn ty_array() { let _: [T; 0]; }
630+
/// TyKind::Ptr
631+
fn ty_ptr() { let _: *const T; let _: *mut T; }
632+
/// TyKind::Ref
633+
fn ty_ref() {
634+
let _: &T;
635+
let _: &mut T;
636+
let _: &'static T;
637+
let _: &'static mut [T];
638+
let _: &T<T<T<T<T>>>>;
639+
let _: &T<T<T<T<T>>>>;
640+
}
641+
/// TyKind::BareFn
642+
fn ty_bare_fn() {
643+
let _: fn();
644+
let _: fn() -> ();
645+
let _: fn(T);
646+
let _: fn(t: T);
647+
let _: fn();
648+
let _: for<'a> fn();
649+
}
650+
/// TyKind::Never
651+
fn ty_never() { let _: !; }
652+
/// TyKind::Tup
653+
fn ty_tup() { let _: (); let _: (T,); let _: (T, T); }
654+
/// TyKind::Path
655+
fn ty_path() {
656+
let _: T;
657+
let _: T<'static>;
658+
let _: T<T>;
659+
let _: T<T>;
660+
let _: T;
661+
let _: <T as ToOwned>::Owned;
662+
}
663+
/// TyKind::TraitObject
664+
fn ty_trait_object() {
665+
let _: dyn Send;
666+
let _: dyn Send + 'static;
667+
let _: dyn Send + 'static;
668+
let _: dyn for<'a> Send;
669+
let _: dyn* Send;
670+
}
671+
/// TyKind::ImplTrait
672+
const fn ty_impl_trait() {
673+
let _: (/*ERROR*/);
674+
let _: (/*ERROR*/);
675+
let _: (/*ERROR*/);
676+
let _: (/*ERROR*/);
677+
let _: (/*ERROR*/);
678+
let _: (/*ERROR*/);
679+
}
680+
/// TyKind::Paren
681+
fn ty_paren() { let _: T; }
682+
/// TyKind::Typeof
683+
/*! unused for now */
684+
fn ty_typeof() { }
685+
/// TyKind::Infer
686+
fn ty_infer() { let _: _; }
687+
/// TyKind::ImplicitSelf
688+
/*! there is no syntax for this */
689+
fn ty_implicit_self() { }
690+
/// TyKind::MacCall
691+
#[expect(deprecated)]
692+
fn ty_mac_call() { let _: T; let _: T; let _: T; }
693+
/// TyKind::CVarArgs
694+
/*! FIXME: todo */
695+
fn ty_c_var_args() { }
696+
/// TyKind::Pat
697+
fn ty_pat() { let _: u32 is 1..=RangeMax; }
698+
}
699+
mod visibilities {
700+
/// VisibilityKind::Public
701+
mod visibility_public {/// VisibilityKind::Public
702+
struct Pub;
703+
}
704+
/// VisibilityKind::Restricted
705+
mod visibility_restricted {/// VisibilityKind::Restricted
706+
struct PubCrate;
707+
struct PubSelf;
708+
struct PubSuper;
709+
struct PubInCrate;
710+
struct PubInSelf;
711+
struct PubInSuper;
712+
struct PubInCrateVisibilities;
713+
struct PubInSelfSuper;
714+
struct PubInSuperMod;
715+
}
716+
}

‎tests/ui/unpretty/expanded-exhaustive.rs

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
//@ compile-flags: -Zunpretty=expanded
1+
//@ revisions: expanded hir
2+
//@[expanded]compile-flags: -Zunpretty=expanded
3+
//@[expanded]check-pass
4+
//@[hir]compile-flags: -Zunpretty=hir
5+
//@[hir]check-fail
26
//@ edition:2024
3-
//@ check-pass
7+
//@ only-x86_64-unknown-linux-gnu because of asm!/global_asm! code
8+
9+
// Note: the HIR revision includes a `.stderr` file because there are some
10+
// errors that only occur once we get past the AST.
411

512
#![feature(auto_traits)]
613
#![feature(box_patterns)]
@@ -202,8 +209,8 @@ mod expressions {
202209
move || value;
203210
async || value;
204211
async move || value;
205-
static || value;
206-
static move || value;
212+
static || value; //[hir]~ ERROR closures cannot be static
213+
static move || value; //[hir]~ ERROR closures cannot be static
207214
(static async || value);
208215
(static async move || value);
209216
|| -> u8 { value };
@@ -232,7 +239,7 @@ mod expressions {
232239
/// ExprKind::Await
233240
fn expr_await() {
234241
let fut;
235-
fut.await;
242+
fut.await; //[hir]~ ERROR `await` is only allowed
236243
}
237244

238245
/// ExprKind::TryBlock
@@ -281,7 +288,7 @@ mod expressions {
281288

282289
/// ExprKind::Underscore
283290
fn expr_underscore() {
284-
_;
291+
_; //[hir]~ ERROR in expressions, `_` can only
285292
}
286293

287294
/// ExprKind::Path
@@ -291,10 +298,14 @@ mod expressions {
291298
crate::expressions::expr_path::<'static>;
292299
<T as Default>::default;
293300
<T as ::core::default::Default>::default::<>;
294-
x::();
295-
x::(T, T) -> T;
301+
x::(); //[hir]~ ERROR parenthesized type parameters
302+
x::(T, T) -> T; //[hir]~ ERROR parenthesized type parameters
296303
crate::() -> ()::expressions::() -> ()::expr_path;
304+
//[hir]~^ ERROR parenthesized type parameters
305+
//[hir]~| ERROR parenthesized type parameters
297306
core::()::marker::()::PhantomData;
307+
//[hir]~^ ERROR parenthesized type parameters
308+
//[hir]~| ERROR parenthesized type parameters
298309
}
299310

300311
/// ExprKind::AddrOf
@@ -390,7 +401,7 @@ mod expressions {
390401

391402
/// ExprKind::Yield
392403
fn expr_yield() {
393-
yield;
404+
yield; //[hir]~ ERROR `yield` can only be used
394405
yield true;
395406
}
396407

@@ -470,7 +481,7 @@ mod items {
470481

471482
/// ItemKind::ForeignMod
472483
mod item_foreign_mod {
473-
unsafe extern "C++" {}
484+
unsafe extern "C++" {} //[hir]~ ERROR invalid ABI
474485
unsafe extern "C" {}
475486
}
476487

@@ -680,7 +691,7 @@ mod patterns {
680691

681692
/// PatKind::Rest
682693
fn pat_rest() {
683-
let ..;
694+
let ..; //[hir]~ ERROR `..` patterns are not allowed here
684695
}
685696

686697
/// PatKind::Never
@@ -795,7 +806,7 @@ mod types {
795806
let _: T<'static>;
796807
let _: T<T>;
797808
let _: T::<T>;
798-
let _: T() -> !;
809+
let _: T() -> !; //[hir]~ ERROR parenthesized type parameters
799810
let _: <T as ToOwned>::Owned;
800811
}
801812

@@ -810,12 +821,12 @@ mod types {
810821

811822
/// TyKind::ImplTrait
812823
const fn ty_impl_trait() {
813-
let _: impl Send;
814-
let _: impl Send + 'static;
815-
let _: impl 'static + Send;
816-
let _: impl ?Sized;
817-
let _: impl ~const Clone;
818-
let _: impl for<'a> Send;
824+
let _: impl Send; //[hir]~ ERROR `impl Trait` is not allowed
825+
let _: impl Send + 'static; //[hir]~ ERROR `impl Trait` is not allowed
826+
let _: impl 'static + Send; //[hir]~ ERROR `impl Trait` is not allowed
827+
let _: impl ?Sized; //[hir]~ ERROR `impl Trait` is not allowed
828+
let _: impl ~const Clone; //[hir]~ ERROR `impl Trait` is not allowed
829+
let _: impl for<'a> Send; //[hir]~ ERROR `impl Trait` is not allowed
819830
}
820831

821832
/// TyKind::Paren

0 commit comments

Comments
 (0)
Please sign in to comment.