Skip to content
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

let_unit_value triggers on generic return value #8998

Closed
madsmtm opened this issue Jun 14, 2022 · 7 comments · Fixed by #9056
Closed

let_unit_value triggers on generic return value #8998

madsmtm opened this issue Jun 14, 2022 · 7 comments · Fixed by #9056
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@madsmtm
Copy link

madsmtm commented Jun 14, 2022

Summary

When using objc, a library commonly used when dealing with Objective-C, you often have to use let _: () = ... to tell the compiler what the return type, since the return type is generic.

This triggers the lint. Trying to apply the lint's suggestion results in a compilation error. The lint doesn't trigger on Rust 1.61.0.

Lint Name

let_unit_value

Reproducer

I tried the following code (see this playground link for a simplified testcase):

// objc v0.2.7
use objc::{class, msg_send};
use objc::runtime::Object;

let cls = class!(NSObject);
let obj: *mut Object = unsafe { msg_send![cls, new] };
let _: () = unsafe { msg_send![obj, release] };

I expected the lint to not trigger, instead it triggers on the last statement.

Version

rustc 1.63.0-nightly (ec55c6130 2022-06-10)
binary: rustc
commit-hash: ec55c61305eaf385fc1b93ac9a78284b4d887fe5
commit-date: 2022-06-10
host: x86_64-apple-darwin
release: 1.63.0-nightly
LLVM version: 14.0.5

Additional Labels

@rustbot label +regression-from-stable-to-nightly
@rustbot label +I-suggestion-causes-error

@madsmtm madsmtm added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Jun 14, 2022
@rustbot
Copy link
Collaborator

rustbot commented Jun 14, 2022

Error: Label regression-from-stable-to-nightly can only be set by Rust team members

Please let @rust-lang/release know if you're having trouble with this bot.

@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Jun 14, 2022
@Jarcho
Copy link
Contributor

Jarcho commented Jun 14, 2022

I assume the msg_send macro in objc is similar to what you have on the playground. i.e. it doesn't call the function directly, but wraps it in a block of code. Functions returning a generic type should be handled already, but only when the function result is assigned more directly.

@madsmtm
Copy link
Author

madsmtm commented Jun 14, 2022

Yup, that's why I wrote the playground example as such

@Jarcho
Copy link
Contributor

Jarcho commented Jun 16, 2022

@rustbot claim

@Aaron1011
Copy link
Member

For what it's worth, I think that would be a false positive even if the suggestion didn't cause a compilation error. Writing let _: () = some_expr can also be used to assert that an expression produces ().

@lilyball
Copy link

I'm running into this with a channel. Approximate code looks like

let (_tx, rx) = oneshot::channel();
let handle = spawn(async {
    let () = rx.await.unwrap();
});

(the context here is a test case for abortion behavior on the spawn function in question, which is why the sender is never used and therefore no other constraints are placed on the channel type)

@bors bors closed this as completed in 7ea4592 Jul 10, 2022
@booleancoercion
Copy link
Contributor

I don't know why this was marked as closed - as far as I can tell, it was not fixed, at least not in this specific case (in an async context of course):

let () = futures::future::pending().await;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants