Skip to content

Commit 5bb0a03

Browse files
committed
Move diagnostics code out of the critical path
1 parent 898f36c commit 5bb0a03

File tree

1 file changed

+19
-18
lines changed
  • src/librustc_typeck/check/method

1 file changed

+19
-18
lines changed

src/librustc_typeck/check/method/mod.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -213,27 +213,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
213213
segment,
214214
);
215215

216-
let mut needs_mut = false;
217-
if let ty::Ref(region, t_type, mutability) = self_ty.kind {
218-
let trait_type = self.tcx.mk_ref(region, ty::TypeAndMut {
219-
ty: t_type,
220-
mutbl: mutability.invert(),
221-
});
222-
match self.lookup_probe(
223-
span,
224-
segment.ident,
225-
trait_type,
226-
call_expr,
227-
ProbeScope::TraitsInScope
228-
) {
229-
Ok(ref new_pick) if *new_pick != pick => {
230-
needs_mut = true;
216+
if result.illegal_sized_bound {
217+
let mut needs_mut = false;
218+
if let ty::Ref(region, t_type, mutability) = self_ty.kind {
219+
let trait_type = self.tcx.mk_ref(region, ty::TypeAndMut {
220+
ty: t_type,
221+
mutbl: mutability.invert(),
222+
});
223+
// We probe again to see if there might be a borrow mutability discrepancy.
224+
match self.lookup_probe(
225+
span,
226+
segment.ident,
227+
trait_type,
228+
call_expr,
229+
ProbeScope::TraitsInScope
230+
) {
231+
Ok(ref new_pick) if *new_pick != pick => {
232+
needs_mut = true;
233+
}
234+
_ => {}
231235
}
232-
_ => {}
233236
}
234-
}
235237

236-
if result.illegal_sized_bound {
237238
// We probe again, taking all traits into account (not only those in scope).
238239
let candidates = match self.lookup_probe(
239240
span,

0 commit comments

Comments
 (0)