forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#41062 - estebank:private-field, r=arielb1
Do not recommend private fields called as method ```rust error: no method named `dog_age` found for type `animal::Dog` in the current scope --> $DIR/private-field.rs:26:23 | 26 | let dog_age = dog.dog_age(); | ^^^^^^^ private field, not a method ``` Fix rust-lang#27654.
- Loading branch information
Showing
3 changed files
with
52 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/test/ui/suggestions/confuse-field-and-method/private-field.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
pub mod animal { | ||
pub struct Dog { | ||
pub age: usize, | ||
dog_age: usize, | ||
} | ||
|
||
impl Dog { | ||
pub fn new(age: usize) -> Dog { | ||
Dog { age: age, dog_age: age * 7 } | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
let dog = animal::Dog::new(3); | ||
let dog_age = dog.dog_age(); | ||
//let dog_age = dog.dog_age; | ||
println!("{}", dog_age); | ||
} |
8 changes: 8 additions & 0 deletions
8
src/test/ui/suggestions/confuse-field-and-method/private-field.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: no method named `dog_age` found for type `animal::Dog` in the current scope | ||
--> $DIR/private-field.rs:26:23 | ||
| | ||
26 | let dog_age = dog.dog_age(); | ||
| ^^^^^^^ private field, not a method | ||
|
||
error: aborting due to previous error | ||
|