Add E0615

This commit is contained in:
Guillaume Gomez 2017-06-12 22:46:51 +02:00
parent a80db25802
commit 5bb58bf2e6
3 changed files with 57 additions and 4 deletions

View file

@ -2933,10 +2933,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
} else if field.node == keywords::Invalid.name() {
self.tcx().types.err
} else if self.method_exists(field.span, field.node, expr_t, expr.id, true) {
self.type_error_struct(field.span, |actual| {
format!("attempted to take value of method `{}` on type \
`{}`", field.node, actual)
}, expr_t)
type_error_struct!(self.tcx().sess, field.span, expr_t, E0615,
"attempted to take value of method `{}` on type `{}`",
field.node, expr_t)
.help("maybe a `()` to call it is missing? \
If not, try an anonymous function")
.emit();

View file

@ -4307,6 +4307,38 @@ let x = &y;
```
"##,
E0615: r##"
Attempted to access a method like a field.
Erroneous code example:
```compile_fail,E0615
struct Foo {
x: u32,
}
impl Foo {
fn method(&self) {}
}
let f = Foo { x: 0 };
f.method; // error: attempted to take value of method `method` on type `Foo`
```
If you want to use a method, add `()` after it:
```ignore
f.method();
```
However, if you wanted to access a field of a struct check that the field name
is spelled correctly. Example:
```ignore
println!("{}", f.x);
```
"##,
E0617: r##"
Attempted to pass an invalid type of variable into a variadic function.