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

quote macros do not err or warn on trailing token-trees in input #12266

Closed
pnkfelix opened this issue Feb 14, 2014 · 4 comments
Closed

quote macros do not err or warn on trailing token-trees in input #12266

pnkfelix opened this issue Feb 14, 2014 · 4 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-syntaxext Area: Syntax extensions C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@pnkfelix
Copy link
Member

here is a snippet of code (i've pasted the full example at the bottom):

fn main() {
    let e = quote_expr!((), x + y);
    println!("expr: {:s}", e.to_str());
    let p = quote_pat!((),  x + y);
    println!("pat:  {:s}", p.to_str());
}

Once #12264 is fixed, then you can compile and run this, and you'll get:

% ./cfg 
expr: x + y
pat:  x

In particular, I fed x + y into both quote_expr! and into quote_pat!, and the + y was simply silently discarded when quote_pat! parsed its input.

The macros should check for trailing input and issue a warning (that one could then use allow/deny/forbid on).


Here is the full example code (again, won't compile until #12264 is fixed):

#[feature(managed_boxes)];
#[feature(quote)];
#[feature(macro_rules)];
extern mod syntax;
extern mod rustc;

use syntax::ast;
use syntax::codemap;
use syntax::parse;
use syntax::parse::token;
use syntax::print::pprust;

fn main() {
    let e = quote_expr!((), x + y);
    println!("expr: {:s}", e.to_str());
    let p = quote_pat!((),  x + y);
    println!("pat:  {:s}", p.to_str());
}

trait SyntaxToStr {
    fn get_interner(&self) -> @token::IdentInterner { token::get_ident_interner() }
    fn get_to_str() -> fn (_: &Self, intr: @token::IdentInterner) -> ~str;
    fn to_str(&self) -> ~str { SyntaxToStr::get_to_str()(self, self.get_interner()) }
}

macro_rules! impl_stx_to_str {
    ($Type:path, $func:path) => {
        impl SyntaxToStr for $Type {
            fn get_to_str() -> fn (_: &$Type, intr: @token::IdentInterner) -> ~str {
                $func
            }
        }
    }
}

impl_stx_to_str!(ast::Ty,       pprust::ty_to_str)
impl_stx_to_str!(ast::Pat,      pprust::pat_to_str)
impl_stx_to_str!(ast::Expr,     pprust::expr_to_str)
impl_stx_to_str!(ast::Stmt,     pprust::stmt_to_str)
impl_stx_to_str!(ast::Item,     pprust::item_to_str)
impl_stx_to_str!(ast::Generics, pprust::generics_to_str)
impl_stx_to_str!(ast::Path,     pprust::path_to_str)

trait QuoteCtxt {
    fn parse_sess(&self) -> @syntax::parse::ParseSess;
    fn cfg(&self) -> ast::CrateConfig;
    fn call_site(&self) -> codemap::Span;
    fn ident_of(&self, st: &str) -> ast::Ident;
}

impl QuoteCtxt for () {
    fn parse_sess(&self)         -> @syntax::parse::ParseSess { parse::new_parse_sess() }
    fn cfg(&self)                -> ast::CrateConfig          { ~[] }
    fn call_site(&self)          -> codemap::Span             { codemap::DUMMY_SP }
    fn ident_of(&self, st: &str) -> ast::Ident                { token::str_to_ident(st) }
}
@huonw huonw added the A-syntaxext Area: Syntax extensions label Nov 17, 2014
@huonw
Copy link
Member

huonw commented Nov 21, 2014

Still an issue. Updated code:

#![feature(quote)]
#![feature(macro_rules)]
extern crate syntax;
extern crate rustc;

use syntax::ast;
use syntax::codemap;
use syntax::parse;
use syntax::parse::token;
use syntax::print::pprust;

fn main() {
    let ctxt = Ctxt { parse: parse::new_parse_sess() };
    let e = quote_expr!(&ctxt, x + y);
    println!("expr: {}", pprust::expr_to_string(&*e));
    let p = quote_pat!(&ctxt,  x + y);
    println!("pat:  {}", pprust::pat_to_string(&*p));
}

struct Ctxt {
    parse: parse::ParseSess
}

impl Ctxt {
    fn parse_sess(&self)         -> &syntax::parse::ParseSess { &self.parse }
    fn cfg(&self)                -> ast::CrateConfig          { vec![] }
    fn call_site(&self)          -> codemap::Span             { codemap::DUMMY_SP }
    fn ident_of(&self, st: &str) -> ast::Ident                { token::str_to_ident(st) }
}

@Stebalien
Copy link
Contributor

Updated code:

#![feature(quote)]
#![feature(rustc_private)]
extern crate syntax;
extern crate rustc;

use syntax::ast;
use syntax::codemap;
use syntax::parse;
use syntax::parse::token;
use syntax::print::pprust;

fn main() {
    let ctxt = Ctxt { parse: parse::ParseSess::new() };
    let e = quote_expr!(&ctxt, x + y);
    println!("expr: {}", pprust::expr_to_string(&*e));
    let p = quote_pat!(&ctxt,  x + y);
    println!("pat:  {}", pprust::pat_to_string(&*p));
}

struct Ctxt {
    parse: parse::ParseSess
}

impl Ctxt {
    fn parse_sess(&self)         -> &syntax::parse::ParseSess { &self.parse }
    fn cfg(&self)                -> ast::CrateConfig          { vec![] }
    fn call_site(&self)          -> codemap::Span             { codemap::DUMMY_SP }
    fn ident_of(&self, st: &str) -> ast::Ident                { token::str_to_ident(st) }
}

@steveklabnik
Copy link
Member

Triage: @Stebalien 's code doesn't work any more, but I don't know how to update it to see if this problem persists.

@Mark-Simulacrum
Copy link
Member

@jseyfried Perhaps you could help out and provide a reproducible example here? This may also be related to macros 2.0 work.

@Mark-Simulacrum Mark-Simulacrum added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints labels Jul 20, 2017
bors added a commit that referenced this issue Sep 30, 2018
Remove quote_*! macros

This deletes a considerable amount of test cases, some of which we may want to keep. I'm not entirely certain what the primary intent of many of them was; if we should keep them I can attempt to edit each case to continue compiling without the quote_*! macros involved.

Fixes #46849.
Fixes #12265.
Fixes #12266.

r? @Manishearth
bors added a commit that referenced this issue Oct 2, 2018
Remove quote_*! macros

This deletes a considerable amount of test cases, some of which we may want to keep. I'm not entirely certain what the primary intent of many of them was; if we should keep them I can attempt to edit each case to continue compiling without the quote_*! macros involved.

Fixes #46849.
Fixes #12265.
Fixes #12266.

r? @Manishearth
bors added a commit that referenced this issue Dec 8, 2018
Remove quote_*! macros

This deletes a considerable amount of test cases, some of which we may want to keep. I'm not entirely certain what the primary intent of many of them was; if we should keep them I can attempt to edit each case to continue compiling without the quote_*! macros involved.

Fixes #46849.
Fixes #12265.
Fixes #12266.
Fixes #26994.

r? @Manishearth
bors added a commit that referenced this issue Jan 23, 2019
Remove quote_*! macros

This deletes a considerable amount of test cases, some of which we may want to keep. I'm not entirely certain what the primary intent of many of them was; if we should keep them I can attempt to edit each case to continue compiling without the quote_*! macros involved.

Fixes #46849.
Fixes #12265.
Fixes #12266.
Fixes #26994.

r? @Manishearth
@bors bors closed this as completed in 01f8e25 Jan 24, 2019
flip1995 pushed a commit to flip1995/rust that referenced this issue Feb 26, 2024
…eds-usize, r=Manishearth

fix: ICE when array index exceeds usize

fixes rust-lang#12253

This PR fixes ICE in `indexing_slicing` as it panics when the index of the array exceeds `usize`.

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-syntaxext Area: Syntax extensions C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

5 participants