Skip to content

Commit f97326d

Browse files
author
Yan Chen
committed
Fix #98260, added the test case
1 parent 94e9374 commit f97326d

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

compiler/rustc_typeck/src/variance/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ fn crate_variances(tcx: TyCtxt<'_>, (): ()) -> CrateVariancesMap<'_> {
3737
}
3838

3939
fn variances_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[ty::Variance] {
40+
// Skip items with no generics - there's nothing to infer in them.
41+
if tcx.generics_of(item_def_id).count() == 0 {
42+
return &[];
43+
}
44+
4045
match tcx.def_kind(item_def_id) {
4146
DefKind::Fn
4247
| DefKind::AssocFn

src/test/ui/typeck/issue-98260.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fn main() {}
2+
trait A {
3+
fn a(aa: B) -> Result<_, B> {
4+
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for return types [E0121]
5+
Ok(())
6+
}
7+
}
8+
9+
enum B {}

src/test/ui/typeck/issue-98260.stderr

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
2+
--> $DIR/issue-98260.rs:3:27
3+
|
4+
LL | fn a(aa: B) -> Result<_, B> {
5+
| -------^----
6+
| | |
7+
| | not allowed in type signatures
8+
| help: replace with the correct return type: `Result<(), B>`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0121`.

0 commit comments

Comments
 (0)