Skip to content

Commit 297dde9

Browse files
committed
Less manipulation of the callee_def_id.
1 parent 2d3d9b2 commit 297dde9

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

compiler/rustc_mir_transform/src/inline.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ impl<'tcx> Inliner<'tcx> {
176176
callee: &Instance<'tcx>,
177177
) -> Result<(), &'static str> {
178178
let caller_def_id = caller_body.source.def_id();
179-
if callee.def_id() == caller_def_id {
179+
let callee_def_id = callee.def_id();
180+
if callee_def_id == caller_def_id {
180181
return Err("self-recursion");
181182
}
182183

@@ -185,7 +186,7 @@ impl<'tcx> Inliner<'tcx> {
185186
// If there is no MIR available (either because it was not in metadata or
186187
// because it has no MIR because it's an extern function), then the inliner
187188
// won't cause cycles on this.
188-
if !self.tcx.is_mir_available(callee.def_id()) {
189+
if !self.tcx.is_mir_available(callee_def_id) {
189190
return Err("item MIR unavailable");
190191
}
191192
}
@@ -205,19 +206,19 @@ impl<'tcx> Inliner<'tcx> {
205206
| InstanceDef::CloneShim(..) => return Ok(()),
206207
}
207208

208-
if self.tcx.is_constructor(callee.def_id()) {
209+
if self.tcx.is_constructor(callee_def_id) {
209210
trace!("constructors always have MIR");
210211
// Constructor functions cannot cause a query cycle.
211212
return Ok(());
212213
}
213214

214-
if let Some(callee_def_id) = callee.def_id().as_local() {
215+
if callee_def_id.is_local() {
215216
// Avoid a cycle here by only using `instance_mir` only if we have
216217
// a lower `DefPathHash` than the callee. This ensures that the callee will
217218
// not inline us. This trick even works with incremental compilation,
218219
// since `DefPathHash` is stable.
219220
if self.tcx.def_path_hash(caller_def_id).local_hash()
220-
< self.tcx.def_path_hash(callee_def_id.to_def_id()).local_hash()
221+
< self.tcx.def_path_hash(callee_def_id).local_hash()
221222
{
222223
return Ok(());
223224
}

0 commit comments

Comments
 (0)