about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_typeck/src/variance/mod.rs5
-rw-r--r--src/test/ui/typeck/issue-98260.rs9
-rw-r--r--src/test/ui/typeck/issue-98260.stderr12
3 files changed, 26 insertions, 0 deletions
diff --git a/compiler/rustc_typeck/src/variance/mod.rs b/compiler/rustc_typeck/src/variance/mod.rs
index e622192f2c9..82103c5a03b 100644
--- a/compiler/rustc_typeck/src/variance/mod.rs
+++ b/compiler/rustc_typeck/src/variance/mod.rs
@@ -37,6 +37,11 @@ fn crate_variances(tcx: TyCtxt<'_>, (): ()) -> CrateVariancesMap<'_> {
 }
 
 fn variances_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[ty::Variance] {
+    // Skip items with no generics - there's nothing to infer in them.
+    if tcx.generics_of(item_def_id).count() == 0 {
+        return &[];
+    }
+
     match tcx.def_kind(item_def_id) {
         DefKind::Fn
         | DefKind::AssocFn
diff --git a/src/test/ui/typeck/issue-98260.rs b/src/test/ui/typeck/issue-98260.rs
new file mode 100644
index 00000000000..cf48294e199
--- /dev/null
+++ b/src/test/ui/typeck/issue-98260.rs
@@ -0,0 +1,9 @@
+fn main() {}
+trait A {
+    fn a(aa: B) -> Result<_, B> {
+    //~^ ERROR: the placeholder `_` is not allowed within types on item signatures for return types [E0121]
+        Ok(())
+    }
+}
+
+enum B {}
diff --git a/src/test/ui/typeck/issue-98260.stderr b/src/test/ui/typeck/issue-98260.stderr
new file mode 100644
index 00000000000..08a1d17e244
--- /dev/null
+++ b/src/test/ui/typeck/issue-98260.stderr
@@ -0,0 +1,12 @@
+error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
+  --> $DIR/issue-98260.rs:3:27
+   |
+LL |     fn a(aa: B) -> Result<_, B> {
+   |                    -------^----
+   |                    |      |
+   |                    |      not allowed in type signatures
+   |                    help: replace with the correct return type: `Result<(), B>`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0121`.