Skip to content

associated constants can't be used #24915

Closed
@tamird

Description

@tamird

https://is.gd/vYwA6X

main.rs:

#![feature(associated_consts)]
struct Foo;

impl Foo {
  const SUP: &'static str = "sup";
}

use Foo::SUP;

fn main() {
  let sup = SUP;
  assert_eq!(sup, Foo::SUP);
}

rustc:

error: unresolved import `Foo::SUP`. Not a module `Foo` [--explain E0432]
 --> <anon>:8:5
8 |> use Foo::SUP;
  |>     ^^^^^^^^

error: aborting due to previous error

I'm not sure if this is specifically not intended, but it seems to me that it would be convenient to mirror the behaviour of enums in this way. cc @quantheory

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)T-langRelevant to the language 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