Skip to content

Commit a1a8c44

Browse files
committed
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
2 parents 28bcffe + 013710e commit a1a8c44

File tree

7 files changed

+43
-31
lines changed

7 files changed

+43
-31
lines changed

src/librustc_mir/hair/pattern/check_match.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -542,12 +542,16 @@ fn check_legality_of_move_bindings(cx: &MatchVisitor,
542542
"cannot bind by-move into a pattern guard")
543543
.span_label(p.span, "moves value into pattern guard")
544544
.emit();
545-
} else if by_ref_span.is_some() {
546-
struct_span_err!(cx.tcx.sess, p.span, E0009,
547-
"cannot bind by-move and by-ref in the same pattern")
548-
.span_label(p.span, "by-move pattern here")
549-
.span_label(by_ref_span.unwrap(), "both by-ref and by-move used")
550-
.emit();
545+
} else if let Some(by_ref_span) = by_ref_span {
546+
struct_span_err!(
547+
cx.tcx.sess,
548+
p.span,
549+
E0009,
550+
"cannot bind by-move and by-ref in the same pattern",
551+
)
552+
.span_label(p.span, "by-move pattern here")
553+
.span_label(by_ref_span, "both by-ref and by-move used")
554+
.emit();
551555
}
552556
};
553557

src/librustc_save_analysis/span_utils.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ impl<'a> SpanUtils<'a> {
154154
let loc = self.sess.source_map().lookup_char_pos(span.lo());
155155
span_bug!(
156156
span,
157-
"Mis-counted brackets when breaking path? Parsing '{}' \
158-
in {}, line {}",
157+
"Mis-counted brackets when breaking path? Parsing '{}' in {}, line {}",
159158
self.snippet(span),
160159
loc.file.name,
161160
loc.line

src/librustc_typeck/check/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
11781178
}
11791179
}
11801180
} else {
1181+
let span = fcx.tcx.sess.source_map().def_span(span);
11811182
fcx.tcx.sess.span_err(span, "function should have one argument");
11821183
}
11831184
} else {
@@ -1226,6 +1227,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
12261227
}
12271228
}
12281229
} else {
1230+
let span = fcx.tcx.sess.source_map().def_span(span);
12291231
fcx.tcx.sess.span_err(span, "function should have one argument");
12301232
}
12311233
} else {

src/librustc_typeck/check/op.rs

+23-14
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,19 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
256256
let source_map = self.tcx.sess.source_map();
257257
match is_assign {
258258
IsAssign::Yes => {
259-
let mut err = struct_span_err!(self.tcx.sess, expr.span, E0368,
260-
"binary assignment operation `{}=` \
261-
cannot be applied to type `{}`",
262-
op.node.as_str(),
263-
lhs_ty);
264-
err.span_label(lhs_expr.span,
265-
format!("cannot use `{}=` on type `{}`",
266-
op.node.as_str(), lhs_ty));
259+
let mut err = struct_span_err!(
260+
self.tcx.sess,
261+
expr.span,
262+
E0368,
263+
"binary assignment operation `{}=` cannot be applied to type `{}`",
264+
op.node.as_str(),
265+
lhs_ty,
266+
);
267+
err.span_label(
268+
lhs_expr.span,
269+
format!("cannot use `{}=` on type `{}`",
270+
op.node.as_str(), lhs_ty),
271+
);
267272
let mut suggested_deref = false;
268273
if let Ref(_, mut rty, _) = lhs_ty.sty {
269274
if {
@@ -280,13 +285,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
280285
rty = rty_inner;
281286
}
282287
let msg = &format!(
283-
"`{}=` can be used on '{}', you can \
284-
dereference `{2}`: `*{2}`",
285-
op.node.as_str(),
286-
rty,
287-
lstring
288+
"`{}=` can be used on '{}', you can dereference `{}`",
289+
op.node.as_str(),
290+
rty,
291+
lstring,
292+
);
293+
err.span_suggestion_with_applicability(
294+
lhs_expr.span,
295+
msg,
296+
format!("*{}", lstring),
297+
errors::Applicability::MachineApplicable,
288298
);
289-
err.help(msg);
290299
suggested_deref = true;
291300
}
292301
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
error: function should have one argument
22
--> $DIR/alloc-error-handler-bad-signature-3.rs:20:1
33
|
4-
LL | / fn oom() -> ! { //~ ERROR function should have one argument
5-
LL | | loop {}
6-
LL | | }
7-
| |_^
4+
LL | fn oom() -> ! { //~ ERROR function should have one argument
5+
| ^^^^^^^^^^^^^
86

97
error: aborting due to previous error
108

src/test/ui/issues/issue-5239-1.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ LL | let x = |ref x: isize| { x += 1; };
55
| -^^^^^
66
| |
77
| cannot use `+=` on type `&isize`
8+
help: `+=` can be used on 'isize', you can dereference `x`
89
|
9-
= help: `+=` can be used on 'isize', you can dereference `x`: `*x`
10+
LL | let x = |ref x: isize| { *x += 1; };
11+
| ^^
1012

1113
error: aborting due to previous error
1214

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
error: function should have one argument
22
--> $DIR/panic-handler-bad-signature-3.rs:20:1
33
|
4-
LL | / fn panic() -> ! { //~ ERROR function should have one argument
5-
LL | | loop {}
6-
LL | | }
7-
| |_^
4+
LL | fn panic() -> ! { //~ ERROR function should have one argument
5+
| ^^^^^^^^^^^^^^^
86

97
error: aborting due to previous error
108

0 commit comments

Comments
 (0)