Skip to content

Commit e8ccc68

Browse files
committed
Thread pure_wrt_drop field through lifetime and type parameters.
1 parent 4bb68be commit e8ccc68

File tree

6 files changed

+27
-5
lines changed

6 files changed

+27
-5
lines changed

src/librustc/hir/lowering.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ impl<'a> LoweringContext<'a> {
408408
bounds: self.lower_bounds(&tp.bounds),
409409
default: tp.default.as_ref().map(|x| self.lower_ty(x)),
410410
span: tp.span,
411+
pure_wrt_drop: tp.attrs.iter().any(|attr| attr.check_name("may_dangle")),
411412
}
412413
}
413414

@@ -427,6 +428,7 @@ impl<'a> LoweringContext<'a> {
427428
hir::LifetimeDef {
428429
lifetime: self.lower_lifetime(&l.lifetime),
429430
bounds: self.lower_lifetimes(&l.bounds),
431+
pure_wrt_drop: l.attrs.iter().any(|attr| attr.check_name("may_dangle")),
430432
}
431433
}
432434

src/librustc/hir/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ impl fmt::Debug for Lifetime {
9595
pub struct LifetimeDef {
9696
pub lifetime: Lifetime,
9797
pub bounds: HirVec<Lifetime>,
98+
pub pure_wrt_drop: bool,
9899
}
99100

100101
/// A "Path" is essentially Rust's notion of a name; for instance:
@@ -290,6 +291,7 @@ pub struct TyParam {
290291
pub bounds: TyParamBounds,
291292
pub default: Option<P<Ty>>,
292293
pub span: Span,
294+
pub pure_wrt_drop: bool,
293295
}
294296

295297
/// Represents lifetimes and type parameters attached to a declaration

src/librustc/infer/error_reporting.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,16 +1226,17 @@ impl<'a, 'gcx, 'tcx> Rebuilder<'a, 'gcx, 'tcx> {
12261226
lifetime: hir::Lifetime,
12271227
region_names: &HashSet<ast::Name>)
12281228
-> hir::HirVec<hir::TyParam> {
1229-
ty_params.iter().map(|ty_param| {
1230-
let bounds = self.rebuild_ty_param_bounds(ty_param.bounds.clone(),
1229+
ty_params.into_iter().map(|ty_param| {
1230+
let bounds = self.rebuild_ty_param_bounds(ty_param.bounds,
12311231
lifetime,
12321232
region_names);
12331233
hir::TyParam {
12341234
name: ty_param.name,
12351235
id: ty_param.id,
12361236
bounds: bounds,
1237-
default: ty_param.default.clone(),
1237+
default: ty_param.default,
12381238
span: ty_param.span,
1239+
pure_wrt_drop: ty_param.pure_wrt_drop,
12391240
}
12401241
}).collect()
12411242
}
@@ -1295,7 +1296,9 @@ impl<'a, 'gcx, 'tcx> Rebuilder<'a, 'gcx, 'tcx> {
12951296
let mut lifetimes = Vec::new();
12961297
for lt in add {
12971298
lifetimes.push(hir::LifetimeDef { lifetime: *lt,
1298-
bounds: hir::HirVec::new() });
1299+
bounds: hir::HirVec::new(),
1300+
pure_wrt_drop: false,
1301+
});
12991302
}
13001303
for lt in &generics.lifetimes {
13011304
if keep.contains(&lt.lifetime.name) ||

src/librustc/ty/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,11 @@ pub struct TypeParameterDef<'tcx> {
680680
pub default_def_id: DefId, // for use in error reporing about defaults
681681
pub default: Option<Ty<'tcx>>,
682682
pub object_lifetime_default: ObjectLifetimeDefault<'tcx>,
683+
684+
/// `pure_wrt_drop`, set by the (unsafe) `#[may_dangle]` attribute
685+
/// on generic parameter `T`, asserts data behind the parameter
686+
/// `T` won't be accessed during the parent type's `Drop` impl.
687+
pub pure_wrt_drop: bool,
683688
}
684689

685690
#[derive(Clone, RustcEncodable, RustcDecodable)]
@@ -688,6 +693,11 @@ pub struct RegionParameterDef<'tcx> {
688693
pub def_id: DefId,
689694
pub index: u32,
690695
pub bounds: Vec<&'tcx ty::Region>,
696+
697+
/// `pure_wrt_drop`, set by the (unsafe) `#[may_dangle]` attribute
698+
/// on generic parameter `'a`, asserts data of lifetime `'a`
699+
/// won't be accessed during the parent type's `Drop` impl.
700+
pub pure_wrt_drop: bool,
691701
}
692702

693703
impl<'tcx> RegionParameterDef<'tcx> {

src/librustc/ty/structural_impls.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::TypeParameterDef<'tcx> {
716716
default: self.default.fold_with(folder),
717717
default_def_id: self.default_def_id,
718718
object_lifetime_default: self.object_lifetime_default.fold_with(folder),
719+
pure_wrt_drop: self.pure_wrt_drop,
719720
}
720721
}
721722

@@ -754,6 +755,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::RegionParameterDef<'tcx> {
754755
def_id: self.def_id,
755756
index: self.index,
756757
bounds: self.bounds.fold_with(folder),
758+
pure_wrt_drop: self.pure_wrt_drop,
757759
}
758760
}
759761

src/librustc_typeck/collect.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,7 @@ fn generics_of_def_id<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
14821482
default_def_id: tcx.map.local_def_id(parent),
14831483
default: None,
14841484
object_lifetime_default: ty::ObjectLifetimeDefault::BaseDefault,
1485+
pure_wrt_drop: false,
14851486
};
14861487
tcx.ty_param_defs.borrow_mut().insert(param_id, def.clone());
14871488
opt_self = Some(def);
@@ -1526,7 +1527,8 @@ fn generics_of_def_id<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
15261527
def_id: tcx.map.local_def_id(l.lifetime.id),
15271528
bounds: l.bounds.iter().map(|l| {
15281529
ast_region_to_region(tcx, l)
1529-
}).collect()
1530+
}).collect(),
1531+
pure_wrt_drop: l.pure_wrt_drop,
15301532
}
15311533
}).collect::<Vec<_>>();
15321534

@@ -1926,6 +1928,7 @@ fn get_or_create_type_parameter_def<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
19261928
default_def_id: ccx.tcx.map.local_def_id(parent),
19271929
default: default,
19281930
object_lifetime_default: object_lifetime_default,
1931+
pure_wrt_drop: param.pure_wrt_drop,
19291932
};
19301933

19311934
if def.name == keywords::SelfType.name() {

0 commit comments

Comments
 (0)