Skip to content

Commit

Permalink
Rollup merge of #83739 - JohnTitor:issue-75889, r=estebank
Browse files Browse the repository at this point in the history
Account for bad placeholder errors on consts/statics with trait objects

Fixes #75889
r? ``@estebank``
  • Loading branch information
JohnTitor authored Jun 21, 2021
2 parents e82b650 + 052d77e commit 1a1909a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
8 changes: 8 additions & 0 deletions compiler/rustc_typeck/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,14 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
match it.kind {
hir::ItemKind::Fn(..) => tcx.ensure().fn_sig(def_id),
hir::ItemKind::OpaqueTy(..) => tcx.ensure().item_bounds(def_id),
hir::ItemKind::Const(ty, ..) | hir::ItemKind::Static(ty, ..) => {
// (#75889): Account for `const C: dyn Fn() -> _ = "";`
if let hir::TyKind::TraitObject(..) = ty.kind {
let mut visitor = PlaceholderHirTyCollector::default();
visitor.visit_item(it);
placeholder_type_error(tcx, None, &[], visitor.0, false, None);
}
}
_ => (),
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/test/ui/error-codes/E0121.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ fn foo() -> _ { 5 } //~ ERROR E0121

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

fn main() {
}
fn main() {}
6 changes: 6 additions & 0 deletions src/test/ui/typeck/issue-75889.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Regression test for #75889.

const FOO: dyn Fn() -> _ = ""; //~ ERROR E0121
static BOO: dyn Fn() -> _ = ""; //~ ERROR E0121

fn main() {}
15 changes: 15 additions & 0 deletions src/test/ui/typeck/issue-75889.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/issue-75889.rs:3:24
|
LL | const FOO: dyn Fn() -> _ = "";
| ^ not allowed in type signatures

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/issue-75889.rs:4:25
|
LL | static BOO: dyn Fn() -> _ = "";
| ^ not allowed in type signatures

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0121`.

0 comments on commit 1a1909a

Please sign in to comment.