mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-06 04:08:40 +00:00
Rollup merge of #125469 - compiler-errors:dont-skip-inner-const-body, r=cjgillot
Don't skip out of inner const when looking for body for suggestion Self-explanatory title, I'll point out the important logic in an inline comment. Fixes #125370
This commit is contained in:
commit
b65b2b6ced
@ -1871,11 +1871,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
|
|||||||
// If this is due to a block, then maybe we forgot a `return`/`break`.
|
// If this is due to a block, then maybe we forgot a `return`/`break`.
|
||||||
if due_to_block
|
if due_to_block
|
||||||
&& let Some(expr) = expression
|
&& let Some(expr) = expression
|
||||||
&& let Some((parent_fn_decl, parent_id)) = fcx
|
&& let Some(parent_fn_decl) =
|
||||||
.tcx
|
fcx.tcx.hir().fn_decl_by_hir_id(fcx.tcx.local_def_id_to_hir_id(fcx.body_id))
|
||||||
.hir()
|
|
||||||
.parent_iter(block_or_return_id)
|
|
||||||
.find_map(|(_, node)| Some((node.fn_decl()?, node.associated_body()?.0)))
|
|
||||||
{
|
{
|
||||||
fcx.suggest_missing_break_or_return_expr(
|
fcx.suggest_missing_break_or_return_expr(
|
||||||
&mut err,
|
&mut err,
|
||||||
@ -1884,7 +1881,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
|
|||||||
expected,
|
expected,
|
||||||
found,
|
found,
|
||||||
block_or_return_id,
|
block_or_return_id,
|
||||||
parent_id,
|
fcx.body_id,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
9
tests/ui/return/dont-suggest-through-inner-const.rs
Normal file
9
tests/ui/return/dont-suggest-through-inner-const.rs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
const fn f() -> usize {
|
||||||
|
//~^ ERROR mismatched types
|
||||||
|
const FIELD: usize = loop {
|
||||||
|
0
|
||||||
|
//~^ ERROR mismatched types
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
17
tests/ui/return/dont-suggest-through-inner-const.stderr
Normal file
17
tests/ui/return/dont-suggest-through-inner-const.stderr
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/dont-suggest-through-inner-const.rs:4:9
|
||||||
|
|
|
||||||
|
LL | 0
|
||||||
|
| ^ expected `()`, found integer
|
||||||
|
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/dont-suggest-through-inner-const.rs:1:17
|
||||||
|
|
|
||||||
|
LL | const fn f() -> usize {
|
||||||
|
| - ^^^^^ expected `usize`, found `()`
|
||||||
|
| |
|
||||||
|
| implicitly returns `()` as its body has no tail or `return` expression
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0308`.
|
Loading…
Reference in New Issue
Block a user