about summary refs log tree commit diff
diff options
context:
space:
mode:
authordianne <diannes.gm@gmail.com>2025-05-21 09:17:11 -0700
committerdianne <diannes.gm@gmail.com>2025-05-21 09:17:11 -0700
commit2a403dc81d092ed42edfed48b94ba34c33028ae3 (patch)
tree161247c50e19ac8496ce5c1f59268cf3a5820ed8
parent444a62712a29e14d3b6147b51fd24e623496bf58 (diff)
downloadrust-2a403dc81d092ed42edfed48b94ba34c33028ae3.tar.gz
rust-2a403dc81d092ed42edfed48b94ba34c33028ae3.zip
lower bodies' params to thir before the body's value
-rw-r--r--compiler/rustc_mir_build/src/thir/cx/mod.rs3
-rw-r--r--tests/ui/associated-consts/associated-const-type-parameter-pattern.stderr18
2 files changed, 11 insertions, 10 deletions
diff --git a/compiler/rustc_mir_build/src/thir/cx/mod.rs b/compiler/rustc_mir_build/src/thir/cx/mod.rs
index 2f593b9a0a7..8c817605847 100644
--- a/compiler/rustc_mir_build/src/thir/cx/mod.rs
+++ b/compiler/rustc_mir_build/src/thir/cx/mod.rs
@@ -27,8 +27,8 @@ pub(crate) fn thir_body(
     if let Some(reported) = cx.typeck_results.tainted_by_errors {
         return Err(reported);
     }
-    let expr = cx.mirror_expr(body.value);
 
+    // Lower the params before the body's expression so errors from params are shown first.
     let owner_id = tcx.local_def_id_to_hir_id(owner_def);
     if let Some(fn_decl) = tcx.hir_fn_decl_by_hir_id(owner_id) {
         let closure_env_param = cx.closure_env_param(owner_def, owner_id);
@@ -48,6 +48,7 @@ pub(crate) fn thir_body(
         }
     }
 
+    let expr = cx.mirror_expr(body.value);
     Ok((tcx.alloc_steal_thir(cx.thir), expr))
 }
 
diff --git a/tests/ui/associated-consts/associated-const-type-parameter-pattern.stderr b/tests/ui/associated-consts/associated-const-type-parameter-pattern.stderr
index a8256f775a6..19b63a041d6 100644
--- a/tests/ui/associated-consts/associated-const-type-parameter-pattern.stderr
+++ b/tests/ui/associated-consts/associated-const-type-parameter-pattern.stderr
@@ -27,7 +27,7 @@ LL |         B::X => println!("B::X"),
    |         ^^^^ `const` depends on a generic parameter
 
 error[E0158]: constant pattern cannot depend on generic parameters
-  --> $DIR/associated-const-type-parameter-pattern.rs:30:9
+  --> $DIR/associated-const-type-parameter-pattern.rs:28:48
    |
 LL | pub trait Foo {
    | -------------
@@ -35,13 +35,12 @@ LL |     const X: EFoo;
    |     ------------- constant defined here
 ...
 LL | pub fn test_let_pat<A: Foo, B: Foo>(arg: EFoo, A::X: EFoo) {
-   |                     - constant depends on this generic parameter
-LL |
-LL |     let A::X = arg;
-   |         ^^^^ `const` depends on a generic parameter
+   |                     -                          ^^^^ `const` depends on a generic parameter
+   |                     |
+   |                     constant depends on this generic parameter
 
 error[E0158]: constant pattern cannot depend on generic parameters
-  --> $DIR/associated-const-type-parameter-pattern.rs:28:48
+  --> $DIR/associated-const-type-parameter-pattern.rs:30:9
    |
 LL | pub trait Foo {
    | -------------
@@ -49,9 +48,10 @@ LL |     const X: EFoo;
    |     ------------- constant defined here
 ...
 LL | pub fn test_let_pat<A: Foo, B: Foo>(arg: EFoo, A::X: EFoo) {
-   |                     -                          ^^^^ `const` depends on a generic parameter
-   |                     |
-   |                     constant depends on this generic parameter
+   |                     - constant depends on this generic parameter
+LL |
+LL |     let A::X = arg;
+   |         ^^^^ `const` depends on a generic parameter
 
 error: aborting due to 4 previous errors