-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #89045 - oli-obk:lazy_normalization_in_opaque_types, r=…
…nikomatsakis Register normalization obligations instead of immediately normalizing in opaque type instantiation For lazy TAIT we will need to instantiate opaque types from within `rustc_infer`, which cannot invoke normalization methods (they are in `rustc_trait_resolution`). So before we move the logic over to `rustc_infer`, we need make sure no normalization happens anymore. This PR resolves that by just registering normalization obligations and continuing. This PR is best reviewed commit by commit I also included f7ad36e which is just an independent cleanup that touches the same code and reduces diagnostics noise a bit r? `@nikomatsakis` cc `@spastorino`
- Loading branch information
Showing
8 changed files
with
78 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use rustc_middle::traits::ObligationCause; | ||
use rustc_middle::ty::{self, ToPredicate, Ty}; | ||
|
||
use crate::traits::{Obligation, PredicateObligation}; | ||
|
||
use super::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; | ||
use super::InferCtxt; | ||
|
||
impl<'a, 'tcx> InferCtxt<'a, 'tcx> { | ||
/// Instead of normalizing an associated type projection, | ||
/// this function generates an inference variable and registers | ||
/// an obligation that this inference variable must be the result | ||
/// of the given projection. This allows us to proceed with projections | ||
/// while they cannot be resolved yet due to missing information or | ||
/// simply due to the lack of access to the trait resolution machinery. | ||
pub fn infer_projection( | ||
&self, | ||
param_env: ty::ParamEnv<'tcx>, | ||
projection_ty: ty::ProjectionTy<'tcx>, | ||
cause: ObligationCause<'tcx>, | ||
recursion_depth: usize, | ||
obligations: &mut Vec<PredicateObligation<'tcx>>, | ||
) -> Ty<'tcx> { | ||
let def_id = projection_ty.item_def_id; | ||
let ty_var = self.next_ty_var(TypeVariableOrigin { | ||
kind: TypeVariableOriginKind::NormalizeProjectionType, | ||
span: self.tcx.def_span(def_id), | ||
}); | ||
let projection = ty::Binder::dummy(ty::ProjectionPredicate { projection_ty, ty: ty_var }); | ||
let obligation = Obligation::with_depth( | ||
cause, | ||
recursion_depth, | ||
param_env, | ||
projection.to_predicate(self.tcx), | ||
); | ||
obligations.push(obligation); | ||
ty_var | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters