remove a bunch of dead parameters in fn

This commit is contained in:
yukang 2024-02-11 14:47:30 +08:00
parent 42752cbe09
commit 2bcbc16caf
16 changed files with 30 additions and 71 deletions

View file

@ -3020,7 +3020,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
/// assignment to `x.f`). /// assignment to `x.f`).
pub(crate) fn report_illegal_reassignment( pub(crate) fn report_illegal_reassignment(
&mut self, &mut self,
_location: Location,
(place, span): (Place<'tcx>, Span), (place, span): (Place<'tcx>, Span),
assigned_span: Span, assigned_span: Span,
err_place: Place<'tcx>, err_place: Place<'tcx>,

View file

@ -1036,7 +1036,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
self, self,
self.infcx.tcx, self.infcx.tcx,
self.body, self.body,
location,
(sd, place_span.0), (sd, place_span.0),
&borrow_set, &borrow_set,
|borrow_index| borrows_in_scope.contains(borrow_index), |borrow_index| borrows_in_scope.contains(borrow_index),
@ -2174,7 +2173,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
// report the error as an illegal reassignment // report the error as an illegal reassignment
let init = &self.move_data.inits[init_index]; let init = &self.move_data.inits[init_index];
let assigned_span = init.span(self.body); let assigned_span = init.span(self.body);
self.report_illegal_reassignment(location, (place, span), assigned_span, place); self.report_illegal_reassignment((place, span), assigned_span, place);
} else { } else {
self.report_mutability_error(place, span, the_place_err, error_access, location) self.report_mutability_error(place, span, the_place_err, error_access, location)
} }

View file

@ -27,7 +27,6 @@ pub(super) fn each_borrow_involving_path<'tcx, F, I, S>(
s: &mut S, s: &mut S,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
body: &Body<'tcx>, body: &Body<'tcx>,
_location: Location,
access_place: (AccessDepth, Place<'tcx>), access_place: (AccessDepth, Place<'tcx>),
borrow_set: &BorrowSet<'tcx>, borrow_set: &BorrowSet<'tcx>,
is_candidate: I, is_candidate: I,

View file

@ -340,7 +340,6 @@ impl<'cx, 'tcx> LoanInvalidationsGenerator<'cx, 'tcx> {
self, self,
self.tcx, self.tcx,
self.body, self.body,
location,
(sd, place), (sd, place),
self.borrow_set, self.borrow_set,
|_| true, |_| true,

View file

@ -662,7 +662,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
polonius_output: Option<Rc<PoloniusOutput>>, polonius_output: Option<Rc<PoloniusOutput>>,
) -> (Option<ClosureRegionRequirements<'tcx>>, RegionErrors<'tcx>) { ) -> (Option<ClosureRegionRequirements<'tcx>>, RegionErrors<'tcx>) {
let mir_def_id = body.source.def_id(); let mir_def_id = body.source.def_id();
self.propagate_constraints(body); self.propagate_constraints();
let mut errors_buffer = RegionErrors::new(infcx.tcx); let mut errors_buffer = RegionErrors::new(infcx.tcx);
@ -716,8 +716,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// for each region variable until all the constraints are /// for each region variable until all the constraints are
/// satisfied. Note that some values may grow **too** large to be /// satisfied. Note that some values may grow **too** large to be
/// feasible, but we check this later. /// feasible, but we check this later.
#[instrument(skip(self, _body), level = "debug")] #[instrument(skip(self), level = "debug")]
fn propagate_constraints(&mut self, _body: &Body<'tcx>) { fn propagate_constraints(&mut self) {
debug!("constraints={:#?}", { debug!("constraints={:#?}", {
let mut constraints: Vec<_> = self.outlives_constraints().collect(); let mut constraints: Vec<_> = self.outlives_constraints().collect();
constraints.sort_by_key(|c| (c.sup, c.sub)); constraints.sort_by_key(|c| (c.sup, c.sub));

View file

@ -96,7 +96,7 @@ where
}); });
} }
fn address_of_allows_mutation(&self, _mt: mir::Mutability, _place: mir::Place<'tcx>) -> bool { fn address_of_allows_mutation(&self) -> bool {
// Exact set of permissions granted by AddressOf is undecided. Conservatively assume that // Exact set of permissions granted by AddressOf is undecided. Conservatively assume that
// it might allow mutation until resolution of #56604. // it might allow mutation until resolution of #56604.
true true
@ -171,10 +171,8 @@ where
self.super_rvalue(rvalue, location); self.super_rvalue(rvalue, location);
match rvalue { match rvalue {
mir::Rvalue::AddressOf(mt, borrowed_place) => { mir::Rvalue::AddressOf(_mt, borrowed_place) => {
if !borrowed_place.is_indirect() if !borrowed_place.is_indirect() && self.address_of_allows_mutation() {
&& self.address_of_allows_mutation(*mt, *borrowed_place)
{
let place_ty = borrowed_place.ty(self.ccx.body, self.ccx.tcx).ty; let place_ty = borrowed_place.ty(self.ccx.body, self.ccx.tcx).ty;
if Q::in_any_value_of_ty(self.ccx, place_ty) { if Q::in_any_value_of_ty(self.ccx, place_ty) {
self.state.qualif.insert(borrowed_place.local); self.state.qualif.insert(borrowed_place.local);

View file

@ -16,7 +16,6 @@ use rustc_index::Idx;
use rustc_middle::middle::region::*; use rustc_middle::middle::region::*;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_span::source_map; use rustc_span::source_map;
use rustc_span::Span;
use super::errs::{maybe_expr_static_mut, maybe_stmt_static_mut}; use super::errs::{maybe_expr_static_mut, maybe_stmt_static_mut};
@ -72,11 +71,7 @@ struct RegionResolutionVisitor<'tcx> {
} }
/// Records the lifetime of a local variable as `cx.var_parent` /// Records the lifetime of a local variable as `cx.var_parent`
fn record_var_lifetime( fn record_var_lifetime(visitor: &mut RegionResolutionVisitor<'_>, var_id: hir::ItemLocalId) {
visitor: &mut RegionResolutionVisitor<'_>,
var_id: hir::ItemLocalId,
_sp: Span,
) {
match visitor.cx.var_parent { match visitor.cx.var_parent {
None => { None => {
// this can happen in extern fn declarations like // this can happen in extern fn declarations like
@ -210,7 +205,7 @@ fn resolve_pat<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, pat: &'tcx hir
// If this is a binding then record the lifetime of that binding. // If this is a binding then record the lifetime of that binding.
if let PatKind::Binding(..) = pat.kind { if let PatKind::Binding(..) = pat.kind {
record_var_lifetime(visitor, pat.hir_id.local_id, pat.span); record_var_lifetime(visitor, pat.hir_id.local_id);
} }
debug!("resolve_pat - pre-increment {} pat = {:?}", visitor.expr_and_pat_count, pat); debug!("resolve_pat - pre-increment {} pat = {:?}", visitor.expr_and_pat_count, pat);

View file

@ -425,9 +425,7 @@ fn check_predicates<'tcx>(
let mut res = Ok(()); let mut res = Ok(());
for (clause, span) in impl1_predicates { for (clause, span) in impl1_predicates {
if !impl2_predicates if !impl2_predicates.iter().any(|pred2| trait_predicates_eq(clause.as_predicate(), *pred2))
.iter()
.any(|pred2| trait_predicates_eq(tcx, clause.as_predicate(), *pred2, span))
{ {
res = res.and(check_specialization_on(tcx, clause, span)) res = res.and(check_specialization_on(tcx, clause, span))
} }
@ -459,10 +457,8 @@ fn check_predicates<'tcx>(
/// ///
/// So we make that check in this function and try to raise a helpful error message. /// So we make that check in this function and try to raise a helpful error message.
fn trait_predicates_eq<'tcx>( fn trait_predicates_eq<'tcx>(
_tcx: TyCtxt<'tcx>,
predicate1: ty::Predicate<'tcx>, predicate1: ty::Predicate<'tcx>,
predicate2: ty::Predicate<'tcx>, predicate2: ty::Predicate<'tcx>,
_span: Span,
) -> bool { ) -> bool {
// FIXME(effects) // FIXME(effects)
predicate1 == predicate2 predicate1 == predicate2

View file

@ -346,7 +346,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
ExprKind::DropTemps(e) => self.check_expr_with_expectation(e, expected), ExprKind::DropTemps(e) => self.check_expr_with_expectation(e, expected),
ExprKind::Array(args) => self.check_expr_array(args, expected, expr), ExprKind::Array(args) => self.check_expr_array(args, expected, expr),
ExprKind::ConstBlock(ref block) => self.check_expr_const_block(block, expected, expr), ExprKind::ConstBlock(ref block) => self.check_expr_const_block(block, expected),
ExprKind::Repeat(element, ref count) => { ExprKind::Repeat(element, ref count) => {
self.check_expr_repeat(element, count, expected, expr) self.check_expr_repeat(element, count, expected, expr)
} }
@ -1493,7 +1493,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self, &self,
block: &'tcx hir::ConstBlock, block: &'tcx hir::ConstBlock,
expected: Expectation<'tcx>, expected: Expectation<'tcx>,
_expr: &'tcx hir::Expr<'tcx>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
let body = self.tcx.hir().body(block.body); let body = self.tcx.hir().body(block.body);

View file

@ -142,7 +142,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
let param_ty = return_if_err!(self.mc.pat_ty_adjusted(param.pat)); let param_ty = return_if_err!(self.mc.pat_ty_adjusted(param.pat));
debug!("consume_body: param_ty = {:?}", param_ty); debug!("consume_body: param_ty = {:?}", param_ty);
let param_place = self.mc.cat_rvalue(param.hir_id, param.pat.span, param_ty); let param_place = self.mc.cat_rvalue(param.hir_id, param_ty);
self.walk_irrefutable_pat(&param_place, param.pat); self.walk_irrefutable_pat(&param_place, param.pat);
} }

View file

@ -273,7 +273,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
deref.region, deref.region,
ty::TypeAndMut { ty: target, mutbl: deref.mutbl }, ty::TypeAndMut { ty: target, mutbl: deref.mutbl },
); );
self.cat_rvalue(expr.hir_id, expr.span, ref_ty) self.cat_rvalue(expr.hir_id, ref_ty)
} else { } else {
previous()? previous()?
}; };
@ -285,7 +285,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
| adjustment::Adjust::Borrow(_) | adjustment::Adjust::Borrow(_)
| adjustment::Adjust::DynStar => { | adjustment::Adjust::DynStar => {
// Result is an rvalue. // Result is an rvalue.
Ok(self.cat_rvalue(expr.hir_id, expr.span, target)) Ok(self.cat_rvalue(expr.hir_id, target))
} }
} }
} }
@ -374,7 +374,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
| hir::ExprKind::Repeat(..) | hir::ExprKind::Repeat(..)
| hir::ExprKind::InlineAsm(..) | hir::ExprKind::InlineAsm(..)
| hir::ExprKind::OffsetOf(..) | hir::ExprKind::OffsetOf(..)
| hir::ExprKind::Err(_) => Ok(self.cat_rvalue(expr.hir_id, expr.span, expr_ty)), | hir::ExprKind::Err(_) => Ok(self.cat_rvalue(expr.hir_id, expr_ty)),
} }
} }
@ -396,7 +396,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
| DefKind::AssocFn, | DefKind::AssocFn,
_, _,
) )
| Res::SelfCtor(..) => Ok(self.cat_rvalue(hir_id, span, expr_ty)), | Res::SelfCtor(..) => Ok(self.cat_rvalue(hir_id, expr_ty)),
Res::Def(DefKind::Static(_), _) => { Res::Def(DefKind::Static(_), _) => {
Ok(PlaceWithHirId::new(hir_id, expr_ty, PlaceBase::StaticItem, Vec::new())) Ok(PlaceWithHirId::new(hir_id, expr_ty, PlaceBase::StaticItem, Vec::new()))
@ -433,13 +433,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
} }
#[instrument(level = "debug", skip(self), ret)] #[instrument(level = "debug", skip(self), ret)]
pub(crate) fn cat_rvalue( pub(crate) fn cat_rvalue(&self, hir_id: hir::HirId, expr_ty: Ty<'tcx>) -> PlaceWithHirId<'tcx> {
&self,
hir_id: hir::HirId,
// FIXME: remove
_span: Span,
expr_ty: Ty<'tcx>,
) -> PlaceWithHirId<'tcx> {
PlaceWithHirId::new(hir_id, expr_ty, PlaceBase::Rvalue, Vec::new()) PlaceWithHirId::new(hir_id, expr_ty, PlaceBase::Rvalue, Vec::new())
} }
@ -487,7 +481,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
}; };
let ref_ty = Ty::new_ref(self.tcx(), region, ty::TypeAndMut { ty: place_ty, mutbl }); let ref_ty = Ty::new_ref(self.tcx(), region, ty::TypeAndMut { ty: place_ty, mutbl });
let base = self.cat_rvalue(expr.hir_id, expr.span, ref_ty); let base = self.cat_rvalue(expr.hir_id, ref_ty);
self.cat_deref(expr, base) self.cat_deref(expr, base)
} }

View file

@ -726,7 +726,7 @@ fn replace_resume_ty_local<'tcx>(
/// The async lowering step and the type / lifetime inference / checking are /// The async lowering step and the type / lifetime inference / checking are
/// still using the `resume` argument for the time being. After this transform, /// still using the `resume` argument for the time being. After this transform,
/// the coroutine body doesn't have the `resume` argument. /// the coroutine body doesn't have the `resume` argument.
fn transform_gen_context<'tcx>(_tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { fn transform_gen_context<'tcx>(body: &mut Body<'tcx>) {
// This leaves the local representing the `resume` argument in place, // This leaves the local representing the `resume` argument in place,
// but turns it into a regular local variable. This is cheaper than // but turns it into a regular local variable. This is cheaper than
// adjusting all local references in the body after removing it. // adjusting all local references in the body after removing it.
@ -1733,7 +1733,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
// Remove the context argument within generator bodies. // Remove the context argument within generator bodies.
if matches!(coroutine_kind, CoroutineKind::Desugared(CoroutineDesugaring::Gen, _)) { if matches!(coroutine_kind, CoroutineKind::Desugared(CoroutineDesugaring::Gen, _)) {
transform_gen_context(tcx, body); transform_gen_context(body);
} }
// The original arguments to the function are no longer arguments, mark them as such. // The original arguments to the function are no longer arguments, mark them as such.

View file

@ -29,17 +29,14 @@ impl<'tcx> MirPass<'tcx> for InstSimplify {
ctx.simplify_bool_cmp(&statement.source_info, rvalue); ctx.simplify_bool_cmp(&statement.source_info, rvalue);
ctx.simplify_ref_deref(&statement.source_info, rvalue); ctx.simplify_ref_deref(&statement.source_info, rvalue);
ctx.simplify_len(&statement.source_info, rvalue); ctx.simplify_len(&statement.source_info, rvalue);
ctx.simplify_cast(&statement.source_info, rvalue); ctx.simplify_cast(rvalue);
} }
_ => {} _ => {}
} }
} }
ctx.simplify_primitive_clone(block.terminator.as_mut().unwrap(), &mut block.statements); ctx.simplify_primitive_clone(block.terminator.as_mut().unwrap(), &mut block.statements);
ctx.simplify_intrinsic_assert( ctx.simplify_intrinsic_assert(block.terminator.as_mut().unwrap());
block.terminator.as_mut().unwrap(),
&mut block.statements,
);
ctx.simplify_nounwind_call(block.terminator.as_mut().unwrap()); ctx.simplify_nounwind_call(block.terminator.as_mut().unwrap());
simplify_duplicate_switch_targets(block.terminator.as_mut().unwrap()); simplify_duplicate_switch_targets(block.terminator.as_mut().unwrap());
} }
@ -143,7 +140,7 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
} }
} }
fn simplify_cast(&self, _source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) { fn simplify_cast(&self, rvalue: &mut Rvalue<'tcx>) {
if let Rvalue::Cast(kind, operand, cast_ty) = rvalue { if let Rvalue::Cast(kind, operand, cast_ty) = rvalue {
let operand_ty = operand.ty(self.local_decls, self.tcx); let operand_ty = operand.ty(self.local_decls, self.tcx);
if operand_ty == *cast_ty { if operand_ty == *cast_ty {
@ -277,11 +274,7 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
} }
} }
fn simplify_intrinsic_assert( fn simplify_intrinsic_assert(&self, terminator: &mut Terminator<'tcx>) {
&self,
terminator: &mut Terminator<'tcx>,
_statements: &mut Vec<Statement<'tcx>>,
) {
let TerminatorKind::Call { func, target, .. } = &mut terminator.kind else { let TerminatorKind::Call { func, target, .. } = &mut terminator.kind else {
return; return;
}; };

View file

@ -197,7 +197,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
| sym::unstable | sym::unstable
| sym::stable | sym::stable
| sym::rustc_allowed_through_unstable_modules | sym::rustc_allowed_through_unstable_modules
| sym::rustc_promotable => self.check_stability_promotable(attr, span, target), | sym::rustc_promotable => self.check_stability_promotable(attr, target),
sym::link_ordinal => self.check_link_ordinal(attr, span, target), sym::link_ordinal => self.check_link_ordinal(attr, span, target),
sym::rustc_confusables => self.check_confusables(attr, target), sym::rustc_confusables => self.check_confusables(attr, target),
sym::rustc_safe_intrinsic => { sym::rustc_safe_intrinsic => {
@ -2102,7 +2102,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
} }
} }
fn check_stability_promotable(&self, attr: &Attribute, _span: Span, target: Target) -> bool { fn check_stability_promotable(&self, attr: &Attribute, target: Target) -> bool {
match target { match target {
Target::Expression => { Target::Expression => {
self.dcx().emit_err(errors::StabilityPromotable { attr_span: attr.span }); self.dcx().emit_err(errors::StabilityPromotable { attr_span: attr.span });

View file

@ -261,12 +261,7 @@ fn encode_predicates<'tcx>(
} }
/// Encodes a region using the Itanium C++ ABI as a vendor extended type. /// Encodes a region using the Itanium C++ ABI as a vendor extended type.
fn encode_region<'tcx>( fn encode_region<'tcx>(region: Region<'tcx>, dict: &mut FxHashMap<DictKey<'tcx>, usize>) -> String {
_tcx: TyCtxt<'tcx>,
region: Region<'tcx>,
dict: &mut FxHashMap<DictKey<'tcx>, usize>,
_options: EncodeTyOptions,
) -> String {
// u6region[I[<region-disambiguator>][<region-index>]E] as vendor extended type // u6region[I[<region-disambiguator>][<region-index>]E] as vendor extended type
let mut s = String::new(); let mut s = String::new();
match region.kind() { match region.kind() {
@ -314,7 +309,7 @@ fn encode_args<'tcx>(
for arg in args { for arg in args {
match arg.unpack() { match arg.unpack() {
GenericArgKind::Lifetime(region) => { GenericArgKind::Lifetime(region) => {
s.push_str(&encode_region(tcx, region, dict, options)); s.push_str(&encode_region(region, dict));
} }
GenericArgKind::Type(ty) => { GenericArgKind::Type(ty) => {
s.push_str(&encode_ty(tcx, ty, dict, options)); s.push_str(&encode_ty(tcx, ty, dict, options));
@ -703,7 +698,7 @@ fn encode_ty<'tcx>(
ty::DynStar => "u7dynstarI", ty::DynStar => "u7dynstarI",
}); });
s.push_str(&encode_predicates(tcx, predicates, dict, options)); s.push_str(&encode_predicates(tcx, predicates, dict, options));
s.push_str(&encode_region(tcx, *region, dict, options)); s.push_str(&encode_region(*region, dict));
s.push('E'); s.push('E');
compress(dict, DictKey::Ty(ty, TyQ::None), &mut s); compress(dict, DictKey::Ty(ty, TyQ::None), &mut s);
typeid.push_str(&s); typeid.push_str(&s);
@ -735,7 +730,6 @@ fn encode_ty<'tcx>(
fn transform_predicates<'tcx>( fn transform_predicates<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
predicates: &List<ty::PolyExistentialPredicate<'tcx>>, predicates: &List<ty::PolyExistentialPredicate<'tcx>>,
_options: EncodeTyOptions,
) -> &'tcx List<ty::PolyExistentialPredicate<'tcx>> { ) -> &'tcx List<ty::PolyExistentialPredicate<'tcx>> {
let predicates: Vec<ty::PolyExistentialPredicate<'tcx>> = predicates let predicates: Vec<ty::PolyExistentialPredicate<'tcx>> = predicates
.iter() .iter()
@ -967,7 +961,7 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
ty::Dynamic(predicates, _region, kind) => { ty::Dynamic(predicates, _region, kind) => {
ty = Ty::new_dynamic( ty = Ty::new_dynamic(
tcx, tcx,
transform_predicates(tcx, predicates, options), transform_predicates(tcx, predicates),
tcx.lifetimes.re_erased, tcx.lifetimes.re_erased,
*kind, *kind,
); );

View file

@ -615,8 +615,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
let UnsatisfiedConst(unsatisfied_const) = self let UnsatisfiedConst(unsatisfied_const) = self
.maybe_add_note_for_unsatisfied_const( .maybe_add_note_for_unsatisfied_const(
&obligation,
trait_ref,
&trait_predicate, &trait_predicate,
&mut err, &mut err,
span, span,
@ -1480,8 +1478,6 @@ pub(super) trait InferCtxtPrivExt<'tcx> {
fn maybe_add_note_for_unsatisfied_const( fn maybe_add_note_for_unsatisfied_const(
&self, &self,
obligation: &PredicateObligation<'tcx>,
trait_ref: ty::PolyTraitRef<'tcx>,
trait_predicate: &ty::PolyTraitPredicate<'tcx>, trait_predicate: &ty::PolyTraitPredicate<'tcx>,
err: &mut Diagnostic, err: &mut Diagnostic,
span: Span, span: Span,
@ -3359,8 +3355,6 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
fn maybe_add_note_for_unsatisfied_const( fn maybe_add_note_for_unsatisfied_const(
&self, &self,
_obligation: &PredicateObligation<'tcx>,
_trait_ref: ty::PolyTraitRef<'tcx>,
_trait_predicate: &ty::PolyTraitPredicate<'tcx>, _trait_predicate: &ty::PolyTraitPredicate<'tcx>,
_err: &mut Diagnostic, _err: &mut Diagnostic,
_span: Span, _span: Span,