-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Miscellaneous cleanups to borrowck related code #150550
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 |
|---|---|---|
|
|
@@ -842,7 +842,7 @@ impl BorrowKind { | |
|
|
||
| /// Returns whether borrows represented by this kind are allowed to be split into separate | ||
| /// Reservation and Activation phases. | ||
| pub fn allows_two_phase_borrow(&self) -> bool { | ||
| pub fn is_two_phase_borrow(&self) -> bool { | ||
|
Member
Author
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. in some sense its always a two phase borrow, just sometimes its activated at the same point its created I think? The previous name confused me because it made it sound like a reference may or may not be a two phase borrow and then we went on to unconditionally treat it as two phase without ever checking if it "actually is". |
||
| match *self { | ||
| BorrowKind::Shared | ||
| | BorrowKind::Fake(_) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,23 +61,28 @@ pub fn compute_implied_outlives_bounds_inner<'tcx>( | |
| "compute_implied_outlives_bounds assumes region obligations are empty before starting" | ||
| ); | ||
|
|
||
| let normalize_ty = |ty| -> Result<_, NoSolution> { | ||
| // We must normalize the type so we can compute the right outlives components. | ||
| // for example, if we have some constrained param type like `T: Trait<Out = U>`, | ||
| // and we know that `&'a T::Out` is WF, then we want to imply `U: 'a`. | ||
| let ty = ocx | ||
| .deeply_normalize(&ObligationCause::dummy_with_span(span), param_env, ty) | ||
| .map_err(|_| NoSolution)?; | ||
| Ok(ty) | ||
| }; | ||
| // FIXME: This doesn't seem right. All call sites already normalize `ty`: | ||
| // - `Ty`s from the `DefiningTy` in Borrowck: we have to normalize in the caller | ||
| // in order to get implied bounds involving any unconstrained region vars | ||
| // created as part of normalizing the sig. See #136547 | ||
| // - `Ty`s from impl headers in Borrowck and in Non-Borrowck contexts: we have | ||
| // to normalize in the caller as computing implied bounds from unnormalized | ||
| // types would be unsound. See #100989 | ||
| // | ||
| // We must normalize the type so we can compute the right outlives components. | ||
| // for example, if we have some constrained param type like `T: Trait<Out = U>`, | ||
| // and we know that `&'a T::Out` is WF, then we want to imply `U: 'a`. | ||
| let normalized_ty = ocx | ||
| .deeply_normalize(&ObligationCause::dummy_with_span(span), param_env, ty) | ||
| .map_err(|_| NoSolution)?; | ||
|
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. did you test removing the
Member
Author
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. it didn't break anything but I also didn't feel confident enough in our test suite to just yeet it 🤔 I guess the failure mode here is "less implied bounds" which is not unsound so it's probably quite safe to do, and it should be easy enough to bisect this PR from a crater regression
Member
Author
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 there were some weird diagnostic changes that I didn't want to spend the time investigating
Member
Author
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. specifically, |
||
|
|
||
| // Sometimes when we ask what it takes for T: WF, we get back that | ||
| // U: WF is required; in that case, we push U onto this stack and | ||
| // process it next. Because the resulting predicates aren't always | ||
| // guaranteed to be a subset of the original type, so we need to store the | ||
| // WF args we've computed in a set. | ||
| let mut checked_wf_args = rustc_data_structures::fx::FxHashSet::default(); | ||
| let mut wf_args = vec![ty.into(), normalize_ty(ty)?.into()]; | ||
| let mut wf_args = vec![ty.into(), normalized_ty.into()]; | ||
|
|
||
| let mut outlives_bounds: Vec<OutlivesBound<'tcx>> = vec![]; | ||
|
|
||
|
|
@@ -103,8 +108,8 @@ pub fn compute_implied_outlives_bounds_inner<'tcx>( | |
| continue; | ||
| }; | ||
| match pred { | ||
| // FIXME(const_generics): Make sure that `<'a, 'b, const N: &'a &'b u32>` is sound | ||
| // if we ever support that | ||
| // FIXME(generic_const_parameter_types): Make sure that `<'a, 'b, const N: &'a &'b u32>` | ||
| // is sound if we ever support that | ||
| ty::PredicateKind::Clause(ty::ClauseKind::Trait(..)) | ||
| | ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(..)) | ||
| | ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..)) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.