Handle non-type args in TraitRefPrintSugared#153902
Closed
ViewWay wants to merge 2 commits intorust-lang:mainfrom
Closed
Handle non-type args in TraitRefPrintSugared#153902ViewWay wants to merge 2 commits intorust-lang:mainfrom
ViewWay wants to merge 2 commits intorust-lang:mainfrom
Conversation
added 2 commits
March 14, 2026 21:37
… trait object types This is a cherry-pick of PR #153738 Problem: - PR #150843 introduced a regression where eager type aliases containing dyn Trait (with associated consts) would incorrectly report 'trait is not dyn compatible' errors - This affected 254 crates depending on old bitvec versions Root cause: - When checking for unspecified assoc items in trait object types, we were filtering for all associated consts (is_const()) - But eager type aliases don't get wfchecked at definition site - This broke the assumption that dyn-incompatible traits would be rejected early Fix: - Changed is_const() to is_type_const() to only check type-level associated consts, not regular associated consts - Regular associated consts cannot be bound in trait object types anyway, so checking them was unnecessary Modified files: - compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_trait.rs - compiler/rustc_middle/src/ty/assoc.rs - compiler/rustc_middle/src/ty/sty.rs - compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs - tests/ui/type-alias/lack-of-wf.rs (new test) Fixes: #153731
The issue was that `TraitRefPrintSugared` called `type_at(1)` which panics when the argument is not a type (e.g., an inference variable). This can happen when there are prior errors in user code, such as incorrect trait parameters with paren sugar syntax. The fix uses `get(1).and_then(|arg| arg.as_type())` to safely check if the argument is a type before accessing it, falling back to the default printing path if not.
Collaborator
Collaborator
|
r? @nnethercote rustbot has assigned @nnethercote. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Collaborator
|
Collaborator
|
The job Click to see the possible cause of the failure (guessed by this bot) |
fmease
requested changes
Mar 15, 2026
Member
There was a problem hiding this comment.
For the love of god, please drop your cherry-pick of the commit I authored in open PR RUST-153738. It makes no sense whatsoever to take ownership of it & to include it here and in your ~5 other PRs. Your PRs can't proceed otherwise.
Collaborator
|
Reminder, once the PR becomes ready for a review, use |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #153853.
The
TraitRefPrintSugaredcalledtype_at(1)which panics when the argument is not a type (e.g., an inference variable).This can happen when there are prior errors in user code, such as incorrect trait parameters with paren sugar syntax.
The fix uses
get(1).and_then(|arg| arg.as_type())to safely check if the argument is a type before accessing it, falling back to the default printing path if not.