Inline get_type
This commit is contained in:
parent
fc27c2eb38
commit
5e89312a22
11 changed files with 63 additions and 40 deletions
|
@ -20,7 +20,7 @@ use hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
|
|||
use hir::map::Map;
|
||||
use hir::ItemLocalId;
|
||||
use hir::LifetimeName;
|
||||
use ty::{self, TyCtxt};
|
||||
use ty::{self, TyCtxt, GenericParamDef};
|
||||
|
||||
use errors::DiagnosticBuilder;
|
||||
use rustc::lint;
|
||||
|
@ -1662,7 +1662,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
.params
|
||||
.iter()
|
||||
.filter_map(|param| {
|
||||
param.get_type().and_then(|ty| Some(ty.object_lifetime_default))
|
||||
match *param {
|
||||
GenericParamDef::Type(ty) => Some(ty.object_lifetime_default),
|
||||
GenericParamDef::Lifetime(_) => None,
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
|
|
|
@ -35,7 +35,7 @@ use infer::type_variable::TypeVariableOrigin;
|
|||
use std::fmt;
|
||||
use syntax::ast;
|
||||
use session::DiagnosticMessageId;
|
||||
use ty::{self, AdtKind, ToPredicate, ToPolyTraitRef, Ty, TyCtxt, TypeFoldable};
|
||||
use ty::{self, AdtKind, ToPredicate, ToPolyTraitRef, Ty, TyCtxt, TypeFoldable, GenericParamDef};
|
||||
use ty::error::ExpectedFound;
|
||||
use ty::fast_reject;
|
||||
use ty::fold::TypeFolder;
|
||||
|
@ -378,7 +378,12 @@ 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.params.iter().filter_map(|param| param.get_type()) {
|
||||
for param in generics.params.iter().filter_map(|param| {
|
||||
match *param {
|
||||
GenericParamDef::Type(ty) => Some(ty),
|
||||
GenericParamDef::Lifetime(_) => None,
|
||||
}
|
||||
}) {
|
||||
let name = param.name.to_string();
|
||||
let ty = trait_ref.substs.type_for_def(¶m);
|
||||
let ty_str = ty.to_string();
|
||||
|
|
|
@ -254,10 +254,9 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedFormatString {
|
|||
Position::ArgumentNamed(s) if s == name => (),
|
||||
// So is `{A}` if A is a type parameter
|
||||
Position::ArgumentNamed(s) => match generics.params.iter().find(|param| {
|
||||
if let GenericParamDef::Type(ty) = param {
|
||||
ty.name == s
|
||||
} else {
|
||||
false
|
||||
match *param {
|
||||
GenericParamDef::Type(ty) => ty.name == s,
|
||||
GenericParamDef::Lifetime(_) => false,
|
||||
}
|
||||
}) {
|
||||
Some(_) => (),
|
||||
|
@ -292,10 +291,11 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedFormatString {
|
|||
let trait_str = tcx.item_path_str(trait_ref.def_id);
|
||||
let generics = tcx.generics_of(trait_ref.def_id);
|
||||
let generic_map = generics.params.iter().filter_map(|param| {
|
||||
if let Some(ty) = param.get_type() {
|
||||
match *param {
|
||||
GenericParamDef::Type(ty) => {
|
||||
Some((ty.name.to_string(), trait_ref.substs.type_for_def(&ty).to_string()))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
GenericParamDef::Lifetime(_) => None
|
||||
}
|
||||
}).collect::<FxHashMap<String, String>>();
|
||||
|
||||
|
|
|
@ -777,13 +777,6 @@ impl GenericParamDef {
|
|||
GenericParamDef::Type(ty) => ty.def_id,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_type(&self) -> Option<TypeParamDef> {
|
||||
match *self {
|
||||
GenericParamDef::Type(ty) => Some(ty),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GenericParamCount {
|
||||
|
@ -834,7 +827,12 @@ impl<'a, 'gcx, 'tcx> Generics {
|
|||
}
|
||||
|
||||
pub fn requires_monomorphization(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool {
|
||||
if self.params.iter().any(|p| p.get_type().is_some()) {
|
||||
if self.params.iter().any(|param| {
|
||||
match *param {
|
||||
GenericParamDef::Type(_) => true,
|
||||
GenericParamDef::Lifetime(_) => false
|
||||
}
|
||||
}) {
|
||||
return true;
|
||||
}
|
||||
if let Some(parent_def_id) = self.parent {
|
||||
|
|
|
@ -243,12 +243,8 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
|
|||
FT: FnMut(&ty::TypeParamDef, &[Kind<'tcx>]) -> Ty<'tcx> {
|
||||
for def in &defs.params {
|
||||
let param = match def {
|
||||
ty::GenericParamDef::Lifetime(ref lt) => {
|
||||
mk_region(lt, substs).into()
|
||||
}
|
||||
ty::GenericParamDef::Type(ref ty) => {
|
||||
mk_type(ty, substs).into()
|
||||
}
|
||||
ty::GenericParamDef::Lifetime(ref lt) => mk_region(lt, substs).into(),
|
||||
ty::GenericParamDef::Type(ref ty) => mk_type(ty, substs).into(),
|
||||
};
|
||||
assert_eq!(def.index() as usize, substs.len());
|
||||
substs.push(param);
|
||||
|
|
|
@ -19,7 +19,7 @@ use ty::{TyError, TyStr, TyArray, TySlice, TyFloat, TyFnDef, TyFnPtr};
|
|||
use ty::{TyParam, TyRawPtr, TyRef, TyNever, TyTuple};
|
||||
use ty::{TyClosure, TyGenerator, TyGeneratorWitness, TyForeign, TyProjection, TyAnon};
|
||||
use ty::{TyDynamic, TyInt, TyUint, TyInfer};
|
||||
use ty::{self, Ty, TyCtxt, TypeFoldable, GenericParamCount};
|
||||
use ty::{self, Ty, TyCtxt, TypeFoldable, GenericParamCount, GenericParamDef};
|
||||
use util::nodemap::FxHashSet;
|
||||
|
||||
use std::cell::Cell;
|
||||
|
@ -337,7 +337,12 @@ impl PrintContext {
|
|||
|
||||
if !verbose {
|
||||
let mut type_params =
|
||||
generics.params.iter().rev().filter_map(|param| param.get_type());
|
||||
generics.params.iter().rev().filter_map(|param| {
|
||||
match *param {
|
||||
GenericParamDef::Type(ty) => Some(ty),
|
||||
GenericParamDef::Lifetime(_) => None,
|
||||
}
|
||||
});
|
||||
if let Some(last_ty) = type_params.next() {
|
||||
if last_ty.has_default {
|
||||
if let Some(substs) = tcx.lift(&substs) {
|
||||
|
|
|
@ -13,7 +13,7 @@ use rustc::hir::def_id::DefId;
|
|||
use rustc::traits::{FulfillmentContext, Normalized, ObligationCause};
|
||||
use rustc::traits::query::{CanonicalTyGoal, NoSolution};
|
||||
use rustc::traits::query::dropck_outlives::{DtorckConstraint, DropckOutlivesResult};
|
||||
use rustc::ty::{self, ParamEnvAnd, Ty, TyCtxt};
|
||||
use rustc::ty::{self, ParamEnvAnd, Ty, TyCtxt, GenericParamDef};
|
||||
use rustc::ty::subst::Subst;
|
||||
use rustc::util::nodemap::FxHashSet;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
|
@ -278,9 +278,13 @@ crate fn adt_dtorck_constraint<'a, 'tcx>(
|
|||
debug!("dtorck_constraint: {:?}", def);
|
||||
|
||||
if def.is_phantom_data() {
|
||||
let type_param = match tcx.generics_of(def_id).params[0] {
|
||||
GenericParamDef::Type(ty) => ty,
|
||||
GenericParamDef::Lifetime(_) => unreachable!(),
|
||||
};
|
||||
let result = DtorckConstraint {
|
||||
outlives: vec![],
|
||||
dtorck_types: vec![tcx.mk_param_from_def(&tcx.generics_of(def_id).params[0].get_type().unwrap())],
|
||||
dtorck_types: vec![tcx.mk_param_from_def(&type_param)],
|
||||
overflows: vec![],
|
||||
};
|
||||
debug!("dtorck_constraint: {:?} => {:?}", def, result);
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
use rustc::hir::{self, ImplItemKind, TraitItemKind};
|
||||
use rustc::infer::{self, InferOk};
|
||||
use rustc::ty::{self, TyCtxt};
|
||||
use rustc::ty::{self, TyCtxt, GenericParamDef};
|
||||
use rustc::ty::util::ExplicitSelf;
|
||||
use rustc::traits::{self, ObligationCause, ObligationCauseCode, Reveal};
|
||||
use rustc::ty::error::{ExpectedFound, TypeError};
|
||||
|
@ -728,8 +728,18 @@ 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);
|
||||
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());
|
||||
let impl_m_type_params = impl_m_generics.params.iter().filter_map(|param| {
|
||||
match *param {
|
||||
GenericParamDef::Type(ty) => Some(ty),
|
||||
GenericParamDef::Lifetime(_) => None,
|
||||
}
|
||||
});
|
||||
let trait_m_type_params = trait_m_generics.params.iter().filter_map(|param| {
|
||||
match *param {
|
||||
GenericParamDef::Type(ty) => Some(ty),
|
||||
GenericParamDef::Lifetime(_) => None,
|
||||
}
|
||||
});
|
||||
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();
|
||||
|
|
|
@ -860,7 +860,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
|
|||
ty.bounds.insert(0, TyParamBound::maybe_sized(self.cx));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
GenericParamDef::Lifetime(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1725,10 +1725,9 @@ pub enum GenericParamDef {
|
|||
|
||||
impl GenericParamDef {
|
||||
pub fn is_synthetic_type_param(&self) -> bool {
|
||||
if let GenericParamDef::Type(ref t) = *self {
|
||||
t.synthetic.is_some()
|
||||
} else {
|
||||
false
|
||||
match self {
|
||||
GenericParamDef::Type(ty) => ty.synthetic.is_some(),
|
||||
GenericParamDef::Lifetime(_) => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1437,9 +1437,12 @@ impl DocFolder for Cache {
|
|||
impl<'a> Cache {
|
||||
fn generics(&mut self, generics: &clean::Generics) {
|
||||
for param in &generics.params {
|
||||
if let clean::GenericParamDef::Type(ref typ) = *param {
|
||||
match *param {
|
||||
clean::GenericParamDef::Type(ref typ) => {
|
||||
self.typarams.insert(typ.did, typ.name.clone());
|
||||
}
|
||||
clean::GenericParamDef::Lifetime(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue