Skip to content

Add "diagnostic items" which behave like lang items #39131

Closed

Description

@Manishearth

It would be nice to have a (rustc-only) system of that lets us annotate structs with things like #[diagnostic_item="String"].

This lets us improve the diagnostics in special cases involving that type (e.g. #39116 (comment)). Clippy currently string-compares the path to do this, but that's hacky and I would rather we avoided that code in rustc.

It's something that would only get hit when we have an error case, so we probably can just store these in a hash map or something.

cc @jonathandturner @nikomatsakis

Activity

  1. added
    T-langRelevant to the language team
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    and removed
    T-langRelevant to the language team
    on Jan 18, 2017
  2. added
    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.
    A-diagnosticsArea: Messages for errors, warnings, and lints
    and removed on Jul 26, 2017
  3. Manishearth commented on Apr 7, 2019

    @Manishearth
    MemberAuthor
  4. Manishearth commented on Apr 7, 2019

    @Manishearth
    MemberAuthor

    Copying over the relevant comment:

    We add a new attribute to the compiler: #[diagnostic = "debug_trait"] and similar so we can stop checking for lang items and instead just check for diagnostic-specific items.

    This will be a bit more involved. Essentially we need to

    1. duplicate the get_lang_items query. Though I don't think there's any point in having a method per diagnostic item.
    2. So I suggest we just make the query return a FxHashMap<Symbol, NodeId>.
    3. We can then build a wrapper method on the TyCtxt that maps a &str to an Option<NodeId> for user convenience
    4. Throw the new attribute on a bunch of types (basically go through https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/utils/paths.rs and just flag all the things in that list)
    5. see if there are any rustc diagnostics that could benefit from this
    6. replace all uses of util/path.rs with a use of the &str -> Option<NodeId> method
    7. complain to @oli-obk that they didn't think this through and there's uses of util/path.rs that do something different
    8. figure out if we need any of this in EarlyLintPasses and make them LateLintPasses
    9. see 7.
  5. added
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    on Apr 7, 2019
  6. added
    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.
    on Apr 8, 2019
  7. added a commit that references this issue on Aug 30, 2019
  8. added
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    and removed
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    on Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-feature-requestCategory: A feature request, i.e: not implemented / a PR.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