-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error message for mutating field of immutable struct could be clearer #27593
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
Comments
steveklabnik
added
the
A-diagnostics
Area: Messages for errors, warnings, and lints
label
Aug 13, 2015
Triage: no change. I agree that "immutable field" is bad here. |
Probably needs an extension of #39139 to immutable bindings instead of just references. Unfamiliar with the code, but possibly easy? |
steveklabnik
removed
the
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
label
Mar 9, 2017
frewsxcv
added a commit
to frewsxcv/rust
that referenced
this issue
Mar 18, 2017
…rner Point to let when modifying field of immutable variable Point at the immutable local variable when trying to modify one of its fields. Given a file: ```rust struct Foo { pub v: Vec<String> } fn main() { let f = Foo { v: Vec::new() }; f.v.push("cat".to_string()); } ``` present the following output: ``` error: cannot borrow immutable field `f.v` as mutable --> file.rs:7:13 | 6 | let f = Foo { v: Vec::new() }; | - this should be `mut` 7 | f.v.push("cat".to_string()); | ^^^ error: aborting due to previous error ``` Fix rust-lang#27593.
arielb1
pushed a commit
to arielb1/rust
that referenced
this issue
Mar 18, 2017
…rner Point to let when modifying field of immutable variable Point at the immutable local variable when trying to modify one of its fields. Given a file: ```rust struct Foo { pub v: Vec<String> } fn main() { let f = Foo { v: Vec::new() }; f.v.push("cat".to_string()); } ``` present the following output: ``` error: cannot borrow immutable field `f.v` as mutable --> file.rs:7:13 | 6 | let f = Foo { v: Vec::new() }; | - this should be `mut` 7 | f.v.push("cat".to_string()); | ^^^ error: aborting due to previous error ``` Fix rust-lang#27593.
arielb1
pushed a commit
to arielb1/rust
that referenced
this issue
Mar 19, 2017
…rner Point to let when modifying field of immutable variable Point at the immutable local variable when trying to modify one of its fields. Given a file: ```rust struct Foo { pub v: Vec<String> } fn main() { let f = Foo { v: Vec::new() }; f.v.push("cat".to_string()); } ``` present the following output: ``` error: cannot borrow immutable field `f.v` as mutable --> file.rs:7:13 | 6 | let f = Foo { v: Vec::new() }; | - this should be `mut` 7 | f.v.push("cat".to_string()); | ^^^ error: aborting due to previous error ``` Fix rust-lang#27593.
frewsxcv
added a commit
to frewsxcv/rust
that referenced
this issue
Mar 19, 2017
…rner Point to let when modifying field of immutable variable Point at the immutable local variable when trying to modify one of its fields. Given a file: ```rust struct Foo { pub v: Vec<String> } fn main() { let f = Foo { v: Vec::new() }; f.v.push("cat".to_string()); } ``` present the following output: ``` error: cannot borrow immutable field `f.v` as mutable --> file.rs:7:13 | 6 | let f = Foo { v: Vec::new() }; | - this should be `mut` 7 | f.v.push("cat".to_string()); | ^^^ error: aborting due to previous error ``` Fix rust-lang#27593.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The above code gives this compile error:
From my perspective, this implies that the field somehow needs to be marked as mutable, when in fact the user error is that the struct is immutable.
I believe the error message could be improved by saying something like
cannot borrow field
vof immutable struct
fas mutable
.#18150 is "related".
The text was updated successfully, but these errors were encountered: