Skip to content

lower bodies' params to thir before the body's value #141356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/rustc_mir_build/src/thir/cx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -48,6 +48,7 @@ pub(crate) fn thir_body(
}
}

let expr = cx.mirror_expr(body.value);
Ok((tcx.alloc_steal_thir(cx.thir), expr))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,31 @@ 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 {
| -------------
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 {
| -------------
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

Expand Down
Loading