Skip to content

Commit 708f053

Browse files
Add test for #65774
Closes #65774
1 parent f94eaea commit 708f053

File tree

4 files changed

+148
-0
lines changed

4 files changed

+148
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#![feature(associated_type_defaults)]
2+
3+
trait MyDisplay { fn method(&self) { } }
4+
5+
impl<'a, T: MyDisplay> MyDisplay for &'a mut T { }
6+
7+
struct T;
8+
9+
trait MPU {
10+
type MpuConfig: MyDisplay = T;
11+
//~^ ERROR the trait bound `T: MyDisplay` is not satisfied
12+
}
13+
14+
struct S;
15+
16+
impl MPU for S { }
17+
//~^ ERROR the trait bound `T: MyDisplay` is not satisfied
18+
19+
trait MyWrite {
20+
fn my_write(&self, _: &dyn MyDisplay) { }
21+
}
22+
23+
trait ProcessType {
24+
fn process_detail_fmt(&self, _: &mut dyn MyWrite);
25+
}
26+
27+
struct Process;
28+
29+
impl ProcessType for Process {
30+
fn process_detail_fmt(&self, writer: &mut dyn MyWrite)
31+
{
32+
33+
let mut val: Option<<S as MPU>::MpuConfig> = None;
34+
let valref: &mut <S as MPU>::MpuConfig = val.as_mut().unwrap();
35+
36+
// // This causes a different ICE (but its similar if you squint right):
37+
// //
38+
// // `Unimplemented` selecting `Binder(<T as MyDisplay>)` during codegen
39+
//
40+
// writer.my_write(valref)
41+
42+
// This one causes the ICE:
43+
// FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<T as MyDisplay>)), depth=1),Unimplemented)
44+
let closure = |config: &mut <S as MPU>::MpuConfig| writer.my_write(&config);
45+
closure(valref);
46+
}
47+
}
48+
49+
fn create() -> &'static dyn ProcessType {
50+
let input: Option<&mut Process> = None;
51+
let process: &mut Process = input.unwrap();
52+
process
53+
}
54+
55+
pub fn main() {
56+
create();
57+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0277]: the trait bound `T: MyDisplay` is not satisfied
2+
--> $DIR/issue-65774-1.rs:10:21
3+
|
4+
LL | trait MPU {
5+
| --------- required by `MPU`
6+
LL | type MpuConfig: MyDisplay = T;
7+
| ^^^^^^^^^ the trait `MyDisplay` is not implemented for `T`
8+
9+
error[E0277]: the trait bound `T: MyDisplay` is not satisfied
10+
--> $DIR/issue-65774-1.rs:16:6
11+
|
12+
LL | impl MPU for S { }
13+
| ^^^ the trait `MyDisplay` is not implemented for `T`
14+
15+
error: aborting due to 2 previous errors
16+
17+
For more information about this error, try `rustc --explain E0277`.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#![feature(associated_type_defaults)]
2+
3+
trait MyDisplay { fn method(&self) { } }
4+
5+
impl<'a, T: MyDisplay> MyDisplay for &'a mut T { }
6+
7+
struct T;
8+
9+
trait MPU {
10+
type MpuConfig: MyDisplay = T;
11+
//~^ ERROR the trait bound `T: MyDisplay` is not satisfied
12+
}
13+
14+
struct S;
15+
16+
impl MPU for S { }
17+
//~^ ERROR the trait bound `T: MyDisplay` is not satisfied
18+
19+
trait MyWrite {
20+
fn my_write(&self, _: &dyn MyDisplay) { }
21+
}
22+
23+
trait ProcessType {
24+
fn process_detail_fmt(&self, _: &mut dyn MyWrite);
25+
}
26+
27+
struct Process;
28+
29+
impl ProcessType for Process {
30+
fn process_detail_fmt(&self, writer: &mut dyn MyWrite)
31+
{
32+
33+
let mut val: Option<<S as MPU>::MpuConfig> = None;
34+
let valref: &mut <S as MPU>::MpuConfig = val.as_mut().unwrap();
35+
36+
// // This causes a different ICE (but its similar if you squint right):
37+
// //
38+
// // `Unimplemented` selecting `Binder(<T as MyDisplay>)` during codegen
39+
//
40+
writer.my_write(valref)
41+
42+
// This one causes the ICE:
43+
// FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<T as MyDisplay>)), depth=1),Unimplemented)
44+
/*let closure = |config: &mut <S as MPU>::MpuConfig| writer.my_write(&config);
45+
closure(valref);*/
46+
}
47+
}
48+
49+
fn create() -> &'static dyn ProcessType {
50+
let input: Option<&mut Process> = None;
51+
let process: &mut Process = input.unwrap();
52+
process
53+
}
54+
55+
pub fn main() {
56+
create();
57+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0277]: the trait bound `T: MyDisplay` is not satisfied
2+
--> $DIR/issue-65774-2.rs:10:21
3+
|
4+
LL | trait MPU {
5+
| --------- required by `MPU`
6+
LL | type MpuConfig: MyDisplay = T;
7+
| ^^^^^^^^^ the trait `MyDisplay` is not implemented for `T`
8+
9+
error[E0277]: the trait bound `T: MyDisplay` is not satisfied
10+
--> $DIR/issue-65774-2.rs:16:6
11+
|
12+
LL | impl MPU for S { }
13+
| ^^^ the trait `MyDisplay` is not implemented for `T`
14+
15+
error: aborting due to 2 previous errors
16+
17+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)