auto merge of #15233 : jbclements/rust/match-var-hygiene-etc, r=cmr

This PR includes two big things and a bunch of little ones.

1) It enables hygiene for variables bound by 'match' expressions.
2) It fixes a bug discovered indirectly (#15221), wherein fold traversal failed to visit nonterminal nodes.
3) It fixes a small bug in the macro tutorial.

It also adds tests for the first two, and makes a bunch of small comment improvements and cleanup.
This commit is contained in:
bors 2014-06-28 05:21:34 +00:00
commit 0ddf6f4b7c
22 changed files with 288 additions and 177 deletions

View file

@ -15,7 +15,7 @@
// This also serves as a pipes test, because Arcs are implemented with pipes.
// ignore-pretty FIXME #15189
// no-pretty-expanded FIXME #15189
extern crate time;

View file

@ -15,7 +15,7 @@
// This also serves as a pipes test, because Arcs are implemented with pipes.
// ignore-pretty FIXME #15189
// no-pretty-expanded FIXME #15189
extern crate time;

View file

@ -38,7 +38,7 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
// ignore-pretty FIXME #15189
// no-pretty-expanded FIXME #15189
#![feature(phase)]
#[phase(plugin)] extern crate green;

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-pretty FIXME #15189
// no-pretty-expanded FIXME #15189
#![feature(phase)]
#![allow(non_snake_case_functions)]

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-pretty FIXME #15189
// no-pretty-expanded FIXME #15189
// ignore-win32 FIXME #13259
extern crate native;

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-pretty FIXME #15189
// no-pretty-expanded FIXME #15189
#[deriving(PartialEq, Eq, PartialOrd, Ord)]
enum E<T> {

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-pretty FIXME #15189
// no-pretty-expanded FIXME #15189
#![feature(struct_variant)]

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-pretty FIXME #15189
// no-pretty-expanded FIXME #15189
#[deriving(PartialEq, Eq, PartialOrd, Ord)]
struct S<T> {

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-pretty FIXME #15189
// no-pretty-expanded FIXME #15189
#[deriving(PartialEq, Eq, PartialOrd, Ord)]
struct TS<T>(T,T);

View file

@ -0,0 +1,23 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(macro_rules)]
macro_rules! inner (
($e:pat ) => ($e))
macro_rules! outer (
($e:pat ) => (inner!($e)))
fn main() {
let outer!(g1) = 13;
g1;
}

View file

@ -10,23 +10,28 @@
#![feature(macro_rules)]
// after fixing #9384 and implementing hygiene for match bindings,
// this now fails because the insertion of the 'y' into the match
// doesn't cause capture. Making this macro hygienic (as I've done)
// could very well make this test case completely pointless....
enum T {
A(int),
B(uint)
}
macro_rules! test(
($e:expr) => (
($id:ident, $e:expr) => (
fn foo(t: T) -> int {
match t {
A(y) => $e,
B(y) => $e
A($id) => $e,
B($id) => $e
}
}
)
)
test!(10 + (y as int))
test!(y, 10 + (y as int))
pub fn main() {
foo(A(20));

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-pretty FIXME #15189
// no-pretty-expanded FIXME #15189
extern crate debug;

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-pretty FIXME #15189
// no-pretty-expanded FIXME #15189
extern crate debug;

View file

@ -15,19 +15,24 @@ enum T {
B(f64)
}
// after fixing #9384 and implementing hygiene for match bindings,
// this now fails because the insertion of the 'y' into the match
// doesn't cause capture. Making this macro hygienic (as I've done)
// could very well make this test case completely pointless....
macro_rules! test(
($e:expr) => (
($id1:ident, $id2:ident, $e:expr) => (
fn foo(a:T, b:T) -> T {
match (a, b) {
(A(x), A(y)) => A($e),
(B(x), B(y)) => B($e),
(A($id1), A($id2)) => A($e),
(B($id1), B($id2)) => B($e),
_ => fail!()
}
}
)
)
test!(x + y)
test!(x,y,x + y)
pub fn main() {
foo(A(1), A(2));

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-pretty FIXME #15189
// no-pretty-expanded FIXME #15189
use std::iter::Unfold;

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-pretty FIXME #15189
// no-pretty-expanded FIXME #15189
pub fn main() {
let yen: char = '¥'; // 0xa5