diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-06-29 20:35:00 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-29 20:35:00 +0200 |
| commit | 05c0b2e397cad7a1aec40b8d9f910e81196a06e8 (patch) | |
| tree | 4c9f9d0a08596d92a0248e1177a5a9da59d25600 | |
| parent | 17d3868c854242593884afcec951fb90015761f2 (diff) | |
| parent | f97326de454583d36fef2efbfeb1ea384b9e9a50 (diff) | |
| download | rust-05c0b2e397cad7a1aec40b8d9f910e81196a06e8.tar.gz rust-05c0b2e397cad7a1aec40b8d9f910e81196a06e8.zip | |
Rollup merge of #98642 - yanchen4791:issue-98260-fix, r=spastorino
Fix #98260 Fixes https://github.com/rust-lang/rust/issues/98260
| -rw-r--r-- | compiler/rustc_typeck/src/variance/mod.rs | 5 | ||||
| -rw-r--r-- | src/test/ui/typeck/issue-98260.rs | 9 | ||||
| -rw-r--r-- | src/test/ui/typeck/issue-98260.stderr | 12 |
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`. |
