Skip to content

use<> bounds ("precise capture") require all type parameters to be listed #130031

Closed
@nikomatsakis

Description

@nikomatsakis

The current implementation of precise capture requires that use<> bounds include all type parameters in scope. This is a temporary limitation that should be lifted. Example:

#![allow(warnings)]

fn main() {
    let mut data = vec![1, 2, 3];
    let mut i = indices(&data);
    data.push(4);
    i.next();
}

fn indices<T>(
    slice: &[T],
) -> impl Iterator<Item = usize> + use<> {
    0 .. slice.len()
}

This code should compile, but it current gives an error (playground):

error: `impl Trait` must mention all type parameters in scope in `use<...>`
  --> src/main.rs:12:6
   |
10 | fn indices<T>(
   |            - type parameter is implicitly captured by this `impl Trait`
11 |     slice: &[T],
12 | ) -> impl Iterator<Item = usize> + use<> {
   |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: currently, all type parameters are required to be mentioned in the precise captures list

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-discussionCategory: Discussion or questions that doesn't represent real issues.F-precise_capturing`#![feature(precise_capturing)]`T-typesRelevant to the types 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