Skip to content

Commit b6c1b63

Browse files
authored
Rollup merge of rust-lang#137776 - nnethercote:rustc_transmute-cleanups, r=jswrenn
Some `rustc_transmute` cleanups A number of small things that can be removed. r? ``@jswrenn``
2 parents b7853ef + b0530c9 commit b6c1b63

File tree

14 files changed

+32
-85
lines changed

14 files changed

+32
-85
lines changed

Cargo.lock

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4501,8 +4501,6 @@ dependencies = [
45014501
"rustc_abi",
45024502
"rustc_data_structures",
45034503
"rustc_hir",
4504-
"rustc_infer",
4505-
"rustc_macros",
45064504
"rustc_middle",
45074505
"rustc_span",
45084506
"tracing",

compiler/rustc_next_trait_solver/src/delegate.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
102102

103103
fn is_transmutable(
104104
&self,
105-
param_env: <Self::Interner as Interner>::ParamEnv,
106105
dst: <Self::Interner as Interner>::Ty,
107106
src: <Self::Interner as Interner>::Ty,
108107
assume: <Self::Interner as Interner>::Const,

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,12 +1091,11 @@ where
10911091

10921092
pub(super) fn is_transmutable(
10931093
&mut self,
1094-
param_env: I::ParamEnv,
10951094
dst: I::Ty,
10961095
src: I::Ty,
10971096
assume: I::Const,
10981097
) -> Result<Certainty, NoSolution> {
1099-
self.delegate.is_transmutable(param_env, dst, src, assume)
1098+
self.delegate.is_transmutable(dst, src, assume)
11001099
}
11011100
}
11021101

compiler/rustc_next_trait_solver/src/solve/trait_goals.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,6 @@ where
617617
)?;
618618

619619
let certainty = ecx.is_transmutable(
620-
goal.param_env,
621620
goal.predicate.trait_ref.args.type_at(0),
622621
goal.predicate.trait_ref.args.type_at(1),
623622
assume,

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,9 +2533,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
25332533
return GetSafeTransmuteErrorAndReason::Silent;
25342534
};
25352535

2536-
let Some(assume) =
2537-
rustc_transmute::Assume::from_const(self.infcx.tcx, obligation.param_env, assume)
2538-
else {
2536+
let Some(assume) = rustc_transmute::Assume::from_const(self.infcx.tcx, assume) else {
25392537
self.dcx().span_delayed_bug(
25402538
span,
25412539
"Unable to construct rustc_transmute::Assume where it was previously possible",
@@ -2547,11 +2545,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
25472545
let src = trait_pred.trait_ref.args.type_at(1);
25482546
let err_msg = format!("`{src}` cannot be safely transmuted into `{dst}`");
25492547

2550-
match rustc_transmute::TransmuteTypeEnv::new(self.infcx).is_transmutable(
2551-
obligation.cause,
2552-
src_and_dst,
2553-
assume,
2554-
) {
2548+
match rustc_transmute::TransmuteTypeEnv::new(self.infcx.tcx)
2549+
.is_transmutable(src_and_dst, assume)
2550+
{
25552551
Answer::No(reason) => {
25562552
let safe_transmute_explanation = match reason {
25572553
rustc_transmute::Reason::SrcIsNotYetSupported => {

compiler/rustc_trait_selection/src/solve/delegate.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use rustc_infer::infer::canonical::{
77
Canonical, CanonicalExt as _, CanonicalQueryInput, CanonicalVarInfo, CanonicalVarValues,
88
};
99
use rustc_infer::infer::{InferCtxt, RegionVariableOrigin, TyCtxtInferExt};
10-
use rustc_infer::traits::ObligationCause;
1110
use rustc_infer::traits::solve::Goal;
1211
use rustc_middle::ty::fold::TypeFoldable;
1312
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt as _};
@@ -222,7 +221,6 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
222221
// register candidates. We probably need to register >1 since we may have an OR of ANDs.
223222
fn is_transmutable(
224223
&self,
225-
param_env: ty::ParamEnv<'tcx>,
226224
dst: Ty<'tcx>,
227225
src: Ty<'tcx>,
228226
assume: ty::Const<'tcx>,
@@ -231,16 +229,14 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
231229
// which will ICE for region vars.
232230
let (dst, src) = self.tcx.erase_regions((dst, src));
233231

234-
let Some(assume) = rustc_transmute::Assume::from_const(self.tcx, param_env, assume) else {
232+
let Some(assume) = rustc_transmute::Assume::from_const(self.tcx, assume) else {
235233
return Err(NoSolution);
236234
};
237235

238236
// FIXME(transmutability): This really should be returning nested goals for `Answer::If*`
239-
match rustc_transmute::TransmuteTypeEnv::new(&self.0).is_transmutable(
240-
ObligationCause::dummy(),
241-
rustc_transmute::Types { src, dst },
242-
assume,
243-
) {
237+
match rustc_transmute::TransmuteTypeEnv::new(self.0.tcx)
238+
.is_transmutable(rustc_transmute::Types { src, dst }, assume)
239+
{
244240
rustc_transmute::Answer::Yes => Ok(Certainty::Yes),
245241
rustc_transmute::Answer::No(_) | rustc_transmute::Answer::If(_) => Err(NoSolution),
246242
}

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -414,22 +414,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
414414
if self.tcx().features().generic_const_exprs() {
415415
assume = crate::traits::evaluate_const(self.infcx, assume, obligation.param_env)
416416
}
417-
let Some(assume) =
418-
rustc_transmute::Assume::from_const(self.infcx.tcx, obligation.param_env, assume)
419-
else {
417+
let Some(assume) = rustc_transmute::Assume::from_const(self.infcx.tcx, assume) else {
420418
return Err(Unimplemented);
421419
};
422420

423421
let dst = predicate.trait_ref.args.type_at(0);
424422
let src = predicate.trait_ref.args.type_at(1);
425423

426424
debug!(?src, ?dst);
427-
let mut transmute_env = rustc_transmute::TransmuteTypeEnv::new(self.infcx);
428-
let maybe_transmutable = transmute_env.is_transmutable(
429-
obligation.cause.clone(),
430-
rustc_transmute::Types { dst, src },
431-
assume,
432-
);
425+
let mut transmute_env = rustc_transmute::TransmuteTypeEnv::new(self.infcx.tcx);
426+
let maybe_transmutable =
427+
transmute_env.is_transmutable(rustc_transmute::Types { dst, src }, assume);
433428

434429
let fully_flattened = match maybe_transmutable {
435430
Answer::No(_) => Err(Unimplemented)?,

compiler/rustc_transmute/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ edition = "2024"
88
rustc_abi = { path = "../rustc_abi", optional = true }
99
rustc_data_structures = { path = "../rustc_data_structures" }
1010
rustc_hir = { path = "../rustc_hir", optional = true }
11-
rustc_infer = { path = "../rustc_infer", optional = true }
12-
rustc_macros = { path = "../rustc_macros", optional = true }
1311
rustc_middle = { path = "../rustc_middle", optional = true }
1412
rustc_span = { path = "../rustc_span", optional = true }
1513
tracing = "0.1"
@@ -19,8 +17,6 @@ tracing = "0.1"
1917
rustc = [
2018
"dep:rustc_abi",
2119
"dep:rustc_hir",
22-
"dep:rustc_infer",
23-
"dep:rustc_macros",
2420
"dep:rustc_middle",
2521
"dep:rustc_span",
2622
]

compiler/rustc_transmute/src/layout/dfa.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl<R> Transitions<R>
3838
where
3939
R: Ref,
4040
{
41-
#[allow(dead_code)]
41+
#[cfg(test)]
4242
fn insert(&mut self, transition: Transition<R>, state: State) {
4343
match transition {
4444
Transition::Byte(b) => {
@@ -86,15 +86,6 @@ impl<R> Dfa<R>
8686
where
8787
R: Ref,
8888
{
89-
#[allow(dead_code)]
90-
pub(crate) fn unit() -> Self {
91-
let transitions: Map<State, Transitions<R>> = Map::default();
92-
let start = State::new();
93-
let accepting = start;
94-
95-
Self { transitions, start, accepting }
96-
}
97-
9889
#[cfg(test)]
9990
pub(crate) fn bool() -> Self {
10091
let mut transitions: Map<State, Transitions<R>> = Map::default();

compiler/rustc_transmute/src/layout/nfa.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,6 @@ where
159159
}
160160
Self { transitions, start, accepting }
161161
}
162-
163-
#[allow(dead_code)]
164-
pub(crate) fn edges_from(&self, start: State) -> Option<&Map<Transition<R>, Set<State>>> {
165-
self.transitions.get(&start)
166-
}
167162
}
168163

169164
impl State {

0 commit comments

Comments
 (0)