Skip to content

NLL diagnostic regression on generator + short-lived yield #56508

Closed
@pnkfelix

Description

@pnkfelix

Spawned off of issue #55850 and PR #56460

Consider code like this (it is issue-55850.rs from PR #56460):

#![allow(unused_mut)]
#![feature(generators, generator_trait)]

use std::ops::Generator;
use std::ops::GeneratorState::Yielded;

pub struct GenIter<G>(G);

impl <G> Iterator for GenIter<G>
where
    G: Generator,
{
    type Item = G::Yield;

    fn next(&mut self) -> Option<Self::Item> {
        unsafe {
            match self.0.resume() {
                Yielded(y) => Some(y),
                _ => None
            }
        }
    }
}

fn bug<'a>() -> impl Iterator<Item = &'a str> {
    GenIter(move || {
        let mut s = String::new();
        yield &s[..]
    })
}

fn main() {
    bug();
}

Right now, AST-borrowck includes this note:

note: borrowed value must be valid for the lifetime 'a as defined on the function body at 35:8...
  --> $DIR/issue-55850.rs:35:8
   |
LL | fn bug<'a>() -> impl Iterator<Item = &'a str> {
   |        ^^

but even after PR #56460 lands (fixing an ICE), NLL does not include such a note.

Metadata

Metadata

Assignees

Labels

A-NLLArea: Non-lexical lifetimes (NLL)A-coroutinesArea: CoroutinesE-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.NLL-diagnosticsWorking towards the "diagnostic parity" goalP-mediumMedium priorityT-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

Issue actions