Eliminate ty::Generics::types()
And with one final incanation, the specific kind iterators were banished from ty::Generics, never to be seen again!
This commit is contained in:
parent
d557ff983f
commit
0b8b14f6f5
9 changed files with 52 additions and 36 deletions
|
@ -1659,8 +1659,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
.entry(def_id)
|
||||
.or_insert_with(|| {
|
||||
tcx.generics_of(def_id)
|
||||
.types_depr()
|
||||
.map(|def| def.object_lifetime_default)
|
||||
.params
|
||||
.iter()
|
||||
.filter_map(|param| {
|
||||
param.get_type().and_then(|ty| Some(ty.object_lifetime_default))
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
};
|
||||
|
|
|
@ -378,9 +378,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
flags.push(("_Self".to_string(), Some(self.tcx.type_of(def.did).to_string())));
|
||||
}
|
||||
|
||||
for param in generics.types_depr() {
|
||||
for param in generics.params.iter().filter_map(|param| param.get_type()) {
|
||||
let name = param.name.to_string();
|
||||
let ty = trait_ref.substs.type_for_def(param);
|
||||
let ty = trait_ref.substs.type_for_def(¶m);
|
||||
let ty_str = ty.to_string();
|
||||
flags.push((name.clone(), Some(ty_str.clone())));
|
||||
}
|
||||
|
|
|
@ -291,8 +291,12 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedFormatString {
|
|||
let name = tcx.item_name(trait_ref.def_id);
|
||||
let trait_str = tcx.item_path_str(trait_ref.def_id);
|
||||
let generics = tcx.generics_of(trait_ref.def_id);
|
||||
let generic_map = generics.types_depr().map(|param| {
|
||||
(param.name.to_string(), trait_ref.substs.type_for_def(param).to_string())
|
||||
let generic_map = generics.params.iter().filter_map(|param| {
|
||||
if let Some(ty) = param.get_type() {
|
||||
Some((ty.name.to_string(), trait_ref.substs.type_for_def(&ty).to_string()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}).collect::<FxHashMap<String, String>>();
|
||||
|
||||
let parser = Parser::new(&self.0);
|
||||
|
|
|
@ -847,16 +847,6 @@ impl<'a, 'gcx, 'tcx> Generics {
|
|||
count
|
||||
}
|
||||
|
||||
pub fn types_depr(&self) -> impl DoubleEndedIterator<Item = &TypeParamDef> {
|
||||
self.params.iter().filter_map(|p| {
|
||||
if let GenericParamDef::Type(ty) = p {
|
||||
Some(ty)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn requires_monomorphization(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool {
|
||||
if self.params.iter().any(|p| p.get_type().is_some()) {
|
||||
return true;
|
||||
|
|
|
@ -25,6 +25,7 @@ use util::nodemap::{FxHashSet, FxHashMap};
|
|||
use std::cell::Cell;
|
||||
use std::fmt;
|
||||
use std::usize;
|
||||
use std::iter;
|
||||
|
||||
use rustc_data_structures::indexed_vec::Idx;
|
||||
use rustc_target::spec::abi::Abi;
|
||||
|
@ -335,17 +336,21 @@ impl PrintContext {
|
|||
}
|
||||
|
||||
if !verbose {
|
||||
if generics.types_depr().last().map_or(false, |def| def.has_default) {
|
||||
if let Some(substs) = tcx.lift(&substs) {
|
||||
let tps = substs.types().rev().skip(child_types);
|
||||
for (def, actual) in generics.types_depr().rev().zip(tps) {
|
||||
if !def.has_default {
|
||||
break;
|
||||
let mut type_params =
|
||||
generics.params.iter().rev().filter_map(|param| param.get_type());
|
||||
if let Some(last_ty) = type_params.next() {
|
||||
if last_ty.has_default {
|
||||
if let Some(substs) = tcx.lift(&substs) {
|
||||
let mut tps = substs.types().rev().skip(child_types);
|
||||
let zipped = iter::once((last_ty, tps.next().unwrap()))
|
||||
.chain(type_params.zip(tps));
|
||||
for (ty, actual) in zipped {
|
||||
if !ty.has_default ||
|
||||
tcx.type_of(ty.def_id).subst(tcx, substs) != actual {
|
||||
break;
|
||||
}
|
||||
num_supplied_defaults += 1;
|
||||
}
|
||||
if tcx.type_of(def.def_id).subst(tcx, substs) != actual {
|
||||
break;
|
||||
}
|
||||
num_supplied_defaults += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -429,7 +429,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
|
|||
});
|
||||
names.extend(generics.params.iter().map(|param| {
|
||||
match param {
|
||||
GenericParamDef::Lifetime(lt) => (Kind::Lifetime, lt.name.as_str()),
|
||||
GenericParamDef::Lifetime(lt) => (Kind::Lifetime, lt.name),
|
||||
GenericParamDef::Type(ty) => (Kind::Type, ty.name),
|
||||
}
|
||||
}));
|
||||
|
|
|
@ -728,7 +728,9 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
let mut error_found = false;
|
||||
let impl_m_generics = tcx.generics_of(impl_m.def_id);
|
||||
let trait_m_generics = tcx.generics_of(trait_m.def_id);
|
||||
for (impl_ty, trait_ty) in impl_m_generics.types_depr().zip(trait_m_generics.types_depr()) {
|
||||
let impl_m_type_params = impl_m_generics.params.iter().filter_map(|param| param.get_type());
|
||||
let trait_m_type_params = trait_m_generics.params.iter().filter_map(|param| param.get_type());
|
||||
for (impl_ty, trait_ty) in impl_m_type_params.zip(trait_m_type_params) {
|
||||
if impl_ty.synthetic != trait_ty.synthetic {
|
||||
let impl_node_id = tcx.hir.as_local_node_id(impl_ty.def_id).unwrap();
|
||||
let impl_span = tcx.hir.span(impl_node_id);
|
||||
|
|
|
@ -370,14 +370,22 @@ fn check_where_clauses<'a, 'gcx, 'fcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>,
|
|||
let mut substituted_predicates = Vec::new();
|
||||
|
||||
let generics = tcx.generics_of(def_id);
|
||||
let is_our_default = |def: &ty::TypeParamDef|
|
||||
def.has_default && def.index >= generics.parent_count as u32;
|
||||
let is_our_default = |def: &ty::TypeParamDef| {
|
||||
def.has_default && def.index >= generics.parent_count as u32
|
||||
};
|
||||
|
||||
// Check that concrete defaults are well-formed. See test `type-check-defaults.rs`.
|
||||
// For example this forbids the declaration:
|
||||
// struct Foo<T = Vec<[u32]>> { .. }
|
||||
// Here the default `Vec<[u32]>` is not WF because `[u32]: Sized` does not hold.
|
||||
for d in generics.types_depr().cloned().filter(is_our_default).map(|p| p.def_id) {
|
||||
for d in generics.params.iter().filter_map(|param| {
|
||||
if let GenericParamDef::Type(ty) = *param {
|
||||
if is_our_default(&ty) {
|
||||
return Some(ty.def_id);
|
||||
}
|
||||
}
|
||||
None
|
||||
}) {
|
||||
let ty = fcx.tcx.type_of(d);
|
||||
// ignore dependent defaults -- that is, where the default of one type
|
||||
// parameter includes another (e.g., <T, U = T>). In those cases, we can't
|
||||
|
|
|
@ -1800,12 +1800,16 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
|
|||
// Bounds in the type_params and lifetimes fields are repeated in the
|
||||
// predicates field (see rustc_typeck::collect::ty_generics), so remove
|
||||
// them.
|
||||
let stripped_typarams = gens.types_depr().filter_map(|tp| {
|
||||
if tp.name == keywords::SelfType.name().as_str() {
|
||||
assert_eq!(tp.index, 0);
|
||||
None
|
||||
let stripped_typarams = gens.params.iter().filter_map(|param| {
|
||||
if let ty::GenericParamDef::Type(ty) = param {
|
||||
if ty.name == keywords::SelfType.name().as_str() {
|
||||
assert_eq!(ty.index, 0);
|
||||
None
|
||||
} else {
|
||||
Some(ty.clean(cx))
|
||||
}
|
||||
} else {
|
||||
Some(tp.clean(cx))
|
||||
None
|
||||
}
|
||||
}).collect::<Vec<_>>();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue