From 5f58985f5df2e7fbbef6c1acf54ece9df90ccbf3 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 28 Feb 2025 16:34:41 +1100 Subject: [PATCH] Remove `rustc_transmute`'s dependence on `rustc_infer`. `TransmuteTypeEnv` only needs a `TyCtxt`, not an `InferCtxt`. --- Cargo.lock | 1 - .../error_reporting/traits/fulfillment_errors.rs | 2 +- .../rustc_trait_selection/src/solve/delegate.rs | 2 +- .../src/traits/select/confirmation.rs | 2 +- compiler/rustc_transmute/Cargo.toml | 2 -- compiler/rustc_transmute/src/lib.rs | 13 ++++++------- 6 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fb4cf235c6f..4cb87ec4413 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4500,7 +4500,6 @@ dependencies = [ "rustc_abi", "rustc_data_structures", "rustc_hir", - "rustc_infer", "rustc_macros", "rustc_middle", "rustc_span", diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index 596f794568c..b2cc1804673 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -2544,7 +2544,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let src = trait_pred.trait_ref.args.type_at(1); let err_msg = format!("`{src}` cannot be safely transmuted into `{dst}`"); - match rustc_transmute::TransmuteTypeEnv::new(self.infcx).is_transmutable( + match rustc_transmute::TransmuteTypeEnv::new(self.infcx.tcx).is_transmutable( obligation.cause, src_and_dst, assume, diff --git a/compiler/rustc_trait_selection/src/solve/delegate.rs b/compiler/rustc_trait_selection/src/solve/delegate.rs index 58d8a3a6254..550ffe8cc3b 100644 --- a/compiler/rustc_trait_selection/src/solve/delegate.rs +++ b/compiler/rustc_trait_selection/src/solve/delegate.rs @@ -236,7 +236,7 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate< }; // FIXME(transmutability): This really should be returning nested goals for `Answer::If*` - match rustc_transmute::TransmuteTypeEnv::new(&self.0).is_transmutable( + match rustc_transmute::TransmuteTypeEnv::new(self.0.tcx).is_transmutable( ObligationCause::dummy(), rustc_transmute::Types { src, dst }, assume, diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 32cbb97e314..53c61c15a21 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -424,7 +424,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let src = predicate.trait_ref.args.type_at(1); debug!(?src, ?dst); - let mut transmute_env = rustc_transmute::TransmuteTypeEnv::new(self.infcx); + let mut transmute_env = rustc_transmute::TransmuteTypeEnv::new(self.infcx.tcx); let maybe_transmutable = transmute_env.is_transmutable( obligation.cause.clone(), rustc_transmute::Types { dst, src }, diff --git a/compiler/rustc_transmute/Cargo.toml b/compiler/rustc_transmute/Cargo.toml index e9daf6b0c38..3b6bb59196e 100644 --- a/compiler/rustc_transmute/Cargo.toml +++ b/compiler/rustc_transmute/Cargo.toml @@ -8,7 +8,6 @@ edition = "2024" rustc_abi = { path = "../rustc_abi", optional = true } rustc_data_structures = { path = "../rustc_data_structures" } rustc_hir = { path = "../rustc_hir", optional = true } -rustc_infer = { path = "../rustc_infer", optional = true } rustc_macros = { path = "../rustc_macros", optional = true } rustc_middle = { path = "../rustc_middle", optional = true } rustc_span = { path = "../rustc_span", optional = true } @@ -19,7 +18,6 @@ tracing = "0.1" rustc = [ "dep:rustc_abi", "dep:rustc_hir", - "dep:rustc_infer", "dep:rustc_macros", "dep:rustc_middle", "dep:rustc_span", diff --git a/compiler/rustc_transmute/src/lib.rs b/compiler/rustc_transmute/src/lib.rs index f9537f708ef..9726c9e98aa 100644 --- a/compiler/rustc_transmute/src/lib.rs +++ b/compiler/rustc_transmute/src/lib.rs @@ -81,7 +81,6 @@ pub enum Reason { #[cfg(feature = "rustc")] mod rustc { use rustc_hir::lang_items::LangItem; - use rustc_infer::infer::InferCtxt; use rustc_macros::TypeVisitable; use rustc_middle::traits::ObligationCause; use rustc_middle::ty::{Const, ParamEnv, Ty, TyCtxt}; @@ -97,13 +96,13 @@ mod rustc { pub dst: Ty<'tcx>, } - pub struct TransmuteTypeEnv<'cx, 'tcx> { - infcx: &'cx InferCtxt<'tcx>, + pub struct TransmuteTypeEnv<'tcx> { + tcx: TyCtxt<'tcx>, } - impl<'cx, 'tcx> TransmuteTypeEnv<'cx, 'tcx> { - pub fn new(infcx: &'cx InferCtxt<'tcx>) -> Self { - Self { infcx } + impl<'tcx> TransmuteTypeEnv<'tcx> { + pub fn new(tcx: TyCtxt<'tcx>) -> Self { + Self { tcx } } #[allow(unused)] @@ -117,7 +116,7 @@ mod rustc { types.src, types.dst, assume, - self.infcx.tcx, + self.tcx, ) .answer() }