1
Fork 0

Thread pure_wrt_drop field through lifetime and type parameters.

This commit is contained in:
Felix S. Klock II 2016-10-11 16:06:43 +02:00
parent 4bb68be681
commit e8ccc68254
6 changed files with 27 additions and 5 deletions

View file

@ -408,6 +408,7 @@ impl<'a> LoweringContext<'a> {
bounds: self.lower_bounds(&tp.bounds),
default: tp.default.as_ref().map(|x| self.lower_ty(x)),
span: tp.span,
pure_wrt_drop: tp.attrs.iter().any(|attr| attr.check_name("may_dangle")),
}
}
@ -427,6 +428,7 @@ impl<'a> LoweringContext<'a> {
hir::LifetimeDef {
lifetime: self.lower_lifetime(&l.lifetime),
bounds: self.lower_lifetimes(&l.bounds),
pure_wrt_drop: l.attrs.iter().any(|attr| attr.check_name("may_dangle")),
}
}

View file

@ -95,6 +95,7 @@ impl fmt::Debug for Lifetime {
pub struct LifetimeDef {
pub lifetime: Lifetime,
pub bounds: HirVec<Lifetime>,
pub pure_wrt_drop: bool,
}
/// A "Path" is essentially Rust's notion of a name; for instance:
@ -290,6 +291,7 @@ pub struct TyParam {
pub bounds: TyParamBounds,
pub default: Option<P<Ty>>,
pub span: Span,
pub pure_wrt_drop: bool,
}
/// Represents lifetimes and type parameters attached to a declaration

View file

@ -1226,16 +1226,17 @@ impl<'a, 'gcx, 'tcx> Rebuilder<'a, 'gcx, 'tcx> {
lifetime: hir::Lifetime,
region_names: &HashSet<ast::Name>)
-> hir::HirVec<hir::TyParam> {
ty_params.iter().map(|ty_param| {
let bounds = self.rebuild_ty_param_bounds(ty_param.bounds.clone(),
ty_params.into_iter().map(|ty_param| {
let bounds = self.rebuild_ty_param_bounds(ty_param.bounds,
lifetime,
region_names);
hir::TyParam {
name: ty_param.name,
id: ty_param.id,
bounds: bounds,
default: ty_param.default.clone(),
default: ty_param.default,
span: ty_param.span,
pure_wrt_drop: ty_param.pure_wrt_drop,
}
}).collect()
}
@ -1295,7 +1296,9 @@ impl<'a, 'gcx, 'tcx> Rebuilder<'a, 'gcx, 'tcx> {
let mut lifetimes = Vec::new();
for lt in add {
lifetimes.push(hir::LifetimeDef { lifetime: *lt,
bounds: hir::HirVec::new() });
bounds: hir::HirVec::new(),
pure_wrt_drop: false,
});
}
for lt in &generics.lifetimes {
if keep.contains(&lt.lifetime.name) ||

View file

@ -680,6 +680,11 @@ pub struct TypeParameterDef<'tcx> {
pub default_def_id: DefId, // for use in error reporing about defaults
pub default: Option<Ty<'tcx>>,
pub object_lifetime_default: ObjectLifetimeDefault<'tcx>,
/// `pure_wrt_drop`, set by the (unsafe) `#[may_dangle]` attribute
/// on generic parameter `T`, asserts data behind the parameter
/// `T` won't be accessed during the parent type's `Drop` impl.
pub pure_wrt_drop: bool,
}
#[derive(Clone, RustcEncodable, RustcDecodable)]
@ -688,6 +693,11 @@ pub struct RegionParameterDef<'tcx> {
pub def_id: DefId,
pub index: u32,
pub bounds: Vec<&'tcx ty::Region>,
/// `pure_wrt_drop`, set by the (unsafe) `#[may_dangle]` attribute
/// on generic parameter `'a`, asserts data of lifetime `'a`
/// won't be accessed during the parent type's `Drop` impl.
pub pure_wrt_drop: bool,
}
impl<'tcx> RegionParameterDef<'tcx> {

View file

@ -716,6 +716,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::TypeParameterDef<'tcx> {
default: self.default.fold_with(folder),
default_def_id: self.default_def_id,
object_lifetime_default: self.object_lifetime_default.fold_with(folder),
pure_wrt_drop: self.pure_wrt_drop,
}
}
@ -754,6 +755,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::RegionParameterDef<'tcx> {
def_id: self.def_id,
index: self.index,
bounds: self.bounds.fold_with(folder),
pure_wrt_drop: self.pure_wrt_drop,
}
}

View file

@ -1482,6 +1482,7 @@ fn generics_of_def_id<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
default_def_id: tcx.map.local_def_id(parent),
default: None,
object_lifetime_default: ty::ObjectLifetimeDefault::BaseDefault,
pure_wrt_drop: false,
};
tcx.ty_param_defs.borrow_mut().insert(param_id, def.clone());
opt_self = Some(def);
@ -1526,7 +1527,8 @@ fn generics_of_def_id<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
def_id: tcx.map.local_def_id(l.lifetime.id),
bounds: l.bounds.iter().map(|l| {
ast_region_to_region(tcx, l)
}).collect()
}).collect(),
pure_wrt_drop: l.pure_wrt_drop,
}
}).collect::<Vec<_>>();
@ -1926,6 +1928,7 @@ fn get_or_create_type_parameter_def<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
default_def_id: ccx.tcx.map.local_def_id(parent),
default: default,
object_lifetime_default: object_lifetime_default,
pure_wrt_drop: param.pure_wrt_drop,
};
if def.name == keywords::SelfType.name() {