Skip to content

Commit

Permalink
Add new error codes and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed May 27, 2017
1 parent 8be89f5 commit 998b197
Show file tree
Hide file tree
Showing 72 changed files with 180 additions and 167 deletions.
27 changes: 15 additions & 12 deletions src/librustc_typeck/check/method/suggest.rs
Expand Up @@ -165,18 +165,21 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
.. }) => {
let tcx = self.tcx;

let mut err = self.type_error_struct(span,
|actual| {
format!("no {} named `{}` found for type `{}` in the current scope",
if mode == Mode::MethodCall {
"method"
} else {
"associated item"
},
item_name,
actual)
},
rcvr_ty);
let actual = self.resolve_type_vars_if_possible(&rcvr_ty);
let mut err = if !actual.references_error() {
struct_span_err!(tcx.sess, span, E0599,
"no {} named `{}` found for type `{}` in the \
current scope",
if mode == Mode::MethodCall {
"method"
} else {
"associated item"
},
item_name,
self.ty_to_string(actual))
} else {
self.tcx.sess.diagnostic().struct_dummy()
};

// If the method name is the name of a field with a function or closure type,
// give a helping note that it has to be called as (x.f)(...).
Expand Down
12 changes: 11 additions & 1 deletion src/librustc_typeck/diagnostics.rs
Expand Up @@ -4005,7 +4005,7 @@ details.
[issue #33685]: https://github.com/rust-lang/rust/issues/33685
"##,

E0582: r##"
E0582: r##"
A lifetime appears only in an associated-type binding,
and not in the input types to the trait.
Expand Down Expand Up @@ -4042,6 +4042,16 @@ details.
[issue #33685]: https://github.com/rust-lang/rust/issues/33685
"##,

E0599: r##"
```compile_fail,E0599
struct Mouth;
let x = Mouth;
x.chocolate(); // error: no method named `chocolate` found for type `Mouth`
// in the current scope
```
"##,

}

register_diagnostics! {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/codemap_tests/huge_multispan_highlight.stderr
@@ -1,4 +1,4 @@
error: cannot borrow immutable local variable `x` as mutable
error[E0596]: cannot borrow immutable local variable `x` as mutable
--> $DIR/huge_multispan_highlight.rs:100:18
|
12 | let x = "foo";
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/did_you_mean/issue-31424.stderr
@@ -1,4 +1,4 @@
error: cannot borrow immutable argument `self` as mutable
error[E0596]: cannot borrow immutable argument `self` as mutable
--> $DIR/issue-31424.rs:17:15
|
17 | (&mut self).bar();
Expand All @@ -7,7 +7,7 @@ error: cannot borrow immutable argument `self` as mutable
| try removing `&mut` here
| cannot reborrow mutably

error: cannot borrow immutable argument `self` as mutable
error[E0596]: cannot borrow immutable argument `self` as mutable
--> $DIR/issue-31424.rs:23:15
|
22 | fn bar(self: &mut Self) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/did_you_mean/issue-34126.stderr
@@ -1,4 +1,4 @@
error: cannot borrow immutable argument `self` as mutable
error[E0596]: cannot borrow immutable argument `self` as mutable
--> $DIR/issue-34126.rs:16:23
|
16 | self.run(&mut self);
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/did_you_mean/issue-34337.stderr
@@ -1,4 +1,4 @@
error: cannot borrow immutable local variable `key` as mutable
error[E0596]: cannot borrow immutable local variable `key` as mutable
--> $DIR/issue-34337.rs:16:14
|
16 | get(&mut key);
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/did_you_mean/issue-35937.stderr
@@ -1,20 +1,20 @@
error: cannot borrow immutable field `f.v` as mutable
error[E0596]: cannot borrow immutable field `f.v` as mutable
--> $DIR/issue-35937.rs:17:5
|
16 | let f = Foo { v: Vec::new() };
| - consider changing this to `mut f`
17 | f.v.push("cat".to_string());
| ^^^ cannot mutably borrow immutable field

error: cannot assign to immutable field `s.x`
error[E0594]: cannot assign to immutable field `s.x`
--> $DIR/issue-35937.rs:26:5
|
25 | let s = S { x: 42 };
| - consider changing this to `mut s`
26 | s.x += 1;
| ^^^^^^^^ cannot mutably borrow immutable field

error: cannot assign to immutable field `s.x`
error[E0594]: cannot assign to immutable field `s.x`
--> $DIR/issue-35937.rs:30:5
|
29 | fn bar(s: S) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/did_you_mean/issue-37139.stderr
@@ -1,4 +1,4 @@
error: cannot borrow immutable local variable `x` as mutable
error[E0596]: cannot borrow immutable local variable `x` as mutable
--> $DIR/issue-37139.rs:22:23
|
22 | test(&mut x);
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/did_you_mean/issue-38147-2.stderr
@@ -1,4 +1,4 @@
error: cannot borrow immutable borrowed content `*self.s` as mutable
error[E0596]: cannot borrow immutable borrowed content `*self.s` as mutable
--> $DIR/issue-38147-2.rs:17:9
|
12 | s: &'a String
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/did_you_mean/issue-38147-3.stderr
@@ -1,4 +1,4 @@
error: cannot borrow immutable borrowed content `*self.s` as mutable
error[E0596]: cannot borrow immutable borrowed content `*self.s` as mutable
--> $DIR/issue-38147-3.rs:17:9
|
12 | s: &'a String
Expand Down
24 changes: 12 additions & 12 deletions src/test/ui/did_you_mean/issue-39544.stderr
@@ -1,28 +1,28 @@
error: cannot borrow immutable field `z.x` as mutable
error[E0596]: cannot borrow immutable field `z.x` as mutable
--> $DIR/issue-39544.rs:21:18
|
20 | let z = Z { x: X::Y };
| - consider changing this to `mut z`
21 | let _ = &mut z.x;
| ^^^ cannot mutably borrow immutable field

error: cannot borrow immutable field `self.x` as mutable
error[E0596]: cannot borrow immutable field `self.x` as mutable
--> $DIR/issue-39544.rs:26:22
|
25 | fn foo<'z>(&'z self) {
| -------- use `&'z mut self` here to make mutable
26 | let _ = &mut self.x;
| ^^^^^^ cannot mutably borrow immutable field

error: cannot borrow immutable field `self.x` as mutable
error[E0596]: cannot borrow immutable field `self.x` as mutable
--> $DIR/issue-39544.rs:30:22
|
29 | fn foo1(&self, other: &Z) {
| ----- use `&mut self` here to make mutable
30 | let _ = &mut self.x;
| ^^^^^^ cannot mutably borrow immutable field

error: cannot borrow immutable field `other.x` as mutable
error[E0596]: cannot borrow immutable field `other.x` as mutable
--> $DIR/issue-39544.rs:31:22
|
29 | fn foo1(&self, other: &Z) {
Expand All @@ -31,15 +31,15 @@ error: cannot borrow immutable field `other.x` as mutable
31 | let _ = &mut other.x;
| ^^^^^^^ cannot mutably borrow immutable field

error: cannot borrow immutable field `self.x` as mutable
error[E0596]: cannot borrow immutable field `self.x` as mutable
--> $DIR/issue-39544.rs:35:22
|
34 | fn foo2<'a>(&'a self, other: &Z) {
| -------- use `&'a mut self` here to make mutable
35 | let _ = &mut self.x;
| ^^^^^^ cannot mutably borrow immutable field

error: cannot borrow immutable field `other.x` as mutable
error[E0596]: cannot borrow immutable field `other.x` as mutable
--> $DIR/issue-39544.rs:36:22
|
34 | fn foo2<'a>(&'a self, other: &Z) {
Expand All @@ -48,15 +48,15 @@ error: cannot borrow immutable field `other.x` as mutable
36 | let _ = &mut other.x;
| ^^^^^^^ cannot mutably borrow immutable field

error: cannot borrow immutable field `self.x` as mutable
error[E0596]: cannot borrow immutable field `self.x` as mutable
--> $DIR/issue-39544.rs:40:22
|
39 | fn foo3<'a>(self: &'a Self, other: &Z) {
| -------- use `&'a mut Self` here to make mutable
40 | let _ = &mut self.x;
| ^^^^^^ cannot mutably borrow immutable field

error: cannot borrow immutable field `other.x` as mutable
error[E0596]: cannot borrow immutable field `other.x` as mutable
--> $DIR/issue-39544.rs:41:22
|
39 | fn foo3<'a>(self: &'a Self, other: &Z) {
Expand All @@ -65,23 +65,23 @@ error: cannot borrow immutable field `other.x` as mutable
41 | let _ = &mut other.x;
| ^^^^^^^ cannot mutably borrow immutable field

error: cannot borrow immutable field `other.x` as mutable
error[E0596]: cannot borrow immutable field `other.x` as mutable
--> $DIR/issue-39544.rs:45:22
|
44 | fn foo4(other: &Z) {
| -- use `&mut Z` here to make mutable
45 | let _ = &mut other.x;
| ^^^^^^^ cannot mutably borrow immutable field

error: cannot borrow immutable field `z.x` as mutable
error[E0596]: cannot borrow immutable field `z.x` as mutable
--> $DIR/issue-39544.rs:51:18
|
50 | pub fn with_arg(z: Z, w: &Z) {
| - consider changing this to `mut z`
51 | let _ = &mut z.x;
| ^^^ cannot mutably borrow immutable field

error: cannot borrow immutable field `w.x` as mutable
error[E0596]: cannot borrow immutable field `w.x` as mutable
--> $DIR/issue-39544.rs:52:18
|
50 | pub fn with_arg(z: Z, w: &Z) {
Expand All @@ -90,7 +90,7 @@ error: cannot borrow immutable field `w.x` as mutable
52 | let _ = &mut w.x;
| ^^^ cannot mutably borrow immutable field

error: cannot assign to immutable borrowed content `*x.0`
error[E0594]: cannot assign to immutable borrowed content `*x.0`
--> $DIR/issue-39544.rs:58:5
|
58 | *x.0 = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/did_you_mean/issue-40823.stderr
@@ -1,4 +1,4 @@
error: cannot borrow immutable borrowed content `*buf` as mutable
error[E0596]: cannot borrow immutable borrowed content `*buf` as mutable
--> $DIR/issue-40823.rs:13:5
|
13 | buf.iter_mut();
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/dropck/dropck-eyepatch-extern-crate.stderr
@@ -1,4 +1,4 @@
error: `c` does not live long enough
error[E0597]: `c` does not live long enough
--> $DIR/dropck-eyepatch-extern-crate.rs:55:1
|
39 | dt = Dt("dt", &c); //~ ERROR `c` does not live long enough
Expand All @@ -9,7 +9,7 @@ error: `c` does not live long enough
|
= note: values in a scope are dropped in the opposite order they are created

error: `c` does not live long enough
error[E0597]: `c` does not live long enough
--> $DIR/dropck-eyepatch-extern-crate.rs:55:1
|
40 | dr = Dr("dr", &c); //~ ERROR `c` does not live long enough
Expand All @@ -20,7 +20,7 @@ error: `c` does not live long enough
|
= note: values in a scope are dropped in the opposite order they are created

error: `c` does not live long enough
error[E0597]: `c` does not live long enough
--> $DIR/dropck-eyepatch-extern-crate.rs:55:1
|
47 | pt = Pt("pt", &c_long, &c); //~ ERROR `c` does not live long enough
Expand All @@ -31,7 +31,7 @@ error: `c` does not live long enough
|
= note: values in a scope are dropped in the opposite order they are created

error: `c` does not live long enough
error[E0597]: `c` does not live long enough
--> $DIR/dropck-eyepatch-extern-crate.rs:55:1
|
48 | pr = Pr("pr", &c_long, &c); //~ ERROR `c` does not live long enough
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/dropck/dropck-eyepatch-reorder.stderr
@@ -1,4 +1,4 @@
error: `c` does not live long enough
error[E0597]: `c` does not live long enough
--> $DIR/dropck-eyepatch-reorder.rs:73:1
|
57 | dt = Dt("dt", &c); //~ ERROR `c` does not live long enough
Expand All @@ -9,7 +9,7 @@ error: `c` does not live long enough
|
= note: values in a scope are dropped in the opposite order they are created

error: `c` does not live long enough
error[E0597]: `c` does not live long enough
--> $DIR/dropck-eyepatch-reorder.rs:73:1
|
58 | dr = Dr("dr", &c); //~ ERROR `c` does not live long enough
Expand All @@ -20,7 +20,7 @@ error: `c` does not live long enough
|
= note: values in a scope are dropped in the opposite order they are created

error: `c` does not live long enough
error[E0597]: `c` does not live long enough
--> $DIR/dropck-eyepatch-reorder.rs:73:1
|
65 | pt = Pt("pt", &c_long, &c); //~ ERROR `c` does not live long enough
Expand All @@ -31,7 +31,7 @@ error: `c` does not live long enough
|
= note: values in a scope are dropped in the opposite order they are created

error: `c` does not live long enough
error[E0597]: `c` does not live long enough
--> $DIR/dropck-eyepatch-reorder.rs:73:1
|
66 | pr = Pr("pr", &c_long, &c); //~ ERROR `c` does not live long enough
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/dropck/dropck-eyepatch.stderr
@@ -1,4 +1,4 @@
error: `c` does not live long enough
error[E0597]: `c` does not live long enough
--> $DIR/dropck-eyepatch.rs:96:1
|
80 | dt = Dt("dt", &c); //~ ERROR `c` does not live long enough
Expand All @@ -9,7 +9,7 @@ error: `c` does not live long enough
|
= note: values in a scope are dropped in the opposite order they are created

error: `c` does not live long enough
error[E0597]: `c` does not live long enough
--> $DIR/dropck-eyepatch.rs:96:1
|
81 | dr = Dr("dr", &c); //~ ERROR `c` does not live long enough
Expand All @@ -20,7 +20,7 @@ error: `c` does not live long enough
|
= note: values in a scope are dropped in the opposite order they are created

error: `c` does not live long enough
error[E0597]: `c` does not live long enough
--> $DIR/dropck-eyepatch.rs:96:1
|
88 | pt = Pt("pt", &c_long, &c); //~ ERROR `c` does not live long enough
Expand All @@ -31,7 +31,7 @@ error: `c` does not live long enough
|
= note: values in a scope are dropped in the opposite order they are created

error: `c` does not live long enough
error[E0597]: `c` does not live long enough
--> $DIR/dropck-eyepatch.rs:96:1
|
89 | pr = Pr("pr", &c_long, &c); //~ ERROR `c` does not live long enough
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issue-41652/issue_41652.stderr
@@ -1,4 +1,4 @@
error: no method named `f` found for type `{integer}` in the current scope
error[E0599]: no method named `f` found for type `{integer}` in the current scope
--> $DIR/issue_41652.rs:19:11
|
19 | 3.f()
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/lifetimes/borrowck-let-suggestion.stderr
@@ -1,4 +1,4 @@
error: borrowed value does not live long enough
error[E0597]: borrowed value does not live long enough
--> $DIR/borrowck-let-suggestion.rs:12:23
|
12 | let x = [1].iter();
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/macros/macro-backtrace-invalid-internals.stderr
@@ -1,4 +1,4 @@
error: no method named `fake` found for type `{integer}` in the current scope
error[E0599]: no method named `fake` found for type `{integer}` in the current scope
--> $DIR/macro-backtrace-invalid-internals.rs:15:13
|
15 | 1.fake()
Expand All @@ -25,7 +25,7 @@ error: attempted tuple index `0` on type `{integer}`, but the type was not a tup
52 | fake_anon_field_stmt!();
| ------------------------ in this macro invocation

error: no method named `fake` found for type `{integer}` in the current scope
error[E0599]: no method named `fake` found for type `{integer}` in the current scope
--> $DIR/macro-backtrace-invalid-internals.rs:33:13
|
33 | 1.fake()
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/mismatched_types/issue-36053-2.stderr
@@ -1,4 +1,4 @@
error: no method named `count` found for type `std::iter::Filter<std::iter::Fuse<std::iter::Once<&str>>, [closure@$DIR/issue-36053-2.rs:17:39: 17:53]>` in the current scope
error[E0599]: no method named `count` found for type `std::iter::Filter<std::iter::Fuse<std::iter::Once<&str>>, [closure@$DIR/issue-36053-2.rs:17:39: 17:53]>` in the current scope
--> $DIR/issue-36053-2.rs:17:55
|
17 | once::<&str>("str").fuse().filter(|a: &str| true).count();
Expand Down
@@ -1,4 +1,4 @@
error: no method named `unwrap` found for type `std::result::Result<(), Foo>` in the current scope
error[E0599]: no method named `unwrap` found for type `std::result::Result<(), Foo>` in the current scope
--> $DIR/method-help-unsatisfied-bound.rs:15:7
|
15 | a.unwrap();
Expand Down

0 comments on commit 998b197

Please sign in to comment.