Skip to content

Handle attributes on anonymous namespaces - #3502

Open
lwz23 wants to merge 2 commits into
rust-lang:mainfrom
lwz23:fix/anonymous-namespace-attributes
Open

lwz23 wants to merge 2 commits into
rust-lang:mainfrom
lwz23:fix/anonymous-namespace-attributes

Conversation

@lwz23

@lwz23 lwz23 commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #3485.

When libclang leaves the spelling of an anonymous namespace empty, tokenize_namespace reads its tokens to identify the name. A C++ attribute before { made it treat [ as a module name and panic. Skip the bracketed attribute sequence while looking for the namespace name, so an attributed anonymous namespace is handled like an ordinary anonymous namespace. Named namespaces remain covered by the same fixture.

Added a C++17 header regression test with both anonymous and named attributed namespaces. Verified the new test fails with the reported panic before the change and passes afterward. Also ran the existing inline/nested namespace tests, cargo test -p bindgen, the generated expectation compilation, formatting, and workspace Clippy with warnings denied.

AI assistance: Codex helped prepare the change and tests; I reviewed and ran the checks above.

@rustbot rustbot added the A-C++ label Sep 23, 2026
Comment thread bindgen/ir/context.rs Outdated
let spelling = token.spelling();
if looking_for_name {
// Skip C++ attributes before the namespace name or `{`.
match spelling {

@emilio emilio Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems we don't need this to be separate to the match right below, or am I missing something?

View changes since the review

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.

Agreed, the separate match was unnecessary. I folded the attribute-depth arms into the existing token match in 4e80951. The namespace-attributes header test and nightly formatting check pass.

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--enable-cxx-namespaces panics on namespace [[deprecated]] { ("[" is not a valid Ident)

3 participants