Skip to content

Commit

Permalink
Improve comment phrasing
Browse files Browse the repository at this point in the history
Co-authored-by: oliver <151407407+kwfn@users.noreply.github.com>
  • Loading branch information
sjwang05 and oliver committed Dec 3, 2023
1 parent 32d7890 commit 1091774
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,8 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
&& let hir::Node::Expr(expr) = self.tcx.hir().get(*arg_hir_id)
&& let Some(arg_ty) = typeck_results.expr_ty_adjusted_opt(expr)
{
// Suggest dereferencing the argument to a function/method call if possible

let mut real_trait_pred = trait_pred;
while let Some((parent_code, parent_trait_pred)) = code.parent() {
code = parent_code;
Expand Down Expand Up @@ -763,7 +765,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
{
if steps > 0 {
// Don't care about `&mut` because `DerefMut` is used less
// often and user will not expect autoderef happens.
// often and user will not expect that an autoderef happens.
if let Some(hir::Node::Expr(hir::Expr {
kind:
hir::ExprKind::AddrOf(
Expand Down Expand Up @@ -850,6 +852,8 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
&& let hir::Node::Expr(rhs) = self.tcx.hir().get(*rhs_hir_id)
&& let Some(rhs_ty) = typeck_results.expr_ty_opt(rhs)
{
// Suggest dereferencing the LHS, RHS, or both terms of a binop if possible

let trait_pred = predicate.unwrap_or(trait_pred);
let lhs_ty = self.tcx.instantiate_bound_regions_with_erased(trait_pred.self_ty());
let lhs_autoderef = (self.autoderef_steps)(lhs_ty);
Expand All @@ -869,6 +873,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
.rev();
if let Some((lsteps, rsteps)) =
autoderefs.find_map(|((lsteps, (l_ty, _)), (rsteps, (r_ty, _)))| {
// Create a new predicate with the dereferenced LHS and RHS
// We simultaneously dereference both sides rather than doing them
// one at a time to account for cases such as &Box<T> == &&T
let trait_pred_and_ty = trait_pred.map_bound(|inner| {
(
ty::TraitPredicate {
Expand Down Expand Up @@ -909,6 +916,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
expr = inner;
steps -= 1;
}
// Empty suggestions with empty spans ICE with debug assertions
if steps == 0 {
return (
msg.trim_end_matches(" and dereferencing instead"),
Expand Down Expand Up @@ -936,6 +944,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
format!("{derefs}"),
)]
};
// Empty suggestions with empty spans ICE with debug assertions
if !prefix_span.is_empty() {
suggestion.push((prefix_span, String::new()));
}
Expand Down

0 comments on commit 1091774

Please sign in to comment.