Skip to content

Commit 2ec3eea

Browse files
committed
auto merge of #14626 : klutzy/rust/issue-14618, r=alexcrichton
As part of removing `pub use` glob, two extra import globs were injected to make `quote_expr!` work. However the globs caused `unused_import` warning in some places. Quasiquoter needed the globs since it generated idents (e.g. `TyU`) rather than absolute paths (`::syntax::ast::TyU`). This patch removes the extra globs and makes quasiquoter use absolute paths. Fixes #14618 cc @sfackler
2 parents 8d8a291 + 1ec6de3 commit 2ec3eea

File tree

2 files changed

+54
-70
lines changed

2 files changed

+54
-70
lines changed

src/libregex_macros/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
html_root_url = "http://doc.rust-lang.org/")]
2121

2222
#![feature(macro_registrar, managed_boxes, quote)]
23-
#![allow(unused_imports)] // `quote_expr!` adds some `use` globs which may be unused
2423

2524
extern crate regex;
2625
extern crate syntax;

src/libsyntax/ext/quote.rs

+54-69
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,16 @@ fn mk_ident(cx: &ExtCtxt, sp: Span, ident: ast::Ident) -> @ast::Expr {
401401
vec!(e_str))
402402
}
403403

404+
fn mk_ast_path(cx: &ExtCtxt, sp: Span, name: &str) -> @ast::Expr {
405+
let idents = vec!(id_ext("syntax"), id_ext("ast"), id_ext(name));
406+
cx.expr_path(cx.path_global(sp, idents))
407+
}
408+
409+
fn mk_token_path(cx: &ExtCtxt, sp: Span, name: &str) -> @ast::Expr {
410+
let idents = vec!(id_ext("syntax"), id_ext("parse"), id_ext("token"), id_ext(name));
411+
cx.expr_path(cx.path_global(sp, idents))
412+
}
413+
404414
fn mk_binop(cx: &ExtCtxt, sp: Span, bop: token::BinOp) -> @ast::Expr {
405415
let name = match bop {
406416
PLUS => "PLUS",
@@ -414,116 +424,96 @@ fn mk_binop(cx: &ExtCtxt, sp: Span, bop: token::BinOp) -> @ast::Expr {
414424
SHL => "SHL",
415425
SHR => "SHR"
416426
};
417-
cx.expr_ident(sp, id_ext(name))
427+
mk_token_path(cx, sp, name)
418428
}
419429

420430
fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> @ast::Expr {
421431

422432
match *tok {
423433
BINOP(binop) => {
424-
return cx.expr_call_ident(sp,
425-
id_ext("BINOP"),
426-
vec!(mk_binop(cx, sp, binop)));
434+
return cx.expr_call(sp, mk_token_path(cx, sp, "BINOP"), vec!(mk_binop(cx, sp, binop)));
427435
}
428436
BINOPEQ(binop) => {
429-
return cx.expr_call_ident(sp,
430-
id_ext("BINOPEQ"),
431-
vec!(mk_binop(cx, sp, binop)));
437+
return cx.expr_call(sp, mk_token_path(cx, sp, "BINOPEQ"),
438+
vec!(mk_binop(cx, sp, binop)));
432439
}
433440

434441
LIT_CHAR(i) => {
435442
let e_char = cx.expr_lit(sp, ast::LitChar(i));
436443

437-
return cx.expr_call_ident(sp, id_ext("LIT_CHAR"), vec!(e_char));
444+
return cx.expr_call(sp, mk_token_path(cx, sp, "LIT_CHAR"), vec!(e_char));
438445
}
439446

440447
LIT_INT(i, ity) => {
441448
let s_ity = match ity {
442-
ast::TyI => "TyI".to_string(),
443-
ast::TyI8 => "TyI8".to_string(),
444-
ast::TyI16 => "TyI16".to_string(),
445-
ast::TyI32 => "TyI32".to_string(),
446-
ast::TyI64 => "TyI64".to_string()
449+
ast::TyI => "TyI",
450+
ast::TyI8 => "TyI8",
451+
ast::TyI16 => "TyI16",
452+
ast::TyI32 => "TyI32",
453+
ast::TyI64 => "TyI64"
447454
};
448-
let e_ity = cx.expr_ident(sp, id_ext(s_ity.as_slice()));
449-
455+
let e_ity = mk_ast_path(cx, sp, s_ity);
450456
let e_i64 = cx.expr_lit(sp, ast::LitInt(i, ast::TyI64));
451-
452-
return cx.expr_call_ident(sp,
453-
id_ext("LIT_INT"),
454-
vec!(e_i64, e_ity));
457+
return cx.expr_call(sp, mk_token_path(cx, sp, "LIT_INT"), vec!(e_i64, e_ity));
455458
}
456459

457460
LIT_UINT(u, uty) => {
458461
let s_uty = match uty {
459-
ast::TyU => "TyU".to_string(),
460-
ast::TyU8 => "TyU8".to_string(),
461-
ast::TyU16 => "TyU16".to_string(),
462-
ast::TyU32 => "TyU32".to_string(),
463-
ast::TyU64 => "TyU64".to_string()
462+
ast::TyU => "TyU",
463+
ast::TyU8 => "TyU8",
464+
ast::TyU16 => "TyU16",
465+
ast::TyU32 => "TyU32",
466+
ast::TyU64 => "TyU64"
464467
};
465-
let e_uty = cx.expr_ident(sp, id_ext(s_uty.as_slice()));
466-
468+
let e_uty = mk_ast_path(cx, sp, s_uty);
467469
let e_u64 = cx.expr_lit(sp, ast::LitUint(u, ast::TyU64));
468-
469-
return cx.expr_call_ident(sp,
470-
id_ext("LIT_UINT"),
471-
vec!(e_u64, e_uty));
470+
return cx.expr_call(sp, mk_token_path(cx, sp, "LIT_UINT"), vec!(e_u64, e_uty));
472471
}
473472

474473
LIT_INT_UNSUFFIXED(i) => {
475474
let e_i64 = cx.expr_lit(sp, ast::LitInt(i, ast::TyI64));
476-
477-
return cx.expr_call_ident(sp,
478-
id_ext("LIT_INT_UNSUFFIXED"),
479-
vec!(e_i64));
475+
return cx.expr_call(sp, mk_token_path(cx, sp, "LIT_INT_UNSUFFIXED"), vec!(e_i64));
480476
}
481477

482478
LIT_FLOAT(fident, fty) => {
483479
let s_fty = match fty {
484-
ast::TyF32 => "TyF32".to_string(),
485-
ast::TyF64 => "TyF64".to_string(),
486-
ast::TyF128 => "TyF128".to_string()
480+
ast::TyF32 => "TyF32",
481+
ast::TyF64 => "TyF64",
482+
ast::TyF128 => "TyF128"
487483
};
488-
let e_fty = cx.expr_ident(sp, id_ext(s_fty.as_slice()));
489-
484+
let e_fty = mk_ast_path(cx, sp, s_fty);
490485
let e_fident = mk_ident(cx, sp, fident);
491-
492-
return cx.expr_call_ident(sp,
493-
id_ext("LIT_FLOAT"),
494-
vec!(e_fident, e_fty));
486+
return cx.expr_call(sp, mk_token_path(cx, sp, "LIT_FLOAT"), vec!(e_fident, e_fty));
495487
}
496488

497489
LIT_STR(ident) => {
498-
return cx.expr_call_ident(sp,
499-
id_ext("LIT_STR"),
500-
vec!(mk_ident(cx, sp, ident)));
490+
return cx.expr_call(sp,
491+
mk_token_path(cx, sp, "LIT_STR"),
492+
vec!(mk_ident(cx, sp, ident)));
501493
}
502494

503495
LIT_STR_RAW(ident, n) => {
504-
return cx.expr_call_ident(sp,
505-
id_ext("LIT_STR_RAW"),
506-
vec!(mk_ident(cx, sp, ident),
507-
cx.expr_uint(sp, n)));
496+
return cx.expr_call(sp,
497+
mk_token_path(cx, sp, "LIT_STR_RAW"),
498+
vec!(mk_ident(cx, sp, ident), cx.expr_uint(sp, n)));
508499
}
509500

510501
IDENT(ident, b) => {
511-
return cx.expr_call_ident(sp,
512-
id_ext("IDENT"),
513-
vec!(mk_ident(cx, sp, ident),
514-
cx.expr_bool(sp, b)));
502+
return cx.expr_call(sp,
503+
mk_token_path(cx, sp, "IDENT"),
504+
vec!(mk_ident(cx, sp, ident), cx.expr_bool(sp, b)));
515505
}
516506

517507
LIFETIME(ident) => {
518-
return cx.expr_call_ident(sp,
519-
id_ext("LIFETIME"),
520-
vec!(mk_ident(cx, sp, ident)));
508+
return cx.expr_call(sp,
509+
mk_token_path(cx, sp, "LIFETIME"),
510+
vec!(mk_ident(cx, sp, ident)));
521511
}
522512

523513
DOC_COMMENT(ident) => {
524-
return cx.expr_call_ident(sp,
525-
id_ext("DOC_COMMENT"),
526-
vec!(mk_ident(cx, sp, ident)));
514+
return cx.expr_call(sp,
515+
mk_token_path(cx, sp, "DOC_COMMENT"),
516+
vec!(mk_ident(cx, sp, ident)));
527517
}
528518

529519
INTERPOLATED(_) => fail!("quote! with interpolated token"),
@@ -565,19 +555,16 @@ fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> @ast::Expr {
565555
EOF => "EOF",
566556
_ => fail!()
567557
};
568-
cx.expr_ident(sp, id_ext(name))
558+
mk_token_path(cx, sp, name)
569559
}
570560

571-
572561
fn mk_tt(cx: &ExtCtxt, sp: Span, tt: &ast::TokenTree) -> Vec<@ast::Stmt> {
573-
574562
match *tt {
575-
576563
ast::TTTok(sp, ref tok) => {
577564
let e_sp = cx.expr_ident(sp, id_ext("_sp"));
578-
let e_tok = cx.expr_call_ident(sp,
579-
id_ext("TTTok"),
580-
vec!(e_sp, mk_token(cx, sp, tok)));
565+
let e_tok = cx.expr_call(sp,
566+
mk_ast_path(cx, sp, "TTTok"),
567+
vec!(e_sp, mk_token(cx, sp, tok)));
581568
let e_push =
582569
cx.expr_method_call(sp,
583570
cx.expr_ident(sp, id_ext("tt")),
@@ -695,8 +682,6 @@ fn expand_wrapper(cx: &ExtCtxt,
695682
cx_expr: @ast::Expr,
696683
expr: @ast::Expr) -> @ast::Expr {
697684
let uses = [
698-
&["syntax", "ast"],
699-
&["syntax", "parse", "token"],
700685
&["syntax", "ext", "quote", "rt"],
701686
].iter().map(|path| {
702687
let path = path.iter().map(|s| s.to_string()).collect();

0 commit comments

Comments
 (0)