Skip to content

Commit 84ad515

Browse files
authored
Rollup merge of #39707 - durka:parsimonious-span-note, r=jonathandturner
change span_notes to notes in E0368/E0369 Fixes #39650. All the uses of `span_note` in these errors were reusing the same span as the original error, which causes unnecessary repetition. For an example, see the changes to [src/test/ui/span/issue-39018.stderr](https://github.com/rust-lang/rust/pull/39707/files?diff=unified#diff-46336f62958fdb34233db414cb9914a1R4). r? @jonathandturner
2 parents 3199b24 + 9fffd14 commit 84ad515

File tree

4 files changed

+13
-52
lines changed

4 files changed

+13
-52
lines changed

src/librustc_typeck/check/op.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
212212
self.lookup_op_method(expr, ty_mut.ty, vec![rhs_ty_var],
213213
Symbol::intern(name), trait_def_id,
214214
lhs_expr).is_ok() {
215-
err.span_note(
216-
lhs_expr.span,
215+
err.note(
217216
&format!(
218-
"this is a reference of type that `{}` can be applied to, \
219-
you need to dereference this variable once for this \
217+
"this is a reference to a type that `{}` can be applied \
218+
to; you need to dereference this variable once for this \
220219
operation to work",
221220
op.node.as_str()));
222221
}
@@ -244,11 +243,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
244243
rhs_expr, rhs_ty_var, &mut err) {
245244
// This has nothing here because it means we did string
246245
// concatenation (e.g. "Hello " + "World!"). This means
247-
// we don't want the span in the else clause to be emmitted
246+
// we don't want the note in the else clause to be emitted
248247
} else {
249-
span_note!(&mut err, lhs_expr.span,
250-
"an implementation of `{}` might be missing for `{}`",
251-
missing_trait, lhs_ty);
248+
err.note(
249+
&format!("an implementation of `{}` might be missing for `{}`",
250+
missing_trait, lhs_ty));
252251
}
253252
}
254253
err.emit();
@@ -271,16 +270,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
271270
rhs_expr: &'gcx hir::Expr,
272271
rhs_ty_var: Ty<'tcx>,
273272
mut err: &mut errors::DiagnosticBuilder) -> bool {
274-
// If this function returns false it means we use it to make sure we print
275-
// out the an "implementation of span_note!" above where this function is
276-
// called and if true we don't.
273+
// If this function returns true it means a note was printed, so we don't need
274+
// to print the normal "implementation of `std::ops::Add` might be missing" note
277275
let mut is_string_addition = false;
278276
let rhs_ty = self.check_expr_coercable_to_type(rhs_expr, rhs_ty_var);
279277
if let TyRef(_, l_ty) = lhs_ty.sty {
280278
if let TyRef(_, r_ty) = rhs_ty.sty {
281279
if l_ty.ty.sty == TyStr && r_ty.ty.sty == TyStr {
282-
span_note!(&mut err, lhs_expr.span,
283-
"`+` can't be used to concatenate two `&str` strings");
280+
err.note("`+` can't be used to concatenate two `&str` strings");
284281
let codemap = self.tcx.sess.codemap();
285282
let suggestion =
286283
match (codemap.span_to_snippet(lhs_expr.span),

src/test/compile-fail/binary-op-on-double-ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn main() {
1313
let vr = v.iter().filter(|x| {
1414
x % 2 == 0
1515
//~^ ERROR binary operation `%` cannot be applied to type `&&{integer}`
16-
//~| NOTE this is a reference of type that `%` can be applied to
16+
//~| NOTE this is a reference to a type that `%` can be applied to
1717
//~| NOTE an implementation of `std::ops::Rem` might be missing for `&&{integer}`
1818
});
1919
println!("{:?}", vr);

src/test/parse-fail/issue-39018.stderr

-28
This file was deleted.

src/test/ui/span/issue-39018.stderr

+2-10
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&'static str`
44
12 | let x = "Hello " + "World!";
55
| ^^^^^^^^
66
|
7-
note: `+` can't be used to concatenate two `&str` strings
8-
--> $DIR/issue-39018.rs:12:13
9-
|
10-
12 | let x = "Hello " + "World!";
11-
| ^^^^^^^^
7+
= note: `+` can't be used to concatenate two `&str` strings
128
help: to_owned() can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left.
139
| let x = "Hello ".to_owned() + "World!";
1410

@@ -18,11 +14,7 @@ error[E0369]: binary operation `+` cannot be applied to type `World`
1814
17 | let y = World::Hello + World::Goodbye;
1915
| ^^^^^^^^^^^^
2016
|
21-
note: an implementation of `std::ops::Add` might be missing for `World`
22-
--> $DIR/issue-39018.rs:17:13
23-
|
24-
17 | let y = World::Hello + World::Goodbye;
25-
| ^^^^^^^^^^^^
17+
= note: an implementation of `std::ops::Add` might be missing for `World`
2618

2719
error: aborting due to 2 previous errors
2820

0 commit comments

Comments
 (0)