Skip to content

Merge typeck loop with static/const item eval loop #140854

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 10, 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
4 changes: 0 additions & 4 deletions compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions tests/ui/closures/closure-return-type-mismatch.stderr
Original file line number Diff line number Diff line change
@@ -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
|
Expand All @@ -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`.
30 changes: 15 additions & 15 deletions tests/ui/coercion/coerce-loop-issue-122561.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand Down Expand Up @@ -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
|
Expand Down
24 changes: 12 additions & 12 deletions tests/ui/consts/effect_param.stderr
Original file line number Diff line number Diff line change
@@ -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::<false>(42, 43);
| ^^^^^^^^^^^--------- help: remove the unnecessary generics
LL | i8::checked_sub::<true>(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::<true>(42, 43);
| ^^^^^^^^^^^-------- help: remove the unnecessary generics
LL | i8::checked_sub::<false>(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::<true>(42, 43);
| ^^^^^^^^^^^-------- help: remove the unnecessary generics
LL | i8::checked_sub::<false>(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::<false>(42, 43);
| ^^^^^^^^^^^--------- help: remove the unnecessary generics
LL | i8::checked_sub::<true>(42, 43);
| ^^^^^^^^^^^-------- help: remove the unnecessary generics
| |
| expected 0 generic arguments

Expand Down
30 changes: 15 additions & 15 deletions tests/ui/did_you_mean/dont-suggest-hygienic-fields.stderr
Original file line number Diff line number Diff line change
@@ -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
|
Expand Down Expand Up @@ -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.
Expand Down
16 changes: 8 additions & 8 deletions tests/ui/impl-trait/normalize-tait-in-const.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ LL | pub type Alias<'a> = impl T<Item = &'a ()>;
|
= 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
|
Expand All @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/parser/pat-lt-bracket-6.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ LL | let Test(&desc[..]) = x;
|
= note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch19-00-patterns.html>

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
|
Expand All @@ -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.
Expand Down
26 changes: 13 additions & 13 deletions tests/ui/proc-macro/bad-projection.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/return/dont-suggest-through-inner-const.stderr
Original file line number Diff line number Diff line change
@@ -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
|
Expand All @@ -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`.
36 changes: 18 additions & 18 deletions tests/ui/traits/const-traits/no-explicit-const-params.stderr
Original file line number Diff line number Diff line change
@@ -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::<false>();
| ^^^--------- help: remove the unnecessary generics
LL | foo::<true>();
| ^^^-------- help: remove the unnecessary generics
| |
| expected 0 generic arguments
|
Expand All @@ -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<false>>::bar();
| ^^^------- help: remove the unnecessary generics
LL | <() as Bar<true>>::bar();
| ^^^------ help: remove the unnecessary generics
| |
| expected 0 generic arguments
|
Expand All @@ -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<false>>::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::<true>();
| ^^^-------- help: remove the unnecessary generics
LL | foo::<false>();
| ^^^--------- help: remove the unnecessary generics
| |
| expected 0 generic arguments
|
Expand All @@ -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<true>>::bar();
| ^^^------ help: remove the unnecessary generics
LL | <() as Bar<false>>::bar();
| ^^^------- help: remove the unnecessary generics
| |
| expected 0 generic arguments
|
Expand All @@ -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<false>>::bar();
| ^^

error: aborting due to 5 previous errors

Some errors have detailed explanations: E0107, E0277.
Expand Down
Loading
Loading