8000 Account for late-bound lifetimes in generics by cjgillot · Pull Request #103448 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Account for late-bound lifetimes in generics #103448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adapt clippy.
  • Loading branch information
cjgillot committed Oct 26, 2022
commit bf1127ddb1238ee5f012d3e6df49d92ac1a1cfca
4 changes: 1 addition & 3 deletions src/tools/clippy/clippy_lints/src/eta_reduction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
.map_or(callee_ty, |id| cx.tcx.type_of(id));
if check_sig(cx, closure_ty, call_ty);
let substs = cx.typeck_results().node_substs(callee.hir_id);
// This fixes some false positives that I don't entirely understand
if substs.is_empty() || !cx.typeck_results().expr_ty(expr).has_late_bound_regions();
// A type param function ref like `T::f` is not 'static, however
// it is if cast like `T::f as fn()`. This seems like a rustc bug.
if !substs.types().any(|t| matches!(t.kind(), ty::Param(_)));
Expand Down Expand Up @@ -217,7 +215,7 @@ fn check_sig<'tcx>(cx: &LateContext<'tcx>, closure_ty: Ty<'tcx>, call_ty: Ty<'tc
return false;
};
let closure_sig = cx.tcx.signature_unclosure(substs.as_closure().sig(), Unsafety::Normal);
cx.tcx.erase_late_bound_regions(closure_sig) == cx.tcx.erase_late_bound_regions(call_sig)
cx.tcx.anonymize_late_bound_regions(closure_sig) == cx.tcx.anonymize_late_bound_regions(call_sig)
}

fn get_ufcs_type_name(cx: &LateContext<'_>, method_def_id: DefId) -> String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,9 @@ fn is_to_string_on_string_like<'a>(
}

if let Some(substs) = cx.typeck_results().node_substs_opt(call_expr.hir_id)
&& let [generic_arg] = substs.as_slice()
&& let substs = substs.as_slice()
&& let Some(generic_arg) = substs.get(0)
&& substs.iter().skip(1).all(|arg| matches!(arg.unpack(), ty::GenericArgKind::Lifetime(_)))
&& let GenericArgKind::Type(ty) = generic_arg.unpack()
&& let Some(deref_trait_id) = cx.tcx.get_diagnostic_item(sym::Deref)
&& let Some(as_ref_trait_id) = cx.tcx.get_diagnostic_item(sym::AsRef)
Expand Down
5 changes: 4 additions & 1 deletion src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,12 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion {
&& let Some(trait_ref) = cx.tcx.impl_trait_ref(item.def_id)
&& let Some(trait_item_id) = cx.tcx.associated_item(def_id).trait_item_def_id
{
let substs = ty::InternalSubsts::identity_for_item(cx.tcx, trait_item_id)
.rebase_onto(cx.tcx, trait_ref.def_id, trait_ref.substs);
let substs = cx.tcx.erase_regions(substs);
(
trait_item_id,
FnKind::ImplTraitFn(cx.tcx.erase_regions(trait_ref.substs) as *const _ as usize),
FnKind::ImplTraitFn(substs as *const _ as usize),
usize::from(sig.decl.implicit_self.has_implicit_self()),
)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl<'tcx> PassByRefOrValue {
return;
}

let fn_sig = cx.tcx.fn_sig(def_id);
let fn_sig = cx.tcx.type_of(def_id).fn_sig(cx.tcx);
let fn_body = cx.enclosing_body.map(|id| cx.tcx.hir().body(id));

// Gather all the lifetimes found in the output type which may affect whether
Expand Down
0