Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Oct 5, 2019
1 parent 35a3b58 commit 169b040
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
7 changes: 7 additions & 0 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_typeck/check/method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
30 changes: 16 additions & 14 deletions src/librustc_typeck/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,24 +557,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));
}
}
Expand Down

0 comments on commit 169b040

Please sign in to comment.