Skip to content

Commit d16e62b

Browse files
Replace ItemCtxt::report_placeholder_type_error match with a call to TyCtxt::def_descr
1 parent ad3b725 commit d16e62b

27 files changed

+86
-70
lines changed

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -277,17 +277,7 @@ impl<'tcx> ItemCtxt<'tcx> {
277277
}
278278
_ => self.item_def_id,
279279
};
280-
// FIXME: just invoke `tcx.def_descr` instead of going through the HIR
281-
// Can also remove most `descr` methods then.
282-
let kind = match self.tcx.hir_node_by_def_id(kind_id) {
283-
Node::Item(it) => it.kind.descr(),
284-
Node::ImplItem(it) => it.kind.descr(),
285-
Node::TraitItem(it) => it.kind.descr(),
286-
Node::ForeignItem(it) => it.kind.descr(),
287-
Node::OpaqueTy(_) => "opaque type",
288-
Node::Synthetic => self.tcx.def_descr(kind_id.into()),
289-
node => todo!("{node:#?}"),
290-
};
280+
let kind = self.tcx.def_descr(kind_id.into());
291281
let mut diag = placeholder_type_error_diag(
292282
self,
293283
generics,

tests/ui/closures/missing-body.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Checks that the compiler complains about the missing closure body and does not
2+
// crash.
3+
// This is a regression test for <https://github.com/rust-lang/rust/issues/143128>.
4+
5+
fn main() { |b: [str; _]| {}; }
6+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for closures
7+
//~| ERROR the size for values of type `str` cannot be known at compilation time

tests/ui/closures/missing-body.stderr

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for closures
2+
--> $DIR/missing-body.rs:5:23
3+
|
4+
LL | fn main() { |b: [str; _]| {}; }
5+
| ^ not allowed in type signatures
6+
7+
error[E0277]: the size for values of type `str` cannot be known at compilation time
8+
--> $DIR/missing-body.rs:5:17
9+
|
10+
LL | fn main() { |b: [str; _]| {}; }
11+
| ^^^^^^^^ doesn't have a size known at compile-time
12+
|
13+
= help: the trait `Sized` is not implemented for `str`
14+
= note: slice and array elements must have `Sized` type
15+
16+
error: aborting due to 2 previous errors
17+
18+
Some errors have detailed explanations: E0121, E0277.
19+
For more information about an error, try `rustc --explain E0121`.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
302302
LL | trait P<F> where F: Fn() -> _ {
303303
| ^ not allowed in type signatures
304304

305-
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
305+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions
306306
--> $DIR/bad-assoc-ty.rs:88:38
307307
|
308308
LL | fn foo<F>(_: F) where F: Fn() -> _ {}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
284284
LL | trait P<F> where F: Fn() -> _ {
285285
| ^ not allowed in type signatures
286286

287-
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
287+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions
288288
--> $DIR/bad-assoc-ty.rs:88:38
289289
|
290290
LL | fn foo<F>(_: F) where F: Fn() -> _ {}

tests/ui/did_you_mean/bad-assoc-ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ trait P<F> where F: Fn() -> _ {
8686

8787
trait Q {
8888
fn foo<F>(_: F) where F: Fn() -> _ {}
89-
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
89+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated functions
9090
}
9191

9292
fn main() {}

tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ trait Foo<T>: Sized {
77

88
impl Foo<usize> for () {
99
fn bar(i: _, t: _, s: _) -> _ {
10-
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
10+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated functions
1111
//~| ERROR type annotations needed
1212
(1, 2)
1313
}

tests/ui/did_you_mean/replace-impl-infer-ty-from-trait.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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 associated functions
22
--> $DIR/replace-impl-infer-ty-from-trait.rs:9:15
33
|
44
LL | fn bar(i: _, t: _, s: _) -> _ {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ LL | fn fold<T>(&self, _: T, &self._) {}
2929
= note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686>
3030
= note: `#[warn(anonymous_parameters)]` on by default
3131

32-
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
32+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods
3333
--> $DIR/error-recovery-mismatch.rs:11:35
3434
|
3535
LL | fn fold<T>(&self, _: T, &self._) {}

tests/ui/self/self-infer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
struct S;
22

33
impl S {
4-
fn f(self: _) {} //~ERROR the placeholder `_` is not allowed within types on item signatures for functions
5-
fn g(self: &_) {} //~ERROR the placeholder `_` is not allowed within types on item signatures for functions
4+
fn f(self: _) {} //~ERROR the placeholder `_` is not allowed within types on item signatures for methods
5+
fn g(self: &_) {} //~ERROR the placeholder `_` is not allowed within types on item signatures for methods
66
}
77

88
fn main() {}

tests/ui/self/self-infer.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
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 methods
22
--> $DIR/self-infer.rs:4:16
33
|
44
LL | fn f(self: _) {}
55
| ^ not allowed in type signatures
66

7-
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
7+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for methods
88
--> $DIR/self-infer.rs:5:17
99
|
1010
LL | fn g(self: &_) {}

tests/ui/suggestions/bad-infer-in-trait-impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ trait Foo {
44

55
impl Foo for () {
66
fn bar(s: _) {}
7-
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
7+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated functions
88
//~| ERROR has 1 parameter but the declaration in trait `Foo::bar` has 0
99
}
1010

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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 associated functions
22
--> $DIR/bad-infer-in-trait-impl.rs:6:15
33
|
44
LL | fn bar(s: _) {}

tests/ui/traits/const-traits/ice-119717-constant-lifetime.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LL | impl<T> const FromResidual for T {
1616
= note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local
1717
= note: only traits defined in the current crate can be implemented for a type parameter
1818

19-
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
19+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated functions
2020
--> $DIR/ice-119717-constant-lifetime.rs:9:31
2121
|
2222
LL | fn from_residual(t: T) -> _ {

tests/ui/traits/method-argument-mismatch-variance-ice-119867.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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 associated functions
22
--> $DIR/method-argument-mismatch-variance-ice-119867.rs:8:23
33
|
44
LL | fn deserialize(s: _) {}

tests/ui/typeck/issue-74086.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
fn main() {
22
static BUG: fn(_) -> u8 = |_| 8;
3-
//~^ 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 statics
44
}

tests/ui/typeck/issue-74086.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items
1+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for statics
22
--> $DIR/issue-74086.rs:2:20
33
|
44
LL | static BUG: fn(_) -> u8 = |_| 8;

tests/ui/typeck/issue-75889.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constant items
1+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
22
--> $DIR/issue-75889.rs:3:24
33
|
44
LL | const FOO: dyn Fn() -> _ = "";
55
| ^ not allowed in type signatures
66

7-
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items
7+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for statics
88
--> $DIR/issue-75889.rs:4:25
99
|
1010
LL | static BOO: dyn Fn() -> _ = "";

tests/ui/typeck/issue-81885.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const TEST4: fn() -> _ = 42;
2-
//~^ 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 constants
33

44
fn main() {
55
const TEST5: fn() -> _ = 42;
6-
//~^ 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 constants
77
}

tests/ui/typeck/issue-81885.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constant items
1+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
22
--> $DIR/issue-81885.rs:1:22
33
|
44
LL | const TEST4: fn() -> _ = 42;
55
| ^ not allowed in type signatures
66

7-
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constant items
7+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
88
--> $DIR/issue-81885.rs:5:26
99
|
1010
LL | const TEST5: fn() -> _ = 42;

tests/ui/typeck/issue-83621-placeholder-static-in-extern.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
1+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for statics
22
--> $DIR/issue-83621-placeholder-static-in-extern.rs:4:15
33
|
44
LL | static x: _;

tests/ui/typeck/issue-88643.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ use std::collections::HashMap;
88
pub trait T {}
99

1010
static CALLBACKS: HashMap<*const dyn T, dyn FnMut(&mut _) + 'static> = HashMap::new();
11-
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for static items [E0121]
11+
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for statics [E0121]
1212

1313
static CALLBACKS2: Vec<dyn Fn(& _)> = Vec::new();
14-
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for static items [E0121]
14+
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for statics [E0121]
1515

1616
static CALLBACKS3: Option<dyn Fn(& _)> = None;
17-
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for static items [E0121]
17+
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for statics [E0121]
1818

1919
fn main() {}

tests/ui/typeck/issue-88643.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items
1+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for statics
22
--> $DIR/issue-88643.rs:10:56
33
|
44
LL | static CALLBACKS: HashMap<*const dyn T, dyn FnMut(&mut _) + 'static> = HashMap::new();
55
| ^ not allowed in type signatures
66

7-
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items
7+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for statics
88
--> $DIR/issue-88643.rs:13:33
99
|
1010
LL | static CALLBACKS2: Vec<dyn Fn(& _)> = Vec::new();
1111
| ^ not allowed in type signatures
1212

13-
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items
13+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for statics
1414
--> $DIR/issue-88643.rs:16:36
1515
|
1616
LL | static CALLBACKS3: Option<dyn Fn(& _)> = None;

tests/ui/typeck/typeck_type_placeholder_item.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Test9 {
4141
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
4242

4343
fn test10(&self, _x : _) { }
44-
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
44+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods
4545
}
4646

4747
fn test11(x: &usize) -> &_ {
@@ -56,10 +56,10 @@ unsafe fn test12(x: *const usize) -> *const *const _ {
5656

5757
impl Clone for Test9 {
5858
fn clone(&self) -> _ { Test9 }
59-
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
59+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods
6060

6161
fn clone_from(&mut self, other: _) { *self = Test9; }
62-
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
62+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods
6363
}
6464

6565
struct Test10 {
@@ -108,15 +108,15 @@ pub fn main() {
108108
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
109109

110110
fn fn_test10(&self, _x : _) { }
111-
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
111+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods
112112
}
113113

114114
impl Clone for FnTest9 {
115115
fn clone(&self) -> _ { FnTest9 }
116-
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
116+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods
117117

118118
fn clone_from(&mut self, other: _) { *self = FnTest9; }
119-
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
119+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods
120120
}
121121

122122
struct FnTest10 {
@@ -140,19 +140,19 @@ pub fn main() {
140140

141141
trait T {
142142
fn method_test1(&self, x: _);
143-
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
143+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods
144144
fn method_test2(&self, x: _) -> _;
145-
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
146-
//~| ERROR the placeholder `_` is not allowed within types on item signatures for functions
145+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods
146+
//~| ERROR the placeholder `_` is not allowed within types on item signatures for methods
147147
fn method_test3(&self) -> _;
148-
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
148+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for methods
149149
fn assoc_fn_test1(x: _);
150-
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
150+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated functions
151151
fn assoc_fn_test2(x: _) -> _;
152-
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
153-
//~| ERROR the placeholder `_` is not allowed within types on item signatures for functions
152+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated functions
153+
//~| ERROR the placeholder `_` is not allowed within types on item signatures for associated functions
154154
fn assoc_fn_test3() -> _;
155-
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
155+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated functions
156156
}
157157

158158
struct BadStruct<_>(_);

0 commit comments

Comments
 (0)