Skip to content

E0700 does not point to where the captured lifetime is #68604

Open
@Nokel81

Description

@Nokel81
Contributor

The error message

error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds

does not point to where in the block the captured lifetime is (which makes debugging it difficult).

It does, however, point to the scope:

note: hidden type `impl futures::Future` captures the scope of call-site for function at 48:40
  --> rs/agent-updater/src/fetcher.rs:48:40
   |
48 |       ) -> Result<PathBuf, FetcherError> {
   |  ________________________________________^
49 | |         let checksum = m.get_valid_checksum()?;
51 | |
...  |
72 | |         Ok(folder)
73 | |     }
   | |_____^

Activity

Centril

Centril commented on Jan 28, 2020

@Centril
Contributor

@Nokel81 Do you have / could you make a small self-contained example we could use when trying to improve the diagnostics?

added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
on Jan 28, 2020
added
D-papercutDiagnostics: An error or lint that needs small tweaks.
on Jan 28, 2020
Nokel81

Nokel81 commented on Jan 28, 2020

@Nokel81
ContributorAuthor

Yes, here is a minimal example. (cannot be a playground link since the playground doesn't have slog.

Example:

use std::{
    collections::HashMap, 
    io,
    sync::Mutex, 
    path::PathBuf
};
use reqwest::Response;
use hyper;
use slog::Logger;

pub struct Module;
pub struct DownloaderError;

pub trait Downloader {
    fn get<'life0, 'life1, 'async_trait>(
        &'life0 self,
        url: &'life1 str,
    ) -> ::core::pin::Pin<
        Box<
            dyn ::core::future::Future<Output = Result<Response, DownloaderError>>
                + ::core::marker::Send
                + 'async_trait,
        >,
    >
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait;
}

pub struct Fetcher<T>
where
    T: Downloader,
{
    downloader: T,
    storage_folder: PathBuf,
    download_cache: Mutex<HashMap<[u8; 32], Vec<u8>>>,
}

impl<T> Fetcher<T>
where
    T: Downloader,
{
    pub fn new(downloader: T, storage_folder: PathBuf) -> Fetcher<T> {
        Self {
            downloader,
            storage_folder,
            download_cache: Mutex::new(HashMap::new()),
        }
    }

    pub async fn fetch_module(
        &self,
        logger: Logger,
        m: &Module,
    ) -> Result<PathBuf, DownloaderError> {
        Ok(PathBuf::new())
    }
}

This is compiled on stable 1.40.

If you remove the line logger: Logger, from the fetch_module method then the compiler error goes away.

skeet70

skeet70 commented on Jan 31, 2020

@skeet70

This may be related to #63033.

added
AsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.
on Feb 11, 2020
tmandry

tmandry commented on Feb 11, 2020

@tmandry
Member

Marking as triaged. This issue would benefit from a more minimized example.

Nokel81

Nokel81 commented on Feb 11, 2020

@Nokel81
ContributorAuthor

I try and get a smaller one tomorrow.

added
E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
on Apr 3, 2021
kadiwa4

kadiwa4 commented on Dec 24, 2024

@kadiwa4
Contributor

Minimized:

trait Trait {}
async fn f(_: &(), _: Box<dyn Trait>, _: &()) {}

This compiles successfully since 1.69.0.
@rustbot label: -E-needs-mcve +S-has-mcve

added
S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issue
and removed
E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
on Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant 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

        Participants

        @Centril@skeet70@estebank@tmandry@Nokel81

        Issue actions

          E0700 does not point to where the captured lifetime is · Issue #68604 · rust-lang/rust