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 993b819

Browse files
committedJun 12, 2025·
Report infer ty errors during hir ty lowering
This centralizes the placeholder type error reporting in one location, but it also exposes the granularity at which we convert things from hir to ty more. E.g. previously infer types in where bounds were errored together with the function signature, but now they are independent.
1 parent fe5c95d commit 993b819

25 files changed

+327
-602
lines changed
 

‎compiler/rustc_hir/src/hir.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3134,6 +3134,15 @@ pub enum TraitItemKind<'hir> {
31343134
/// type.
31353135
Type(GenericBounds<'hir>, Option<&'hir Ty<'hir>>),
31363136
}
3137+
impl TraitItemKind<'_> {
3138+
pub fn descr(&self) -> &'static str {
3139+
match self {
3140+
TraitItemKind::Const(..) => "associated constant",
3141+
TraitItemKind::Fn(..) => "function",
3142+
TraitItemKind::Type(..) => "associated type",
3143+
}
3144+
}
3145+
}
31373146

31383147
// The bodies for items are stored "out of line", in a separate
31393148
// hashmap in the `Crate`. Here we just record the hir-id of the item
@@ -3194,6 +3203,15 @@ pub enum ImplItemKind<'hir> {
31943203
/// An associated type.
31953204
Type(&'hir Ty<'hir>),
31963205
}
3206+
impl ImplItemKind<'_> {
3207+
pub fn descr(&self) -> &'static str {
3208+
match self {
3209+
ImplItemKind::Const(..) => "associated constant",
3210+
ImplItemKind::Fn(..) => "function",
3211+
ImplItemKind::Type(..) => "associated type",
3212+
}
3213+
}
3214+
}
31973215

31983216
/// A constraint on an associated item.
31993217
///
@@ -4517,6 +4535,16 @@ pub enum ForeignItemKind<'hir> {
45174535
Type,
45184536
}
45194537

4538+
impl ForeignItemKind<'_> {
4539+
pub fn descr(&self) -> &'static str {
4540+
match self {
4541+
ForeignItemKind::Fn(..) => "function",
4542+
ForeignItemKind::Static(..) => "static variable",
4543+
ForeignItemKind::Type => "type",
4544+
}
4545+
}
4546+
}
4547+
45204548
/// A variable captured by a closure.
45214549
#[derive(Debug, Copy, Clone, HashStable_Generic)]
45224550
pub struct Upvar {

‎compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
231231
item.name = ? tcx.def_path_str(def_id)
232232
);
233233
crate::collect::lower_item(tcx, item.item_id());
234-
crate::collect::reject_placeholder_type_signatures_in_item(tcx, item);
235234

236235
let res = match item.kind {
237236
// Right now we check that every default trait implementation

‎compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 87 additions & 193 deletions
Large diffs are not rendered by default.

‎compiler/rustc_middle/src/ty/util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ impl<'tcx> TyCtxt<'tcx> {
767767
pub fn def_kind_descr(self, def_kind: DefKind, def_id: DefId) -> &'static str {
768768
match def_kind {
769769
DefKind::AssocFn if self.associated_item(def_id).is_method() => "method",
770+
DefKind::AssocTy if self.opt_rpitit_info(def_id).is_some() => "opaque type",
770771
DefKind::Closure if let Some(coroutine_kind) = self.coroutine_kind(def_id) => {
771772
match coroutine_kind {
772773
hir::CoroutineKind::Desugared(

‎tests/ui/async-await/issues/issue-95307.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55

66
pub trait C {
77
async fn new() -> [u8; _];
8-
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for functions
8+
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for opaque types
9+
//~| ERROR: the placeholder `_` is not allowed within types on item signatures for opaque types
10+
//~| ERROR: the placeholder `_` is not allowed within types on item signatures for opaque types
11+
//~| ERROR: the placeholder `_` is not allowed within types on item signatures for opaque types
912
//~| ERROR using `_` for array lengths is unstable
1013
}
1114

‎tests/ui/async-await/issues/issue-95307.stderr

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,33 @@
1-
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
1+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for opaque types
22
--> $DIR/issue-95307.rs:7:28
33
|
44
LL | async fn new() -> [u8; _];
55
| ^ not allowed in type signatures
66

7+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for opaque types
8+
--> $DIR/issue-95307.rs:7:28
9+
|
10+
LL | async fn new() -> [u8; _];
11+
| ^ not allowed in type signatures
12+
|
13+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
14+
15+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for opaque types
16+
--> $DIR/issue-95307.rs:7:28
17+
|
18+
LL | async fn new() -> [u8; _];
19+
| ^ not allowed in type signatures
20+
|
21+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
22+
23+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for opaque types
24+
--> $DIR/issue-95307.rs:7:28
25+
|
26+
LL | async fn new() -> [u8; _];
27+
| ^ not allowed in type signatures
28+
|
29+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
30+
731
error[E0658]: using `_` for array lengths is unstable
832
--> $DIR/issue-95307.rs:7:28
933
|
@@ -14,7 +38,7 @@ LL | async fn new() -> [u8; _];
1438
= help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable
1539
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1640

17-
error: aborting due to 2 previous errors
41+
error: aborting due to 5 previous errors
1842

1943
Some errors have detailed explanations: E0121, E0658.
2044
For more information about an error, try `rustc --explain E0121`.

‎tests/ui/did_you_mean/bad-assoc-ty.stderr

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -249,84 +249,36 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
249249
|
250250
LL | fn bar<F>(_: F) where F: Fn() -> _ {}
251251
| ^ not allowed in type signatures
252-
|
253-
help: use type parameters instead
254-
|
255-
LL - fn bar<F>(_: F) where F: Fn() -> _ {}
256-
LL + fn bar<F, T>(_: F) where F: Fn() -> T {}
257-
|
258252

259253
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
260254
--> $DIR/bad-assoc-ty.rs:57:19
261255
|
262256
LL | fn baz<F: Fn() -> _>(_: F) {}
263257
| ^ not allowed in type signatures
264-
|
265-
help: use type parameters instead
266-
|
267-
LL - fn baz<F: Fn() -> _>(_: F) {}
268-
LL + fn baz<F: Fn() -> T, T>(_: F) {}
269-
|
270258

271259
error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs
272260
--> $DIR/bad-assoc-ty.rs:60:33
273261
|
274262
LL | struct L<F>(F) where F: Fn() -> _;
275263
| ^ not allowed in type signatures
276-
|
277-
help: use type parameters instead
278-
|
279-
LL - struct L<F>(F) where F: Fn() -> _;
280-
LL + struct L<F, T>(F) where F: Fn() -> T;
281-
|
282-
283-
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
284-
--> $DIR/bad-assoc-ty.rs:82:38
285-
|
286-
LL | fn foo<F>(_: F) where F: Fn() -> _ {}
287-
| ^ not allowed in type signatures
288-
|
289-
help: use type parameters instead
290-
|
291-
LL - fn foo<F>(_: F) where F: Fn() -> _ {}
292-
LL + fn foo<F, T>(_: F) where F: Fn() -> T {}
293-
|
294264

295265
error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs
296266
--> $DIR/bad-assoc-ty.rs:62:30
297267
|
298268
LL | struct M<F> where F: Fn() -> _ {
299269
| ^ not allowed in type signatures
300-
|
301-
help: use type parameters instead
302-
|
303-
LL - struct M<F> where F: Fn() -> _ {
304-
LL + struct M<F, T> where F: Fn() -> T {
305-
|
306270

307271
error[E0121]: the placeholder `_` is not allowed within types on item signatures for enums
308272
--> $DIR/bad-assoc-ty.rs:66:28
309273
|
310274
LL | enum N<F> where F: Fn() -> _ {
311275
| ^ not allowed in type signatures
312-
|
313-
help: use type parameters instead
314-
|
315-
LL - enum N<F> where F: Fn() -> _ {
316-
LL + enum N<F, T> where F: Fn() -> T {
317-
|
318276

319277
error[E0121]: the placeholder `_` is not allowed within types on item signatures for unions
320278
--> $DIR/bad-assoc-ty.rs:71:29
321279
|
322280
LL | union O<F> where F: Fn() -> _ {
323281
| ^ not allowed in type signatures
324-
|
325-
help: use type parameters instead
326-
|
327-
LL - union O<F> where F: Fn() -> _ {
328-
LL + union O<F, T> where F: Fn() -> T {
329-
|
330282

331283
error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
332284
--> $DIR/bad-assoc-ty.rs:73:5
@@ -345,12 +297,12 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
345297
|
346298
LL | trait P<F> where F: Fn() -> _ {
347299
| ^ not allowed in type signatures
300+
301+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
302+
--> $DIR/bad-assoc-ty.rs:82:38
348303
|
349-
help: use type parameters instead
350-
|
351-
LL - trait P<F> where F: Fn() -> _ {
352-
LL + trait P<F, T> where F: Fn() -> T {
353-
|
304+
LL | fn foo<F>(_: F) where F: Fn() -> _ {}
305+
| ^ not allowed in type signatures
354306

355307
error: aborting due to 29 previous errors; 1 warning emitted
356308

‎tests/ui/fn/error-recovery-mismatch.stderr

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
3434
|
3535
LL | fn fold<T>(&self, _: T, &self._) {}
3636
| ^ not allowed in type signatures
37-
|
38-
help: use type parameters instead
39-
|
40-
LL - fn fold<T>(&self, _: T, &self._) {}
41-
LL + fn fold<T, U>(&self, _: T, &self.U) {}
42-
|
4337

4438
error: aborting due to 4 previous errors; 1 warning emitted
4539

‎tests/ui/generics/overlapping-errors-span-issue-123861.stderr

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
3030
|
3131
LL | fn mainIterator<_ = _> {}
3232
| ^ not allowed in type signatures
33-
|
34-
help: use type parameters instead
35-
|
36-
LL - fn mainIterator<_ = _> {}
37-
LL + fn mainIterator<T = T> {}
38-
|
3933

4034
error: aborting due to 4 previous errors
4135

‎tests/ui/impl-trait/in-trait/not-inferred-generic.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | ().publish_typed();
55
| ^^^^^^^^^^^^^ cannot infer type of the type parameter `F` declared on the method `publish_typed`
66
|
77
= note: cannot satisfy `_: Clone`
8-
= note: associated types cannot be accessed directly on a `trait`, they can only be accessed through a specific `impl`
8+
= note: opaque types cannot be accessed directly on a `trait`, they can only be accessed through a specific `impl`
99
note: required by a bound in `TypedClient::publish_typed::{anon_assoc#0}`
1010
--> $DIR/not-inferred-generic.rs:4:12
1111
|

‎tests/ui/macros/issue-118048.stderr

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@ LL | foo!(_);
66
| |
77
| not allowed in type signatures
88
| not allowed in type signatures
9-
|
10-
help: use type parameters instead
11-
|
12-
LL ~ fn foo<T>(_: $ty, _: $ty) {}
13-
LL | }
14-
LL | }
15-
LL |
16-
LL ~ foo!(T);
17-
|
189

1910
error: aborting due to 1 previous error
2011

‎tests/ui/macros/macro-span-issue-116502.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ fn bug() {
55
macro_rules! m {
66
() => {
77
_ //~ ERROR the placeholder `_` is not allowed within types on item signatures for structs
8+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for structs
9+
//~| ERROR the placeholder `_` is not allowed within types on item signatures for structs
810
};
911
}
1012
struct S<T = m!()>(m!(), T)

‎tests/ui/macros/macro-span-issue-116502.stderr

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,35 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
22
--> $DIR/macro-span-issue-116502.rs:7:13
33
|
44
LL | _
5-
| ^
6-
| |
7-
| not allowed in type signatures
8-
| not allowed in type signatures
9-
| not allowed in type signatures
5+
| ^ not allowed in type signatures
106
...
11-
LL | struct S<T = m!()>(m!(), T)
12-
| ---- ---- in this macro invocation
13-
| |
14-
| in this macro invocation
15-
LL | where
167
LL | T: Trait<m!()>;
178
| ---- in this macro invocation
189
|
1910
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
2011

21-
error: aborting due to 1 previous error
12+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs
13+
--> $DIR/macro-span-issue-116502.rs:7:13
14+
|
15+
LL | _
16+
| ^ not allowed in type signatures
17+
...
18+
LL | struct S<T = m!()>(m!(), T)
19+
| ---- in this macro invocation
20+
|
21+
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
22+
23+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs
24+
--> $DIR/macro-span-issue-116502.rs:7:13
25+
|
26+
LL | _
27+
| ^ not allowed in type signatures
28+
...
29+
LL | struct S<T = m!()>(m!(), T)
30+
| ---- in this macro invocation
31+
|
32+
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
33+
34+
error: aborting due to 3 previous errors
2235

2336
For more information about this error, try `rustc --explain E0121`.

‎tests/ui/self/self-infer.stderr

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,12 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
33
|
44
LL | fn f(self: _) {}
55
| ^ not allowed in type signatures
6-
|
7-
help: use type parameters instead
8-
|
9-
LL - fn f(self: _) {}
10-
LL + fn f<T>(self: T) {}
11-
|
126

137
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
148
--> $DIR/self-infer.rs:5:17
159
|
1610
LL | fn g(self: &_) {}
1711
| ^ not allowed in type signatures
18-
|
19-
help: use type parameters instead
20-
|
21-
LL - fn g(self: &_) {}
22-
LL + fn g<T>(self: &T) {}
23-
|
2412

2513
error: aborting due to 2 previous errors
2614

‎tests/ui/suggestions/bad-infer-in-trait-impl.stderr

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
33
|
44
LL | fn bar(s: _) {}
55
| ^ not allowed in type signatures
6-
|
7-
help: use type parameters instead
8-
|
9-
LL - fn bar(s: _) {}
10-
LL + fn bar<T>(s: T) {}
11-
|
126

137
error[E0050]: method `bar` has 1 parameter but the declaration in trait `Foo::bar` has 0
148
--> $DIR/bad-infer-in-trait-impl.rs:6:15

‎tests/ui/typeck/issue-74086.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
fn main() {
22
static BUG: fn(_) -> u8 = |_| 8;
3-
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions [E0121]
4-
//~| ERROR the placeholder `_` is not allowed within types on item signatures for static items
3+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for static items
54
}

‎tests/ui/typeck/issue-74086.stderr

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
2-
--> $DIR/issue-74086.rs:2:20
3-
|
4-
LL | static BUG: fn(_) -> u8 = |_| 8;
5-
| ^ not allowed in type signatures
6-
71
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items
82
--> $DIR/issue-74086.rs:2:20
93
|
104
LL | static BUG: fn(_) -> u8 = |_| 8;
115
| ^ not allowed in type signatures
126

13-
error: aborting due to 2 previous errors
7+
error: aborting due to 1 previous error
148

159
For more information about this error, try `rustc --explain E0121`.

‎tests/ui/typeck/issue-81885.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
const TEST4: fn() -> _ = 42;
2-
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
3-
//~| ERROR the placeholder `_` is not allowed within types on item signatures for constant items
2+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constant items
43

54
fn main() {
65
const TEST5: fn() -> _ = 42;
7-
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
8-
//~| ERROR the placeholder `_` is not allowed within types on item signatures for constant items
6+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constant items
97
}

‎tests/ui/typeck/issue-81885.stderr

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
1-
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
2-
--> $DIR/issue-81885.rs:1:22
3-
|
4-
LL | const TEST4: fn() -> _ = 42;
5-
| ^ not allowed in type signatures
6-
71
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constant items
82
--> $DIR/issue-81885.rs:1:22
93
|
104
LL | const TEST4: fn() -> _ = 42;
115
| ^ not allowed in type signatures
126

13-
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
14-
--> $DIR/issue-81885.rs:6:26
15-
|
16-
LL | const TEST5: fn() -> _ = 42;
17-
| ^ not allowed in type signatures
18-
197
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constant items
20-
--> $DIR/issue-81885.rs:6:26
8+
--> $DIR/issue-81885.rs:5:26
219
|
2210
LL | const TEST5: fn() -> _ = 42;
2311
| ^ not allowed in type signatures
2412

25-
error: aborting due to 4 previous errors
13+
error: aborting due to 2 previous errors
2614

2715
For more information about this error, try `rustc --explain E0121`.

‎tests/ui/typeck/type-placeholder-fn-in-const.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ struct MyStruct;
22

33
trait Test {
44
const TEST: fn() -> _;
5-
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for functions [E0121]
6-
//~| ERROR: the placeholder `_` is not allowed within types on item signatures for associated constants [E0121]
5+
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for associated constants [E0121]
76
}
87

98
impl Test for MyStruct {
109
const TEST: fn() -> _ = 42;
11-
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for functions [E0121]
12-
//~| ERROR: the placeholder `_` is not allowed within types on item signatures for associated constants [E0121]
10+
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for associated constants [E0121]
1311
}
1412

1513
fn main() {}
Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
1-
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
2-
--> $DIR/type-placeholder-fn-in-const.rs:10:25
3-
|
4-
LL | const TEST: fn() -> _ = 42;
5-
| ^ not allowed in type signatures
6-
7-
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
8-
--> $DIR/type-placeholder-fn-in-const.rs:4:25
9-
|
10-
LL | const TEST: fn() -> _;
11-
| ^ not allowed in type signatures
12-
131
error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants
14-
--> $DIR/type-placeholder-fn-in-const.rs:10:25
2+
--> $DIR/type-placeholder-fn-in-const.rs:9:25
153
|
164
LL | const TEST: fn() -> _ = 42;
175
| ^ not allowed in type signatures
@@ -22,6 +10,6 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
2210
LL | const TEST: fn() -> _;
2311
| ^ not allowed in type signatures
2412

25-
error: aborting due to 4 previous errors
13+
error: aborting due to 2 previous errors
2614

2715
For more information about this error, try `rustc --explain E0121`.

‎tests/ui/typeck/typeck_type_placeholder_item.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ fn test7(x: _) { let _x: usize = x; }
3333

3434
fn test8(_f: fn() -> _) { }
3535
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
36-
//~^^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
3736

3837
struct Test9;
3938

@@ -67,6 +66,7 @@ struct Test10 {
6766
a: _,
6867
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for structs
6968
b: (_, _),
69+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for structs
7070
}
7171

7272
pub fn main() {
@@ -99,7 +99,6 @@ pub fn main() {
9999

100100
fn fn_test8(_f: fn() -> _) { }
101101
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
102-
//~^^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
103102

104103
struct FnTest9;
105104

@@ -123,6 +122,7 @@ pub fn main() {
123122
a: _,
124123
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for structs
125124
b: (_, _),
125+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for structs
126126
}
127127

128128
fn fn_test11(_: _) -> (_, _) { panic!() }
@@ -158,9 +158,11 @@ trait BadTrait<_> {}
158158
//~^ ERROR expected identifier, found reserved identifier `_`
159159
impl BadTrait<_> for BadStruct<_> {}
160160
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for implementations
161+
//~| ERROR the placeholder `_` is not allowed within types on item signatures for implementations
161162

162163
fn impl_trait() -> impl BadTrait<_> {
163-
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
164+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for opaque types
165+
//~| ERROR the placeholder `_` is not allowed within types on item signatures for opaque types
164166
unimplemented!()
165167
}
166168

@@ -180,7 +182,8 @@ struct Struct;
180182
trait Trait<T> {}
181183
impl Trait<usize> for Struct {}
182184
type Y = impl Trait<_>;
183-
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for type aliases
185+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for opaque types
186+
//~| ERROR the placeholder `_` is not allowed within types on item signatures for opaque types
184187
#[define_opaque(Y)]
185188
fn foo() -> Y {
186189
Struct
@@ -197,6 +200,7 @@ trait Qux {
197200
// type E: _; // FIXME: make the parser propagate the existence of `B`
198201
type F: std::ops::Fn(_);
199202
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated types
203+
//~| ERROR the placeholder `_` is not allowed within types on item signatures for associated types
200204
}
201205
impl Qux for Struct {
202206
//~^ ERROR not all trait items implemented, missing: `F`

‎tests/ui/typeck/typeck_type_placeholder_item.stderr

Lines changed: 125 additions & 239 deletions
Large diffs are not rendered by default.

‎tests/ui/typeck/typeck_type_placeholder_item_help.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ const TEST3: _ = Some(42);
1111
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants
1212

1313
const TEST4: fn() -> _ = 42;
14-
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
15-
//~| ERROR the placeholder `_` is not allowed within types on item signatures for constant items
14+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constant items
1615

1716
trait Test5 {
1817
const TEST5: _ = 42;

‎tests/ui/typeck/typeck_type_placeholder_item_help.stderr

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,14 @@ LL - const TEST3: _ = Some(42);
3131
LL + const TEST3: Option<i32> = Some(42);
3232
|
3333

34-
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
35-
--> $DIR/typeck_type_placeholder_item_help.rs:13:22
36-
|
37-
LL | const TEST4: fn() -> _ = 42;
38-
| ^ not allowed in type signatures
39-
4034
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constant items
4135
--> $DIR/typeck_type_placeholder_item_help.rs:13:22
4236
|
4337
LL | const TEST4: fn() -> _ = 42;
4438
| ^ not allowed in type signatures
4539

4640
error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants
47-
--> $DIR/typeck_type_placeholder_item_help.rs:25:18
41+
--> $DIR/typeck_type_placeholder_item_help.rs:24:18
4842
|
4943
LL | const TEST6: _ = 13;
5044
| ^ not allowed in type signatures
@@ -56,7 +50,7 @@ LL + const TEST6: i32 = 13;
5650
|
5751

5852
error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants
59-
--> $DIR/typeck_type_placeholder_item_help.rs:18:18
53+
--> $DIR/typeck_type_placeholder_item_help.rs:17:18
6054
|
6155
LL | const TEST5: _ = 42;
6256
| ^ not allowed in type signatures
@@ -68,7 +62,7 @@ LL + const TEST5: i32 = 42;
6862
|
6963

7064
error[E0308]: mismatched types
71-
--> $DIR/typeck_type_placeholder_item_help.rs:30:28
65+
--> $DIR/typeck_type_placeholder_item_help.rs:29:28
7266
|
7367
LL | let _: Option<usize> = test1();
7468
| ------------- ^^^^^^^ expected `Option<usize>`, found `Option<i32>`
@@ -79,7 +73,7 @@ LL | let _: Option<usize> = test1();
7973
found enum `Option<i32>`
8074

8175
error[E0308]: mismatched types
82-
--> $DIR/typeck_type_placeholder_item_help.rs:31:18
76+
--> $DIR/typeck_type_placeholder_item_help.rs:30:18
8377
|
8478
LL | let _: f64 = test1();
8579
| --- ^^^^^^^ expected `f64`, found `Option<i32>`
@@ -89,7 +83,7 @@ LL | let _: f64 = test1();
8983
= note: expected type `f64`
9084
found enum `Option<i32>`
9185

92-
error: aborting due to 9 previous errors
86+
error: aborting due to 8 previous errors
9387

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

0 commit comments

Comments
 (0)
Please sign in to comment.