Skip to content

Commit 4fcaa4a

Browse files
committed
review comments
1 parent 722bb51 commit 4fcaa4a

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

src/librustc/hir/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,13 @@ impl Mutability {
10531053
MutImmutable => MutImmutable,
10541054
}
10551055
}
1056+
1057+
pub fn not(self) -> Self {
1058+
match self {
1059+
MutMutable => MutImmutable,
1060+
MutImmutable => MutMutable,
1061+
}
1062+
}
10561063
}
10571064

10581065
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Hash, HashStable)]

src/librustc_typeck/check/method/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
215215

216216
let mut needs_mut = false;
217217
if let ty::Ref(region, t_type, mutability) = self_ty.kind {
218-
let trait_type = match mutability {
219-
hir::Mutability::MutMutable => self.tcx.mk_imm_ref(region, t_type),
220-
hir::Mutability::MutImmutable => self.tcx.mk_mut_ref(region, t_type),
221-
};
218+
let trait_type = self.tcx.mk_ref(region, ty::TypeAndMut {
219+
ty: t_type,
220+
mutbl: mutability.not(),
221+
});
222222
match self.lookup_probe(
223223
span,
224224
segment.ident,

src/librustc_typeck/check/method/suggest.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -564,24 +564,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
564564
let msg = format!("the `{}` method cannot be invoked on a trait object", item_name);
565565
let mut err = self.sess().struct_span_err(span, &msg);
566566
if !candidates.is_empty() {
567-
let help = format!("{an}other candidate{s} {were} found in the following \
568-
trait{s}, perhaps add a `use` for {one_of_them}:",
569-
an = if candidates.len() == 1 {"an" } else { "" },
570-
s = pluralise!(candidates.len()),
571-
were = if candidates.len() == 1 { "was" } else { "were" },
572-
one_of_them = if candidates.len() == 1 {
573-
"it"
574-
} else {
575-
"one_of_them"
576-
});
567+
let help = format!(
568+
"{an}other candidate{s} {were} found in the following trait{s}, perhaps \
569+
add a `use` for {one_of_them}:",
570+
an = if candidates.len() == 1 {"an" } else { "" },
571+
s = pluralise!(candidates.len()),
572+
were = if candidates.len() == 1 { "was" } else { "were" },
573+
one_of_them = if candidates.len() == 1 {
574+
"it"
575+
} else {
576+
"one_of_them"
577+
},
578+
);
577579
self.suggest_use_candidates(&mut err, help, candidates);
578580
}
579581
if let ty::Ref(region, t_type, mutability) = rcvr_ty.kind {
580-
let trait_type = match mutability {
581-
hir::Mutability::MutMutable => self.tcx.mk_imm_ref(region, t_type),
582-
hir::Mutability::MutImmutable => self.tcx.mk_mut_ref(region, t_type),
583-
};
584582
if needs_mut {
583+
let trait_type = self.tcx.mk_ref(region, ty::TypeAndMut {
584+
ty: t_type,
585+
mutbl: mutability.not(),
586+
});
585587
err.note(&format!("you need `{}` instead of `{}`", trait_type, rcvr_ty));
586588
}
587589
}

0 commit comments

Comments
 (0)