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

Lifetime Regression using Parser::parse_all_token_trees #30668

Closed
KyleMayes opened this issue Jan 1, 2016 · 3 comments
Closed

Lifetime Regression using Parser::parse_all_token_trees #30668

KyleMayes opened this issue Jan 1, 2016 · 3 comments
Labels
A-lifetimes Area: Lifetimes / regions

Comments

@KyleMayes
Copy link
Contributor

The below code worked until I updated today. I'm not sure which version of the nightly build I had previously, but it was about ten days old.

#![feature(rustc_private)]

extern crate syntax;

use syntax::parse;
use syntax::ast::{TokenTree};
use syntax::parse::{ParseSess};

fn parse_token_trees(source: &str) -> Vec<TokenTree> {
    let session = ParseSess::new();
    let source = source.into();
    let mut parser = parse::new_parser_from_source_str(&session, vec![], "".into(), source);
    parser.parse_all_token_trees().unwrap()
}

Rust Playpen (this produces the same error I am seeing)

If I change it to this, it compiles:

#![feature(rustc_private)]

extern crate syntax;

use syntax::parse;
use syntax::ast::{TokenTree};
use syntax::parse::{ParseSess};

fn parse_token_trees(source: &str) -> Vec<TokenTree> {
    let session = ParseSess::new();
    let source = source.into();
    let mut parser = parse::new_parser_from_source_str(&session, vec![], "".into(), source);
    let tts = parser.parse_all_token_trees().unwrap();
    tts
}

Meta

rustc 1.7.0-nightly (2370d461a 2015-12-30)
binary: rustc
commit-hash: 2370d461a648035b54aae492e7df66256f0f18c6
commit-date: 2015-12-30
host: x86_64-unknown-linux-gnu
release: 1.7.0-nightly
@arielb1 arielb1 changed the title Lifetime Regression Lifetime Regression using Parser::parse_all_token_trees Jan 1, 2016
@arielb1
Copy link
Contributor

arielb1 commented Jan 1, 2016

The problem is that parse_all_token_trees now returns a Result<Vec<TokenTree>, DiagnosticBuilder<'sess>>, and DiagnosticBuilder<'sess> has a destructor (that even uses the borrowed data!) and therefore session must be alive for the containing scope, so from a compiler POV this is a simple case of API breakage.

On the other hand:

  1. I think the lifetime restriction is unnecessary here - after all, the Result is always consumed by the unwrap, so it is never destroyed by the caller - so we could try to have dropck be smarter about this kind of thing, but that would be low-priority
  2. We could use better error-reporting for lifetime conflicts - currently, we unpredictably pick 2 constraints that are related to the conflict, but we throw away all other constraints without looking at them.

@steveklabnik steveklabnik added the A-lifetimes Area: Lifetimes / regions label Jan 4, 2016
@llogiq
Copy link
Contributor

llogiq commented Aug 7, 2016

Probably related to #28970

@arielb1
Copy link
Contributor

arielb1 commented Sep 25, 2016

not a compiler bug, and the "unpredictably pick 2 constraints" part had been fixed in May.

@arielb1 arielb1 closed this as completed Sep 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions
Projects
None yet
Development

No branches or pull requests

4 participants