Skip to content

Commit e2ea213

Browse files
authored
Rollup merge of #143234 - GuillaumeGomez:ice-143128, r=oli-obk
Replace `ItemCtxt::report_placeholder_type_error` match with a call to `TyCtxt::def_descr` Fixes #143128. We could likely use `tcx.def_descr` in more places (and therefore remove more `descr` methods). If it's something that we want to do, I can send a follow-up. r? `@oli-obk`
2 parents 79e96c0 + 74fda50 commit e2ea213

30 files changed

+89
-101
lines changed

compiler/rustc_hir/src/hir.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3141,15 +3141,6 @@ pub enum TraitItemKind<'hir> {
31413141
/// type.
31423142
Type(GenericBounds<'hir>, Option<&'hir Ty<'hir>>),
31433143
}
3144-
impl TraitItemKind<'_> {
3145-
pub fn descr(&self) -> &'static str {
3146-
match self {
3147-
TraitItemKind::Const(..) => "associated constant",
3148-
TraitItemKind::Fn(..) => "function",
3149-
TraitItemKind::Type(..) => "associated type",
3150-
}
3151-
}
3152-
}
31533144

31543145
// The bodies for items are stored "out of line", in a separate
31553146
// hashmap in the `Crate`. Here we just record the hir-id of the item
@@ -3211,15 +3202,6 @@ pub enum ImplItemKind<'hir> {
32113202
/// An associated type.
32123203
Type(&'hir Ty<'hir>),
32133204
}
3214-
impl ImplItemKind<'_> {
3215-
pub fn descr(&self) -> &'static str {
3216-
match self {
3217-
ImplItemKind::Const(..) => "associated constant",
3218-
ImplItemKind::Fn(..) => "function",
3219-
ImplItemKind::Type(..) => "associated type",
3220-
}
3221-
}
3222-
}
32233205

32243206
/// A constraint on an associated item.
32253207
///
@@ -4545,16 +4527,6 @@ pub enum ForeignItemKind<'hir> {
45454527
Type,
45464528
}
45474529

4548-
impl ForeignItemKind<'_> {
4549-
pub fn descr(&self) -> &'static str {
4550-
match self {
4551-
ForeignItemKind::Fn(..) => "function",
4552-
ForeignItemKind::Static(..) => "static variable",
4553-
ForeignItemKind::Type => "type",
4554-
}
4555-
}
4556-
}
4557-
45584530
/// A variable captured by a closure.
45594531
#[derive(Debug, Copy, Clone, HashStable_Generic)]
45604532
pub struct Upvar {

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.fixed

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: i32, t: usize, s: &()) -> (usize, i32) {
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.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
}

0 commit comments

Comments
 (0)