-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 #99258 - estebank:suggest-let, r=wesleywiser
Provide structured suggestion for dropped temp value
- Loading branch information
Showing
19 changed files
with
220 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// run-rustfix | ||
|
||
use std::collections::HashMap; | ||
|
||
fn main() { | ||
let tmp: Box<_>; | ||
let mut buggy_map: HashMap<usize, &usize> = HashMap::new(); | ||
let binding = Box::new(1); | ||
buggy_map.insert(42, &*binding); //~ ERROR temporary value dropped while borrowed | ||
|
||
// but it is ok if we use a temporary | ||
tmp = Box::new(2); | ||
buggy_map.insert(43, &*tmp); | ||
} |
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 |
---|---|---|
@@ -1,8 +1,6 @@ | ||
use std::collections::HashMap; | ||
|
||
|
||
|
||
// run-rustfix | ||
|
||
use std::collections::HashMap; | ||
|
||
fn main() { | ||
let tmp: Box<_>; | ||
|
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,9 @@ | ||
// run-rustfix | ||
fn id<T>(x: T) -> T { x } | ||
|
||
fn main() { | ||
let x = Some(3); | ||
let binding = id(5); | ||
let y = x.as_ref().unwrap_or(&binding); //~ ERROR | ||
let _ = &y; | ||
} |
3 changes: 2 additions & 1 deletion
3
src/test/ui/issues/issue-11493.rs → src/test/ui/borrowck/issue-11493.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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
// run-rustfix | ||
fn id<T>(x: T) -> T { x } | ||
|
||
fn main() { | ||
let x = Some(3); | ||
let y = x.as_ref().unwrap_or(&id(5)); //~ ERROR | ||
&y; | ||
let _ = &y; | ||
} |
12 changes: 8 additions & 4 deletions
12
src/test/ui/issues/issue-11493.stderr → src/test/ui/borrowck/issue-11493.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
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,17 @@ | ||
// run-rustfix | ||
use std::cell::RefCell; | ||
|
||
fn main() { | ||
let mut r = 0; | ||
let s = 0; | ||
let x = RefCell::new((&mut r,s)); | ||
|
||
let binding = x.borrow(); | ||
let val: &_ = binding.0; | ||
//~^ ERROR temporary value dropped while borrowed [E0716] | ||
//~| NOTE temporary value is freed at the end of this statement | ||
//~| NOTE creates a temporary which is freed while still in use | ||
//~| HELP consider using a `let` binding to create a longer lived value | ||
println!("{}", val); | ||
//~^ borrow later used here | ||
} |
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
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,13 @@ | ||
// run-rustfix | ||
fn main() { | ||
let msg; | ||
let binding = Some("Hello".to_string()); | ||
match binding { | ||
//~^ ERROR temporary value dropped while borrowed | ||
Some(ref m) => { | ||
msg = m; | ||
}, | ||
None => { panic!() } | ||
} | ||
println!("{}", *msg); | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// run-rustfix | ||
fn main() { | ||
let msg; | ||
match Some("Hello".to_string()) { | ||
|
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
Oops, something went wrong.