Skip to content

Commit 29d6a8e

Browse files
committed
auto merge of #15425 : jbclements/rust/hygiene-for-3-kinds-of-args, r=cmr
This pull request adds hygiene for 3 kinds of argument bindings: - arguments to item fns, - arguments to `ExprFnBlock`s, and - arguments to `ExprProc`s It also adds a bunch of unit tests, fixes a few macro uses to be non-capturing, and has a few cleanup items. local `make check` succeeds.
2 parents 9f2a43c + cc13f9b commit 29d6a8e

File tree

8 files changed

+297
-123
lines changed

8 files changed

+297
-123
lines changed

src/librustc/middle/trans/_match.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -781,9 +781,9 @@ fn extract_vec_elems<'a>(
781781
// matches should fit that sort of pattern or NONE (however, some of the
782782
// matches may be wildcards like _ or identifiers).
783783
macro_rules! any_pat (
784-
($m:expr, $pattern:pat) => (
784+
($m:expr, $col:expr, $pattern:pat) => (
785785
($m).iter().any(|br| {
786-
match br.pats.get(col).node {
786+
match br.pats.get($col).node {
787787
$pattern => true,
788788
_ => false
789789
}
@@ -792,11 +792,11 @@ macro_rules! any_pat (
792792
)
793793

794794
fn any_uniq_pat(m: &[Match], col: uint) -> bool {
795-
any_pat!(m, ast::PatBox(_))
795+
any_pat!(m, col, ast::PatBox(_))
796796
}
797797

798798
fn any_region_pat(m: &[Match], col: uint) -> bool {
799-
any_pat!(m, ast::PatRegion(_))
799+
any_pat!(m, col, ast::PatRegion(_))
800800
}
801801

802802
fn any_irrefutable_adt_pat(bcx: &Block, m: &[Match], col: uint) -> bool {

src/libstd/io/extensions.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -508,14 +508,15 @@ mod bench {
508508
use prelude::*;
509509
use self::test::Bencher;
510510

511+
// why is this a macro? wouldn't an inlined function work just as well?
511512
macro_rules! u64_from_be_bytes_bench_impl(
512-
($size:expr, $stride:expr, $start_index:expr) =>
513+
($b:expr, $size:expr, $stride:expr, $start_index:expr) =>
513514
({
514515
use super::u64_from_be_bytes;
515516

516517
let data = Vec::from_fn($stride*100+$start_index, |i| i as u8);
517518
let mut sum = 0u64;
518-
b.iter(|| {
519+
$b.iter(|| {
519520
let mut i = $start_index;
520521
while i < data.len() {
521522
sum += u64_from_be_bytes(data.as_slice(), i, $size);
@@ -527,31 +528,31 @@ mod bench {
527528

528529
#[bench]
529530
fn u64_from_be_bytes_4_aligned(b: &mut Bencher) {
530-
u64_from_be_bytes_bench_impl!(4, 4, 0);
531+
u64_from_be_bytes_bench_impl!(b, 4, 4, 0);
531532
}
532533

533534
#[bench]
534535
fn u64_from_be_bytes_4_unaligned(b: &mut Bencher) {
535-
u64_from_be_bytes_bench_impl!(4, 4, 1);
536+
u64_from_be_bytes_bench_impl!(b, 4, 4, 1);
536537
}
537538

538539
#[bench]
539540
fn u64_from_be_bytes_7_aligned(b: &mut Bencher) {
540-
u64_from_be_bytes_bench_impl!(7, 8, 0);
541+
u64_from_be_bytes_bench_impl!(b, 7, 8, 0);
541542
}
542543

543544
#[bench]
544545
fn u64_from_be_bytes_7_unaligned(b: &mut Bencher) {
545-
u64_from_be_bytes_bench_impl!(7, 8, 1);
546+
u64_from_be_bytes_bench_impl!(b, 7, 8, 1);
546547
}
547548

548549
#[bench]
549550
fn u64_from_be_bytes_8_aligned(b: &mut Bencher) {
550-
u64_from_be_bytes_bench_impl!(8, 8, 0);
551+
u64_from_be_bytes_bench_impl!(b, 8, 8, 0);
551552
}
552553

553554
#[bench]
554555
fn u64_from_be_bytes_8_unaligned(b: &mut Bencher) {
555-
u64_from_be_bytes_bench_impl!(8, 8, 1);
556+
u64_from_be_bytes_bench_impl!(b, 8, 8, 1);
556557
}
557558
}

src/libsyntax/ast.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ pub struct TyParam {
190190
pub span: Span
191191
}
192192

193+
/// Represents lifetimes and type parameters attached to a declaration
194+
/// of a function, enum, trait, etc.
193195
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
194196
pub struct Generics {
195197
pub lifetimes: Vec<Lifetime>,
@@ -288,7 +290,7 @@ pub enum Pat_ {
288290
PatWild,
289291
PatWildMulti,
290292
// A PatIdent may either be a new bound variable,
291-
// or a nullary enum (in which case the second field
293+
// or a nullary enum (in which case the third field
292294
// is None).
293295
// In the nullary enum case, the parser can't determine
294296
// which it is. The resolver determines this, and
@@ -453,10 +455,10 @@ pub enum Expr_ {
453455
ExprCast(Gc<Expr>, P<Ty>),
454456
ExprIf(Gc<Expr>, P<Block>, Option<Gc<Expr>>),
455457
ExprWhile(Gc<Expr>, P<Block>),
456-
// FIXME #6993: change to Option<Name>
458+
// FIXME #6993: change to Option<Name> ... or not, if these are hygienic.
457459
ExprForLoop(Gc<Pat>, Gc<Expr>, P<Block>, Option<Ident>),
458460
// Conditionless loop (can be exited with break, cont, or ret)
459-
// FIXME #6993: change to Option<Name>
461+
// FIXME #6993: change to Option<Name> ... or not, if these are hygienic.
460462
ExprLoop(P<Block>, Option<Ident>),
461463
ExprMatch(Gc<Expr>, Vec<Arm>),
462464
ExprFnBlock(P<FnDecl>, P<Block>),
@@ -468,9 +470,8 @@ pub enum Expr_ {
468470
ExprField(Gc<Expr>, SpannedIdent, Vec<P<Ty>>),
469471
ExprIndex(Gc<Expr>, Gc<Expr>),
470472

471-
/// Expression that looks like a "name". For example,
472-
/// `std::slice::from_elem::<uint>` is an ExprPath that's the "name" part
473-
/// of a function call.
473+
/// Variable reference, possibly containing `::` and/or
474+
/// type parameters, e.g. foo::bar::<baz>
474475
ExprPath(Path),
475476

476477
ExprAddrOf(Mutability, Gc<Expr>),
@@ -643,6 +644,8 @@ pub struct TypeField {
643644
pub span: Span,
644645
}
645646

647+
/// Represents a required method in a trait declaration,
648+
/// one without a default implementation
646649
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
647650
pub struct TypeMethod {
648651
pub ident: Ident,
@@ -656,6 +659,8 @@ pub struct TypeMethod {
656659
pub vis: Visibility,
657660
}
658661

662+
/// Represents a method declaration in a trait declaration, possibly
663+
/// including a default implementation
659664
// A trait method is either required (meaning it doesn't have an
660665
// implementation, just a signature) or provided (meaning it has a default
661666
// implementation).
@@ -741,6 +746,7 @@ impl fmt::Show for Onceness {
741746
}
742747
}
743748

749+
/// Represents the type of a closure
744750
#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
745751
pub struct ClosureTy {
746752
pub lifetimes: Vec<Lifetime>,
@@ -809,6 +815,7 @@ pub struct InlineAsm {
809815
pub dialect: AsmDialect
810816
}
811817

818+
/// represents an argument in a function header
812819
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
813820
pub struct Arg {
814821
pub ty: P<Ty>,
@@ -836,7 +843,7 @@ impl Arg {
836843
}
837844
}
838845

839-
// represents the header (not the body) of a function declaration
846+
/// represents the header (not the body) of a function declaration
840847
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
841848
pub struct FnDecl {
842849
pub inputs: Vec<Arg>,
@@ -1107,6 +1114,7 @@ pub enum Item_ {
11071114
ItemTy(P<Ty>, Generics),
11081115
ItemEnum(EnumDef, Generics),
11091116
ItemStruct(Gc<StructDef>, Generics),
1117+
/// Represents a Trait Declaration
11101118
ItemTrait(Generics, Sized, Vec<TraitRef> , Vec<TraitMethod> ),
11111119
ItemImpl(Generics,
11121120
Option<TraitRef>, // (optional) trait this impl implements

src/libsyntax/ext/base.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use parse::parser;
1919
use parse::token;
2020
use parse::token::{InternedString, intern, str_to_ident};
2121
use util::small_vector::SmallVector;
22+
use ext::mtwt;
2223

2324
use std::collections::HashMap;
2425
use std::gc::{Gc, GC};
@@ -273,7 +274,7 @@ pub struct BlockInfo {
273274
// should macros escape from this scope?
274275
pub macros_escape: bool,
275276
// what are the pending renames?
276-
pub pending_renames: RenameList,
277+
pub pending_renames: mtwt::RenameList,
277278
}
278279

279280
impl BlockInfo {
@@ -285,9 +286,6 @@ impl BlockInfo {
285286
}
286287
}
287288

288-
// a list of ident->name renamings
289-
pub type RenameList = Vec<(ast::Ident, Name)>;
290-
291289
// The base map of methods for expanding syntax extension
292290
// AST nodes into full ASTs
293291
pub fn syntax_expander_table() -> SyntaxEnv {

0 commit comments

Comments
 (0)