Skip to content

Commit a60e267

Browse files
committed
Do not check transmute if has non region infer
Signed-off-by: hi-rustin <[email protected]>
1 parent a28f3c8 commit a60e267

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

compiler/rustc_hir_typeck/src/intrinsicck.rs

Lines changed: 5 additions & 2 deletions
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+
// We can't check anything if there are 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

Lines changed: 10 additions & 0 deletions
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() {}
Lines changed: 9 additions & 0 deletions
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)