Skip to content

Commit dfbb6e8

Browse files
MaikKleinarielb1
authored andcommitted
Move instance related methods from TyCtxt to Instance
1 parent d3c4142 commit dfbb6e8

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/librustc/ty/instance.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,42 @@ impl<'tcx> InstanceDef<'tcx> {
7777
pub fn attrs<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> ty::Attributes<'tcx> {
7878
tcx.get_attrs(self.def_id())
7979
}
80+
81+
pub fn is_inline<'a>(
82+
&self,
83+
tcx: TyCtxt<'a, 'tcx, 'tcx>
84+
) -> bool {
85+
use hir::map::DefPathData;
86+
let def_id = match *self {
87+
ty::InstanceDef::Item(def_id) => def_id,
88+
ty::InstanceDef::DropGlue(_, Some(_)) => return false,
89+
_ => return true
90+
};
91+
match tcx.def_key(def_id).disambiguated_data.data {
92+
DefPathData::StructCtor |
93+
DefPathData::EnumVariant(..) |
94+
DefPathData::ClosureExpr => true,
95+
_ => false
96+
}
97+
}
98+
99+
pub fn requires_local<'a>(
100+
&self,
101+
tcx: TyCtxt<'a, 'tcx, 'tcx>
102+
) -> bool {
103+
use syntax::attr::requests_inline;
104+
if self.is_inline(tcx) {
105+
return true
106+
}
107+
if let ty::InstanceDef::DropGlue(..) = *self {
108+
// Drop glue wants to be instantiated at every translation
109+
// unit, but without an #[inline] hint. We should make this
110+
// available to normal end-users.
111+
return true
112+
}
113+
requests_inline(&self.attrs(tcx)[..]) ||
114+
tcx.is_const_fn(self.def_id())
115+
}
80116
}
81117

82118
impl<'tcx> fmt::Display for Instance<'tcx> {

src/librustc_mir/monomorphize/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub trait MonoItemExt<'a, 'tcx>: fmt::Debug {
9696
// If this function isn't inlined or otherwise has explicit
9797
// linkage, then we'll be creating a globally shared version.
9898
if self.explicit_linkage(tcx).is_some() ||
99-
!tcx.requires_local_instance(instance)
99+
!instance.def.requires_local(tcx)
100100
{
101101
return InstantiationMode::GloballyShared { may_conflict: false }
102102
}

0 commit comments

Comments
 (0)