Skip to content

layout: handle rigid aliases without params#151814

Merged
rust-bors[bot] merged 3 commits intorust-lang:mainfrom
lcnr:silent-layout-error
Feb 12, 2026
Merged

layout: handle rigid aliases without params#151814
rust-bors[bot] merged 3 commits intorust-lang:mainfrom
lcnr:silent-layout-error

Conversation

@lcnr
Copy link
Contributor

@lcnr lcnr commented Jan 29, 2026

fixes #151791

r? types

@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 Jan 29, 2026
@rustbot

This comment has been minimized.

@lcnr lcnr added beta-nominated Nominated for backporting to the compiler in the beta channel. stable-nominated Nominated for backporting to the compiler in the stable channel. labels Jan 29, 2026
@lcnr lcnr force-pushed the silent-layout-error branch 2 times, most recently from bb2a5e1 to 3b7aeda Compare January 29, 2026 10:54
@lcnr lcnr force-pushed the silent-layout-error branch from 3b7aeda to 4bb3f0a Compare January 29, 2026 10:55
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. label Jan 29, 2026
@lcnr lcnr force-pushed the silent-layout-error branch from 27d6dbd to 0035ae3 Compare January 29, 2026 13:02
// Due to trivial bounds, this can even be the case if the alias does not reference
// any generic parameters, e.g. a `for<'a> u32: Trait<'a>` where-bound means that
// `<u32 as Trait<'static>>::Assoc` is rigid.
let err = if ty.has_param() || !cx.typing_env.param_env.caller_bounds().is_empty() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a weird fix? Like, just because there were where clauses, doesn't mean they they were even relevant to the alias, right? Like, this would mean that <u32 as Trait<'static>>::Assoc would be "too generic", if there is a where clause like where u8: Foo, but "unknown" if there isn't that bound, even though that where clause seemingly makes no difference?

I'm not sure I have a better easy solution in mind. As a heuristic, we could see if there is a bound like X: Y<...> if the alias is <X as Y<...>>::Z - this is not quite enough, because that doesn't guarantee that it could be normalized even if not too-generic, but is better than a blank check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I don't care as the else branch is actually unreachable as normalization should have failed for non-wf aliases, so the only way you can get an alias in layout_of is if it is still rigid.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 6, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 6, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before 5dfbf67 (the commit that revealed the bug this fixes) we had this in the middle of borrowck:

            &Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, ty) => {
                let trait_ref =
                    ty::TraitRef::new(tcx, tcx.require_lang_item(LangItem::Sized, span), [ty]);

                self.prove_trait_ref(
                    trait_ref,
                    location.to_locations(),
                    ConstraintCategory::SizedBound,
                );
            }

Was that .prove_trait_ref(..., ..., ConstraintCategory::SizedBound) what was "rescuing" this code from having to think about this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, the code broken by his compiled previously and this check could have at most resulted in errors.

The reason this regressed is that we've added new associated constants to the standard library causing us to evaluate things and to check their layout in more places

lcnr added 2 commits February 10, 2026 18:00
aliases may be rigid even if they don't reference params. If the alias isn't well-formed, trying to normalize it as part of the input should have already failed
@lcnr lcnr force-pushed the silent-layout-error branch from 0035ae3 to 337abba Compare February 10, 2026 18:01
@jackh726
Copy link
Member

So, !cx.typing_env.param_env.caller_bounds().is_empty() is still too weak - but I'm okay to land this.

r=me if you aren't concerned @lcnr

@lcnr
Copy link
Contributor Author

lcnr commented Feb 10, 2026

The only thing this accepting too much code is that we are not guaranteed to ICE when encountering a bug.

That seems acceptable to me.

@bors r=jackh726

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 10, 2026

📌 Commit 337abba has been approved by jackh726

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 10, 2026
Zalathar added a commit to Zalathar/rust that referenced this pull request Feb 11, 2026
layout: handle rigid aliases without params

fixes rust-lang#151791

r? types
Zalathar added a commit to Zalathar/rust that referenced this pull request Feb 11, 2026
layout: handle rigid aliases without params

fixes rust-lang#151791

r? types
Zalathar added a commit to Zalathar/rust that referenced this pull request Feb 12, 2026
layout: handle rigid aliases without params

fixes rust-lang#151791

r? types
rust-bors bot pushed a commit that referenced this pull request Feb 12, 2026
Rollup of 17 pull requests

Successful merges:

 - #142415 (Add note when inherent impl for a alias type defined outside of the crate)
 - #142680 (Fix passing/returning structs with the 64-bit SPARC ABI)
 - #150768 (Don't compute FnAbi for LLVM intrinsics in backends)
 - #151152 (Add FCW for derive helper attributes that will conflict with built-in attributes)
 - #151814 (layout: handle rigid aliases without params)
 - #151863 (Borrowck: simplify diagnostics for placeholders)
 - #152159 (Add note for `?Sized` params in int-ptr casts diag)
 - #152434 (Clarify names of `QueryVTable` functions for "executing" a query)
 - #152478 (Remove tm_factory field from CodegenContext)
 - #152498 (Partially revert "resolve: Update `NameBindingData::vis` in place")
 - #152316 (fix: add continue)
 - #152394 (Correctly check if a macro call is actually a macro call in rustdoc highlighter)
 - #152425 (Port #![test_runner] to the attribute parser)
 - #152481 (Use cg_ssa's produce_final_output_artifacts in cg_clif)
 - #152485 (fix issue#152482)
 - #152495 (Clean up some subdiagnostics)
 - #152502 (Implement `BinaryHeap::from_raw_vec`)
@rust-bors rust-bors bot merged commit 3db13e2 into rust-lang:main Feb 12, 2026
11 checks passed
rust-timer added a commit that referenced this pull request Feb 12, 2026
Rollup merge of #151814 - lcnr:silent-layout-error, r=jackh726

layout: handle rigid aliases without params

fixes #151791

r? types
@apiraino
Copy link
Contributor

Beta backport approved as per compiler team on Zulip. A backport PR will be authored by the release team at the end of the current development cycle. Backport labels handled by them.

It didn't make to the dot release 1.93.1 but maybe we're happier with this baking a little bit before backporting to a dot release (.2 in this case, if planned for other reasons).

@rustbot label +beta-accepted

@rustbot rustbot added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Feb 12, 2026
@cuviper cuviper added this to the 1.94.0 milestone Feb 12, 2026
@cuviper cuviper removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Feb 12, 2026
rust-bors bot pushed a commit that referenced this pull request Feb 12, 2026
[beta] backports, plus stable versions in stdarch

- Replace `stdarch` version placeholders with 1.94
- Parse ident with allowing recovery when trying to diagnose #151249
- Revert enabling `outline-atomics` on various platforms #151896
- Revert doc attribute parsing errors to future warnings #151952
- Remove the 4 failing tests from rustdoc-gui #152194
- Remove rustdoc GUI flaky test #152116
- Align `ArrayWindows` trait impls with `Windows` #151613
- Fix suppression of `unused_assignment` in binding of `unused_variable` #151556
- layout: handle rigid aliases without params #151814
- Fix missing unused_variables lint when using a match guard #151990
- Partially revert "resolve: Update `NameBindingData::vis` in place" #152498
- [BETA]: parse array lengths without stripping const blocks #152237

r? cuviper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beta-accepted Accepted for backporting to the compiler in the beta channel. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. stable-nominated Nominated for backporting to the compiler in the stable channel. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression in 1.93.0 the type <XYZ as Archive>::Archived has an unknown layout

7 participants