Skip to content

Commit d178fce

Browse files
committed
Add specific diagnostic for transmuting between equal associated types
1 parent 6cb1d95 commit d178fce

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/librustc/middle/intrinsicck.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,12 @@ impl<'a, 'tcx> ExprVisitor<'a, 'tcx> {
113113
let mut err = struct_span_err!(self.tcx.sess, span, E0512,
114114
"cannot transmute between types of different sizes, \
115115
or dependently-sized types");
116+
if from == to {
117+
err.note(&format!("`{}` does not have a fixed size", from));
118+
} else {
116119
err.note(&format!("source type: `{}` ({})", from, skeleton_string(from, sk_from)))
117120
.note(&format!("target type: `{}` ({})", to, skeleton_string(to, sk_to)));
121+
}
118122
err.emit()
119123
}
120124
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trait Foo {
2+
type Bar;
3+
}
4+
5+
unsafe fn noop<F: Foo>(foo: F::Bar) -> F::Bar {
6+
::std::mem::transmute(foo) //~ ERROR cannot transmute between types of different sizes
7+
}
8+
9+
fn main() {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
2+
--> $DIR/transmute-equal-assoc-types.rs:6:5
3+
|
4+
LL | ::std::mem::transmute(foo) //~ ERROR cannot transmute between types of different sizes
5+
| ^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `<F as Foo>::Bar` does not have a fixed size
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0512`.

0 commit comments

Comments
 (0)