From fd88e2b7291170d0dac536130307a8cc680c8294 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 20 May 2014 20:28:00 -0700 Subject: [PATCH 01/12] syntax: Parse global paths in patterns Closes #6449 --- src/libsyntax/parse/parser.rs | 2 +- src/test/run-pass/issue-6449.rs | 51 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/test/run-pass/issue-6449.rs diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c42febcd607..5829f63b2c5 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2920,7 +2920,7 @@ impl<'a> Parser<'a> { _ => {} } - if !is_ident_or_path(&self.token) + if (!is_ident_or_path(&self.token) && self.token != token::MOD_SEP) || self.is_keyword(keywords::True) || self.is_keyword(keywords::False) { // Parse an expression pattern or exp .. exp. diff --git a/src/test/run-pass/issue-6449.rs b/src/test/run-pass/issue-6449.rs new file mode 100644 index 00000000000..48e2890b259 --- /dev/null +++ b/src/test/run-pass/issue-6449.rs @@ -0,0 +1,51 @@ +// Copyright 2012-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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +enum Foo { + Bar(int), + Baz, +} + +enum Other { + Other1(Foo), + Other2(Foo, Foo), +} + +fn main() { + match Baz { + ::Bar(3) => fail!(), + ::Bar(_) if false => fail!(), + ::Bar(..) if false => fail!(), + ::Bar(_n) => fail!(), + ::Baz => {} + } + match Bar(3) { + ::Bar(3) => {} + ::Bar(_) if false => fail!(), + ::Bar(..) if false => fail!(), + ::Bar(_n) => fail!(), + ::Baz => fail!(), + } + match Bar(4) { + ::Bar(3) => fail!(), + ::Bar(_) if false => fail!(), + ::Bar(..) if false => fail!(), + ::Bar(n) => assert_eq!(n, 4), + ::Baz => fail!(), + } + + match Other1(Baz) { + ::Other1(::Baz) => {} + ::Other1(::Bar(_)) => {} + ::Other2(::Baz, ::Bar(_)) => {} + ::Other2(::Bar(..), ::Baz) => {} + ::Other2(..) => {} + } +} From aef1a9c57b2b21f3a227ead094d4d7add6f57522 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 20 May 2014 20:39:15 -0700 Subject: [PATCH 02/12] rustc: Prevant an out of bounds access in typeck Closes #7092 --- src/librustc/middle/typeck/check/method.rs | 18 +++++++----------- src/test/compile-fail/issue-7092.rs | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 src/test/compile-fail/issue-7092.rs diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index 839e3dd080a..9e8edfccd5b 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -555,17 +555,13 @@ impl<'a> LookupContext<'a> { param_ty: param_ty) { debug!("push_inherent_candidates_from_param(param_ty={:?})", param_ty); - self.push_inherent_candidates_from_bounds( - rcvr_ty, - self.fcx - .inh - .param_env - .type_param_bounds - .get(param_ty.idx) - .trait_bounds - .as_slice(), - restrict_to, - param_numbered(param_ty.idx)); + let i = param_ty.idx; + match self.fcx.inh.param_env.type_param_bounds.as_slice().get(i) { + Some(b) => self.push_inherent_candidates_from_bounds( + rcvr_ty, b.trait_bounds.as_slice(), restrict_to, + param_numbered(param_ty.idx)), + None => {} + } } diff --git a/src/test/compile-fail/issue-7092.rs b/src/test/compile-fail/issue-7092.rs new file mode 100644 index 00000000000..bcecab80758 --- /dev/null +++ b/src/test/compile-fail/issue-7092.rs @@ -0,0 +1,22 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +enum Whatever { +} + +fn foo(x: Whatever) { + match x { + Some(field) => field.access(), + //~^ ERROR: mismatched types: expected `Whatever` but found + //~^^ ERROR: does not implement any method in scope named `access` + } +} + +fn main(){} From 8505b14b00420605679b39d9b23484b8b0820364 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 20 May 2014 21:00:56 -0700 Subject: [PATCH 03/12] rustc: Fix a dynamic borrow error in resolve Closes #8208 Closes #10980 --- src/librustc/middle/resolve.rs | 2 +- src/test/compile-fail/issue-8208.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/test/compile-fail/issue-8208.rs diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index cd3375799a3..ac37af05359 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -2040,7 +2040,7 @@ impl<'a> Resolver<'a> { return; } - let mut imports = module.imports.borrow_mut(); + let imports = module.imports.borrow(); let import_count = imports.len(); while module.resolved_import_count.get() < import_count { let import_index = module.resolved_import_count.get(); diff --git a/src/test/compile-fail/issue-8208.rs b/src/test/compile-fail/issue-8208.rs new file mode 100644 index 00000000000..8d8e87da76e --- /dev/null +++ b/src/test/compile-fail/issue-8208.rs @@ -0,0 +1,17 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(globs)] + +use self::*; //~ ERROR: unresolved import + +fn main() { +} + From d3a0471490493176e742c545fb505a35ada63b60 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 20 May 2014 21:11:28 -0700 Subject: [PATCH 04/12] test: Add a test for fixed issue #10763 Closes #10763 --- src/test/run-pass/issue-10763.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/test/run-pass/issue-10763.rs diff --git a/src/test/run-pass/issue-10763.rs b/src/test/run-pass/issue-10763.rs new file mode 100644 index 00000000000..92ea6026ff6 --- /dev/null +++ b/src/test/run-pass/issue-10763.rs @@ -0,0 +1,13 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +extern "Rust" fn foo() {} + +fn main() {} From f0a1df692e9580f5aad837da1a5725f026b19a45 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 20 May 2014 21:24:01 -0700 Subject: [PATCH 05/12] test: Add test for fixed issue #11736 Closes #11736 --- src/test/run-pass/issue-11736.rs | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/test/run-pass/issue-11736.rs diff --git a/src/test/run-pass/issue-11736.rs b/src/test/run-pass/issue-11736.rs new file mode 100644 index 00000000000..4eb9dd1474e --- /dev/null +++ b/src/test/run-pass/issue-11736.rs @@ -0,0 +1,35 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +extern crate collections; +extern crate std; + +use collections::Bitv; + +fn main() { + // Generate sieve of Eratosthenes for n up to 1e6 + let n = 1000000u; + let sieve = Bitv::new(n+1, true); + let limit: uint = (n as f32).sqrt() as uint; + for i in range(2, limit+1) { + if sieve[i] { + let mut j = 0; + while i*i + j*i <= n { + sieve[i*i+j*i] = false; + j += 1; + } + } + } + for i in range(2, n+1) { + if sieve[i] { + } + } +} + From 1b2dd90f1b23e612f4ab499656d02d367594d45d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 20 May 2014 21:25:49 -0700 Subject: [PATCH 06/12] test: Add a test for fixed issue #11844 Closes #11844 --- src/test/compile-fail/issue-11844.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/test/compile-fail/issue-11844.rs diff --git a/src/test/compile-fail/issue-11844.rs b/src/test/compile-fail/issue-11844.rs new file mode 100644 index 00000000000..4e11481b5d2 --- /dev/null +++ b/src/test/compile-fail/issue-11844.rs @@ -0,0 +1,19 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let a = Some(box 1); + match a { + Ok(a) => //~ ERROR: mismatched types + println!("{}",a), //~ ERROR: failed to find an implementation of trait + None => fail!() + } +} + From 40d3241a4a929dc095dd94862e25e5684ef1083d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 20 May 2014 21:34:10 -0700 Subject: [PATCH 07/12] rustc: Avoid out of bounds in check_match Closes #12116 --- src/librustc/middle/check_match.rs | 1 + src/test/compile-fail/issue-12116.rs | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/test/compile-fail/issue-12116.rs diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 1017f4cfe2f..67bdb949327 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -247,6 +247,7 @@ fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@Pat]) -> useful { _ => *r.get(0) } } + None if v.len() == 0 => return not_useful, None => v[0] }; let left_ty = if real_pat.id == 0 { ty::mk_nil() } diff --git a/src/test/compile-fail/issue-12116.rs b/src/test/compile-fail/issue-12116.rs new file mode 100644 index 00000000000..a80e405d05c --- /dev/null +++ b/src/test/compile-fail/issue-12116.rs @@ -0,0 +1,25 @@ +// Copyright 2012-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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +enum IntList { + Cons(int, Box), + Nil +} + +fn tail(source_list: &IntList) -> IntList { + match source_list { + &Cons(val, box ref next_list) => tail(next_list), + &Cons(val, box Nil) => Cons(val, box Nil), + //~^ ERROR: unreachable pattern + _ => fail!() + } +} + +fn main() {} From 0089215472db188f7d102fa3fa3e086880d2ee4f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 20 May 2014 21:42:30 -0700 Subject: [PATCH 08/12] rustc: Avoid an unwrap() in check_match Closes #12369 --- src/librustc/middle/check_match.rs | 6 ++++-- src/test/compile-fail/issue-12369.rs | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 src/test/compile-fail/issue-12369.rs diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 67bdb949327..7b91928ba41 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -342,8 +342,10 @@ fn is_useful_specialized(cx: &MatchCheckCtxt, let ms = m.iter().filter_map(|r| { specialize(cx, r.as_slice(), &ctor, arity, lty) }).collect::(); - let could_be_useful = is_useful( - cx, &ms, specialize(cx, v, &ctor, arity, lty).unwrap().as_slice()); + let could_be_useful = match specialize(cx, v, &ctor, arity, lty) { + Some(v) => is_useful(cx, &ms, v.as_slice()), + None => return not_useful, + }; match could_be_useful { useful_ => useful(lty, ctor), u => u, diff --git a/src/test/compile-fail/issue-12369.rs b/src/test/compile-fail/issue-12369.rs new file mode 100644 index 00000000000..7d800899e52 --- /dev/null +++ b/src/test/compile-fail/issue-12369.rs @@ -0,0 +1,19 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let sl = vec![1,2,3]; + let v: int = match sl.as_slice() { + [] => 0, + [a,b,c] => 3, + [a, ..rest] => a, + [10,a, ..rest] => 10 //~ ERROR: unreachable pattern + }; +} From 827999cd1fe866582007611becd1bfeb02405c6f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 20 May 2014 21:44:22 -0700 Subject: [PATCH 09/12] test: Add a test for fixed issue #12567 Closes #12567 --- src/test/compile-fail/issue-12567.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/test/compile-fail/issue-12567.rs diff --git a/src/test/compile-fail/issue-12567.rs b/src/test/compile-fail/issue-12567.rs new file mode 100644 index 00000000000..d5a8339ba19 --- /dev/null +++ b/src/test/compile-fail/issue-12567.rs @@ -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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn match_vecs<'a, T>(l1: &'a [T], l2: &'a [T]) { + match (l1, l2) { + ([], []) => println!("both empty"), + ([], [hd, ..tl]) | ([hd, ..tl], []) => println!("one empty"), + //~^ ERROR: cannot move out of dereference + //~^^ ERROR: cannot move out of dereference + ([hd1, ..tl1], [hd2, ..tl2]) => println!("both nonempty"), + //~^ ERROR: cannot move out of dereference + //~^^ ERROR: cannot move out of dereference + } +} + +fn main() {} From 4aac621b5accd679a9c6a71d602cc892a828395e Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 20 May 2014 21:47:12 -0700 Subject: [PATCH 10/12] test: Add test for fixed issue #12796 Doesn't close #12796 because the error message is awful. --- src/test/compile-fail/issue-12796.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/test/compile-fail/issue-12796.rs diff --git a/src/test/compile-fail/issue-12796.rs b/src/test/compile-fail/issue-12796.rs new file mode 100644 index 00000000000..8b5fb90e2d4 --- /dev/null +++ b/src/test/compile-fail/issue-12796.rs @@ -0,0 +1,20 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// error-pattern: missing `Self` type param in the substitution of `fn(Self)` + +trait Trait { + fn outer(self) { + fn inner(_: Self) { + } + } +} + +fn main() { } From a016aa2405470f40c3f92a6decae630c883b25d1 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 20 May 2014 22:07:45 -0700 Subject: [PATCH 11/12] rustc: Turn a Box ICE into an error Closes #14092 --- src/librustc/middle/typeck/astconv.rs | 5 +++-- src/test/compile-fail/issue-14092.rs | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 src/test/compile-fail/issue-14092.rs diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index e9a95a4a9eb..cb3e900af7d 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -433,9 +433,10 @@ pub fn ast_ty_to_builtin_ty`") + supplied to `Box`"); + Some(ty::mk_err()) } _ => None } diff --git a/src/test/compile-fail/issue-14092.rs b/src/test/compile-fail/issue-14092.rs new file mode 100644 index 00000000000..4d663d00fb2 --- /dev/null +++ b/src/test/compile-fail/issue-14092.rs @@ -0,0 +1,14 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn fn1(0: Box) {} //~ ERROR: not enough type parameters supplied to `Box` + +fn main() {} + From 0d4b840523824252be67d191cc0945c5713ea47c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 20 May 2014 22:39:14 -0700 Subject: [PATCH 12/12] rustc: Fix an ICE with box-placement syntax Closes #14084 --- src/librustc/middle/typeck/check/mod.rs | 3 ++- src/test/compile-fail/issue-14084.rs | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/test/compile-fail/issue-14084.rs diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 68f4fd95626..820c5bd859c 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -2767,7 +2767,8 @@ fn check_expr_with_unifier(fcx: &FnCtxt, if !checked { tcx.sess.span_err(expr.span, "only the managed heap and exchange heap are \ - currently supported") + currently supported"); + fcx.write_ty(id, ty::mk_err()); } } diff --git a/src/test/compile-fail/issue-14084.rs b/src/test/compile-fail/issue-14084.rs new file mode 100644 index 00000000000..d247bf0913c --- /dev/null +++ b/src/test/compile-fail/issue-14084.rs @@ -0,0 +1,14 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + box ( () ) 0; + //~^ ERROR: only the managed heap and exchange heap are currently supported +}