forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
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#103276 - compiler-errors:default-on-uninit-…
…ice, r=TaKO8Ki Erase regions before checking for `Default` in uninitialized binding error Fixes rust-lang#103250
- Loading branch information
Showing
3 changed files
with
63 additions
and
2 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,37 @@ | ||
// edition:2021 | ||
|
||
type TranslateFn = Box<dyn Fn(String, String) -> String>; | ||
|
||
pub struct DeviceCluster { | ||
devices: Vec<Device>, | ||
} | ||
|
||
impl DeviceCluster { | ||
pub async fn do_something(&mut self) -> Result<String, Box<dyn std::error::Error>> { | ||
let mut last_error: Box<dyn std::error::Error>; | ||
|
||
for device in &mut self.devices { | ||
match device.do_something().await { | ||
Ok(info) => { | ||
return Ok(info); | ||
} | ||
Err(e) => {} | ||
} | ||
} | ||
|
||
Err(last_error) | ||
//~^ ERROR used binding `last_error` isn't initialized | ||
} | ||
} | ||
|
||
pub struct Device { | ||
translate_fn: Option<TranslateFn>, | ||
} | ||
|
||
impl Device { | ||
pub async fn do_something(&mut self) -> Result<String, Box<dyn std::error::Error>> { | ||
Ok(String::from("")) | ||
} | ||
} | ||
|
||
fn main() {} |
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 @@ | ||
error[E0381]: used binding `last_error` isn't initialized | ||
--> $DIR/issue-103250.rs:22:13 | ||
| | ||
LL | let mut last_error: Box<dyn std::error::Error>; | ||
| -------------- binding declared here but left uninitialized | ||
... | ||
LL | Err(last_error) | ||
| ^^^^^^^^^^ `last_error` used here but it isn't initialized | ||
| | ||
help: consider assigning a value | ||
| | ||
LL | let mut last_error: Box<dyn std::error::Error> = todo!(); | ||
| +++++++++ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0381`. |