Rollup merge of #40816 - estebank:issue-38321, r=nikomatsakis
Clarify suggetion for field used as method Instead of ```rust error: no method named `src_addr` found for type `&wire::ipv4::Repr` in the current scope --> src/wire/ipv4.rs:409:34 | 409 | packet.set_src_addr(self.src_addr()); | ^^^^^^^^ | note: did you mean to write `self.src_addr`? --> src/wire/ipv4.rs:409:34 | 409 | packet.set_src_addr(self.src_addr()); | ^^^^^^^^ ``` present ```rust error: no method named `src_addr` found for type `&wire::ipv4::Repr` in the current scope --> src/wire/ipv4.rs:409:34 | 409 | packet.set_src_addr(self.src_addr()); | ^^^^^^^^ field, not a method | = help: did you mean to write `self.src_addr` instead of `self.src_addr(...)`? ``` Fix #38321.
This commit is contained in:
commit
7f1083e741
9 changed files with 186 additions and 30 deletions
|
@ -197,18 +197,18 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
let field_ty = field.ty(tcx, substs);
|
let field_ty = field.ty(tcx, substs);
|
||||||
|
|
||||||
if self.is_fn_ty(&field_ty, span) {
|
if self.is_fn_ty(&field_ty, span) {
|
||||||
err.span_note(span,
|
err.help(&format!("use `({0}.{1})(...)` if you \
|
||||||
&format!("use `({0}.{1})(...)` if you \
|
meant to call the function \
|
||||||
meant to call the function \
|
stored in the `{1}` field",
|
||||||
stored in the `{1}` field",
|
expr_string,
|
||||||
expr_string,
|
item_name));
|
||||||
item_name));
|
|
||||||
} else {
|
} else {
|
||||||
err.span_note(span,
|
err.help(&format!("did you mean to write `{0}.{1}` \
|
||||||
&format!("did you mean to write `{0}.{1}`?",
|
instead of `{0}.{1}(...)`?",
|
||||||
expr_string,
|
expr_string,
|
||||||
item_name));
|
item_name));
|
||||||
}
|
}
|
||||||
|
err.span_label(span, &"field, not a method");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@ struct Obj<F> where F: FnMut() -> u32 {
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let o = Obj { closure: || 42 };
|
let o = Obj { closure: || 42 };
|
||||||
o.closure(); //~ ERROR no method named `closure` found
|
o.closure();
|
||||||
//~^ NOTE use `(o.closure)(...)` if you meant to call the function stored in the `closure` field
|
//~^ ERROR no method named `closure` found
|
||||||
|
//~| HELP use `(o.closure)(...)` if you meant to call the function stored in the `closure` field
|
||||||
|
//~| NOTE field, not a method
|
||||||
}
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
error: no method named `closure` found for type `Obj<[closure@$DIR/issue-18343.rs:16:28: 16:33]>` in the current scope
|
||||||
|
--> $DIR/issue-18343.rs:17:7
|
||||||
|
|
|
||||||
|
17 | o.closure();
|
||||||
|
| ^^^^^^^ field, not a method
|
||||||
|
|
|
||||||
|
= help: use `(o.closure)(...)` if you meant to call the function stored in the `closure` field
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
|
@ -48,45 +48,58 @@ fn main() {
|
||||||
|
|
||||||
let o_closure = Obj { closure: || 42, not_closure: 42 };
|
let o_closure = Obj { closure: || 42, not_closure: 42 };
|
||||||
o_closure.closure(); //~ ERROR no method named `closure` found
|
o_closure.closure(); //~ ERROR no method named `closure` found
|
||||||
//~^ NOTE use `(o_closure.closure)(...)` if you meant to call the function stored
|
//~^ HELP use `(o_closure.closure)(...)` if you meant to call the function stored
|
||||||
|
//~| NOTE field, not a method
|
||||||
|
|
||||||
o_closure.not_closure(); //~ ERROR no method named `not_closure` found
|
o_closure.not_closure();
|
||||||
//~^ NOTE did you mean to write `o_closure.not_closure`?
|
//~^ ERROR no method named `not_closure` found
|
||||||
|
//~| NOTE field, not a method
|
||||||
|
//~| HELP did you mean to write `o_closure.not_closure` instead of `o_closure.not_closure(...)`?
|
||||||
|
|
||||||
let o_func = Obj { closure: func, not_closure: 5 };
|
let o_func = Obj { closure: func, not_closure: 5 };
|
||||||
o_func.closure(); //~ ERROR no method named `closure` found
|
o_func.closure(); //~ ERROR no method named `closure` found
|
||||||
//~^ NOTE use `(o_func.closure)(...)` if you meant to call the function stored
|
//~^ HELP use `(o_func.closure)(...)` if you meant to call the function stored
|
||||||
|
//~| NOTE field, not a method
|
||||||
|
|
||||||
let boxed_fn = BoxedObj { boxed_closure: Box::new(func) };
|
let boxed_fn = BoxedObj { boxed_closure: Box::new(func) };
|
||||||
boxed_fn.boxed_closure();//~ ERROR no method named `boxed_closure` found
|
boxed_fn.boxed_closure();//~ ERROR no method named `boxed_closure` found
|
||||||
//~^ NOTE use `(boxed_fn.boxed_closure)(...)` if you meant to call the function stored
|
//~^ HELP use `(boxed_fn.boxed_closure)(...)` if you meant to call the function stored
|
||||||
|
//~| NOTE field, not a method
|
||||||
|
|
||||||
let boxed_closure = BoxedObj { boxed_closure: Box::new(|| 42_u32) as Box<FnBox() -> u32> };
|
let boxed_closure = BoxedObj { boxed_closure: Box::new(|| 42_u32) as Box<FnBox() -> u32> };
|
||||||
boxed_closure.boxed_closure();//~ ERROR no method named `boxed_closure` found
|
boxed_closure.boxed_closure();//~ ERROR no method named `boxed_closure` found
|
||||||
//~^ NOTE use `(boxed_closure.boxed_closure)(...)` if you meant to call the function stored
|
//~^ HELP use `(boxed_closure.boxed_closure)(...)` if you meant to call the function stored
|
||||||
|
//~| NOTE field, not a method
|
||||||
|
|
||||||
// test expression writing in the notes
|
// test expression writing in the notes
|
||||||
|
|
||||||
let w = Wrapper { wrap: o_func };
|
let w = Wrapper { wrap: o_func };
|
||||||
w.wrap.closure();//~ ERROR no method named `closure` found
|
w.wrap.closure();//~ ERROR no method named `closure` found
|
||||||
//~^ NOTE use `(w.wrap.closure)(...)` if you meant to call the function stored
|
//~^ HELP use `(w.wrap.closure)(...)` if you meant to call the function stored
|
||||||
|
//~| NOTE field, not a method
|
||||||
|
|
||||||
w.wrap.not_closure();//~ ERROR no method named `not_closure` found
|
w.wrap.not_closure();
|
||||||
//~^ NOTE did you mean to write `w.wrap.not_closure`?
|
//~^ ERROR no method named `not_closure` found
|
||||||
|
//~| NOTE field, not a method
|
||||||
|
//~| HELP did you mean to write `w.wrap.not_closure` instead of `w.wrap.not_closure(...)`?
|
||||||
|
|
||||||
check_expression().closure();//~ ERROR no method named `closure` found
|
check_expression().closure();//~ ERROR no method named `closure` found
|
||||||
//~^ NOTE use `(check_expression().closure)(...)` if you meant to call the function stored
|
//~^ HELP use `(check_expression().closure)(...)` if you meant to call the function stored
|
||||||
|
//~| NOTE field, not a method
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FuncContainerOuter {
|
impl FuncContainerOuter {
|
||||||
fn run(&self) {
|
fn run(&self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
(*self.container).f1(1); //~ ERROR no method named `f1` found
|
(*self.container).f1(1); //~ ERROR no method named `f1` found
|
||||||
//~^ NOTE use `((*self.container).f1)(...)`
|
//~^ HELP use `((*self.container).f1)(...)`
|
||||||
|
//~| NOTE field, not a method
|
||||||
(*self.container).f2(1); //~ ERROR no method named `f2` found
|
(*self.container).f2(1); //~ ERROR no method named `f2` found
|
||||||
//~^ NOTE use `((*self.container).f2)(...)`
|
//~^ HELP use `((*self.container).f2)(...)`
|
||||||
|
//~| NOTE field, not a method
|
||||||
(*self.container).f3(1); //~ ERROR no method named `f3` found
|
(*self.container).f3(1); //~ ERROR no method named `f3` found
|
||||||
//~^ NOTE use `((*self.container).f3)(...)`
|
//~^ HELP use `((*self.container).f3)(...)`
|
||||||
|
//~| NOTE field, not a method
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,90 @@
|
||||||
|
error: no method named `closure` found for type `Obj<[closure@$DIR/issue-2392.rs:49:36: 49:41]>` in the current scope
|
||||||
|
--> $DIR/issue-2392.rs:50:15
|
||||||
|
|
|
||||||
|
50 | o_closure.closure(); //~ ERROR no method named `closure` found
|
||||||
|
| ^^^^^^^ field, not a method
|
||||||
|
|
|
||||||
|
= help: use `(o_closure.closure)(...)` if you meant to call the function stored in the `closure` field
|
||||||
|
|
||||||
|
error: no method named `not_closure` found for type `Obj<[closure@$DIR/issue-2392.rs:49:36: 49:41]>` in the current scope
|
||||||
|
--> $DIR/issue-2392.rs:54:15
|
||||||
|
|
|
||||||
|
54 | o_closure.not_closure();
|
||||||
|
| ^^^^^^^^^^^ field, not a method
|
||||||
|
|
|
||||||
|
= help: did you mean to write `o_closure.not_closure` instead of `o_closure.not_closure(...)`?
|
||||||
|
|
||||||
|
error: no method named `closure` found for type `Obj<fn() -> u32 {func}>` in the current scope
|
||||||
|
--> $DIR/issue-2392.rs:60:12
|
||||||
|
|
|
||||||
|
60 | o_func.closure(); //~ ERROR no method named `closure` found
|
||||||
|
| ^^^^^^^ field, not a method
|
||||||
|
|
|
||||||
|
= help: use `(o_func.closure)(...)` if you meant to call the function stored in the `closure` field
|
||||||
|
|
||||||
|
error: no method named `boxed_closure` found for type `BoxedObj` in the current scope
|
||||||
|
--> $DIR/issue-2392.rs:65:14
|
||||||
|
|
|
||||||
|
65 | boxed_fn.boxed_closure();//~ ERROR no method named `boxed_closure` found
|
||||||
|
| ^^^^^^^^^^^^^ field, not a method
|
||||||
|
|
|
||||||
|
= help: use `(boxed_fn.boxed_closure)(...)` if you meant to call the function stored in the `boxed_closure` field
|
||||||
|
|
||||||
|
error: no method named `boxed_closure` found for type `BoxedObj` in the current scope
|
||||||
|
--> $DIR/issue-2392.rs:70:19
|
||||||
|
|
|
||||||
|
70 | boxed_closure.boxed_closure();//~ ERROR no method named `boxed_closure` found
|
||||||
|
| ^^^^^^^^^^^^^ field, not a method
|
||||||
|
|
|
||||||
|
= help: use `(boxed_closure.boxed_closure)(...)` if you meant to call the function stored in the `boxed_closure` field
|
||||||
|
|
||||||
|
error: no method named `closure` found for type `Obj<fn() -> u32 {func}>` in the current scope
|
||||||
|
--> $DIR/issue-2392.rs:77:12
|
||||||
|
|
|
||||||
|
77 | w.wrap.closure();//~ ERROR no method named `closure` found
|
||||||
|
| ^^^^^^^ field, not a method
|
||||||
|
|
|
||||||
|
= help: use `(w.wrap.closure)(...)` if you meant to call the function stored in the `closure` field
|
||||||
|
|
||||||
|
error: no method named `not_closure` found for type `Obj<fn() -> u32 {func}>` in the current scope
|
||||||
|
--> $DIR/issue-2392.rs:81:12
|
||||||
|
|
|
||||||
|
81 | w.wrap.not_closure();
|
||||||
|
| ^^^^^^^^^^^ field, not a method
|
||||||
|
|
|
||||||
|
= help: did you mean to write `w.wrap.not_closure` instead of `w.wrap.not_closure(...)`?
|
||||||
|
|
||||||
|
error: no method named `closure` found for type `Obj<std::boxed::Box<std::boxed::FnBox<(), Output=u32> + 'static>>` in the current scope
|
||||||
|
--> $DIR/issue-2392.rs:86:24
|
||||||
|
|
|
||||||
|
86 | check_expression().closure();//~ ERROR no method named `closure` found
|
||||||
|
| ^^^^^^^ field, not a method
|
||||||
|
|
|
||||||
|
= help: use `(check_expression().closure)(...)` if you meant to call the function stored in the `closure` field
|
||||||
|
|
||||||
|
error: no method named `f1` found for type `FuncContainer` in the current scope
|
||||||
|
--> $DIR/issue-2392.rs:94:31
|
||||||
|
|
|
||||||
|
94 | (*self.container).f1(1); //~ ERROR no method named `f1` found
|
||||||
|
| ^^ field, not a method
|
||||||
|
|
|
||||||
|
= help: use `((*self.container).f1)(...)` if you meant to call the function stored in the `f1` field
|
||||||
|
|
||||||
|
error: no method named `f2` found for type `FuncContainer` in the current scope
|
||||||
|
--> $DIR/issue-2392.rs:97:31
|
||||||
|
|
|
||||||
|
97 | (*self.container).f2(1); //~ ERROR no method named `f2` found
|
||||||
|
| ^^ field, not a method
|
||||||
|
|
|
||||||
|
= help: use `((*self.container).f2)(...)` if you meant to call the function stored in the `f2` field
|
||||||
|
|
||||||
|
error: no method named `f3` found for type `FuncContainer` in the current scope
|
||||||
|
--> $DIR/issue-2392.rs:100:31
|
||||||
|
|
|
||||||
|
100 | (*self.container).f3(1); //~ ERROR no method named `f3` found
|
||||||
|
| ^^ field, not a method
|
||||||
|
|
|
||||||
|
= help: use `((*self.container).f3)(...)` if you meant to call the function stored in the `f3` field
|
||||||
|
|
||||||
|
error: aborting due to 11 previous errors
|
||||||
|
|
|
@ -19,7 +19,9 @@ fn main() {
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
demo.example(1); //~ ERROR no method named `example`
|
demo.example(1);
|
||||||
//~^ NOTE use `(demo.example)(...)`
|
//~^ ERROR no method named `example`
|
||||||
|
//~| HELP use `(demo.example)(...)`
|
||||||
|
//~| NOTE field, not a method
|
||||||
// (demo.example)(1);
|
// (demo.example)(1);
|
||||||
}
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
error: no method named `example` found for type `Example` in the current scope
|
||||||
|
--> $DIR/issue-32128.rs:22:10
|
||||||
|
|
|
||||||
|
22 | demo.example(1);
|
||||||
|
| ^^^^^^^ field, not a method
|
||||||
|
|
|
||||||
|
= help: use `(demo.example)(...)` if you meant to call the function stored in the `example` field
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
|
@ -35,12 +35,15 @@ fn main() {
|
||||||
let o = Obj { fn_ptr: empty, closure: || 42 };
|
let o = Obj { fn_ptr: empty, closure: || 42 };
|
||||||
let p = &o;
|
let p = &o;
|
||||||
p.closure(); //~ ERROR no method named `closure` found
|
p.closure(); //~ ERROR no method named `closure` found
|
||||||
//~^ NOTE use `(p.closure)(...)` if you meant to call the function stored in the `closure` field
|
//~^ HELP use `(p.closure)(...)` if you meant to call the function stored in the `closure` field
|
||||||
|
//~| NOTE `closure` is a field storing a function, not a method
|
||||||
let q = &p;
|
let q = &p;
|
||||||
q.fn_ptr(); //~ ERROR no method named `fn_ptr` found
|
q.fn_ptr(); //~ ERROR no method named `fn_ptr` found
|
||||||
//~^ NOTE use `(q.fn_ptr)(...)` if you meant to call the function stored in the `fn_ptr` field
|
//~^ HELP use `(q.fn_ptr)(...)` if you meant to call the function stored in the `fn_ptr` field
|
||||||
|
//~| NOTE `fn_ptr` is a field storing a function, not a method
|
||||||
let r = D(C { c_fn_ptr: empty });
|
let r = D(C { c_fn_ptr: empty });
|
||||||
let s = &r;
|
let s = &r;
|
||||||
s.c_fn_ptr(); //~ ERROR no method named `c_fn_ptr` found
|
s.c_fn_ptr(); //~ ERROR no method named `c_fn_ptr` found
|
||||||
//~^ NOTE use `(s.c_fn_ptr)(...)` if you meant to call the function stored in the `c_fn_ptr`
|
//~^ HELP use `(s.c_fn_ptr)(...)` if you meant to call the function stored in the `c_fn_ptr`
|
||||||
|
//~| NOTE `c_fn_ptr` is a field storing a function, not a method
|
||||||
}
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
error: no method named `closure` found for type `&Obj<[closure@$DIR/issue-33784.rs:35:43: 35:48]>` in the current scope
|
||||||
|
--> $DIR/issue-33784.rs:37:7
|
||||||
|
|
|
||||||
|
37 | p.closure(); //~ ERROR no method named `closure` found
|
||||||
|
| ^^^^^^^ field, not a method
|
||||||
|
|
|
||||||
|
= help: use `(p.closure)(...)` if you meant to call the function stored in the `closure` field
|
||||||
|
|
||||||
|
error: no method named `fn_ptr` found for type `&&Obj<[closure@$DIR/issue-33784.rs:35:43: 35:48]>` in the current scope
|
||||||
|
--> $DIR/issue-33784.rs:41:7
|
||||||
|
|
|
||||||
|
41 | q.fn_ptr(); //~ ERROR no method named `fn_ptr` found
|
||||||
|
| ^^^^^^ field, not a method
|
||||||
|
|
|
||||||
|
= help: use `(q.fn_ptr)(...)` if you meant to call the function stored in the `fn_ptr` field
|
||||||
|
|
||||||
|
error: no method named `c_fn_ptr` found for type `&D` in the current scope
|
||||||
|
--> $DIR/issue-33784.rs:46:7
|
||||||
|
|
|
||||||
|
46 | s.c_fn_ptr(); //~ ERROR no method named `c_fn_ptr` found
|
||||||
|
| ^^^^^^^^ field, not a method
|
||||||
|
|
|
||||||
|
= help: use `(s.c_fn_ptr)(...)` if you meant to call the function stored in the `c_fn_ptr` field
|
||||||
|
|
||||||
|
error: aborting due to 3 previous errors
|
||||||
|
|
Loading…
Add table
Reference in a new issue