Skip to content

Commit 872d3bc

Browse files
committed
Simplify labels and move tests to ui
1 parent 6341a8b commit 872d3bc

File tree

9 files changed

+150
-20
lines changed

9 files changed

+150
-20
lines changed

src/librustc_typeck/check/method/suggest.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -202,19 +202,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
202202
stored in the `{1}` field",
203203
expr_string,
204204
item_name));
205-
err.span_label(span,
206-
&format!("`{}` is a field storing a \
207-
function, not a method",
208-
item_name));
209205
} else {
210206
err.help(&format!("did you mean to write `{0}.{1}` \
211207
instead of `{0}.{1}(...)`?",
212208
expr_string,
213209
item_name));
214-
err.span_label(span,
215-
&format!("`{}` is a field, not a method",
216-
item_name));
217210
}
211+
err.span_label(span, &"field, not a method");
218212
break;
219213
}
220214
}

src/test/compile-fail/issue-18343.rs renamed to src/test/ui/suggestions/confuse-field-and-method/issue-18343.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ fn main() {
1717
o.closure();
1818
//~^ ERROR no method named `closure` found
1919
//~| HELP use `(o.closure)(...)` if you meant to call the function stored in the `closure` field
20-
//~| NOTE `closure` is a field storing a function, not a method
20+
//~| NOTE field, not a method
2121
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: no method named `closure` found for type `Obj<[closure@$DIR/issue-18343.rs:16:28: 16:33]>` in the current scope
2+
--> $DIR/issue-18343.rs:17:7
3+
|
4+
17 | o.closure();
5+
| ^^^^^^^ field, not a method
6+
|
7+
= help: use `(o.closure)(...)` if you meant to call the function stored in the `closure` field
8+
9+
error: aborting due to previous error
10+

src/test/compile-fail/issue-2392.rs renamed to src/test/ui/suggestions/confuse-field-and-method/issue-2392.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -49,57 +49,57 @@ fn main() {
4949
let o_closure = Obj { closure: || 42, not_closure: 42 };
5050
o_closure.closure(); //~ ERROR no method named `closure` found
5151
//~^ HELP use `(o_closure.closure)(...)` if you meant to call the function stored
52-
//~| NOTE `closure` is a field storing a function, not a method
52+
//~| NOTE field, not a method
5353

5454
o_closure.not_closure();
5555
//~^ ERROR no method named `not_closure` found
56-
//~| NOTE `not_closure` is a field, not a method
56+
//~| NOTE field, not a method
5757
//~| HELP did you mean to write `o_closure.not_closure` instead of `o_closure.not_closure(...)`?
5858

5959
let o_func = Obj { closure: func, not_closure: 5 };
6060
o_func.closure(); //~ ERROR no method named `closure` found
6161
//~^ HELP use `(o_func.closure)(...)` if you meant to call the function stored
62-
//~| NOTE `closure` is a field storing a function, not a method
62+
//~| NOTE field, not a method
6363

6464
let boxed_fn = BoxedObj { boxed_closure: Box::new(func) };
6565
boxed_fn.boxed_closure();//~ ERROR no method named `boxed_closure` found
6666
//~^ HELP use `(boxed_fn.boxed_closure)(...)` if you meant to call the function stored
67-
//~| NOTE `boxed_closure` is a field storing a function, not a method
67+
//~| NOTE field, not a method
6868

6969
let boxed_closure = BoxedObj { boxed_closure: Box::new(|| 42_u32) as Box<FnBox() -> u32> };
7070
boxed_closure.boxed_closure();//~ ERROR no method named `boxed_closure` found
7171
//~^ HELP use `(boxed_closure.boxed_closure)(...)` if you meant to call the function stored
72-
//~| NOTE `boxed_closure` is a field storing a function, not a method
72+
//~| NOTE field, not a method
7373

7474
// test expression writing in the notes
7575

7676
let w = Wrapper { wrap: o_func };
7777
w.wrap.closure();//~ ERROR no method named `closure` found
7878
//~^ HELP use `(w.wrap.closure)(...)` if you meant to call the function stored
79-
//~| NOTE `closure` is a field storing a function, not a method
79+
//~| NOTE field, not a method
8080

8181
w.wrap.not_closure();
8282
//~^ ERROR no method named `not_closure` found
83-
//~| NOTE `not_closure` is a field, not a method
83+
//~| NOTE field, not a method
8484
//~| HELP did you mean to write `w.wrap.not_closure` instead of `w.wrap.not_closure(...)`?
8585

8686
check_expression().closure();//~ ERROR no method named `closure` found
8787
//~^ HELP use `(check_expression().closure)(...)` if you meant to call the function stored
88-
//~| NOTE `closure` is a field storing a function, not a method
88+
//~| NOTE field, not a method
8989
}
9090

9191
impl FuncContainerOuter {
9292
fn run(&self) {
9393
unsafe {
9494
(*self.container).f1(1); //~ ERROR no method named `f1` found
9595
//~^ HELP use `((*self.container).f1)(...)`
96-
//~| NOTE `f1` is a field storing a function, not a method
96+
//~| NOTE field, not a method
9797
(*self.container).f2(1); //~ ERROR no method named `f2` found
9898
//~^ HELP use `((*self.container).f2)(...)`
99-
//~| NOTE `f2` is a field storing a function, not a method
99+
//~| NOTE field, not a method
100100
(*self.container).f3(1); //~ ERROR no method named `f3` found
101101
//~^ HELP use `((*self.container).f3)(...)`
102-
//~| NOTE `f3` is a field storing a function, not a method
102+
//~| NOTE field, not a method
103103
}
104104
}
105105
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
error: no method named `closure` found for type `Obj<[closure@$DIR/issue-2392.rs:49:36: 49:41]>` in the current scope
2+
--> $DIR/issue-2392.rs:50:15
3+
|
4+
50 | o_closure.closure(); //~ ERROR no method named `closure` found
5+
| ^^^^^^^ field, not a method
6+
|
7+
= help: use `(o_closure.closure)(...)` if you meant to call the function stored in the `closure` field
8+
9+
error: no method named `not_closure` found for type `Obj<[closure@$DIR/issue-2392.rs:49:36: 49:41]>` in the current scope
10+
--> $DIR/issue-2392.rs:54:15
11+
|
12+
54 | o_closure.not_closure();
13+
| ^^^^^^^^^^^ field, not a method
14+
|
15+
= help: did you mean to write `o_closure.not_closure` instead of `o_closure.not_closure(...)`?
16+
17+
error: no method named `closure` found for type `Obj<fn() -> u32 {func}>` in the current scope
18+
--> $DIR/issue-2392.rs:60:12
19+
|
20+
60 | o_func.closure(); //~ ERROR no method named `closure` found
21+
| ^^^^^^^ field, not a method
22+
|
23+
= help: use `(o_func.closure)(...)` if you meant to call the function stored in the `closure` field
24+
25+
error: no method named `boxed_closure` found for type `BoxedObj` in the current scope
26+
--> $DIR/issue-2392.rs:65:14
27+
|
28+
65 | boxed_fn.boxed_closure();//~ ERROR no method named `boxed_closure` found
29+
| ^^^^^^^^^^^^^ field, not a method
30+
|
31+
= help: use `(boxed_fn.boxed_closure)(...)` if you meant to call the function stored in the `boxed_closure` field
32+
33+
error: no method named `boxed_closure` found for type `BoxedObj` in the current scope
34+
--> $DIR/issue-2392.rs:70:19
35+
|
36+
70 | boxed_closure.boxed_closure();//~ ERROR no method named `boxed_closure` found
37+
| ^^^^^^^^^^^^^ field, not a method
38+
|
39+
= help: use `(boxed_closure.boxed_closure)(...)` if you meant to call the function stored in the `boxed_closure` field
40+
41+
error: no method named `closure` found for type `Obj<fn() -> u32 {func}>` in the current scope
42+
--> $DIR/issue-2392.rs:77:12
43+
|
44+
77 | w.wrap.closure();//~ ERROR no method named `closure` found
45+
| ^^^^^^^ field, not a method
46+
|
47+
= help: use `(w.wrap.closure)(...)` if you meant to call the function stored in the `closure` field
48+
49+
error: no method named `not_closure` found for type `Obj<fn() -> u32 {func}>` in the current scope
50+
--> $DIR/issue-2392.rs:81:12
51+
|
52+
81 | w.wrap.not_closure();
53+
| ^^^^^^^^^^^ field, not a method
54+
|
55+
= help: did you mean to write `w.wrap.not_closure` instead of `w.wrap.not_closure(...)`?
56+
57+
error: no method named `closure` found for type `Obj<std::boxed::Box<std::boxed::FnBox<(), Output=u32> + 'static>>` in the current scope
58+
--> $DIR/issue-2392.rs:86:24
59+
|
60+
86 | check_expression().closure();//~ ERROR no method named `closure` found
61+
| ^^^^^^^ field, not a method
62+
|
63+
= help: use `(check_expression().closure)(...)` if you meant to call the function stored in the `closure` field
64+
65+
error: no method named `f1` found for type `FuncContainer` in the current scope
66+
--> $DIR/issue-2392.rs:94:31
67+
|
68+
94 | (*self.container).f1(1); //~ ERROR no method named `f1` found
69+
| ^^ field, not a method
70+
|
71+
= help: use `((*self.container).f1)(...)` if you meant to call the function stored in the `f1` field
72+
73+
error: no method named `f2` found for type `FuncContainer` in the current scope
74+
--> $DIR/issue-2392.rs:97:31
75+
|
76+
97 | (*self.container).f2(1); //~ ERROR no method named `f2` found
77+
| ^^ field, not a method
78+
|
79+
= help: use `((*self.container).f2)(...)` if you meant to call the function stored in the `f2` field
80+
81+
error: no method named `f3` found for type `FuncContainer` in the current scope
82+
--> $DIR/issue-2392.rs:100:31
83+
|
84+
100 | (*self.container).f3(1); //~ ERROR no method named `f3` found
85+
| ^^ field, not a method
86+
|
87+
= help: use `((*self.container).f3)(...)` if you meant to call the function stored in the `f3` field
88+
89+
error: aborting due to 11 previous errors
90+

src/test/compile-fail/issue-32128.rs renamed to src/test/ui/suggestions/confuse-field-and-method/issue-32128.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ fn main() {
2222
demo.example(1);
2323
//~^ ERROR no method named `example`
2424
//~| HELP use `(demo.example)(...)`
25-
//~| NOTE `example` is a field storing a function, not a method
25+
//~| NOTE field, not a method
2626
// (demo.example)(1);
2727
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: no method named `example` found for type `Example` in the current scope
2+
--> $DIR/issue-32128.rs:22:10
3+
|
4+
22 | demo.example(1);
5+
| ^^^^^^^ field, not a method
6+
|
7+
= help: use `(demo.example)(...)` if you meant to call the function stored in the `example` field
8+
9+
error: aborting due to previous error
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: no method named `closure` found for type `&Obj<[closure@$DIR/issue-33784.rs:35:43: 35:48]>` in the current scope
2+
--> $DIR/issue-33784.rs:37:7
3+
|
4+
37 | p.closure(); //~ ERROR no method named `closure` found
5+
| ^^^^^^^ field, not a method
6+
|
7+
= help: use `(p.closure)(...)` if you meant to call the function stored in the `closure` field
8+
9+
error: no method named `fn_ptr` found for type `&&Obj<[closure@$DIR/issue-33784.rs:35:43: 35:48]>` in the current scope
10+
--> $DIR/issue-33784.rs:41:7
11+
|
12+
41 | q.fn_ptr(); //~ ERROR no method named `fn_ptr` found
13+
| ^^^^^^ field, not a method
14+
|
15+
= help: use `(q.fn_ptr)(...)` if you meant to call the function stored in the `fn_ptr` field
16+
17+
error: no method named `c_fn_ptr` found for type `&D` in the current scope
18+
--> $DIR/issue-33784.rs:46:7
19+
|
20+
46 | s.c_fn_ptr(); //~ ERROR no method named `c_fn_ptr` found
21+
| ^^^^^^^^ field, not a method
22+
|
23+
= help: use `(s.c_fn_ptr)(...)` if you meant to call the function stored in the `c_fn_ptr` field
24+
25+
error: aborting due to 3 previous errors
26+

0 commit comments

Comments
 (0)