Skip to content

Commit cde49cf

Browse files
authored
Rollup merge of rust-lang#83739 - JohnTitor:issue-75889, r=estebank
Account for bad placeholder errors on consts/statics with trait objects Fixes rust-lang#75889 r? `@estebank`
2 parents e82b650 + 052d77e commit cde49cf

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
@@ -813,6 +813,14 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
813813
match it.kind {
814814
hir::ItemKind::Fn(..) => tcx.ensure().fn_sig(def_id),
815815
hir::ItemKind::OpaqueTy(..) => tcx.ensure().item_bounds(def_id),
816+
hir::ItemKind::Const(ty, ..) | hir::ItemKind::Static(ty, ..) => {
817+
// (#75889): Account for `const C: dyn Fn() -> _ = "";`
818+
if let hir::TyKind::TraitObject(..) = ty.kind {
819+
let mut visitor = PlaceholderHirTyCollector::default();
820+
visitor.visit_item(it);
821+
placeholder_type_error(tcx, None, &[], visitor.0, false, None);
822+
}
823+
}
816824
_ => (),
817825
}
818826
}

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)