Skip to content

Missing help when trying to enable stabilized library feature on stable #88802

Closed

Description

@jruderman

Given the following code:

#![feature(discriminant_value)]
fn main() {
    let y = Some(1);
    println!("{:?}", std::mem::discriminant(&y));
}

The current output is:

error[E0554]: `#![feature]` may not be used on the stable release channel
 --> src/main.rs:1:1
  |
1 | #![feature(discriminant_value)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Ideally the output should look like:

error: ...
help: the feature `discriminant_value` has been stable since 1.21.0 and no longer requires an attribute to enable

(or it could be downgraded from error to warning)

#83722 fixed this for #![feature(min_const_generics)] but not for #![feature(discriminant_value)], somehow

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Sep 9, 2021
  2. jyn514 commented on Sep 10, 2021

    @jyn514
    Member

    Hmm, this might be because it's a library feature and not a language feature?

  3. jyn514 commented on Sep 10, 2021

    @jyn514
    Member

    Mentoring instructions: include library features in this check:

    let stable_since = lang_features

  4. added
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
    A-stabilityArea: `#[stable]`, `#[unstable]` etc.
    on Sep 10, 2021
  5. changed the title [-]Missing help when trying to enable stabilized feature on stable[/-] [+]Missing help when trying to enable stabilized library feature on stable[/+] on Sep 10, 2021
  6. chansuke commented on Sep 11, 2021

    @chansuke
    Contributor

    @rustbot claim

  7. vishadGoyal commented on Sep 11, 2021

    @vishadGoyal
    Contributor

    Hi! I started working on this but didn't know I had to claim it first. It's my first time contributing to open source.
    Anyway, so far I realized we need to combine these two Vectors instead of just using the declared_lang_features vector
    the vectors

    use of features

    The remaining challenge is to combine two vectors with different data types.
    Hope this helps @chansuke Best of luck!

  8. chansuke commented on Sep 11, 2021

    @chansuke
    Contributor

    @vishadGoyal I appreciate your great work. You should work on this :)

  9. removed their assignment
    on Sep 11, 2021
  10. vishadGoyal commented on Sep 11, 2021

    @vishadGoyal
    Contributor

    @rustbot claim

  11. 10 remaining items

  12. jyn514 commented on Sep 13, 2021

    @jyn514
    Member

    @vishadGoyal yes, queries can only be run through a TyCtxt. No, I wouldn't expect so, there's the ast::Attributes but you need more than just a Session to access them.

    What's wrong with recording the since field in Session like I suggested?

  13. vishadGoyal commented on Sep 13, 2021

    @vishadGoyal
    Contributor

    The data is not already present where the declared_lib_features is currently being built.
    Its present in library/core/src/intrinsics.rs
    I'm not sure how to access it from where you mentioned.

  14. jyn514 commented on Sep 13, 2021

    @jyn514
    Member

    @vishadGoyal it should be in the attribute you're currently looking at - see how it's done in

    if let Some(stab_attr) = stab_attrs.iter().find(|stab_attr| attr.has_name(**stab_attr)) {

    The language features are hard-coded into the compiler, but that doesn't mean the library features aren't available, they just have to be determined at runtime.

  15. vishadGoyal commented on Sep 13, 2021

    @vishadGoyal
    Contributor

    I logged the attribute being looked at

    [Attribute { kind: Normal(AttrItem { path: Path { span: ../reproduce-88802.rs:1:4: 1:11 (#0), segments: [PathSegment { ident: feature#0, id: NodeId(4294967040), args: None }], tokens: None }, args: Delimited(DelimSpan { open: ../reproduce-88802.rs:1:11: 1:12 (#0), close: ../reproduce-88802.rs:1:30: 1:31 (#0) }, Parenthemetasis, TokenStream([(Token(Token { kind: Ident("discriminant_value", false), span: ../reproduce-88802.rs:1:12: 1:30 (#0) }), Alone)])), tokens: None }, Some(LazyTokenStream(AttrAnnotatedTokenStream([(Token(Token { kind: Pound, span: ../reproduce-88802.rs:1:1: 1:2 (#0) }), Joint), (Token(Token { kind: Not, span: ../reproduce-88802.rs:1:2: 1:3 (#0) }), Alone), (Delimited(DelimSpan { open: ../reproduce-88802.rs:1:3: 1:4 (#0), close: ../reproduce-88802.rs:1:31: 1:32 (#0) }, Bracket, AttrAnnotatedTokenStream([(Token(Token { kind: Ident("feature", false), span: ../reproduce-88802.rs:1:4: 1:11 (#0) }), Alone), (Delimited(DelimSpan { open: ../reproduce-88802.rs:1:11: 1:12 (#0), close: ../reproduce-88802.rs:1:30: 1:31 (#0) }, Paren, AttrAnnotatedTokenStream([(Token(Token { kind: Ident("discriminant_value", false), span: ../reproduce-88802.rs:1:12: 1:30 (#0) }), Alone)])), Alone)])), Alone)])))), id: AttrId(0), style: Inner, span: ../reproduce-88802.rs:1:1: 1:32 (#0) }]
    

    I couldn't find any stability attribute in it or it's meta. The output when I printed the meta of this attr was

    Some(MetaItem { path: Path { span: ../reproduce-88802.rs:1:4: 1:11 (#0), segments: [PathSegment { ident: feature#0, id: NodeId(4294967040), args: None }], tokens: None }, kind: List([MetaItem(MetaItem { path: Path { span: ../reproduce-88802.rs:1:12: 1:30 (#0), segments: [PathSegment { ident: discriminant_value#0, id: NodeId(4294967040), args: None }], tokens: None }, kind: Word, span: ../reproduce-88802.rs:1:12: 1:30 (#0) })]), span: ../reproduce-88802.rs:1:1: 1:32 (#0) })
    
  16. jyn514 commented on Sep 13, 2021

    @jyn514
    Member

    @vishadGoyal you're looking at the #[feature(...)] attribute. You want to look at the #[stable(...)] attribute.

    Hmm, this may be tricky to do in parsing, since it's in another crate - I wonder if we could delay checking library features until later in the compiler, maybe to the pass where it checks if the feature is already stable? I remember @Mark-Simulacrum saying features were checked early to avoid stabilizing syntax by accident, but that shouldn't be an issue for library features: https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Why.20are.20feature.20gates.20checked.20during.20parsing.3F

  17. added
    E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.
    and removed
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    on Sep 13, 2021
  18. vishadGoyal commented on Sep 14, 2021

    @vishadGoyal
    Contributor

    I'm new to this so can you explain why the treatment can be different for lang features and lib features?

  19. jyn514 commented on Sep 14, 2021

    @jyn514
    Member

    Library features can't affect the syntax passed to proc macros; language features can.

  20. vishadGoyal commented on Sep 16, 2021

    @vishadGoyal
    Contributor

    So, what should be the ideal behavior in this scenario?
    If #![feature] is used with only lib features and not with a language feature, should the compiler still throw an error or just a warning for unnecessary_stable_feature_lint?
    Or should we always throw an error if #![feature] is used in beta or stable channels?

  21. jyn514 commented on Sep 16, 2021

    @jyn514
    Member

    @vishadGoyal you should still give a hard error, but it should be later in the compiler after the TyCtxt has been constructed, not during parsing.

  22. vishadGoyal commented on Sep 16, 2021

    @vishadGoyal
    Contributor

    I've made the suggested changes. #89012

  23. added a commit that references this issue on Sep 17, 2021
  24. jyn514 commented on Sep 23, 2021

    @jyn514
    Member

    Fixed in #89012.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-stabilityArea: `#[stable]`, `#[unstable]` etc.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.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