-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Formalize defining_use_anchor #99383
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
Changes from all commits
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 |
---|---|---|
|
@@ -239,17 +239,31 @@ impl<'tcx> InferCtxtInner<'tcx> { | |
} | ||
} | ||
|
||
#[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
pub enum DefiningAnchor { | ||
/// `DefId` of the item. | ||
Bind(LocalDefId), | ||
/// When opaque types are not resolved, we `Bubble` up, meaning | ||
/// return the opaque/hidden type pair from query, for caller of query to handle it. | ||
Bubble, | ||
/// Used to catch type mismatch errors when handling opaque types. | ||
Error, | ||
} | ||
|
||
pub struct InferCtxt<'a, 'tcx> { | ||
pub tcx: TyCtxt<'tcx>, | ||
|
||
/// The `DefId` of the item in whose context we are performing inference or typeck. | ||
/// It is used to check whether an opaque type use is a defining use. | ||
/// | ||
/// If it is `None`, we can't resolve opaque types here and need to bubble up | ||
/// If it is `DefiningAnchor::Bubble`, we can't resolve opaque types here and need to bubble up | ||
/// the obligation. This frequently happens for | ||
/// short lived InferCtxt within queries. The opaque type obligations are forwarded | ||
/// to the outside until the end up in an `InferCtxt` for typeck or borrowck. | ||
pub defining_use_anchor: Option<LocalDefId>, | ||
/// | ||
/// It is default value is `DefiningAnchor::Error`, this way it is easier to catch errors that | ||
/// might come up during inference or typeck. | ||
pub defining_use_anchor: DefiningAnchor, | ||
|
||
/// During type-checking/inference of a body, `in_progress_typeck_results` | ||
/// contains a reference to the typeck results being built up, which are | ||
|
@@ -526,7 +540,7 @@ impl<'tcx> fmt::Display for FixupError<'tcx> { | |
pub struct InferCtxtBuilder<'tcx> { | ||
tcx: TyCtxt<'tcx>, | ||
fresh_typeck_results: Option<RefCell<ty::TypeckResults<'tcx>>>, | ||
defining_use_anchor: Option<LocalDefId>, | ||
defining_use_anchor: DefiningAnchor, | ||
} | ||
|
||
pub trait TyCtxtInferExt<'tcx> { | ||
|
@@ -535,7 +549,11 @@ pub trait TyCtxtInferExt<'tcx> { | |
|
||
impl<'tcx> TyCtxtInferExt<'tcx> for TyCtxt<'tcx> { | ||
fn infer_ctxt(self) -> InferCtxtBuilder<'tcx> { | ||
InferCtxtBuilder { tcx: self, defining_use_anchor: None, fresh_typeck_results: None } | ||
InferCtxtBuilder { | ||
tcx: self, | ||
defining_use_anchor: DefiningAnchor::Error, | ||
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. This used to be the equivalent to 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. 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. Ah sorry, I totally forgot about this I will look into this asap. |
||
fresh_typeck_results: None, | ||
} | ||
} | ||
} | ||
|
||
|
@@ -545,7 +563,7 @@ impl<'tcx> InferCtxtBuilder<'tcx> { | |
/// Will also change the scope for opaque type defining use checks to the given owner. | ||
pub fn with_fresh_in_progress_typeck_results(mut self, table_owner: LocalDefId) -> Self { | ||
self.fresh_typeck_results = Some(RefCell::new(ty::TypeckResults::new(table_owner))); | ||
self.with_opaque_type_inference(table_owner) | ||
self.with_opaque_type_inference(DefiningAnchor::Bind(table_owner)) | ||
} | ||
|
||
/// Whenever the `InferCtxt` should be able to handle defining uses of opaque types, | ||
|
@@ -554,8 +572,8 @@ impl<'tcx> InferCtxtBuilder<'tcx> { | |
/// It is only meant to be called in two places, for typeck | ||
/// (via `with_fresh_in_progress_typeck_results`) and for the inference context used | ||
/// in mir borrowck. | ||
pub fn with_opaque_type_inference(mut self, defining_use_anchor: LocalDefId) -> Self { | ||
self.defining_use_anchor = Some(defining_use_anchor); | ||
pub fn with_opaque_type_inference(mut self, defining_use_anchor: DefiningAnchor) -> Self { | ||
self.defining_use_anchor = defining_use_anchor; | ||
self | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.