diff options
| author | bors <bors@rust-lang.org> | 2015-02-25 20:32:58 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-02-25 20:32:58 +0000 |
| commit | 4db0b32467535d718d6474de7ae8d1007d900818 (patch) | |
| tree | 85c3f0131e2347eb2c0b2931a6c41284a52aaa1b /src/test | |
| parent | 880fb89bde126aa43fc348d0b93839d3d18a1f51 (diff) | |
| parent | 357b41bfcfcfd902d842a20f2c5858b8e196495d (diff) | |
| download | rust-4db0b32467535d718d6474de7ae8d1007d900818.tar.gz rust-4db0b32467535d718d6474de7ae8d1007d900818.zip | |
Auto merge of #22796 - Manishearth:rollup, r=Manishearth
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/compile-fail/borrowck-fn-in-const-a.rs | 22 | ||||
| -rw-r--r-- | src/test/compile-fail/borrowck-fn-in-const-b.rs | 24 | ||||
| -rw-r--r-- | src/test/compile-fail/borrowck-fn-in-const-c.rs | 33 | ||||
| -rw-r--r-- | src/test/compile-fail/lint-unsafe-code.rs | 49 | ||||
| -rw-r--r-- | src/test/compile-fail/unsafe_no_drop_flag-gate.rs | 23 | ||||
| -rw-r--r-- | src/test/run-pass/auto-ref-sliceable.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/coerce-reborrow-mut-vec-arg.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/coerce-reborrow-mut-vec-rcvr.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/env-home-dir.rs | 9 | ||||
| -rw-r--r-- | src/test/run-pass/generic-static-methods.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/issue-15149.rs | 32 | ||||
| -rw-r--r-- | src/test/run-pass/issue-16272.rs | 6 | ||||
| -rw-r--r-- | src/test/run-pass/issue-20091.rs | 17 | ||||
| -rw-r--r-- | src/test/run-pass/issue-3559.rs | 4 | ||||
| -rw-r--r-- | src/test/run-pass/monad.rs | 12 | ||||
| -rw-r--r-- | src/test/run-pass/std-sync-right-kind-impls.rs | 27 | ||||
| -rw-r--r-- | src/test/run-pass/trait-generic.rs | 8 | ||||
| -rw-r--r-- | src/test/run-pass/unboxed-closures-infer-upvar.rs | 2 |
18 files changed, 229 insertions, 47 deletions
diff --git a/src/test/compile-fail/borrowck-fn-in-const-a.rs b/src/test/compile-fail/borrowck-fn-in-const-a.rs new file mode 100644 index 00000000000..3098807f272 --- /dev/null +++ b/src/test/compile-fail/borrowck-fn-in-const-a.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 <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. + +// Check that we check fns appearing in constant declarations. +// Issue #22382. + +const MOVE: fn(&String) -> String = { + fn broken(x: &String) -> String { + return *x //~ ERROR cannot move + } + broken +}; + +fn main() { +} diff --git a/src/test/compile-fail/borrowck-fn-in-const-b.rs b/src/test/compile-fail/borrowck-fn-in-const-b.rs new file mode 100644 index 00000000000..7e29b2ee0fd --- /dev/null +++ b/src/test/compile-fail/borrowck-fn-in-const-b.rs @@ -0,0 +1,24 @@ +// 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. + +// Check that we check fns appearing in constant declarations. +// Issue #22382. + +// How about mutating an immutable vector? +const MUTATE: fn(&Vec<String>) = { + fn broken(x: &Vec<String>) { + x.push(format!("this is broken")); + //~^ ERROR cannot borrow + } + broken +}; + +fn main() { +} diff --git a/src/test/compile-fail/borrowck-fn-in-const-c.rs b/src/test/compile-fail/borrowck-fn-in-const-c.rs new file mode 100644 index 00000000000..e607397e920 --- /dev/null +++ b/src/test/compile-fail/borrowck-fn-in-const-c.rs @@ -0,0 +1,33 @@ +// 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. + +// Check that we check fns appearing in constant declarations. +// Issue #22382. + +// Returning local references? +struct DropString { + inner: String +} +impl Drop for DropString { + fn drop(&mut self) { + self.inner.clear(); + self.inner.push_str("dropped"); + } +} +const LOCAL_REF: fn() -> &'static str = { + fn broken() -> &'static str { + let local = DropString { inner: format!("Some local string") }; + return &local.inner; //~ ERROR does not live long enough + } + broken +}; + +fn main() { +} diff --git a/src/test/compile-fail/lint-unsafe-code.rs b/src/test/compile-fail/lint-unsafe-code.rs index 7b17d887757..8440cf3a88e 100644 --- a/src/test/compile-fail/lint-unsafe-code.rs +++ b/src/test/compile-fail/lint-unsafe-code.rs @@ -15,6 +15,8 @@ use std::marker::PhantomFn; struct Bar; +struct Bar2; +struct Bar3; #[allow(unsafe_code)] mod allowed_unsafe { @@ -46,6 +48,53 @@ impl Baz for Bar { unsafe fn provided_override(&self) {} //~ ERROR: implementation of an `unsafe` method } + +#[allow(unsafe_code)] +trait A { + unsafe fn allowed_unsafe(&self); + unsafe fn allowed_unsafe_provided(&self) {} +} + +#[allow(unsafe_code)] +impl Baz for Bar2 { + unsafe fn baz(&self) {} + unsafe fn provided_override(&self) {} +} + +impl Baz for Bar3 { + #[allow(unsafe_code)] + unsafe fn baz(&self) {} + unsafe fn provided_override(&self) {} //~ ERROR: implementation of an `unsafe` method +} + +#[allow(unsafe_code)] +unsafe trait B { + fn dummy(&self) {} +} + +trait C { + #[allow(unsafe_code)] + unsafe fn baz(&self); + unsafe fn provided(&self) {} //~ ERROR: implementation of an `unsafe` method +} + +impl C for Bar { + #[allow(unsafe_code)] + unsafe fn baz(&self) {} + unsafe fn provided(&self) {} //~ ERROR: implementation of an `unsafe` method +} + +impl C for Bar2 { + unsafe fn baz(&self) {} //~ ERROR: implementation of an `unsafe` method +} + +trait D { + #[allow(unsafe_code)] + unsafe fn unsafe_provided(&self) {} +} + +impl D for Bar {} + fn main() { unsafe {} //~ ERROR: usage of an `unsafe` block diff --git a/src/test/compile-fail/unsafe_no_drop_flag-gate.rs b/src/test/compile-fail/unsafe_no_drop_flag-gate.rs new file mode 100644 index 00000000000..542698fd152 --- /dev/null +++ b/src/test/compile-fail/unsafe_no_drop_flag-gate.rs @@ -0,0 +1,23 @@ +// Copyright 2015 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. + +pub struct T; + +#[unsafe_no_drop_flag] +//~^ ERROR unsafe_no_drop_flag has unstable semantics and may be removed +pub struct S { + pub x: T, +} + +impl Drop for S { + fn drop(&mut self) {} +} + +pub fn main() {} diff --git a/src/test/run-pass/auto-ref-sliceable.rs b/src/test/run-pass/auto-ref-sliceable.rs index 652f21c2ae3..d2e9bc2efe7 100644 --- a/src/test/run-pass/auto-ref-sliceable.rs +++ b/src/test/run-pass/auto-ref-sliceable.rs @@ -23,5 +23,5 @@ pub fn main() { let mut v = vec!(1); v.push_val(2); v.push_val(3); - assert_eq!(v, vec!(1, 2, 3)); + assert_eq!(v, [1, 2, 3]); } diff --git a/src/test/run-pass/coerce-reborrow-mut-vec-arg.rs b/src/test/run-pass/coerce-reborrow-mut-vec-arg.rs index f87f2e07c9d..2473b4b674e 100644 --- a/src/test/run-pass/coerce-reborrow-mut-vec-arg.rs +++ b/src/test/run-pass/coerce-reborrow-mut-vec-arg.rs @@ -22,5 +22,5 @@ fn bar(v: &mut [uint]) { pub fn main() { let mut the_vec = vec!(1, 2, 3, 100); bar(&mut the_vec); - assert_eq!(the_vec, vec!(100, 3, 2, 1)); + assert_eq!(the_vec, [100, 3, 2, 1]); } diff --git a/src/test/run-pass/coerce-reborrow-mut-vec-rcvr.rs b/src/test/run-pass/coerce-reborrow-mut-vec-rcvr.rs index 4f97e6a2081..ea09bb3904d 100644 --- a/src/test/run-pass/coerce-reborrow-mut-vec-rcvr.rs +++ b/src/test/run-pass/coerce-reborrow-mut-vec-rcvr.rs @@ -18,5 +18,5 @@ fn bar(v: &mut [uint]) { pub fn main() { let mut the_vec = vec!(1, 2, 3, 100); bar(&mut the_vec); - assert_eq!(the_vec, vec!(100, 3, 2, 1)); + assert_eq!(the_vec, [100, 3, 2, 1]); } diff --git a/src/test/run-pass/env-home-dir.rs b/src/test/run-pass/env-home-dir.rs index 0e1ab73c02d..5d68a25a14a 100644 --- a/src/test/run-pass/env-home-dir.rs +++ b/src/test/run-pass/env-home-dir.rs @@ -9,13 +9,14 @@ // except according to those terms. use std::env::*; +use std::path::PathBuf; #[cfg(unix)] fn main() { let oldhome = var("HOME"); set_var("HOME", "/home/MountainView"); - assert!(home_dir() == Some(Path::new("/home/MountainView"))); + assert!(home_dir() == Some(PathBuf::new("/home/MountainView"))); remove_var("HOME"); if cfg!(target_os = "android") { @@ -36,14 +37,14 @@ fn main() { assert!(home_dir().is_some()); set_var("HOME", "/home/MountainView"); - assert!(home_dir() == Some(Path::new("/home/MountainView"))); + assert!(home_dir() == Some(PathBuf::new("/home/MountainView"))); remove_var("HOME"); set_var("USERPROFILE", "/home/MountainView"); - assert!(home_dir() == Some(Path::new("/home/MountainView"))); + assert!(home_dir() == Some(PathBuf::new("/home/MountainView"))); set_var("HOME", "/home/MountainView"); set_var("USERPROFILE", "/home/PaloAlto"); - assert!(home_dir() == Some(Path::new("/home/MountainView"))); + assert!(home_dir() == Some(PathBuf::new("/home/MountainView"))); } diff --git a/src/test/run-pass/generic-static-methods.rs b/src/test/run-pass/generic-static-methods.rs index 7f84efcdd5d..010f54dd559 100644 --- a/src/test/run-pass/generic-static-methods.rs +++ b/src/test/run-pass/generic-static-methods.rs @@ -24,5 +24,5 @@ impl<T> vec_utils<T> for Vec<T> { } pub fn main() { - assert_eq!(vec_utils::map_(&vec!(1,2,3), |&x| x+1), vec!(2,3,4)); + assert_eq!(vec_utils::map_(&vec!(1,2,3), |&x| x+1), [2,3,4]); } diff --git a/src/test/run-pass/issue-15149.rs b/src/test/run-pass/issue-15149.rs index aa176d5b0f0..d995ecc492e 100644 --- a/src/test/run-pass/issue-15149.rs +++ b/src/test/run-pass/issue-15149.rs @@ -1,5 +1,3 @@ -// no-prefer-dynamic - // 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. @@ -10,12 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::slice::SliceExt; -use std::old_io::{fs, USER_RWX}; -use std::process; +// no-prefer-dynamic + +#![feature(fs, process, env, path, rand)] + use std::env; -use std::old_path::BytesContainer; +use std::fs; +use std::process; use std::rand::random; +use std::str; fn main() { // If we're the child, make sure we were invoked correctly @@ -34,21 +35,20 @@ fn main() { fn test() { // If we're the parent, copy our own binary to a new directory. let my_path = env::current_exe().unwrap(); - let my_dir = my_path.dir_path(); + let my_dir = my_path.parent().unwrap(); let random_u32: u32 = random(); - let child_dir = Path::new(my_dir.join(format!("issue-15149-child-{}", - random_u32))); - fs::mkdir(&child_dir, USER_RWX).unwrap(); + let child_dir = my_dir.join(&format!("issue-15149-child-{}", random_u32)); + fs::create_dir(&child_dir).unwrap(); - let child_path = child_dir.join(format!("mytest{}", - env::consts::EXE_SUFFIX)); + let child_path = child_dir.join(&format!("mytest{}", + env::consts::EXE_SUFFIX)); fs::copy(&my_path, &child_path).unwrap(); // Append the new directory to our own PATH. let path = { let mut paths: Vec<_> = env::split_paths(&env::var_os("PATH").unwrap()).collect(); - paths.push(child_dir.clone()); + paths.push(child_dir.to_path_buf()); env::join_paths(paths.iter()).unwrap() }; @@ -58,9 +58,9 @@ fn test() { assert!(child_output.status.success(), format!("child assertion failed\n child stdout:\n {}\n child stderr:\n {}", - child_output.stdout.container_as_str().unwrap(), - child_output.stderr.container_as_str().unwrap())); + str::from_utf8(&child_output.stdout).unwrap(), + str::from_utf8(&child_output.stderr).unwrap())); - fs::rmdir_recursive(&child_dir).unwrap(); + fs::remove_dir_all(&child_dir).unwrap(); } diff --git a/src/test/run-pass/issue-16272.rs b/src/test/run-pass/issue-16272.rs index 3bab78ab0df..92d8dfa2cf9 100644 --- a/src/test/run-pass/issue-16272.rs +++ b/src/test/run-pass/issue-16272.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::old_io::{process, Command}; +use std::process::Command; use std::env; fn main() { @@ -22,10 +22,8 @@ fn main() { } fn test() { - let status = Command::new(env::current_exe().unwrap()) + let status = Command::new(&env::current_exe().unwrap()) .arg("foo").arg("") - .stdout(process::InheritFd(1)) - .stderr(process::InheritFd(2)) .status().unwrap(); assert!(status.success()); } diff --git a/src/test/run-pass/issue-20091.rs b/src/test/run-pass/issue-20091.rs index 4d20e6360ad..ba107dd2cf9 100644 --- a/src/test/run-pass/issue-20091.rs +++ b/src/test/run-pass/issue-20091.rs @@ -8,14 +8,19 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// ignore-windows currently windows requires UTF-8 for spawning processes - -use std::old_io::Command; -use std::env; - +#[cfg(unix)] fn main() { + use std::process::Command; + use std::env; + use std::os::unix::prelude::*; + use std::ffi::OsStr; + if env::args().len() == 1 { - assert!(Command::new(env::current_exe().unwrap()).arg(b"\xff") + assert!(Command::new(&env::current_exe().unwrap()) + .arg(<OsStr as OsStrExt>::from_bytes(b"\xff")) .status().unwrap().success()) } } + +#[cfg(windows)] +fn main() {} diff --git a/src/test/run-pass/issue-3559.rs b/src/test/run-pass/issue-3559.rs index 754412ea949..3f1a1c75d8a 100644 --- a/src/test/run-pass/issue-3559.rs +++ b/src/test/run-pass/issue-3559.rs @@ -24,6 +24,6 @@ pub fn main() { let mut table = HashMap::new(); table.insert("one".to_string(), 1); table.insert("two".to_string(), 2); - assert!(check_strs(&format!("{:?}", table), "HashMap {\"one\": 1, \"two\": 2}") || - check_strs(&format!("{:?}", table), "HashMap {\"two\": 2, \"one\": 1}")); + assert!(check_strs(&format!("{:?}", table), "{\"one\": 1, \"two\": 2}") || + check_strs(&format!("{:?}", table), "{\"two\": 2, \"one\": 1}")); } diff --git a/src/test/run-pass/monad.rs b/src/test/run-pass/monad.rs index 457c0a35fd7..0d563f1a714 100644 --- a/src/test/run-pass/monad.rs +++ b/src/test/run-pass/monad.rs @@ -44,11 +44,11 @@ fn transform(x: Option<int>) -> Option<String> { pub fn main() { assert_eq!(transform(Some(10)), Some("11".to_string())); assert_eq!(transform(None), None); - assert!((vec!("hi".to_string())) + assert_eq!((vec!("hi".to_string())) .bind(|x| vec!(x.clone(), format!("{}!", x)) ) - .bind(|x| vec!(x.clone(), format!("{}?", x)) ) == - vec!("hi".to_string(), - "hi?".to_string(), - "hi!".to_string(), - "hi!?".to_string())); + .bind(|x| vec!(x.clone(), format!("{}?", x)) ), + ["hi".to_string(), + "hi?".to_string(), + "hi!".to_string(), + "hi!?".to_string()]); } diff --git a/src/test/run-pass/std-sync-right-kind-impls.rs b/src/test/run-pass/std-sync-right-kind-impls.rs new file mode 100644 index 00000000000..d2d72ed1661 --- /dev/null +++ b/src/test/run-pass/std-sync-right-kind-impls.rs @@ -0,0 +1,27 @@ +// Copyright 2015 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. + +use std::sync; + +fn assert_both<T: Sync + Send>() {} + +fn main() { + assert_both::<sync::StaticMutex>(); + assert_both::<sync::StaticCondvar>(); + assert_both::<sync::StaticRwLock>(); + assert_both::<sync::Mutex<()>>(); + assert_both::<sync::Condvar>(); + assert_both::<sync::RwLock<()>>(); + assert_both::<sync::Semaphore>(); + assert_both::<sync::Barrier>(); + assert_both::<sync::Arc<()>>(); + assert_both::<sync::Weak<()>>(); + assert_both::<sync::Once>(); +} diff --git a/src/test/run-pass/trait-generic.rs b/src/test/run-pass/trait-generic.rs index 5f4b18df6e1..0dedf621a4f 100644 --- a/src/test/run-pass/trait-generic.rs +++ b/src/test/run-pass/trait-generic.rs @@ -44,9 +44,9 @@ fn bar<U:to_str,T:map<U>>(x: T) -> Vec<String> { } pub fn main() { - assert_eq!(foo(vec!(1)), vec!("hi".to_string())); - assert_eq!(bar::<int, Vec<int> >(vec!(4, 5)), vec!("4".to_string(), "5".to_string())); + assert_eq!(foo(vec!(1)), ["hi".to_string()]); + assert_eq!(bar::<int, Vec<int> >(vec!(4, 5)), ["4".to_string(), "5".to_string()]); assert_eq!(bar::<String, Vec<String> >(vec!("x".to_string(), "y".to_string())), - vec!("x".to_string(), "y".to_string())); - assert_eq!(bar::<(), Vec<()>>(vec!(())), vec!("()".to_string())); + ["x".to_string(), "y".to_string()]); + assert_eq!(bar::<(), Vec<()>>(vec!(())), ["()".to_string()]); } diff --git a/src/test/run-pass/unboxed-closures-infer-upvar.rs b/src/test/run-pass/unboxed-closures-infer-upvar.rs index 087ef5dcf05..1401fe7470b 100644 --- a/src/test/run-pass/unboxed-closures-infer-upvar.rs +++ b/src/test/run-pass/unboxed-closures-infer-upvar.rs @@ -18,5 +18,5 @@ fn f<F: FnMut()>(mut f: F) { fn main() { let mut v: Vec<_> = vec![]; f(|| v.push(0)); - assert_eq!(v, vec![0]); + assert_eq!(v, [0]); } |
