-
Notifications
You must be signed in to change notification settings - Fork 13k
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
[Experimental] <T as Into<T>>::into
lint
#129249
base: master
Are you sure you want to change the base?
Conversation
r? @chenyukang rustbot has assigned @chenyukang. Use |
Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
@bors try @craterbot check |
@bors try |
🔒 Merge conflict This pull request and the master branch diverged in a way that cannot be automatically merged. Please rebase on top of the latest master branch, and let the reviewer approve again. How do I rebase?Assuming
You may also read Git Rebasing to Resolve Conflicts by Drew Blessing for a short tutorial. Please avoid the "Resolve conflicts" button on GitHub. It uses Sometimes step 4 will complete without asking for resolution. This is usually due to difference between how Error message
|
compiler/rustc_lint/src/builtin.rs
Outdated
fn check_item_post(&mut self, cx: &LateContext<'tcx>, item: &hir::Item<'_>) { | ||
let hir::ItemKind::Use(path, kind) = item.kind else { return }; | ||
tracing::info!("{:#?}", item); | ||
tracing::info!(?path, ?kind); | ||
for res in &path.res { | ||
let Res::Def(DefKind::TyAlias, def_id) = res else { continue }; | ||
let ty = cx.tcx.type_of(def_id).instantiate_identity(); | ||
let name = cx.tcx.item_name(*def_id); | ||
// println!("{ty:?} {name:?}"); | ||
self.ignored_types.push(ty); | ||
for stripped in cx.tcx.stripped_cfg_items(def_id.krate) { | ||
if stripped.name.name == name { | ||
tracing::info!("{name:#?}"); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the right way to do this check, but it was the fastest way of getting a semi-accurate discard of types that have type
aliases in scope to somewhat handle platform cfg
cases.
@bors try |
[Experimental] `<T as Into<T>>::into` lint Running crater to see how common that pattern is. The Lint would have to be at most warn-by-default because there are a handful of cases detected that are actually perfectly reasonable (`type` aliases with per-platform `cfg`, or macros) which are now at best half-heartedly handled. I've detected a handful of cases where we're calling `.into()` unnecessarily in the `rustc` codebase as well, and changed those.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
🤔 looks like you are reimplementing a subset of https://rust-lang.github.io/rust-clippy/master/index.html#/useless_conversion ? edit: spoiler
|
looks a bit like a mix of |
This comment has been minimized.
This comment has been minimized.
@matthiaskrgr I'm trying to gauge how common the root cause of the recent |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bc26a90
to
293695f
Compare
This comment has been minimized.
This comment has been minimized.
293695f
to
399747c
Compare
@bors try |
[Experimental] `<T as Into<T>>::into` lint Running crater to see how common that pattern is. The Lint would have to be at most warn-by-default because there are a handful of cases detected that are actually perfectly reasonable (`type` aliases with per-platform `cfg`, or macros) which are now at best half-heartedly handled. I've detected a handful of cases where we're calling `.into()` unnecessarily in the `rustc` codebase as well, and changed those. CC rust-lang#127343.
☀️ Try build successful - checks-actions |
@craterbot check |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
|
@estebank Skimming over the results, everything being flagged looks like the lint is operating exactly as intended. I personally think it'd be reasonable to make this warn-by-default. |
@joshtriplett I have some additional work I want to do to minimize false positives (once I get a |
@estebank I would aim for directly getting this into rustc, rather than trying to go back and fix the clippy lint. Do you think it'd be worth landing this as allow-by-default, to reduce the amount of work you need to do to keep this up to date as you work on the false-positive-reduction to make it warn-by-default? |
Let me see what I can accomplish in the coming days. We might still want to make it allow-by-default at first, and go file PRs for the projects affected in the crater run, but then we can enable it after a (few?) cycle(s). I just realized that we have no mechanism for "enable this lint as deny or warn on nightly but not on stable" as a way of getting feedback on lints from nightly users before it starts hitting stable users. The only way of doing that is making it warn-by-default and then patch beta to make it allow-by-default. It sounds like a reasonable thing to do for any "iffy" lints going forward. |
Running crater to see how common that pattern is. The Lint would have to be at most warn-by-default because there are a handful of cases detected that are actually perfectly reasonable (
type
aliases with per-platformcfg
, or macros) which are now at best half-heartedly handled.I've detected a handful of cases where we're calling
.into()
unnecessarily in therustc
codebase as well, and changed those.CC #127343.