Skip to content

Commit eff7645

Browse files
committed
Avoid ICE by accounting for missing type
Fix #105330
1 parent 203c876 commit eff7645

File tree

3 files changed

+131
-1
lines changed

3 files changed

+131
-1
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1607,7 +1607,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
16071607
| ObligationCauseCode::ObjectCastObligation(..)
16081608
| ObligationCauseCode::OpaqueType
16091609
);
1610-
let expected_ty = data.term.ty().unwrap();
1610+
let expected_ty = data.term.ty().unwrap_or_else(|| self.tcx.ty_error());
16111611

16121612
// constrain inference variables a bit more to nested obligations from normalize so
16131613
// we can have more helpful errors.

src/test/ui/issues/issue-105330.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
pub trait TraitWAssocConst {
2+
const A: usize;
3+
}
4+
pub struct Demo {}
5+
6+
impl TraitWAssocConst for impl Demo { //~ ERROR E0404
7+
//~^ ERROR E0562
8+
pubconst A: str = 32; //~ ERROR expected one of
9+
}
10+
11+
fn foo<A: TraitWAssocConst<A=32>>() { //~ ERROR E0658
12+
foo::<Demo>()(); //~ ERROR E0271
13+
//~^ ERROR E0618
14+
//~| ERROR E0277
15+
}
16+
17+
fn main<A: TraitWAssocConst<A=32>>() { //~ ERROR E0131
18+
//~^ ERROR E0658
19+
foo::<Demo>(); //~ ERROR E0277
20+
//~^ ERROR E0271
21+
}
+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
error: expected one of `!` or `::`, found `A`
2+
--> $DIR/issue-105330.rs:8:14
3+
|
4+
LL | impl TraitWAssocConst for impl Demo {
5+
| - while parsing this item list starting here
6+
LL |
7+
LL | pubconst A: str = 32;
8+
| ^ expected one of `!` or `::`
9+
LL | }
10+
| - the item list ends here
11+
12+
error[E0404]: expected trait, found struct `Demo`
13+
--> $DIR/issue-105330.rs:6:32
14+
|
15+
LL | impl TraitWAssocConst for impl Demo {
16+
| ^^^^ not a trait
17+
18+
error[E0658]: associated const equality is incomplete
19+
--> $DIR/issue-105330.rs:11:28
20+
|
21+
LL | fn foo<A: TraitWAssocConst<A=32>>() {
22+
| ^^^^
23+
|
24+
= note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information
25+
= help: add `#![feature(associated_const_equality)]` to the crate attributes to enable
26+
27+
error[E0658]: associated const equality is incomplete
28+
--> $DIR/issue-105330.rs:17:29
29+
|
30+
LL | fn main<A: TraitWAssocConst<A=32>>() {
31+
| ^^^^
32+
|
33+
= note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information
34+
= help: add `#![feature(associated_const_equality)]` to the crate attributes to enable
35+
36+
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type
37+
--> $DIR/issue-105330.rs:6:27
38+
|
39+
LL | impl TraitWAssocConst for impl Demo {
40+
| ^^^^^^^^^
41+
42+
error[E0277]: the trait bound `Demo: TraitWAssocConst` is not satisfied
43+
--> $DIR/issue-105330.rs:12:11
44+
|
45+
LL | foo::<Demo>()();
46+
| ^^^^ the trait `TraitWAssocConst` is not implemented for `Demo`
47+
|
48+
note: required by a bound in `foo`
49+
--> $DIR/issue-105330.rs:11:11
50+
|
51+
LL | fn foo<A: TraitWAssocConst<A=32>>() {
52+
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo`
53+
54+
error[E0271]: type mismatch resolving `<Demo as TraitWAssocConst>::A == 32`
55+
--> $DIR/issue-105330.rs:12:11
56+
|
57+
LL | foo::<Demo>()();
58+
| ^^^^ types differ
59+
|
60+
note: required by a bound in `foo`
61+
--> $DIR/issue-105330.rs:11:28
62+
|
63+
LL | fn foo<A: TraitWAssocConst<A=32>>() {
64+
| ^^^^ required by this bound in `foo`
65+
66+
error[E0618]: expected function, found `()`
67+
--> $DIR/issue-105330.rs:12:5
68+
|
69+
LL | fn foo<A: TraitWAssocConst<A=32>>() {
70+
| ----------------------------------- `foo::<Demo>` defined here returns `()`
71+
LL | foo::<Demo>()();
72+
| ^^^^^^^^^^^^^--
73+
| |
74+
| call expression requires function
75+
76+
error[E0277]: the trait bound `Demo: TraitWAssocConst` is not satisfied
77+
--> $DIR/issue-105330.rs:19:11
78+
|
79+
LL | foo::<Demo>();
80+
| ^^^^ the trait `TraitWAssocConst` is not implemented for `Demo`
81+
|
82+
note: required by a bound in `foo`
83+
--> $DIR/issue-105330.rs:11:11
84+
|
85+
LL | fn foo<A: TraitWAssocConst<A=32>>() {
86+
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo`
87+
88+
error[E0271]: type mismatch resolving `<Demo as TraitWAssocConst>::A == 32`
89+
--> $DIR/issue-105330.rs:19:11
90+
|
91+
LL | foo::<Demo>();
92+
| ^^^^ types differ
93+
|
94+
note: required by a bound in `foo`
95+
--> $DIR/issue-105330.rs:11:28
96+
|
97+
LL | fn foo<A: TraitWAssocConst<A=32>>() {
98+
| ^^^^ required by this bound in `foo`
99+
100+
error[E0131]: `main` function is not allowed to have generic parameters
101+
--> $DIR/issue-105330.rs:17:8
102+
|
103+
LL | fn main<A: TraitWAssocConst<A=32>>() {
104+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `main` cannot have generic parameters
105+
106+
error: aborting due to 11 previous errors
107+
108+
Some errors have detailed explanations: E0131, E0271, E0277, E0404, E0562, E0618, E0658.
109+
For more information about an error, try `rustc --explain E0131`.

0 commit comments

Comments
 (0)