Skip to content

Commit

Permalink
Auto merge of #92805 - BoxyUwU:revert-lazy-anon-const-substs, r=lcnr
Browse files Browse the repository at this point in the history
partially revertish `lazily "compute" anon const default substs`

reverts #87280 except for some of the changes around `ty::Unevaluated` having a visitor and a generic for promoted
why revert: <rust-lang/rust#92805 (comment)>

r? `@lcnr`
  • Loading branch information
bors committed Jan 16, 2022
2 parents 938b4c3 + fb86f84 commit f4a88f2
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 39 deletions.
3 changes: 1 addition & 2 deletions clippy_lints/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
// skip if there is a `self` parameter binding to a type
// that contains `Self` (i.e.: `self: Box<Self>`), see #4804
if let Some(trait_self_ty) = self.trait_self_ty {
if map.name(cmt.hir_id) == kw::SelfLower && contains_ty(self.cx.tcx, cmt.place.ty(), trait_self_ty)
{
if map.name(cmt.hir_id) == kw::SelfLower && contains_ty(cmt.place.ty(), trait_self_ty) {
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/let_underscore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
if let Some(init) = local.init;
then {
let init_ty = cx.typeck_results().expr_ty(init);
let contains_sync_guard = init_ty.walk(cx.tcx).any(|inner| match inner.unpack() {
let contains_sync_guard = init_ty.walk().any(|inner| match inner.unpack() {
GenericArgKind::Type(inner_ty) => {
SYNC_GUARD_PATHS.iter().any(|path| match_type(cx, inner_ty, path))
},
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/loops/same_item_push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub(super) fn check<'tcx>(
if same_item_push_visitor.should_lint();
if let Some((vec, pushed_item)) = same_item_push_visitor.vec_push;
let vec_ty = cx.typeck_results().expr_ty(vec);
let ty = vec_ty.walk(cx.tcx).nth(1).unwrap().expect_ty();
let ty = vec_ty.walk().nth(1).unwrap().expect_ty();
if cx
.tcx
.lang_items()
Expand Down
10 changes: 5 additions & 5 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2129,10 +2129,10 @@ impl<'tcx> LateLintPass<'tcx> for Methods {

// walk the return type and check for Self (this does not check associated types)
if let Some(self_adt) = self_ty.ty_adt_def() {
if contains_adt_constructor(cx.tcx, ret_ty, self_adt) {
if contains_adt_constructor(ret_ty, self_adt) {
return;
}
} else if contains_ty(cx.tcx, ret_ty, self_ty) {
} else if contains_ty(ret_ty, self_ty) {
return;
}

Expand All @@ -2143,10 +2143,10 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
if let ty::PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder() {
// walk the associated type and check for Self
if let Some(self_adt) = self_ty.ty_adt_def() {
if contains_adt_constructor(cx.tcx, projection_predicate.ty, self_adt) {
if contains_adt_constructor(projection_predicate.ty, self_adt) {
return;
}
} else if contains_ty(cx.tcx, projection_predicate.ty, self_ty) {
} else if contains_ty(projection_predicate.ty, self_ty) {
return;
}
}
Expand Down Expand Up @@ -2195,7 +2195,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
if let TraitItemKind::Fn(_, _) = item.kind;
let ret_ty = return_ty(cx, item.hir_id());
let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty().skip_binder();
if !contains_ty(cx.tcx, ret_ty, self_ty);
if !contains_ty(ret_ty, self_ty);

then {
span_lint(
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/needless_pass_by_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
let fn_def_id = cx.tcx.hir().local_def_id(hir_id);

let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds().iter())
.filter(|p| !p.is_global(cx.tcx))
.filter(|p| !p.is_global())
.filter_map(|obligation| {
// Note that we do not want to deal with qualified predicates here.
match obligation.predicate.kind().no_bound_vars() {
Expand Down
5 changes: 4 additions & 1 deletion clippy_lints/src/non_copy_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ fn is_value_unfrozen_expr<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId, def_id: D

let result = cx.tcx.const_eval_resolve(
cx.param_env,
ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs),
ty::Unevaluated::new(
ty::WithOptConstParam::unknown(def_id),
substs,
),
None,
);
is_value_unfrozen_raw(cx, result, ty)
Expand Down
8 changes: 4 additions & 4 deletions clippy_lints/src/non_send_fields_in_send_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy {
non_send_fields.push(NonSendField {
def: field_def,
ty: field_ty,
generic_params: collect_generic_params(cx, field_ty),
generic_params: collect_generic_params(field_ty),
})
}
}
Expand Down Expand Up @@ -171,8 +171,8 @@ impl<'tcx> NonSendField<'tcx> {

/// Given a type, collect all of its generic parameters.
/// Example: `MyStruct<P, Box<Q, R>>` => `vec![P, Q, R]`
fn collect_generic_params<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Vec<Ty<'tcx>> {
ty.walk(cx.tcx)
fn collect_generic_params(ty: Ty<'_>) -> Vec<Ty<'_>> {
ty.walk()
.filter_map(|inner| match inner.unpack() {
GenericArgKind::Type(inner_ty) => Some(inner_ty),
_ => None,
Expand Down Expand Up @@ -226,7 +226,7 @@ fn ty_allowed_with_raw_pointer_heuristic<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'t

/// Checks if the type contains any pointer-like types in substs (including nested ones)
fn contains_pointer_like<'tcx>(cx: &LateContext<'tcx>, target_ty: Ty<'tcx>) -> bool {
for ty_node in target_ty.walk(cx.tcx) {
for ty_node in target_ty.walk() {
if let GenericArgKind::Type(inner_ty) = ty_node.unpack() {
match inner_ty.kind() {
ty::RawPtr(_) => {
Expand Down
15 changes: 6 additions & 9 deletions clippy_lints/src/redundant_clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rustc_middle::mir::{
visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor as _},
Mutability,
};
use rustc_middle::ty::{self, fold::TypeVisitor, Ty, TyCtxt};
use rustc_middle::ty::{self, fold::TypeVisitor, Ty};
use rustc_mir_dataflow::{Analysis, AnalysisDomain, CallReturnPlaces, GenKill, GenKillAnalysis, ResultsCursor};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::source_map::{BytePos, Span};
Expand Down Expand Up @@ -575,7 +575,7 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> {
self.possible_borrower.add(borrowed.local, lhs);
},
other => {
if ContainsRegion(self.cx.tcx)
if ContainsRegion
.visit_ty(place.ty(&self.body.local_decls, self.cx.tcx).ty)
.is_continue()
{
Expand Down Expand Up @@ -624,7 +624,7 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> {
.flat_map(HybridBitSet::iter)
.collect();

if ContainsRegion(self.cx.tcx)
if ContainsRegion
.visit_ty(self.body.local_decls[*dest].ty)
.is_break()
{
Expand Down Expand Up @@ -703,15 +703,12 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleOriginVisitor<'a, 'tcx> {
}
}

struct ContainsRegion<'tcx>(TyCtxt<'tcx>);
struct ContainsRegion;

impl<'tcx> TypeVisitor<'tcx> for ContainsRegion<'tcx> {
impl TypeVisitor<'_> for ContainsRegion {
type BreakTy = ();
fn tcx_for_anon_const_substs(&self) -> Option<TyCtxt<'tcx>> {
Some(self.0)
}

fn visit_region(&mut self, _: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
fn visit_region(&mut self, _: ty::Region<'_>) -> ControlFlow<Self::BreakTy> {
ControlFlow::BREAK
}
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/returns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ impl<'tcx> Visitor<'tcx> for BorrowVisitor<'_, 'tcx> {
.fn_sig(def_id)
.output()
.skip_binder()
.walk(self.cx.tcx)
.walk()
.any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_)));
}

Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/self_named_constructors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors {

// Ensure method is constructor-like
if let Some(self_adt) = self_ty.ty_adt_def() {
if !contains_adt_constructor(cx.tcx, ret_ty, self_adt) {
if !contains_adt_constructor(ret_ty, self_adt) {
return;
}
} else if !contains_ty(cx.tcx, ret_ty, self_ty) {
} else if !contains_ty(ret_ty, self_ty) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/unnecessary_sort_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ fn expr_borrows(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
let ty = cx.typeck_results().expr_ty(expr);
matches!(ty.kind(), ty::Ref(..))
|| ty
.walk(cx.tcx)
.walk()
.any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_)))
}

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/use_self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
//
// See also https://github.com/rust-lang/rust-clippy/issues/2894.
for (impl_hir_ty, trait_sem_ty) in impl_inputs_outputs.zip(trait_method_sig.inputs_and_output) {
if trait_sem_ty.walk(cx.tcx).any(|inner| inner == self_ty.into()) {
if trait_sem_ty.walk().any(|inner| inner == self_ty.into()) {
let mut visitor = SkipTyCollector::default();
visitor.visit_ty(impl_hir_ty);
types_to_skip.extend(visitor.types_to_skip);
Expand Down
5 changes: 4 additions & 1 deletion clippy_utils/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,10 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
.tcx
.const_eval_resolve(
self.param_env,
ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs),
ty::Unevaluated::new(
ty::WithOptConstParam::unknown(def_id),
substs,
),
None,
)
.ok()
Expand Down
6 changes: 3 additions & 3 deletions clippy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1955,7 +1955,7 @@ pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_>, did: DefId) -> bool {
.predicates_of(did)
.predicates
.iter()
.filter_map(|(p, _)| if p.is_global(cx.tcx) { Some(*p) } else { None });
.filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None });
traits::impossible_predicates(
cx.tcx,
traits::elaborate_predicates(cx.tcx, predicates)
Expand Down Expand Up @@ -2001,15 +2001,15 @@ pub fn is_slice_of_primitives(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<S
if is_primitive {
// if we have wrappers like Array, Slice or Tuple, print these
// and get the type enclosed in the slice ref
match expr_type.peel_refs().walk(cx.tcx).nth(1).unwrap().expect_ty().kind() {
match expr_type.peel_refs().walk().nth(1).unwrap().expect_ty().kind() {
rustc_ty::Slice(..) => return Some("slice".into()),
rustc_ty::Array(..) => return Some("array".into()),
rustc_ty::Tuple(..) => return Some("tuple".into()),
_ => {
// is_recursively_primitive_type() should have taken care
// of the rest and we can rely on the type that is found
let refs_peeled = expr_type.peel_refs();
return Some(refs_peeled.walk(cx.tcx).last().unwrap().to_string());
return Some(refs_peeled.walk().last().unwrap().to_string());
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_utils/src/qualify_min_const_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub fn is_min_const_fn<'a, 'tcx>(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, msrv:
}

fn check_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) -> McfResult {
for arg in ty.walk(tcx) {
for arg in ty.walk() {
let ty = match arg.unpack() {
GenericArgKind::Type(ty) => ty,

Expand Down
10 changes: 5 additions & 5 deletions clippy_utils/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ pub fn can_partially_move_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool
}

/// Walks into `ty` and returns `true` if any inner type is the same as `other_ty`
pub fn contains_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, other_ty: Ty<'tcx>) -> bool {
ty.walk(tcx).any(|inner| match inner.unpack() {
pub fn contains_ty(ty: Ty<'_>, other_ty: Ty<'_>) -> bool {
ty.walk().any(|inner| match inner.unpack() {
GenericArgKind::Type(inner_ty) => ty::TyS::same_type(other_ty, inner_ty),
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false,
})
}

/// Walks into `ty` and returns `true` if any inner type is an instance of the given adt
/// constructor.
pub fn contains_adt_constructor<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, adt: &'tcx AdtDef) -> bool {
ty.walk(tcx).any(|inner| match inner.unpack() {
pub fn contains_adt_constructor(ty: Ty<'_>, adt: &AdtDef) -> bool {
ty.walk().any(|inner| match inner.unpack() {
GenericArgKind::Type(inner_ty) => inner_ty.ty_adt_def() == Some(adt),
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false,
})
Expand Down Expand Up @@ -221,7 +221,7 @@ fn is_normalizable_helper<'tcx>(
.iter()
.all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, substs), cache))
}),
_ => ty.walk(cx.tcx).all(|generic_arg| match generic_arg.unpack() {
_ => ty.walk().all(|generic_arg| match generic_arg.unpack() {
GenericArgKind::Type(inner_ty) if inner_ty != ty => {
is_normalizable_helper(cx, param_env, inner_ty, cache)
},
Expand Down

0 comments on commit f4a88f2

Please sign in to comment.