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

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

Closed
fmease opened this issue Nov 10, 2023 · 0 comments · Fixed by #117818
Closed

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

fmease opened this issue Nov 10, 2023 · 0 comments · Fixed by #117818
Assignees
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@fmease
Copy link
Member

fmease commented Nov 10, 2023

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>;`
@fmease fmease added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Nov 10, 2023
@fmease fmease self-assigned this Nov 10, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 10, 2023
@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 10, 2023
@fmease fmease changed the title default on free constant items (with body) doesn't get rejected default on free constant items doesn't get rejected Nov 11, 2023
bors added a commit to rust-lang-ci/rust that referenced this issue Dec 17, 2023
…n-free-consts, r=cjgillot

Properly reject `default` on free const items

Fixes rust-lang#117791.

Technically speaking, this is a breaking change but I doubt it will lead to any real-world regressions (maybe in some macro-trickery crates?). Doing a crater run probably isn't worth it.
bors added a commit to rust-lang-ci/rust that referenced this issue Dec 18, 2023
…n-free-consts, r=cjgillot

Properly reject `default` on free const items

Fixes rust-lang#117791.

Technically speaking, this is a breaking change but I doubt it will lead to any real-world regressions (maybe in some macro-trickery crates?). Doing a crater run probably isn't worth it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants