Skip to content

Commit 2a403dc

Browse files
committed
lower bodies' params to thir before the body's value
1 parent 444a627 commit 2a403dc

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

compiler/rustc_mir_build/src/thir/cx/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ pub(crate) fn thir_body(
2727
if let Some(reported) = cx.typeck_results.tainted_by_errors {
2828
return Err(reported);
2929
}
30-
let expr = cx.mirror_expr(body.value);
3130

31+
// Lower the params before the body's expression so errors from params are shown first.
3232
let owner_id = tcx.local_def_id_to_hir_id(owner_def);
3333
if let Some(fn_decl) = tcx.hir_fn_decl_by_hir_id(owner_id) {
3434
let closure_env_param = cx.closure_env_param(owner_def, owner_id);
@@ -48,6 +48,7 @@ pub(crate) fn thir_body(
4848
}
4949
}
5050

51+
let expr = cx.mirror_expr(body.value);
5152
Ok((tcx.alloc_steal_thir(cx.thir), expr))
5253
}
5354

tests/ui/associated-consts/associated-const-type-parameter-pattern.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,31 @@ LL | B::X => println!("B::X"),
2727
| ^^^^ `const` depends on a generic parameter
2828

2929
error[E0158]: constant pattern cannot depend on generic parameters
30-
--> $DIR/associated-const-type-parameter-pattern.rs:30:9
30+
--> $DIR/associated-const-type-parameter-pattern.rs:28:48
3131
|
3232
LL | pub trait Foo {
3333
| -------------
3434
LL | const X: EFoo;
3535
| ------------- constant defined here
3636
...
3737
LL | pub fn test_let_pat<A: Foo, B: Foo>(arg: EFoo, A::X: EFoo) {
38-
| - constant depends on this generic parameter
39-
LL |
40-
LL | let A::X = arg;
41-
| ^^^^ `const` depends on a generic parameter
38+
| - ^^^^ `const` depends on a generic parameter
39+
| |
40+
| constant depends on this generic parameter
4241

4342
error[E0158]: constant pattern cannot depend on generic parameters
44-
--> $DIR/associated-const-type-parameter-pattern.rs:28:48
43+
--> $DIR/associated-const-type-parameter-pattern.rs:30:9
4544
|
4645
LL | pub trait Foo {
4746
| -------------
4847
LL | const X: EFoo;
4948
| ------------- constant defined here
5049
...
5150
LL | pub fn test_let_pat<A: Foo, B: Foo>(arg: EFoo, A::X: EFoo) {
52-
| - ^^^^ `const` depends on a generic parameter
53-
| |
54-
| constant depends on this generic parameter
51+
| - constant depends on this generic parameter
52+
LL |
53+
LL | let A::X = arg;
54+
| ^^^^ `const` depends on a generic parameter
5555

5656
error: aborting due to 4 previous errors
5757

0 commit comments

Comments
 (0)