-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Lint uncallable function #54127
Lint uncallable function #54127
Conversation
Hm, I think I recall seeing that syn is somehow using functions or types like this as arguments that are never called but used for trait based dispatch.. cc @dtolnay (Not sure whether there's actually any concern to be had here but want to make sure) |
3f3c3ad
to
832be28
Compare
Is this something that needs to be linted at all? |
My motivation for adding this case to the lint is bringing the unreachable code/divergence checking in typeck closer to the unreachable code checking for MIR. I imagine it's not that common, but seems to naturally extend the existing lint and at least provide a warning that an entire function may be eliminated during codegen. |
This comment has been minimized.
This comment has been minimized.
Thanks for the ping @Mark-Simulacrum. Yes we use this. |
☔ The latest upstream changes (presumably #53508) made this pull request unmergeable. Please resolve the merge conflicts. |
Triage; @nikomatsakis Hello, are you able to review this PR? |
I've not been reviewing this because it is marked as blocked on #54125, which has not yet landed. |
☔ The latest upstream changes (presumably #54667) made this pull request unmergeable. Please resolve the merge conflicts. |
937a92e
to
88a07ed
Compare
This now no longer depends on #54125. |
This comment has been minimized.
This comment has been minimized.
88a07ed
to
0a7c060
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
dd385a8
to
f7405ad
Compare
This comment has been minimized.
This comment has been minimized.
4ba3269
to
a10962b
Compare
This comment has been minimized.
This comment has been minimized.
a10962b
to
5d7ebdb
Compare
Ping from triage @nikomatsakis: It looks like this PR is ready for your review. |
☔ The latest upstream changes (presumably #56340) made this pull request unmergeable. Please resolve the merge conflicts. |
📌 Commit adac7a1 has been approved by |
⌛ Testing commit adac7a1 with merge fe7b85910c7e42bdcfd75d53a15ab74acc9ec0dd... |
💔 Test failed - status-travis |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
|
Not sure what code is triggering that, seems worth finding out though. |
The code that's triggering this is: #[derive(Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
struct Empty {}
|
Wait, how is that function uncallable? That |
You're right — I misread it as |
Ping from triage @varkor : Have you been able to make any progress on this PR? |
Not yet; it's been a busy couple of weeks. I shall try to do so soon. |
@bors r- Not sure why this is r+ed... |
As for the PR itself; I am not at all sure this is "unobjectionable". In particular, functions such as |
@Centril: can you give a real example? |
@varkor Certainly; For example, given |
@Centril: I think it's always sufficient in such an instance to use an identity function, without explicitly mentioning |
@varkor If that identity function is a closure, then yes, e.g. #![feature(never_type)]
fn main() {
fn make() -> Result<u8, !> { Ok(1) }
fn absurd<T>(x: !) -> T { x }
let _: u8 = make().unwrap_or_else(absurd); // Works fine.
let _: u8 = make().unwrap_or_else(|x| x); // Also works fine because of coercions.
let _: u8 = make().unwrap_or_else(core::convert::identity); // Does not.
} I think writing |
I can see that uncallable functions are plausibly useful from a documentation perspective. I think I'd be satisfied making functions taking never types as parameters immediately diverging, so that the following would work. fn bar(_: !) -> u32 {
// Implicitly diverging, because an argument is `!`.
} Then we can start warning against any other code in such an uncallable function. (Uncallable functions that use some type other than |
I'm going to close this PR, as it's extremely low priority for the lang team to look at, and keeping it open indefinitely is not useful. |
Functions with parameters whose types are uninhabited now fall under the
unreachable_code
lint, unless they're part of a trait implementation, as these are currently necessary.r? @nikomatsakis