Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect "use of undeclared lifetime name" error with nested async functions #93911

Closed
alexcrichton opened this issue Feb 11, 2022 · 1 comment · Fixed by #109940
Closed
Labels
A-lifetimes Area: Lifetimes / regions E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@alexcrichton
Copy link
Member

Given this Rust code:

struct Foo<'a>(&'a u32);

impl<'a> Foo<'a> {
    async fn foo() {
        struct Bar<'b>(&'b u32);

        impl<'b> Bar<'b> {
            async fn bar() {}
        }
    }
}

the compiler errors out with:

$ rustc +nightly foo.rs --crate-type lib --edition 2021
error[E0261]: use of undeclared lifetime name `'a`
 --> foo.rs:3:6
  |
3 | impl<'a> Foo<'a> {
  |      ^^ undeclared lifetime
  |
  = help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
help: consider introducing lifetime `'a` here
  |
7 |         impl<'a, 'b> Bar<'b> {
  |              +++
help: consider introducing lifetime `'a` here
  |
8 |             async fn bar<'a>() {}
  |                         ++++

error: aborting due to previous error

For more information about this error, try `rustc --explain E0261`.

however this code:

struct Foo<'a>(&'a u32);

impl<'a> Foo<'a> {
    async fn foo() {}
}

struct Bar<'b>(&'b u32);

impl<'b> Bar<'b> {
    async fn bar() {}
}

compiles successfully.

This seems like it might be related to the expansion of async code internally in rustc but I'm not entirely sure myself.

The nightly I tested is:

$ rustc +nightly -vV
rustc 1.60.0-nightly (e646f3d2a 2022-02-10)
binary: rustc
commit-hash: e646f3d2a9541952310778288854943678738ea9
commit-date: 2022-02-10
host: aarch64-unknown-linux-gnu
release: 1.60.0-nightly
LLVM version: 13.0.0
@ehuss ehuss added A-lifetimes Area: Lifetimes / regions E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. labels Mar 21, 2023
@ehuss
Copy link
Contributor

ehuss commented Mar 21, 2023

This appears to have been fixed by #94773, but I think it would be good to add a regression test.

JohnTitor added a commit to JohnTitor/rust that referenced this issue Apr 4, 2023
compiler-errors added a commit to compiler-errors/rust that referenced this issue Apr 4, 2023
…errors

Add regression test for rust-lang#93911

r? `@compiler-errors`
Closes rust-lang#93911
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 4, 2023
…mpiler-errors

Rollup of 9 pull requests

Successful merges:

 - rust-lang#109723 (Pull some tuple variant fields out into their own struct)
 - rust-lang#109838 (Fix `non_exhaustive_omitted_patterns` lint span)
 - rust-lang#109901 (Enforce VarDebugInfo::Place in MIR validation.)
 - rust-lang#109913 (Doc-comment  `IndexVec::from_elem` and use it in a few more places)
 - rust-lang#109914 (Emit feature error for parenthesized generics in associated type bounds)
 - rust-lang#109919 (rustdoc: escape GAT args in more cases)
 - rust-lang#109937 (Don't collect return-position impl traits for documentation)
 - rust-lang#109938 (Move a const-prop-lint specific hack from mir interpret to const-prop-lint and make it fallible)
 - rust-lang#109940 (Add regression test for rust-lang#93911)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants