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 127d9bc

Browse files
committedMay 1, 2025
Auto merge of #140430 - nnethercote:hir-exhaustive, r=<try>
Improve test coverage of HIR pretty printing. Details in individual commits. r? `@dtolnay`
2 parents 6e23095 + 69e54ae commit 127d9bc

File tree

6 files changed

+930
-75
lines changed

6 files changed

+930
-75
lines changed
 

‎tests/ui/unpretty/expanded-exhaustive.stdout renamed to ‎tests/ui/unpretty/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/exhaustive.rs:211:9
3+
|
4+
LL | static || value;
5+
| ^^^^^^^^^
6+
7+
error[E0697]: closures cannot be static
8+
--> $DIR/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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`.

‎tests/ui/unpretty/exhaustive.hir.stdout

Lines changed: 715 additions & 0 deletions
Large diffs are not rendered by default.

‎tests/ui/unpretty/expanded-exhaustive.rs renamed to ‎tests/ui/unpretty/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]~ ERROR closures cannot be static
212+
static move || value; //[hir]~ ERROR 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]~ ERROR `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]~ ERROR 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]~ ERROR parenthesized type parameters
301+
x::(T, T) -> T; //[hir]~ ERROR parenthesized type parameters
296302
crate::() -> ()::expressions::() -> ()::expr_path;
303+
//[hir]~^ ERROR parenthesized type parameters
304+
//[hir]~| ERROR parenthesized type parameters
297305
core::()::marker::()::PhantomData;
306+
//[hir]~^ ERROR parenthesized type parameters
307+
//[hir]~| ERROR 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]~ ERROR `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]~ ERROR 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]~ ERROR `..` 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]~ ERROR 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]~ ERROR `impl Trait` is not allowed
824+
let _: impl Send + 'static; //[hir]~ ERROR `impl Trait` is not allowed
825+
let _: impl 'static + Send; //[hir]~ ERROR `impl Trait` is not allowed
826+
let _: impl ?Sized; //[hir]~ ERROR `impl Trait` is not allowed
827+
let _: impl ~const Clone; //[hir]~ ERROR `impl Trait` is not allowed
828+
let _: impl for<'a> Send; //[hir]~ ERROR `impl Trait` is not allowed
819829
}
820830

821831
/// TyKind::Paren

0 commit comments

Comments
 (0)
Please sign in to comment.