}
pub(super) fn is_object_safe_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
- trait_def_id: DefId)
- -> bool {
+ trait_def_id: DefId) -> bool {
tcx.object_safety_violations(trait_def_id).is_empty()
}
pub fn index(&self) -> u32 {
match self {
GenericParamDef::Lifetime(lt) => lt.index,
- GenericParamDef::Type(ty) => ty.index,
+ GenericParamDef::Type(ty) => ty.index,
+ }
+ }
+
+ pub fn def_id(&self) -> DefId {
+ match self {
+ GenericParamDef::Lifetime(lt) => lt.def_id,
+ GenericParamDef::Type(ty) => ty.def_id,
}
}
pub parent_count: usize,
pub params: Vec<GenericParamDef>,
- /// Reverse map to each `TypeParamDef`'s `index` field
+ /// Reverse map to the `index` field of each `GenericParamDef`'s inner type
pub param_def_id_to_index: FxHashMap<DefId, u32>,
pub has_self: bool,
param_counts
}
- pub fn type_params_without_defaults(&self) -> usize {
- let mut count = 0;
- for param in self.params.iter() {
- if let GenericParamDef::Type(ty) = param {
- if !ty.has_default {
- count += 1
- }
- }
- }
- count
- }
-
pub fn requires_monomorphization(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool {
if self.params.iter().any(|p| p.get_type().is_some()) {
return true;
mk_type: &mut FT)
where FR: FnMut(&ty::RegionParamDef, &[Kind<'tcx>]) -> ty::Region<'tcx>,
FT: FnMut(&ty::TypeParamDef, &[Kind<'tcx>]) -> Ty<'tcx> {
- // Handle Self first, before all regions.
- let mut skip_self = defs.parent.is_none() && defs.has_self;
- if skip_self {
- let def = defs.params.iter().find_map(|p| p.get_type()).unwrap();
- let ty = mk_type(&def, substs);
- assert_eq!(def.index as usize, substs.len());
- substs.push(ty.into());
- }
-
for def in &defs.params {
let param = match def {
ty::GenericParamDef::Lifetime(ref lt) => {
mk_region(lt, substs).into()
}
ty::GenericParamDef::Type(ref ty) => {
- if skip_self {
- skip_self = false;
- continue
- }
mk_type(ty, substs).into()
}
};
if def.is_phantom_data() {
let result = DtorckConstraint {
outlives: vec![],
- dtorck_types: vec![tcx.mk_param_from_def(
- &tcx.generics_of(def_id)
- .params
- .iter()
- .find_map(|p| p.get_type())
- .expect("should be at least one type parameter"))],
+ dtorck_types: vec![tcx.mk_param_from_def(&tcx.generics_of(def_id).params[0].get_type().unwrap())],
overflows: vec![],
};
debug!("dtorck_constraint: {:?} => {:?}", def, result);
use llvm::debuginfo::{DIFile, DIType, DIScope, DIBuilderRef, DISubprogram, DIArray, DIFlags};
use rustc::hir::TransFnAttrFlags;
use rustc::hir::def_id::{DefId, CrateNum};
-use rustc::ty::subst::Substs;
+use rustc::ty::subst::{Substs, UnpackedKind};
use rustc::ty::GenericParamDef;
use abi::Abi;
};
}
-#[derive(PartialEq, Eq, Hash)]
-pub enum Kind {
- Lifetime,
- Type,
-}
-
/// Creates the function-specific debug context.
///
/// Returns the FunctionDebugContext for the function which holds state needed
// Again, only create type information if full debuginfo is enabled
let template_params: Vec<_> = if cx.sess().opts.debuginfo == FullDebugInfo {
let names = get_parameter_names(cx, generics);
- let names = names.iter().flat_map(|(kind, param)| {
- if kind == &Kind::Type {
- Some(param)
+ substs.iter().zip(names).filter_map(|(kind, name)| {
+ if let UnpackedKind::Type(ty) = kind.unpack() {
+ let actual_type = cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), ty);
+ let actual_type_metadata =
+ type_metadata(cx, actual_type, syntax_pos::DUMMY_SP);
+ let name = CString::new(name.as_str().as_bytes()).unwrap();
+ Some(unsafe {
+ llvm::LLVMRustDIBuilderCreateTemplateTypeParameter(
+ DIB(cx),
+ ptr::null_mut(),
+ name.as_ptr(),
+ actual_type_metadata,
+ file_metadata,
+ 0,
+ 0)
+ })
} else {
None
}
- });
- substs.types().zip(names).map(|(ty, name)| {
- let actual_type = cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), ty);
- let actual_type_metadata = type_metadata(cx, actual_type, syntax_pos::DUMMY_SP);
- let name = CString::new(name.as_str().as_bytes()).unwrap();
- unsafe {
- llvm::LLVMRustDIBuilderCreateTemplateTypeParameter(
- DIB(cx),
- ptr::null_mut(),
- name.as_ptr(),
- actual_type_metadata,
- file_metadata,
- 0,
- 0)
- }
}).collect()
} else {
vec![]
fn get_parameter_names(cx: &CodegenCx,
generics: &ty::Generics)
- -> Vec<(Kind, InternedString)> {
+ -> Vec<InternedString> {
let mut names = generics.parent.map_or(vec![], |def_id| {
get_parameter_names(cx, cx.tcx.generics_of(def_id))
});
names.extend(generics.params.iter().map(|param| {
match param {
- GenericParamDef::Lifetime(lt) => (Kind::Lifetime, lt.name),
- GenericParamDef::Type(ty) => (Kind::Type, ty.name),
+ GenericParamDef::Lifetime(lt) => lt.name,
+ GenericParamDef::Type(ty) => ty.name,
}
}));
names
let type_params_offset = self_ty.is_some() as usize;
let ty_param_defs = param_counts.types - type_params_offset;
if !infer_types || num_types_provided > ty_param_defs {
+ let type_params_without_defaults = {
+ let mut count = 0;
+ for param in decl_generics.params.iter() {
+ if let ty::GenericParamDef::Type(ty) = param {
+ if !ty.has_default {
+ count += 1
+ }
+ }
+ }
+ count
+ };
+
check_type_argument_count(tcx,
span,
num_types_provided,
ty_param_defs,
- decl_generics.type_params_without_defaults() - type_params_offset);
+ type_params_without_defaults - type_params_offset);
}
let is_object = self_ty.map_or(false, |ty| ty.sty == TRAIT_OBJECT_DUMMY_SELF);
let type_params_offset
= (generics.parent.is_none() && generics.has_self) as usize;
let type_params = param_counts.types - type_params_offset;
+ let type_params_without_defaults = {
+ let mut count = 0;
+ for param in generics.params.iter() {
+ if let ty::GenericParamDef::Type(ty) = param {
+ if !ty.has_default {
+ count += 1
+ }
+ }
+ }
+ count
+ };
let type_params_barring_defaults =
- generics.type_params_without_defaults() - type_params_offset;
+ type_params_without_defaults - type_params_offset;
(type_params_barring_defaults, type_params, param_counts.lifetimes)
});
.collect();
for method_param in generics.params.iter() {
- // Shadowing is currently permitted with lifetimes.
+ // Shadowing is checked in resolve_lifetime.
if let GenericParamDef::Lifetime(_) = method_param {
continue;
}
.chain(types)
.collect();
- let param_def_id_to_index =
- params.iter()
- .map(|param| {
- match param {
- ty::GenericParamDef::Lifetime(lt) => (lt.def_id, lt.index),
- ty::GenericParamDef::Type(ty) => (ty.def_id, ty.index),
- }
- })
- .collect();
+ let param_def_id_to_index = params.iter()
+ .map(|param| (param.def_id(), param.index()))
+ .collect();
tcx.alloc_generics(ty::Generics {
parent: parent_def_id,