Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow Metadata to be Placed on Nested Module Syntax #3369

Open
InsertCreativityHere opened this issue Jan 15, 2025 · 0 comments
Open

Disallow Metadata to be Placed on Nested Module Syntax #3369

InsertCreativityHere opened this issue Jan 15, 2025 · 0 comments

Comments

@InsertCreativityHere
Copy link
Member

InsertCreativityHere commented Jan 15, 2025

For 3.8, we added support for nested module syntax:

module Foo::Bar {...}

This is great, but it introduces some unfortunate ambiguity with how metadata applies to this syntax.
For example, if you write:

["something"]
module Foo::Bar {}

I think there are really 3 separate ways to interpret this:

  1. Metadata applies to the innermost module (Bar)
  2. Metadata applies to the outermost module (Foo)
  3. Metadata applies to the entire construct (Foo::Bar)

I think all 3 of these are valid intuitive beliefs. So no matter which we pick, some users will be surprised, and all users will be uncertain.
So, I think we should pick the secret option 4: Disallow metadata to be placed on nested-module definitions.


This isn't even my idea. Option 4 is what Rust and C++ do. For example, compiling this causes a syntax error:

namespace [[deprecated]] Foo::Bar::Baz
{
    struct Hello { int i; };
}
/tmp/j2zpwYlh9a/main.cpp:4:1: error: a nested namespace definition cannot have attributes
    4 | namespace [[deprecated]] Foo::Bar::Baz
      | ^~~~~~~~~

But it's totally okay with attributes on 'normal' modules:

namespace [[deprecated]] Baz
{
    struct Hello { int i; };
}
/tmp/f2wtwFCLHt/main.cpp: In function 'int main()':
/tmp/f2wtwFCLHt/main.cpp:13:16: warning: 'Baz' is deprecated [-Wdeprecated-declarations]
   13 |     Baz::Hello there {5};

Since nested-module syntax is new for 3.8, we aren't loosing anything by not supporting this.
Of course, we can revisit this in the future if supporting metadata with nested-module syntax becomes a requested feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant