Stop relying on rustc_type_ir in non-type-system crates

This commit is contained in:
Michael Goulet 2025-03-13 18:05:00 +00:00
parent 19c84c8812
commit b88f85a410
37 changed files with 136 additions and 163 deletions

View file

@ -2,7 +2,7 @@ use std::cell::RefCell;
use std::collections::hash_map;
use std::rc::Rc;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
use rustc_data_structures::unord::{UnordMap, UnordSet};
use rustc_errors::Subdiagnostic;
use rustc_hir::CRATE_HIR_ID;
@ -25,7 +25,6 @@ use rustc_mir_dataflow::{Analysis, MaybeReachable, ResultsCursor};
use rustc_session::lint::builtin::TAIL_EXPR_DROP_ORDER;
use rustc_session::lint::{self};
use rustc_span::{DUMMY_SP, Span, Symbol};
use rustc_type_ir::data_structures::IndexMap;
use tracing::debug;
fn place_has_common_prefix<'tcx>(left: &Place<'tcx>, right: &Place<'tcx>) -> bool {
@ -199,7 +198,7 @@ pub(crate) fn run_lint<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &Body<
// and, for each block, the vector of locations.
//
// We group them per-block because they tend to scheduled in the same drop ladder block.
let mut bid_per_block = IndexMap::default();
let mut bid_per_block = FxIndexMap::default();
let mut bid_places = UnordSet::new();
let mut ty_dropped_components = UnordMap::default();
@ -455,8 +454,8 @@ pub(crate) fn run_lint<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &Body<
}
/// Extract binding names if available for diagnosis
fn collect_user_names(body: &Body<'_>) -> IndexMap<Local, Symbol> {
let mut names = IndexMap::default();
fn collect_user_names(body: &Body<'_>) -> FxIndexMap<Local, Symbol> {
let mut names = FxIndexMap::default();
for var_debug_info in &body.var_debug_info {
if let mir::VarDebugInfoContents::Place(place) = &var_debug_info.value
&& let Some(local) = place.local_or_deref_local()
@ -470,9 +469,9 @@ fn collect_user_names(body: &Body<'_>) -> IndexMap<Local, Symbol> {
/// Assign names for anonymous or temporary values for diagnosis
fn assign_observables_names(
locals: impl IntoIterator<Item = Local>,
user_names: &IndexMap<Local, Symbol>,
) -> IndexMap<Local, (String, bool)> {
let mut names = IndexMap::default();
user_names: &FxIndexMap<Local, Symbol>,
) -> FxIndexMap<Local, (String, bool)> {
let mut names = FxIndexMap::default();
let mut assigned_names = FxHashSet::default();
let mut idx = 0u64;
let mut fresh_name = || {

View file

@ -5,7 +5,6 @@ use rustc_index::IndexSlice;
use rustc_middle::mir::*;
use rustc_middle::ty::layout::{IntegerExt, TyAndLayout};
use rustc_middle::ty::{self, ScalarInt, Ty, TyCtxt};
use rustc_type_ir::TyKind::*;
use tracing::instrument;
use super::simplify::simplify_cfg;
@ -293,13 +292,13 @@ fn can_cast(
) -> bool {
let from_scalar = ScalarInt::try_from_uint(src_val.into(), src_layout.size).unwrap();
let v = match src_layout.ty.kind() {
Uint(_) => from_scalar.to_uint(src_layout.size),
Int(_) => from_scalar.to_int(src_layout.size) as u128,
ty::Uint(_) => from_scalar.to_uint(src_layout.size),
ty::Int(_) => from_scalar.to_int(src_layout.size) as u128,
_ => unreachable!("invalid int"),
};
let size = match *cast_ty.kind() {
Int(t) => Integer::from_int_ty(&tcx, t).size(),
Uint(t) => Integer::from_uint_ty(&tcx, t).size(),
ty::Int(t) => Integer::from_int_ty(&tcx, t).size(),
ty::Uint(t) => Integer::from_uint_ty(&tcx, t).size(),
_ => unreachable!("invalid int"),
};
let v = size.truncate(v);

View file

@ -13,11 +13,10 @@ use rustc_middle::mir::visit::{NonUseContext, PlaceContext, Visitor};
use rustc_middle::mir::*;
use rustc_middle::ty::adjustment::PointerCoercion;
use rustc_middle::ty::{
self, CoroutineArgsExt, InstanceKind, ScalarInt, Ty, TyCtxt, TypeVisitableExt, Variance,
self, CoroutineArgsExt, InstanceKind, ScalarInt, Ty, TyCtxt, TypeVisitableExt, Upcast, Variance,
};
use rustc_middle::{bug, span_bug};
use rustc_trait_selection::traits::ObligationCtxt;
use rustc_type_ir::Upcast;
use crate::util::{self, is_within_packed};