Why can't `Self` be used to refer to an enum's variant in a method body?

后端 未结 5 2003
无人及你
无人及你 2020-12-11 15:20

This question is now obsolete because this feature has been implemented. Related answer.


The following Rust code fails to compile:

enum Foo {
          


        
5条回答
  •  一个人的身影
    2020-12-11 16:14

    There is an experimental feature that would make your example work without any other changes. You can try it out in a nightly build of Rust by adding this in your main file:

    #![feature(type_alias_enum_variants)]
    

    You can follow the progress of the feature towards stabilisation in its tracking issue.

提交回复
热议问题