-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Introduce Unnormalized wrapper
#155083
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
base: main
Are you sure you want to change the base?
Introduce Unnormalized wrapper
#155083
Changes from all commits
0a93671
a5d71cc
1613665
5407a88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| id: append-method-call | ||
|
|
||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: $OBJ.instantiate($A1, $A2) | ||
| # fix: $OBJ.instantiate($A1, $A2).skip_normalization() | ||
|
|
||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: $OBJ.instantiate_identity() | ||
| # fix: $OBJ.instantiate_identity().skip_normalization() | ||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: $OBJ.instantiate_identity($A) | ||
| # fix: $OBJ.instantiate_identity($A).skip_normalization() | ||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: $OBJ.instantiate_own($A1, $A2) | ||
| # fix: $OBJ.instantiate_own($A1, $A2).map(Unnormalized::skip_normalization) | ||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: $OBJ.instantiate_own_identity() | ||
| # fix: $OBJ.instantiate_own_identity().map(Unnormalized::skip_normalization) | ||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: $OBJ.iter_instantiated($A1, $A2) | ||
| # fix: $OBJ.iter_instantiated($A1, $A2).map(Unnormalized::skip_normalization) | ||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: $OBJ.iter_identity() | ||
| # fix: $OBJ.iter_identity().map(Unnormalized::skip_normalization) | ||
|
|
||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: $OBJ.iter_identity_copied() | ||
| # fix: $OBJ.iter_identity_copied().map(Unnormalized::skip_normalization) | ||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: $OBJ.iter_instantiated_copied($A1, $A2) | ||
| # fix: $OBJ.iter_instantiated_copied($A1, $A2).map(Unnormalized::skip_normalization) | ||
|
|
||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: $OBJ.type_of($A1).instantiate($A2, $A3) | ||
| # fix: $OBJ.type_of($A1).instantiate($A2, $A3).uncertain_skip() | ||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: $OBJ.fn_sig($A1).instantiate($A2, $A3) | ||
| # fix: $OBJ.fn_sig($A1).instantiate($A2, $A3).uncertain_skip() | ||
| # | ||
| # normalization. | ||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: $OBJ.normalize_erasing_regions($A1, $A2) | ||
| # fix: $OBJ.normalize_erasing_regions($A1, Unnormalized::new($A2)) | ||
|
|
||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: $OBJ.try_normalize_erasing_regions($A1, $A2) | ||
| # fix: $OBJ.try_normalize_erasing_regions($A1, Unnormalized::new($A2)) | ||
|
|
||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: wfcx.deeply_normalize($SPAN, $A2, $V) | ||
| # fix: wfcx.deeply_normalize($SPAN, $A2, Unnormalized::new($V)) | ||
| # | ||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: $OBJ.normalize($SPAN, $A2, $V) | ||
| # fix: $OBJ.normalize($SPAN, $A2, Unnormalized::new($V)) | ||
| # borrowck normalization | ||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: $OBJ.normalize($A1, $A2) | ||
| # fix: $OBJ.normalize(Unnormalized::new($A1), $A2) | ||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: $OBJ.deeply_normalize($A1, $A2) | ||
| # fix: $OBJ.deeply_normalize(Unnormalized::new($A1), $A2) | ||
|
|
||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: DeeplyNormalize { value: $V } | ||
| # fix: DeeplyNormalize { value: Unnormalized::new($V), tcx: PhantomData } | ||
|
|
||
| # uncertain skip iter | ||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: $OBJ.iter_instantiated_copied($A1, $A2) | ||
| # fix: $OBJ.iter_instantiated_copied($A1, $A2).map(Unnormalized::uncertain_skip) | ||
|
|
||
|
|
||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: $OBJ.ty($A1, args) | ||
| # fix: $OBJ.ty($A1, args).uncertain_skip() | ||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: ty::EarlyBinder::bind($A1).instantiate($A2, $A3) | ||
| # fix: ty::EarlyBinder::bind($A1).instantiate($A2, $A3).uncertain_skip() | ||
|
|
||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: $OBJ.normalize($A1, $A2, $A3) | ||
| # fix: ocx.structurally_normalize_ty($A1, $A2, Unnormalized::new($A3)) | ||
| # | ||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: $OBJ.instantiate_identity().skip_normalization() | ||
| # fix: $OBJ.instantiate_identity() | ||
| rule: | ||
| kind: call_expression | ||
| # pattern: $OBJ.instantiate($A1, $A2).skip_normalization() | ||
| pattern: $OBJ.instantiate($$$ARGS) | ||
| # fix: $OBJ.instantiate($A1, $A2) | ||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: $OBJ.iter_identity().map(Unnormalized::skip_normalization) | ||
| # fix: $OBJ.iter_identity() | ||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: $OBJ.iter_instantiated_copied($A1, $A2).map(Unnormalized::skip_normalization) | ||
| # fix: $OBJ.iter_instantiated_copied($A1, $A2) | ||
| # rule: | ||
| # kind: call_expression | ||
| # pattern: $OBJ.iter_instantiated($A1, $A2).map(Unnormalized::skip_normalization) | ||
| # fix: $OBJ.iter_instantiated($A1, $A2) | ||
|
|
||
| language: Rust |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -472,8 +472,13 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { | |
| // The move occurred as one of the arguments to a function call. Is that | ||
| // argument generic? `def_id` can't be a closure here, so using `fn_sig` is fine | ||
| let arg_param = if self.infcx.tcx.def_kind(def_id).is_fn_like() | ||
| && let sig = | ||
| self.infcx.tcx.fn_sig(def_id).instantiate_identity().skip_binder() | ||
| && let sig = self | ||
| .infcx | ||
| .tcx | ||
| .fn_sig(def_id) | ||
| .instantiate_identity() | ||
| .skip_normalization() | ||
| .skip_binder() | ||
| && let Some(arg_ty) = sig.inputs().get(pos + offset) | ||
| && let ty::Param(arg_param) = arg_ty.kind() | ||
| { | ||
|
|
@@ -685,7 +690,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { | |
| place_span: Span, | ||
| ) -> Option<ty::Mutability> { | ||
| let tcx = self.infcx.tcx; | ||
| let sig = tcx.fn_sig(callee_did).instantiate_identity().skip_binder(); | ||
| let sig = tcx.fn_sig(callee_did).instantiate_identity().skip_normalization().skip_binder(); | ||
| let clauses = tcx.predicates_of(callee_did); | ||
|
|
||
| let generic_args = match call_expr.kind { | ||
|
|
@@ -703,7 +708,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { | |
|
|
||
| // First, is there at least one method on one of `param`'s trait bounds? | ||
| // This keeps us from suggesting borrowing the argument to `mem::drop`, e.g. | ||
| if !clauses.instantiate_identity(tcx).predicates.iter().any(|clause| { | ||
| if !clauses.instantiate_identity(tcx).skip_normalization().predicates.iter().any(|clause| { | ||
| clause.as_trait_clause().is_some_and(|tc| { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we probably want a function |
||
| tc.self_ty().skip_binder().is_param(param.index) | ||
| && tc.polarity() == ty::PredicatePolarity::Positive | ||
|
|
@@ -729,8 +734,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { | |
| )); | ||
| let can_subst = |ty: Ty<'tcx>| { | ||
| // Normalize before comparing to see through type aliases and projections. | ||
| let old_ty = ty::EarlyBinder::bind(ty).instantiate(tcx, generic_args); | ||
| let new_ty = ty::EarlyBinder::bind(ty).instantiate(tcx, new_args); | ||
| let old_ty = | ||
| ty::EarlyBinder::bind(ty).instantiate(tcx, generic_args).skip_normalization(); | ||
| let new_ty = | ||
| ty::EarlyBinder::bind(ty).instantiate(tcx, new_args).skip_normalization(); | ||
| if let Ok(old_ty) = tcx.try_normalize_erasing_regions( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would try to change |
||
| self.infcx.typing_env(self.infcx.param_env), | ||
| old_ty, | ||
|
|
@@ -754,21 +761,23 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { | |
| } | ||
|
|
||
| // Test the callee's predicates, substituting in `ref_ty` for the moved argument type. | ||
| clauses.instantiate(tcx, new_args).predicates.iter().all(|&(mut clause)| { | ||
| // Normalize before testing to see through type aliases and projections. | ||
| if let Ok(normalized) = tcx.try_normalize_erasing_regions( | ||
| self.infcx.typing_env(self.infcx.param_env), | ||
| clause, | ||
| ) { | ||
| clause = normalized; | ||
| } | ||
| self.infcx.predicate_must_hold_modulo_regions(&Obligation::new( | ||
| tcx, | ||
| ObligationCause::dummy(), | ||
| self.infcx.param_env, | ||
| clause, | ||
| )) | ||
| }) | ||
| clauses.instantiate(tcx, new_args).skip_normalization().predicates.iter().all( | ||
| |&(mut clause)| { | ||
| // Normalize before testing to see through type aliases and projections. | ||
| if let Ok(normalized) = tcx.try_normalize_erasing_regions( | ||
| self.infcx.typing_env(self.infcx.param_env), | ||
| clause, | ||
| ) { | ||
| clause = normalized; | ||
| } | ||
| self.infcx.predicate_must_hold_modulo_regions(&Obligation::new( | ||
| tcx, | ||
| ObligationCause::dummy(), | ||
| self.infcx.param_env, | ||
| clause, | ||
| )) | ||
| }, | ||
| ) | ||
| }) { | ||
| let place_desc = if let Some(desc) = self.describe_place(moved_place) { | ||
| format!("`{desc}`") | ||
|
|
@@ -4153,11 +4162,20 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { | |
| if is_closure { | ||
| None | ||
| } else { | ||
| let ty = self.infcx.tcx.type_of(self.mir_def_id()).instantiate_identity(); | ||
| let ty = self | ||
| .infcx | ||
| .tcx | ||
| .type_of(self.mir_def_id()) | ||
| .instantiate_identity() | ||
| .skip_normalization(); | ||
| match ty.kind() { | ||
| ty::FnDef(_, _) | ty::FnPtr(..) => self.annotate_fn_sig( | ||
| self.mir_def_id(), | ||
| self.infcx.tcx.fn_sig(self.mir_def_id()).instantiate_identity(), | ||
| self.infcx | ||
| .tcx | ||
| .fn_sig(self.mir_def_id()) | ||
| .instantiate_identity() | ||
| .skip_normalization(), | ||
| ), | ||
| _ => None, | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
View changes since the review
can you add
fn skip_bindertoUnnormalized<[Early]Binder<T>>directly. When skipping binders we also don't care about normalization