From a60e267200c9cdfe8295855eb2d9ad02ad73a087 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Mon, 21 Nov 2022 09:03:33 +0800 Subject: [PATCH 1/2] Do not check transmute if has non region infer Signed-off-by: hi-rustin --- compiler/rustc_hir_typeck/src/intrinsicck.rs | 7 +++++-- src/test/ui/consts/issue-104609.rs | 10 ++++++++++ src/test/ui/consts/issue-104609.stderr | 9 +++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/consts/issue-104609.rs create mode 100644 src/test/ui/consts/issue-104609.stderr diff --git a/compiler/rustc_hir_typeck/src/intrinsicck.rs b/compiler/rustc_hir_typeck/src/intrinsicck.rs index 9812d96fcc3..c9878e381a9 100644 --- a/compiler/rustc_hir_typeck/src/intrinsicck.rs +++ b/compiler/rustc_hir_typeck/src/intrinsicck.rs @@ -3,7 +3,7 @@ use rustc_hir as hir; use rustc_index::vec::Idx; use rustc_middle::ty::layout::{LayoutError, SizeSkeleton}; -use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitable}; use rustc_target::abi::{Pointer, VariantIdx}; use super::FnCtxt; @@ -46,7 +46,10 @@ pub fn check_transmute(&self, from: Ty<'tcx>, to: Ty<'tcx>, hir_id: HirId) { let from = normalize(from); let to = normalize(to); trace!(?from, ?to); - + if from.has_non_region_infer() || to.has_non_region_infer() { + // We can't check anything if there are inference variables. + return; + } // Transmutes that are only changing lifetimes are always ok. if from == to { return; diff --git a/src/test/ui/consts/issue-104609.rs b/src/test/ui/consts/issue-104609.rs new file mode 100644 index 00000000000..01fd1c48cf8 --- /dev/null +++ b/src/test/ui/consts/issue-104609.rs @@ -0,0 +1,10 @@ +fn foo() { + oops; + //~^ ERROR: cannot find value `oops` in this scope +} + +unsafe fn bar() { + std::mem::transmute::<_, *mut _>(1_u8); +} + +fn main() {} diff --git a/src/test/ui/consts/issue-104609.stderr b/src/test/ui/consts/issue-104609.stderr new file mode 100644 index 00000000000..00360c44d61 --- /dev/null +++ b/src/test/ui/consts/issue-104609.stderr @@ -0,0 +1,9 @@ +error[E0425]: cannot find value `oops` in this scope + --> $DIR/issue-104609.rs:2:5 + | +LL | oops; + | ^^^^ not found in this scope + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0425`. From fec6ffc8164692c9acc64078126275a2c2b99bcb Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Mon, 21 Nov 2022 20:03:28 +0800 Subject: [PATCH 2/2] Add delay span bug Signed-off-by: hi-rustin --- compiler/rustc_hir_typeck/src/intrinsicck.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_hir_typeck/src/intrinsicck.rs b/compiler/rustc_hir_typeck/src/intrinsicck.rs index c9878e381a9..c2dc1402465 100644 --- a/compiler/rustc_hir_typeck/src/intrinsicck.rs +++ b/compiler/rustc_hir_typeck/src/intrinsicck.rs @@ -47,7 +47,7 @@ pub fn check_transmute(&self, from: Ty<'tcx>, to: Ty<'tcx>, hir_id: HirId) { let to = normalize(to); trace!(?from, ?to); if from.has_non_region_infer() || to.has_non_region_infer() { - // We can't check anything if there are inference variables. + tcx.sess.delay_span_bug(span, "argument to transmute has inference variables"); return; } // Transmutes that are only changing lifetimes are always ok.