Skip to content
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

Infer regions for opaque types in borrowck #67681

Merged
merged 25 commits into from
Feb 15, 2020
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
033bd8c
Explain a test
matthewjasper Dec 26, 2019
7f41cf4
Check associated opaque types don't use unconstrained lifetimes
matthewjasper Dec 26, 2019
4af0952
Call `is_freeze` less in unsafety-checking
matthewjasper Dec 28, 2019
60970be
Distinguish RPIT from other impl trait
matthewjasper Dec 28, 2019
43dae91
Give some more queries descriptions
matthewjasper Dec 28, 2019
9664122
Simplify function signature in opaque_types
matthewjasper Dec 26, 2019
378b5b4
Generate more accurate MIR in `construct_error`
matthewjasper Dec 26, 2019
43a3348
Arena allocate the result of mir_borrowck
matthewjasper Dec 26, 2019
75ac0cc
Prepare to use borrowck to resolve opaque types
matthewjasper Dec 25, 2019
d9b9f00
Infer opaque type regions in borrow checking
matthewjasper Dec 26, 2019
edee23e
Avoid unnecessary opaque type errors in borrowck
matthewjasper Dec 28, 2019
2fb0254
Ensure RPIT types get recorded in borrowck
matthewjasper Dec 28, 2019
bb8c991
Erase regions in opaque types in typeck
matthewjasper Dec 28, 2019
93ac5bc
Update tests
matthewjasper Dec 28, 2019
f23bca7
Address review comments
matthewjasper Dec 29, 2019
728224d
Show inferred opaque types with `#[rustc_regions]`
matthewjasper Jan 5, 2020
5cfa7d1
Handle equal regions in opaque type inference
matthewjasper Jan 8, 2020
2bd16f3
Improve opaque type lifetime errors
matthewjasper Jan 11, 2020
dd1687e
Always check upper bounds when choosing member regions
matthewjasper Jan 11, 2020
e3e5d27
Use member constraint for most opaque types in NLL
matthewjasper Jan 11, 2020
78e0ab5
Update tests
matthewjasper Jan 11, 2020
6d9e270
Fix and test nested impl Trait
matthewjasper Jan 12, 2020
223a2ee
Add fast path to eq_opaque_type_and_type
matthewjasper Jan 17, 2020
edddb62
Split `type_of` out of collect.rs
matthewjasper Jan 17, 2020
d863978
Fix tests after rebase
matthewjasper Feb 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc/ty/flags.rs
Original file line number Diff line number Diff line change
@@ -138,7 +138,7 @@ impl FlagComputation {
}

&ty::Opaque(_, substs) => {
self.add_flags(TypeFlags::HAS_PROJECTION);
self.add_flags(TypeFlags::HAS_PROJECTION | TypeFlags::HAS_TY_OPAQUE);
self.add_substs(substs);
}

3 changes: 3 additions & 0 deletions src/librustc/ty/fold.rs
Original file line number Diff line number Diff line change
@@ -78,6 +78,9 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
fn has_projections(&self) -> bool {
self.has_type_flags(TypeFlags::HAS_PROJECTION)
}
fn has_opaque_types(&self) -> bool {
self.has_type_flags(TypeFlags::HAS_TY_OPAQUE)
}
fn references_error(&self) -> bool {
self.has_type_flags(TypeFlags::HAS_TY_ERR)
}
5 changes: 4 additions & 1 deletion src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
@@ -481,6 +481,8 @@ bitflags! {

const HAS_CT_INFER = 1 << 14;
const HAS_CT_PLACEHOLDER = 1 << 15;
/// Does this have any [Opaque] types.
const HAS_TY_OPAQUE = 1 << 16;

const NEEDS_SUBST = TypeFlags::HAS_PARAMS.bits |
TypeFlags::HAS_RE_EARLY_BOUND.bits;
@@ -503,7 +505,8 @@ bitflags! {
TypeFlags::HAS_RE_ERASED.bits |
TypeFlags::HAS_TY_PLACEHOLDER.bits |
TypeFlags::HAS_CT_INFER.bits |
TypeFlags::HAS_CT_PLACEHOLDER.bits;
TypeFlags::HAS_CT_PLACEHOLDER.bits |
TypeFlags::HAS_TY_OPAQUE.bits;
}
}

2 changes: 1 addition & 1 deletion src/librustc/ty/util.rs
Original file line number Diff line number Diff line change
@@ -615,7 +615,7 @@ impl<'tcx> TyCtxt<'tcx> {
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
if let ty::Opaque(def_id, substs) = t.kind {
self.expand_opaque_ty(def_id, substs).unwrap_or(t)
} else if t.has_projections() {
} else if t.has_opaque_types() {
t.super_fold_with(self)
} else {
t
16 changes: 16 additions & 0 deletions src/librustc_mir/borrow_check/type_check/mod.rs
Original file line number Diff line number Diff line change
@@ -1196,6 +1196,22 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
anon_ty={:?})",
revealed_ty, anon_ty
);

// Fast path for the common case.
if !anon_ty.has_opaque_types() {
if let Err(terr) = self.eq_types(anon_ty, revealed_ty, locations, category) {
span_mirbug!(
self,
locations,
"eq_opaque_type_and_type: `{:?}=={:?}` failed with `{:?}`",
revealed_ty,
anon_ty,
terr
);
}
return Ok(());
}

let infcx = self.infcx;
let tcx = infcx.tcx;
let param_env = self.param_env;