Skip to content

refining_impl_trait lint false positive when nesting Fn inside impl Future #165091

Closed

Description

@tvsfx

When compiling this code (playground):

trait Foo {
    fn bar(
        &self,
    ) -> impl Future<Output = Box<dyn Fn(&mut ())>>;
}

struct Nope;
impl Foo for Nope {
    fn bar(
        &self,
    ) -> impl Future<Output = Box<dyn Fn(&mut ())>>
    { async { todo!() }}    
}

I get a refining_impl_trait compiler warning (on stable and nightly)

Warning

   Compiling playground v0.0.1 (/playground)
warning: impl trait in impl method signature does not match trait method signature
  --> src/lib.rs:13:22
   |
 6 |     ) -> impl Future<Output = Box<dyn Fn(&mut ())>>;
   |          ------------------------------------------ return type from trait method defined here
...
13 |     ) -> impl Future<Output = Box<dyn Fn(&mut ())>>
   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this bound is stronger than that defined on the trait
   |
   = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate
   = note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information
   = note: `#[warn(refining_impl_trait_internal)]` (part of `#[warn(refining_impl_trait)]`) on by default
help: replace the return type so that it matches the trait
   |
13 -     ) -> impl Future<Output = Box<dyn Fn(&mut ())>>
13 +     ) -> impl std::future::Future<Output = std::boxed::Box<(dyn for<'a> std::ops::Fn(&'a mut ()) + 'static)>>
   |

warning: `playground` (lib) generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.75s

Meta

rustc --version --verbose:

Stable channel

Build using the Stable version: 1.99.1
Beta channel

Build using the Beta version: 1.100.0-beta.7

(2026-10-17 fd8e211ae301c84a86d1)
Nightly channel

Build using the Nightly version: 1.101.0-nightly

(2026-10-27 41089d07a0a2afc16adf)

Activity

  1. added
    C-bug
    on Oct 28, 2026
  2. added
    needs-triage
    on Oct 28, 2026
  3. maxdexh commented on Oct 28, 2026

    @maxdexh
    Member

    Even when writing out the implicit parts:

    trait Foo {
        fn bar(&self) -> impl Future<Output = Box<dyn Fn(&mut ())>>;
    }
    
    struct Nope;
    impl Foo for Nope {
        fn bar(
            &self,
        ) -> impl Future<Output = Box<(dyn for<'a> Fn(&'a mut ()) + 'static)>> {
            async { todo!() }
        }
    }

    The diagnostic recommends:

    -     ) -> impl Future<Output = Box<(dyn for<'a> Fn(&'a mut ()) + 'static)>> {
    +     ) -> impl std::future::Future<Output = std::boxed::Box<(dyn for<'a> std::ops::Fn(&'a mut ()) + 'static)>> {

    Rustc is drunk and should go home

  4. added
    T-compiler
    T-types
    L-false-positive
    L-refining_impl_trait
    A-lints
    D-incorrect
    A-higher-ranked
    A-dyn-trait
    and removed
    needs-triage
    on Oct 28, 2026
  5. self-assigned this
    on Oct 31, 2026
  6. added 2 commits that reference this issue on Nov 6, 2026
    ce56425
    7cff0d6
  7. added a commit that references this issue on Nov 7, 2026
    ca85e70
  8. added a commit that references this issue on Nov 7, 2026
    b91c5b6
  9. added a commit that references this issue on Nov 8, 2026
    c063e73
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-dyn-traitA-higher-rankedA-lintsC-bugD-incorrectL-false-positiveL-refining_impl_traitT-compilerT-types

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions