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 0d411a0

Browse files
committedApr 29, 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 25cdf1f commit 0d411a0

File tree

4 files changed

+930
-75
lines changed

4 files changed

+930
-75
lines changed
 

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

Lines changed: 15 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
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+
9+
// Note: the HIR revision includes a `.stderr` file because there are some
10+
// errors that only occur once we get past the AST.
511

612
#![feature(auto_traits)]
713
#![feature(box_patterns)]
@@ -211,7 +217,10 @@ mod expressions {
211217
}
212218

213219
/// ExprKind::Await
214-
fn expr_await() { let fut; fut.await; }
220+
fn expr_await() {
221+
let fut;
222+
fut.await;
223+
}
215224

216225
/// ExprKind::TryBlock
217226
fn expr_try_block() { try {} try { return; } }
@@ -242,7 +251,9 @@ mod expressions {
242251
}
243252

244253
/// ExprKind::Underscore
245-
fn expr_underscore() { _; }
254+
fn expr_underscore() {
255+
_;
256+
}
246257

247258
/// ExprKind::Path
248259
fn expr_path() {
@@ -300,65 +311,12 @@ mod expressions {
300311

301312

302313

303-
304-
305-
306-
307-
308-
309314
// ...
310315

311316

312317

313318

314319

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-
362320
// concat_idents is deprecated
363321

364322

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

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

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
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+
8+
// Note: the HIR revision includes a `.stderr` file because there are some
9+
// errors that only occur once we get past the AST.
410

511
#![feature(auto_traits)]
612
#![feature(box_patterns)]
@@ -202,8 +208,8 @@ mod expressions {
202208
move || value;
203209
async || value;
204210
async move || value;
205-
static || value;
206-
static move || value;
211+
static || value; //[hir]~ closures cannot be static
212+
static move || value; //[hir]~ closures cannot be static
207213
(static async || value);
208214
(static async move || value);
209215
|| -> u8 { value };
@@ -232,7 +238,7 @@ mod expressions {
232238
/// ExprKind::Await
233239
fn expr_await() {
234240
let fut;
235-
fut.await;
241+
fut.await; //[hir]~ `await` is only allowed
236242
}
237243

238244
/// ExprKind::TryBlock
@@ -281,7 +287,7 @@ mod expressions {
281287

282288
/// ExprKind::Underscore
283289
fn expr_underscore() {
284-
_;
290+
_; //[hir]~ in expressions, `_` can only
285291
}
286292

287293
/// ExprKind::Path
@@ -291,10 +297,14 @@ mod expressions {
291297
crate::expressions::expr_path::<'static>;
292298
<T as Default>::default;
293299
<T as ::core::default::Default>::default::<>;
294-
x::();
295-
x::(T, T) -> T;
300+
x::(); //[hir]~ parenthesized type parameters
301+
x::(T, T) -> T; //[hir]~ parenthesized type parameters
296302
crate::() -> ()::expressions::() -> ()::expr_path;
303+
//[hir]~^ parenthesized type parameters
304+
//[hir]~| parenthesized type parameters
297305
core::()::marker::()::PhantomData;
306+
//[hir]~^ parenthesized type parameters
307+
//[hir]~| parenthesized type parameters
298308
}
299309

300310
/// ExprKind::AddrOf
@@ -390,7 +400,7 @@ mod expressions {
390400

391401
/// ExprKind::Yield
392402
fn expr_yield() {
393-
yield;
403+
yield; //[hir]~ `yield` can only be used
394404
yield true;
395405
}
396406

@@ -470,7 +480,7 @@ mod items {
470480

471481
/// ItemKind::ForeignMod
472482
mod item_foreign_mod {
473-
unsafe extern "C++" {}
483+
unsafe extern "C++" {} //[hir]~ invalid ABI
474484
unsafe extern "C" {}
475485
}
476486

@@ -680,7 +690,7 @@ mod patterns {
680690

681691
/// PatKind::Rest
682692
fn pat_rest() {
683-
let ..;
693+
let ..; //[hir]~ `..` patterns are not allowed here
684694
}
685695

686696
/// PatKind::Never
@@ -795,7 +805,7 @@ mod types {
795805
let _: T<'static>;
796806
let _: T<T>;
797807
let _: T::<T>;
798-
let _: T() -> !;
808+
let _: T() -> !; //[hir]~ parenthesized type parameters
799809
let _: <T as ToOwned>::Owned;
800810
}
801811

@@ -810,12 +820,12 @@ mod types {
810820

811821
/// TyKind::ImplTrait
812822
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;
823+
let _: impl Send; //[hir]~ `impl Trait` is not allowed
824+
let _: impl Send + 'static; //[hir]~ `impl Trait` is not allowed
825+
let _: impl 'static + Send; //[hir]~ `impl Trait` is not allowed
826+
let _: impl ?Sized; //[hir]~ `impl Trait` is not allowed
827+
let _: impl ~const Clone; //[hir]~ `impl Trait` is not allowed
828+
let _: impl for<'a> Send; //[hir]~ `impl Trait` is not allowed
819829
}
820830

821831
/// TyKind::Paren

0 commit comments

Comments
 (0)
Please sign in to comment.