review comments
This commit is contained in:
parent
722bb515e2
commit
4fcaa4a283
3 changed files with 27 additions and 18 deletions
|
|
@ -1053,6 +1053,13 @@ impl Mutability {
|
|||
MutImmutable => MutImmutable,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn not(self) -> Self {
|
||||
match self {
|
||||
MutMutable => MutImmutable,
|
||||
MutImmutable => MutMutable,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Hash, HashStable)]
|
||||
|
|
|
|||
|
|
@ -215,10 +215,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
|
||||
let mut needs_mut = false;
|
||||
if let ty::Ref(region, t_type, mutability) = self_ty.kind {
|
||||
let trait_type = match mutability {
|
||||
hir::Mutability::MutMutable => self.tcx.mk_imm_ref(region, t_type),
|
||||
hir::Mutability::MutImmutable => self.tcx.mk_mut_ref(region, t_type),
|
||||
};
|
||||
let trait_type = self.tcx.mk_ref(region, ty::TypeAndMut {
|
||||
ty: t_type,
|
||||
mutbl: mutability.not(),
|
||||
});
|
||||
match self.lookup_probe(
|
||||
span,
|
||||
segment.ident,
|
||||
|
|
|
|||
|
|
@ -564,24 +564,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
let msg = format!("the `{}` method cannot be invoked on a trait object", item_name);
|
||||
let mut err = self.sess().struct_span_err(span, &msg);
|
||||
if !candidates.is_empty() {
|
||||
let help = format!("{an}other candidate{s} {were} found in the following \
|
||||
trait{s}, perhaps add a `use` for {one_of_them}:",
|
||||
an = if candidates.len() == 1 {"an" } else { "" },
|
||||
s = pluralise!(candidates.len()),
|
||||
were = if candidates.len() == 1 { "was" } else { "were" },
|
||||
one_of_them = if candidates.len() == 1 {
|
||||
"it"
|
||||
} else {
|
||||
"one_of_them"
|
||||
});
|
||||
let help = format!(
|
||||
"{an}other candidate{s} {were} found in the following trait{s}, perhaps \
|
||||
add a `use` for {one_of_them}:",
|
||||
an = if candidates.len() == 1 {"an" } else { "" },
|
||||
s = pluralise!(candidates.len()),
|
||||
were = if candidates.len() == 1 { "was" } else { "were" },
|
||||
one_of_them = if candidates.len() == 1 {
|
||||
"it"
|
||||
} else {
|
||||
"one_of_them"
|
||||
},
|
||||
);
|
||||
self.suggest_use_candidates(&mut err, help, candidates);
|
||||
}
|
||||
if let ty::Ref(region, t_type, mutability) = rcvr_ty.kind {
|
||||
let trait_type = match mutability {
|
||||
hir::Mutability::MutMutable => self.tcx.mk_imm_ref(region, t_type),
|
||||
hir::Mutability::MutImmutable => self.tcx.mk_mut_ref(region, t_type),
|
||||
};
|
||||
if needs_mut {
|
||||
let trait_type = self.tcx.mk_ref(region, ty::TypeAndMut {
|
||||
ty: t_type,
|
||||
mutbl: mutability.not(),
|
||||
});
|
||||
err.note(&format!("you need `{}` instead of `{}`", trait_type, rcvr_ty));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue