Skip to content

Commit 9cefd9d

Browse files
authored
Rollup merge of #104657 - hi-rustin:rustin-patch-check-transmute, r=compiler-errors
Do not check transmute if has non region infer close #104609 See: #104609 (comment) r? `@compiler-errors`
2 parents 89be53d + fec6ffc commit 9cefd9d

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

compiler/rustc_hir_typeck/src/intrinsicck.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_errors::struct_span_err;
33
use rustc_hir as hir;
44
use rustc_index::vec::Idx;
55
use rustc_middle::ty::layout::{LayoutError, SizeSkeleton};
6-
use rustc_middle::ty::{self, Ty, TyCtxt};
6+
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitable};
77
use rustc_target::abi::{Pointer, VariantIdx};
88

99
use super::FnCtxt;
@@ -46,7 +46,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
4646
let from = normalize(from);
4747
let to = normalize(to);
4848
trace!(?from, ?to);
49-
49+
if from.has_non_region_infer() || to.has_non_region_infer() {
50+
tcx.sess.delay_span_bug(span, "argument to transmute has inference variables");
51+
return;
52+
}
5053
// Transmutes that are only changing lifetimes are always ok.
5154
if from == to {
5255
return;

src/test/ui/consts/issue-104609.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fn foo() {
2+
oops;
3+
//~^ ERROR: cannot find value `oops` in this scope
4+
}
5+
6+
unsafe fn bar() {
7+
std::mem::transmute::<_, *mut _>(1_u8);
8+
}
9+
10+
fn main() {}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0425]: cannot find value `oops` in this scope
2+
--> $DIR/issue-104609.rs:2:5
3+
|
4+
LL | oops;
5+
| ^^^^ not found in this scope
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)