fix [std_instead_of_core]: false positives for core::io/MSRV#16964
Conversation
|
r? @Jarcho rustbot has assigned @Jarcho. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Lintcheck changes for d9517a6
This comment will be updated if you push new changes |
This comment has been minimized.
This comment has been minimized.
|
Reminder, once the PR becomes ready for a review, use |
751c8ff to
bc2d729
Compare
This comment has been minimized.
This comment has been minimized.
87538e5 to
2ae396b
Compare
|
It was a little more involved than I anticipated, but I believe I have resolved the false positive I was intending to, and also solved a couple of additional multi-import ones. I've added additional test cases for the lint which should catch any regressions. This also solved some MSRV issues too. For example, Because I was struggling to understand how the lint worked initially, I've refactored it probably more than it strictly had to be. However I believe it is now easier to understand (at least to my new-to-clippy eyes), with additional comments and internal documentation. @rustbot ready |
std_instead_of_core false positive for core::iostd_instead_of_core false positives for core::io/MSRV
2ae396b to
bc66086
Compare
|
The only change this needed for the title is in fn is_stable(cx: &LateContext<'_>, mut def_id: DefId, msrv: Msrv) -> bool {
loop {
if let Some(stability) = cx.tcx.lookup_stability(def_id) {
match stability.level {
// Workaround for items from `core::intrinsics` with a stable export in a different module.
// Not that we ignore the `since` field as we are already accessing the item in question.
StabilityLevel::Stable { allowed_through_unstable_modules: Some(_), .. } => return true,
StabilityLevel::Stable { since, .. } => match since {
StableSince::Version(v) if !msrv.meets(cx, v) => return false,
StableSince::Current if msrv.current(cx).is_none() => return false,
StableSince::Err(_) => return false,
StableSince::Version(_) | StableSince::Current => {},
},
StabilityLevel::Unstable { .. } => return false,
}
}
match cx.tcx.opt_parent(def_id) {
Some(parent) => def_id = parent,
None => return true,
}
}
}The rest of the changes should be a separate PR. |
|
With the lint now firing on 1.97-beta, I presume this will also need backporting before that stabilizes. |
Using suggestion proposed in: rust-lang#16964 (comment)
bc66086 to
efb5560
Compare
|
@Jarcho thanks for the feedback! I've reduced this PR down to just your suggestion, but I believe it's led to a much larger multi-import false-positive rate. Namely, instances such as |
|
I've added my original changes as a followup commit within this PR and confirmed it resolves the multi-import regressions. With the regressions in mind, I feel it is appropriate to consider this PR in its current entirety. However, I'm happy to try and resolve the regressions differently if that's desirable. |
std_instead_of_core false positives for core::io/MSRVstd_instead_of_core]: false positives for core::io/MSRV/multi-imports
|
Please do split it into multiple PRs. I haven't reviewed that part and the multi-import fixes are less important. The whole thing likely won't be backported either. |
Using suggestion proposed in: rust-lang#16964 (comment)
c974a5b to
d9517a6
Compare
std_instead_of_core]: false positives for core::io/MSRV/multi-importsstd_instead_of_core]: false positives for core::io/MSRV
|
Understood, I'll open up a PR shortly with the multi-import fix. |
|
Please see #17252 for the split-off commit fixing the multi-import issue discussed here. |
Objective
std_instead_of_core#13158.std_instead_of_core#13158Solution
Previously the lint had an exception for all instances of a stable item in an unstable module, primarily to allow certain intrinsics such as
copyto be accessible. Instead, I check for the presence ofrustc_allowed_through_unstable_modulesto handle those exceptions, and allow theis_stablecheck within the lint to early out as soon as any part of its path is unstable.I believe this was the last piece required to resolve #13158, and have added tests for all examples listed in the issue. If there are other examples of this lint failing, I'd greatly appreciate seeing them!
Notes
std_instead_of_corefalse positive forcore::iorust#156164Please write a short comment explaining your change (or "none" for internal only changes)
changelog: fix certain false positives for [
std_instead_of_core] for stable items in an unstable module (e.g.,core::io::ErrorKind), and other MSRV-unaware issues.