Skip to content

Reject non-constructor self types in const-arg tuple-call lowering#157513

Open
Dnreikronos wants to merge 1 commit into
rust-lang:mainfrom
Dnreikronos:fix-tracing-const-arg-157152
Open

Reject non-constructor self types in const-arg tuple-call lowering#157513
Dnreikronos wants to merge 1 commit into
rust-lang:mainfrom
Dnreikronos:fix-tracing-const-arg-157152

Conversation

@Dnreikronos

@Dnreikronos Dnreikronos commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Turning on min_generic_const_args makes tracing stop compiling. Its logging macros expand a field name to something like FieldName<{ FieldName::len(stringify!(field)) }>, and under mgca a braced call in const-arg position gets lowered as a tuple constructor. So lowering tries to resolve the bare self type FieldName (written without its const N), which kicks off an E0107 "missing generics" cascade pointing deep into macro code. But FieldName::len(..) is just an associated fn, not a constructor, so lowering it like a TupleCall was wrong in the first place. See #157152.

Only an enum can host a tuple-variant ctor, so for any other self type that can't (struct, union, primitive, foreign type) the call has to be an assoc fn and needs wrapping in const { ... }. We catch those from the self type's resolution before lowering it and emit the existing "complex const arguments must be placed inside of a const block" error, which is the message you'd want anyway. Enums, aliases, Self and type params get left alone since they might resolve to an enum. tbh the bare generic enum case (Option::Some(0)) still E0107s, and imo that's better as a follow-up since catching it needs the variant type before lowering. Tests cover struct/union/primitive/foreign plus the wrapped forms that compile, and I checked it against the real tracing 0.1.44 crate too.

fwiw just the code changes and tests were implemented with AI help and I verified/reproduced/tested everything locally before sending to remote.

A braced const argument that is a call, like `Ty<{ Ty::f() }>`, is lowered
as a tuple constructor. When the callee's self type cannot host a
tuple-variant constructor (a struct, union, primitive, or foreign type),
the call is an associated function, not a constructor, and must be wrapped
in a `const { ... }` block.

Detect that from the self type's resolution before lowering it, and emit
the existing "complex const arguments must be placed inside of a `const`
block" diagnostic. A generic struct written without its arguments, as
`tracing`'s logging macros generate, would otherwise produce a spurious
E0107 "missing generics" cascade; a primitive or foreign type would
surface an opaque "invalid base path" error.

Enums, aliases, `Self`, and type parameters are left to constructor
lowering, since each may resolve to an enum.

Add UI tests for struct, union, primitive, and foreign self types, plus
the `const { ... }`-wrapped form that compiles.
@rustbot

rustbot commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

HIR ty lowering was modified

cc @fmease

@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 Jun 5, 2026
@rustbot

rustbot commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

BoxyUwU is currently at their maximum review capacity.
They may take a while to respond.

@Dnreikronos

Copy link
Copy Markdown
Contributor Author

r? @fmease

cc @BoxyUwU

@rustbot rustbot assigned fmease and unassigned BoxyUwU Jun 6, 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.

4 participants