From f97326de454583d36fef2efbfeb1ea384b9e9a50 Mon Sep 17 00:00:00 2001 From: Yan Chen Date: Tue, 28 Jun 2022 12:46:42 -0700 Subject: [PATCH] Fix #98260, added the test case --- compiler/rustc_typeck/src/variance/mod.rs | 5 +++++ src/test/ui/typeck/issue-98260.rs | 9 +++++++++ src/test/ui/typeck/issue-98260.stderr | 12 ++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 src/test/ui/typeck/issue-98260.rs create mode 100644 src/test/ui/typeck/issue-98260.stderr diff --git a/compiler/rustc_typeck/src/variance/mod.rs b/compiler/rustc_typeck/src/variance/mod.rs index e622192f2c94d..82103c5a03b6e 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 0000000000000..cf48294e1997f --- /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 0000000000000..08a1d17e244a8 --- /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`.