Skip to content

tests: rustc_public: Check const allocation for all variables (1 of 11 was missing)#152628

Open
Enselic wants to merge 1 commit intorust-lang:mainfrom
Enselic:ptr-const-allocation
Open

tests: rustc_public: Check const allocation for all variables (1 of 11 was missing)#152628
Enselic wants to merge 1 commit intorust-lang:mainfrom
Enselic:ptr-const-allocation

Conversation

@Enselic
Copy link
Member

@Enselic Enselic commented Feb 14, 2026

In the test tests/ui-fulldeps/rustc_public/check_allocation.rs there is a check for constant allocations of local variables of this function:

fn other_consts() {{
    let _max_u128 = u128::MAX;
    let _min_i128 = i128::MIN;
    let _max_i8 = i8::MAX;
    let _char = 'x';
    let _false = false;
    let _true = true;
    let _ptr = &BAR;
    let _null_ptr: *const u8 = NULL;
    let _tuple = TUPLE;
    let _char_id = const {{ type_id::<char>() }};
    let _bool_id = const {{ type_id::<bool>() }};
}}

The current test only finds 10 out of 11 allocations. The constant allocation for

let _ptr = &BAR;

is not checked, because the SingleUseConsts MIR pass does not optimize away that assignment. Add code to also collect constant allocation from assignment rvalues to find the constant allocation for that last variable.

Not only does this change make sense on its own, it also makes the test pass both with and without the SingleUseConsts pass.

Discovered while investigating ways to avoid this tests/ui-fulldeps/rustc_public/check_allocation.rs hack from #151426 which wants to stop running SingleUseConsts for non-optimized builds.

…1 was missing)

In the test `tests/ui-fulldeps/rustc_public/check_allocation.rs` there
is a check for constant allocations of local variables of this function:

    fn other_consts() {{
        let _max_u128 = u128::MAX;
        let _min_i128 = i128::MIN;
        let _max_i8 = i8::MAX;
        let _char = 'x';
        let _false = false;
        let _true = true;
        let _ptr = &BAR;
        let _null_ptr: *const u8 = NULL;
        let _tuple = TUPLE;
        let _char_id = const {{ type_id::<char>() }};
        let _bool_id = const {{ type_id::<bool>() }};
    }}

The current test only finds 10 out of 11 allocations. The constant
allocation for

    let _ptr = &BAR;

is not checked, because the `SingleUseConsts` MIR pass does not optimize
away that assignment. Add code to also collect constant allocation from
assignment rvalues. Not only does this change make sense on its own, it
also makes the test pass both with and without the `SingleUseConsts`
pass.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 14, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 14, 2026

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Fallback group: @Mark-Simulacrum, @jieyouxu
  • @Mark-Simulacrum, @jieyouxu expanded to Mark-Simulacrum, jieyouxu

@Mark-Simulacrum
Copy link
Member

r? compiler

@chenyukang
Copy link
Member

@bors reroll

@rust-bors

This comment has been minimized.

@chenyukang
Copy link
Member

@rustbot reroll

@chenyukang
Copy link
Member

oops, assign the same reviwer

@rustbot reroll

@rustbot

This comment has been minimized.

@jieyouxu
Copy link
Member

r? me

@rustbot rustbot assigned jieyouxu and unassigned Mark-Simulacrum Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants