about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <yuki.okushi@huawei.com>2021-06-10 12:06:47 +0900
committerYuki Okushi <yuki.okushi@huawei.com>2021-06-10 12:06:47 +0900
commit052d77ea5669380fafbc210b517e51f7c7281c68 (patch)
treed8ec00af7a7140650cdb36efa49e3a65463edb75
parenteab201df7028ebb6812c0b1a01702ac6ecfcceed (diff)
downloadrust-052d77ea5669380fafbc210b517e51f7c7281c68.tar.gz
rust-052d77ea5669380fafbc210b517e51f7c7281c68.zip
Account for bad placeholder errors on consts/statics with trait objects
-rw-r--r--compiler/rustc_typeck/src/collect.rs8
-rw-r--r--src/test/ui/error-codes/E0121.rs3
-rw-r--r--src/test/ui/typeck/issue-75889.rs6
-rw-r--r--src/test/ui/typeck/issue-75889.stderr15
4 files changed, 30 insertions, 2 deletions
diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs
index ee3ac3b62d9..89bfb77b855 100644
--- a/compiler/rustc_typeck/src/collect.rs
+++ b/compiler/rustc_typeck/src/collect.rs
@@ -808,6 +808,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);
+                    }
+                }
                 _ => (),
             }
         }
diff --git a/src/test/ui/error-codes/E0121.rs b/src/test/ui/error-codes/E0121.rs
index f8b4d61b323..98cd6d54c1f 100644
--- a/src/test/ui/error-codes/E0121.rs
+++ b/src/test/ui/error-codes/E0121.rs
@@ -2,5 +2,4 @@ fn foo() -> _ { 5 } //~ ERROR E0121
 
 static BAR: _ = "test"; //~ ERROR E0121
 
-fn main() {
-}
+fn main() {}
diff --git a/src/test/ui/typeck/issue-75889.rs b/src/test/ui/typeck/issue-75889.rs
new file mode 100644
index 00000000000..84c067ed0c7
--- /dev/null
+++ b/src/test/ui/typeck/issue-75889.rs
@@ -0,0 +1,6 @@
+// Regression test for #75889.
+
+const FOO: dyn Fn() -> _ = ""; //~ ERROR E0121
+static BOO: dyn Fn() -> _ = ""; //~ ERROR E0121
+
+fn main() {}
diff --git a/src/test/ui/typeck/issue-75889.stderr b/src/test/ui/typeck/issue-75889.stderr
new file mode 100644
index 00000000000..0a8a3c9e743
--- /dev/null
+++ b/src/test/ui/typeck/issue-75889.stderr
@@ -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`.