Use ParamBounds in WhereRegionPredicate
This commit is contained in:
parent
aed530a457
commit
80dbe58efc
@ -314,8 +314,8 @@ pub trait Visitor<'v> : Sized {
|
||||
fn visit_trait_ref(&mut self, t: &'v TraitRef) {
|
||||
walk_trait_ref(self, t)
|
||||
}
|
||||
fn visit_ty_param_bound(&mut self, bounds: &'v ParamBound) {
|
||||
walk_ty_param_bound(self, bounds)
|
||||
fn visit_param_bound(&mut self, bounds: &'v ParamBound) {
|
||||
walk_param_bound(self, bounds)
|
||||
}
|
||||
fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef, m: TraitBoundModifier) {
|
||||
walk_poly_trait_ref(self, t, m)
|
||||
@ -537,13 +537,13 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
|
||||
ItemTrait(.., ref generics, ref bounds, ref trait_item_refs) => {
|
||||
visitor.visit_id(item.id);
|
||||
visitor.visit_generics(generics);
|
||||
walk_list!(visitor, visit_ty_param_bound, bounds);
|
||||
walk_list!(visitor, visit_param_bound, bounds);
|
||||
walk_list!(visitor, visit_trait_item_ref, trait_item_refs);
|
||||
}
|
||||
ItemTraitAlias(ref generics, ref bounds) => {
|
||||
visitor.visit_id(item.id);
|
||||
visitor.visit_generics(generics);
|
||||
walk_list!(visitor, visit_ty_param_bound, bounds);
|
||||
walk_list!(visitor, visit_param_bound, bounds);
|
||||
}
|
||||
}
|
||||
walk_list!(visitor, visit_attribute, &item.attrs);
|
||||
@ -731,7 +731,7 @@ pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v
|
||||
walk_list!(visitor, visit_attribute, &foreign_item.attrs);
|
||||
}
|
||||
|
||||
pub fn walk_ty_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v ParamBound) {
|
||||
pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v ParamBound) {
|
||||
match *bound {
|
||||
TraitTyParamBound(ref typ, modifier) => {
|
||||
visitor.visit_poly_trait_ref(typ, modifier);
|
||||
@ -763,7 +763,7 @@ pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Generi
|
||||
walk_list!(visitor, visit_attribute, attrs.iter());
|
||||
}
|
||||
}
|
||||
walk_list!(visitor, visit_ty_param_bound, ¶m.bounds);
|
||||
walk_list!(visitor, visit_param_bound, ¶m.bounds);
|
||||
}
|
||||
|
||||
pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics) {
|
||||
@ -782,14 +782,14 @@ pub fn walk_where_predicate<'v, V: Visitor<'v>>(
|
||||
ref bound_generic_params,
|
||||
..}) => {
|
||||
visitor.visit_ty(bounded_ty);
|
||||
walk_list!(visitor, visit_ty_param_bound, bounds);
|
||||
walk_list!(visitor, visit_param_bound, bounds);
|
||||
walk_list!(visitor, visit_generic_param, bound_generic_params);
|
||||
}
|
||||
&WherePredicate::RegionPredicate(WhereRegionPredicate{ref lifetime,
|
||||
ref bounds,
|
||||
..}) => {
|
||||
visitor.visit_lifetime(lifetime);
|
||||
walk_list!(visitor, visit_lifetime, bounds);
|
||||
walk_list!(visitor, visit_param_bound, bounds);
|
||||
}
|
||||
&WherePredicate::EqPredicate(WhereEqPredicate{id,
|
||||
ref lhs_ty,
|
||||
@ -866,7 +866,7 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
|
||||
}
|
||||
TraitItemKind::Type(ref bounds, ref default) => {
|
||||
visitor.visit_id(trait_item.id);
|
||||
walk_list!(visitor, visit_ty_param_bound, bounds);
|
||||
walk_list!(visitor, visit_param_bound, bounds);
|
||||
walk_list!(visitor, visit_ty, default);
|
||||
}
|
||||
}
|
||||
|
@ -1447,7 +1447,7 @@ impl<'a> LoweringContext<'a> {
|
||||
};
|
||||
|
||||
for bound in bounds {
|
||||
hir::intravisit::walk_ty_param_bound(&mut lifetime_collector, &bound);
|
||||
hir::intravisit::walk_param_bound(&mut lifetime_collector, &bound);
|
||||
}
|
||||
|
||||
(
|
||||
@ -2125,10 +2125,7 @@ impl<'a> LoweringContext<'a> {
|
||||
}) => hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
|
||||
span,
|
||||
lifetime: self.lower_lifetime(lifetime),
|
||||
bounds: bounds
|
||||
.iter()
|
||||
.map(|bound| self.lower_lifetime(bound))
|
||||
.collect(),
|
||||
bounds: self.lower_param_bounds(bounds, ImplTraitContext::Disallowed),
|
||||
}),
|
||||
WherePredicate::EqPredicate(WhereEqPredicate {
|
||||
id,
|
||||
|
@ -596,7 +596,7 @@ pub struct WhereBoundPredicate {
|
||||
pub struct WhereRegionPredicate {
|
||||
pub span: Span,
|
||||
pub lifetime: Lifetime,
|
||||
pub bounds: HirVec<Lifetime>,
|
||||
pub bounds: ParamBounds,
|
||||
}
|
||||
|
||||
/// An equality predicate (unsupported), e.g. `T=int`
|
||||
|
@ -2180,7 +2180,12 @@ impl<'a> State<'a> {
|
||||
self.s.word(":")?;
|
||||
|
||||
for (i, bound) in bounds.iter().enumerate() {
|
||||
self.print_lifetime(bound)?;
|
||||
match bound {
|
||||
hir::ParamBound::Outlives(lt) => {
|
||||
self.print_lifetime(lt)?;
|
||||
}
|
||||
_ => bug!(),
|
||||
}
|
||||
|
||||
if i != 0 {
|
||||
self.s.word(":")?;
|
||||
|
@ -726,7 +726,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||
this.with(scope, |_old_scope, this| {
|
||||
this.visit_generics(generics);
|
||||
for bound in bounds {
|
||||
this.visit_ty_param_bound(bound);
|
||||
this.visit_param_bound(bound);
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -741,7 +741,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||
self.with(scope, |_old_scope, this| {
|
||||
this.visit_generics(generics);
|
||||
for bound in bounds {
|
||||
this.visit_ty_param_bound(bound);
|
||||
this.visit_param_bound(bound);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -786,7 +786,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||
self.with(scope, |_old_scope, this| {
|
||||
this.visit_generics(generics);
|
||||
for bound in bounds {
|
||||
this.visit_ty_param_bound(bound);
|
||||
this.visit_param_bound(bound);
|
||||
}
|
||||
if let Some(ty) = ty {
|
||||
this.visit_ty(ty);
|
||||
@ -882,7 +882,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||
match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => {}
|
||||
GenericParamKind::Type { ref default, .. } => {
|
||||
walk_list!(self, visit_ty_param_bound, ¶m.bounds);
|
||||
walk_list!(self, visit_param_bound, ¶m.bounds);
|
||||
if let Some(ref ty) = default {
|
||||
self.visit_ty(&ty);
|
||||
}
|
||||
@ -917,13 +917,13 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||
let result = self.with(scope, |old_scope, this| {
|
||||
this.check_lifetime_params(old_scope, &bound_generic_params);
|
||||
this.visit_ty(&bounded_ty);
|
||||
walk_list!(this, visit_ty_param_bound, bounds);
|
||||
walk_list!(this, visit_param_bound, bounds);
|
||||
});
|
||||
self.trait_ref_hack = false;
|
||||
result
|
||||
} else {
|
||||
self.visit_ty(&bounded_ty);
|
||||
walk_list!(self, visit_ty_param_bound, bounds);
|
||||
walk_list!(self, visit_param_bound, bounds);
|
||||
}
|
||||
}
|
||||
&hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
|
||||
@ -932,9 +932,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||
..
|
||||
}) => {
|
||||
self.visit_lifetime(lifetime);
|
||||
for bound in bounds {
|
||||
self.visit_lifetime(bound);
|
||||
}
|
||||
walk_list!(self, visit_param_bound, bounds);
|
||||
}
|
||||
&hir::WherePredicate::EqPredicate(hir::WhereEqPredicate {
|
||||
ref lhs_ty,
|
||||
|
@ -203,9 +203,9 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
|
||||
hir_visit::walk_impl_item(self, ii)
|
||||
}
|
||||
|
||||
fn visit_ty_param_bound(&mut self, bounds: &'v hir::ParamBound) {
|
||||
fn visit_param_bound(&mut self, bounds: &'v hir::ParamBound) {
|
||||
self.record("ParamBound", Id::None, bounds);
|
||||
hir_visit::walk_ty_param_bound(self, bounds)
|
||||
hir_visit::walk_param_bound(self, bounds)
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, s: &'v hir::StructField) {
|
||||
@ -322,9 +322,9 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
|
||||
ast_visit::walk_impl_item(self, ii)
|
||||
}
|
||||
|
||||
fn visit_ty_param_bound(&mut self, bounds: &'v ast::ParamBound) {
|
||||
fn visit_param_bound(&mut self, bounds: &'v ast::ParamBound) {
|
||||
self.record("ParamBound", Id::None, bounds);
|
||||
ast_visit::walk_ty_param_bound(self, bounds)
|
||||
ast_visit::walk_param_bound(self, bounds)
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, s: &'v ast::StructField) {
|
||||
|
@ -815,7 +815,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> {
|
||||
GenericParamKind::Lifetime { .. } => self.visit_generic_param(param),
|
||||
GenericParamKind::Type { ref default, .. } => {
|
||||
for bound in ¶m.bounds {
|
||||
self.visit_ty_param_bound(bound);
|
||||
self.visit_param_bound(bound);
|
||||
}
|
||||
|
||||
if let Some(ref ty) = default {
|
||||
@ -2076,7 +2076,7 @@ impl<'a> Resolver<'a> {
|
||||
let local_def_id = this.definitions.local_def_id(item.id);
|
||||
this.with_self_rib(Def::SelfTy(Some(local_def_id), None), |this| {
|
||||
this.visit_generics(generics);
|
||||
walk_list!(this, visit_ty_param_bound, bounds);
|
||||
walk_list!(this, visit_param_bound, bounds);
|
||||
|
||||
for trait_item in trait_items {
|
||||
this.check_proc_macro_attrs(&trait_item.attrs);
|
||||
@ -2119,7 +2119,7 @@ impl<'a> Resolver<'a> {
|
||||
let local_def_id = this.definitions.local_def_id(item.id);
|
||||
this.with_self_rib(Def::SelfTy(Some(local_def_id), None), |this| {
|
||||
this.visit_generics(generics);
|
||||
walk_list!(this, visit_ty_param_bound, bounds);
|
||||
walk_list!(this, visit_param_bound, bounds);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -1512,7 +1512,12 @@ pub fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
&hir::WherePredicate::RegionPredicate(ref region_pred) => {
|
||||
let r1 = AstConv::ast_region_to_region(&icx, ®ion_pred.lifetime, None);
|
||||
for bound in ®ion_pred.bounds {
|
||||
let r2 = AstConv::ast_region_to_region(&icx, bound, None);
|
||||
let r2 = match bound {
|
||||
hir::ParamBound::Outlives(lt) => {
|
||||
AstConv::ast_region_to_region(&icx, lt, None)
|
||||
}
|
||||
_ => bug!(),
|
||||
};
|
||||
let pred = ty::Binder::bind(ty::OutlivesPredicate(r1, r2));
|
||||
predicates.push(ty::Predicate::RegionOutlives(pred))
|
||||
}
|
||||
|
@ -486,11 +486,8 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
|
||||
.iter()
|
||||
.flat_map(|(name, lifetime)| {
|
||||
let empty = Vec::new();
|
||||
let bounds: FxHashSet<Lifetime> = finished
|
||||
.get(name)
|
||||
.unwrap_or(&empty)
|
||||
.iter()
|
||||
.map(|region| self.get_lifetime(region, names_map))
|
||||
let bounds: FxHashSet<ParamBound> = finished.get(name).unwrap_or(&empty).iter()
|
||||
.map(|region| ParamBound::Outlives(self.get_lifetime(region, names_map)))
|
||||
.collect();
|
||||
|
||||
if bounds.is_empty() {
|
||||
@ -538,7 +535,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
|
||||
&self,
|
||||
ty_to_bounds: FxHashMap<Type, FxHashSet<ParamBound>>,
|
||||
ty_to_fn: FxHashMap<Type, (Option<PolyTrait>, Option<Type>)>,
|
||||
lifetime_to_bounds: FxHashMap<Lifetime, FxHashSet<Lifetime>>,
|
||||
lifetime_to_bounds: FxHashMap<Lifetime, FxHashSet<ParamBound>>,
|
||||
) -> Vec<WherePredicate> {
|
||||
ty_to_bounds
|
||||
.into_iter()
|
||||
@ -615,7 +612,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
|
||||
.filter(|&(_, ref bounds)| !bounds.is_empty())
|
||||
.map(|(lifetime, bounds)| {
|
||||
let mut bounds_vec = bounds.into_iter().collect();
|
||||
self.sort_where_lifetimes(&mut bounds_vec);
|
||||
self.sort_where_bounds(&mut bounds_vec);
|
||||
WherePredicate::RegionPredicate {
|
||||
lifetime,
|
||||
bounds: bounds_vec,
|
||||
@ -918,14 +915,6 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
|
||||
self.unstable_debug_sort(&mut bounds);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn sort_where_lifetimes(&self, mut bounds: &mut Vec<Lifetime>) {
|
||||
// We should never have identical bounds - and if we do,
|
||||
// they're visually identical as well. Therefore, using
|
||||
// an unstable sort is fine.
|
||||
self.unstable_debug_sort(&mut bounds);
|
||||
}
|
||||
|
||||
// This might look horrendously hacky, but it's actually not that bad.
|
||||
//
|
||||
// For performance reasons, we use several different FxHashMaps
|
||||
|
@ -375,7 +375,7 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec<clean::Item>) {
|
||||
let trait_ = associated_trait.clean(cx).map(|bound| {
|
||||
match bound {
|
||||
clean::TraitBound(polyt, _) => polyt.trait_,
|
||||
clean::RegionBound(..) => unreachable!(),
|
||||
clean::Outlives(..) => unreachable!(),
|
||||
}
|
||||
});
|
||||
if trait_.def_id() == tcx.lang_items().deref_trait() {
|
||||
|
@ -1459,8 +1459,8 @@ impl Clean<Attributes> for [ast::Attribute] {
|
||||
|
||||
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)]
|
||||
pub enum ParamBound {
|
||||
RegionBound(Lifetime),
|
||||
TraitBound(PolyTrait, hir::TraitBoundModifier)
|
||||
TraitBound(PolyTrait, hir::TraitBoundModifier),
|
||||
Outlives(Lifetime),
|
||||
}
|
||||
|
||||
impl ParamBound {
|
||||
@ -1510,7 +1510,7 @@ impl ParamBound {
|
||||
impl Clean<ParamBound> for hir::ParamBound {
|
||||
fn clean(&self, cx: &DocContext) -> ParamBound {
|
||||
match *self {
|
||||
hir::Outlives(lt) => RegionBound(lt.clean(cx)),
|
||||
hir::Outlives(lt) => Outlives(lt.clean(cx)),
|
||||
hir::TraitTyParamBound(ref t, modifier) => TraitBound(t.clean(cx), modifier),
|
||||
}
|
||||
}
|
||||
@ -1624,7 +1624,7 @@ impl<'tcx> Clean<Option<Vec<ParamBound>>> for Substs<'tcx> {
|
||||
fn clean(&self, cx: &DocContext) -> Option<Vec<ParamBound>> {
|
||||
let mut v = Vec::new();
|
||||
v.extend(self.regions().filter_map(|r| r.clean(cx))
|
||||
.map(RegionBound));
|
||||
.map(Outlives));
|
||||
v.extend(self.types().map(|t| TraitBound(PolyTrait {
|
||||
trait_: t.clean(cx),
|
||||
generic_params: Vec::new(),
|
||||
@ -1721,7 +1721,7 @@ impl Clean<Option<Lifetime>> for ty::RegionKind {
|
||||
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)]
|
||||
pub enum WherePredicate {
|
||||
BoundPredicate { ty: Type, bounds: Vec<ParamBound> },
|
||||
RegionPredicate { lifetime: Lifetime, bounds: Vec<Lifetime>},
|
||||
RegionPredicate { lifetime: Lifetime, bounds: Vec<ParamBound> },
|
||||
EqPredicate { lhs: Type, rhs: Type },
|
||||
}
|
||||
|
||||
@ -1791,7 +1791,7 @@ impl<'tcx> Clean<WherePredicate> for ty::OutlivesPredicate<ty::Region<'tcx>, ty:
|
||||
let ty::OutlivesPredicate(ref a, ref b) = *self;
|
||||
WherePredicate::RegionPredicate {
|
||||
lifetime: a.clean(cx).unwrap(),
|
||||
bounds: vec![b.clean(cx).unwrap()]
|
||||
bounds: vec![ParamBound::Outlives(b.clean(cx).unwrap())]
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1802,7 +1802,7 @@ impl<'tcx> Clean<WherePredicate> for ty::OutlivesPredicate<Ty<'tcx>, ty::Region<
|
||||
|
||||
WherePredicate::BoundPredicate {
|
||||
ty: ty.clean(cx),
|
||||
bounds: vec![ParamBound::RegionBound(lt.clean(cx).unwrap())]
|
||||
bounds: vec![ParamBound::Outlives(lt.clean(cx).unwrap())]
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1820,9 +1820,7 @@ impl<'tcx> Clean<Type> for ty::ProjectionTy<'tcx> {
|
||||
fn clean(&self, cx: &DocContext) -> Type {
|
||||
let trait_ = match self.trait_ref(cx.tcx).clean(cx) {
|
||||
ParamBound::TraitBound(t, _) => t.trait_,
|
||||
ParamBound::RegionBound(_) => {
|
||||
panic!("cleaning a trait got a region")
|
||||
}
|
||||
ParamBound::Outlives(_) => panic!("cleaning a trait got a lifetime"),
|
||||
};
|
||||
Type::QPath {
|
||||
name: cx.tcx.associated_item(self.item_def_id).name.clean(cx),
|
||||
@ -2979,18 +2977,13 @@ impl Clean<Type> for hir::Ty {
|
||||
TyTraitObject(ref bounds, ref lifetime) => {
|
||||
match bounds[0].clean(cx).trait_ {
|
||||
ResolvedPath { path, typarams: None, did, is_generic } => {
|
||||
let mut bounds: Vec<_> = bounds[1..].iter().map(|bound| {
|
||||
let mut bounds: Vec<self::ParamBound> = bounds[1..].iter().map(|bound| {
|
||||
TraitBound(bound.clean(cx), hir::TraitBoundModifier::None)
|
||||
}).collect();
|
||||
if !lifetime.is_elided() {
|
||||
bounds.push(RegionBound(lifetime.clean(cx)));
|
||||
}
|
||||
ResolvedPath {
|
||||
path,
|
||||
typarams: Some(bounds),
|
||||
did,
|
||||
is_generic,
|
||||
bounds.push(self::Outlives(lifetime.clean(cx)));
|
||||
}
|
||||
ResolvedPath { path, typarams: Some(bounds), did, is_generic, }
|
||||
}
|
||||
_ => Infer // shouldn't happen
|
||||
}
|
||||
@ -3087,7 +3080,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
|
||||
inline::record_extern_fqn(cx, did, TypeKind::Trait);
|
||||
|
||||
let mut typarams = vec![];
|
||||
reg.clean(cx).map(|b| typarams.push(RegionBound(b)));
|
||||
reg.clean(cx).map(|b| typarams.push(Outlives(b)));
|
||||
for did in obj.auto_traits() {
|
||||
let empty = cx.tcx.intern_substs(&[]);
|
||||
let path = external_path(cx, &cx.tcx.item_name(did).as_str(),
|
||||
@ -3144,7 +3137,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
|
||||
tr
|
||||
} else if let ty::Predicate::TypeOutlives(pred) = *predicate {
|
||||
// these should turn up at the end
|
||||
pred.skip_binder().1.clean(cx).map(|r| regions.push(RegionBound(r)));
|
||||
pred.skip_binder().1.clean(cx).map(|r| regions.push(Outlives(r)));
|
||||
return None;
|
||||
} else {
|
||||
return None;
|
||||
@ -4455,8 +4448,8 @@ struct RegionDeps<'tcx> {
|
||||
|
||||
#[derive(Eq, PartialEq, Hash, Debug)]
|
||||
enum SimpleBound {
|
||||
RegionBound(Lifetime),
|
||||
TraitBound(Vec<PathSegment>, Vec<SimpleBound>, Vec<GenericParamDef>, hir::TraitBoundModifier)
|
||||
TraitBound(Vec<PathSegment>, Vec<SimpleBound>, Vec<GenericParamDef>, hir::TraitBoundModifier),
|
||||
Outlives(Lifetime),
|
||||
}
|
||||
|
||||
enum AutoTraitResult {
|
||||
@ -4477,7 +4470,7 @@ impl AutoTraitResult {
|
||||
impl From<ParamBound> for SimpleBound {
|
||||
fn from(bound: ParamBound) -> Self {
|
||||
match bound.clone() {
|
||||
ParamBound::RegionBound(l) => SimpleBound::RegionBound(l),
|
||||
ParamBound::Outlives(l) => SimpleBound::Outlives(l),
|
||||
ParamBound::TraitBound(t, mod_) => match t.trait_ {
|
||||
Type::ResolvedPath { path, typarams, .. } => {
|
||||
SimpleBound::TraitBound(path.segments,
|
||||
|
@ -84,7 +84,7 @@ pub fn where_clauses(cx: &DocContext, clauses: Vec<WP>) -> Vec<WP> {
|
||||
!bounds.iter_mut().any(|b| {
|
||||
let trait_ref = match *b {
|
||||
clean::TraitBound(ref mut tr, _) => tr,
|
||||
clean::RegionBound(..) => return false,
|
||||
clean::Outlives(..) => return false,
|
||||
};
|
||||
let (did, path) = match trait_ref.trait_ {
|
||||
clean::ResolvedPath { did, ref mut path, ..} => (did, path),
|
||||
|
@ -270,7 +270,7 @@ impl fmt::Display for clean::PolyTrait {
|
||||
impl fmt::Display for clean::ParamBound {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
clean::RegionBound(ref lt) => {
|
||||
clean::Outlives(ref lt) => {
|
||||
write!(f, "{}", *lt)
|
||||
}
|
||||
clean::TraitBound(ref ty, modifier) => {
|
||||
|
@ -393,7 +393,7 @@ pub struct WhereBoundPredicate {
|
||||
pub struct WhereRegionPredicate {
|
||||
pub span: Span,
|
||||
pub lifetime: Lifetime,
|
||||
pub bounds: Vec<Lifetime>,
|
||||
pub bounds: ParamBounds,
|
||||
}
|
||||
|
||||
/// An equality predicate (unsupported).
|
||||
|
@ -1610,7 +1610,7 @@ impl<'a> Parser<'a> {
|
||||
s.print_mutability(mut_ty.mutbl)?;
|
||||
s.popen()?;
|
||||
s.print_type(&mut_ty.ty)?;
|
||||
s.print_bounds(" +", &bounds)?;
|
||||
s.print_type_bounds(" +", &bounds)?;
|
||||
s.pclose()
|
||||
});
|
||||
err.span_suggestion_with_applicability(
|
||||
@ -4790,10 +4790,10 @@ impl<'a> Parser<'a> {
|
||||
|
||||
// Parse bounds of a lifetime parameter `BOUND + BOUND + BOUND`, possibly with trailing `+`.
|
||||
// BOUND = LT_BOUND (e.g. `'a`)
|
||||
fn parse_lt_param_bounds(&mut self) -> Vec<Lifetime> {
|
||||
fn parse_lt_param_bounds(&mut self) -> ParamBounds {
|
||||
let mut lifetimes = Vec::new();
|
||||
while self.check_lifetime() {
|
||||
lifetimes.push(self.expect_lifetime());
|
||||
lifetimes.push(ast::ParamBound::Outlives(self.expect_lifetime()));
|
||||
|
||||
if !self.eat_plus() {
|
||||
break
|
||||
@ -4868,9 +4868,7 @@ impl<'a> Parser<'a> {
|
||||
let lifetime = self.expect_lifetime();
|
||||
// Parse lifetime parameter.
|
||||
let bounds = if self.eat(&token::Colon) {
|
||||
self.parse_lt_param_bounds().iter()
|
||||
.map(|bound| ast::ParamBound::Outlives(*bound))
|
||||
.collect()
|
||||
self.parse_lt_param_bounds()
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
|
@ -293,7 +293,7 @@ pub fn ty_to_string(ty: &ast::Ty) -> String {
|
||||
}
|
||||
|
||||
pub fn bounds_to_string(bounds: &[ast::ParamBound]) -> String {
|
||||
to_string(|s| s.print_bounds("", bounds))
|
||||
to_string(|s| s.print_type_bounds("", bounds))
|
||||
}
|
||||
|
||||
pub fn pat_to_string(pat: &ast::Pat) -> String {
|
||||
@ -1078,10 +1078,10 @@ impl<'a> State<'a> {
|
||||
}
|
||||
ast::TyKind::TraitObject(ref bounds, syntax) => {
|
||||
let prefix = if syntax == ast::TraitObjectSyntax::Dyn { "dyn" } else { "" };
|
||||
self.print_bounds(prefix, &bounds[..])?;
|
||||
self.print_type_bounds(prefix, &bounds[..])?;
|
||||
}
|
||||
ast::TyKind::ImplTrait(ref bounds) => {
|
||||
self.print_bounds("impl", &bounds[..])?;
|
||||
self.print_type_bounds("impl", &bounds[..])?;
|
||||
}
|
||||
ast::TyKind::Array(ref ty, ref length) => {
|
||||
self.s.word("[")?;
|
||||
@ -1184,7 +1184,7 @@ impl<'a> State<'a> {
|
||||
self.word_space("type")?;
|
||||
self.print_ident(ident)?;
|
||||
if let Some(bounds) = bounds {
|
||||
self.print_bounds(":", bounds)?;
|
||||
self.print_type_bounds(":", bounds)?;
|
||||
}
|
||||
if let Some(ty) = ty {
|
||||
self.s.space()?;
|
||||
@ -1373,7 +1373,7 @@ impl<'a> State<'a> {
|
||||
real_bounds.push(b.clone());
|
||||
}
|
||||
}
|
||||
self.print_bounds(":", &real_bounds[..])?;
|
||||
self.print_type_bounds(":", &real_bounds[..])?;
|
||||
self.print_where_clause(&generics.where_clause)?;
|
||||
self.s.word(" ")?;
|
||||
self.bopen()?;
|
||||
@ -1400,7 +1400,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
}
|
||||
self.nbsp()?;
|
||||
self.print_bounds("=", &real_bounds[..])?;
|
||||
self.print_type_bounds("=", &real_bounds[..])?;
|
||||
self.print_where_clause(&generics.where_clause)?;
|
||||
self.s.word(";")?;
|
||||
}
|
||||
@ -2809,7 +2809,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_bounds(&mut self,
|
||||
pub fn print_type_bounds(&mut self,
|
||||
prefix: &str,
|
||||
bounds: &[ast::ParamBound])
|
||||
-> io::Result<()> {
|
||||
@ -2851,7 +2851,7 @@ impl<'a> State<'a> {
|
||||
|
||||
pub fn print_lifetime_bounds(&mut self,
|
||||
lifetime: &ast::Lifetime,
|
||||
bounds: &[ast::Lifetime])
|
||||
bounds: &ast::ParamBounds)
|
||||
-> io::Result<()>
|
||||
{
|
||||
self.print_lifetime(lifetime)?;
|
||||
@ -2861,7 +2861,10 @@ impl<'a> State<'a> {
|
||||
if i != 0 {
|
||||
self.s.word(" + ")?;
|
||||
}
|
||||
self.print_lifetime(bound)?;
|
||||
match bound {
|
||||
ast::ParamBound::Outlives(lt) => self.print_lifetime(lt)?,
|
||||
_ => panic!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@ -2881,17 +2884,12 @@ impl<'a> State<'a> {
|
||||
match param.kind {
|
||||
ast::GenericParamKind::Lifetime { ref lifetime } => {
|
||||
s.print_outer_attributes_inline(¶m.attrs)?;
|
||||
s.print_lifetime_bounds(lifetime, ¶m.bounds.iter().map(|bound| {
|
||||
match bound {
|
||||
ast::ParamBound::Outlives(lt) => *lt,
|
||||
_ => panic!(),
|
||||
}
|
||||
}).collect::<Vec<_>>().as_slice())
|
||||
s.print_lifetime_bounds(lifetime, ¶m.bounds)
|
||||
},
|
||||
ast::GenericParamKind::Type { ref default } => {
|
||||
s.print_outer_attributes_inline(¶m.attrs)?;
|
||||
s.print_ident(param.ident)?;
|
||||
s.print_bounds(":", ¶m.bounds)?;
|
||||
s.print_type_bounds(":", ¶m.bounds)?;
|
||||
match default {
|
||||
Some(ref default) => {
|
||||
s.s.space()?;
|
||||
@ -2931,7 +2929,7 @@ impl<'a> State<'a> {
|
||||
}) => {
|
||||
self.print_formal_generic_params(bound_generic_params)?;
|
||||
self.print_type(bounded_ty)?;
|
||||
self.print_bounds(":", bounds)?;
|
||||
self.print_type_bounds(":", bounds)?;
|
||||
}
|
||||
ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate{ref lifetime,
|
||||
ref bounds,
|
||||
|
@ -95,9 +95,9 @@ impl<'ast> Visitor<'ast> for NodeCounter {
|
||||
self.count += 1;
|
||||
walk_trait_ref(self, t)
|
||||
}
|
||||
fn visit_ty_param_bound(&mut self, bounds: &ParamBound) {
|
||||
fn visit_param_bound(&mut self, bounds: &ParamBound) {
|
||||
self.count += 1;
|
||||
walk_ty_param_bound(self, bounds)
|
||||
walk_param_bound(self, bounds)
|
||||
}
|
||||
fn visit_poly_trait_ref(&mut self, t: &PolyTraitRef, m: &TraitBoundModifier) {
|
||||
self.count += 1;
|
||||
|
@ -86,8 +86,8 @@ pub trait Visitor<'ast>: Sized {
|
||||
fn visit_trait_item(&mut self, ti: &'ast TraitItem) { walk_trait_item(self, ti) }
|
||||
fn visit_impl_item(&mut self, ii: &'ast ImplItem) { walk_impl_item(self, ii) }
|
||||
fn visit_trait_ref(&mut self, t: &'ast TraitRef) { walk_trait_ref(self, t) }
|
||||
fn visit_ty_param_bound(&mut self, bounds: &'ast ParamBound) {
|
||||
walk_ty_param_bound(self, bounds)
|
||||
fn visit_param_bound(&mut self, bounds: &'ast ParamBound) {
|
||||
walk_param_bound(self, bounds)
|
||||
}
|
||||
fn visit_poly_trait_ref(&mut self, t: &'ast PolyTraitRef, m: &'ast TraitBoundModifier) {
|
||||
walk_poly_trait_ref(self, t, m)
|
||||
@ -276,12 +276,12 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
|
||||
}
|
||||
ItemKind::Trait(.., ref generics, ref bounds, ref methods) => {
|
||||
visitor.visit_generics(generics);
|
||||
walk_list!(visitor, visit_ty_param_bound, bounds);
|
||||
walk_list!(visitor, visit_param_bound, bounds);
|
||||
walk_list!(visitor, visit_trait_item, methods);
|
||||
}
|
||||
ItemKind::TraitAlias(ref generics, ref bounds) => {
|
||||
visitor.visit_generics(generics);
|
||||
walk_list!(visitor, visit_ty_param_bound, bounds);
|
||||
walk_list!(visitor, visit_param_bound, bounds);
|
||||
}
|
||||
ItemKind::Mac(ref mac) => visitor.visit_mac(mac),
|
||||
ItemKind::MacroDef(ref ts) => visitor.visit_mac_def(ts, item.id),
|
||||
@ -341,7 +341,7 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
|
||||
}
|
||||
TyKind::TraitObject(ref bounds, ..) |
|
||||
TyKind::ImplTrait(ref bounds) => {
|
||||
walk_list!(visitor, visit_ty_param_bound, bounds);
|
||||
walk_list!(visitor, visit_param_bound, bounds);
|
||||
}
|
||||
TyKind::Typeof(ref expression) => {
|
||||
visitor.visit_anon_const(expression)
|
||||
@ -479,7 +479,7 @@ pub fn walk_global_asm<'a, V: Visitor<'a>>(_: &mut V, _: &'a GlobalAsm) {
|
||||
// Empty!
|
||||
}
|
||||
|
||||
pub fn walk_ty_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a ParamBound) {
|
||||
pub fn walk_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a ParamBound) {
|
||||
match *bound {
|
||||
TraitTyParamBound(ref typ, ref modifier) => {
|
||||
visitor.visit_poly_trait_ref(typ, modifier);
|
||||
@ -517,14 +517,14 @@ pub fn walk_where_predicate<'a, V: Visitor<'a>>(visitor: &mut V, predicate: &'a
|
||||
ref bound_generic_params,
|
||||
..}) => {
|
||||
visitor.visit_ty(bounded_ty);
|
||||
walk_list!(visitor, visit_ty_param_bound, bounds);
|
||||
walk_list!(visitor, visit_param_bound, bounds);
|
||||
walk_list!(visitor, visit_generic_param, bound_generic_params);
|
||||
}
|
||||
WherePredicate::RegionPredicate(WhereRegionPredicate{ref lifetime,
|
||||
ref bounds,
|
||||
..}) => {
|
||||
visitor.visit_lifetime(lifetime);
|
||||
walk_list!(visitor, visit_lifetime, bounds);
|
||||
walk_list!(visitor, visit_param_bound, bounds);
|
||||
}
|
||||
WherePredicate::EqPredicate(WhereEqPredicate{ref lhs_ty,
|
||||
ref rhs_ty,
|
||||
@ -585,7 +585,7 @@ pub fn walk_trait_item<'a, V: Visitor<'a>>(visitor: &mut V, trait_item: &'a Trai
|
||||
&sig.decl, trait_item.span, trait_item.id);
|
||||
}
|
||||
TraitItemKind::Type(ref bounds, ref default) => {
|
||||
walk_list!(visitor, visit_ty_param_bound, bounds);
|
||||
walk_list!(visitor, visit_param_bound, bounds);
|
||||
walk_list!(visitor, visit_ty, default);
|
||||
}
|
||||
TraitItemKind::Macro(ref mac) => {
|
||||
|
Loading…
Reference in New Issue
Block a user