Skip to content

Commit fba7f77

Browse files
committed
Revert the non-view changes
1 parent 0ca62cc commit fba7f77

File tree

4 files changed

+109
-126
lines changed

4 files changed

+109
-126
lines changed

src/librustc/infer/outlives/verify.rs

+16-23
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
5151

5252
// Start with anything like `T: 'a` we can scrape from the
5353
// environment
54-
let param_bounds = self
55-
.declared_generic_bounds_from_env(GenericKind::Param(param_ty))
56-
.into_iter()
57-
.map(|outlives| outlives.1);
54+
let param_bounds =
55+
self.declared_generic_bounds_from_env(param_ty).into_iter().map(|outlives| outlives.1);
5856

5957
// Add in the default bound of fn body that applies to all in
6058
// scope type parameters:
@@ -110,24 +108,21 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
110108

111109
let projection_ty_as_ty = projection_ty.as_ty();
112110

113-
let mut bounds = Vec::new();
114-
115111
// Search the env for where clauses like `P: 'a`.
116-
bounds.extend(
117-
self.projection_approx_declared_bounds_from_env(projection_ty).into_iter().map(
118-
|ty::OutlivesPredicate(ty, r)| {
119-
let vb = VerifyBound::OutlivedBy(r);
120-
if ty == projection_ty_as_ty {
121-
// Micro-optimize if this is an exact match (this
122-
// occurs often when there are no region variables
123-
// involved).
124-
vb
125-
} else {
126-
VerifyBound::IfEq(ty, Box::new(vb))
127-
}
128-
},
129-
),
130-
);
112+
let env_bounds = self
113+
.projection_approx_declared_bounds_from_env(projection_ty)
114+
.into_iter()
115+
.map(|ty::OutlivesPredicate(ty, r)| {
116+
let vb = VerifyBound::OutlivedBy(r);
117+
if ty == projection_ty_as_ty {
118+
// Micro-optimize if this is an exact match (this
119+
// occurs often when there are no region variables
120+
// involved).
121+
vb
122+
} else {
123+
VerifyBound::IfEq(ty, Box::new(vb))
124+
}
125+
});
131126

132127
// Extend with bounds that we can find from the trait.
133128
let trait_bounds = self
@@ -176,8 +171,6 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
176171
&self,
177172
compare_ty: impl Fn(Ty<'tcx>) -> bool,
178173
) -> Vec<ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>> {
179-
let tcx = self.tcx;
180-
181174
// To start, collect bounds from user environment. Note that
182175
// parameter environments are already elaborated, so we don't
183176
// have to worry about that. Comparing using `==` is a bit

src/librustc/infer/region_constraints/mod.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -904,18 +904,13 @@ impl<'tcx> VerifyBound<'tcx> {
904904
}
905905
}
906906

907-
pub fn or(self, vb: impl FnOnce() -> VerifyBound<'tcx>) -> VerifyBound<'tcx> {
908-
if self.must_hold() {
907+
pub fn or(self, vb: VerifyBound<'tcx>) -> VerifyBound<'tcx> {
908+
if self.must_hold() || vb.cannot_hold() {
909909
self
910+
} else if self.cannot_hold() || vb.must_hold() {
911+
vb
910912
} else {
911-
let vb = vb();
912-
if vb.cannot_hold() {
913-
self
914-
} else if self.cannot_hold() || vb.must_hold() {
915-
vb
916-
} else {
917-
VerifyBound::AnyBound(vec![self, vb])
918-
}
913+
VerifyBound::AnyBound(vec![self, vb])
919914
}
920915
}
921916

src/librustc/ty/outlives.rs

+88-88
Original file line numberDiff line numberDiff line change
@@ -60,106 +60,106 @@ fn compute_components(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, out: &mut SmallVec<[Compo
6060
// with `collect()` because of the need to sometimes skip subtrees
6161
// in the `subtys` iterator (e.g., when encountering a
6262
// projection).
63-
match ty.kind {
64-
ty::view::Closure(def_id, ref substs) => {
65-
for upvar_ty in substs.as_closure().upvar_tys(def_id, tcx) {
66-
compute_components(tcx, upvar_ty, out);
67-
}
63+
match ty.into() {
64+
ty::view::Closure(def_id, ref substs) => {
65+
for upvar_ty in substs.as_closure().upvar_tys(def_id, tcx) {
66+
compute_components(tcx, upvar_ty, out);
6867
}
68+
}
6969

70-
ty::view::Generator(def_id, ref substs, _) => {
71-
// Same as the closure case
72-
for upvar_ty in substs.as_generator().upvar_tys(def_id, tcx) {
73-
compute_components(tcx, upvar_ty, out);
74-
}
75-
76-
// We ignore regions in the generator interior as we don't
77-
// want these to affect region inference
70+
ty::view::Generator(def_id, ref substs, _) => {
71+
// Same as the closure case
72+
for upvar_ty in substs.as_generator().upvar_tys(def_id, tcx) {
73+
compute_components(tcx, upvar_ty, out);
7874
}
7975

80-
// All regions are bound inside a witness
81-
ty::view::GeneratorWitness(..) => (),
76+
// We ignore regions in the generator interior as we don't
77+
// want these to affect region inference
78+
}
8279

83-
// OutlivesTypeParameterEnv -- the actual checking that `X:'a`
84-
// is implied by the environment is done in regionck.
85-
ty::view::Param(p) => {
86-
out.push(Component::Param(p));
87-
}
80+
// All regions are bound inside a witness
81+
ty::view::GeneratorWitness(..) => (),
82+
83+
// OutlivesTypeParameterEnv -- the actual checking that `X:'a`
84+
// is implied by the environment is done in regionck.
85+
ty::view::Param(p) => {
86+
out.push(Component::Param(p));
87+
}
8888

89-
// For projections, we prefer to generate an obligation like
90-
// `<P0 as Trait<P1...Pn>>::Foo: 'a`, because this gives the
91-
// regionck more ways to prove that it holds. However,
92-
// regionck is not (at least currently) prepared to deal with
93-
// higher-ranked regions that may appear in the
94-
// trait-ref. Therefore, if we see any higher-ranke regions,
95-
// we simply fallback to the most restrictive rule, which
96-
// requires that `Pi: 'a` for all `i`.
97-
ty::view::Projection(data) => {
98-
if !data.has_escaping_bound_vars() {
99-
// best case: no escaping regions, so push the
100-
// projection and skip the subtree (thus generating no
101-
// constraints for Pi). This defers the choice between
102-
// the rules OutlivesProjectionEnv,
103-
// OutlivesProjectionTraitDef, and
104-
// OutlivesProjectionComponents to regionck.
105-
out.push(Component::Projection(data));
106-
} else {
107-
// fallback case: hard code
108-
// OutlivesProjectionComponents. Continue walking
109-
// through and constrain Pi.
110-
let subcomponents = capture_components(tcx, ty);
111-
out.push(Component::EscapingProjection(subcomponents));
112-
}
89+
// For projections, we prefer to generate an obligation like
90+
// `<P0 as Trait<P1...Pn>>::Foo: 'a`, because this gives the
91+
// regionck more ways to prove that it holds. However,
92+
// regionck is not (at least currently) prepared to deal with
93+
// higher-ranked regions that may appear in the
94+
// trait-ref. Therefore, if we see any higher-ranke regions,
95+
// we simply fallback to the most restrictive rule, which
96+
// requires that `Pi: 'a` for all `i`.
97+
ty::view::Projection(data) => {
98+
if !data.has_escaping_bound_vars() {
99+
// best case: no escaping regions, so push the
100+
// projection and skip the subtree (thus generating no
101+
// constraints for Pi). This defers the choice between
102+
// the rules OutlivesProjectionEnv,
103+
// OutlivesProjectionTraitDef, and
104+
// OutlivesProjectionComponents to regionck.
105+
out.push(Component::Projection(data));
106+
} else {
107+
// fallback case: hard code
108+
// OutlivesProjectionComponents. Continue walking
109+
// through and constrain Pi.
110+
let subcomponents = capture_components(tcx, ty);
111+
out.push(Component::EscapingProjection(subcomponents));
113112
}
113+
}
114114

115-
ty::view::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
115+
ty::view::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
116116

117-
// We assume that inference variables are fully resolved.
118-
// So, if we encounter an inference variable, just record
119-
// the unresolved variable as a component.
120-
ty::view::Infer(infer_ty) => {
121-
out.push(Component::UnresolvedInferenceVariable(infer_ty));
122-
}
117+
// We assume that inference variables are fully resolved.
118+
// So, if we encounter an inference variable, just record
119+
// the unresolved variable as a component.
120+
ty::view::Infer(infer_ty) => {
121+
out.push(Component::UnresolvedInferenceVariable(infer_ty));
122+
}
123123

124-
// Most types do not introduce any region binders, nor
125-
// involve any other subtle cases, and so the WF relation
126-
// simply constraints any regions referenced directly by
127-
// the type and then visits the types that are lexically
128-
// contained within. (The comments refer to relevant rules
129-
// from RFC1214.)
130-
ty::view::Bool | // OutlivesScalar
131-
ty::view::Char | // OutlivesScalar
132-
ty::view::Int(..) | // OutlivesScalar
133-
ty::view::Uint(..) | // OutlivesScalar
134-
ty::view::Float(..) | // OutlivesScalar
135-
ty::view::Never | // ...
136-
ty::view::Adt(..) | // OutlivesNominalType
137-
ty::view::Opaque(..) | // OutlivesNominalType (ish)
138-
ty::view::Foreign(..) | // OutlivesNominalType
139-
ty::view::Str | // OutlivesScalar (ish)
140-
ty::view::Array(..) | // ...
141-
ty::view::Slice(..) | // ...
142-
ty::view::RawPtr(..) | // ...
143-
ty::view::Ref(..) | // OutlivesReference
144-
ty::view::Tuple(..) | // ...
145-
ty::view::FnDef(..) | // OutlivesFunction (*)
146-
ty::view::FnPtr(_) | // OutlivesFunction (*)
147-
ty::view::Dynamic(..) | // OutlivesObject, OutlivesFragment (*)
148-
ty::view::Placeholder(..) |
149-
ty::view::Bound(..) |
150-
ty::view::Error => {
151-
// (*) Bare functions and traits are both binders. In the
152-
// RFC, this means we would add the bound regions to the
153-
// "bound regions list". In our representation, no such
154-
// list is maintained explicitly, because bound regions
155-
// themselves can be readily identified.
156-
157-
push_region_constraints(ty, out);
158-
for subty in ty.walk_shallow() {
159-
compute_components(tcx, subty, out);
160-
}
124+
// Most types do not introduce any region binders, nor
125+
// involve any other subtle cases, and so the WF relation
126+
// simply constraints any regions referenced directly by
127+
// the type and then visits the types that are lexically
128+
// contained within. (The comments refer to relevant rules
129+
// from RFC1214.)
130+
ty::view::Bool | // OutlivesScalar
131+
ty::view::Char | // OutlivesScalar
132+
ty::view::Int(..) | // OutlivesScalar
133+
ty::view::Uint(..) | // OutlivesScalar
134+
ty::view::Float(..) | // OutlivesScalar
135+
ty::view::Never | // ...
136+
ty::view::Adt(..) | // OutlivesNominalType
137+
ty::view::Opaque(..) | // OutlivesNominalType (ish)
138+
ty::view::Foreign(..) | // OutlivesNominalType
139+
ty::view::Str | // OutlivesScalar (ish)
140+
ty::view::Array(..) | // ...
141+
ty::view::Slice(..) | // ...
142+
ty::view::RawPtr(..) | // ...
143+
ty::view::Ref(..) | // OutlivesReference
144+
ty::view::Tuple(..) | // ...
145+
ty::view::FnDef(..) | // OutlivesFunction (*)
146+
ty::view::FnPtr(_) | // OutlivesFunction (*)
147+
ty::view::Dynamic(..) | // OutlivesObject, OutlivesFragment (*)
148+
ty::view::Placeholder(..) |
149+
ty::view::Bound(..) |
150+
ty::view::Error => {
151+
// (*) Bare functions and traits are both binders. In the
152+
// RFC, this means we would add the bound regions to the
153+
// "bound regions list". In our representation, no such
154+
// list is maintained explicitly, because bound regions
155+
// themselves can be readily identified.
156+
157+
push_region_constraints(ty, out);
158+
for subty in ty.walk_shallow() {
159+
compute_components(tcx, subty, out);
161160
}
162161
}
162+
}
163163
}
164164

165165
fn capture_components(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Vec<Component<'tcx>> {

src/librustc_data_structures/captures.rs

-5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,3 @@
88
pub trait Captures<'a> {}
99

1010
impl<T: ?Sized> Captures<'_> for T {}
11-
12-
#[allow(unused_lifetimes)]
13-
pub trait Captures2<'a, 'b> {}
14-
15-
impl<T: ?Sized> Captures2<'_, '_> for T {}

0 commit comments

Comments
 (0)