Skip to content

Conversation

@GrigorenkoPV
Copy link
Contributor

@GrigorenkoPV GrigorenkoPV commented Dec 7, 2025

As suggested in #149174 (comment), this PR adds an ability to omit : () from const item declarations. If the type is omitted, it defaults to (). This is similar to how function declarations treat -> ().

Implementation details:

  • The gate is #![feature(const_items_unit_type_default)] with the same tracking issue as for #![feature(const_block_items)]
  • ast::ConstItem's ty is changed from Box<ast::Ty> into ast::FnRetTy, which is like an Option<Box<Ty>> but with a Span for the None variant.
  • During parsing:
    • static items with unspecified type still give an error, just as before
    • const items with an unspecified type no longer give the previous error, but instead demand that you have the new feature enabled and fallback to : ().
  • During AST->HIR lowering:
    • const items with no type specified in AST get a () in HIR
  • rustfmt support included

TODO:

  • Sadly, it seemes like it undoes the internal compiler error: missing type for const item #69396. Maybe instead of falling back to : (), fallback to : _ (as it was before) when the feature is not enabled?
  • make a separate tracking issue or update Tracking Issue for item-level const blocks #149226
  • is the feature gate name ok?
  • do not reuse FnRetTy or rename it?
  • do the "unspecified means ()" substitution not during AST->HIR, but later on?
  • allow to omit : () for static items too? for consistency. despite static: () being kinda useless.
  • better diagnostic messages?

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. T-lang Relevant to the language team labels Dec 7, 2025
@GrigorenkoPV
Copy link
Contributor Author

CC @joshtriplett as the lang champion

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot removed the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Dec 7, 2025
@rustbot rustbot added the T-clippy Relevant to the Clippy team. label Dec 7, 2025
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Dec 12, 2025

☔ The latest upstream changes (presumably #149891) made this pull request unmergeable. Please resolve the merge conflicts.

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 2, 2026

☔ The latest upstream changes made this pull request unmergeable. Please resolve the merge conflicts.

@GrigorenkoPV GrigorenkoPV marked this pull request as ready for review January 24, 2026 18:13
@rustbot
Copy link
Collaborator

rustbot commented Jan 24, 2026

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 24, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 24, 2026

r? @tiif

rustbot has assigned @tiif.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@tiif
Copy link
Member

tiif commented Jan 26, 2026

This PR is out of my comfort zone.

r? @jdonszelmann

since you reviewed the previous PR :)

(also I suppose this also needs approval from rustfmt and clippy? not sure what is the best course of action here, I will leave it to the next reviewer to judge.)

@rustbot rustbot assigned jdonszelmann and unassigned tiif Jan 26, 2026
Copy link
Member

@Centri3 Centri3 left a comment

Choose a reason for hiding this comment

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

Clippy changes look good to me.
Cool PR in my opinion

View changes since this review

@jdonszelmann
Copy link
Contributor

jdonszelmann commented Jan 26, 2026

@joshtriplett @scottmcm at the very least this needs lang approval. Scott seems to have suggested this. I think I'm very much against it: if the plan is to have toplevel const{} blocks, I don't see why we need this, and I think that leaving out types here is very inconsisten. I know this is what functions do, but I really don't think I like this for consts. Especially since returning () from functions is super common, but assigning them to consts is not except this case that we're already trying to simplyfy as a top-level const block. I'm not on T-lang, but I would object to it if I were.

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-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants