Skip to content

Commit 76df265

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

28 files changed

+88
-72
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/rustdoc-ui/invalid_infered_static_and_const.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/invalid_infered_static_and_const.rs:1: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/invalid_infered_static_and_const.rs:2:25
99
|
1010
LL | static BOO: dyn Fn() -> _ = "";

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._) {}

0 commit comments

Comments
 (0)