mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 00:34:06 +00:00
Rollup merge of #103276 - compiler-errors:default-on-uninit-ice, r=TaKO8Ki
Erase regions before checking for `Default` in uninitialized binding error Fixes #103250
This commit is contained in:
commit
e29ecb70af
@ -492,10 +492,17 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
let Some(default_trait) = tcx.get_diagnostic_item(sym::Default) else {
|
||||
return false;
|
||||
};
|
||||
// Regions are already solved, so we must use a fresh InferCtxt,
|
||||
// but the type has region variables, so erase those.
|
||||
tcx.infer_ctxt()
|
||||
.build()
|
||||
.type_implements_trait(default_trait, ty, ty::List::empty(), param_env)
|
||||
.may_apply()
|
||||
.type_implements_trait(
|
||||
default_trait,
|
||||
tcx.erase_regions(ty),
|
||||
ty::List::empty(),
|
||||
param_env,
|
||||
)
|
||||
.must_apply_modulo_regions()
|
||||
};
|
||||
|
||||
let assign_value = match ty.kind() {
|
||||
|
37
src/test/ui/borrowck/issue-103250.rs
Normal file
37
src/test/ui/borrowck/issue-103250.rs
Normal file
@ -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() {}
|
17
src/test/ui/borrowck/issue-103250.stderr
Normal file
17
src/test/ui/borrowck/issue-103250.stderr
Normal file
@ -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`.
|
Loading…
Reference in New Issue
Block a user