Skip to content

default on free constant items doesn't get rejected #117791

Closed
@fmease

Description

@fmease

The following code compiles successfully while it should lead to an error due to the presence of the contextual keyword default on the free constant item:

default const K: () = ();
fn main() {}

The AST validation code was incorrectly implemented and only rejects default on free const items that don't have a body:

default const K: ();
stderr
error: `default` is only allowed on items in trait impls
 --> src/lib.rs:1:1
  |
1 | default const K: ();
  | -------^^^^^^^^^^^^^
  | |
  | `default` because of this

error: free constant item without body
 --> src/lib.rs:1:1
  |
1 | default const K: ();
  | ^^^^^^^^^^^^^^^^^^^-
  |                    |
  |                    help: provide a definition for the constant: `= <expr>;`

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions