From 0b6e493515d92d4b269eb07c05bf706b64fa5db8 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 9 May 2025 15:16:26 +0000 Subject: [PATCH] Merge typeck loop with static/const item eval loop --- compiler/rustc_hir_analysis/src/lib.rs | 4 --- .../closure-return-type-mismatch.stderr | 16 ++++----- .../coercion/coerce-loop-issue-122561.stderr | 30 ++++++++-------- tests/ui/consts/effect_param.stderr | 24 ++++++------- .../dont-suggest-hygienic-fields.stderr | 30 ++++++++-------- .../impl-trait/normalize-tait-in-const.stderr | 16 ++++----- tests/ui/parser/pat-lt-bracket-6.stderr | 12 +++---- tests/ui/proc-macro/bad-projection.stderr | 26 +++++++------- .../dont-suggest-through-inner-const.stderr | 12 +++---- .../no-explicit-const-params.stderr | 36 +++++++++---------- tests/ui/transmutability/uninhabited.stderr | 36 +++++++++---------- 11 files changed, 119 insertions(+), 123 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index 91dde13be550e..d010f1fc85164 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -223,10 +223,6 @@ pub fn check_crate(tcx: TyCtxt<'_>) { } _ => (), } - }); - - tcx.par_hir_body_owners(|item_def_id| { - let def_kind = tcx.def_kind(item_def_id); // Skip `AnonConst`s because we feed their `type_of`. if !matches!(def_kind, DefKind::AnonConst) { tcx.ensure_ok().typeck(item_def_id); diff --git a/tests/ui/closures/closure-return-type-mismatch.stderr b/tests/ui/closures/closure-return-type-mismatch.stderr index 052bbbb5ed579..f9587d8dad1de 100644 --- a/tests/ui/closures/closure-return-type-mismatch.stderr +++ b/tests/ui/closures/closure-return-type-mismatch.stderr @@ -1,11 +1,3 @@ -error[E0308]: mismatched types - --> $DIR/closure-return-type-mismatch.rs:20:41 - | -LL | static FOO: fn() -> bool = || -> bool { 1 }; - | ---- ^ expected `bool`, found integer - | | - | expected `bool` because of return type - error[E0308]: mismatched types --> $DIR/closure-return-type-mismatch.rs:7:9 | @@ -27,6 +19,14 @@ LL | if false { LL | return "hello" | ^^^^^^^ expected `bool`, found `&str` +error[E0308]: mismatched types + --> $DIR/closure-return-type-mismatch.rs:20:41 + | +LL | static FOO: fn() -> bool = || -> bool { 1 }; + | ---- ^ expected `bool`, found integer + | | + | expected `bool` because of return type + error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/coercion/coerce-loop-issue-122561.stderr b/tests/ui/coercion/coerce-loop-issue-122561.stderr index 3af7e7cddb31d..6415fd554cba9 100644 --- a/tests/ui/coercion/coerce-loop-issue-122561.stderr +++ b/tests/ui/coercion/coerce-loop-issue-122561.stderr @@ -24,21 +24,6 @@ help: consider returning a value here LL | fn for_in_arg(a: &[(); for x in 0..2 {} /* `usize` value */]) -> bool { | +++++++++++++++++++ -error[E0308]: mismatched types - --> $DIR/coerce-loop-issue-122561.rs:85:5 - | -LL | / for i in 0.. { -LL | | -LL | | } - | |_____^ expected `i32`, found `()` - | - = note: `for` loops evaluate to unit type `()` -help: consider returning a value here - | -LL ~ } -LL + /* `i32` value */ - | - error[E0308]: mismatched types --> $DIR/coerce-loop-issue-122561.rs:4:5 | @@ -202,6 +187,21 @@ LL ~ } LL + /* `loop {}` or `panic!("...")` */ | +error[E0308]: mismatched types + --> $DIR/coerce-loop-issue-122561.rs:85:5 + | +LL | / for i in 0.. { +LL | | +LL | | } + | |_____^ expected `i32`, found `()` + | + = note: `for` loops evaluate to unit type `()` +help: consider returning a value here + | +LL ~ } +LL + /* `i32` value */ + | + error[E0308]: mismatched types --> $DIR/coerce-loop-issue-122561.rs:92:9 | diff --git a/tests/ui/consts/effect_param.stderr b/tests/ui/consts/effect_param.stderr index c63be8035f30f..a20092dbf047a 100644 --- a/tests/ui/consts/effect_param.stderr +++ b/tests/ui/consts/effect_param.stderr @@ -1,32 +1,32 @@ error[E0107]: method takes 0 generic arguments but 1 generic argument was supplied - --> $DIR/effect_param.rs:11:9 + --> $DIR/effect_param.rs:4:9 | -LL | i8::checked_sub::(42, 43); - | ^^^^^^^^^^^--------- help: remove the unnecessary generics +LL | i8::checked_sub::(42, 43); + | ^^^^^^^^^^^-------- help: remove the unnecessary generics | | | expected 0 generic arguments error[E0107]: method takes 0 generic arguments but 1 generic argument was supplied - --> $DIR/effect_param.rs:13:9 + --> $DIR/effect_param.rs:6:9 | -LL | i8::checked_sub::(42, 43); - | ^^^^^^^^^^^-------- help: remove the unnecessary generics +LL | i8::checked_sub::(42, 43); + | ^^^^^^^^^^^--------- help: remove the unnecessary generics | | | expected 0 generic arguments error[E0107]: method takes 0 generic arguments but 1 generic argument was supplied - --> $DIR/effect_param.rs:4:9 + --> $DIR/effect_param.rs:11:9 | -LL | i8::checked_sub::(42, 43); - | ^^^^^^^^^^^-------- help: remove the unnecessary generics +LL | i8::checked_sub::(42, 43); + | ^^^^^^^^^^^--------- help: remove the unnecessary generics | | | expected 0 generic arguments error[E0107]: method takes 0 generic arguments but 1 generic argument was supplied - --> $DIR/effect_param.rs:6:9 + --> $DIR/effect_param.rs:13:9 | -LL | i8::checked_sub::(42, 43); - | ^^^^^^^^^^^--------- help: remove the unnecessary generics +LL | i8::checked_sub::(42, 43); + | ^^^^^^^^^^^-------- help: remove the unnecessary generics | | | expected 0 generic arguments diff --git a/tests/ui/did_you_mean/dont-suggest-hygienic-fields.stderr b/tests/ui/did_you_mean/dont-suggest-hygienic-fields.stderr index 411eec8496339..08166355748b5 100644 --- a/tests/ui/did_you_mean/dont-suggest-hygienic-fields.stderr +++ b/tests/ui/did_you_mean/dont-suggest-hygienic-fields.stderr @@ -1,18 +1,3 @@ -error[E0560]: struct `Crate` has no field named `fiel` - --> $DIR/dont-suggest-hygienic-fields.rs:44:34 - | -LL | environment!(); - | -------------- in this macro invocation -... -LL | const CRATE: Crate = Crate { fiel: () }; - | ^^^^ unknown field - | - = note: this error originates in the macro `environment` (in Nightly builds, run with -Z macro-backtrace for more info) -help: a field with a similar name exists - | -LL | const CRATE: Crate = Crate { field: () }; - | + - error[E0609]: no field `field` on type `Compound` --> $DIR/dont-suggest-hygienic-fields.rs:24:16 | @@ -48,6 +33,21 @@ error[E0609]: no field `0` on type `Component` LL | let _ = ty.0; | ^ unknown field +error[E0560]: struct `Crate` has no field named `fiel` + --> $DIR/dont-suggest-hygienic-fields.rs:44:34 + | +LL | environment!(); + | -------------- in this macro invocation +... +LL | const CRATE: Crate = Crate { fiel: () }; + | ^^^^ unknown field + | + = note: this error originates in the macro `environment` (in Nightly builds, run with -Z macro-backtrace for more info) +help: a field with a similar name exists + | +LL | const CRATE: Crate = Crate { field: () }; + | + + error: aborting due to 6 previous errors Some errors have detailed explanations: E0026, E0560, E0609. diff --git a/tests/ui/impl-trait/normalize-tait-in-const.stderr b/tests/ui/impl-trait/normalize-tait-in-const.stderr index d4ba9a3117022..2b6825b1ac672 100644 --- a/tests/ui/impl-trait/normalize-tait-in-const.stderr +++ b/tests/ui/impl-trait/normalize-tait-in-const.stderr @@ -25,14 +25,6 @@ LL | pub type Alias<'a> = impl T; | = note: `Alias` must be used in combination with a concrete type within the same crate -error[E0015]: cannot call non-const closure in constant functions - --> $DIR/normalize-tait-in-const.rs:28:5 - | -LL | fun(filter_positive()); - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - error[E0308]: mismatched types --> $DIR/normalize-tait-in-const.rs:22:9 | @@ -52,6 +44,14 @@ note: this item must have a `#[define_opaque(foo::Alias)]` attribute to be able LL | pub const fn filter_positive<'a>() -> &'a Alias<'a> { | ^^^^^^^^^^^^^^^ +error[E0015]: cannot call non-const closure in constant functions + --> $DIR/normalize-tait-in-const.rs:28:5 + | +LL | fun(filter_positive()); + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants + error: aborting due to 5 previous errors Some errors have detailed explanations: E0015, E0308. diff --git a/tests/ui/parser/pat-lt-bracket-6.stderr b/tests/ui/parser/pat-lt-bracket-6.stderr index 0274809f800c5..83c88d1085ef8 100644 --- a/tests/ui/parser/pat-lt-bracket-6.stderr +++ b/tests/ui/parser/pat-lt-bracket-6.stderr @@ -6,12 +6,6 @@ LL | let Test(&desc[..]) = x; | = note: arbitrary expressions are not allowed in patterns: -error[E0308]: mismatched types - --> $DIR/pat-lt-bracket-6.rs:10:30 - | -LL | const RECOVERY_WITNESS: () = 0; - | ^ expected `()`, found integer - error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 2 fields --> $DIR/pat-lt-bracket-6.rs:5:14 | @@ -26,6 +20,12 @@ help: use `_` to explicitly ignore each field LL | let Test(&desc[..], _) = x; | +++ +error[E0308]: mismatched types + --> $DIR/pat-lt-bracket-6.rs:10:30 + | +LL | const RECOVERY_WITNESS: () = 0; + | ^ expected `()`, found integer + error: aborting due to 3 previous errors Some errors have detailed explanations: E0023, E0308. diff --git a/tests/ui/proc-macro/bad-projection.stderr b/tests/ui/proc-macro/bad-projection.stderr index aa6b3da6da995..f2981499367b8 100644 --- a/tests/ui/proc-macro/bad-projection.stderr +++ b/tests/ui/proc-macro/bad-projection.stderr @@ -10,6 +10,19 @@ help: this trait has no implementations, consider adding one LL | trait Project { | ^^^^^^^^^^^^^ +error[E0277]: the trait bound `(): Project` is not satisfied + --> $DIR/bad-projection.rs:14:17 + | +LL | pub fn uwu() -> <() as Project>::Assoc {} + | ^^^^^^^^^^^^^^^^^^^^^^ the trait `Project` is not implemented for `()` + | +help: this trait has no implementations, consider adding one + --> $DIR/bad-projection.rs:9:1 + | +LL | trait Project { + | ^^^^^^^^^^^^^ + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + error[E0593]: function is expected to take 1 argument, but it takes 0 arguments --> $DIR/bad-projection.rs:14:1 | @@ -47,19 +60,6 @@ help: this trait has no implementations, consider adding one LL | trait Project { | ^^^^^^^^^^^^^ -error[E0277]: the trait bound `(): Project` is not satisfied - --> $DIR/bad-projection.rs:14:17 - | -LL | pub fn uwu() -> <() as Project>::Assoc {} - | ^^^^^^^^^^^^^^^^^^^^^^ the trait `Project` is not implemented for `()` - | -help: this trait has no implementations, consider adding one - --> $DIR/bad-projection.rs:9:1 - | -LL | trait Project { - | ^^^^^^^^^^^^^ - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - error: aborting due to 5 previous errors Some errors have detailed explanations: E0277, E0593. diff --git a/tests/ui/return/dont-suggest-through-inner-const.stderr b/tests/ui/return/dont-suggest-through-inner-const.stderr index 6aeee74b0adf9..fc98b7373754e 100644 --- a/tests/ui/return/dont-suggest-through-inner-const.stderr +++ b/tests/ui/return/dont-suggest-through-inner-const.stderr @@ -1,9 +1,3 @@ -error[E0308]: mismatched types - --> $DIR/dont-suggest-through-inner-const.rs:4:9 - | -LL | 0 - | ^ expected `()`, found integer - error[E0308]: mismatched types --> $DIR/dont-suggest-through-inner-const.rs:1:17 | @@ -12,6 +6,12 @@ LL | const fn f() -> usize { | | | implicitly returns `()` as its body has no tail or `return` expression +error[E0308]: mismatched types + --> $DIR/dont-suggest-through-inner-const.rs:4:9 + | +LL | 0 + | ^ expected `()`, found integer + error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/traits/const-traits/no-explicit-const-params.stderr b/tests/ui/traits/const-traits/no-explicit-const-params.stderr index 9bd2c2cb8da2a..6955e9ab2985d 100644 --- a/tests/ui/traits/const-traits/no-explicit-const-params.stderr +++ b/tests/ui/traits/const-traits/no-explicit-const-params.stderr @@ -1,8 +1,8 @@ error[E0107]: function takes 0 generic arguments but 1 generic argument was supplied - --> $DIR/no-explicit-const-params.rs:22:5 + --> $DIR/no-explicit-const-params.rs:15:5 | -LL | foo::(); - | ^^^--------- help: remove the unnecessary generics +LL | foo::(); + | ^^^-------- help: remove the unnecessary generics | | | expected 0 generic arguments | @@ -13,10 +13,10 @@ LL | const fn foo() {} | ^^^ error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied - --> $DIR/no-explicit-const-params.rs:24:12 + --> $DIR/no-explicit-const-params.rs:17:12 | -LL | <() as Bar>::bar(); - | ^^^------- help: remove the unnecessary generics +LL | <() as Bar>::bar(); + | ^^^------ help: remove the unnecessary generics | | | expected 0 generic arguments | @@ -26,17 +26,11 @@ note: trait defined here, with 0 generic parameters LL | trait Bar { | ^^^ -error[E0277]: the trait bound `(): const Bar` is not satisfied - --> $DIR/no-explicit-const-params.rs:24:6 - | -LL | <() as Bar>::bar(); - | ^^ - error[E0107]: function takes 0 generic arguments but 1 generic argument was supplied - --> $DIR/no-explicit-const-params.rs:15:5 + --> $DIR/no-explicit-const-params.rs:22:5 | -LL | foo::(); - | ^^^-------- help: remove the unnecessary generics +LL | foo::(); + | ^^^--------- help: remove the unnecessary generics | | | expected 0 generic arguments | @@ -47,10 +41,10 @@ LL | const fn foo() {} | ^^^ error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied - --> $DIR/no-explicit-const-params.rs:17:12 + --> $DIR/no-explicit-const-params.rs:24:12 | -LL | <() as Bar>::bar(); - | ^^^------ help: remove the unnecessary generics +LL | <() as Bar>::bar(); + | ^^^------- help: remove the unnecessary generics | | | expected 0 generic arguments | @@ -60,6 +54,12 @@ note: trait defined here, with 0 generic parameters LL | trait Bar { | ^^^ +error[E0277]: the trait bound `(): const Bar` is not satisfied + --> $DIR/no-explicit-const-params.rs:24:6 + | +LL | <() as Bar>::bar(); + | ^^ + error: aborting due to 5 previous errors Some errors have detailed explanations: E0107, E0277. diff --git a/tests/ui/transmutability/uninhabited.stderr b/tests/ui/transmutability/uninhabited.stderr index 4c5c4107a852a..3044b502d3146 100644 --- a/tests/ui/transmutability/uninhabited.stderr +++ b/tests/ui/transmutability/uninhabited.stderr @@ -1,21 +1,3 @@ -error[E0080]: evaluation of constant value failed - --> $DIR/uninhabited.rs:41:9 - | -LL | assert!(false); - | ^^^^^^^^^^^^^^ evaluation panicked: assertion failed: false - -error[E0080]: evaluation of constant value failed - --> $DIR/uninhabited.rs:63:9 - | -LL | assert!(false); - | ^^^^^^^^^^^^^^ evaluation panicked: assertion failed: false - -error[E0080]: evaluation of constant value failed - --> $DIR/uninhabited.rs:87:9 - | -LL | assert!(false); - | ^^^^^^^^^^^^^^ evaluation panicked: assertion failed: false - error[E0277]: `()` cannot be safely transmuted into `void::Void` --> $DIR/uninhabited.rs:29:41 | @@ -58,6 +40,12 @@ LL | | lifetimes: true, LL | | }> | |__________^ required by this bound in `is_maybe_transmutable` +error[E0080]: evaluation of constant value failed + --> $DIR/uninhabited.rs:41:9 + | +LL | assert!(false); + | ^^^^^^^^^^^^^^ evaluation panicked: assertion failed: false + error[E0277]: `()` cannot be safely transmuted into `yawning_void_enum::Void` --> $DIR/uninhabited.rs:71:41 | @@ -79,6 +67,12 @@ LL | | lifetimes: true, LL | | }> | |__________^ required by this bound in `is_maybe_transmutable` +error[E0080]: evaluation of constant value failed + --> $DIR/uninhabited.rs:63:9 + | +LL | assert!(false); + | ^^^^^^^^^^^^^^ evaluation panicked: assertion failed: false + error[E0277]: `u128` cannot be safely transmuted into `DistantVoid` --> $DIR/uninhabited.rs:92:43 | @@ -100,6 +94,12 @@ LL | | lifetimes: true, LL | | }> | |__________^ required by this bound in `is_maybe_transmutable` +error[E0080]: evaluation of constant value failed + --> $DIR/uninhabited.rs:87:9 + | +LL | assert!(false); + | ^^^^^^^^^^^^^^ evaluation panicked: assertion failed: false + error[E0277]: `Src` cannot be safely transmuted into `issue_126267::Error` --> $DIR/uninhabited.rs:108:42 |