Skip to content

Commit

Permalink
Thread pure_wrt_drop field through lifetime and type parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
pnkfelix committed Oct 11, 2016
1 parent 4bb68be commit e8ccc68
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/librustc/hir/lowering.rs
Expand Up @@ -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")),
}
}

Expand All @@ -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")),
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/librustc/hir/mod.rs
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions src/librustc/infer/error_reporting.rs
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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) ||
Expand Down
10 changes: 10 additions & 0 deletions src/librustc/ty/mod.rs
Expand Up @@ -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)]
Expand All @@ -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> {
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/ty/structural_impls.rs
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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,
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/librustc_typeck/collect.rs
Expand Up @@ -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);
Expand Down Expand Up @@ -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<_>>();

Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit e8ccc68

Please sign in to comment.