Refactor counting methods
This commit is contained in:
@@ -745,8 +745,8 @@ pub fn walk_ty_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v TyPar
|
|||||||
pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v GenericParam) {
|
pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v GenericParam) {
|
||||||
visitor.visit_id(param.id);
|
visitor.visit_id(param.id);
|
||||||
match param.kind {
|
match param.kind {
|
||||||
GenericParamKind::Lifetime { ref bounds, ref lifetime_deprecated, .. } => {
|
GenericParamKind::Lifetime { ref bounds, ref lifetime, .. } => {
|
||||||
match lifetime_deprecated.name {
|
match lifetime.name {
|
||||||
LifetimeName::Name(name) => {
|
LifetimeName::Name(name) => {
|
||||||
visitor.visit_name(param.span, name);
|
visitor.visit_name(param.span, name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -705,7 +705,7 @@ impl<'a> LoweringContext<'a> {
|
|||||||
name: hir_name,
|
name: hir_name,
|
||||||
bounds: vec![].into(),
|
bounds: vec![].into(),
|
||||||
in_band: true,
|
in_band: true,
|
||||||
lifetime_deprecated: hir::Lifetime {
|
lifetime: hir::Lifetime {
|
||||||
id: def_node_id,
|
id: def_node_id,
|
||||||
span,
|
span,
|
||||||
name: hir_name,
|
name: hir_name,
|
||||||
@@ -1424,7 +1424,7 @@ impl<'a> LoweringContext<'a> {
|
|||||||
name,
|
name,
|
||||||
bounds: vec![].into(),
|
bounds: vec![].into(),
|
||||||
in_band: false,
|
in_band: false,
|
||||||
lifetime_deprecated: hir::Lifetime {
|
lifetime: hir::Lifetime {
|
||||||
id: def_node_id,
|
id: def_node_id,
|
||||||
span: lifetime.span,
|
span: lifetime.span,
|
||||||
name,
|
name,
|
||||||
@@ -1947,7 +1947,7 @@ impl<'a> LoweringContext<'a> {
|
|||||||
itctx: ImplTraitContext)
|
itctx: ImplTraitContext)
|
||||||
-> hir::GenericParam {
|
-> hir::GenericParam {
|
||||||
match param.kind {
|
match param.kind {
|
||||||
GenericParamKind::Lifetime { ref bounds, ref lifetime, .. } => {
|
GenericParamKind::Lifetime { ref bounds, ref lifetime } => {
|
||||||
let was_collecting_in_band = self.is_collecting_in_band_lifetimes;
|
let was_collecting_in_band = self.is_collecting_in_band_lifetimes;
|
||||||
self.is_collecting_in_band_lifetimes = false;
|
self.is_collecting_in_band_lifetimes = false;
|
||||||
|
|
||||||
@@ -1960,7 +1960,7 @@ impl<'a> LoweringContext<'a> {
|
|||||||
name: lifetime.name,
|
name: lifetime.name,
|
||||||
bounds: bounds.iter().map(|lt| self.lower_lifetime(lt)).collect(),
|
bounds: bounds.iter().map(|lt| self.lower_lifetime(lt)).collect(),
|
||||||
in_band: false,
|
in_band: false,
|
||||||
lifetime_deprecated: lifetime,
|
lifetime,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -462,7 +462,7 @@ pub enum GenericParamKind {
|
|||||||
// `fn foo(x: &'a u8) -> &'a u8 { x }`
|
// `fn foo(x: &'a u8) -> &'a u8 { x }`
|
||||||
in_band: bool,
|
in_band: bool,
|
||||||
// We keep a `Lifetime` around for now just so we can `visit_lifetime`.
|
// We keep a `Lifetime` around for now just so we can `visit_lifetime`.
|
||||||
lifetime_deprecated: Lifetime,
|
lifetime: Lifetime,
|
||||||
},
|
},
|
||||||
Type {
|
Type {
|
||||||
name: Name,
|
name: Name,
|
||||||
|
|||||||
@@ -208,11 +208,11 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::GenericParamKind {
|
|||||||
mem::discriminant(self).hash_stable(hcx, hasher);
|
mem::discriminant(self).hash_stable(hcx, hasher);
|
||||||
match self {
|
match self {
|
||||||
hir::GenericParamKind::Lifetime { name, ref bounds, in_band,
|
hir::GenericParamKind::Lifetime { name, ref bounds, in_band,
|
||||||
ref lifetime_deprecated } => {
|
ref lifetime } => {
|
||||||
name.hash_stable(hcx, hasher);
|
name.hash_stable(hcx, hasher);
|
||||||
bounds.hash_stable(hcx, hasher);
|
bounds.hash_stable(hcx, hasher);
|
||||||
in_band.hash_stable(hcx, hasher);
|
in_band.hash_stable(hcx, hasher);
|
||||||
lifetime_deprecated.hash_stable(hcx, hasher);
|
lifetime.hash_stable(hcx, hasher);
|
||||||
}
|
}
|
||||||
hir::GenericParamKind::Type { name, ref bounds, ref default, synthetic, attrs } => {
|
hir::GenericParamKind::Type { name, ref bounds, ref default, synthetic, attrs } => {
|
||||||
name.hash_stable(hcx, hasher);
|
name.hash_stable(hcx, hasher);
|
||||||
|
|||||||
@@ -1220,20 +1220,17 @@ fn compute_object_lifetime_defaults(
|
|||||||
.map(|set| match *set {
|
.map(|set| match *set {
|
||||||
Set1::Empty => "BaseDefault".to_string(),
|
Set1::Empty => "BaseDefault".to_string(),
|
||||||
Set1::One(Region::Static) => "'static".to_string(),
|
Set1::One(Region::Static) => "'static".to_string(),
|
||||||
Set1::One(Region::EarlyBound(i, _, _)) => {
|
Set1::One(Region::EarlyBound(mut i, _, _)) => {
|
||||||
let mut j = 0;
|
generics.params.iter().find_map(|param| match param.kind {
|
||||||
generics.params.iter().find(|param| match param.kind {
|
|
||||||
GenericParamKind::Lifetime { .. } => {
|
GenericParamKind::Lifetime { .. } => {
|
||||||
if i == j {
|
if i == 0 {
|
||||||
return true;
|
return Some(param.name().to_string());
|
||||||
}
|
}
|
||||||
j += 1;
|
i -= 1;
|
||||||
false
|
None
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => None,
|
||||||
}).unwrap()
|
}).unwrap()
|
||||||
.name()
|
|
||||||
.to_string()
|
|
||||||
}
|
}
|
||||||
Set1::One(_) => bug!(),
|
Set1::One(_) => bug!(),
|
||||||
Set1::Many => "Ambiguous".to_string(),
|
Set1::Many => "Ambiguous".to_string(),
|
||||||
|
|||||||
@@ -274,15 +274,14 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
|||||||
let substs = Substs::for_item(tcx, def_id, |param, substs| {
|
let substs = Substs::for_item(tcx, def_id, |param, substs| {
|
||||||
match param.kind {
|
match param.kind {
|
||||||
GenericParamDefKind::Lifetime => {
|
GenericParamDefKind::Lifetime => {
|
||||||
let i = param.index as usize - own_self;
|
let mut i = param.index as usize - own_self;
|
||||||
let mut j = 0;
|
|
||||||
for arg in &generic_args.args {
|
for arg in &generic_args.args {
|
||||||
match arg {
|
match arg {
|
||||||
GenericArg::Lifetime(lt) => {
|
GenericArg::Lifetime(lt) => {
|
||||||
if i == j {
|
if i == 0 {
|
||||||
return self.ast_region_to_region(lt, Some(param)).into();
|
return self.ast_region_to_region(lt, Some(param)).into();
|
||||||
}
|
}
|
||||||
j += 1;
|
i -= 1;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
@@ -297,17 +296,16 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
|||||||
return ty.into();
|
return ty.into();
|
||||||
}
|
}
|
||||||
|
|
||||||
let i = i - (lt_accepted + own_self);
|
let mut i = i - (lt_accepted + own_self);
|
||||||
if i < ty_provided {
|
if i < ty_provided {
|
||||||
// A provided type parameter.
|
// A provided type parameter.
|
||||||
let mut j = 0;
|
|
||||||
for arg in &generic_args.args {
|
for arg in &generic_args.args {
|
||||||
match arg {
|
match arg {
|
||||||
GenericArg::Type(ty) => {
|
GenericArg::Type(ty) => {
|
||||||
if i == j {
|
if i == 0 {
|
||||||
return self.ast_ty_to_ty(ty).into();
|
return self.ast_ty_to_ty(ty).into();
|
||||||
}
|
}
|
||||||
j += 1;
|
i -= 1;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -325,21 +325,20 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
|
|||||||
let provided = &segment.args;
|
let provided = &segment.args;
|
||||||
let own_counts = method_generics.own_counts();
|
let own_counts = method_generics.own_counts();
|
||||||
Substs::for_item(self.tcx, pick.item.def_id, |param, _| {
|
Substs::for_item(self.tcx, pick.item.def_id, |param, _| {
|
||||||
let i = param.index as usize;
|
let mut i = param.index as usize;
|
||||||
if i < parent_substs.len() {
|
if i < parent_substs.len() {
|
||||||
parent_substs[i]
|
parent_substs[i]
|
||||||
} else {
|
} else {
|
||||||
match param.kind {
|
match param.kind {
|
||||||
GenericParamDefKind::Lifetime => {
|
GenericParamDefKind::Lifetime => {
|
||||||
if let Some(lifetime) = provided.as_ref().and_then(|data| {
|
if let Some(lifetime) = provided.as_ref().and_then(|data| {
|
||||||
let mut j = 0;
|
|
||||||
for arg in &data.args {
|
for arg in &data.args {
|
||||||
match arg {
|
match arg {
|
||||||
GenericArg::Lifetime(lt) => {
|
GenericArg::Lifetime(lt) => {
|
||||||
if i - parent_substs.len() == j {
|
if i == parent_substs.len() {
|
||||||
return Some(lt);
|
return Some(lt);
|
||||||
}
|
}
|
||||||
j += 1;
|
i -= 1;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
@@ -352,14 +351,13 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
|
|||||||
}
|
}
|
||||||
GenericParamDefKind::Type {..} => {
|
GenericParamDefKind::Type {..} => {
|
||||||
if let Some(ast_ty) = provided.as_ref().and_then(|data| {
|
if let Some(ast_ty) = provided.as_ref().and_then(|data| {
|
||||||
let mut j = 0;
|
|
||||||
for arg in &data.args {
|
for arg in &data.args {
|
||||||
match arg {
|
match arg {
|
||||||
GenericArg::Type(ty) => {
|
GenericArg::Type(ty) => {
|
||||||
if i - parent_substs.len() - own_counts.lifetimes == j {
|
if i == parent_substs.len() + own_counts.lifetimes {
|
||||||
return Some(ty);
|
return Some(ty);
|
||||||
}
|
}
|
||||||
j += 1;
|
i -= 1;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -492,12 +492,12 @@ pub fn walk_ty_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a TyPar
|
|||||||
|
|
||||||
pub fn walk_generic_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a GenericParam) {
|
pub fn walk_generic_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a GenericParam) {
|
||||||
match param.kind {
|
match param.kind {
|
||||||
GenericParamKind::Lifetime { ref bounds, ref lifetime, .. } => {
|
GenericParamKind::Lifetime { ref bounds, ref lifetime } => {
|
||||||
visitor.visit_ident(param.ident);
|
visitor.visit_ident(param.ident);
|
||||||
walk_list!(visitor, visit_lifetime, bounds);
|
walk_list!(visitor, visit_lifetime, bounds);
|
||||||
walk_list!(visitor, visit_attribute, param.attrs.iter());
|
walk_list!(visitor, visit_attribute, param.attrs.iter());
|
||||||
}
|
}
|
||||||
GenericParamKind::Type { ref bounds, ref default, .. } => {
|
GenericParamKind::Type { ref bounds, ref default } => {
|
||||||
visitor.visit_ident(t.ident);
|
visitor.visit_ident(t.ident);
|
||||||
walk_list!(visitor, visit_ty_param_bound, bounds);
|
walk_list!(visitor, visit_ty_param_bound, bounds);
|
||||||
walk_list!(visitor, visit_ty, default);
|
walk_list!(visitor, visit_ty, default);
|
||||||
|
|||||||
Reference in New Issue
Block a user