Eliminate ty::Generics::lifetimes()
Begone lazy lifetime code!
This commit is contained in:
parent
b75f421ee9
commit
d557ff983f
@ -14,7 +14,7 @@ use infer::outlives::free_region_map::FreeRegionRelations;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use syntax::ast;
|
||||
use traits::{self, PredicateObligation};
|
||||
use ty::{self, Ty, TyCtxt};
|
||||
use ty::{self, Ty, TyCtxt, GenericParamDef};
|
||||
use ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder};
|
||||
use ty::outlives::Component;
|
||||
use ty::subst::{Kind, Substs, UnpackedKind};
|
||||
@ -313,7 +313,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
// `['a]` for the first impl trait and `'b` for the
|
||||
// second.
|
||||
let mut least_region = None;
|
||||
for region_def in abstract_type_generics.lifetimes_depr() {
|
||||
for region_def in abstract_type_generics.params.iter().filter_map(|param| {
|
||||
if let GenericParamDef::Lifetime(lt) = param {
|
||||
Some(lt)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}) {
|
||||
// Find the index of this region in the list of substitutions.
|
||||
let index = region_def.index as usize;
|
||||
|
||||
|
@ -847,16 +847,6 @@ impl<'a, 'gcx, 'tcx> Generics {
|
||||
count
|
||||
}
|
||||
|
||||
pub fn lifetimes_depr(&self) -> impl DoubleEndedIterator<Item = &RegionParamDef> {
|
||||
self.params.iter().filter_map(|p| {
|
||||
if let GenericParamDef::Lifetime(lt) = p {
|
||||
Some(lt)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn types_depr(&self) -> impl DoubleEndedIterator<Item = &TypeParamDef> {
|
||||
self.params.iter().filter_map(|p| {
|
||||
if let GenericParamDef::Type(ty) = p {
|
||||
|
@ -104,14 +104,6 @@ fn enforce_impl_params_are_constrained<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
ctp::identify_constrained_type_params(
|
||||
tcx, &impl_predicates.predicates.as_slice(), impl_trait_ref, &mut input_parameters);
|
||||
|
||||
// Disallow ANY unconstrained type parameters.
|
||||
for (ty_param, param) in impl_generics.types_depr().zip(impl_hir_generics.ty_params()) {
|
||||
let param_ty = ty::ParamTy::for_def(ty_param);
|
||||
if !input_parameters.contains(&ctp::Parameter::from(param_ty)) {
|
||||
report_unused_parameter(tcx, param.span, "type", ¶m_ty.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
// Disallow unconstrained lifetimes, but only if they appear in assoc types.
|
||||
let lifetimes_in_associated_types: FxHashSet<_> = impl_item_refs.iter()
|
||||
.map(|item_ref| tcx.hir.local_def_id(item_ref.id.node_id))
|
||||
@ -122,13 +114,27 @@ fn enforce_impl_params_are_constrained<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
.flat_map(|def_id| {
|
||||
ctp::parameters_for(&tcx.type_of(def_id), true)
|
||||
}).collect();
|
||||
for (ty_lt, lt) in impl_generics.lifetimes_depr().zip(impl_hir_generics.lifetimes()) {
|
||||
let param = ctp::Parameter::from(ty_lt.to_early_bound_region_data());
|
||||
|
||||
if lifetimes_in_associated_types.contains(¶m) && // (*)
|
||||
!input_parameters.contains(¶m) {
|
||||
report_unused_parameter(tcx, lt.lifetime.span,
|
||||
"lifetime", <.lifetime.name.name().to_string());
|
||||
for (ty_param, hir_param) in impl_generics.params.iter()
|
||||
.zip(impl_hir_generics.params.iter()) {
|
||||
match (ty_param, hir_param) {
|
||||
// Disallow ANY unconstrained type parameters.
|
||||
(ty::GenericParamDef::Type(ty_ty), hir::GenericParamDef::Type(hir_ty)) => {
|
||||
let param_ty = ty::ParamTy::for_def(ty_ty);
|
||||
if !input_parameters.contains(&ctp::Parameter::from(param_ty)) {
|
||||
report_unused_parameter(tcx, hir_ty.span, "type", ¶m_ty.to_string());
|
||||
}
|
||||
}
|
||||
(ty::GenericParamDef::Lifetime(ty_lt), hir::GenericParamDef::Lifetime(hir_lt)) => {
|
||||
let param = ctp::Parameter::from(ty_lt.to_early_bound_region_data());
|
||||
if lifetimes_in_associated_types.contains(¶m) && // (*)
|
||||
!input_parameters.contains(¶m) {
|
||||
report_unused_parameter(tcx, hir_lt.lifetime.span,
|
||||
"lifetime", &hir_lt.lifetime.name.name().to_string());
|
||||
}
|
||||
}
|
||||
(ty::GenericParamDef::Type(_), _) => continue,
|
||||
(ty::GenericParamDef::Lifetime(_), _) => continue,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1849,10 +1849,15 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
|
||||
// and instead see `where T: Foo + Bar + Sized + 'a`
|
||||
|
||||
Generics {
|
||||
params: gens.lifetimes_depr()
|
||||
.into_iter()
|
||||
.map(|lp| GenericParamDef::Lifetime(lp.clean(cx)))
|
||||
.chain(
|
||||
params: gens.params
|
||||
.iter()
|
||||
.flat_map(|param| {
|
||||
if let ty::GenericParamDef::Lifetime(lt) = param {
|
||||
Some(GenericParamDef::Lifetime(lt.clean(cx)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}).chain(
|
||||
simplify::ty_params(stripped_typarams)
|
||||
.into_iter()
|
||||
.map(|tp| GenericParamDef::Type(tp))
|
||||
|
Loading…
x
Reference in New Issue
Block a user