Skip to content

Implementation of trait "not general enough" in nightly, works fine on stable #131488

Open

Description

Code

I tried this (reduced) code:

use tokio::sync::mpsc::{unbounded_channel,UnboundedSender};

pub trait Role: 'static + Sync + Send {
    type Return : Send;
}

pub trait BasicRole: 'static + Send + Sync {}
impl Role for dyn BasicRole + '_ {
    type Return = ();
}

pub struct ReturnEnvelope<R: Role + ?Sized> {
	pub return_path: Option<R::Return>,
}

pub fn start() {
    let (_basic_role_input, mut basic_role_output): (UnboundedSender<ReturnEnvelope<dyn BasicRole>>, _) = unbounded_channel();

    let event_loop = async move {
        let _ = basic_role_output.recv().await;
    };
    let _ = ::tokio::task::spawn(event_loop);
}

(playground)

I expected to see this happen: successful compile.

Instead, this happened: I received this error:

error: implementation of `Role` is not general enough
  --> src/lib.rs:22:13
   |
22 |     let _ = ::tokio::task::spawn(event_loop);
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Role` is not general enough
   |
   = note: `Role` would have to be implemented for the type `(dyn BasicRole + '0)`, for any lifetime `'0`...
   = note: ...but `Role` is actually implemented for the type `(dyn BasicRole + '1)`, for some specific lifetime `'1`

This can also be seen on the playground configured to use nightly.

I am aware that handling this construct correctly seems to be an outstanding issue, I'm specifically reporting the inconsistency that it does work on stable and not nightly.

Version it worked on

It most recently worked on: 1.81.0 stable (most recent)

Version with regression

rustc --version --verbose:

rustc 1.83.0-nightly (eb4e23467 2024-10-09)
binary: rustc
commit-hash: eb4e2346748e1760f74fcaa27b42431e0b95f8f3
commit-date: 2024-10-09
host: x86_64-pc-windows-msvc
release: 1.83.0-nightly
LLVM version: 19.1.1

However, this has been an issue since at least the 2024-08-17 nightly (feeba19)

@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.Category: This is a bug.I-prioritizeIssue: Indicates that prioritization has been requested for this issue.Issue: Indicates that prioritization has been requested for this issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.Performance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions