Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb65b2b6

Browse files
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 suggestionSelf-explanatory title, I'll point out the important logic in an inline comment.Fixes#125370
2 parents09e7592 +c58b7c9 commitb65b2b6

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

‎compiler/rustc_hir_typeck/src/coercion.rs‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,11 +1871,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
18711871
// If this is due to a block, then maybe we forgot a `return`/`break`.
18721872
if due_to_block
18731873
&&letSome(expr) = expression
1874-
&&letSome((parent_fn_decl, parent_id)) = fcx
1875-
.tcx
1876-
.hir()
1877-
.parent_iter(block_or_return_id)
1878-
.find_map(|(_, node)|Some((node.fn_decl()?, node.associated_body()?.0)))
1874+
&&letSome(parent_fn_decl) =
1875+
fcx.tcx.hir().fn_decl_by_hir_id(fcx.tcx.local_def_id_to_hir_id(fcx.body_id))
18791876
{
18801877
fcx.suggest_missing_break_or_return_expr(
18811878
&mut err,
@@ -1884,7 +1881,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
18841881
expected,
18851882
found,
18861883
block_or_return_id,
1887-
parent_id,
1884+
fcx.body_id,
18881885
);
18891886
}
18901887

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
constfnf() ->usize{
2+
//~^ ERROR mismatched types
3+
constFIELD:usize =loop{
4+
0
5+
//~^ ERROR mismatched types
6+
};
7+
}
8+
9+
fnmain(){}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/dont-suggest-through-inner-const.rs:4:9
3+
|
4+
LL | 0
5+
| ^ expected `()`, found integer
6+
7+
error[E0308]: mismatched types
8+
--> $DIR/dont-suggest-through-inner-const.rs:1:17
9+
|
10+
LL | const fn f() -> usize {
11+
| - ^^^^^ expected `usize`, found `()`
12+
| |
13+
| implicitly returns `()` as its body has no tail or `return` expression
14+
15+
error: aborting due to 2 previous errors
16+
17+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp