mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Rollup merge of #112024 - compiler-errors:dont-break-thru-item, r=WaffleLapkin
Don't suggest break through nested items Fixes #112020
This commit is contained in:
commit
02c4b4b279
@ -874,7 +874,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
let found = self.resolve_vars_with_obligations(found);
|
||||
|
||||
let in_loop = self.is_loop(id)
|
||||
|| self.tcx.hir().parent_iter(id).any(|(parent_id, _)| self.is_loop(parent_id));
|
||||
|| self
|
||||
.tcx
|
||||
.hir()
|
||||
.parent_iter(id)
|
||||
.take_while(|(_, node)| {
|
||||
// look at parents until we find the first body owner
|
||||
node.body_id().is_none()
|
||||
})
|
||||
.any(|(parent_id, _)| self.is_loop(parent_id));
|
||||
|
||||
let in_local_statement = self.is_local_statement(id)
|
||||
|| self
|
||||
|
55
tests/ui/loops/dont-suggest-break-thru-item.rs
Normal file
55
tests/ui/loops/dont-suggest-break-thru-item.rs
Normal file
@ -0,0 +1,55 @@
|
||||
// edition:2021
|
||||
|
||||
#![feature(inline_const)]
|
||||
|
||||
fn closure() {
|
||||
loop {
|
||||
let closure = || {
|
||||
if true {
|
||||
Err(1)
|
||||
//~^ ERROR mismatched types
|
||||
}
|
||||
|
||||
Ok(())
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn async_block() {
|
||||
loop {
|
||||
let fut = async {
|
||||
if true {
|
||||
Err(1)
|
||||
//~^ ERROR mismatched types
|
||||
}
|
||||
|
||||
Ok(())
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn fn_item() {
|
||||
let _ = loop {
|
||||
fn foo() -> Result<(), ()> {
|
||||
if true {
|
||||
Err(1)
|
||||
//~^ ERROR mismatched types
|
||||
}
|
||||
Err(())
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
fn const_block() {
|
||||
let _ = loop {
|
||||
const {
|
||||
if true {
|
||||
Err(1)
|
||||
//~^ ERROR mismatched types
|
||||
}
|
||||
Err(())
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
fn main() {}
|
55
tests/ui/loops/dont-suggest-break-thru-item.stderr
Normal file
55
tests/ui/loops/dont-suggest-break-thru-item.stderr
Normal file
@ -0,0 +1,55 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/dont-suggest-break-thru-item.rs:9:17
|
||||
|
|
||||
LL | / if true {
|
||||
LL | | Err(1)
|
||||
| | ^^^^^^ expected `()`, found `Result<_, {integer}>`
|
||||
LL | |
|
||||
LL | | }
|
||||
| |_____________- expected this to be `()`
|
||||
|
|
||||
= note: expected unit type `()`
|
||||
found enum `Result<_, {integer}>`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/dont-suggest-break-thru-item.rs:22:17
|
||||
|
|
||||
LL | / if true {
|
||||
LL | | Err(1)
|
||||
| | ^^^^^^ expected `()`, found `Result<_, {integer}>`
|
||||
LL | |
|
||||
LL | | }
|
||||
| |_____________- expected this to be `()`
|
||||
|
|
||||
= note: expected unit type `()`
|
||||
found enum `Result<_, {integer}>`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/dont-suggest-break-thru-item.rs:35:17
|
||||
|
|
||||
LL | / if true {
|
||||
LL | | Err(1)
|
||||
| | ^^^^^^ expected `()`, found `Result<_, {integer}>`
|
||||
LL | |
|
||||
LL | | }
|
||||
| |_____________- expected this to be `()`
|
||||
|
|
||||
= note: expected unit type `()`
|
||||
found enum `Result<_, {integer}>`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/dont-suggest-break-thru-item.rs:47:17
|
||||
|
|
||||
LL | / if true {
|
||||
LL | | Err(1)
|
||||
| | ^^^^^^ expected `()`, found `Result<_, {integer}>`
|
||||
LL | |
|
||||
LL | | }
|
||||
| |_____________- expected this to be `()`
|
||||
|
|
||||
= note: expected unit type `()`
|
||||
found enum `Result<_, {integer}>`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
Loading…
Reference in New Issue
Block a user