]> git.lizzy.rs Git - rust.git/commitdiff
Fix #98260, added the test case
authorYan Chen <ychen2@futurewei.com>
Tue, 28 Jun 2022 19:46:42 +0000 (12:46 -0700)
committerYan Chen <ychen2@futurewei.com>
Tue, 28 Jun 2022 22:20:30 +0000 (15:20 -0700)
compiler/rustc_typeck/src/variance/mod.rs
src/test/ui/typeck/issue-98260.rs [new file with mode: 0644]
src/test/ui/typeck/issue-98260.stderr [new file with mode: 0644]

index e622192f2c94dab0b2fb10010938780275e3b509..82103c5a03b6e04fe52fcf2ba3ba2af3ed57b1f5 100644 (file)
@@ -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 (file)
index 0000000..cf48294
--- /dev/null
@@ -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 (file)
index 0000000..08a1d17
--- /dev/null
@@ -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`.