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:
commit
0ddf6f4b7c
22 changed files with 288 additions and 177 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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> {
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
|
||||
|
|
|
|||
|
|
@ -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> {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
23
src/test/run-pass/issue-15221.rs
Normal file
23
src/test/run-pass/issue-15221.rs
Normal 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;
|
||||
}
|
||||
|
||||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue