Skip to content

Commit e2b4654

Browse files
Flush errors before deep normalize in dropck_outlives
1 parent 3799d84 commit e2b4654

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs

+8
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ where
196196
debug!("dropck_outlives: ty from dtorck_types = {:?}", ty);
197197
ty
198198
} else {
199+
// Flush errors b/c `deeply_normalize` doesn't expect pending
200+
// obligations, and we may have pending obligations from the
201+
// branch above (from other types).
202+
let errors = ocx.select_all_or_error();
203+
if !errors.is_empty() {
204+
return Err(errors);
205+
}
206+
199207
ocx.deeply_normalize(&cause, param_env, ty)?;
200208

201209
let errors = ocx.select_where_possible();
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Test that we don't ICE when computing the drop types for
2+
3+
trait Decode<'a> {
4+
type Decoder;
5+
}
6+
7+
trait NonImplementedTrait {
8+
type Assoc;
9+
}
10+
struct NonImplementedStruct;
11+
12+
pub struct ADecoder<'a> {
13+
b: <B as Decode<'a>>::Decoder,
14+
}
15+
fn make_a_decoder<'a>() -> ADecoder<'a> {
16+
//~^ ERROR the trait bound
17+
//~| ERROR the trait bound
18+
panic!()
19+
}
20+
21+
struct B;
22+
impl<'a> Decode<'a> for B {
23+
type Decoder = BDecoder;
24+
//~^ ERROR the trait bound
25+
}
26+
pub struct BDecoder {
27+
non_implemented: <NonImplementedStruct as NonImplementedTrait>::Assoc,
28+
//~^ ERROR the trait bound
29+
}
30+
31+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied in `ADecoder<'a>`
2+
--> $DIR/dropck-normalize-errors.rs:15:28
3+
|
4+
LL | fn make_a_decoder<'a>() -> ADecoder<'a> {
5+
| ^^^^^^^^^^^^ within `ADecoder<'a>`, the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct`
6+
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/dropck-normalize-errors.rs:7:1
9+
|
10+
LL | trait NonImplementedTrait {
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
12+
note: required because it appears within the type `BDecoder`
13+
--> $DIR/dropck-normalize-errors.rs:26:12
14+
|
15+
LL | pub struct BDecoder {
16+
| ^^^^^^^^
17+
note: required because it appears within the type `ADecoder<'a>`
18+
--> $DIR/dropck-normalize-errors.rs:12:12
19+
|
20+
LL | pub struct ADecoder<'a> {
21+
| ^^^^^^^^
22+
= note: the return type of a function must have a statically known size
23+
24+
error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied in `BDecoder`
25+
--> $DIR/dropck-normalize-errors.rs:23:20
26+
|
27+
LL | type Decoder = BDecoder;
28+
| ^^^^^^^^ within `BDecoder`, the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct`
29+
|
30+
help: this trait has no implementations, consider adding one
31+
--> $DIR/dropck-normalize-errors.rs:7:1
32+
|
33+
LL | trait NonImplementedTrait {
34+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
35+
note: required because it appears within the type `BDecoder`
36+
--> $DIR/dropck-normalize-errors.rs:26:12
37+
|
38+
LL | pub struct BDecoder {
39+
| ^^^^^^^^
40+
note: required by a bound in `Decode::Decoder`
41+
--> $DIR/dropck-normalize-errors.rs:4:5
42+
|
43+
LL | type Decoder;
44+
| ^^^^^^^^^^^^^ required by this bound in `Decode::Decoder`
45+
help: consider relaxing the implicit `Sized` restriction
46+
|
47+
LL | type Decoder: ?Sized;
48+
| ++++++++
49+
50+
error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied
51+
--> $DIR/dropck-normalize-errors.rs:27:22
52+
|
53+
LL | non_implemented: <NonImplementedStruct as NonImplementedTrait>::Assoc,
54+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct`
55+
|
56+
help: this trait has no implementations, consider adding one
57+
--> $DIR/dropck-normalize-errors.rs:7:1
58+
|
59+
LL | trait NonImplementedTrait {
60+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
61+
62+
error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied
63+
--> $DIR/dropck-normalize-errors.rs:15:28
64+
|
65+
LL | fn make_a_decoder<'a>() -> ADecoder<'a> {
66+
| ^^^^^^^^^^^^ the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct`
67+
|
68+
help: this trait has no implementations, consider adding one
69+
--> $DIR/dropck-normalize-errors.rs:7:1
70+
|
71+
LL | trait NonImplementedTrait {
72+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
73+
74+
error: aborting due to 4 previous errors
75+
76+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)