Skip to content

Commit a5d71cc

Browse files
committed
temporarily skip normalization for all wrapper usages
1 parent 0a93671 commit a5d71cc

191 files changed

Lines changed: 1906 additions & 896 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

append_method.yaml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
id: append-method-call
2+
3+
# rule:
4+
# kind: call_expression
5+
# pattern: $OBJ.instantiate($A1, $A2)
6+
# fix: $OBJ.instantiate($A1, $A2).skip_normalization()
7+
8+
# rule:
9+
# kind: call_expression
10+
# pattern: $OBJ.instantiate_identity()
11+
# fix: $OBJ.instantiate_identity().skip_normalization()
12+
# rule:
13+
# kind: call_expression
14+
# pattern: $OBJ.instantiate_identity($A)
15+
# fix: $OBJ.instantiate_identity($A).skip_normalization()
16+
# rule:
17+
# kind: call_expression
18+
# pattern: $OBJ.instantiate_own($A1, $A2)
19+
# fix: $OBJ.instantiate_own($A1, $A2).map(Unnormalized::skip_normalization)
20+
# rule:
21+
# kind: call_expression
22+
# pattern: $OBJ.instantiate_own_identity()
23+
# fix: $OBJ.instantiate_own_identity().map(Unnormalized::skip_normalization)
24+
# rule:
25+
# kind: call_expression
26+
# pattern: $OBJ.iter_instantiated($A1, $A2)
27+
# fix: $OBJ.iter_instantiated($A1, $A2).map(Unnormalized::skip_normalization)
28+
# rule:
29+
# kind: call_expression
30+
# pattern: $OBJ.iter_identity()
31+
# fix: $OBJ.iter_identity().map(Unnormalized::skip_normalization)
32+
33+
# rule:
34+
# kind: call_expression
35+
# pattern: $OBJ.iter_identity_copied()
36+
# fix: $OBJ.iter_identity_copied().map(Unnormalized::skip_normalization)
37+
# rule:
38+
# kind: call_expression
39+
# pattern: $OBJ.iter_instantiated_copied($A1, $A2)
40+
# fix: $OBJ.iter_instantiated_copied($A1, $A2).map(Unnormalized::skip_normalization)
41+
42+
# rule:
43+
# kind: call_expression
44+
# pattern: $OBJ.type_of($A1).instantiate($A2, $A3)
45+
# fix: $OBJ.type_of($A1).instantiate($A2, $A3).uncertain_skip()
46+
# rule:
47+
# kind: call_expression
48+
# pattern: $OBJ.fn_sig($A1).instantiate($A2, $A3)
49+
# fix: $OBJ.fn_sig($A1).instantiate($A2, $A3).uncertain_skip()
50+
#
51+
# normalization.
52+
# rule:
53+
# kind: call_expression
54+
# pattern: $OBJ.normalize_erasing_regions($A1, $A2)
55+
# fix: $OBJ.normalize_erasing_regions($A1, Unnormalized::new($A2))
56+
57+
# rule:
58+
# kind: call_expression
59+
# pattern: $OBJ.try_normalize_erasing_regions($A1, $A2)
60+
# fix: $OBJ.try_normalize_erasing_regions($A1, Unnormalized::new($A2))
61+
62+
# rule:
63+
# kind: call_expression
64+
# pattern: wfcx.deeply_normalize($SPAN, $A2, $V)
65+
# fix: wfcx.deeply_normalize($SPAN, $A2, Unnormalized::new($V))
66+
#
67+
# rule:
68+
# kind: call_expression
69+
# pattern: $OBJ.normalize($SPAN, $A2, $V)
70+
# fix: $OBJ.normalize($SPAN, $A2, Unnormalized::new($V))
71+
# borrowck normalization
72+
# rule:
73+
# kind: call_expression
74+
# pattern: $OBJ.normalize($A1, $A2)
75+
# fix: $OBJ.normalize(Unnormalized::new($A1), $A2)
76+
# rule:
77+
# kind: call_expression
78+
# pattern: $OBJ.deeply_normalize($A1, $A2)
79+
# fix: $OBJ.deeply_normalize(Unnormalized::new($A1), $A2)
80+
81+
# rule:
82+
# kind: call_expression
83+
# pattern: DeeplyNormalize { value: $V }
84+
# fix: DeeplyNormalize { value: Unnormalized::new($V), tcx: PhantomData }
85+
86+
# uncertain skip iter
87+
# rule:
88+
# kind: call_expression
89+
# pattern: $OBJ.iter_instantiated_copied($A1, $A2)
90+
# fix: $OBJ.iter_instantiated_copied($A1, $A2).map(Unnormalized::uncertain_skip)
91+
92+
93+
# rule:
94+
# kind: call_expression
95+
# pattern: $OBJ.ty($A1, args)
96+
# fix: $OBJ.ty($A1, args).uncertain_skip()
97+
# rule:
98+
# kind: call_expression
99+
# pattern: ty::EarlyBinder::bind($A1).instantiate($A2, $A3)
100+
# fix: ty::EarlyBinder::bind($A1).instantiate($A2, $A3).uncertain_skip()
101+
102+
# rule:
103+
# kind: call_expression
104+
# pattern: $OBJ.normalize($A1, $A2, $A3)
105+
# fix: ocx.structurally_normalize_ty($A1, $A2, Unnormalized::new($A3))
106+
#
107+
# rule:
108+
# kind: call_expression
109+
# pattern: $OBJ.instantiate_identity().skip_normalization()
110+
# fix: $OBJ.instantiate_identity()
111+
rule:
112+
kind: call_expression
113+
# pattern: $OBJ.instantiate($A1, $A2).skip_normalization()
114+
pattern: $OBJ.instantiate($$$ARGS)
115+
# fix: $OBJ.instantiate($A1, $A2)
116+
# rule:
117+
# kind: call_expression
118+
# pattern: $OBJ.iter_identity().map(Unnormalized::skip_normalization)
119+
# fix: $OBJ.iter_identity()
120+
# rule:
121+
# kind: call_expression
122+
# pattern: $OBJ.iter_instantiated_copied($A1, $A2).map(Unnormalized::skip_normalization)
123+
# fix: $OBJ.iter_instantiated_copied($A1, $A2)
124+
# rule:
125+
# kind: call_expression
126+
# pattern: $OBJ.iter_instantiated($A1, $A2).map(Unnormalized::skip_normalization)
127+
# fix: $OBJ.iter_instantiated($A1, $A2)
128+
129+
language: Rust

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,13 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
472472
// The move occurred as one of the arguments to a function call. Is that
473473
// argument generic? `def_id` can't be a closure here, so using `fn_sig` is fine
474474
let arg_param = if self.infcx.tcx.def_kind(def_id).is_fn_like()
475-
&& let sig =
476-
self.infcx.tcx.fn_sig(def_id).instantiate_identity().skip_binder()
475+
&& let sig = self
476+
.infcx
477+
.tcx
478+
.fn_sig(def_id)
479+
.instantiate_identity()
480+
.skip_normalization()
481+
.skip_binder()
477482
&& let Some(arg_ty) = sig.inputs().get(pos + offset)
478483
&& let ty::Param(arg_param) = arg_ty.kind()
479484
{
@@ -685,7 +690,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
685690
place_span: Span,
686691
) -> Option<ty::Mutability> {
687692
let tcx = self.infcx.tcx;
688-
let sig = tcx.fn_sig(callee_did).instantiate_identity().skip_binder();
693+
let sig = tcx.fn_sig(callee_did).instantiate_identity().skip_normalization().skip_binder();
689694
let clauses = tcx.predicates_of(callee_did);
690695

691696
let generic_args = match call_expr.kind {
@@ -703,7 +708,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
703708

704709
// First, is there at least one method on one of `param`'s trait bounds?
705710
// This keeps us from suggesting borrowing the argument to `mem::drop`, e.g.
706-
if !clauses.instantiate_identity(tcx).predicates.iter().any(|clause| {
711+
if !clauses.instantiate_identity(tcx).skip_normalization().predicates.iter().any(|clause| {
707712
clause.as_trait_clause().is_some_and(|tc| {
708713
tc.self_ty().skip_binder().is_param(param.index)
709714
&& tc.polarity() == ty::PredicatePolarity::Positive
@@ -729,8 +734,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
729734
));
730735
let can_subst = |ty: Ty<'tcx>| {
731736
// Normalize before comparing to see through type aliases and projections.
732-
let old_ty = ty::EarlyBinder::bind(ty).instantiate(tcx, generic_args);
733-
let new_ty = ty::EarlyBinder::bind(ty).instantiate(tcx, new_args);
737+
let old_ty =
738+
ty::EarlyBinder::bind(ty).instantiate(tcx, generic_args).skip_normalization();
739+
let new_ty =
740+
ty::EarlyBinder::bind(ty).instantiate(tcx, new_args).skip_normalization();
734741
if let Ok(old_ty) = tcx.try_normalize_erasing_regions(
735742
self.infcx.typing_env(self.infcx.param_env),
736743
old_ty,
@@ -754,21 +761,23 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
754761
}
755762

756763
// Test the callee's predicates, substituting in `ref_ty` for the moved argument type.
757-
clauses.instantiate(tcx, new_args).predicates.iter().all(|&(mut clause)| {
758-
// Normalize before testing to see through type aliases and projections.
759-
if let Ok(normalized) = tcx.try_normalize_erasing_regions(
760-
self.infcx.typing_env(self.infcx.param_env),
761-
clause,
762-
) {
763-
clause = normalized;
764-
}
765-
self.infcx.predicate_must_hold_modulo_regions(&Obligation::new(
766-
tcx,
767-
ObligationCause::dummy(),
768-
self.infcx.param_env,
769-
clause,
770-
))
771-
})
764+
clauses.instantiate(tcx, new_args).skip_normalization().predicates.iter().all(
765+
|&(mut clause)| {
766+
// Normalize before testing to see through type aliases and projections.
767+
if let Ok(normalized) = tcx.try_normalize_erasing_regions(
768+
self.infcx.typing_env(self.infcx.param_env),
769+
clause,
770+
) {
771+
clause = normalized;
772+
}
773+
self.infcx.predicate_must_hold_modulo_regions(&Obligation::new(
774+
tcx,
775+
ObligationCause::dummy(),
776+
self.infcx.param_env,
777+
clause,
778+
))
779+
},
780+
)
772781
}) {
773782
let place_desc = if let Some(desc) = self.describe_place(moved_place) {
774783
format!("`{desc}`")
@@ -4153,11 +4162,20 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
41534162
if is_closure {
41544163
None
41554164
} else {
4156-
let ty = self.infcx.tcx.type_of(self.mir_def_id()).instantiate_identity();
4165+
let ty = self
4166+
.infcx
4167+
.tcx
4168+
.type_of(self.mir_def_id())
4169+
.instantiate_identity()
4170+
.skip_normalization();
41574171
match ty.kind() {
41584172
ty::FnDef(_, _) | ty::FnPtr(..) => self.annotate_fn_sig(
41594173
self.mir_def_id(),
4160-
self.infcx.tcx.fn_sig(self.mir_def_id()).instantiate_identity(),
4174+
self.infcx
4175+
.tcx
4176+
.fn_sig(self.mir_def_id())
4177+
.instantiate_identity()
4178+
.skip_normalization(),
41614179
),
41624180
_ => None,
41634181
}

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,9 +1366,16 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
13661366
let parent_self_ty =
13671367
matches!(tcx.def_kind(parent_did), rustc_hir::def::DefKind::Impl { .. })
13681368
.then_some(parent_did)
1369-
.and_then(|did| match tcx.type_of(did).instantiate_identity().kind() {
1370-
ty::Adt(def, ..) => Some(def.did()),
1371-
_ => None,
1369+
.and_then(|did| {
1370+
match tcx
1371+
.type_of(did)
1372+
.instantiate_identity()
1373+
.skip_normalization()
1374+
.kind()
1375+
{
1376+
ty::Adt(def, ..) => Some(def.did()),
1377+
_ => None,
1378+
}
13721379
});
13731380
let is_option_or_result = parent_self_ty.is_some_and(|def_id| {
13741381
matches!(tcx.get_diagnostic_name(def_id), Some(sym::Option | sym::Result))
@@ -1445,7 +1452,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
14451452
&& let self_ty = self.infcx.instantiate_binder_with_fresh_vars(
14461453
fn_call_span,
14471454
BoundRegionConversionTime::FnCall,
1448-
tcx.fn_sig(method_did).instantiate(tcx, method_args).input(0),
1455+
tcx.fn_sig(method_did)
1456+
.instantiate(tcx, method_args)
1457+
.skip_normalization()
1458+
.input(0),
14491459
)
14501460
&& self.infcx.can_eq(self.infcx.param_env, ty, self_ty)
14511461
{

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,12 +627,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
627627
hir::ExprKind::Call(callee, _) => {
628628
let ty = typeck_result.node_type_opt(callee.hir_id)?;
629629
let ty::FnDef(fn_def_id, args) = *ty.kind() else { return None };
630-
tcx.predicates_of(fn_def_id).instantiate(tcx, args)
630+
tcx.predicates_of(fn_def_id).instantiate(tcx, args).skip_normalization()
631631
}
632632
hir::ExprKind::MethodCall(..) => {
633633
let (_, method) = typeck_result.type_dependent_def(parent.hir_id)?;
634634
let args = typeck_result.node_args(parent.hir_id);
635-
tcx.predicates_of(method).instantiate(tcx, args)
635+
tcx.predicates_of(method).instantiate(tcx, args).skip_normalization()
636636
}
637637
_ => return None,
638638
};

compiler/rustc_borrowck/src/diagnostics/opaque_types.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_hir::def_id::DefId;
99
use rustc_middle::mir::{self, ConstraintCategory, Location};
1010
use rustc_middle::ty::{
1111
self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
12+
Unnormalized,
1213
};
1314
use rustc_span::Span;
1415
use rustc_trait_selection::error_reporting::infer::region::unexpected_hidden_region_diagnostic;
@@ -282,6 +283,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for CheckExplicitRegionMentionAndCollectGen
282283
.tcx
283284
.explicit_item_bounds(def_id)
284285
.iter_instantiated_copied(self.tcx, opaque.args)
286+
.map(Unnormalized::skip_normalization)
285287
{
286288
bound.visit_with(self)?;
287289
}

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
595595

596596
let mut output_ty = self.regioncx.universal_regions().unnormalized_output_ty;
597597
if let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) = *output_ty.kind() {
598-
output_ty = self.infcx.tcx.type_of(def_id).instantiate_identity()
598+
output_ty = self.infcx.tcx.type_of(def_id).instantiate_identity().skip_normalization()
599599
};
600600

601601
debug!("report_fnmut_error: output_ty={:?}", output_ty);
@@ -930,7 +930,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
930930
debug!(?fn_did, ?args);
931931

932932
// Only suggest this on function calls, not closures
933-
let ty = tcx.type_of(fn_did).instantiate_identity();
933+
let ty = tcx.type_of(fn_did).instantiate_identity().skip_normalization();
934934
debug!("ty: {:?}, ty.kind: {:?}", ty, ty.kind());
935935
if let ty::Closure(_, _) = ty.kind() {
936936
return;
@@ -1050,7 +1050,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
10501050
else {
10511051
return;
10521052
};
1053-
let ty::Closure(_, args) = *tcx.type_of(closure_def_id).instantiate_identity().kind()
1053+
let ty::Closure(_, args) =
1054+
*tcx.type_of(closure_def_id).instantiate_identity().skip_normalization().kind()
10541055
else {
10551056
return;
10561057
};
@@ -1143,7 +1144,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
11431144
}
11441145
});
11451146

1146-
let preds = tcx.predicates_of(method_def_id).instantiate(tcx, args);
1147+
let preds = tcx.predicates_of(method_def_id).instantiate(tcx, args).skip_normalization();
11471148

11481149
let ocx = ObligationCtxt::new(&self.infcx);
11491150
ocx.register_obligations(preds.iter().map(|(pred, span)| {

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
418418

419419
// Get the parent fn's signature with liberated late-bound regions,
420420
// so we have `ReLateParam` instead of `ReBound`.
421-
let parent_fn_sig = tcx.fn_sig(parent_def_id).instantiate_identity();
421+
let parent_fn_sig = tcx.fn_sig(parent_def_id).instantiate_identity().skip_normalization();
422422
let liberated_sig = tcx.liberate_late_bound_regions(parent_def_id, parent_fn_sig);
423423
let parent_param_ty = *liberated_sig.inputs().get(param_index)?;
424424

@@ -1023,10 +1023,10 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
10231023
return None;
10241024
};
10251025

1026-
let found = tcx
1027-
.any_free_region_meets(&tcx.type_of(region_parent).instantiate_identity(), |r| {
1028-
r.kind() == ty::ReEarlyParam(region)
1029-
});
1026+
let found = tcx.any_free_region_meets(
1027+
&tcx.type_of(region_parent).instantiate_identity().skip_normalization(),
1028+
|r| r.kind() == ty::ReEarlyParam(region),
1029+
);
10301030

10311031
Some(RegionName {
10321032
name: self.synthesize_region_name(),
@@ -1056,6 +1056,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
10561056
.tcx
10571057
.predicates_of(self.body.source.def_id())
10581058
.instantiate_identity(self.infcx.tcx)
1059+
.skip_normalization()
10591060
.predicates;
10601061

10611062
if let Some(upvar_index) = self

compiler/rustc_borrowck/src/region_infer/opaque_types/mod.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -569,16 +569,17 @@ pub(crate) fn apply_definition_site_hidden_types<'tcx>(
569569
};
570570

571571
// We erase all non-member region of the opaque and need to treat these as existentials.
572-
let expected_ty =
573-
ty::fold_regions(tcx, expected.ty.instantiate(tcx, key.args), |re, _dbi| {
574-
match re.kind() {
575-
ty::ReErased => infcx.next_nll_region_var(
576-
NllRegionVariableOrigin::Existential { name: None },
577-
|| crate::RegionCtxt::Existential(None),
578-
),
579-
_ => re,
580-
}
581-
});
572+
let expected_ty = ty::fold_regions(
573+
tcx,
574+
expected.ty.instantiate(tcx, key.args).skip_normalization(),
575+
|re, _dbi| match re.kind() {
576+
ty::ReErased => infcx.next_nll_region_var(
577+
NllRegionVariableOrigin::Existential { name: None },
578+
|| crate::RegionCtxt::Existential(None),
579+
),
580+
_ => re,
581+
},
582+
);
582583

583584
// We now simply equate the expected with the actual hidden type.
584585
let locations = Locations::All(hidden_type.span);

0 commit comments

Comments
 (0)