Skip to content

Commit

Permalink
non_erasable_generics no longer needs tcx
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdd0121 committed Oct 28, 2024
1 parent 6c25def commit f86a0e8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
14 changes: 5 additions & 9 deletions src/infallible_allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::mir::mono::MonoItem;
use rustc_middle::ty::{Instance, TyCtxt};
use rustc_middle::ty::Instance;
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::source_map::Spanned;
use rustc_span::symbol::sym;
Expand All @@ -20,12 +20,8 @@ declare_tool_lint! {

declare_lint_pass!(InfallibleAllocation => [INFALLIBLE_ALLOCATION]);

fn is_generic_fn<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> bool {
instance
.args
.non_erasable_generics(tcx, instance.def_id())
.next()
.is_some()
fn is_generic_fn<'tcx>(instance: Instance<'tcx>) -> bool {
instance.args.non_erasable_generics().next().is_some()
}

impl<'tcx> LateLintPass<'tcx> for InfallibleAllocation {
Expand Down Expand Up @@ -163,7 +159,7 @@ impl<'tcx> LateLintPass<'tcx> for InfallibleAllocation {
let accessee = item.node;

if !accessee.def_id().is_local() && infallible.contains(&accessee) {
let is_generic = is_generic_fn(cx.tcx, *accessor);
let is_generic = is_generic_fn(*accessor);
let generic_note = if is_generic {
format!(
" when the caller is monomorphized as `{}`",
Expand All @@ -188,7 +184,7 @@ impl<'tcx> LateLintPass<'tcx> for InfallibleAllocation {
let mut visited = FxHashSet::default();
visited.insert(*accessor);
visited.insert(accessee);
while is_generic_fn(cx.tcx, caller) {
while is_generic_fn(caller) {
let spanned_caller = match backward
.get(&caller)
.map(|x| &**x)
Expand Down
2 changes: 1 addition & 1 deletion src/monomorphize_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ fn collect_items_rec<'tcx>(
// Check for PMEs and emit a diagnostic if one happened. To try to show relevant edges of the
// mono item graph.
if tcx.dcx().err_count() > error_count
&& starting_item.node.is_generic_fn(tcx)
&& starting_item.node.is_generic_fn()
&& starting_item.node.is_user_defined()
{
let formatted_item = with_no_trimmed_paths!(starting_item.node.to_string());
Expand Down

0 comments on commit f86a0e8

Please sign in to comment.