Skip to content

Commit d1478a5

Browse files
author
Yiming Lei
committed
delay E0512 as a bug by checking the references_error
fix #106695
1 parent 1bc3683 commit d1478a5

File tree

5 files changed

+15
-26
lines changed

5 files changed

+15
-26
lines changed

compiler/rustc_hir_typeck/src/intrinsicck.rs

+10
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
105105
} else {
106106
err.note(&format!("source type: `{}` ({})", from, skeleton_string(from, sk_from)))
107107
.note(&format!("target type: `{}` ({})", to, skeleton_string(to, sk_to)));
108+
let mut should_delay_as_bug = false;
109+
if let Err(LayoutError::Unknown(bad_from)) = sk_from && bad_from.references_error() {
110+
should_delay_as_bug = true;
111+
}
112+
if let Err(LayoutError::Unknown(bad_to)) = sk_to && bad_to.references_error() {
113+
should_delay_as_bug = true;
114+
}
115+
if should_delay_as_bug {
116+
err.delay_as_bug();
117+
}
108118
}
109119
err.emit();
110120
}

tests/ui/type-alias-impl-trait/issue-53092-2.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
type Bug<T, U> = impl Fn(T) -> U + Copy; //~ ERROR cycle detected
55

66
const CONST_BUG: Bug<u8, ()> = unsafe { std::mem::transmute(|_: u8| ()) };
7-
//~^ ERROR: cannot transmute
87

98
fn make_bug<T, U: From<T>>() -> Bug<T, U> {
109
|x| x.into() //~ ERROR the trait bound `U: From<T>` is not satisfied

tests/ui/type-alias-impl-trait/issue-53092-2.stderr

+4-13
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,14 @@ LL | | CONST_BUG(0);
2424
LL | | }
2525
| |_^
2626

27-
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
28-
--> $DIR/issue-53092-2.rs:6:41
29-
|
30-
LL | const CONST_BUG: Bug<u8, ()> = unsafe { std::mem::transmute(|_: u8| ()) };
31-
| ^^^^^^^^^^^^^^^^^^^
32-
|
33-
= note: source type: `[closure@$DIR/issue-53092-2.rs:6:61: 6:68]` (0 bits)
34-
= note: target type: `Bug<u8, ()>` (size can vary because of [type error])
35-
3627
error[E0277]: the trait bound `U: From<T>` is not satisfied
37-
--> $DIR/issue-53092-2.rs:10:5
28+
--> $DIR/issue-53092-2.rs:9:5
3829
|
3930
LL | |x| x.into()
4031
| ^^^^^^^^^^^^ the trait `From<T>` is not implemented for `U`
4132
|
4233
note: required by a bound in `make_bug`
43-
--> $DIR/issue-53092-2.rs:9:19
34+
--> $DIR/issue-53092-2.rs:8:19
4435
|
4536
LL | fn make_bug<T, U: From<T>>() -> Bug<T, U> {
4637
| ^^^^^^^ required by this bound in `make_bug`
@@ -49,7 +40,7 @@ help: consider restricting type parameter `U`
4940
LL | type Bug<T, U: std::convert::From<T>> = impl Fn(T) -> U + Copy;
5041
| +++++++++++++++++++++++
5142

52-
error: aborting due to 3 previous errors
43+
error: aborting due to 2 previous errors
5344

54-
Some errors have detailed explanations: E0277, E0391, E0512.
45+
Some errors have detailed explanations: E0277, E0391.
5546
For more information about an error, try `rustc --explain E0277`.

tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@ mod foo {
1515

1616
fn main() {
1717
let _: foo::Foo = std::mem::transmute(0u8);
18-
//~^ ERROR cannot transmute between types of different sizes, or dependently-sized types
1918
}

tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.stderr

+1-11
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,5 @@ LL | pub type Foo = impl Copy;
66
|
77
= note: `Foo` must be used in combination with a concrete type within the same module
88

9-
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
10-
--> $DIR/no_inferrable_concrete_type.rs:17:23
11-
|
12-
LL | let _: foo::Foo = std::mem::transmute(0u8);
13-
| ^^^^^^^^^^^^^^^^^^^
14-
|
15-
= note: source type: `u8` (8 bits)
16-
= note: target type: `Foo` (size can vary because of [type error])
17-
18-
error: aborting due to 2 previous errors
9+
error: aborting due to previous error
1910

20-
For more information about this error, try `rustc --explain E0512`.

0 commit comments

Comments
 (0)