Skip to content

this function depends on never type fallback being () #126466

Open

Description

Am I doing something wrong here?

Code:

fn get_or_set<T, G, GF>(
  &self,
  key: &str,
  get_value: G,
  expiration: Option<Duration>,
) -> Pin<Box<dyn Future<Output = Result<T, CacheError>> + Send + '_>>
where
  T: Serialize + for<'de> Deserialize<'de> + Send + 'static,
  G: FnOnce() -> GF + Send + 'static,
  GF: Future<Output = Result<T, CacheError>> + Send + 'static,
{
  let pool = self.pool.clone();
  let codec = &self.codec;
  let key = key.to_string();
  let expiration = expiration.map(|exp| Expiration::EX(exp.whole_seconds() as i64));

  Box::pin(async move {
      match pool.get::<Option<String>, _>(&key).await {
          Ok(Some(value)) => Ok(codec.decode(&value).map_err(CacheError::from)?),
          Ok(None) => {
              let new_value = get_value().await?;
              pool.set(
                  &key,
                  codec.encode(&new_value).map_err(CacheError::from)?,
                  expiration,
                  None,
                  false,
              )
              .await?;
              Ok(new_value)
          }
          Err(err) => Err(CacheError::from(err)),
      }
  })
}

rustc:

warning: this function depends on never type fallback being `()`
   --> src/backend/cache.rs:122:5
    |
122 | /     fn get_or_set<T, G, GF>(
123 | |         &self,
124 | |         key: &str,
125 | |         get_value: G,
...   |
130 | |         G: FnOnce() -> GF + Send + 'static,
131 | |         GF: Future<Output = Result<T, CacheError>> + Send + 'static,
    | |____________________________________________________________________^
    |
    = 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: `#[warn(dependency_on_unit_never_type_fallback)]` on by default

Meta

rustc --version --verbose:

rustc 1.81.0-nightly (f1586001a 2024-06-13)
binary: rustc
commit-hash: f1586001ace26df7cafeb6534eaf76fb2c5513e5
commit-date: 2024-06-13
host: aarch64-apple-darwin
release: 1.81.0-nightly
LLVM version: 18.1.7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.C-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.L-dependency_on_unit_never_type_fallbackLint: dependency_on_unit_never_type_fallbackLint: dependency_on_unit_never_type_fallbackS-needs-reproStatus: This issue has no reproduction and needs a reproduction to make progress.Status: This issue has no reproduction and needs a reproduction to make progress.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions