-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #41564 - gaurikholkar:master, r=nikomatsakis
Disable ref hint for pattern in let and adding ui tests #40402 A fix to #40402 The `to prevent move, use ref e or ref mut e ` has been disabled. ``` fn main() { let v = vec![String::from("oh no")]; let e = v[0]; } ``` now gives ``` error[E0507]: cannot move out of indexed content --> example.rs:4:13 | 4 | let e = v[0]; | ^^^^ cannot move out of indexed content error: aborting due to previous error ``` I have added ui tests for the same and also modified a compile-fail test.
- Loading branch information
Showing
7 changed files
with
146 additions
and
19 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
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
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
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,20 @@ | ||
// Copyright 2016 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. | ||
|
||
// Check that we do not suggest `ref f` here in the `main()` function. | ||
struct Foo { | ||
pub v: Vec<String>, | ||
} | ||
|
||
fn main() { | ||
let mut f = Foo { v: Vec::new() }; | ||
f.v.push("hello".to_string()); | ||
let e = f.v[0]; | ||
} |
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[E0507]: cannot move out of indexed content | ||
--> $DIR/issue-40402-1.rs:19:13 | ||
| | ||
19 | let e = f.v[0]; | ||
| ^^^^^^ cannot move out of indexed content | ||
|
||
error: aborting due to previous error | ||
|
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,16 @@ | ||
// Copyright 2016 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. | ||
|
||
// Check that we do suggest `(ref a, ref b)` here, since `a` and `b` | ||
// are nested within a pattern | ||
fn main() { | ||
let x = vec![(String::new(), String::new())]; | ||
let (a, b) = x[0]; | ||
} |
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,11 @@ | ||
error[E0507]: cannot move out of indexed content | ||
--> $DIR/issue-40402-2.rs:15:18 | ||
| | ||
15 | let (a, b) = x[0]; | ||
| - - ^^^^ cannot move out of indexed content | ||
| | | | ||
| | ...and here (use `ref b` or `ref mut b`) | ||
| hint: to prevent move, use `ref a` or `ref mut a` | ||
|
||
error: aborting due to previous error | ||
|