-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Updated clippy to account for changes from rust-lang/rust#44766 #2140
Conversation
The way to fix that is to change the linting API to also pass down an |
@Manishearth Thanks for the quick reply. Yes that's exactly what I suspected (and what I wrote in my PR description). I'll figure it out and update everything. Thanks for taking a look! :) |
Make sure that before merging the rust side the clippy commit you point to is within the clippy repo. I can do this for you once you're sure you're ready to merge (until then, wait). This way the references in rust history never break. |
Sorry, I should have added more details. The exact process to be followed is in this comment. Here's the relevant bit:
|
Yep, I'm aware. I'm saying I'll do that when you're sure it's ready to be merged. |
Perfect! Thank you! |
In my opinion, the correct fix is not to thread down Rather, we should extend the /// Context for lint checking after type checking.
pub struct LateContext<'a, 'tcx: 'a> {
/// Type context we're checking in.
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
/// Side-tables for the body we are in.
pub tables: &'a ty::TypeckTables<'tcx>,
/// Parameter environment for the item we are in.
pub param_env: ty::ParamEnv<'tcx>,
/// Generic type parameters in scope for the item we are in.
pub generics: Option<&'tcx ty::Generics>, // <-- THIS IS NEW
/// Items accessible from the crate being checked.
pub access_levels: &'a AccessLevels,
/// The store of registered lints and the lint levels.
lint_sess: LintSession<'tcx, LateLintPassObject>,
last_ast_node_with_lint_attrs: ast::NodeId,
} I used an (To be honest, I think that We can then initialize the field to let old_generics = self.generics;
self.generics = self.tcx.generics_of(self.tcx.hir.local_def_id(id));
...
self.generics = old_generics; Now we can change the lint code in if !cx.generics.unwrap().types.is_empty() {
// when the result of `new()` depends on a type parameter we should not require
// an impl of `Default`
return;
} |
What about |
Ah, sticking generics on the late context is a good idea. |
I won't get to a PC until Monday. Can someone else take this PR? |
on it |
Hi Manish, if you'd like me to go in and finish this I'm happy to do it. It sounds like you're already working on it currently so I'll leave it to you. I wouldn't want our work to conflict. :) |
Pushed to the rustup branch on this repo. I couldn't find the |
It seems like LateContext was never changed to provide a Generics field? Is there an alternate way to handle this? Or is this something that was supposed to be added to rustc itself? |
I believe the idea was to change LateContext to include that field. Niko wrote "THIS IS NEW" beside it in his instructions. I may have some time to look into this a bit later today or tomorrow. I'll be able to help you more then. :) |
Oh, I thought the plan was for you to include that in your Rust PR. I've got a WIP of it here: https://github.com/manishearth/rust/tree/lint-generics . It should work but I haven't compiled it yet (and will be getting on a flight so won't be able to look at it until later). |
Manish has incorporated my commit into #2187. When that is merged I think this can be closed. Thanks Manish! :) |
Add generics to LateContext Fixes clippy breakage from #44766 as discussed in rust-lang/rust-clippy#2140 (comment) r? @nikomatsakis
In rust-lang/rust#44766, I make some changes to the ast and the hir which break some clippy code. Please DO NOT merge these changes until that PR is merged. This PR shouldn't even pass CI until those changes land in the compiler, but I thought I would mention it anyway just in case.
Some of the breaking changes were easy to fix, but there is one particular lint that I don't know how to fix. There's a TODO comment and commented out code in this PR to show where the problem is. I would appreciate some advice about how to go about fixing this.
The problem is that there is no more
sig.generics
. As part of my rustc PR, I lifted the generics property from each individual method signature to the trait/impl item itself. This is in preparation for implementing generic associated types. When I fixed rustfmt, I was able to resolve this by adding a parameter to the function that needed to check generics so that the generics could be passed in from above. I tried doing that here but ran into some problems along the way. Do you think the right thing to do is to add a generics parameter tocheck_fn
?