Auto merge of #53842 - estebank:various, r=petrochenkov
Various small diagnostic and code clean up - Point at def span on incorrect `panic` or `oom` function - Use structured suggestion instead of note for `+=` that can be performed on a dereference of the left binding - Small code formatting cleanup
This commit is contained in:
commit
a1a8c444f9
7 changed files with 43 additions and 31 deletions
|
@ -542,12 +542,16 @@ fn check_legality_of_move_bindings(cx: &MatchVisitor,
|
||||||
"cannot bind by-move into a pattern guard")
|
"cannot bind by-move into a pattern guard")
|
||||||
.span_label(p.span, "moves value into pattern guard")
|
.span_label(p.span, "moves value into pattern guard")
|
||||||
.emit();
|
.emit();
|
||||||
} else if by_ref_span.is_some() {
|
} else if let Some(by_ref_span) = by_ref_span {
|
||||||
struct_span_err!(cx.tcx.sess, p.span, E0009,
|
struct_span_err!(
|
||||||
"cannot bind by-move and by-ref in the same pattern")
|
cx.tcx.sess,
|
||||||
.span_label(p.span, "by-move pattern here")
|
p.span,
|
||||||
.span_label(by_ref_span.unwrap(), "both by-ref and by-move used")
|
E0009,
|
||||||
.emit();
|
"cannot bind by-move and by-ref in the same pattern",
|
||||||
|
)
|
||||||
|
.span_label(p.span, "by-move pattern here")
|
||||||
|
.span_label(by_ref_span, "both by-ref and by-move used")
|
||||||
|
.emit();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -154,8 +154,7 @@ impl<'a> SpanUtils<'a> {
|
||||||
let loc = self.sess.source_map().lookup_char_pos(span.lo());
|
let loc = self.sess.source_map().lookup_char_pos(span.lo());
|
||||||
span_bug!(
|
span_bug!(
|
||||||
span,
|
span,
|
||||||
"Mis-counted brackets when breaking path? Parsing '{}' \
|
"Mis-counted brackets when breaking path? Parsing '{}' in {}, line {}",
|
||||||
in {}, line {}",
|
|
||||||
self.snippet(span),
|
self.snippet(span),
|
||||||
loc.file.name,
|
loc.file.name,
|
||||||
loc.line
|
loc.line
|
||||||
|
|
|
@ -1178,6 +1178,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
let span = fcx.tcx.sess.source_map().def_span(span);
|
||||||
fcx.tcx.sess.span_err(span, "function should have one argument");
|
fcx.tcx.sess.span_err(span, "function should have one argument");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1226,6 +1227,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
let span = fcx.tcx.sess.source_map().def_span(span);
|
||||||
fcx.tcx.sess.span_err(span, "function should have one argument");
|
fcx.tcx.sess.span_err(span, "function should have one argument");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -256,14 +256,19 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
let source_map = self.tcx.sess.source_map();
|
let source_map = self.tcx.sess.source_map();
|
||||||
match is_assign {
|
match is_assign {
|
||||||
IsAssign::Yes => {
|
IsAssign::Yes => {
|
||||||
let mut err = struct_span_err!(self.tcx.sess, expr.span, E0368,
|
let mut err = struct_span_err!(
|
||||||
"binary assignment operation `{}=` \
|
self.tcx.sess,
|
||||||
cannot be applied to type `{}`",
|
expr.span,
|
||||||
op.node.as_str(),
|
E0368,
|
||||||
lhs_ty);
|
"binary assignment operation `{}=` cannot be applied to type `{}`",
|
||||||
err.span_label(lhs_expr.span,
|
op.node.as_str(),
|
||||||
format!("cannot use `{}=` on type `{}`",
|
lhs_ty,
|
||||||
op.node.as_str(), lhs_ty));
|
);
|
||||||
|
err.span_label(
|
||||||
|
lhs_expr.span,
|
||||||
|
format!("cannot use `{}=` on type `{}`",
|
||||||
|
op.node.as_str(), lhs_ty),
|
||||||
|
);
|
||||||
let mut suggested_deref = false;
|
let mut suggested_deref = false;
|
||||||
if let Ref(_, mut rty, _) = lhs_ty.sty {
|
if let Ref(_, mut rty, _) = lhs_ty.sty {
|
||||||
if {
|
if {
|
||||||
|
@ -280,13 +285,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
rty = rty_inner;
|
rty = rty_inner;
|
||||||
}
|
}
|
||||||
let msg = &format!(
|
let msg = &format!(
|
||||||
"`{}=` can be used on '{}', you can \
|
"`{}=` can be used on '{}', you can dereference `{}`",
|
||||||
dereference `{2}`: `*{2}`",
|
op.node.as_str(),
|
||||||
op.node.as_str(),
|
rty,
|
||||||
rty,
|
lstring,
|
||||||
lstring
|
);
|
||||||
|
err.span_suggestion_with_applicability(
|
||||||
|
lhs_expr.span,
|
||||||
|
msg,
|
||||||
|
format!("*{}", lstring),
|
||||||
|
errors::Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
err.help(msg);
|
|
||||||
suggested_deref = true;
|
suggested_deref = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
error: function should have one argument
|
error: function should have one argument
|
||||||
--> $DIR/alloc-error-handler-bad-signature-3.rs:20:1
|
--> $DIR/alloc-error-handler-bad-signature-3.rs:20:1
|
||||||
|
|
|
|
||||||
LL | / fn oom() -> ! { //~ ERROR function should have one argument
|
LL | fn oom() -> ! { //~ ERROR function should have one argument
|
||||||
LL | | loop {}
|
| ^^^^^^^^^^^^^
|
||||||
LL | | }
|
|
||||||
| |_^
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,10 @@ LL | let x = |ref x: isize| { x += 1; };
|
||||||
| -^^^^^
|
| -^^^^^
|
||||||
| |
|
| |
|
||||||
| cannot use `+=` on type `&isize`
|
| cannot use `+=` on type `&isize`
|
||||||
|
help: `+=` can be used on 'isize', you can dereference `x`
|
||||||
|
|
|
|
||||||
= help: `+=` can be used on 'isize', you can dereference `x`: `*x`
|
LL | let x = |ref x: isize| { *x += 1; };
|
||||||
|
| ^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
error: function should have one argument
|
error: function should have one argument
|
||||||
--> $DIR/panic-handler-bad-signature-3.rs:20:1
|
--> $DIR/panic-handler-bad-signature-3.rs:20:1
|
||||||
|
|
|
|
||||||
LL | / fn panic() -> ! { //~ ERROR function should have one argument
|
LL | fn panic() -> ! { //~ ERROR function should have one argument
|
||||||
LL | | loop {}
|
| ^^^^^^^^^^^^^^^
|
||||||
LL | | }
|
|
||||||
| |_^
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue