change span_notes to notes in E0368/E0369

This commit is contained in:
Alex Burka 2017-02-09 20:37:59 +00:00
parent e7fc53b8f0
commit 9fffd14171
4 changed files with 13 additions and 52 deletions

View File

@ -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()));
}
@ -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();
@ -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),

View File

@ -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);

View File

@ -1,28 +0,0 @@
error[E0369]: binary operation `+` cannot be applied to type `&'static str`
--> src/test/ui/span/issue-39018.rs:2:13
|
2 | let x = "Hello " + "World!";
| ^^^^^^^^
|
note: `+` can't be used to concatenate two `&str` strings
--> src/test/ui/span/issue-39018.rs:2:13
|
2 | let x = "Hello " + "World!";
| ^^^^^^^^
help: to_owned() can be used to create an owned `String` from a string reference. This allows concatenation since the `String` is owned.
| let x = "Hello ".to_owned() + "World!";
error[E0369]: binary operation `+` cannot be applied to type `World`
--> src/test/ui/span/issue-39018.rs:7:13
|
7 | let y = World::Hello + World::Goodbye;
| ^^^^^^^^^^^^
|
note: an implementation of `std::ops::Add` might be missing for `World`
--> src/test/ui/span/issue-39018.rs:7:13
|
7 | let y = World::Hello + World::Goodbye;
| ^^^^^^^^^^^^
error: aborting due to 2 previous errors

View File

@ -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!";
@ -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