Skip to content

Commit 998b197

Browse files
Add new error codes and update tests
1 parent 8be89f5 commit 998b197

File tree

72 files changed

+180
-167
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+180
-167
lines changed

src/librustc_typeck/check/method/suggest.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,21 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
165165
.. }) => {
166166
let tcx = self.tcx;
167167

168-
let mut err = self.type_error_struct(span,
169-
|actual| {
170-
format!("no {} named `{}` found for type `{}` in the current scope",
171-
if mode == Mode::MethodCall {
172-
"method"
173-
} else {
174-
"associated item"
175-
},
176-
item_name,
177-
actual)
178-
},
179-
rcvr_ty);
168+
let actual = self.resolve_type_vars_if_possible(&rcvr_ty);
169+
let mut err = if !actual.references_error() {
170+
struct_span_err!(tcx.sess, span, E0599,
171+
"no {} named `{}` found for type `{}` in the \
172+
current scope",
173+
if mode == Mode::MethodCall {
174+
"method"
175+
} else {
176+
"associated item"
177+
},
178+
item_name,
179+
self.ty_to_string(actual))
180+
} else {
181+
self.tcx.sess.diagnostic().struct_dummy()
182+
};
180183

181184
// If the method name is the name of a field with a function or closure type,
182185
// give a helping note that it has to be called as (x.f)(...).

src/librustc_typeck/diagnostics.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -4005,7 +4005,7 @@ details.
40054005
[issue #33685]: https://github.com/rust-lang/rust/issues/33685
40064006
"##,
40074007

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

4045+
E0599: r##"
4046+
```compile_fail,E0599
4047+
struct Mouth;
4048+
4049+
let x = Mouth;
4050+
x.chocolate(); // error: no method named `chocolate` found for type `Mouth`
4051+
// in the current scope
4052+
```
4053+
"##,
4054+
40454055
}
40464056

40474057
register_diagnostics! {

src/test/ui/codemap_tests/huge_multispan_highlight.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: cannot borrow immutable local variable `x` as mutable
1+
error[E0596]: cannot borrow immutable local variable `x` as mutable
22
--> $DIR/huge_multispan_highlight.rs:100:18
33
|
44
12 | let x = "foo";

src/test/ui/did_you_mean/issue-31424.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: cannot borrow immutable argument `self` as mutable
1+
error[E0596]: cannot borrow immutable argument `self` as mutable
22
--> $DIR/issue-31424.rs:17:15
33
|
44
17 | (&mut self).bar();
@@ -7,7 +7,7 @@ error: cannot borrow immutable argument `self` as mutable
77
| try removing `&mut` here
88
| cannot reborrow mutably
99

10-
error: cannot borrow immutable argument `self` as mutable
10+
error[E0596]: cannot borrow immutable argument `self` as mutable
1111
--> $DIR/issue-31424.rs:23:15
1212
|
1313
22 | fn bar(self: &mut Self) {

src/test/ui/did_you_mean/issue-34126.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: cannot borrow immutable argument `self` as mutable
1+
error[E0596]: cannot borrow immutable argument `self` as mutable
22
--> $DIR/issue-34126.rs:16:23
33
|
44
16 | self.run(&mut self);

src/test/ui/did_you_mean/issue-34337.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: cannot borrow immutable local variable `key` as mutable
1+
error[E0596]: cannot borrow immutable local variable `key` as mutable
22
--> $DIR/issue-34337.rs:16:14
33
|
44
16 | get(&mut key);

src/test/ui/did_you_mean/issue-35937.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
error: cannot borrow immutable field `f.v` as mutable
1+
error[E0596]: cannot borrow immutable field `f.v` as mutable
22
--> $DIR/issue-35937.rs:17:5
33
|
44
16 | let f = Foo { v: Vec::new() };
55
| - consider changing this to `mut f`
66
17 | f.v.push("cat".to_string());
77
| ^^^ cannot mutably borrow immutable field
88

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

17-
error: cannot assign to immutable field `s.x`
17+
error[E0594]: cannot assign to immutable field `s.x`
1818
--> $DIR/issue-35937.rs:30:5
1919
|
2020
29 | fn bar(s: S) {

src/test/ui/did_you_mean/issue-37139.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: cannot borrow immutable local variable `x` as mutable
1+
error[E0596]: cannot borrow immutable local variable `x` as mutable
22
--> $DIR/issue-37139.rs:22:23
33
|
44
22 | test(&mut x);

src/test/ui/did_you_mean/issue-38147-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: cannot borrow immutable borrowed content `*self.s` as mutable
1+
error[E0596]: cannot borrow immutable borrowed content `*self.s` as mutable
22
--> $DIR/issue-38147-2.rs:17:9
33
|
44
12 | s: &'a String

src/test/ui/did_you_mean/issue-38147-3.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: cannot borrow immutable borrowed content `*self.s` as mutable
1+
error[E0596]: cannot borrow immutable borrowed content `*self.s` as mutable
22
--> $DIR/issue-38147-3.rs:17:9
33
|
44
12 | s: &'a String

src/test/ui/did_you_mean/issue-39544.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
error: cannot borrow immutable field `z.x` as mutable
1+
error[E0596]: cannot borrow immutable field `z.x` as mutable
22
--> $DIR/issue-39544.rs:21:18
33
|
44
20 | let z = Z { x: X::Y };
55
| - consider changing this to `mut z`
66
21 | let _ = &mut z.x;
77
| ^^^ cannot mutably borrow immutable field
88

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

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

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

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

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

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

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

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

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

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

93-
error: cannot assign to immutable borrowed content `*x.0`
93+
error[E0594]: cannot assign to immutable borrowed content `*x.0`
9494
--> $DIR/issue-39544.rs:58:5
9595
|
9696
58 | *x.0 = 1;

src/test/ui/did_you_mean/issue-40823.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: cannot borrow immutable borrowed content `*buf` as mutable
1+
error[E0596]: cannot borrow immutable borrowed content `*buf` as mutable
22
--> $DIR/issue-40823.rs:13:5
33
|
44
13 | buf.iter_mut();

src/test/ui/dropck/dropck-eyepatch-extern-crate.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: `c` does not live long enough
1+
error[E0597]: `c` does not live long enough
22
--> $DIR/dropck-eyepatch-extern-crate.rs:55:1
33
|
44
39 | dt = Dt("dt", &c); //~ ERROR `c` does not live long enough
@@ -9,7 +9,7 @@ error: `c` does not live long enough
99
|
1010
= note: values in a scope are dropped in the opposite order they are created
1111

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

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

34-
error: `c` does not live long enough
34+
error[E0597]: `c` does not live long enough
3535
--> $DIR/dropck-eyepatch-extern-crate.rs:55:1
3636
|
3737
48 | pr = Pr("pr", &c_long, &c); //~ ERROR `c` does not live long enough

src/test/ui/dropck/dropck-eyepatch-reorder.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: `c` does not live long enough
1+
error[E0597]: `c` does not live long enough
22
--> $DIR/dropck-eyepatch-reorder.rs:73:1
33
|
44
57 | dt = Dt("dt", &c); //~ ERROR `c` does not live long enough
@@ -9,7 +9,7 @@ error: `c` does not live long enough
99
|
1010
= note: values in a scope are dropped in the opposite order they are created
1111

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

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

34-
error: `c` does not live long enough
34+
error[E0597]: `c` does not live long enough
3535
--> $DIR/dropck-eyepatch-reorder.rs:73:1
3636
|
3737
66 | pr = Pr("pr", &c_long, &c); //~ ERROR `c` does not live long enough

src/test/ui/dropck/dropck-eyepatch.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: `c` does not live long enough
1+
error[E0597]: `c` does not live long enough
22
--> $DIR/dropck-eyepatch.rs:96:1
33
|
44
80 | dt = Dt("dt", &c); //~ ERROR `c` does not live long enough
@@ -9,7 +9,7 @@ error: `c` does not live long enough
99
|
1010
= note: values in a scope are dropped in the opposite order they are created
1111

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

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

34-
error: `c` does not live long enough
34+
error[E0597]: `c` does not live long enough
3535
--> $DIR/dropck-eyepatch.rs:96:1
3636
|
3737
89 | pr = Pr("pr", &c_long, &c); //~ ERROR `c` does not live long enough

src/test/ui/issue-41652/issue_41652.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: no method named `f` found for type `{integer}` in the current scope
1+
error[E0599]: no method named `f` found for type `{integer}` in the current scope
22
--> $DIR/issue_41652.rs:19:11
33
|
44
19 | 3.f()

src/test/ui/lifetimes/borrowck-let-suggestion.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: borrowed value does not live long enough
1+
error[E0597]: borrowed value does not live long enough
22
--> $DIR/borrowck-let-suggestion.rs:12:23
33
|
44
12 | let x = [1].iter();

src/test/ui/macros/macro-backtrace-invalid-internals.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: no method named `fake` found for type `{integer}` in the current scope
1+
error[E0599]: no method named `fake` found for type `{integer}` in the current scope
22
--> $DIR/macro-backtrace-invalid-internals.rs:15:13
33
|
44
15 | 1.fake()
@@ -25,7 +25,7 @@ error: attempted tuple index `0` on type `{integer}`, but the type was not a tup
2525
52 | fake_anon_field_stmt!();
2626
| ------------------------ in this macro invocation
2727

28-
error: no method named `fake` found for type `{integer}` in the current scope
28+
error[E0599]: no method named `fake` found for type `{integer}` in the current scope
2929
--> $DIR/macro-backtrace-invalid-internals.rs:33:13
3030
|
3131
33 | 1.fake()

src/test/ui/mismatched_types/issue-36053-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
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
1+
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
22
--> $DIR/issue-36053-2.rs:17:55
33
|
44
17 | once::<&str>("str").fuse().filter(|a: &str| true).count();

src/test/ui/mismatched_types/method-help-unsatisfied-bound.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: no method named `unwrap` found for type `std::result::Result<(), Foo>` in the current scope
1+
error[E0599]: no method named `unwrap` found for type `std::result::Result<(), Foo>` in the current scope
22
--> $DIR/method-help-unsatisfied-bound.rs:15:7
33
|
44
15 | a.unwrap();

0 commit comments

Comments
 (0)