Closed
Description
The following code (playground):
struct A {
banana: u8,
}
impl A {
fn new(peach: u8) -> A {
A {
banana: banana // note: banana not in scope here
}
}
}
produces the following error:
error[E0425]: cannot find value `banana` in this scope
--> src/lib.rs:8:21
|
8 | banana: banana
| ^^^^^^
| |
| `self` value is a keyword only available in methods with `self` parameter
| help: try: `self.banana`
First, help
is wrong, because this is a static method and self is not available in scope. Second it is not clear why a line above help
is talking about self
at all.
Activity
petrochenkov commentedon Apr 18, 2019
The original logic was to
self.banana
, that's a common mistakeself
assuming it's forgotten, that's also a common mistake, which is especially likely if you are referring to something that is named exactly like a field.Unfortunately, the messages were reworded and repositioned by later changes.
Rollup merge of rust-lang#60061 - estebank:field-sugg, r=davidtwco
Rollup merge of rust-lang#60061 - estebank:field-sugg, r=davidtwco
Rollup merge of rust-lang#60061 - estebank:field-sugg, r=davidtwco
Rollup merge of rust-lang#60061 - estebank:field-sugg, r=davidtwco