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

Warning about Rust 2024 with the newest Nightly Compiler: this function depends on never type fallback being () #1228

Open
kamulos opened this issue Jun 19, 2024 · 5 comments

Comments

@kamulos
Copy link
Contributor

kamulos commented Jun 19, 2024

In my code I often use code that ignores the return value of operations like set:

use redis::{Commands, Connection, RedisError};

fn do_something(connection: &mut Connection) -> Result<(), RedisError> {
    connection.set("test", "test_data")?;
    Ok(())
}

Now with the newest nightly compiler I get the following warning:

warning: this function depends on never type fallback being `()`
 --> src/main.rs:3:1
  |
3 | pub fn do_something(connection: &mut Connection) -> Result<(), RedisError> {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
  = help: specify the types explicitly
note: in edition 2024, the requirement `!: FromRedisValue` will fail
 --> src/main.rs:4:16
  |
4 |     connection.set("test", "test_data")?;
  |                ^^^
  = note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default

Now I don't entirely understand what's going on here, but this warning seems to be fixable for me like this:

- connection.set("test", "test_data")?;
+ let _: () = connection.set("test", "test_data")?;

This is just not very convenient nor pretty. Am I doing something wrong? Is there any way the redis crate can mute this warning?

@nihohit
Copy link
Contributor

nihohit commented Jun 19, 2024

I'm looking into this, but ATM I'm not sure how to solve this on the crate side.

@kamulos
Copy link
Contributor Author

kamulos commented Jun 19, 2024

Hmm, just tried it again. I think this could basically be the following situation:

#![feature(never_type)]

trait Constructible {
    fn construct() -> Self;
}

impl Constructible for () {
    fn construct() -> Self {
        ()
    }
}

// impl Constructible for ! {
//     fn construct() -> Self {
//         loop {}
//     }
// }

fn generic_return<T: Constructible>() -> Result<T, ()> {
    Ok(T::construct())
}

fn main() -> Result<(), ()> {
    generic_return()?;
    Ok(())
}

If I enable the implementation for !, the warning goes away. Unfortunately I still don't understand it...

@nihohit
Copy link
Contributor

nihohit commented Jun 19, 2024

Unfortunately I still don't understand it...

https://discord.com/channels/273534239310479360/1253055949598363760

join the club 😅, I received explanations and I still don't fully grasp it.

@kamulos
Copy link
Contributor Author

kamulos commented Jun 19, 2024

I don't think I have access via your link. Do I need to join a specific channel before I can read that?

What I also noticed in my example is as soon as I replace the ? by .unwrap() it stops working entirely without an explicit specification of the generic return type.

fn main() -> Result<(), ()> {
    generic_return().unwrap();
    Ok(())
}

To me it feels like these two should be interchangeable without such different type inference.

@nihohit
Copy link
Contributor

nihohit commented Jun 20, 2024

I don't think I have access via your link

You need to join the Rust Programming Language server - https://discord.com/invite/rust-lang-community

To me it feels like these two should be interchangeable without such different type inference.

No, because ? desugars to a match, see rust-lang/rust#51125 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants