Skip to content

Commit 5bb58bf

Browse files
Add E0615
1 parent a80db25 commit 5bb58bf

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

src/librustc_typeck/check/mod.rs

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

src/librustc_typeck/diagnostics.rs

+32
Original file line numberDiff line numberDiff line change
@@ -4307,6 +4307,38 @@ let x = &y;
43074307
```
43084308
"##,
43094309

4310+
E0615: r##"
4311+
Attempted to access a method like a field.
4312+
4313+
Erroneous code example:
4314+
4315+
```compile_fail,E0615
4316+
struct Foo {
4317+
x: u32,
4318+
}
4319+
4320+
impl Foo {
4321+
fn method(&self) {}
4322+
}
4323+
4324+
let f = Foo { x: 0 };
4325+
f.method; // error: attempted to take value of method `method` on type `Foo`
4326+
```
4327+
4328+
If you want to use a method, add `()` after it:
4329+
4330+
```ignore
4331+
f.method();
4332+
```
4333+
4334+
However, if you wanted to access a field of a struct check that the field name
4335+
is spelled correctly. Example:
4336+
4337+
```ignore
4338+
println!("{}", f.x);
4339+
```
4340+
"##,
4341+
43104342
E0617: r##"
43114343
Attempted to pass an invalid type of variable into a variadic function.
43124344

src/test/compile-fail/E0615.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct Foo {
12+
x: u32,
13+
}
14+
15+
impl Foo {
16+
fn method(&self) {}
17+
}
18+
19+
fn main() {
20+
let f = Foo { x: 0 };
21+
f.method; //~ ERROR E0615
22+
}

0 commit comments

Comments
 (0)