-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Do not attempt to ascribe projections out of a ty var #55637
Merged
bors
merged 2 commits into
rust-lang:master
from
pnkfelix:issue-55552-dont-attempt-to-ascribe-projections-out-of-a-ty-var
Nov 10, 2018
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||||
---|---|---|---|---|---|---|
|
@@ -991,20 +991,39 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { | |||||
let v1 = ty::Contravariant.xform(v); | ||||||
|
||||||
let tcx = self.infcx.tcx; | ||||||
let mut projected_ty = PlaceTy::from_ty(ty); | ||||||
let ty = self.normalize(ty, locations); | ||||||
|
||||||
// We need to follow any provided projetions into the type. | ||||||
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.
Suggested change
|
||||||
// | ||||||
// if we hit a ty var as we descend, then just skip the | ||||||
// attempt to relate the mir local with any type. | ||||||
#[derive(Debug)] struct HitTyVar; | ||||||
let mut curr_projected_ty: Result<PlaceTy, HitTyVar>; | ||||||
|
||||||
curr_projected_ty = Ok(PlaceTy::from_ty(ty)); | ||||||
for proj in &user_ty.projs { | ||||||
projected_ty = projected_ty.projection_ty_core( | ||||||
let projected_ty = if let Ok(projected_ty) = curr_projected_ty { | ||||||
projected_ty | ||||||
} else { | ||||||
break; | ||||||
}; | ||||||
curr_projected_ty = projected_ty.projection_ty_core( | ||||||
tcx, proj, |this, field, &()| { | ||||||
let ty = this.field_ty(tcx, field); | ||||||
self.normalize(ty, locations) | ||||||
if this.to_ty(tcx).is_ty_var() { | ||||||
Err(HitTyVar) | ||||||
} else { | ||||||
let ty = this.field_ty(tcx, field); | ||||||
Ok(self.normalize(ty, locations)) | ||||||
} | ||||||
}); | ||||||
} | ||||||
debug!("user_ty base: {:?} freshened: {:?} projs: {:?} yields: {:?}", | ||||||
user_ty.base, ty, user_ty.projs, projected_ty); | ||||||
user_ty.base, ty, user_ty.projs, curr_projected_ty); | ||||||
|
||||||
let ty = projected_ty.to_ty(tcx); | ||||||
|
||||||
self.relate_types(ty, v1, a, locations, category)?; | ||||||
if let Ok(projected_ty) = curr_projected_ty { | ||||||
let ty = projected_ty.to_ty(tcx); | ||||||
self.relate_types(ty, v1, a, locations, category)?; | ||||||
} | ||||||
} | ||||||
UserTypeAnnotation::TypeOf(def_id, canonical_substs) => { | ||||||
let ( | ||||||
|
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 | ||||
---|---|---|---|---|---|---|
|
@@ -151,17 +151,35 @@ impl AscribeUserTypeCx<'me, 'gcx, 'tcx> { | |||||
debug!("relate_type_and_user_type: ty of def-id is {:?}", ty); | ||||||
let ty = self.normalize(ty); | ||||||
|
||||||
let mut projected_ty = PlaceTy::from_ty(ty); | ||||||
// We need to follow any provided projetions into the type. | ||||||
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.
Suggested change
|
||||||
// | ||||||
// if we hit a ty var as we descend, then just skip the | ||||||
// attempt to relate the mir local with any type. | ||||||
|
||||||
struct HitTyVar; | ||||||
let mut curr_projected_ty: Result<PlaceTy, HitTyVar>; | ||||||
curr_projected_ty = Ok(PlaceTy::from_ty(ty)); | ||||||
for proj in projs { | ||||||
projected_ty = projected_ty.projection_ty_core( | ||||||
let projected_ty = if let Ok(projected_ty) = curr_projected_ty { | ||||||
projected_ty | ||||||
} else { | ||||||
break; | ||||||
}; | ||||||
curr_projected_ty = projected_ty.projection_ty_core( | ||||||
tcx, proj, |this, field, &()| { | ||||||
let ty = this.field_ty(tcx, field); | ||||||
self.normalize(ty) | ||||||
if this.to_ty(tcx).is_ty_var() { | ||||||
Err(HitTyVar) | ||||||
} else { | ||||||
let ty = this.field_ty(tcx, field); | ||||||
Ok(self.normalize(ty)) | ||||||
} | ||||||
}); | ||||||
} | ||||||
let ty = projected_ty.to_ty(tcx); | ||||||
|
||||||
self.relate(mir_ty, variance, ty)?; | ||||||
if let Ok(projected_ty) = curr_projected_ty { | ||||||
let ty = projected_ty.to_ty(tcx); | ||||||
self.relate(mir_ty, variance, ty)?; | ||||||
} | ||||||
|
||||||
if let Some(UserSelfTy { | ||||||
impl_def_id, | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nit: rustfmt would put the
)
on the next line.