Skip to content

Add macro checks to lints #48855

Closed
Closed

Description

@Manishearth

From #48385

Many of our lints trigger even when the code is within a macro defined by an external crate. They should include macro checks.

Clippy has a function for this already.

We should include this in librustc::lint somewhere, and use it for various lints. It should not be used for future compat lints.

One possible thing to do here is to work it into the lint framework itself, so that non-future-compat lints which are triggered on macro spans will not actually be emitted.

We should still have the helper function since some lints may involve multiple important spans so they need the ability to check them all.

Ideally there would be a way to turn this off, though -- in case you want to find issues in your macros. It's a tricky problem.

Willing to mentor the basic issue of importing the macro checks and applying them in most lints (or working it into the framework).

Activity

  1. added
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
    on Mar 8, 2018
  2. Manishearth commented on Mar 8, 2018

    @Manishearth
    MemberAuthor

    @Dylan-DPC would you like to work on this?

  3. added
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    on Mar 8, 2018
  4. oli-obk commented on Mar 9, 2018

    @oli-obk
    Contributor

    I'm not sure, but @flip1995 might be already on it (see #48364)

  5. Manishearth commented on Mar 9, 2018

    @Manishearth
    MemberAuthor

    So that's focusing on span_suggestion -- we need to both fix that and fix the general lint case, except for future compat lints

  6. oli-obk commented on Mar 9, 2018

    @oli-obk
    Contributor

    In clippy we are doing this on a case-by-case basis. Do we really want to blanket ignore all lints in local expansions of external macros?

  7. Manishearth commented on Mar 9, 2018

    @Manishearth
    MemberAuthor

    Honestly I don't know. Future compat lints must show, but aside from that the cases where we want to still show a lint on a macro expansion is when the linted code is completely within the invocation, which can't be detected easily right now.

  8. Dylan-DPC-zz commented on Mar 9, 2018

    @Dylan-DPC-zz

    @Manishearth Ye sure 👍

  9. Manishearth commented on Apr 5, 2018

    @Manishearth
    MemberAuthor

    Any updates?

  10. Dylan-DPC-zz commented on Apr 6, 2018

    @Dylan-DPC-zz

    @Manishearth haven't started with it. Will work on it this weekend.

  11. Dylan-DPC-zz commented on Apr 6, 2018

    @Dylan-DPC-zz

    @Manishearth is there a common place where all lints are used? or i have to hunt down each lint implementation?

  12. Manishearth commented on Apr 6, 2018

    @Manishearth
    MemberAuthor

    they all implement EarlyLintPass or LateLintPass. The implementations are scattered.

    What you want to do is tweak span_lint and similar functions to do the macro check, except for when the lint is a future compat lint (ignore this part for now)

  13. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on May 14, 2018
  14. nrc commented on Jul 2, 2018

    @nrc
    Member

    From @cramertj on Discord: problematic interaction with #[derive(fail)]

    warning: trait objects without an explicit `dyn` are deprecated
       --> src/lib.rs:144:25
        |
    144 |         #[derive(Debug, Fail)]
        |                         ^^^^ help: use `dyn`: `dyn (Fail)`
    
  15. alexcrichton commented on Jul 17, 2018

    @alexcrichton
    Member

    I've revived #49755 at #52467, and I've confirmed @nrc that the warning with derive(Fail) no longer happens after that PR

  16. self-assigned this
    on Jul 17, 2018
  17. added a commit that references this issue on Jul 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-edition-2018Area: The 2018 editionA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.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.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions