-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add suggestions for std_instead_of_core #11456
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
Add suggestions for std_instead_of_core #11456
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Manishearth (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
This needs tests for the more fun cases with mixed imports. e.g. use std::fmt::{Result, format};
use std::{collections::HashMap, fs, str}; Should end up as (if there's going to be a suggestion for them) use core::fmt::Result;
use alloc::fmt::format;
use alloc::collections::HashMap;
use std::fs;
use core::str; I don't remember how those get picked up by the lint. |
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.
overall looks good but i want to discuss the exact text a bit, and i agree with @Jarcho that more examples would be great!
| ^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: consider importing the item from `core` | ||
| ^^^ help: consider importing the item from `core`: `core` |
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.
hm, not a fan of how this looks where "core" gets repeated. it sounds confusing but it makes sense if you understand how the span arrows work.
thoughts on better ways to present this? perhaps "consider importing the item using: core
"?
unsure if that's better, open to opinions!
Is this turned off by default? I mean, will this have any impact on no_std programs. Or is it automatically disabled if no_std is found? |
No, these are restriction lints (and this PR is not adding them, it is improving the existing ones. We've had them for a while) |
Currently this fails with Getting the replacement right here seems complicated - If you can give me some starting points on how to handle this, I can have a go though. Otherwise, maybe let's just detect this case and not offer any suggestions for now? We could open a new issue for handling these kinds of replacements. |
Yeah that sounds fine. We should also file an issue on rustfix for that. (ideally take the JSON-format rust output and the file and include them in the issue) |
@bors r+ |
Is it really a rustfix issue though? Currently our lint will first try to replace "std" with with core (for Result import) and then the same "std" with alloc (for the format import). Do you think rustfix should simply apply the second suggestion in this case? |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Fixes #11446