Skip to content

fix: Fix handling of generic params in anon consts - #23179

Open
ChayimFriedman2 wants to merge 2 commits into
rust-lang:masterfrom
ChayimFriedman2:anon-const-params
Open

fix: Fix handling of generic params in anon consts #23179
ChayimFriedman2 wants to merge 2 commits into
rust-lang:masterfrom
ChayimFriedman2:anon-const-params

Conversation

@ChayimFriedman2

@ChayimFriedman2 ChayimFriedman2 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

I also took the chance to cleanup the test code for collecting infer defs.

Fixes #23175. The reason this fixes that is because the issue was the we omitted the projection from the dyn type as we incorrectly thought it refers Self.

Best reviewed commit-by-commit.

This also closes gaps we had, e.g. now `check_impl()` will include field defaults.

The only changes to tests are some ordering changes due to sorting by the root expr's location now instead of the full item's location, and removal of trait functions without bodies, since they don't have a root expr. As their inference is meaningless (only the parameter types, unless you have anon consts in the parameters' patterns which we don't have in our tests), I felt safe to ignore that.
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 17, 2026
200..206 '_other': Between<M, 0, T>
222..242 '{ ... }': Between<M, 0, T>
232..236 'self': Between<M, 0, T>
320..335 '{ Consts::MAX }': usize

@ChayimFriedman2 ChayimFriedman2 Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The order change is because now we sort by the root expr's location instead of the full item's.

View changes since the review

}
"#,
expect![[r#"
43..47 'self': &'? Self

@ChayimFriedman2 ChayimFriedman2 Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Trait methods without default body are now ignored since they do not have a root expr. As their inference is meaningless (only the parameter types, unless you have anon consts in the parameters' patterns which we don't have in our tests), I felt safe to ignore that.

View changes since the review

"#,
expect![[r#"
Foo[T: invariant]
Foo[T: bivariant]

@ChayimFriedman2 ChayimFriedman2 Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Besides the fact that this code is erroneous, rustc also sees this as bivariant, as evidenced by the fact that it emits a "type parameter T is never used" error.

View changes since the review

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FP the method cannot be invoked on a trait object because its Self: Sized bound is not satisfied

2 participants