Rollup merge of #83739 - JohnTitor:issue-75889, r=estebank

Account for bad placeholder errors on consts/statics with trait objects

Fixes #75889
r? ``@estebank``
This commit is contained in:
Yuki Okushi 2021-06-21 09:42:12 +09:00 committed by GitHub
commit 1a1909a8a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 2 deletions

View file

@ -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);
}
}
_ => (),
}
}

View file

@ -2,5 +2,4 @@ fn foo() -> _ { 5 } //~ ERROR E0121
static BAR: _ = "test"; //~ ERROR E0121
fn main() {
}
fn main() {}

View file

@ -0,0 +1,6 @@
// Regression test for #75889.
const FOO: dyn Fn() -> _ = ""; //~ ERROR E0121
static BOO: dyn Fn() -> _ = ""; //~ ERROR E0121
fn main() {}

View file

@ -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`.