Skip to content

NLL: fix E0594 "change to mutable ref" suggestion #51612

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

Merged
merged 2 commits into from
Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add test case from issue #51515
  • Loading branch information
ashtneoi committed Jul 9, 2018
commit a49b75d2f342f5904d89f34f46dfd621c20da7f7
18 changes: 18 additions & 0 deletions src/test/ui/suggestions/issue-51515.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2018 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.

#![feature(nll)]

fn main() {
let foo = &16;
*foo = 32;
let bar = foo;
*bar = 64;
}
17 changes: 17 additions & 0 deletions src/test/ui/suggestions/issue-51515.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0594]: cannot assign to `*foo` which is behind a `&` reference
--> $DIR/issue-51515.rs:15:5
|
LL | let foo = &16;
| --- help: consider changing this to be a mutable reference: `&mut 16`
LL | *foo = 32;
| ^^^^^^^^^ `foo` is a `&` reference, so the data it refers to cannot be written

error[E0594]: cannot assign to `*bar` which is behind a `&` reference
--> $DIR/issue-51515.rs:17:5
|
LL | *bar = 64;
| ^^^^^^^^^ `bar` is a `&` reference, so the data it refers to cannot be written

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0594`.