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

Lines changed: 15 additions & 12 deletions
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

Lines changed: 11 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)