File tree Expand file tree Collapse file tree 2 files changed +11
-10
lines changed
compiler/rustc_mir_build/src/thir/cx
tests/ui/associated-consts Expand file tree Collapse file tree 2 files changed +11
-10
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -27,31 +27,31 @@ LL | B::X => println!("B::X"),
2727 | ^^^^ `const` depends on a generic parameter
2828
2929error[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 |
3232LL | pub trait Foo {
3333 | -------------
3434LL | const X: EFoo;
3535 | ------------- constant defined here
3636...
3737LL | 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
4342error[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 |
4645LL | pub trait Foo {
4746 | -------------
4847LL | const X: EFoo;
4948 | ------------- constant defined here
5049...
5150LL | 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
5656error: aborting due to 4 previous errors
5757
You can’t perform that action at this time.
0 commit comments