Skip to content

Commit e2640a5

Browse files
committed
typeck: use .peel_refs() more.
1 parent 50a0ec9 commit e2640a5

File tree

1 file changed

+10
-17
lines changed
  • src/librustc_typeck/check

1 file changed

+10
-17
lines changed

src/librustc_typeck/check/op.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
268268
op.node.as_str(), lhs_ty),
269269
);
270270
let mut suggested_deref = false;
271-
if let Ref(_, mut rty, _) = lhs_ty.sty {
271+
if let Ref(_, rty, _) = lhs_ty.sty {
272272
if {
273273
self.infcx.type_is_copy_modulo_regions(self.param_env,
274274
rty,
@@ -279,13 +279,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
279279
.is_ok()
280280
} {
281281
if let Ok(lstring) = source_map.span_to_snippet(lhs_expr.span) {
282-
while let Ref(_, rty_inner, _) = rty.sty {
283-
rty = rty_inner;
284-
}
285282
let msg = &format!(
286283
"`{}=` can be used on '{}', you can dereference `{}`",
287284
op.node.as_str(),
288-
rty,
285+
rty.peel_refs(),
289286
lstring,
290287
);
291288
err.span_suggestion(
@@ -361,7 +358,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
361358
}
362359

363360
let mut suggested_deref = false;
364-
if let Ref(_, mut rty, _) = lhs_ty.sty {
361+
if let Ref(_, rty, _) = lhs_ty.sty {
365362
if {
366363
self.infcx.type_is_copy_modulo_regions(self.param_env,
367364
rty,
@@ -372,17 +369,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
372369
.is_ok()
373370
} {
374371
if let Ok(lstring) = source_map.span_to_snippet(lhs_expr.span) {
375-
while let Ref(_, rty_inner, _) = rty.sty {
376-
rty = rty_inner;
377-
}
378-
let msg = &format!(
379-
"`{}` can be used on '{}', you can \
380-
dereference `{2}`: `*{2}`",
381-
op.node.as_str(),
382-
rty,
383-
lstring
384-
);
385-
err.help(msg);
372+
err.help(&format!(
373+
"`{}` can be used on '{}', you can \
374+
dereference `{2}`: `*{2}`",
375+
op.node.as_str(),
376+
rty.peel_refs(),
377+
lstring
378+
));
386379
suggested_deref = true;
387380
}
388381
}

0 commit comments

Comments
 (0)