Skip to content

Commit

Permalink
Rollup merge of rust-lang#120590 - compiler-errors:dead, r=Nilstrieb
Browse files Browse the repository at this point in the history
Remove unused args from functions

`#[instrument]` suppresses the unused arguments from a function, *and* suppresses unused methods too! This PR removes things which are only used via `#[instrument]` calls, and fixes some other errors (privacy?) that I will comment inline.

It's possible that some of these arguments were being passed in for the purposes of being instrumented, but I am unconvinced by most of them.
  • Loading branch information
matthiaskrgr committed Feb 4, 2024
2 parents 199206f + 6b2a824 commit dc1f20a
Show file tree
Hide file tree
Showing 22 changed files with 32 additions and 124 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>(

// Solve the region constraints.
let (closure_region_requirements, nll_errors) =
regioncx.solve(infcx, param_env, body, polonius_output.clone());
regioncx.solve(infcx, body, polonius_output.clone());

if !nll_errors.is_empty() {
// Suppress unhelpful extra errors in `infer_opaque_types`.
Expand Down
41 changes: 2 additions & 39 deletions compiler/rustc_borrowck/src/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
pub(super) fn solve(
&mut self,
infcx: &InferCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
body: &Body<'tcx>,
polonius_output: Option<Rc<PoloniusOutput>>,
) -> (Option<ClosureRegionRequirements<'tcx>>, RegionErrors<'tcx>) {
Expand All @@ -674,7 +673,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// eagerly.
let mut outlives_requirements = infcx.tcx.is_typeck_child(mir_def_id).then(Vec::new);

self.check_type_tests(infcx, body, outlives_requirements.as_mut(), &mut errors_buffer);
self.check_type_tests(infcx, outlives_requirements.as_mut(), &mut errors_buffer);

debug!(?errors_buffer);
debug!(?outlives_requirements);
Expand Down Expand Up @@ -932,7 +931,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
fn check_type_tests(
&self,
infcx: &InferCtxt<'tcx>,
body: &Body<'tcx>,
mut propagated_outlives_requirements: Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
errors_buffer: &mut RegionErrors<'tcx>,
) {
Expand All @@ -957,12 +955,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
}

if let Some(propagated_outlives_requirements) = &mut propagated_outlives_requirements {
if self.try_promote_type_test(
infcx,
body,
type_test,
propagated_outlives_requirements,
) {
if self.try_promote_type_test(infcx, type_test, propagated_outlives_requirements) {
continue;
}
}
Expand Down Expand Up @@ -1016,7 +1009,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
fn try_promote_type_test(
&self,
infcx: &InferCtxt<'tcx>,
body: &Body<'tcx>,
type_test: &TypeTest<'tcx>,
propagated_outlives_requirements: &mut Vec<ClosureOutlivesRequirement<'tcx>>,
) -> bool {
Expand Down Expand Up @@ -1179,35 +1171,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
Some(ClosureOutlivesSubject::Ty(ClosureOutlivesSubjectTy::bind(tcx, ty)))
}

/// Returns a universally quantified region that outlives the
/// value of `r` (`r` may be existentially or universally
/// quantified).
///
/// Since `r` is (potentially) an existential region, it has some
/// value which may include (a) any number of points in the CFG
/// and (b) any number of `end('x)` elements of universally
/// quantified regions. To convert this into a single universal
/// region we do as follows:
///
/// - Ignore the CFG points in `'r`. All universally quantified regions
/// include the CFG anyhow.
/// - For each `end('x)` element in `'r`, compute the mutual LUB, yielding
/// a result `'y`.
#[instrument(skip(self), level = "debug", ret)]
pub(crate) fn universal_upper_bound(&self, r: RegionVid) -> RegionVid {
debug!(r = %self.region_value_str(r));

// Find the smallest universal region that contains all other
// universal regions within `region`.
let mut lub = self.universal_regions.fr_fn_body;
let r_scc = self.constraint_sccs.scc(r);
for ur in self.scc_values.universal_regions_outlived_by(r_scc) {
lub = self.universal_region_relations.postdom_upper_bound(lub, ur);
}

lub
}

/// Like `universal_upper_bound`, but returns an approximation more suitable
/// for diagnostics. If `r` contains multiple disjoint universal regions
/// (e.g. 'a and 'b in `fn foo<'a, 'b> { ... }`, we pick the lower-numbered region.
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ pub(crate) fn type_check<'mir, 'tcx>(
CustomTypeOp::new(
|ocx| {
ocx.infcx.register_member_constraints(
param_env,
opaque_type_key,
decl.hidden_type.ty,
decl.hidden_type.span,
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_hir_analysis/src/astconv/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
speculative: bool,
dup_bindings: &mut FxHashMap<DefId, Span>,
path_span: Span,
constness: ty::BoundConstness,
only_self_bounds: OnlySelfBounds,
polarity: ty::ImplPolarity,
) -> Result<(), ErrorGuaranteed> {
// Given something like `U: SomeTrait<T = X>`, we want to produce a
// predicate like `<U as SomeTrait>::T = X`. This is somewhat
Expand Down
16 changes: 2 additions & 14 deletions compiler/rustc_hir_analysis/src/astconv/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc_middle::ty::{
self, GenericArgsRef, GenericParamDef, GenericParamDefKind, IsSuggestable, Ty, TyCtxt,
};
use rustc_session::lint::builtin::LATE_BOUND_LIFETIME_ARGUMENTS;
use rustc_span::{symbol::kw, Span};
use rustc_span::symbol::kw;
use smallvec::SmallVec;

/// Report an error that a generic argument did not match the generic parameter that was
Expand Down Expand Up @@ -404,7 +404,6 @@ pub fn create_args_for_parent_generic_args<'tcx: 'a, 'a>(
/// Used specifically for function calls.
pub fn check_generic_arg_count_for_call(
tcx: TyCtxt<'_>,
span: Span,
def_id: DefId,
generics: &ty::Generics,
seg: &hir::PathSegment<'_>,
Expand All @@ -418,25 +417,14 @@ pub fn check_generic_arg_count_for_call(
};
let has_self = generics.parent.is_none() && generics.has_self;

check_generic_arg_count(
tcx,
span,
def_id,
seg,
generics,
gen_args,
gen_pos,
has_self,
seg.infer_args,
)
check_generic_arg_count(tcx, def_id, seg, generics, gen_args, gen_pos, has_self, seg.infer_args)
}

/// Checks that the correct number of generic arguments have been provided.
/// This is used both for datatypes and function calls.
#[instrument(skip(tcx, gen_pos), level = "debug")]
pub(crate) fn check_generic_arg_count(
tcx: TyCtxt<'_>,
span: Span,
def_id: DefId,
seg: &hir::PathSegment<'_>,
gen_params: &ty::Generics,
Expand Down
10 changes: 3 additions & 7 deletions compiler/rustc_hir_analysis/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use rustc_hir as hir;
use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit::{walk_generics, Visitor as _};
use rustc_hir::{GenericArg, GenericArgs, OpaqueTyOrigin};
use rustc_hir::{GenericArg, GenericArgs};
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
use rustc_infer::traits::ObligationCause;
use rustc_middle::middle::stability::AllowUnstable;
Expand Down Expand Up @@ -379,7 +379,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {

let mut arg_count = check_generic_arg_count(
tcx,
span,
def_id,
seg,
generics,
Expand Down Expand Up @@ -773,9 +772,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
speculative,
&mut dup_bindings,
binding.span,
constness,
only_self_bounds,
polarity,
);
// Okay to ignore `Err` because of `ErrorGuaranteed` (see above).
}
Expand Down Expand Up @@ -2491,7 +2488,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let opaque_ty = tcx.hir().item(item_id);

match opaque_ty.kind {
hir::ItemKind::OpaqueTy(&hir::OpaqueTy { origin, .. }) => {
hir::ItemKind::OpaqueTy(&hir::OpaqueTy { .. }) => {
let local_def_id = item_id.owner_id.def_id;
// If this is an RPITIT and we are using the new RPITIT lowering scheme, we
// generate the def_id of an associated type for the trait and return as
Expand All @@ -2501,7 +2498,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
} else {
local_def_id.to_def_id()
};
self.impl_trait_ty_to_ty(def_id, lifetimes, origin, in_trait)
self.impl_trait_ty_to_ty(def_id, lifetimes, in_trait)
}
ref i => bug!("`impl Trait` pointed to non-opaque type?? {:#?}", i),
}
Expand Down Expand Up @@ -2557,7 +2554,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
&self,
def_id: DefId,
lifetimes: &[hir::GenericArg<'_>],
origin: OpaqueTyOrigin,
in_trait: bool,
) -> Ty<'tcx> {
debug!("impl_trait_ty_to_ty(def_id={:?}, lifetimes={:?})", def_id, lifetimes);
Expand Down
12 changes: 3 additions & 9 deletions compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// We must not attempt to select obligations after this method has run, or risk query cycle
/// ICE.
#[instrument(level = "debug", skip(self))]
pub(in super::super) fn resolve_coroutine_interiors(&self, def_id: DefId) {
pub(in super::super) fn resolve_coroutine_interiors(&self) {
// Try selecting all obligations that are not blocked on inference variables.
// Once we start unifying coroutine witnesses, trying to select obligations on them will
// trigger query cycle ICEs, as doing so requires MIR.
Expand Down Expand Up @@ -1175,14 +1175,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// parameter internally, but we don't allow users to specify the
// parameter's value explicitly, so we have to do some error-
// checking here.
let arg_count = check_generic_arg_count_for_call(
tcx,
span,
def_id,
generics,
seg,
IsMethodCall::No,
);
let arg_count =
check_generic_arg_count_for_call(tcx, def_id, generics, seg, IsMethodCall::No);

if let ExplicitLateBound::Yes = arg_count.explicit_late_bound {
explicit_late_bound = ExplicitLateBound::Yes;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ fn typeck_with_fallback<'tcx>(
debug!(pending_obligations = ?fcx.fulfillment_cx.borrow().pending_obligations());

// This must be the last thing before `report_ambiguity_errors`.
fcx.resolve_coroutine_interiors(def_id.to_def_id());
fcx.resolve_coroutine_interiors();

debug!(pending_obligations = ?fcx.fulfillment_cx.borrow().pending_obligations());

Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_hir_typeck/src/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,8 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
pub(crate) fn cat_rvalue(
&self,
hir_id: hir::HirId,
span: Span,
// FIXME: remove
_span: Span,
expr_ty: Ty<'tcx>,
) -> PlaceWithHirId<'tcx> {
PlaceWithHirId::new(hir_id, expr_ty, PlaceBase::Rvalue, Vec::new())
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_hir_typeck/src/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {

let arg_count_correct = check_generic_arg_count_for_call(
self.tcx,
self.span,
pick.item.def_id,
generics,
seg,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ impl<'tcx> InferCtxt<'tcx> {
}

#[instrument(skip(self, snapshot), level = "debug")]
fn rollback_to(&self, cause: &str, snapshot: CombinedSnapshot<'tcx>) {
fn rollback_to(&self, snapshot: CombinedSnapshot<'tcx>) {
let CombinedSnapshot { undo_snapshot, region_constraints_snapshot, universe } = snapshot;

self.universe.set(universe);
Expand Down Expand Up @@ -894,7 +894,7 @@ impl<'tcx> InferCtxt<'tcx> {
self.commit_from(snapshot);
}
Err(_) => {
self.rollback_to("commit_if_ok -- error", snapshot);
self.rollback_to(snapshot);
}
}
r
Expand All @@ -908,7 +908,7 @@ impl<'tcx> InferCtxt<'tcx> {
{
let snapshot = self.start_snapshot();
let r = f(&snapshot);
self.rollback_to("probe", snapshot);
self.rollback_to(snapshot);
r
}

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_infer/src/infer/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ impl<'tcx> InferCtxt<'tcx> {
#[instrument(level = "debug", skip(self))]
pub fn register_member_constraints(
&self,
param_env: ty::ParamEnv<'tcx>,
opaque_type_key: OpaqueTypeKey<'tcx>,
concrete_ty: Ty<'tcx>,
span: Span,
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_infer/src/infer/relate/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,11 @@ impl<'tcx> InferCtxt<'tcx> {
}

(ty::ConstKind::Infer(InferConst::Var(vid)), _) => {
return self.unify_const_variable(vid, b, relation.param_env());
return self.unify_const_variable(vid, b);
}

(_, ty::ConstKind::Infer(InferConst::Var(vid))) => {
return self.unify_const_variable(vid, a, relation.param_env());
return self.unify_const_variable(vid, a);
}

(ty::ConstKind::Infer(InferConst::EffectVar(vid)), _) => {
Expand Down Expand Up @@ -310,7 +310,6 @@ impl<'tcx> InferCtxt<'tcx> {
&self,
target_vid: ty::ConstVid,
ct: ty::Const<'tcx>,
param_env: ty::ParamEnv<'tcx>,
) -> RelateResult<'tcx, ty::Const<'tcx>> {
let span = match self.inner.borrow_mut().const_unification_table().probe_value(target_vid) {
ConstVariableValue::Known { value } => {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/thir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,6 @@ impl<'tcx> PatRangeBoundary<'tcx> {
a.partial_cmp(&b)
}
ty::Int(ity) => {
use rustc_middle::ty::layout::IntegerExt;
let size = rustc_target::abi::Integer::from_int_ty(&tcx, *ity).size();
let a = size.sign_extend(a) as i128;
let b = size.sign_extend(b) as i128;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<'tcx> TypeRelation<'tcx> for MatchAgainstFreshVars<'tcx> {
fn regions(
&mut self,
a: ty::Region<'tcx>,
b: ty::Region<'tcx>,
_b: ty::Region<'tcx>,
) -> RelateResult<'tcx, ty::Region<'tcx>> {
Ok(a)
}
Expand Down
9 changes: 2 additions & 7 deletions compiler/rustc_mir_transform/src/const_prop_lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,12 +541,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
}

#[instrument(level = "trace", skip(self), ret)]
fn eval_rvalue(
&mut self,
rvalue: &Rvalue<'tcx>,
location: Location,
dest: &Place<'tcx>,
) -> Option<()> {
fn eval_rvalue(&mut self, rvalue: &Rvalue<'tcx>, dest: &Place<'tcx>) -> Option<()> {
if !dest.projection.is_empty() {
return None;
}
Expand Down Expand Up @@ -733,7 +728,7 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
_ if place.is_indirect() => {}
ConstPropMode::NoPropagation => self.ensure_not_propagated(place.local),
ConstPropMode::OnlyInsideOwnBlock | ConstPropMode::FullConstProp => {
if self.eval_rvalue(rvalue, location, place).is_none() {
if self.eval_rvalue(rvalue, place).is_none() {
// Const prop failed, so erase the destination, ensuring that whatever happens
// from here on, does not know about the previous value.
// This is important in case we have
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_pattern_analysis/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::MatchArm;
/// Traverse the patterns to collect any variants of a non_exhaustive enum that fail to be mentioned
/// in a given column.
#[instrument(level = "debug", skip(cx), ret)]
fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
fn collect_nonexhaustive_missing_variants<'p, 'tcx>(
cx: &RustcMatchCheckCtxt<'p, 'tcx>,
column: &PatternColumn<'p, RustcMatchCheckCtxt<'p, 'tcx>>,
) -> Result<Vec<WitnessPat<'p, 'tcx>>, ErrorGuaranteed> {
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_query_system/src/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl From<DepNodeIndex> for QueryInvocationId {
}
}

pub(crate) struct MarkFrame<'a> {
pub struct MarkFrame<'a> {
index: SerializedDepNodeIndex,
parent: Option<&'a MarkFrame<'a>>,
}
Expand Down Expand Up @@ -754,7 +754,6 @@ impl<D: Deps> DepGraphData<D> {
&self,
qcx: Qcx,
parent_dep_node_index: SerializedDepNodeIndex,
dep_node: &DepNode,
frame: Option<&MarkFrame<'_>>,
) -> Option<()> {
let dep_dep_node_color = self.colors.get(parent_dep_node_index);
Expand Down Expand Up @@ -861,7 +860,7 @@ impl<D: Deps> DepGraphData<D> {
let prev_deps = self.previous.edge_targets_from(prev_dep_node_index);

for dep_dep_node_index in prev_deps {
self.try_mark_parent_green(qcx, dep_dep_node_index, dep_node, Some(&frame))?;
self.try_mark_parent_green(qcx, dep_dep_node_index, Some(&frame))?;
}

// If we got here without hitting a `return` that means that all
Expand Down
Loading

0 comments on commit dc1f20a

Please sign in to comment.