]> git.lizzy.rs Git - rust.git/commitdiff
`HirId` for `deferred_transmute_checks`
authorlcnr <rust@lcnr.de>
Mon, 3 Oct 2022 11:49:31 +0000 (13:49 +0200)
committerlcnr <rust@lcnr.de>
Mon, 3 Oct 2022 11:53:17 +0000 (13:53 +0200)
compiler/rustc_hir_analysis/src/check/expr.rs
compiler/rustc_hir_analysis/src/check/fn_ctxt/checks.rs
compiler/rustc_hir_analysis/src/check/inherited.rs
compiler/rustc_hir_analysis/src/check/intrinsicck.rs

index 09362eab673e83faf667157c8173e9a8942bb986..b9459887c4617d460673bdc39b88aef63a6bf034 100644 (file)
@@ -542,7 +542,7 @@ pub(crate) fn check_expr_path(
                 // been resolved or we errored. This is important as we can only check transmute
                 // on concrete types, but the output type may not be known yet (it would only
                 // be known if explicitly specified via turbofish).
-                self.deferred_transmute_checks.borrow_mut().push((from, to, expr.span));
+                self.deferred_transmute_checks.borrow_mut().push((from, to, expr.hir_id));
             }
             if !tcx.features().unsized_fn_params {
                 // We want to remove some Sized bounds from std functions,
index 55902aafb35d053e82790eff3e78549494a53012..44d7973d6320463cc5739a53adfbe39e35345b34 100644 (file)
@@ -50,8 +50,8 @@ pub(in super::super) fn check_casts(&self) {
     pub(in super::super) fn check_transmutes(&self) {
         let mut deferred_transmute_checks = self.deferred_transmute_checks.borrow_mut();
         debug!("FnCtxt::check_transmutes: {} deferred checks", deferred_transmute_checks.len());
-        for (from, to, span) in deferred_transmute_checks.drain(..) {
-            self.check_transmute(span, from, to);
+        for (from, to, hir_id) in deferred_transmute_checks.drain(..) {
+            self.check_transmute(from, to, hir_id);
         }
     }
 
index 37c830d4e3850f14c63e2ce1b918b8ae70ae0997..2546227e138583fbb625b8d9fd51d45fe4d598cb 100644 (file)
@@ -55,7 +55,7 @@ pub struct Inherited<'a, 'tcx> {
 
     pub(super) deferred_cast_checks: RefCell<Vec<super::cast::CastCheck<'tcx>>>,
 
-    pub(super) deferred_transmute_checks: RefCell<Vec<(Ty<'tcx>, Ty<'tcx>, Span)>>,
+    pub(super) deferred_transmute_checks: RefCell<Vec<(Ty<'tcx>, Ty<'tcx>, hir::HirId)>>,
 
     pub(super) deferred_asm_checks: RefCell<Vec<(&'tcx hir::InlineAsm<'tcx>, hir::HirId)>>,
 
index c604c8af8d25d6aff1f664f9637735484083e622..13a800304158b269dddade5a7566e958085a2f6a 100644 (file)
@@ -1,3 +1,4 @@
+use hir::HirId;
 use rustc_ast::InlineAsmTemplatePiece;
 use rustc_data_structures::fx::FxHashSet;
 use rustc_errors::struct_span_err;
@@ -6,7 +7,7 @@
 use rustc_middle::ty::layout::{LayoutError, SizeSkeleton};
 use rustc_middle::ty::{self, Article, FloatTy, IntTy, Ty, TyCtxt, TypeVisitable, UintTy};
 use rustc_session::lint;
-use rustc_span::{Span, Symbol, DUMMY_SP};
+use rustc_span::{Symbol, DUMMY_SP};
 use rustc_target::abi::{Pointer, VariantIdx};
 use rustc_target::asm::{InlineAsmReg, InlineAsmRegClass, InlineAsmRegOrRegClass, InlineAsmType};
 
@@ -40,11 +41,13 @@ fn unpack_option_like<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
 }
 
 impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
-    pub fn check_transmute(&self, span: Span, from: Ty<'tcx>, to: Ty<'tcx>) {
+    pub fn check_transmute(&self, from: Ty<'tcx>, to: Ty<'tcx>, hir_id: HirId) {
+        let tcx = self.tcx;
+        let span = tcx.hir().span(hir_id);
         let convert = |ty: Ty<'tcx>| {
             let ty = self.resolve_vars_if_possible(ty);
-            let ty = self.tcx.normalize_erasing_regions(self.param_env, ty);
-            (SizeSkeleton::compute(ty, self.tcx, self.param_env), ty)
+            let ty = tcx.normalize_erasing_regions(self.param_env, ty);
+            (SizeSkeleton::compute(ty, tcx, self.param_env), ty)
         };
         let (sk_from, from) = convert(from);
         let (sk_to, to) = convert(to);
@@ -57,9 +60,9 @@ pub fn check_transmute(&self, span: Span, from: Ty<'tcx>, to: Ty<'tcx>) {
 
             // Special-case transmuting from `typeof(function)` and
             // `Option<typeof(function)>` to present a clearer error.
-            let from = unpack_option_like(self.tcx, from);
-            if let (&ty::FnDef(..), SizeSkeleton::Known(size_to)) = (from.kind(), sk_to) && size_to == Pointer.size(&self.tcx) {
-                struct_span_err!(self.tcx.sess, span, E0591, "can't transmute zero-sized type")
+            let from = unpack_option_like(tcx, from);
+            if let (&ty::FnDef(..), SizeSkeleton::Known(size_to)) = (from.kind(), sk_to) && size_to == Pointer.size(&tcx) {
+                struct_span_err!(tcx.sess, span, E0591, "can't transmute zero-sized type")
                     .note(&format!("source type: {from}"))
                     .note(&format!("target type: {to}"))
                     .help("cast with `as` to a pointer instead")
@@ -83,7 +86,7 @@ pub fn check_transmute(&self, span: Span, from: Ty<'tcx>, to: Ty<'tcx>) {
         };
 
         let mut err = struct_span_err!(
-            self.tcx.sess,
+            tcx.sess,
             span,
             E0512,
             "cannot transmute between types of different sizes, \