Skip to content

Commit

Permalink
Rollup merge of rust-lang#39707 - durka:parsimonious-span-note, r=jon…
Browse files Browse the repository at this point in the history
…athandturner

change span_notes to notes in E0368/E0369

Fixes rust-lang#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
  • Loading branch information
frewsxcv authored Feb 10, 2017
2 parents 3199b24 + 9fffd14 commit 84ad515
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 52 deletions.
23 changes: 10 additions & 13 deletions src/librustc_typeck/check/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
self.lookup_op_method(expr, ty_mut.ty, vec![rhs_ty_var],
Symbol::intern(name), trait_def_id,
lhs_expr).is_ok() {
err.span_note(
lhs_expr.span,
err.note(
&format!(
"this is a reference of type that `{}` can be applied to, \
you need to dereference this variable once for this \
"this is a reference to a type that `{}` can be applied \
to; you need to dereference this variable once for this \
operation to work",
op.node.as_str()));
}
Expand Down Expand Up @@ -244,11 +243,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
rhs_expr, rhs_ty_var, &mut err) {
// This has nothing here because it means we did string
// concatenation (e.g. "Hello " + "World!"). This means
// we don't want the span in the else clause to be emmitted
// we don't want the note in the else clause to be emitted
} else {
span_note!(&mut err, lhs_expr.span,
"an implementation of `{}` might be missing for `{}`",
missing_trait, lhs_ty);
err.note(
&format!("an implementation of `{}` might be missing for `{}`",
missing_trait, lhs_ty));
}
}
err.emit();
Expand All @@ -271,16 +270,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
rhs_expr: &'gcx hir::Expr,
rhs_ty_var: Ty<'tcx>,
mut err: &mut errors::DiagnosticBuilder) -> bool {
// If this function returns false it means we use it to make sure we print
// out the an "implementation of span_note!" above where this function is
// called and if true we don't.
// If this function returns true it means a note was printed, so we don't need
// to print the normal "implementation of `std::ops::Add` might be missing" note
let mut is_string_addition = false;
let rhs_ty = self.check_expr_coercable_to_type(rhs_expr, rhs_ty_var);
if let TyRef(_, l_ty) = lhs_ty.sty {
if let TyRef(_, r_ty) = rhs_ty.sty {
if l_ty.ty.sty == TyStr && r_ty.ty.sty == TyStr {
span_note!(&mut err, lhs_expr.span,
"`+` can't be used to concatenate two `&str` strings");
err.note("`+` can't be used to concatenate two `&str` strings");
let codemap = self.tcx.sess.codemap();
let suggestion =
match (codemap.span_to_snippet(lhs_expr.span),
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/binary-op-on-double-ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn main() {
let vr = v.iter().filter(|x| {
x % 2 == 0
//~^ ERROR binary operation `%` cannot be applied to type `&&{integer}`
//~| NOTE this is a reference of type that `%` can be applied to
//~| NOTE this is a reference to a type that `%` can be applied to
//~| NOTE an implementation of `std::ops::Rem` might be missing for `&&{integer}`
});
println!("{:?}", vr);
Expand Down
28 changes: 0 additions & 28 deletions src/test/parse-fail/issue-39018.stderr

This file was deleted.

12 changes: 2 additions & 10 deletions src/test/ui/span/issue-39018.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&'static str`
12 | let x = "Hello " + "World!";
| ^^^^^^^^
|
note: `+` can't be used to concatenate two `&str` strings
--> $DIR/issue-39018.rs:12:13
|
12 | let x = "Hello " + "World!";
| ^^^^^^^^
= note: `+` can't be used to concatenate two `&str` strings
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.
| let x = "Hello ".to_owned() + "World!";

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

error: aborting due to 2 previous errors

0 comments on commit 84ad515

Please sign in to comment.