Skip to content

Commit b5782ba

Browse files
committed
Catch a bad placeholder type error for statics in externs
1 parent a5029ac commit b5782ba

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

compiler/rustc_typeck/src/collect.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -735,8 +735,14 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
735735
tcx.ensure().generics_of(item.def_id);
736736
tcx.ensure().type_of(item.def_id);
737737
tcx.ensure().predicates_of(item.def_id);
738-
if let hir::ForeignItemKind::Fn(..) = item.kind {
739-
tcx.ensure().fn_sig(item.def_id);
738+
match item.kind {
739+
hir::ForeignItemKind::Fn(..) => tcx.ensure().fn_sig(item.def_id),
740+
hir::ForeignItemKind::Static(..) => {
741+
let mut visitor = PlaceholderHirTyCollector::default();
742+
visitor.visit_foreign_item(item);
743+
placeholder_type_error(tcx, None, &[], visitor.0, false, None);
744+
}
745+
_ => (),
740746
}
741747
}
742748
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Regression test for #83621.
2+
3+
extern "C" {
4+
static x: _; //~ ERROR: [E0121]
5+
}
6+
7+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
2+
--> $DIR/issue-83621-placeholder-static-in-extern.rs:4:15
3+
|
4+
LL | static x: _;
5+
| ^ not allowed in type signatures
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0121`.

0 commit comments

Comments
 (0)