Migrated remaining src/test/run-pass/ subdirectories to src/test/ui/run-pass/.
This commit is contained in:
parent
20ca02569a
commit
76ceeddb2b
171 changed files with 0 additions and 0 deletions
|
|
@ -1,26 +0,0 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![crate_type = "rlib"]
|
||||
|
||||
extern crate custom;
|
||||
|
||||
use std::sync::atomic::{ATOMIC_USIZE_INIT, Ordering};
|
||||
|
||||
use custom::A;
|
||||
|
||||
#[global_allocator]
|
||||
static ALLOCATOR: A = A(ATOMIC_USIZE_INIT);
|
||||
|
||||
pub fn get() -> usize {
|
||||
ALLOCATOR.0.load(Ordering::SeqCst)
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![feature(allocator_api)]
|
||||
#![crate_type = "rlib"]
|
||||
|
||||
use std::alloc::{GlobalAlloc, System, Layout};
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
pub struct A(pub AtomicUsize);
|
||||
|
||||
unsafe impl GlobalAlloc for A {
|
||||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
||||
self.0.fetch_add(1, Ordering::SeqCst);
|
||||
System.alloc(layout)
|
||||
}
|
||||
|
||||
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
|
||||
self.0.fetch_add(1, Ordering::SeqCst);
|
||||
System.dealloc(ptr, layout)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![crate_type = "rlib"]
|
||||
|
||||
use std::fmt;
|
||||
|
||||
pub fn work_with(p: &fmt::Debug) {
|
||||
drop(p);
|
||||
}
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
// aux-build:helper.rs
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![feature(allocator_api)]
|
||||
|
||||
extern crate helper;
|
||||
|
||||
use std::alloc::{self, Global, Alloc, System, Layout};
|
||||
use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};
|
||||
|
||||
static HITS: AtomicUsize = ATOMIC_USIZE_INIT;
|
||||
|
||||
struct A;
|
||||
|
||||
unsafe impl alloc::GlobalAlloc for A {
|
||||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
||||
HITS.fetch_add(1, Ordering::SeqCst);
|
||||
System.alloc(layout)
|
||||
}
|
||||
|
||||
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
|
||||
HITS.fetch_add(1, Ordering::SeqCst);
|
||||
System.dealloc(ptr, layout)
|
||||
}
|
||||
}
|
||||
|
||||
#[global_allocator]
|
||||
static GLOBAL: A = A;
|
||||
|
||||
fn main() {
|
||||
println!("hello!");
|
||||
|
||||
let n = HITS.load(Ordering::SeqCst);
|
||||
assert!(n > 0);
|
||||
unsafe {
|
||||
let layout = Layout::from_size_align(4, 2).unwrap();
|
||||
|
||||
let ptr = Global.alloc(layout.clone()).unwrap();
|
||||
helper::work_with(&ptr);
|
||||
assert_eq!(HITS.load(Ordering::SeqCst), n + 1);
|
||||
Global.dealloc(ptr, layout.clone());
|
||||
assert_eq!(HITS.load(Ordering::SeqCst), n + 2);
|
||||
|
||||
let s = String::with_capacity(10);
|
||||
helper::work_with(&s);
|
||||
assert_eq!(HITS.load(Ordering::SeqCst), n + 3);
|
||||
drop(s);
|
||||
assert_eq!(HITS.load(Ordering::SeqCst), n + 4);
|
||||
|
||||
let ptr = System.alloc(layout.clone()).unwrap();
|
||||
assert_eq!(HITS.load(Ordering::SeqCst), n + 4);
|
||||
helper::work_with(&ptr);
|
||||
System.dealloc(ptr, layout);
|
||||
assert_eq!(HITS.load(Ordering::SeqCst), n + 4);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
// aux-build:custom.rs
|
||||
// aux-build:helper.rs
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![feature(allocator_api)]
|
||||
|
||||
extern crate custom;
|
||||
extern crate helper;
|
||||
|
||||
use std::alloc::{Global, Alloc, System, Layout};
|
||||
use std::sync::atomic::{Ordering, ATOMIC_USIZE_INIT};
|
||||
|
||||
#[global_allocator]
|
||||
static GLOBAL: custom::A = custom::A(ATOMIC_USIZE_INIT);
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
let n = GLOBAL.0.load(Ordering::SeqCst);
|
||||
let layout = Layout::from_size_align(4, 2).unwrap();
|
||||
|
||||
let ptr = Global.alloc(layout.clone()).unwrap();
|
||||
helper::work_with(&ptr);
|
||||
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 1);
|
||||
Global.dealloc(ptr, layout.clone());
|
||||
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 2);
|
||||
|
||||
let ptr = System.alloc(layout.clone()).unwrap();
|
||||
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 2);
|
||||
helper::work_with(&ptr);
|
||||
System.dealloc(ptr, layout);
|
||||
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 2);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
// aux-build:custom.rs
|
||||
// aux-build:custom-as-global.rs
|
||||
// aux-build:helper.rs
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![feature(allocator_api)]
|
||||
|
||||
extern crate custom;
|
||||
extern crate custom_as_global;
|
||||
extern crate helper;
|
||||
|
||||
use std::alloc::{alloc, dealloc, GlobalAlloc, System, Layout};
|
||||
use std::sync::atomic::{Ordering, ATOMIC_USIZE_INIT};
|
||||
|
||||
static GLOBAL: custom::A = custom::A(ATOMIC_USIZE_INIT);
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
let n = custom_as_global::get();
|
||||
let layout = Layout::from_size_align(4, 2).unwrap();
|
||||
|
||||
// Global allocator routes to the `custom_as_global` global
|
||||
let ptr = alloc(layout.clone());
|
||||
helper::work_with(&ptr);
|
||||
assert_eq!(custom_as_global::get(), n + 1);
|
||||
dealloc(ptr, layout.clone());
|
||||
assert_eq!(custom_as_global::get(), n + 2);
|
||||
|
||||
// Usage of the system allocator avoids all globals
|
||||
let ptr = System.alloc(layout.clone());
|
||||
helper::work_with(&ptr);
|
||||
assert_eq!(custom_as_global::get(), n + 2);
|
||||
System.dealloc(ptr, layout.clone());
|
||||
assert_eq!(custom_as_global::get(), n + 2);
|
||||
|
||||
// Usage of our personal allocator doesn't affect other instances
|
||||
let ptr = GLOBAL.alloc(layout.clone());
|
||||
helper::work_with(&ptr);
|
||||
assert_eq!(custom_as_global::get(), n + 2);
|
||||
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), 1);
|
||||
GLOBAL.dealloc(ptr, layout);
|
||||
assert_eq!(custom_as_global::get(), n + 2);
|
||||
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
// Copyright 2016 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.
|
||||
|
||||
// pretty-expanded FIXME #23616
|
||||
|
||||
fn main() {
|
||||
let _ = test(Some(0).into_iter());
|
||||
}
|
||||
|
||||
trait Parser {
|
||||
type Input: Iterator;
|
||||
type Output;
|
||||
fn parse(self, input: Self::Input) -> Result<(Self::Output, Self::Input), ()>;
|
||||
fn chain<P>(self, p: P) -> Chain<Self, P> where Self: Sized {
|
||||
Chain(self, p)
|
||||
}
|
||||
}
|
||||
|
||||
struct Token<T>(T::Item) where T: Iterator;
|
||||
|
||||
impl<T> Parser for Token<T> where T: Iterator {
|
||||
type Input = T;
|
||||
type Output = T::Item;
|
||||
fn parse(self, _input: Self::Input) -> Result<(Self::Output, Self::Input), ()> {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
struct Chain<L, R>(L, R);
|
||||
|
||||
impl<L, R> Parser for Chain<L, R> where L: Parser, R: Parser<Input = L::Input> {
|
||||
type Input = L::Input;
|
||||
type Output = (L::Output, R::Output);
|
||||
fn parse(self, _input: Self::Input) -> Result<(Self::Output, Self::Input), ()> {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
fn test<I>(i: I) -> Result<((), I), ()> where I: Iterator<Item = i32> {
|
||||
Chain(Token(0), Token(1))
|
||||
.chain(Chain(Token(0), Token(1)))
|
||||
.chain(Chain(Token(0), Token(1)))
|
||||
.chain(Chain(Token(0), Token(1)))
|
||||
.chain(Chain(Token(0), Token(1)))
|
||||
.chain(Chain(Token(0), Token(1)))
|
||||
.chain(Chain(Token(0), Token(1)))
|
||||
.chain(Chain(Token(0), Token(1)))
|
||||
.chain(Chain(Token(0), Token(1)))
|
||||
.parse(i)
|
||||
.map(|(_, i)| ((), i))
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
trait Nat {
|
||||
const VALUE: usize;
|
||||
}
|
||||
|
||||
struct Zero;
|
||||
struct Succ<N>(N);
|
||||
|
||||
impl Nat for Zero {
|
||||
const VALUE: usize = 0;
|
||||
}
|
||||
|
||||
impl<N: Nat> Nat for Succ<N> {
|
||||
const VALUE: usize = N::VALUE + 1;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x: [i32; <Succ<Succ<Succ<Succ<Zero>>>>>::VALUE] = [1, 2, 3, 4];
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
// Copyright 2017 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(core_intrinsics)]
|
||||
|
||||
use std::intrinsics;
|
||||
|
||||
const SWAPPED_U8: u8 = unsafe { intrinsics::bswap(0x12_u8) };
|
||||
const SWAPPED_U16: u16 = unsafe { intrinsics::bswap(0x12_34_u16) };
|
||||
const SWAPPED_I32: i32 = unsafe { intrinsics::bswap(0x12_34_56_78_i32) };
|
||||
|
||||
fn main() {
|
||||
assert_eq!(SWAPPED_U8, 0x12);
|
||||
assert_eq!(SWAPPED_U16, 0x34_12);
|
||||
assert_eq!(SWAPPED_I32, 0x78_56_34_12);
|
||||
}
|
||||
|
|
@ -1,364 +0,0 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
// https://github.com/rust-lang/rust/issues/34997
|
||||
|
||||
pub const CST_1: u32 = 0;
|
||||
pub const CST_2: u32 = CST_1+1;
|
||||
pub const CST_3: u32 = CST_2+1;
|
||||
pub const CST_4: u32 = CST_3+1;
|
||||
pub const CST_5: u32 = CST_4+1;
|
||||
pub const CST_6: u32 = CST_5+1;
|
||||
pub const CST_7: u32 = CST_6+1;
|
||||
pub const CST_8: u32 = CST_7+1;
|
||||
pub const CST_9: u32 = CST_8+1;
|
||||
pub const CST_10: u32 = CST_9+1;
|
||||
pub const CST_11: u32 = CST_10+1;
|
||||
pub const CST_12: u32 = CST_11+1;
|
||||
pub const CST_13: u32 = CST_12+1;
|
||||
pub const CST_14: u32 = CST_13+1;
|
||||
pub const CST_15: u32 = CST_14+1;
|
||||
pub const CST_16: u32 = CST_15+1;
|
||||
pub const CST_17: u32 = CST_16+1;
|
||||
pub const CST_18: u32 = CST_17+1;
|
||||
pub const CST_19: u32 = CST_18+1;
|
||||
pub const CST_20: u32 = CST_19+1;
|
||||
pub const CST_21: u32 = CST_20+1;
|
||||
pub const CST_22: u32 = CST_21+1;
|
||||
pub const CST_23: u32 = CST_22+1;
|
||||
pub const CST_24: u32 = CST_23+1;
|
||||
pub const CST_25: u32 = CST_24+1;
|
||||
pub const CST_26: u32 = CST_25+1;
|
||||
pub const CST_27: u32 = CST_26+1;
|
||||
pub const CST_28: u32 = CST_27+1;
|
||||
pub const CST_29: u32 = CST_28+1;
|
||||
pub const CST_30: u32 = CST_29+1;
|
||||
pub const CST_31: u32 = CST_30+1;
|
||||
pub const CST_32: u32 = CST_31+1;
|
||||
pub const CST_33: u32 = CST_32+1;
|
||||
pub const CST_34: u32 = CST_33+1;
|
||||
pub const CST_35: u32 = CST_34+1;
|
||||
pub const CST_36: u32 = CST_35+1;
|
||||
pub const CST_37: u32 = CST_36+1;
|
||||
pub const CST_38: u32 = CST_37+1;
|
||||
pub const CST_39: u32 = CST_38+1;
|
||||
pub const CST_40: u32 = CST_39+1;
|
||||
pub const CST_41: u32 = CST_40+1;
|
||||
pub const CST_42: u32 = CST_41+1;
|
||||
pub const CST_43: u32 = CST_42+1;
|
||||
pub const CST_44: u32 = CST_43+1;
|
||||
pub const CST_45: u32 = CST_44+1;
|
||||
pub const CST_46: u32 = CST_45+1;
|
||||
pub const CST_47: u32 = CST_46+1;
|
||||
pub const CST_48: u32 = CST_47+1;
|
||||
pub const CST_49: u32 = CST_48+1;
|
||||
pub const CST_50: u32 = CST_49+1;
|
||||
pub const CST_51: u32 = CST_50+1;
|
||||
pub const CST_52: u32 = CST_51+1;
|
||||
pub const CST_53: u32 = CST_52+1;
|
||||
pub const CST_54: u32 = CST_53+1;
|
||||
pub const CST_55: u32 = CST_54+1;
|
||||
pub const CST_56: u32 = CST_55+1;
|
||||
pub const CST_57: u32 = CST_56+1;
|
||||
pub const CST_58: u32 = CST_57+1;
|
||||
pub const CST_59: u32 = CST_58+1;
|
||||
pub const CST_60: u32 = CST_59+1;
|
||||
pub const CST_61: u32 = CST_60+1;
|
||||
pub const CST_62: u32 = CST_61+1;
|
||||
pub const CST_63: u32 = CST_62+1;
|
||||
pub const CST_64: u32 = CST_63+1;
|
||||
pub const CST_65: u32 = CST_64+1;
|
||||
pub const CST_66: u32 = CST_65+1;
|
||||
pub const CST_67: u32 = CST_66+1;
|
||||
pub const CST_68: u32 = CST_67+1;
|
||||
pub const CST_69: u32 = CST_68+1;
|
||||
pub const CST_70: u32 = CST_69+1;
|
||||
pub const CST_71: u32 = CST_70+1;
|
||||
pub const CST_72: u32 = CST_71+1;
|
||||
pub const CST_73: u32 = CST_72+1;
|
||||
pub const CST_74: u32 = CST_73+1;
|
||||
pub const CST_75: u32 = CST_74+1;
|
||||
pub const CST_76: u32 = CST_75+1;
|
||||
pub const CST_77: u32 = CST_76+1;
|
||||
pub const CST_78: u32 = CST_77+1;
|
||||
pub const CST_79: u32 = CST_78+1;
|
||||
pub const CST_80: u32 = CST_79+1;
|
||||
pub const CST_81: u32 = CST_80+1;
|
||||
pub const CST_82: u32 = CST_81+1;
|
||||
pub const CST_83: u32 = CST_82+1;
|
||||
pub const CST_84: u32 = CST_83+1;
|
||||
pub const CST_85: u32 = CST_84+1;
|
||||
pub const CST_86: u32 = CST_85+1;
|
||||
pub const CST_87: u32 = CST_86+1;
|
||||
pub const CST_88: u32 = CST_87+1;
|
||||
pub const CST_89: u32 = CST_88+1;
|
||||
pub const CST_90: u32 = CST_89+1;
|
||||
pub const CST_91: u32 = CST_90+1;
|
||||
pub const CST_92: u32 = CST_91+1;
|
||||
pub const CST_93: u32 = CST_92+1;
|
||||
pub const CST_94: u32 = CST_93+1;
|
||||
pub const CST_95: u32 = CST_94+1;
|
||||
pub const CST_96: u32 = CST_95+1;
|
||||
pub const CST_97: u32 = CST_96+1;
|
||||
pub const CST_98: u32 = CST_97+1;
|
||||
pub const CST_99: u32 = CST_98+1;
|
||||
pub const CST_100: u32 = CST_99+1;
|
||||
pub const CST_101: u32 = CST_100+1;
|
||||
pub const CST_102: u32 = CST_101+1;
|
||||
pub const CST_103: u32 = CST_102+1;
|
||||
pub const CST_104: u32 = CST_103+1;
|
||||
pub const CST_105: u32 = CST_104+1;
|
||||
pub const CST_106: u32 = CST_105+1;
|
||||
pub const CST_107: u32 = CST_106+1;
|
||||
pub const CST_108: u32 = CST_107+1;
|
||||
pub const CST_109: u32 = CST_108+1;
|
||||
pub const CST_110: u32 = CST_109+1;
|
||||
pub const CST_111: u32 = CST_110+1;
|
||||
pub const CST_112: u32 = CST_111+1;
|
||||
pub const CST_113: u32 = CST_112+1;
|
||||
pub const CST_114: u32 = CST_113+1;
|
||||
pub const CST_115: u32 = CST_114+1;
|
||||
pub const CST_116: u32 = CST_115+1;
|
||||
pub const CST_117: u32 = CST_116+1;
|
||||
pub const CST_118: u32 = CST_117+1;
|
||||
pub const CST_119: u32 = CST_118+1;
|
||||
pub const CST_120: u32 = CST_119+1;
|
||||
pub const CST_121: u32 = CST_120+1;
|
||||
pub const CST_122: u32 = CST_121+1;
|
||||
pub const CST_123: u32 = CST_122+1;
|
||||
pub const CST_124: u32 = CST_123+1;
|
||||
pub const CST_125: u32 = CST_124+1;
|
||||
pub const CST_126: u32 = CST_125+1;
|
||||
pub const CST_127: u32 = CST_126+1;
|
||||
pub const CST_128: u32 = CST_127+1;
|
||||
pub const CST_129: u32 = CST_128+1;
|
||||
pub const CST_130: u32 = CST_129+1;
|
||||
pub const CST_131: u32 = CST_130+1;
|
||||
pub const CST_132: u32 = CST_131+1;
|
||||
pub const CST_133: u32 = CST_132+1;
|
||||
pub const CST_134: u32 = CST_133+1;
|
||||
pub const CST_135: u32 = CST_134+1;
|
||||
pub const CST_136: u32 = CST_135+1;
|
||||
pub const CST_137: u32 = CST_136+1;
|
||||
pub const CST_138: u32 = CST_137+1;
|
||||
pub const CST_139: u32 = CST_138+1;
|
||||
pub const CST_140: u32 = CST_139+1;
|
||||
pub const CST_141: u32 = CST_140+1;
|
||||
pub const CST_142: u32 = CST_141+1;
|
||||
pub const CST_143: u32 = CST_142+1;
|
||||
pub const CST_144: u32 = CST_143+1;
|
||||
pub const CST_145: u32 = CST_144+1;
|
||||
pub const CST_146: u32 = CST_145+1;
|
||||
pub const CST_147: u32 = CST_146+1;
|
||||
pub const CST_148: u32 = CST_147+1;
|
||||
pub const CST_149: u32 = CST_148+1;
|
||||
pub const CST_150: u32 = CST_149+1;
|
||||
pub const CST_151: u32 = CST_150+1;
|
||||
pub const CST_152: u32 = CST_151+1;
|
||||
pub const CST_153: u32 = CST_152+1;
|
||||
pub const CST_154: u32 = CST_153+1;
|
||||
pub const CST_155: u32 = CST_154+1;
|
||||
pub const CST_156: u32 = CST_155+1;
|
||||
pub const CST_157: u32 = CST_156+1;
|
||||
pub const CST_158: u32 = CST_157+1;
|
||||
pub const CST_159: u32 = CST_158+1;
|
||||
pub const CST_160: u32 = CST_159+1;
|
||||
pub const CST_161: u32 = CST_160+1;
|
||||
pub const CST_162: u32 = CST_161+1;
|
||||
pub const CST_163: u32 = CST_162+1;
|
||||
pub const CST_164: u32 = CST_163+1;
|
||||
pub const CST_165: u32 = CST_164+1;
|
||||
pub const CST_166: u32 = CST_165+1;
|
||||
pub const CST_167: u32 = CST_166+1;
|
||||
pub const CST_168: u32 = CST_167+1;
|
||||
pub const CST_169: u32 = CST_168+1;
|
||||
pub const CST_170: u32 = CST_169+1;
|
||||
pub const CST_171: u32 = CST_170+1;
|
||||
pub const CST_172: u32 = CST_171+1;
|
||||
pub const CST_173: u32 = CST_172+1;
|
||||
pub const CST_174: u32 = CST_173+1;
|
||||
pub const CST_175: u32 = CST_174+1;
|
||||
pub const CST_176: u32 = CST_175+1;
|
||||
pub const CST_177: u32 = CST_176+1;
|
||||
pub const CST_178: u32 = CST_177+1;
|
||||
pub const CST_179: u32 = CST_178+1;
|
||||
pub const CST_180: u32 = CST_179+1;
|
||||
pub const CST_181: u32 = CST_180+1;
|
||||
pub const CST_182: u32 = CST_181+1;
|
||||
pub const CST_183: u32 = CST_182+1;
|
||||
pub const CST_184: u32 = CST_183+1;
|
||||
pub const CST_185: u32 = CST_184+1;
|
||||
pub const CST_186: u32 = CST_185+1;
|
||||
pub const CST_187: u32 = CST_186+1;
|
||||
pub const CST_188: u32 = CST_187+1;
|
||||
pub const CST_189: u32 = CST_188+1;
|
||||
pub const CST_190: u32 = CST_189+1;
|
||||
pub const CST_191: u32 = CST_190+1;
|
||||
pub const CST_192: u32 = CST_191+1;
|
||||
pub const CST_193: u32 = CST_192+1;
|
||||
pub const CST_194: u32 = CST_193+1;
|
||||
pub const CST_195: u32 = CST_194+1;
|
||||
pub const CST_196: u32 = CST_195+1;
|
||||
pub const CST_197: u32 = CST_196+1;
|
||||
pub const CST_198: u32 = CST_197+1;
|
||||
pub const CST_199: u32 = CST_198+1;
|
||||
pub const CST_200: u32 = CST_199+1;
|
||||
pub const CST_201: u32 = CST_200+1;
|
||||
pub const CST_202: u32 = CST_201+1;
|
||||
pub const CST_203: u32 = CST_202+1;
|
||||
pub const CST_204: u32 = CST_203+1;
|
||||
pub const CST_205: u32 = CST_204+1;
|
||||
pub const CST_206: u32 = CST_205+1;
|
||||
pub const CST_207: u32 = CST_206+1;
|
||||
pub const CST_208: u32 = CST_207+1;
|
||||
pub const CST_209: u32 = CST_208+1;
|
||||
pub const CST_210: u32 = CST_209+1;
|
||||
pub const CST_211: u32 = CST_210+1;
|
||||
pub const CST_212: u32 = CST_211+1;
|
||||
pub const CST_213: u32 = CST_212+1;
|
||||
pub const CST_214: u32 = CST_213+1;
|
||||
pub const CST_215: u32 = CST_214+1;
|
||||
pub const CST_216: u32 = CST_215+1;
|
||||
pub const CST_217: u32 = CST_216+1;
|
||||
pub const CST_218: u32 = CST_217+1;
|
||||
pub const CST_219: u32 = CST_218+1;
|
||||
pub const CST_220: u32 = CST_219+1;
|
||||
pub const CST_221: u32 = CST_220+1;
|
||||
pub const CST_222: u32 = CST_221+1;
|
||||
pub const CST_223: u32 = CST_222+1;
|
||||
pub const CST_224: u32 = CST_223+1;
|
||||
pub const CST_225: u32 = CST_224+1;
|
||||
pub const CST_226: u32 = CST_225+1;
|
||||
pub const CST_227: u32 = CST_226+1;
|
||||
pub const CST_228: u32 = CST_227+1;
|
||||
pub const CST_229: u32 = CST_228+1;
|
||||
pub const CST_230: u32 = CST_229+1;
|
||||
pub const CST_231: u32 = CST_230+1;
|
||||
pub const CST_232: u32 = CST_231+1;
|
||||
pub const CST_233: u32 = CST_232+1;
|
||||
pub const CST_234: u32 = CST_233+1;
|
||||
pub const CST_235: u32 = CST_234+1;
|
||||
pub const CST_236: u32 = CST_235+1;
|
||||
pub const CST_237: u32 = CST_236+1;
|
||||
pub const CST_238: u32 = CST_237+1;
|
||||
pub const CST_239: u32 = CST_238+1;
|
||||
pub const CST_240: u32 = CST_239+1;
|
||||
pub const CST_241: u32 = CST_240+1;
|
||||
pub const CST_242: u32 = CST_241+1;
|
||||
pub const CST_243: u32 = CST_242+1;
|
||||
pub const CST_244: u32 = CST_243+1;
|
||||
pub const CST_245: u32 = CST_244+1;
|
||||
pub const CST_246: u32 = CST_245+1;
|
||||
pub const CST_247: u32 = CST_246+1;
|
||||
pub const CST_248: u32 = CST_247+1;
|
||||
pub const CST_249: u32 = CST_248+1;
|
||||
pub const CST_250: u32 = CST_249+1;
|
||||
pub const CST_251: u32 = CST_250+1;
|
||||
pub const CST_252: u32 = CST_251+1;
|
||||
pub const CST_253: u32 = CST_252+1;
|
||||
pub const CST_254: u32 = CST_253+1;
|
||||
pub const CST_255: u32 = CST_254+1;
|
||||
pub const CST_256: u32 = CST_255+1;
|
||||
pub const CST_257: u32 = CST_256+1;
|
||||
pub const CST_258: u32 = CST_257+1;
|
||||
pub const CST_259: u32 = CST_258+1;
|
||||
pub const CST_260: u32 = CST_259+1;
|
||||
pub const CST_261: u32 = CST_260+1;
|
||||
pub const CST_262: u32 = CST_261+1;
|
||||
pub const CST_263: u32 = CST_262+1;
|
||||
pub const CST_264: u32 = CST_263+1;
|
||||
pub const CST_265: u32 = CST_264+1;
|
||||
pub const CST_266: u32 = CST_265+1;
|
||||
pub const CST_267: u32 = CST_266+1;
|
||||
pub const CST_268: u32 = CST_267+1;
|
||||
pub const CST_269: u32 = CST_268+1;
|
||||
pub const CST_270: u32 = CST_269+1;
|
||||
pub const CST_271: u32 = CST_270+1;
|
||||
pub const CST_272: u32 = CST_271+1;
|
||||
pub const CST_273: u32 = CST_272+1;
|
||||
pub const CST_274: u32 = CST_273+1;
|
||||
pub const CST_275: u32 = CST_274+1;
|
||||
pub const CST_276: u32 = CST_275+1;
|
||||
pub const CST_277: u32 = CST_276+1;
|
||||
pub const CST_278: u32 = CST_277+1;
|
||||
pub const CST_279: u32 = CST_278+1;
|
||||
pub const CST_280: u32 = CST_279+1;
|
||||
pub const CST_281: u32 = CST_280+1;
|
||||
pub const CST_282: u32 = CST_281+1;
|
||||
pub const CST_283: u32 = CST_282+1;
|
||||
pub const CST_284: u32 = CST_283+1;
|
||||
pub const CST_285: u32 = CST_284+1;
|
||||
pub const CST_286: u32 = CST_285+1;
|
||||
pub const CST_287: u32 = CST_286+1;
|
||||
pub const CST_288: u32 = CST_287+1;
|
||||
pub const CST_289: u32 = CST_288+1;
|
||||
pub const CST_290: u32 = CST_289+1;
|
||||
pub const CST_291: u32 = CST_290+1;
|
||||
pub const CST_292: u32 = CST_291+1;
|
||||
pub const CST_293: u32 = CST_292+1;
|
||||
pub const CST_294: u32 = CST_293+1;
|
||||
pub const CST_295: u32 = CST_294+1;
|
||||
pub const CST_296: u32 = CST_295+1;
|
||||
pub const CST_297: u32 = CST_296+1;
|
||||
pub const CST_298: u32 = CST_297+1;
|
||||
pub const CST_299: u32 = CST_298+1;
|
||||
pub const CST_300: u32 = CST_299+1;
|
||||
pub const CST_301: u32 = CST_300+1;
|
||||
pub const CST_302: u32 = CST_301+1;
|
||||
pub const CST_303: u32 = CST_302+1;
|
||||
pub const CST_304: u32 = CST_303+1;
|
||||
pub const CST_305: u32 = CST_304+1;
|
||||
pub const CST_306: u32 = CST_305+1;
|
||||
pub const CST_307: u32 = CST_306+1;
|
||||
pub const CST_308: u32 = CST_307+1;
|
||||
pub const CST_309: u32 = CST_308+1;
|
||||
pub const CST_310: u32 = CST_309+1;
|
||||
pub const CST_311: u32 = CST_310+1;
|
||||
pub const CST_312: u32 = CST_311+1;
|
||||
pub const CST_313: u32 = CST_312+1;
|
||||
pub const CST_314: u32 = CST_313+1;
|
||||
pub const CST_315: u32 = CST_314+1;
|
||||
pub const CST_316: u32 = CST_315+1;
|
||||
pub const CST_317: u32 = CST_316+1;
|
||||
pub const CST_318: u32 = CST_317+1;
|
||||
pub const CST_319: u32 = CST_318+1;
|
||||
pub const CST_320: u32 = CST_319+1;
|
||||
pub const CST_321: u32 = CST_320+1;
|
||||
pub const CST_322: u32 = CST_321+1;
|
||||
pub const CST_323: u32 = CST_322+1;
|
||||
pub const CST_324: u32 = CST_323+1;
|
||||
pub const CST_325: u32 = CST_324+1;
|
||||
pub const CST_326: u32 = CST_325+1;
|
||||
pub const CST_327: u32 = CST_326+1;
|
||||
pub const CST_328: u32 = CST_327+1;
|
||||
pub const CST_329: u32 = CST_328+1;
|
||||
pub const CST_330: u32 = CST_329+1;
|
||||
pub const CST_331: u32 = CST_330+1;
|
||||
pub const CST_332: u32 = CST_331+1;
|
||||
pub const CST_333: u32 = CST_332+1;
|
||||
pub const CST_334: u32 = CST_333+1;
|
||||
pub const CST_335: u32 = CST_334+1;
|
||||
pub const CST_336: u32 = CST_335+1;
|
||||
pub const CST_337: u32 = CST_336+1;
|
||||
pub const CST_338: u32 = CST_337+1;
|
||||
pub const CST_339: u32 = CST_338+1;
|
||||
pub const CST_340: u32 = CST_339+1;
|
||||
pub const CST_341: u32 = CST_340+1;
|
||||
pub const CST_342: u32 = CST_341+1;
|
||||
pub const CST_343: u32 = CST_342+1;
|
||||
pub const CST_344: u32 = CST_343+1;
|
||||
pub const CST_345: u32 = CST_344+1;
|
||||
pub const CST_346: u32 = CST_345+1;
|
||||
pub const CST_347: u32 = CST_346+1;
|
||||
pub const CST_348: u32 = CST_347+1;
|
||||
pub const CST_349: u32 = CST_348+1;
|
||||
pub const CST_350: u32 = CST_349+1;
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
// 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(const_let)]
|
||||
|
||||
type Array = [u32; { let x = 2; 5 }];
|
||||
|
||||
pub fn main() {}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
// 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(const_let)]
|
||||
|
||||
enum Foo {
|
||||
Bar = { let x = 1; 3 }
|
||||
}
|
||||
|
||||
pub fn main() {}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
// 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.
|
||||
|
||||
// test that certain things are disallowed in constant functions
|
||||
|
||||
#![feature(const_fn, const_let)]
|
||||
|
||||
// no destructuring
|
||||
const fn i((
|
||||
a,
|
||||
b
|
||||
): (u32, u32)) -> u32 {
|
||||
a + b
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
// https://github.com/rust-lang/rust/issues/25574
|
||||
|
||||
const A: [u8; 4] = *b"fooo";
|
||||
|
||||
fn main() {
|
||||
match *b"xxxx" {
|
||||
A => {},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
// https://github.com/rust-lang/rust/issues/48279
|
||||
|
||||
#![feature(min_const_fn)]
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub struct NonZeroU32 {
|
||||
value: u32
|
||||
}
|
||||
|
||||
impl NonZeroU32 {
|
||||
const unsafe fn new_unchecked(value: u32) -> Self {
|
||||
NonZeroU32 { value }
|
||||
}
|
||||
}
|
||||
|
||||
//pub const FOO_ATOM: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(7) };
|
||||
pub const FOO_ATOM: NonZeroU32 = unsafe { NonZeroU32 { value: 7 } };
|
||||
|
||||
fn main() {
|
||||
match None {
|
||||
Some(FOO_ATOM) => {}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
// Copyright 2017 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(const_fn, const_let)]
|
||||
|
||||
const fn x() {
|
||||
let t = true;
|
||||
let x = || t;
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
// https://github.com/rust-lang/rust/issues/27918
|
||||
|
||||
fn main() {
|
||||
match b" " {
|
||||
b"1234" => {},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
// https://github.com/rust-lang/rust/issues/48821
|
||||
|
||||
#![feature(const_fn, const_let)]
|
||||
|
||||
const fn foo(i: usize) -> usize {
|
||||
let x = i;
|
||||
x
|
||||
}
|
||||
|
||||
static FOO: usize = foo(42);
|
||||
|
||||
const fn bar(mut i: usize) -> usize {
|
||||
i += 8;
|
||||
let x = &i;
|
||||
*x
|
||||
}
|
||||
|
||||
static BAR: usize = bar(42);
|
||||
|
||||
const fn boo(mut i: usize) -> usize {
|
||||
{
|
||||
let mut x = i;
|
||||
x += 10;
|
||||
i = x;
|
||||
}
|
||||
i
|
||||
}
|
||||
|
||||
static BOO: usize = boo(42);
|
||||
|
||||
fn main() {
|
||||
assert!(FOO == 42);
|
||||
assert!(BAR == 50);
|
||||
assert!(BOO == 52);
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
// https://github.com/rust-lang/rust/issues/46114
|
||||
|
||||
#![feature(min_const_fn)]
|
||||
|
||||
#[derive(Eq, PartialEq)]
|
||||
struct A { value: u32 }
|
||||
|
||||
const fn new(value: u32) -> A {
|
||||
A { value }
|
||||
}
|
||||
|
||||
const A_1: A = new(1);
|
||||
const A_2: A = new(2);
|
||||
|
||||
fn main() {
|
||||
let a_str = match new(42) {
|
||||
A_1 => "A 1",
|
||||
A_2 => "A 2",
|
||||
_ => "Unknown A",
|
||||
};
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
struct CustomAutoRooterVFTable {
|
||||
trace: unsafe extern "C" fn(this: *mut i32, trc: *mut u32),
|
||||
}
|
||||
|
||||
unsafe trait CustomAutoTraceable: Sized {
|
||||
const vftable: CustomAutoRooterVFTable = CustomAutoRooterVFTable {
|
||||
trace: Self::trace,
|
||||
};
|
||||
|
||||
unsafe extern "C" fn trace(this: *mut i32, trc: *mut u32) {
|
||||
let this = this as *const Self;
|
||||
let this = this.as_ref().unwrap();
|
||||
Self::do_trace(this, trc);
|
||||
}
|
||||
|
||||
fn do_trace(&self, trc: *mut u32);
|
||||
}
|
||||
|
||||
unsafe impl CustomAutoTraceable for () {
|
||||
fn do_trace(&self, _: *mut u32) {
|
||||
// nop
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _ = <()>::vftable;
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
// https://github.com/rust-lang/rust/issues/37448
|
||||
|
||||
fn main() {
|
||||
struct A;
|
||||
const FOO: &A = &(A as A);
|
||||
let _x = FOO;
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
// compile-flags: -O
|
||||
|
||||
fn foo(_: &'static [&'static str]) {}
|
||||
fn bar(_: &'static [&'static str; 3]) {}
|
||||
fn baz_i32(_: &'static i32) {}
|
||||
fn baz_u32(_: &'static u32) {}
|
||||
|
||||
fn main() {
|
||||
foo(&["a", "b", "c"]);
|
||||
bar(&["d", "e", "f"]);
|
||||
|
||||
// make sure that these do not cause trouble despite overflowing
|
||||
baz_u32(&(0-1));
|
||||
baz_i32(&-std::i32::MIN);
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
const FOO: &[u8] = b"foo";
|
||||
const BAR: &[u8] = &[1, 2, 3];
|
||||
|
||||
const BOO: &i32 = &42;
|
||||
|
||||
fn main() {
|
||||
match &[1u8, 2, 3] as &[u8] {
|
||||
FOO => panic!("a"),
|
||||
BAR => println!("b"),
|
||||
_ => panic!("c"),
|
||||
}
|
||||
|
||||
match b"foo" as &[u8] {
|
||||
FOO => println!("a"),
|
||||
BAR => panic!("b"),
|
||||
_ => panic!("c"),
|
||||
}
|
||||
|
||||
match &43 {
|
||||
&42 => panic!(),
|
||||
BOO => panic!(),
|
||||
_ => println!("d"),
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
// https://github.com/rust-lang/rust/issues/45044
|
||||
|
||||
const X: [u8; 1] = [0; 1];
|
||||
|
||||
fn main() {
|
||||
match &X {
|
||||
&X => println!("a"),
|
||||
_ => println!("b"),
|
||||
};
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
// https://github.com/rust-lang/rust/issues/43754
|
||||
|
||||
#![feature(min_const_fn)]
|
||||
const fn foo(x: usize) -> usize {
|
||||
return x;
|
||||
}
|
||||
fn main() {
|
||||
[0; foo(2)];
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
// https://github.com/rust-lang/rust/issues/49181
|
||||
|
||||
#[derive(Eq, PartialEq)]
|
||||
#[repr(i8)]
|
||||
pub enum A {
|
||||
B = -1,
|
||||
C = 1,
|
||||
}
|
||||
|
||||
pub const D: A = A::B;
|
||||
|
||||
fn main() {
|
||||
match A::C {
|
||||
D => {},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
// Copyright 2018 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(const_transmute)]
|
||||
|
||||
use std::mem;
|
||||
|
||||
#[repr(transparent)]
|
||||
struct Foo(u32);
|
||||
|
||||
const TRANSMUTED_U32: u32 = unsafe { mem::transmute(Foo(3)) };
|
||||
|
||||
fn main() {
|
||||
assert_eq!(TRANSMUTED_U32, 3);
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
// https://github.com/rust-lang/rust/issues/41898
|
||||
|
||||
use std::num::NonZeroU64;
|
||||
|
||||
fn main() {
|
||||
const FOO: NonZeroU64 = unsafe { NonZeroU64::new_unchecked(2) };
|
||||
if let FOO = FOO {}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
// Copyright 2017 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(generators, generator_trait)]
|
||||
|
||||
use std::ops::Generator;
|
||||
|
||||
fn msg() -> u32 {
|
||||
0
|
||||
}
|
||||
|
||||
pub fn foo() -> impl Generator<Yield=(), Return=u32> {
|
||||
|| {
|
||||
yield;
|
||||
return msg();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
// Copyright 2017 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(generators, generator_trait)]
|
||||
|
||||
use std::ops::Generator;
|
||||
|
||||
pub fn foo() -> impl Generator<Yield = (), Return = ()> {
|
||||
|| {
|
||||
if false {
|
||||
yield;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bar<T: 'static>(t: T) -> Box<Generator<Yield = T, Return = ()>> {
|
||||
Box::new(|| {
|
||||
yield t;
|
||||
})
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
// Copyright 2017 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(generators)]
|
||||
|
||||
fn main() {
|
||||
let _a = || {
|
||||
yield;
|
||||
let a = String::new();
|
||||
a.len()
|
||||
};
|
||||
}
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
// Copyright 2017 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(generators, generator_trait)]
|
||||
|
||||
use std::ops::Generator;
|
||||
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
|
||||
|
||||
static A: AtomicUsize = ATOMIC_USIZE_INIT;
|
||||
|
||||
struct B;
|
||||
|
||||
impl Drop for B {
|
||||
fn drop(&mut self) {
|
||||
A.fetch_add(1, Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn test() -> bool { true }
|
||||
fn test2() -> bool { false }
|
||||
|
||||
fn main() {
|
||||
t1();
|
||||
t2();
|
||||
}
|
||||
|
||||
fn t1() {
|
||||
let mut a = || {
|
||||
let b = B;
|
||||
if test() {
|
||||
drop(b);
|
||||
}
|
||||
yield;
|
||||
};
|
||||
|
||||
let n = A.load(Ordering::SeqCst);
|
||||
unsafe { a.resume() };
|
||||
assert_eq!(A.load(Ordering::SeqCst), n + 1);
|
||||
unsafe { a.resume() };
|
||||
assert_eq!(A.load(Ordering::SeqCst), n + 1);
|
||||
}
|
||||
|
||||
fn t2() {
|
||||
let mut a = || {
|
||||
let b = B;
|
||||
if test2() {
|
||||
drop(b);
|
||||
}
|
||||
yield;
|
||||
};
|
||||
|
||||
let n = A.load(Ordering::SeqCst);
|
||||
unsafe { a.resume() };
|
||||
assert_eq!(A.load(Ordering::SeqCst), n);
|
||||
unsafe { a.resume() };
|
||||
assert_eq!(A.load(Ordering::SeqCst), n + 1);
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
// Copyright 2017 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(generators, generator_trait)]
|
||||
|
||||
use std::ops::{GeneratorState, Generator};
|
||||
|
||||
fn finish<T>(mut amt: usize, mut t: T) -> T::Return
|
||||
where T: Generator<Yield = ()>
|
||||
{
|
||||
loop {
|
||||
match unsafe { t.resume() } {
|
||||
GeneratorState::Yielded(()) => amt = amt.checked_sub(1).unwrap(),
|
||||
GeneratorState::Complete(ret) => {
|
||||
assert_eq!(amt, 0);
|
||||
return ret
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn main() {
|
||||
finish(1, || yield);
|
||||
finish(8, || {
|
||||
for _ in 0..8 {
|
||||
yield;
|
||||
}
|
||||
});
|
||||
finish(1, || {
|
||||
if true {
|
||||
yield;
|
||||
} else {
|
||||
}
|
||||
});
|
||||
finish(1, || {
|
||||
if false {
|
||||
} else {
|
||||
yield;
|
||||
}
|
||||
});
|
||||
finish(2, || {
|
||||
if { yield; false } {
|
||||
yield;
|
||||
panic!()
|
||||
}
|
||||
yield
|
||||
});
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
// Copyright 2017 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(generators, generator_trait)]
|
||||
|
||||
use std::ops::Generator;
|
||||
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
|
||||
|
||||
static A: AtomicUsize = ATOMIC_USIZE_INIT;
|
||||
|
||||
struct B;
|
||||
|
||||
impl Drop for B {
|
||||
fn drop(&mut self) {
|
||||
A.fetch_add(1, Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
t1();
|
||||
t2();
|
||||
t3();
|
||||
}
|
||||
|
||||
fn t1() {
|
||||
let b = B;
|
||||
let mut foo = || {
|
||||
yield;
|
||||
drop(b);
|
||||
};
|
||||
|
||||
let n = A.load(Ordering::SeqCst);
|
||||
drop(unsafe { foo.resume() });
|
||||
assert_eq!(A.load(Ordering::SeqCst), n);
|
||||
drop(foo);
|
||||
assert_eq!(A.load(Ordering::SeqCst), n + 1);
|
||||
}
|
||||
|
||||
fn t2() {
|
||||
let b = B;
|
||||
let mut foo = || {
|
||||
yield b;
|
||||
};
|
||||
|
||||
let n = A.load(Ordering::SeqCst);
|
||||
drop(unsafe { foo.resume() });
|
||||
assert_eq!(A.load(Ordering::SeqCst), n + 1);
|
||||
drop(foo);
|
||||
assert_eq!(A.load(Ordering::SeqCst), n + 1);
|
||||
}
|
||||
|
||||
fn t3() {
|
||||
let b = B;
|
||||
let foo = || {
|
||||
yield;
|
||||
drop(b);
|
||||
};
|
||||
|
||||
let n = A.load(Ordering::SeqCst);
|
||||
assert_eq!(A.load(Ordering::SeqCst), n);
|
||||
drop(foo);
|
||||
assert_eq!(A.load(Ordering::SeqCst), n + 1);
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
// Copyright 2017 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(generators, generator_trait)]
|
||||
|
||||
use std::ops::{ Generator, GeneratorState };
|
||||
|
||||
fn foo(_: &str) -> String {
|
||||
String::new()
|
||||
}
|
||||
|
||||
fn bar(baz: String) -> impl Generator<Yield = String, Return = ()> {
|
||||
move || {
|
||||
yield foo(&baz);
|
||||
}
|
||||
}
|
||||
|
||||
fn foo2(_: &str) -> Result<String, ()> {
|
||||
Err(())
|
||||
}
|
||||
|
||||
fn bar2(baz: String) -> impl Generator<Yield = String, Return = ()> {
|
||||
move || {
|
||||
if let Ok(quux) = foo2(&baz) {
|
||||
yield quux;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
assert_eq!(bar(String::new()).resume(), GeneratorState::Yielded(String::new()));
|
||||
assert_eq!(bar2(String::new()).resume(), GeneratorState::Complete(()));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
// Copyright 2018 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(generators)]
|
||||
|
||||
use std::cell::RefCell;
|
||||
|
||||
struct A;
|
||||
|
||||
impl A {
|
||||
fn test(&self, a: ()) {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Test that the MIR local with type &A created for the auto-borrow adjustment
|
||||
// is caught by typeck
|
||||
move || {
|
||||
A.test(yield);
|
||||
};
|
||||
|
||||
// Test that the std::cell::Ref temporary returned from the `borrow` call
|
||||
// is caught by typeck
|
||||
let y = RefCell::new(true);
|
||||
static move || {
|
||||
yield *y.borrow();
|
||||
return "Done";
|
||||
};
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
// Copyright 2017 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(generators, generator_trait)]
|
||||
|
||||
use std::ops::{GeneratorState, Generator};
|
||||
|
||||
struct W<T>(T);
|
||||
|
||||
// This impl isn't safe in general, but the generator used in this test is movable
|
||||
// so it won't cause problems.
|
||||
impl<T: Generator<Return = ()>> Iterator for W<T> {
|
||||
type Item = T::Yield;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
match unsafe { self.0.resume() } {
|
||||
GeneratorState::Complete(..) => None,
|
||||
GeneratorState::Yielded(v) => Some(v),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn test() -> impl Generator<Return=(), Yield=u8> {
|
||||
|| {
|
||||
for i in 1..6 {
|
||||
yield i
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let end = 11;
|
||||
|
||||
let closure_test = |start| {
|
||||
move || {
|
||||
for i in start..end {
|
||||
yield i
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
assert!(W(test()).chain(W(closure_test(6))).eq(1..11));
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
// Copyright 2017 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(generators, generator_trait)]
|
||||
|
||||
use std::ops::Generator;
|
||||
|
||||
fn main() {
|
||||
let b = |_| 3;
|
||||
let mut a = || {
|
||||
b(yield);
|
||||
};
|
||||
unsafe { a.resume() };
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
// Copyright 2017 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(generators)]
|
||||
|
||||
enum Enum {
|
||||
A(String),
|
||||
B
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|| {
|
||||
loop {
|
||||
if let true = true {
|
||||
match Enum::A(String::new()) {
|
||||
Enum::A(_var) => {}
|
||||
Enum::B => {}
|
||||
}
|
||||
}
|
||||
yield;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
// Copyright 2017 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(generators)]
|
||||
#![feature(generator_trait)]
|
||||
|
||||
use std::ops::Generator;
|
||||
use std::ops::GeneratorState;
|
||||
|
||||
fn main() {
|
||||
let _generator = || {
|
||||
let mut sub_generator = || {
|
||||
yield 2;
|
||||
};
|
||||
|
||||
match unsafe { sub_generator.resume() } {
|
||||
GeneratorState::Yielded(x) => {
|
||||
yield x;
|
||||
}
|
||||
_ => panic!(),
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
// ignore-wasm32-bare compiled as panic=abort by default
|
||||
|
||||
#![feature(generators, generator_trait)]
|
||||
|
||||
use std::ops::Generator;
|
||||
use std::panic;
|
||||
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
|
||||
|
||||
static A: AtomicUsize = ATOMIC_USIZE_INIT;
|
||||
|
||||
struct B;
|
||||
|
||||
impl Drop for B {
|
||||
fn drop(&mut self) {
|
||||
A.fetch_add(1, Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
|
||||
fn bool_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let b = B;
|
||||
let mut foo = || {
|
||||
if bool_true() {
|
||||
panic!();
|
||||
}
|
||||
drop(b);
|
||||
yield;
|
||||
};
|
||||
|
||||
assert_eq!(A.load(Ordering::SeqCst), 0);
|
||||
let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
||||
unsafe { foo.resume() }
|
||||
}));
|
||||
assert!(res.is_err());
|
||||
assert_eq!(A.load(Ordering::SeqCst), 1);
|
||||
|
||||
let mut foo = || {
|
||||
if bool_true() {
|
||||
panic!();
|
||||
}
|
||||
drop(B);
|
||||
yield;
|
||||
};
|
||||
|
||||
assert_eq!(A.load(Ordering::SeqCst), 1);
|
||||
let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
||||
unsafe { foo.resume() }
|
||||
}));
|
||||
assert!(res.is_err());
|
||||
assert_eq!(A.load(Ordering::SeqCst), 1);
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
// ignore-wasm32-bare compiled with panic=abort by default
|
||||
|
||||
#![feature(generators, generator_trait)]
|
||||
|
||||
use std::ops::Generator;
|
||||
use std::panic;
|
||||
|
||||
fn main() {
|
||||
let mut foo = || {
|
||||
if true {
|
||||
panic!();
|
||||
}
|
||||
yield;
|
||||
};
|
||||
|
||||
let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
||||
unsafe { foo.resume() }
|
||||
}));
|
||||
assert!(res.is_err());
|
||||
|
||||
for _ in 0..10 {
|
||||
let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
||||
unsafe { foo.resume() }
|
||||
}));
|
||||
assert!(res.is_err());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
// Copyright 2017 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(generators)]
|
||||
|
||||
fn _run(bar: &mut i32) {
|
||||
|| {
|
||||
{
|
||||
let _baz = &*bar;
|
||||
yield;
|
||||
}
|
||||
|
||||
*bar = 2;
|
||||
};
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
// ignore-wasm32-bare compiled with panic=abort by default
|
||||
|
||||
#![feature(generators, generator_trait)]
|
||||
|
||||
use std::ops::{GeneratorState, Generator};
|
||||
use std::panic;
|
||||
|
||||
fn main() {
|
||||
let mut foo = || {
|
||||
if true {
|
||||
return
|
||||
}
|
||||
yield;
|
||||
};
|
||||
|
||||
match unsafe { foo.resume() } {
|
||||
GeneratorState::Complete(()) => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
|
||||
match panic::catch_unwind(move || unsafe { foo.resume() }) {
|
||||
Ok(_) => panic!("generator successfully resumed"),
|
||||
Err(_) => {}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,181 +0,0 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
// ignore-emscripten no threads support
|
||||
// compile-flags: --test
|
||||
|
||||
#![feature(generators, generator_trait)]
|
||||
|
||||
use std::ops::{GeneratorState, Generator};
|
||||
use std::thread;
|
||||
|
||||
#[test]
|
||||
fn simple() {
|
||||
let mut foo = || {
|
||||
if false {
|
||||
yield;
|
||||
}
|
||||
};
|
||||
|
||||
match unsafe { foo.resume() } {
|
||||
GeneratorState::Complete(()) => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn return_capture() {
|
||||
let a = String::from("foo");
|
||||
let mut foo = || {
|
||||
if false {
|
||||
yield;
|
||||
}
|
||||
a
|
||||
};
|
||||
|
||||
match unsafe { foo.resume() } {
|
||||
GeneratorState::Complete(ref s) if *s == "foo" => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simple_yield() {
|
||||
let mut foo = || {
|
||||
yield;
|
||||
};
|
||||
|
||||
match unsafe { foo.resume() } {
|
||||
GeneratorState::Yielded(()) => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
match unsafe { foo.resume() } {
|
||||
GeneratorState::Complete(()) => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn yield_capture() {
|
||||
let b = String::from("foo");
|
||||
let mut foo = || {
|
||||
yield b;
|
||||
};
|
||||
|
||||
match unsafe { foo.resume() } {
|
||||
GeneratorState::Yielded(ref s) if *s == "foo" => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
match unsafe { foo.resume() } {
|
||||
GeneratorState::Complete(()) => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simple_yield_value() {
|
||||
let mut foo = || {
|
||||
yield String::from("bar");
|
||||
return String::from("foo")
|
||||
};
|
||||
|
||||
match unsafe { foo.resume() } {
|
||||
GeneratorState::Yielded(ref s) if *s == "bar" => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
match unsafe { foo.resume() } {
|
||||
GeneratorState::Complete(ref s) if *s == "foo" => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn return_after_yield() {
|
||||
let a = String::from("foo");
|
||||
let mut foo = || {
|
||||
yield;
|
||||
return a
|
||||
};
|
||||
|
||||
match unsafe { foo.resume() } {
|
||||
GeneratorState::Yielded(()) => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
match unsafe { foo.resume() } {
|
||||
GeneratorState::Complete(ref s) if *s == "foo" => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_and_sync() {
|
||||
assert_send_sync(|| {
|
||||
yield
|
||||
});
|
||||
assert_send_sync(|| {
|
||||
yield String::from("foo");
|
||||
});
|
||||
assert_send_sync(|| {
|
||||
yield;
|
||||
return String::from("foo");
|
||||
});
|
||||
let a = 3;
|
||||
assert_send_sync(|| {
|
||||
yield a;
|
||||
return
|
||||
});
|
||||
let a = 3;
|
||||
assert_send_sync(move || {
|
||||
yield a;
|
||||
return
|
||||
});
|
||||
let a = String::from("a");
|
||||
assert_send_sync(|| {
|
||||
yield ;
|
||||
drop(a);
|
||||
return
|
||||
});
|
||||
let a = String::from("a");
|
||||
assert_send_sync(move || {
|
||||
yield ;
|
||||
drop(a);
|
||||
return
|
||||
});
|
||||
|
||||
fn assert_send_sync<T: Send + Sync>(_: T) {}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_over_threads() {
|
||||
let mut foo = || { yield };
|
||||
thread::spawn(move || {
|
||||
match unsafe { foo.resume() } {
|
||||
GeneratorState::Yielded(()) => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
match unsafe { foo.resume() } {
|
||||
GeneratorState::Complete(()) => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
}).join().unwrap();
|
||||
|
||||
let a = String::from("a");
|
||||
let mut foo = || { yield a };
|
||||
thread::spawn(move || {
|
||||
match unsafe { foo.resume() } {
|
||||
GeneratorState::Yielded(ref s) if *s == "a" => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
match unsafe { foo.resume() } {
|
||||
GeneratorState::Complete(()) => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
}).join().unwrap();
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
// Copyright 2017 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(generators, generator_trait)]
|
||||
|
||||
use std::ops::{Generator, GeneratorState};
|
||||
|
||||
fn main() {
|
||||
let mut generator = static || {
|
||||
let a = true;
|
||||
let b = &a;
|
||||
yield;
|
||||
assert_eq!(b as *const _, &a as *const _);
|
||||
};
|
||||
unsafe {
|
||||
assert_eq!(generator.resume(), GeneratorState::Yielded(()));
|
||||
assert_eq!(generator.resume(), GeneratorState::Complete(()));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
// Copyright 2018 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(generators)]
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
static move || {
|
||||
// Tests that the generator transformation finds out that `a` is not live
|
||||
// during the yield expression. Type checking will also compute liveness
|
||||
// and it should also find out that `a` is not live.
|
||||
// The compiler will panic if the generator transformation finds that
|
||||
// `a` is live and type checking finds it dead.
|
||||
let a = {
|
||||
yield ();
|
||||
4i32
|
||||
};
|
||||
&a;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
// aux-build:xcrate-reachable.rs
|
||||
|
||||
#![feature(generator_trait)]
|
||||
|
||||
extern crate xcrate_reachable as foo;
|
||||
|
||||
use std::ops::Generator;
|
||||
|
||||
fn main() {
|
||||
unsafe { foo::foo().resume(); }
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
// aux-build:xcrate.rs
|
||||
|
||||
#![feature(generators, generator_trait)]
|
||||
|
||||
extern crate xcrate;
|
||||
|
||||
use std::ops::{GeneratorState, Generator};
|
||||
|
||||
fn main() {
|
||||
let mut foo = xcrate::foo();
|
||||
|
||||
match unsafe { foo.resume() } {
|
||||
GeneratorState::Complete(()) => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
|
||||
let mut foo = xcrate::bar(3);
|
||||
|
||||
match unsafe { foo.resume() } {
|
||||
GeneratorState::Yielded(3) => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
match unsafe { foo.resume() } {
|
||||
GeneratorState::Complete(()) => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
// Test that a borrow that occurs after a yield in the same
|
||||
// argument list is not treated as live across the yield by
|
||||
// type-checking.
|
||||
|
||||
#![feature(generators)]
|
||||
|
||||
fn foo(_a: (), _b: &bool) {}
|
||||
|
||||
fn bar() {
|
||||
|| {
|
||||
let b = true;
|
||||
foo(yield, &b);
|
||||
};
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
// Test that box-statements with yields in them work.
|
||||
|
||||
#![feature(generators, box_syntax)]
|
||||
|
||||
fn main() {
|
||||
let x = 0i32;
|
||||
|| {
|
||||
let y = 2u32;
|
||||
{
|
||||
let _t = box (&x, yield 0, &y);
|
||||
}
|
||||
match box (&x, yield 0, &y) {
|
||||
_t => {}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
// Copyright 2018 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(generators)]
|
||||
|
||||
fn main() {
|
||||
static || {
|
||||
loop {
|
||||
// Test that `opt` is not live across the yield, even when borrowed in a loop
|
||||
// See https://github.com/rust-lang/rust/issues/52792
|
||||
let opt = {
|
||||
yield;
|
||||
true
|
||||
};
|
||||
&opt;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
// revisions:lexical nll
|
||||
//[nll]compile-flags: -Z disable-nll-user-type-assert
|
||||
#![cfg_attr(nll, feature(nll))]
|
||||
|
||||
#![feature(generators)]
|
||||
|
||||
fn bar<'a>() {
|
||||
let a: &'static str = "hi";
|
||||
let b: &'a str = a;
|
||||
|
||||
|| {
|
||||
yield a;
|
||||
yield b;
|
||||
};
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
// Copyright 2016 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.
|
||||
|
||||
// Fast path, main can see the concrete type returned.
|
||||
fn before() -> impl FnMut(i32) {
|
||||
let mut p = Box::new(0);
|
||||
move |x| *p = x
|
||||
}
|
||||
|
||||
fn send<T: Send>(_: T) {}
|
||||
|
||||
fn main() {
|
||||
send(before());
|
||||
send(after());
|
||||
}
|
||||
|
||||
// Deferred path, main has to wait until typeck finishes,
|
||||
// to check if the return type of after is Send.
|
||||
fn after() -> impl FnMut(i32) {
|
||||
let mut p = Box::new(0);
|
||||
move |x| *p = x
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
// Copyright 2016 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.
|
||||
|
||||
// NOTE commented out due to issue #45994
|
||||
//pub fn fourway_add(a: i32) -> impl Fn(i32) -> impl Fn(i32) -> impl Fn(i32) -> i32 {
|
||||
// move |b| move |c| move |d| a + b + c + d
|
||||
//}
|
||||
|
||||
fn some_internal_fn() -> u32 {
|
||||
1
|
||||
}
|
||||
|
||||
fn other_internal_fn() -> u32 {
|
||||
1
|
||||
}
|
||||
|
||||
// See #40839
|
||||
pub fn return_closure_accessing_internal_fn() -> impl Fn() -> u32 {
|
||||
|| {
|
||||
some_internal_fn() + 1
|
||||
}
|
||||
}
|
||||
|
||||
pub fn return_internal_fn() -> impl Fn() -> u32 {
|
||||
other_internal_fn
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
// Copyright 2018 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 trait FakeGenerator {
|
||||
type Yield;
|
||||
type Return;
|
||||
}
|
||||
|
||||
pub trait FakeFuture {
|
||||
type Output;
|
||||
}
|
||||
|
||||
pub fn future_from_generator<
|
||||
T: FakeGenerator<Yield = ()>
|
||||
>(x: T) -> impl FakeFuture<Output = T::Return> {
|
||||
GenFuture(x)
|
||||
}
|
||||
|
||||
struct GenFuture<T: FakeGenerator<Yield = ()>>(T);
|
||||
|
||||
impl<T: FakeGenerator<Yield = ()>> FakeFuture for GenFuture<T> {
|
||||
type Output = T::Return;
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
// Copyright 2016 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(specialization)]
|
||||
|
||||
trait Foo: std::fmt::Debug + Eq {}
|
||||
|
||||
impl<T: std::fmt::Debug + Eq> Foo for T {}
|
||||
|
||||
fn hide<T: Foo>(x: T) -> impl Foo {
|
||||
x
|
||||
}
|
||||
|
||||
trait Leak<T>: Sized {
|
||||
fn leak(self) -> T;
|
||||
}
|
||||
impl<T, U> Leak<T> for U {
|
||||
default fn leak(self) -> T { panic!("type mismatch") }
|
||||
}
|
||||
impl<T> Leak<T> for T {
|
||||
fn leak(self) -> T { self }
|
||||
}
|
||||
|
||||
trait CheckIfSend: Sized {
|
||||
type T: Default;
|
||||
fn check(self) -> Self::T { Default::default() }
|
||||
}
|
||||
impl<T> CheckIfSend for T {
|
||||
default type T = ();
|
||||
}
|
||||
impl<T: Send> CheckIfSend for T {
|
||||
type T = bool;
|
||||
}
|
||||
|
||||
fn lucky_seven() -> impl Fn(usize) -> u8 {
|
||||
let a = [1, 2, 3, 4, 5, 6, 7];
|
||||
move |i| a[i]
|
||||
}
|
||||
|
||||
fn main() {
|
||||
assert_eq!(hide(42), hide(42));
|
||||
|
||||
assert_eq!(std::mem::size_of_val(&hide([0_u8; 5])), 5);
|
||||
assert_eq!(std::mem::size_of_val(&lucky_seven()), 7);
|
||||
|
||||
assert_eq!(Leak::<i32>::leak(hide(5_i32)), 5_i32);
|
||||
|
||||
assert_eq!(CheckIfSend::check(hide(0_i32)), false);
|
||||
}
|
||||
|
|
@ -1,892 +0,0 @@
|
|||
// Copyright 2016-2017 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.
|
||||
|
||||
// revisions: normal nll
|
||||
//[nll] compile-flags:-Zborrowck=mir
|
||||
|
||||
#![feature(fn_traits,
|
||||
step_trait,
|
||||
unboxed_closures,
|
||||
)]
|
||||
|
||||
//! Derived from: <https://raw.githubusercontent.com/quickfur/dcal/master/dcal.d>.
|
||||
//!
|
||||
//! Originally converted to Rust by [Daniel Keep](https://github.com/DanielKeep).
|
||||
|
||||
use std::fmt::Write;
|
||||
use std::mem;
|
||||
|
||||
/// Date representation.
|
||||
#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||
struct NaiveDate(i32, u32, u32);
|
||||
|
||||
impl NaiveDate {
|
||||
pub fn from_ymd(y: i32, m: u32, d: u32) -> NaiveDate {
|
||||
assert!(1 <= m && m <= 12, "m = {:?}", m);
|
||||
assert!(1 <= d && d <= NaiveDate(y, m, 1).days_in_month(), "d = {:?}", d);
|
||||
NaiveDate(y, m, d)
|
||||
}
|
||||
|
||||
pub fn year(&self) -> i32 {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn month(&self) -> u32 {
|
||||
self.1
|
||||
}
|
||||
|
||||
pub fn day(&self) -> u32 {
|
||||
self.2
|
||||
}
|
||||
|
||||
pub fn succ(&self) -> NaiveDate {
|
||||
let (mut y, mut m, mut d, n) = (
|
||||
self.year(), self.month(), self.day()+1, self.days_in_month());
|
||||
if d > n {
|
||||
d = 1;
|
||||
m += 1;
|
||||
}
|
||||
if m > 12 {
|
||||
m = 1;
|
||||
y += 1;
|
||||
}
|
||||
NaiveDate::from_ymd(y, m, d)
|
||||
}
|
||||
|
||||
pub fn weekday(&self) -> Weekday {
|
||||
use Weekday::*;
|
||||
|
||||
// 0 = Sunday
|
||||
let year = self.year();
|
||||
let dow_jan_1 = (year*365 + ((year-1) / 4) - ((year-1) / 100) + ((year-1) / 400)) % 7;
|
||||
let dow = (dow_jan_1 + (self.day_of_year() as i32 - 1)) % 7;
|
||||
[Sun, Mon, Tue, Wed, Thu, Fri, Sat][dow as usize]
|
||||
}
|
||||
|
||||
pub fn isoweekdate(&self) -> (i32, u32, Weekday) {
|
||||
let first_dow_mon_0 = self.year_first_day_of_week().num_days_from_monday();
|
||||
|
||||
// Work out this date's DOtY and week number, not including year adjustment.
|
||||
let doy_0 = self.day_of_year() - 1;
|
||||
let mut week_mon_0: i32 = ((first_dow_mon_0 + doy_0) / 7) as i32;
|
||||
|
||||
if self.first_week_in_prev_year() {
|
||||
week_mon_0 -= 1;
|
||||
}
|
||||
|
||||
let weeks_in_year = self.last_week_number();
|
||||
|
||||
// Work out the final result.
|
||||
// If the week is -1 or >= weeks_in_year, we will need to adjust the year.
|
||||
let year = self.year();
|
||||
let wd = self.weekday();
|
||||
|
||||
if week_mon_0 < 0 {
|
||||
(year - 1, NaiveDate::from_ymd(year - 1, 1, 1).last_week_number(), wd)
|
||||
} else if week_mon_0 >= weeks_in_year as i32 {
|
||||
(year + 1, (week_mon_0 + 1 - weeks_in_year as i32) as u32, wd)
|
||||
} else {
|
||||
(year, (week_mon_0 + 1) as u32, wd)
|
||||
}
|
||||
}
|
||||
|
||||
fn first_week_in_prev_year(&self) -> bool {
|
||||
let first_dow_mon_0 = self.year_first_day_of_week().num_days_from_monday();
|
||||
|
||||
// Any day in the year *before* the first Monday of that year
|
||||
// is considered to be in the last week of the previous year,
|
||||
// assuming the first week has *less* than four days in it.
|
||||
// Adjust the week appropriately.
|
||||
((7 - first_dow_mon_0) % 7) < 4
|
||||
}
|
||||
|
||||
fn year_first_day_of_week(&self) -> Weekday {
|
||||
NaiveDate::from_ymd(self.year(), 1, 1).weekday()
|
||||
}
|
||||
|
||||
fn weeks_in_year(&self) -> u32 {
|
||||
let days_in_last_week = self.year_first_day_of_week().num_days_from_monday() + 1;
|
||||
if days_in_last_week >= 4 { 53 } else { 52 }
|
||||
}
|
||||
|
||||
fn last_week_number(&self) -> u32 {
|
||||
let wiy = self.weeks_in_year();
|
||||
if self.first_week_in_prev_year() { wiy - 1 } else { wiy }
|
||||
}
|
||||
|
||||
fn day_of_year(&self) -> u32 {
|
||||
(1..self.1).map(|m| NaiveDate::from_ymd(self.year(), m, 1).days_in_month())
|
||||
.fold(0, |a,b| a+b) + self.day()
|
||||
}
|
||||
|
||||
fn is_leap_year(&self) -> bool {
|
||||
let year = self.year();
|
||||
if year % 4 != 0 {
|
||||
return false
|
||||
} else if year % 100 != 0 {
|
||||
return true
|
||||
} else if year % 400 != 0 {
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
fn days_in_month(&self) -> u32 {
|
||||
match self.month() {
|
||||
/* Jan */ 1 => 31,
|
||||
/* Feb */ 2 => if self.is_leap_year() { 29 } else { 28 },
|
||||
/* Mar */ 3 => 31,
|
||||
/* Apr */ 4 => 30,
|
||||
/* May */ 5 => 31,
|
||||
/* Jun */ 6 => 30,
|
||||
/* Jul */ 7 => 31,
|
||||
/* Aug */ 8 => 31,
|
||||
/* Sep */ 9 => 30,
|
||||
/* Oct */ 10 => 31,
|
||||
/* Nov */ 11 => 30,
|
||||
/* Dec */ 12 => 31,
|
||||
_ => unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> std::ops::Add<&'b NaiveDate> for &'a NaiveDate {
|
||||
type Output = NaiveDate;
|
||||
|
||||
fn add(self, other: &'b NaiveDate) -> NaiveDate {
|
||||
assert_eq!(*other, NaiveDate(0, 0, 1));
|
||||
self.succ()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::iter::Step for NaiveDate {
|
||||
fn steps_between(_: &Self, _: &Self) -> Option<usize> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn replace_one(&mut self) -> Self {
|
||||
mem::replace(self, NaiveDate(0, 0, 1))
|
||||
}
|
||||
|
||||
fn replace_zero(&mut self) -> Self {
|
||||
mem::replace(self, NaiveDate(0, 0, 0))
|
||||
}
|
||||
|
||||
fn add_one(&self) -> Self {
|
||||
self.succ()
|
||||
}
|
||||
|
||||
fn sub_one(&self) -> Self {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn add_usize(&self, _: usize) -> Option<Self> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||
pub enum Weekday {
|
||||
Mon,
|
||||
Tue,
|
||||
Wed,
|
||||
Thu,
|
||||
Fri,
|
||||
Sat,
|
||||
Sun,
|
||||
}
|
||||
|
||||
impl Weekday {
|
||||
pub fn num_days_from_monday(&self) -> u32 {
|
||||
use Weekday::*;
|
||||
match *self {
|
||||
Mon => 0,
|
||||
Tue => 1,
|
||||
Wed => 2,
|
||||
Thu => 3,
|
||||
Fri => 4,
|
||||
Sat => 5,
|
||||
Sun => 6,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn num_days_from_sunday(&self) -> u32 {
|
||||
use Weekday::*;
|
||||
match *self {
|
||||
Sun => 0,
|
||||
Mon => 1,
|
||||
Tue => 2,
|
||||
Wed => 3,
|
||||
Thu => 4,
|
||||
Fri => 5,
|
||||
Sat => 6,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// GroupBy implementation.
|
||||
struct GroupBy<It: Iterator, F> {
|
||||
it: std::iter::Peekable<It>,
|
||||
f: F,
|
||||
}
|
||||
|
||||
impl<It, F> Clone for GroupBy<It, F>
|
||||
where
|
||||
It: Iterator + Clone,
|
||||
It::Item: Clone,
|
||||
F: Clone,
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
GroupBy {
|
||||
it: self.it.clone(),
|
||||
f: self.f.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, G, It: 'a, F: 'a> Iterator for GroupBy<It, F>
|
||||
where It: Iterator + Clone,
|
||||
It::Item: Clone,
|
||||
F: Clone + FnMut(&It::Item) -> G,
|
||||
G: Eq + Clone
|
||||
{
|
||||
type Item = (G, InGroup<std::iter::Peekable<It>, F, G>);
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.it.peek().map(&mut self.f).map(|key| {
|
||||
let start = self.it.clone();
|
||||
while let Some(k) = self.it.peek().map(&mut self.f) {
|
||||
if key != k {
|
||||
break;
|
||||
}
|
||||
self.it.next();
|
||||
}
|
||||
|
||||
(key.clone(), InGroup {
|
||||
it: start,
|
||||
f: self.f.clone(),
|
||||
g: key
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct InGroup<It, F, G> {
|
||||
it: It,
|
||||
f: F,
|
||||
g: G
|
||||
}
|
||||
|
||||
impl<It: Iterator, F: FnMut(&It::Item) -> G, G: Eq> Iterator for InGroup<It, F, G> {
|
||||
type Item = It::Item;
|
||||
|
||||
fn next(&mut self) -> Option<It::Item> {
|
||||
self.it.next().and_then(|x| {
|
||||
if (self.f)(&x) == self.g { Some(x) } else { None }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
trait IteratorExt: Iterator + Sized {
|
||||
fn group_by<G, F>(self, f: F) -> GroupBy<Self, F>
|
||||
where F: Clone + FnMut(&Self::Item) -> G,
|
||||
G: Eq
|
||||
{
|
||||
GroupBy { it: self.peekable(), f }
|
||||
}
|
||||
|
||||
fn join(mut self, sep: &str) -> String
|
||||
where Self::Item: std::fmt::Display {
|
||||
let mut s = String::new();
|
||||
if let Some(e) = self.next() {
|
||||
write!(s, "{}", e);
|
||||
for e in self {
|
||||
s.push_str(sep);
|
||||
write!(s, "{}", e);
|
||||
}
|
||||
}
|
||||
s
|
||||
}
|
||||
|
||||
// HACK(eddyb) Only needed because `impl Trait` can't be
|
||||
// used with trait methods: `.foo()` becomes `.__(foo)`.
|
||||
fn __<F, R>(self, f: F) -> R
|
||||
where F: FnOnce(Self) -> R {
|
||||
f(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<It> IteratorExt for It where It: Iterator {}
|
||||
|
||||
///
|
||||
/// Generates an iterator that yields exactly n spaces.
|
||||
///
|
||||
fn spaces(n: usize) -> std::iter::Take<std::iter::Repeat<char>> {
|
||||
std::iter::repeat(' ').take(n)
|
||||
}
|
||||
|
||||
fn test_spaces() {
|
||||
assert_eq!(spaces(0).collect::<String>(), "");
|
||||
assert_eq!(spaces(10).collect::<String>(), " ")
|
||||
}
|
||||
|
||||
///
|
||||
/// Returns an iterator of dates in a given year.
|
||||
///
|
||||
fn dates_in_year(year: i32) -> impl Iterator<Item=NaiveDate>+Clone {
|
||||
InGroup {
|
||||
it: NaiveDate::from_ymd(year, 1, 1)..,
|
||||
f: |d: &NaiveDate| d.year(),
|
||||
g: year
|
||||
}
|
||||
}
|
||||
|
||||
fn test_dates_in_year() {
|
||||
{
|
||||
let mut dates = dates_in_year(2013);
|
||||
assert_eq!(dates.next(), Some(NaiveDate::from_ymd(2013, 1, 1)));
|
||||
|
||||
// Check increment
|
||||
assert_eq!(dates.next(), Some(NaiveDate::from_ymd(2013, 1, 2)));
|
||||
|
||||
// Check monthly rollover
|
||||
for _ in 3..31 {
|
||||
assert!(dates.next() != None);
|
||||
}
|
||||
|
||||
assert_eq!(dates.next(), Some(NaiveDate::from_ymd(2013, 1, 31)));
|
||||
assert_eq!(dates.next(), Some(NaiveDate::from_ymd(2013, 2, 1)));
|
||||
}
|
||||
|
||||
{
|
||||
// Check length of year
|
||||
let mut dates = dates_in_year(2013);
|
||||
for _ in 0..365 {
|
||||
assert!(dates.next() != None);
|
||||
}
|
||||
assert_eq!(dates.next(), None);
|
||||
}
|
||||
|
||||
{
|
||||
// Check length of leap year
|
||||
let mut dates = dates_in_year(1984);
|
||||
for _ in 0..366 {
|
||||
assert!(dates.next() != None);
|
||||
}
|
||||
assert_eq!(dates.next(), None);
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Convenience trait for verifying that a given type iterates over
|
||||
/// `NaiveDate`s.
|
||||
///
|
||||
trait DateIterator: Iterator<Item=NaiveDate> + Clone {}
|
||||
impl<It> DateIterator for It where It: Iterator<Item=NaiveDate> + Clone {}
|
||||
|
||||
fn test_group_by() {
|
||||
let input = [
|
||||
[1, 1],
|
||||
[1, 1],
|
||||
[1, 2],
|
||||
[2, 2],
|
||||
[2, 3],
|
||||
[2, 3],
|
||||
[3, 3]
|
||||
];
|
||||
|
||||
let by_x = input.iter().cloned().group_by(|a| a[0]);
|
||||
let expected_1: &[&[[i32; 2]]] = &[
|
||||
&[[1, 1], [1, 1], [1, 2]],
|
||||
&[[2, 2], [2, 3], [2, 3]],
|
||||
&[[3, 3]]
|
||||
];
|
||||
for ((_, a), b) in by_x.zip(expected_1.iter().cloned()) {
|
||||
assert_eq!(&a.collect::<Vec<_>>()[..], b);
|
||||
}
|
||||
|
||||
let by_y = input.iter().cloned().group_by(|a| a[1]);
|
||||
let expected_2: &[&[[i32; 2]]] = &[
|
||||
&[[1, 1], [1, 1]],
|
||||
&[[1, 2], [2, 2]],
|
||||
&[[2, 3], [2, 3], [3, 3]]
|
||||
];
|
||||
for ((_, a), b) in by_y.zip(expected_2.iter().cloned()) {
|
||||
assert_eq!(&a.collect::<Vec<_>>()[..], b);
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Groups an iterator of dates by month.
|
||||
///
|
||||
fn by_month(it: impl Iterator<Item=NaiveDate> + Clone)
|
||||
-> impl Iterator<Item=(u32, impl Iterator<Item=NaiveDate> + Clone)> + Clone
|
||||
{
|
||||
it.group_by(|d| d.month())
|
||||
}
|
||||
|
||||
fn test_by_month() {
|
||||
let mut months = dates_in_year(2013).__(by_month);
|
||||
for (month, (_, mut date)) in (1..13).zip(&mut months) {
|
||||
assert_eq!(date.nth(0).unwrap(), NaiveDate::from_ymd(2013, month, 1));
|
||||
}
|
||||
assert!(months.next().is_none());
|
||||
}
|
||||
|
||||
///
|
||||
/// Groups an iterator of dates by week.
|
||||
///
|
||||
fn by_week(it: impl DateIterator)
|
||||
-> impl Iterator<Item=(u32, impl DateIterator)> + Clone
|
||||
{
|
||||
// We go forward one day because `isoweekdate` considers the week to start on a Monday.
|
||||
it.group_by(|d| d.succ().isoweekdate().1)
|
||||
}
|
||||
|
||||
fn test_isoweekdate() {
|
||||
fn weeks_uniq(year: i32) -> Vec<((i32, u32), u32)> {
|
||||
let mut weeks = dates_in_year(year).map(|d| d.isoweekdate())
|
||||
.map(|(y,w,_)| (y,w));
|
||||
let mut result = vec![];
|
||||
let mut accum = (weeks.next().unwrap(), 1);
|
||||
for yw in weeks {
|
||||
if accum.0 == yw {
|
||||
accum.1 += 1;
|
||||
} else {
|
||||
result.push(accum);
|
||||
accum = (yw, 1);
|
||||
}
|
||||
}
|
||||
result.push(accum);
|
||||
result
|
||||
}
|
||||
|
||||
let wu_1984 = weeks_uniq(1984);
|
||||
assert_eq!(&wu_1984[..2], &[((1983, 52), 1), ((1984, 1), 7)]);
|
||||
assert_eq!(&wu_1984[wu_1984.len()-2..], &[((1984, 52), 7), ((1985, 1), 1)]);
|
||||
|
||||
let wu_2013 = weeks_uniq(2013);
|
||||
assert_eq!(&wu_2013[..2], &[((2013, 1), 6), ((2013, 2), 7)]);
|
||||
assert_eq!(&wu_2013[wu_2013.len()-2..], &[((2013, 52), 7), ((2014, 1), 2)]);
|
||||
|
||||
let wu_2015 = weeks_uniq(2015);
|
||||
assert_eq!(&wu_2015[..2], &[((2015, 1), 4), ((2015, 2), 7)]);
|
||||
assert_eq!(&wu_2015[wu_2015.len()-2..], &[((2015, 52), 7), ((2015, 53), 4)]);
|
||||
}
|
||||
|
||||
fn test_by_week() {
|
||||
let mut weeks = dates_in_year(2013).__(by_week);
|
||||
assert_eq!(
|
||||
&*weeks.next().unwrap().1.collect::<Vec<_>>(),
|
||||
&[
|
||||
NaiveDate::from_ymd(2013, 1, 1),
|
||||
NaiveDate::from_ymd(2013, 1, 2),
|
||||
NaiveDate::from_ymd(2013, 1, 3),
|
||||
NaiveDate::from_ymd(2013, 1, 4),
|
||||
NaiveDate::from_ymd(2013, 1, 5),
|
||||
]
|
||||
);
|
||||
assert_eq!(
|
||||
&*weeks.next().unwrap().1.collect::<Vec<_>>(),
|
||||
&[
|
||||
NaiveDate::from_ymd(2013, 1, 6),
|
||||
NaiveDate::from_ymd(2013, 1, 7),
|
||||
NaiveDate::from_ymd(2013, 1, 8),
|
||||
NaiveDate::from_ymd(2013, 1, 9),
|
||||
NaiveDate::from_ymd(2013, 1, 10),
|
||||
NaiveDate::from_ymd(2013, 1, 11),
|
||||
NaiveDate::from_ymd(2013, 1, 12),
|
||||
]
|
||||
);
|
||||
assert_eq!(weeks.next().unwrap().1.nth(0).unwrap(), NaiveDate::from_ymd(2013, 1, 13));
|
||||
}
|
||||
|
||||
/// The number of columns per day in the formatted output.
|
||||
const COLS_PER_DAY: u32 = 3;
|
||||
|
||||
/// The number of columns per week in the formatted output.
|
||||
const COLS_PER_WEEK: u32 = 7 * COLS_PER_DAY;
|
||||
|
||||
///
|
||||
/// Formats an iterator of weeks into an iterator of strings.
|
||||
///
|
||||
fn format_weeks(it: impl Iterator<Item = impl DateIterator>) -> impl Iterator<Item=String> {
|
||||
it.map(|week| {
|
||||
let mut buf = String::with_capacity((COLS_PER_DAY * COLS_PER_WEEK + 2) as usize);
|
||||
|
||||
// Format each day into its own cell and append to target string.
|
||||
let mut last_day = 0;
|
||||
let mut first = true;
|
||||
for d in week {
|
||||
last_day = d.weekday().num_days_from_sunday();
|
||||
|
||||
// Insert enough filler to align the first day with its respective day-of-week.
|
||||
if first {
|
||||
buf.extend(spaces((COLS_PER_DAY * last_day) as usize));
|
||||
first = false;
|
||||
}
|
||||
|
||||
write!(buf, " {:>2}", d.day());
|
||||
}
|
||||
|
||||
// Insert more filler at the end to fill up the remainder of the week,
|
||||
// if its a short week (e.g. at the end of the month).
|
||||
buf.extend(spaces((COLS_PER_DAY * (6 - last_day)) as usize));
|
||||
buf
|
||||
})
|
||||
}
|
||||
|
||||
fn test_format_weeks() {
|
||||
let jan_2013 = dates_in_year(2013)
|
||||
.__(by_month).next() // pick January 2013 for testing purposes
|
||||
// NOTE: This `map` is because `next` returns an `Option<_>`.
|
||||
.map(|(_, month)|
|
||||
month.__(by_week)
|
||||
.map(|(_, weeks)| weeks)
|
||||
.__(format_weeks)
|
||||
.join("\n"));
|
||||
|
||||
assert_eq!(
|
||||
jan_2013.as_ref().map(|s| &**s),
|
||||
Some(" 1 2 3 4 5\n\
|
||||
\x20 6 7 8 9 10 11 12\n\
|
||||
\x2013 14 15 16 17 18 19\n\
|
||||
\x2020 21 22 23 24 25 26\n\
|
||||
\x2027 28 29 30 31 ")
|
||||
);
|
||||
}
|
||||
|
||||
///
|
||||
/// Formats the name of a month, centered on COLS_PER_WEEK.
|
||||
///
|
||||
fn month_title(month: u32) -> String {
|
||||
const MONTH_NAMES: &'static [&'static str] = &[
|
||||
"January", "February", "March", "April", "May", "June",
|
||||
"July", "August", "September", "October", "November", "December"
|
||||
];
|
||||
assert_eq!(MONTH_NAMES.len(), 12);
|
||||
|
||||
// Determine how many spaces before and after the month name
|
||||
// we need to center it over the formatted weeks in the month.
|
||||
let name = MONTH_NAMES[(month - 1) as usize];
|
||||
assert!(name.len() < COLS_PER_WEEK as usize);
|
||||
let before = (COLS_PER_WEEK as usize - name.len()) / 2;
|
||||
let after = COLS_PER_WEEK as usize - name.len() - before;
|
||||
|
||||
// NOTE: Being slightly more verbose to avoid extra allocations.
|
||||
let mut result = String::with_capacity(COLS_PER_WEEK as usize);
|
||||
result.extend(spaces(before));
|
||||
result.push_str(name);
|
||||
result.extend(spaces(after));
|
||||
result
|
||||
}
|
||||
|
||||
fn test_month_title() {
|
||||
assert_eq!(month_title(1).len(), COLS_PER_WEEK as usize);
|
||||
}
|
||||
|
||||
///
|
||||
/// Formats a month.
|
||||
///
|
||||
fn format_month(it: impl DateIterator) -> impl Iterator<Item=String> {
|
||||
let mut month_days = it.peekable();
|
||||
let title = month_title(month_days.peek().unwrap().month());
|
||||
|
||||
Some(title).into_iter()
|
||||
.chain(month_days.__(by_week)
|
||||
.map(|(_, week)| week)
|
||||
.__(format_weeks))
|
||||
}
|
||||
|
||||
fn test_format_month() {
|
||||
let month_fmt = dates_in_year(2013)
|
||||
.__(by_month).next() // Pick January as a test case
|
||||
.map(|(_, days)| days.into_iter()
|
||||
.__(format_month)
|
||||
.join("\n"));
|
||||
|
||||
assert_eq!(
|
||||
month_fmt.as_ref().map(|s| &**s),
|
||||
Some(" January \n\
|
||||
\x20 1 2 3 4 5\n\
|
||||
\x20 6 7 8 9 10 11 12\n\
|
||||
\x2013 14 15 16 17 18 19\n\
|
||||
\x2020 21 22 23 24 25 26\n\
|
||||
\x2027 28 29 30 31 ")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Formats an iterator of months.
|
||||
///
|
||||
fn format_months(it: impl Iterator<Item = impl DateIterator>)
|
||||
-> impl Iterator<Item=impl Iterator<Item=String>>
|
||||
{
|
||||
it.map(format_month)
|
||||
}
|
||||
|
||||
///
|
||||
/// Takes an iterator of iterators of strings; the sub-iterators are consumed
|
||||
/// in lock-step, with their elements joined together.
|
||||
///
|
||||
trait PasteBlocks: Iterator + Sized
|
||||
where Self::Item: Iterator<Item=String> {
|
||||
fn paste_blocks(self, sep_width: usize) -> PasteBlocksIter<Self::Item> {
|
||||
PasteBlocksIter {
|
||||
iters: self.collect(),
|
||||
cache: vec![],
|
||||
col_widths: None,
|
||||
sep_width: sep_width,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<It> PasteBlocks for It where It: Iterator, It::Item: Iterator<Item=String> {}
|
||||
|
||||
struct PasteBlocksIter<StrIt>
|
||||
where StrIt: Iterator<Item=String> {
|
||||
iters: Vec<StrIt>,
|
||||
cache: Vec<Option<String>>,
|
||||
col_widths: Option<Vec<usize>>,
|
||||
sep_width: usize,
|
||||
}
|
||||
|
||||
impl<StrIt> Iterator for PasteBlocksIter<StrIt>
|
||||
where StrIt: Iterator<Item=String> {
|
||||
type Item = String;
|
||||
|
||||
fn next(&mut self) -> Option<String> {
|
||||
self.cache.clear();
|
||||
|
||||
// `cache` is now the next line from each iterator.
|
||||
self.cache.extend(self.iters.iter_mut().map(|it| it.next()));
|
||||
|
||||
// If every line in `cache` is `None`, we have nothing further to do.
|
||||
if self.cache.iter().all(|e| e.is_none()) { return None }
|
||||
|
||||
// Get the column widths if we haven't already.
|
||||
let col_widths = match self.col_widths {
|
||||
Some(ref v) => &**v,
|
||||
None => {
|
||||
self.col_widths = Some(self.cache.iter()
|
||||
.map(|ms| ms.as_ref().map(|s| s.len()).unwrap_or(0))
|
||||
.collect());
|
||||
&**self.col_widths.as_ref().unwrap()
|
||||
}
|
||||
};
|
||||
|
||||
// Fill in any `None`s with spaces.
|
||||
let mut parts = col_widths.iter().cloned().zip(self.cache.iter_mut())
|
||||
.map(|(w,ms)| ms.take().unwrap_or_else(|| spaces(w).collect()));
|
||||
|
||||
// Join them all together.
|
||||
let first = parts.next().unwrap_or(String::new());
|
||||
let sep_width = self.sep_width;
|
||||
Some(parts.fold(first, |mut accum, next| {
|
||||
accum.extend(spaces(sep_width));
|
||||
accum.push_str(&next);
|
||||
accum
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
fn test_paste_blocks() {
|
||||
let row = dates_in_year(2013)
|
||||
.__(by_month).map(|(_, days)| days)
|
||||
.take(3)
|
||||
.__(format_months)
|
||||
.paste_blocks(1)
|
||||
.join("\n");
|
||||
assert_eq!(
|
||||
&*row,
|
||||
" January February March \n\
|
||||
\x20 1 2 3 4 5 1 2 1 2\n\
|
||||
\x20 6 7 8 9 10 11 12 3 4 5 6 7 8 9 3 4 5 6 7 8 9\n\
|
||||
\x2013 14 15 16 17 18 19 10 11 12 13 14 15 16 10 11 12 13 14 15 16\n\
|
||||
\x2020 21 22 23 24 25 26 17 18 19 20 21 22 23 17 18 19 20 21 22 23\n\
|
||||
\x2027 28 29 30 31 24 25 26 27 28 24 25 26 27 28 29 30\n\
|
||||
\x20 31 "
|
||||
);
|
||||
}
|
||||
|
||||
///
|
||||
/// Produces an iterator that yields `n` elements at a time.
|
||||
///
|
||||
trait Chunks: Iterator + Sized {
|
||||
fn chunks(self, n: usize) -> ChunksIter<Self> {
|
||||
assert!(n > 0);
|
||||
ChunksIter {
|
||||
it: self,
|
||||
n: n,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<It> Chunks for It where It: Iterator {}
|
||||
|
||||
struct ChunksIter<It>
|
||||
where It: Iterator {
|
||||
it: It,
|
||||
n: usize,
|
||||
}
|
||||
|
||||
// NOTE: `chunks` in Rust is more-or-less impossible without overhead of some kind.
|
||||
// Aliasing rules mean you need to add dynamic borrow checking, and the design of
|
||||
// `Iterator` means that you need to have the iterator's state kept in an allocation
|
||||
// that is jointly owned by the iterator itself and the sub-iterator.
|
||||
// As such, I've chosen to cop-out and just heap-allocate each chunk.
|
||||
|
||||
impl<It> Iterator for ChunksIter<It>
|
||||
where It: Iterator {
|
||||
type Item = Vec<It::Item>;
|
||||
|
||||
fn next(&mut self) -> Option<Vec<It::Item>> {
|
||||
let first = match self.it.next() {
|
||||
Some(e) => e,
|
||||
None => return None
|
||||
};
|
||||
|
||||
let mut result = Vec::with_capacity(self.n);
|
||||
result.push(first);
|
||||
|
||||
Some((&mut self.it).take(self.n-1)
|
||||
.fold(result, |mut acc, next| { acc.push(next); acc }))
|
||||
}
|
||||
}
|
||||
|
||||
fn test_chunks() {
|
||||
let r = &[1, 2, 3, 4, 5, 6, 7];
|
||||
let c = r.iter().cloned().chunks(3).collect::<Vec<_>>();
|
||||
assert_eq!(&*c, &[vec![1, 2, 3], vec![4, 5, 6], vec![7]]);
|
||||
}
|
||||
|
||||
///
|
||||
/// Formats a year.
|
||||
///
|
||||
fn format_year(year: i32, months_per_row: usize) -> String {
|
||||
const COL_SPACING: usize = 1;
|
||||
|
||||
// Start by generating all dates for the given year.
|
||||
dates_in_year(year)
|
||||
|
||||
// Group them by month and throw away month number.
|
||||
.__(by_month).map(|(_, days)| days)
|
||||
|
||||
// Group the months into horizontal rows.
|
||||
.chunks(months_per_row)
|
||||
|
||||
// Format each row
|
||||
.map(|r| r.into_iter()
|
||||
// By formatting each month
|
||||
.__(format_months)
|
||||
|
||||
// Horizontally pasting each respective month's lines together.
|
||||
.paste_blocks(COL_SPACING)
|
||||
.join("\n")
|
||||
)
|
||||
|
||||
// Insert a blank line between each row
|
||||
.join("\n\n")
|
||||
}
|
||||
|
||||
fn test_format_year() {
|
||||
const MONTHS_PER_ROW: usize = 3;
|
||||
|
||||
macro_rules! assert_eq_cal {
|
||||
($lhs:expr, $rhs:expr) => {
|
||||
if $lhs != $rhs {
|
||||
println!("got:\n```\n{}\n```\n", $lhs.replace(" ", "."));
|
||||
println!("expected:\n```\n{}\n```", $rhs.replace(" ", "."));
|
||||
panic!("calendars didn't match!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq_cal!(&format_year(1984, MONTHS_PER_ROW), "\
|
||||
\x20 January February March \n\
|
||||
\x20 1 2 3 4 5 6 7 1 2 3 4 1 2 3\n\
|
||||
\x20 8 9 10 11 12 13 14 5 6 7 8 9 10 11 4 5 6 7 8 9 10\n\
|
||||
\x2015 16 17 18 19 20 21 12 13 14 15 16 17 18 11 12 13 14 15 16 17\n\
|
||||
\x2022 23 24 25 26 27 28 19 20 21 22 23 24 25 18 19 20 21 22 23 24\n\
|
||||
\x2029 30 31 26 27 28 29 25 26 27 28 29 30 31\n\
|
||||
\n\
|
||||
\x20 April May June \n\
|
||||
\x20 1 2 3 4 5 6 7 1 2 3 4 5 1 2\n\
|
||||
\x20 8 9 10 11 12 13 14 6 7 8 9 10 11 12 3 4 5 6 7 8 9\n\
|
||||
\x2015 16 17 18 19 20 21 13 14 15 16 17 18 19 10 11 12 13 14 15 16\n\
|
||||
\x2022 23 24 25 26 27 28 20 21 22 23 24 25 26 17 18 19 20 21 22 23\n\
|
||||
\x2029 30 27 28 29 30 31 24 25 26 27 28 29 30\n\
|
||||
\n\
|
||||
\x20 July August September \n\
|
||||
\x20 1 2 3 4 5 6 7 1 2 3 4 1\n\
|
||||
\x20 8 9 10 11 12 13 14 5 6 7 8 9 10 11 2 3 4 5 6 7 8\n\
|
||||
\x2015 16 17 18 19 20 21 12 13 14 15 16 17 18 9 10 11 12 13 14 15\n\
|
||||
\x2022 23 24 25 26 27 28 19 20 21 22 23 24 25 16 17 18 19 20 21 22\n\
|
||||
\x2029 30 31 26 27 28 29 30 31 23 24 25 26 27 28 29\n\
|
||||
\x20 30 \n\
|
||||
\n\
|
||||
\x20 October November December \n\
|
||||
\x20 1 2 3 4 5 6 1 2 3 1\n\
|
||||
\x20 7 8 9 10 11 12 13 4 5 6 7 8 9 10 2 3 4 5 6 7 8\n\
|
||||
\x2014 15 16 17 18 19 20 11 12 13 14 15 16 17 9 10 11 12 13 14 15\n\
|
||||
\x2021 22 23 24 25 26 27 18 19 20 21 22 23 24 16 17 18 19 20 21 22\n\
|
||||
\x2028 29 30 31 25 26 27 28 29 30 23 24 25 26 27 28 29\n\
|
||||
\x20 30 31 ");
|
||||
|
||||
assert_eq_cal!(&format_year(2015, MONTHS_PER_ROW), "\
|
||||
\x20 January February March \n\
|
||||
\x20 1 2 3 1 2 3 4 5 6 7 1 2 3 4 5 6 7\n\
|
||||
\x20 4 5 6 7 8 9 10 8 9 10 11 12 13 14 8 9 10 11 12 13 14\n\
|
||||
\x2011 12 13 14 15 16 17 15 16 17 18 19 20 21 15 16 17 18 19 20 21\n\
|
||||
\x2018 19 20 21 22 23 24 22 23 24 25 26 27 28 22 23 24 25 26 27 28\n\
|
||||
\x2025 26 27 28 29 30 31 29 30 31 \n\
|
||||
\n\
|
||||
\x20 April May June \n\
|
||||
\x20 1 2 3 4 1 2 1 2 3 4 5 6\n\
|
||||
\x20 5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13\n\
|
||||
\x2012 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20\n\
|
||||
\x2019 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27\n\
|
||||
\x2026 27 28 29 30 24 25 26 27 28 29 30 28 29 30 \n\
|
||||
\x20 31 \n\
|
||||
\n\
|
||||
\x20 July August September \n\
|
||||
\x20 1 2 3 4 1 1 2 3 4 5\n\
|
||||
\x20 5 6 7 8 9 10 11 2 3 4 5 6 7 8 6 7 8 9 10 11 12\n\
|
||||
\x2012 13 14 15 16 17 18 9 10 11 12 13 14 15 13 14 15 16 17 18 19\n\
|
||||
\x2019 20 21 22 23 24 25 16 17 18 19 20 21 22 20 21 22 23 24 25 26\n\
|
||||
\x2026 27 28 29 30 31 23 24 25 26 27 28 29 27 28 29 30 \n\
|
||||
\x20 30 31 \n\
|
||||
\n\
|
||||
\x20 October November December \n\
|
||||
\x20 1 2 3 1 2 3 4 5 6 7 1 2 3 4 5\n\
|
||||
\x20 4 5 6 7 8 9 10 8 9 10 11 12 13 14 6 7 8 9 10 11 12\n\
|
||||
\x2011 12 13 14 15 16 17 15 16 17 18 19 20 21 13 14 15 16 17 18 19\n\
|
||||
\x2018 19 20 21 22 23 24 22 23 24 25 26 27 28 20 21 22 23 24 25 26\n\
|
||||
\x2025 26 27 28 29 30 31 29 30 27 28 29 30 31 ");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Run tests.
|
||||
test_spaces();
|
||||
test_dates_in_year();
|
||||
test_group_by();
|
||||
test_by_month();
|
||||
test_isoweekdate();
|
||||
test_by_week();
|
||||
test_format_weeks();
|
||||
test_month_title();
|
||||
test_format_month();
|
||||
test_paste_blocks();
|
||||
test_chunks();
|
||||
test_format_year();
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
// Copyright 2016 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.
|
||||
|
||||
struct State;
|
||||
type Error = ();
|
||||
|
||||
trait Bind<F> {
|
||||
type Output;
|
||||
fn bind(self, f: F) -> Self::Output;
|
||||
}
|
||||
|
||||
fn bind<T, U, A, B, F>(mut a: A, mut f: F)
|
||||
-> impl FnMut(&mut State) -> Result<U, Error>
|
||||
where F: FnMut(T) -> B,
|
||||
A: FnMut(&mut State) -> Result<T, Error>,
|
||||
B: FnMut(&mut State) -> Result<U, Error>
|
||||
{
|
||||
move |state | {
|
||||
let r = a(state)?;
|
||||
f(r)(state)
|
||||
}
|
||||
}
|
||||
|
||||
fn atom<T>(x: T) -> impl FnMut(&mut State) -> Result<T, Error> {
|
||||
let mut x = Some(x);
|
||||
move |_| x.take().map_or(Err(()), Ok)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
assert_eq!(bind(atom(5), |x| atom(x > 4))(&mut State), Ok(true));
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
fn main() {}
|
||||
|
||||
fn foo() -> impl std::fmt::Debug { "cake" }
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
// Copyright 2017 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::iter::once;
|
||||
|
||||
struct Foo {
|
||||
x: i32,
|
||||
}
|
||||
|
||||
impl Foo {
|
||||
fn inside(&self) -> impl Iterator<Item = &i32> {
|
||||
once(&self.x)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("hi");
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
// Tests for nested self-reference which caused a stack overflow.
|
||||
|
||||
use std::fmt::Debug;
|
||||
use std::ops::*;
|
||||
|
||||
fn gen() -> impl PartialOrd + PartialEq + Debug { }
|
||||
|
||||
struct Bar {}
|
||||
trait Foo<T = Self> {}
|
||||
impl Foo for Bar {}
|
||||
|
||||
fn foo() -> impl Foo {
|
||||
Bar {}
|
||||
}
|
||||
|
||||
fn test_impl_ops() -> impl Add + Sub + Mul + Div { 1 }
|
||||
fn test_impl_assign_ops() -> impl AddAssign + SubAssign + MulAssign + DivAssign { 1 }
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,126 +0,0 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
#![allow(warnings)]
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
fn any_lifetime<'a>() -> &'a u32 { &5 }
|
||||
|
||||
fn static_lifetime() -> &'static u32 { &5 }
|
||||
|
||||
fn any_lifetime_as_static_impl_trait() -> impl Debug {
|
||||
any_lifetime()
|
||||
}
|
||||
|
||||
fn lifetimes_as_static_impl_trait() -> impl Debug {
|
||||
static_lifetime()
|
||||
}
|
||||
|
||||
fn no_params_or_lifetimes_is_static() -> impl Debug + 'static {
|
||||
lifetimes_as_static_impl_trait()
|
||||
}
|
||||
|
||||
fn static_input_type_is_static<T: Debug + 'static>(x: T) -> impl Debug + 'static { x }
|
||||
|
||||
fn type_outlives_reference_lifetime<'a, T: Debug>(x: &'a T) -> impl Debug + 'a { x }
|
||||
fn type_outlives_reference_lifetime_elided<T: Debug>(x: &T) -> impl Debug + '_ { x }
|
||||
|
||||
trait SingleRegionTrait<'a> {}
|
||||
impl<'a> SingleRegionTrait<'a> for u32 {}
|
||||
impl<'a> SingleRegionTrait<'a> for &'a u32 {}
|
||||
struct SingleRegionStruct<'a>(&'a u32);
|
||||
|
||||
fn simple_type_hrtb<'b>() -> impl for<'a> SingleRegionTrait<'a> { 5 }
|
||||
// FIXME(cramertj) add test after #45992 lands to ensure lint is triggered
|
||||
fn elision_single_region_trait(x: &u32) -> impl SingleRegionTrait { x }
|
||||
fn elision_single_region_struct(x: SingleRegionStruct) -> impl Into<SingleRegionStruct> { x }
|
||||
|
||||
fn closure_hrtb() -> impl for<'a> Fn(&'a u32) { |_| () }
|
||||
fn closure_hr_elided() -> impl Fn(&u32) { |_| () }
|
||||
fn closure_hr_elided_return() -> impl Fn(&u32) -> &u32 { |x| x }
|
||||
fn closure_pass_through_elided_return(x: impl Fn(&u32) -> &u32) -> impl Fn(&u32) -> &u32 { x }
|
||||
fn closure_pass_through_reference_elided(x: &impl Fn(&u32) -> &u32) -> &impl Fn(&u32) -> &u32 { x }
|
||||
|
||||
fn nested_lifetime<'a>(input: &'a str)
|
||||
-> impl Iterator<Item = impl Iterator<Item = i32> + 'a> + 'a
|
||||
{
|
||||
input.lines().map(|line| {
|
||||
line.split_whitespace().map(|cell| cell.parse().unwrap())
|
||||
})
|
||||
}
|
||||
|
||||
fn pass_through_elision(x: &u32) -> impl Into<&u32> { x }
|
||||
fn pass_through_elision_with_fn_ptr(x: &fn(&u32) -> &u32) -> impl Into<&fn(&u32) -> &u32> { x }
|
||||
|
||||
fn pass_through_elision_with_fn_path<T: Fn(&u32) -> &u32>(
|
||||
x: &T
|
||||
) -> &impl Fn(&u32) -> &u32 { x }
|
||||
|
||||
fn foo(x: &impl Debug) -> &impl Debug { x }
|
||||
fn foo_explicit_lifetime<'a>(x: &'a impl Debug) -> &'a impl Debug { x }
|
||||
fn foo_explicit_arg<T: Debug>(x: &T) -> &impl Debug { x }
|
||||
|
||||
fn mixed_lifetimes<'a>() -> impl for<'b> Fn(&'b &'a u32) { |_| () }
|
||||
fn mixed_as_static() -> impl Fn(&'static &'static u32) { mixed_lifetimes() }
|
||||
|
||||
trait MultiRegionTrait<'a, 'b>: Debug {}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct MultiRegionStruct<'a, 'b>(&'a u32, &'b u32);
|
||||
impl<'a, 'b> MultiRegionTrait<'a, 'b> for MultiRegionStruct<'a, 'b> {}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct NoRegionStruct;
|
||||
impl<'a, 'b> MultiRegionTrait<'a, 'b> for NoRegionStruct {}
|
||||
|
||||
fn finds_least_region<'a: 'b, 'b>(x: &'a u32, y: &'b u32) -> impl MultiRegionTrait<'a, 'b> {
|
||||
MultiRegionStruct(x, y)
|
||||
}
|
||||
|
||||
fn finds_explicit_bound<'a: 'b, 'b>
|
||||
(x: &'a u32, y: &'b u32) -> impl MultiRegionTrait<'a, 'b> + 'b
|
||||
{
|
||||
MultiRegionStruct(x, y)
|
||||
}
|
||||
|
||||
fn finds_explicit_bound_even_without_least_region<'a, 'b>
|
||||
(x: &'a u32, y: &'b u32) -> impl MultiRegionTrait<'a, 'b> + 'b
|
||||
{
|
||||
NoRegionStruct
|
||||
}
|
||||
|
||||
/* FIXME: `impl Trait<'a> + 'b` should live as long as 'b, even if 'b outlives 'a
|
||||
fn outlives_bounds_even_with_contained_regions<'a, 'b>
|
||||
(x: &'a u32, y: &'b u32) -> impl Debug + 'b
|
||||
{
|
||||
finds_explicit_bound_even_without_least_region(x, y)
|
||||
}
|
||||
*/
|
||||
|
||||
fn unnamed_lifetimes_arent_contained_in_impl_trait_and_will_unify<'a, 'b>
|
||||
(x: &'a u32, y: &'b u32) -> impl Debug
|
||||
{
|
||||
fn deref<'lt>(x: &'lt u32) -> impl Debug { *x }
|
||||
|
||||
if true { deref(x) } else { deref(y) }
|
||||
}
|
||||
|
||||
fn can_add_region_bound_to_static_type<'a, 'b>(_: &'a u32) -> impl Debug + 'a { 5 }
|
||||
|
||||
struct MyVec(Vec<Vec<u8>>);
|
||||
|
||||
impl<'unnecessary_lifetime> MyVec {
|
||||
fn iter_doesnt_capture_unnecessary_lifetime<'s>(&'s self) -> impl Iterator<Item = &'s u8> {
|
||||
self.0.iter().flat_map(|inner_vec| inner_vec.iter())
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
fn foo<T>(t: T) -> impl Into<[T; { const FOO: usize = 1; FOO }]> {
|
||||
[t]
|
||||
}
|
||||
|
||||
fn bar() -> impl Into<[u8; { const FOO: usize = 1; FOO }]> {
|
||||
[99]
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("{:?}", foo(42).into());
|
||||
println!("{:?}", bar().into());
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
fn hrtb(f: impl Fn(&u32) -> u32) -> u32 {
|
||||
f(&22) + f(&44)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let sum = hrtb(|x| x * 2);
|
||||
assert_eq!(sum, 22*2 + 44*2);
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
fn hrtb(f: impl for<'a> Fn(&'a u32) -> &'a u32) -> u32 {
|
||||
f(&22) + f(&44)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let sum = hrtb(|x| x);
|
||||
assert_eq!(sum, 22 + 44);
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
// Copyright 2017 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::fmt::Display;
|
||||
|
||||
fn check_display_eq(iter: &Vec<impl Display>) {
|
||||
let mut collected = String::new();
|
||||
for it in iter {
|
||||
let disp = format!("{} ", it);
|
||||
collected.push_str(&disp);
|
||||
}
|
||||
assert_eq!("0 3 27 823 4891 1 0", collected.trim());
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let i32_list_vec = vec![0i32, 3, 27, 823, 4891, 1, 0];
|
||||
let u32_list_vec = vec![0u32, 3, 27, 823, 4891, 1, 0];
|
||||
let str_list_vec = vec!["0", "3", "27", "823", "4891", "1", "0"];
|
||||
|
||||
check_display_eq(&i32_list_vec);
|
||||
check_display_eq(&u32_list_vec);
|
||||
check_display_eq(&str_list_vec);
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
// Copyright 2017 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::fmt::Display;
|
||||
|
||||
fn check_display_eq(iter: impl IntoIterator<Item = impl Display>) {
|
||||
let mut collected = String::new();
|
||||
for it in iter {
|
||||
let disp = format!("{} ", it);
|
||||
collected.push_str(&disp);
|
||||
}
|
||||
assert_eq!("0 3 27 823 4891 1 0", collected.trim());
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let i32_list = [0i32, 3, 27, 823, 4891, 1, 0];
|
||||
let i32_list_vec = vec![0i32, 3, 27, 823, 4891, 1, 0];
|
||||
let u32_list = [0u32, 3, 27, 823, 4891, 1, 0];
|
||||
let u32_list_vec = vec![0u32, 3, 27, 823, 4891, 1, 0];
|
||||
let u16_list = [0u16, 3, 27, 823, 4891, 1, 0];
|
||||
let str_list = ["0", "3", "27", "823", "4891", "1", "0"];
|
||||
let str_list_vec = vec!["0", "3", "27", "823", "4891", "1", "0"];
|
||||
|
||||
check_display_eq(&i32_list);
|
||||
check_display_eq(i32_list_vec);
|
||||
check_display_eq(&u32_list);
|
||||
check_display_eq(u32_list_vec);
|
||||
check_display_eq(&u16_list);
|
||||
check_display_eq(&str_list);
|
||||
check_display_eq(str_list_vec);
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
// Copyright 2017 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::fmt::Debug;
|
||||
|
||||
trait InTraitDefnParameters {
|
||||
fn in_parameters(_: impl Debug) -> String;
|
||||
}
|
||||
|
||||
impl InTraitDefnParameters for () {
|
||||
fn in_parameters(v: impl Debug) -> String {
|
||||
format!("() + {:?}", v)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let s = <() as InTraitDefnParameters>::in_parameters(22);
|
||||
assert_eq!(s, "() + 22");
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
// Copyright 2017 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::fmt::Display;
|
||||
|
||||
fn foo(f: impl Display + Clone) -> String {
|
||||
let g = f.clone();
|
||||
format!("{} + {}", f, g)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let sum = foo(format!("22"));
|
||||
assert_eq!(sum, r"22 + 22");
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
// Copyright 2016 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.
|
||||
|
||||
// aux-build:xcrate.rs
|
||||
|
||||
extern crate xcrate;
|
||||
|
||||
fn main() {
|
||||
// NOTE line below commeted out due to issue #45994
|
||||
// assert_eq!(xcrate::fourway_add(1)(2)(3)(4), 10);
|
||||
xcrate::return_closure_accessing_internal_fn()();
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
// Copyright 2016 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.
|
||||
|
||||
// aux-build:xcrate.rs
|
||||
|
||||
extern crate xcrate;
|
||||
|
||||
fn main() {
|
||||
xcrate::return_internal_fn()();
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
// Copyright 2016 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.
|
||||
|
||||
// Regression test for #47153: constants in a generic context (such as
|
||||
// a trait) used to ICE.
|
||||
|
||||
#![feature(nll)]
|
||||
#![allow(warnings)]
|
||||
|
||||
trait Foo {
|
||||
const B: bool = true;
|
||||
}
|
||||
|
||||
struct Bar<T> { x: T }
|
||||
|
||||
impl<T> Bar<T> {
|
||||
const B: bool = true;
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
// Copyright 2018 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(nll)]
|
||||
|
||||
pub struct DescriptorSet<'a> {
|
||||
pub slots: Vec<AttachInfo<'a, Resources>>
|
||||
}
|
||||
|
||||
pub trait ResourcesTrait<'r>: Sized {
|
||||
type DescriptorSet: 'r;
|
||||
}
|
||||
|
||||
pub struct Resources;
|
||||
|
||||
impl<'a> ResourcesTrait<'a> for Resources {
|
||||
type DescriptorSet = DescriptorSet<'a>;
|
||||
}
|
||||
|
||||
pub enum AttachInfo<'a, R: ResourcesTrait<'a>> {
|
||||
NextDescriptorSet(Box<R::DescriptorSet>)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _x = DescriptorSet {slots: Vec::new()};
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
// Copyright 2012 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(nll)]
|
||||
|
||||
struct WithDrop;
|
||||
|
||||
impl Drop for WithDrop {
|
||||
fn drop(&mut self) {}
|
||||
}
|
||||
|
||||
fn reborrow_from_closure(r: &mut ()) -> &mut () {
|
||||
let d = WithDrop;
|
||||
(move || { d; &mut *r })()
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
// Copyright 2012 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(nll)]
|
||||
#![feature(generators, generator_trait)]
|
||||
|
||||
struct WithDrop;
|
||||
|
||||
impl Drop for WithDrop {
|
||||
fn drop(&mut self) {}
|
||||
}
|
||||
|
||||
fn reborrow_from_generator(r: &mut ()) {
|
||||
let d = WithDrop;
|
||||
move || { d; yield; &mut *r };
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
// Copyright 2012 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(nll)]
|
||||
#![deny(unused_mut)]
|
||||
|
||||
fn main() {
|
||||
vec![42].iter().map(|_| ()).count();
|
||||
vec![(42, 22)].iter().map(|(_x, _y)| ()).count();
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
// Copyright 2016 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(nll)]
|
||||
#![deny(unused_mut)]
|
||||
|
||||
struct Foo {
|
||||
pub value: i32
|
||||
}
|
||||
|
||||
fn use_foo_mut(mut foo: Foo) {
|
||||
foo = foo;
|
||||
println!("{}", foo.value);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
use_foo_mut(Foo { value: 413 });
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
// Copyright 2016 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(nll)]
|
||||
#![allow(unused_variables)]
|
||||
|
||||
pub trait TryTransform {
|
||||
fn try_transform<F>(self, f: F)
|
||||
where
|
||||
Self: Sized,
|
||||
F: FnOnce(Self);
|
||||
}
|
||||
|
||||
impl<'a, T> TryTransform for &'a mut T {
|
||||
fn try_transform<F>(self, f: F)
|
||||
where
|
||||
// The bug was that `Self: Sized` caused the lifetime of `this` to "extend" for all
|
||||
// of 'a instead of only lasting as long as the binding is used (for just that line).
|
||||
Self: Sized,
|
||||
F: FnOnce(Self),
|
||||
{
|
||||
let this: *mut T = self as *mut T;
|
||||
f(self);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
// Copyright 2018 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(nll)]
|
||||
|
||||
struct List<T> {
|
||||
value: T,
|
||||
next: Option<Box<List<T>>>,
|
||||
}
|
||||
|
||||
fn to_refs<T>(mut list: &mut List<T>) -> Vec<&mut T> {
|
||||
let mut result = vec![];
|
||||
loop {
|
||||
result.push(&mut list.value);
|
||||
if let Some(n) = list.next.as_mut() {
|
||||
list = n;
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut list = List { value: 1, next: None };
|
||||
let vec = to_refs(&mut list);
|
||||
assert_eq!(vec![&mut 1], vec);
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
// Copyright 2016 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(nll)]
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
fn process_or_insert_default(map: &mut HashMap<usize, String>, key: usize) {
|
||||
match map.get_mut(&key) {
|
||||
Some(value) => {
|
||||
process(value);
|
||||
}
|
||||
None => {
|
||||
map.insert(key, "".to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn process(x: &str) {
|
||||
assert_eq!(x, "Hello, world");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let map = &mut HashMap::new();
|
||||
map.insert(22, format!("Hello, world"));
|
||||
map.insert(44, format!("Goodbye, world"));
|
||||
process_or_insert_default(map, 22);
|
||||
process_or_insert_default(map, 66);
|
||||
assert_eq!(map[&66], "");
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
// Copyright 2016 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.
|
||||
|
||||
// A test for something that NLL enables. It sometimes happens that
|
||||
// the `while let` pattern makes some borrows from a variable (in this
|
||||
// case, `x`) that you need in order to compute the next value for
|
||||
// `x`. The lexical checker makes this very painful. The NLL checker
|
||||
// does not.
|
||||
|
||||
#![feature(nll)]
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
enum Foo {
|
||||
Base(usize),
|
||||
Next(Rc<Foo>),
|
||||
}
|
||||
|
||||
fn find_base(mut x: Rc<Foo>) -> Rc<Foo> {
|
||||
while let Foo::Next(n) = &*x {
|
||||
x = n.clone();
|
||||
}
|
||||
x
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let chain = Rc::new(Foo::Next(Rc::new(Foo::Base(44))));
|
||||
let base = find_base(chain);
|
||||
assert_eq!(&*base, &Foo::Base(44));
|
||||
}
|
||||
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
// Copyright 2017 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.
|
||||
//
|
||||
// ignore-test: not a test, used by non_modrs_mods.rs
|
||||
|
||||
pub mod inner_modrs_mod;
|
||||
pub mod inner_foors_mod;
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
// Copyright 2017 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 mod innest;
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
// Copyright 2017 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 fn foo() {}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
// Copyright 2017 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 fn foo() {}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
// Copyright 2017 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 mod innest;
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
// Copyright 2017 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 mod innest;
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
// Copyright 2017 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 fn foo() {}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
// Copyright 2017 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 fn foo() {}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
// Copyright 2017 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 mod innest;
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
// Copyright 2017 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 mod inner_modrs_mod;
|
||||
pub mod inner_foors_mod;
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
// Copyright 2017 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.
|
||||
//
|
||||
// ignore-pretty issue #37195
|
||||
#![feature(non_modrs_mods)]
|
||||
|
||||
pub mod modrs_mod;
|
||||
pub mod foors_mod;
|
||||
|
||||
#[path = "some_crazy_attr_mod_dir/arbitrary_name.rs"]
|
||||
pub mod attr_mod;
|
||||
|
||||
pub fn main() {
|
||||
modrs_mod::inner_modrs_mod::innest::foo();
|
||||
modrs_mod::inner_foors_mod::innest::foo();
|
||||
foors_mod::inner_modrs_mod::innest::foo();
|
||||
foors_mod::inner_foors_mod::innest::foo();
|
||||
attr_mod::inner_modrs_mod::innest::foo();
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
// Copyright 2017 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 mod inner_modrs_mod;
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
// Copyright 2017 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 fn foo() {}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
// Copyright 2017 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 mod innest;
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
// Copyright 2016 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.
|
||||
|
||||
// compile-flags:-C panic=abort
|
||||
// aux-build:exit-success-if-unwind.rs
|
||||
// no-prefer-dynamic
|
||||
// ignore-cloudabi no processes
|
||||
// ignore-emscripten no processes
|
||||
// ignore-macos
|
||||
|
||||
extern crate exit_success_if_unwind;
|
||||
|
||||
use std::process::Command;
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
let mut args = env::args_os();
|
||||
let me = args.next().unwrap();
|
||||
|
||||
if let Some(s) = args.next() {
|
||||
if &*s == "foo" {
|
||||
exit_success_if_unwind::bar(do_panic);
|
||||
}
|
||||
}
|
||||
|
||||
let mut cmd = Command::new(env::args_os().next().unwrap());
|
||||
cmd.arg("foo");
|
||||
|
||||
|
||||
// ARMv6 hanges while printing the backtrace, see #41004
|
||||
if cfg!(target_arch = "arm") && cfg!(target_env = "gnu") {
|
||||
cmd.env("RUST_BACKTRACE", "0");
|
||||
}
|
||||
|
||||
let s = cmd.status();
|
||||
assert!(s.unwrap().code() != Some(0));
|
||||
}
|
||||
|
||||
fn do_panic() {
|
||||
panic!("try to catch me");
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue