Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc::lint could use some helper functions for working with macros #33177

Open
llogiq opened this issue Apr 24, 2016 · 5 comments
Open

rustc::lint could use some helper functions for working with macros #33177

llogiq opened this issue Apr 24, 2016 · 5 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@llogiq
Copy link
Contributor

llogiq commented Apr 24, 2016

(See #22451 and possibly others)

Currently we have a few functions in clippy/src/util/mod.rs to deal with macros. Namely we can check if some span stems from a macro expansion (though that one could need some work), or if some span was expanded by a given macro (by name) somewhere or directly, or if two spans are in the same macro expansion. This is often useful for readability lints which should not be invoked within macro-expanded code (unless perhaps the code before expansion had the same issue, but that is as of yet hard to detect).

I think those functions belong in the rustc::lint crate. This would both benefit internal lints and all other lints outside of clippy which could then make use of those helpers.

However, clippy is currently licensed under MPL, so we'd need agreement from the authors (of the respective code lines) to move this code into rustc proper. Also we'll want to look first if those functions are ready to be moved and clean up any technical debt we may have incurred so far.

cc @Manishearth

@Manishearth
Copy link
Member

As far as licensing is concerned, feel free to relicense my contributions to clippy as Apache v2, MIT, or dual Apache v2/MIT.

... should have put more thought into the license when picking it initially. It has made it easier to copy code into Servo (which I do every now and then, and Servo is MPL), but I'm not sure what the situation with copying to Rust without needing to add a license is. I'm okay with relicensing the whole of clippy, too.

@Manishearth
Copy link
Member

I actually looked through Rust's lints and most of them don't need macro checks; they all make sense from within a macro or across macro boundaries. Some of them like the unused_ ones just need your macro to have underscores or allow annotations. I don't think there's a pressing need for macro checks for any of them, however I would like to move macro checks into rustc::lint so that other lint writers can use them.

@steveklabnik steveklabnik added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed A-compiler labels Mar 24, 2017
@Mark-Simulacrum Mark-Simulacrum added the A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. label Jun 20, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jul 25, 2017
@steveklabnik
Copy link
Member

Triage: A lot has changed since 2016. Do either of you feel this is still an issue?

@Manishearth
Copy link
Member

Manishearth commented Mar 28, 2020

Yes, I think there are still lints in rustc that need macro checks. I recall coming across this relatively recently.

Clippy has its own utilities for this so it's doing fine, but it might be useful to move them in-tree and use them in the builtins.

@workingjubilee
Copy link
Member

"How to identify you are linting into a macro and stop linting if you are an unused_whatever style of lint" is not discussed in the rustc dev guide section on diagnostics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants