Skip to content

Commit 052d77e

Browse files
committed
Account for bad placeholder errors on consts/statics with trait objects
1 parent eab201d commit 052d77e

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

compiler/rustc_typeck/src/collect.rs

+8
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,14 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
808808
match it.kind {
809809
hir::ItemKind::Fn(..) => tcx.ensure().fn_sig(def_id),
810810
hir::ItemKind::OpaqueTy(..) => tcx.ensure().item_bounds(def_id),
811+
hir::ItemKind::Const(ty, ..) | hir::ItemKind::Static(ty, ..) => {
812+
// (#75889): Account for `const C: dyn Fn() -> _ = "";`
813+
if let hir::TyKind::TraitObject(..) = ty.kind {
814+
let mut visitor = PlaceholderHirTyCollector::default();
815+
visitor.visit_item(it);
816+
placeholder_type_error(tcx, None, &[], visitor.0, false, None);
817+
}
818+
}
811819
_ => (),
812820
}
813821
}

src/test/ui/error-codes/E0121.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ fn foo() -> _ { 5 } //~ ERROR E0121
22

33
static BAR: _ = "test"; //~ ERROR E0121
44

5-
fn main() {
6-
}
5+
fn main() {}

src/test/ui/typeck/issue-75889.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Regression test for #75889.
2+
3+
const FOO: dyn Fn() -> _ = ""; //~ ERROR E0121
4+
static BOO: dyn Fn() -> _ = ""; //~ ERROR E0121
5+
6+
fn main() {}

src/test/ui/typeck/issue-75889.stderr

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
2+
--> $DIR/issue-75889.rs:3:24
3+
|
4+
LL | const FOO: dyn Fn() -> _ = "";
5+
| ^ not allowed in type signatures
6+
7+
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
8+
--> $DIR/issue-75889.rs:4:25
9+
|
10+
LL | static BOO: dyn Fn() -> _ = "";
11+
| ^ not allowed in type signatures
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0121`.

0 commit comments

Comments
 (0)