What is `use<...>`?

The compiler suggested that I add + use<'_, N> in my code. The suggestion seems to have worked.

I'm struggling to find documentation on use<...>

2 Likes

The use-bound was added to allow types hidden behind a return-position impl Trait to capture (use) the generic parameters from its scope. The introductory blog post about this feature is quite extensive and has links to more material (RFC, tracking issues) at the end:

9 Likes

If you tell us where you looked for it and didn’t find it, we might be able to make the documentation more complete.

1 Like
  • Web search for Rust "use<...>" and numerous variations on the theme. Usually this is all that is needed. (This one is difficult to fix manually :slight_smile: )
  • Claude sonnet 3.5 (entertaining surreal interlude of the day, but not very useful in this case)
  • Rust Release Notes (I really expected to find something here. Maybe it is there; if so, then it's drowned in the deluge of other uses of "use".)
  • The Rust Book (Didn't really expect to find it here.)
  • A few more which I forget now.
1 Like

I'll fix that: Add the concrete syntax for precise capturing to 1.82 release notes. by kpreid · Pull Request #135542 · rust-lang/rust · GitHub

Apparently this is waiting for the 2024 edition to be stable (because when to use precise capturing is closely tied to the new edition).

By the way, another way to learn about keywords is to look them up in the standard library rustdoc! That will take you to the page for use which includes an explanation of precise capturing syntax.

10 Likes

Another place to look, for things that aren't in the Rust book, is the Rust reference. Searching it for "use" brings up something on use bounds as the sixth result for me (below 4 results on use declarations and one on the #[used] attribute). The section on use bounds is fairly brief, but it links to precise capturing, which has more explanation.

3 Likes

I did actually land on that page, but saw a screenful talking about the usage of use for importing, and concluded (too hastily) that this wasn't what I was looking for.