Move some tests to more reasonable directories - 2

Address comments

Update limits
This commit is contained in:
Caio 2021-01-16 15:54:05 -03:00
parent 63a83c5f55
commit ad35979c50
190 changed files with 3 additions and 69 deletions

View file

@ -1,3 +0,0 @@
// include file for issue-21146.rs
parse_error

View file

@ -1 +0,0 @@
macro_rules! m { () => { $crate::main(); } }

View file

@ -1,34 +0,0 @@
#![feature(box_syntax)]
trait X {
fn get_i(&self) -> isize;
}
struct B {
i: isize
}
impl X for B {
fn get_i(&self) -> isize {
self.i
}
}
struct A<'a> {
p: &'a (dyn X + 'a)
}
fn make_a<'a>(p: &'a dyn X) -> A<'a> {
A { p: p }
}
fn make_make_a<'a>() -> A<'a> {
let b: Box<B> = box B {i:1};
let bb: &B = &*b;
make_a(bb) //~ ERROR cannot return value referencing local data `*b`
}
fn main() {
let _a = make_make_a();
}

View file

@ -1,11 +0,0 @@
error[E0515]: cannot return value referencing local data `*b`
--> $DIR/issue-12470.rs:29:5
|
LL | let bb: &B = &*b;
| --- `*b` is borrowed here
LL | make_a(bb)
| ^^^^^^^^^^ returns a value referencing data owned by the current function
error: aborting due to previous error
For more information about this error, try `rustc --explain E0515`.

View file

@ -1,21 +0,0 @@
// run-pass
pub fn main() {
let x = 1;
let y = 2;
assert_eq!(3, match (x, y) {
(1, 1) => 1,
(2, 2) => 2,
(1..=2, 2) => 3,
_ => 4,
});
// nested tuple
assert_eq!(3, match ((x, y),) {
((1, 1),) => 1,
((2, 2),) => 2,
((1..=2, 2),) => 3,
_ => 4,
});
}

View file

@ -1,21 +0,0 @@
#![deny(unreachable_patterns)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
pub enum E {
A,
B,
}
pub mod b {
pub fn key(e: ::E) -> &'static str {
match e {
A => "A",
//~^ WARN pattern binding `A` is named the same as one of the variants of the type `E`
B => "B", //~ ERROR: unreachable pattern
//~^ WARN pattern binding `B` is named the same as one of the variants of the type `E`
}
}
}
fn main() {}

View file

@ -1,32 +0,0 @@
warning[E0170]: pattern binding `A` is named the same as one of the variants of the type `E`
--> $DIR/issue-14221.rs:13:13
|
LL | A => "A",
| ^ help: to match on the variant, qualify the path: `E::A`
|
= note: `#[warn(bindings_with_variant_name)]` on by default
warning[E0170]: pattern binding `B` is named the same as one of the variants of the type `E`
--> $DIR/issue-14221.rs:15:13
|
LL | B => "B",
| ^ help: to match on the variant, qualify the path: `E::B`
error: unreachable pattern
--> $DIR/issue-14221.rs:15:13
|
LL | A => "A",
| - matches any value
LL |
LL | B => "B",
| ^ unreachable pattern
|
note: the lint level is defined here
--> $DIR/issue-14221.rs:1:9
|
LL | #![deny(unreachable_patterns)]
| ^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error; 2 warnings emitted
For more information about this error, try `rustc --explain E0170`.

View file

@ -1,48 +0,0 @@
// build-pass
#![allow(unused_macros)]
#![allow(dead_code)]
#![feature(llvm_asm)]
type History = Vec<&'static str>;
fn wrap<A>(x:A, which: &'static str, history: &mut History) -> A {
history.push(which);
x
}
macro_rules! demo {
( $output_constraint:tt ) => {
{
let mut x: isize = 0;
let y: isize = 1;
let mut history: History = vec![];
unsafe {
llvm_asm!("mov ($1), $0"
: $output_constraint (*wrap(&mut x, "out", &mut history))
: "r"(&wrap(y, "in", &mut history))
:: "volatile");
}
assert_eq!((x,y), (1,1));
let b: &[_] = &["out", "in"];
assert_eq!(history, b);
}
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn main() {
fn out_write_only_expr_then_in_expr() {
demo!("=r")
}
fn out_read_write_expr_then_in_expr() {
demo!("+r")
}
out_write_only_expr_then_in_expr();
out_read_write_expr_then_in_expr();
}
#[cfg(all(not(target_arch = "x86"), not(target_arch = "x86_64")))]
pub fn main() {}

View file

@ -1,9 +0,0 @@
// run-pass
#![allow(unused_mut)]
#![allow(unused_variables)]
// pretty-expanded FIXME #23616
fn main() {
let mut array = [1, 2, 3];
let pie_slice = &array[1..2];
}

View file

@ -1,38 +0,0 @@
// run-pass
#![allow(illegal_floating_point_literal_pattern)] // FIXME #41620
#![allow(ellipsis_inclusive_range_patterns)]
// regression test for the model lexer handling the DOTDOTDOT syntax (#15877)
pub fn main() {
match 5_usize {
1_usize...5_usize => {}
_ => panic!("should match range"),
}
match 5_usize {
6_usize...7_usize => panic!("shouldn't match range"),
_ => {}
}
match 5_usize {
1_usize => panic!("should match non-first range"),
2_usize...6_usize => {}
_ => panic!("math is broken")
}
match 'c' {
'a'...'z' => {}
_ => panic!("should support char ranges")
}
match -3_isize {
-7...5 => {}
_ => panic!("should match signed range")
}
match 3.0f64 {
1.0...5.0 => {}
_ => panic!("should match float range")
}
match -1.5f64 {
-3.6...3.6 => {}
_ => panic!("should match negative float range")
}
}

View file

@ -1,25 +0,0 @@
// check-pass
#![feature(box_syntax)]
struct Foo { a: isize, b: isize }
fn main() {
let mut x: Box<_> = box Foo { a: 1, b: 2 };
let (a, b) = (&mut x.a, &mut x.b);
let mut foo: Box<_> = box Foo { a: 1, b: 2 };
let (c, d) = (&mut foo.a, &foo.b);
// We explicitly use the references created above to illustrate that the
// borrow checker is accepting this code *not* because of artificially
// short lifetimes, but rather because it understands that all the
// references are of disjoint parts of memory.
use_imm(d);
use_mut(c);
use_mut(b);
use_mut(a);
}
fn use_mut<T>(_: &mut T) { }
fn use_imm<T>(_: &T) { }

View file

@ -1,10 +0,0 @@
#![feature(fn_traits)]
fn id<T>(x: T) -> T { x }
pub fn foo<'a, F: Fn(&'a ())>(bar: F) {
bar.call((
&id(()), //~ ERROR temporary value dropped while borrowed
));
}
fn main() {}

View file

@ -1,16 +0,0 @@
error[E0716]: temporary value dropped while borrowed
--> $DIR/issue-17545.rs:7:10
|
LL | pub fn foo<'a, F: Fn(&'a ())>(bar: F) {
| -- lifetime `'a` defined here
LL | / bar.call((
LL | | &id(()),
| | ^^^^^^ creates a temporary which is freed while still in use
LL | | ));
| | -- temporary value is freed at the end of this statement
| |______|
| argument requires that borrow lasts for `'a`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0716`.

View file

@ -1,19 +0,0 @@
// run-pass
#![allow(dead_code)]
struct S { a: usize }
static A: S = S { a: 3 };
static B: &'static usize = &A.a;
static C: &'static usize = &(A.a);
static D: [usize; 1] = [1];
static E: usize = D[0];
static F: &'static usize = &D[0];
fn main() {
assert_eq!(*B, A.a);
assert_eq!(*B, A.a);
assert_eq!(E, D[0]);
assert_eq!(*F, D[0]);
}

View file

@ -1,10 +0,0 @@
const C1: &'static mut [usize] = &mut [];
//~^ ERROR: mutable references are not allowed in constants
static mut S: usize = 3;
const C2: &'static mut usize = unsafe { &mut S };
//~^ ERROR: constants cannot refer to statics
//~| ERROR: constants cannot refer to statics
//~| ERROR: mutable references are not allowed in constants
fn main() {}

View file

@ -1,32 +0,0 @@
error[E0764]: mutable references are not allowed in constants
--> $DIR/issue-17718-const-bad-values.rs:1:34
|
LL | const C1: &'static mut [usize] = &mut [];
| ^^^^^^^ `&mut` is only allowed in `const fn`
error[E0013]: constants cannot refer to statics
--> $DIR/issue-17718-const-bad-values.rs:5:46
|
LL | const C2: &'static mut usize = unsafe { &mut S };
| ^
|
= help: consider extracting the value of the `static` to a `const`, and referring to that
error[E0013]: constants cannot refer to statics
--> $DIR/issue-17718-const-bad-values.rs:5:46
|
LL | const C2: &'static mut usize = unsafe { &mut S };
| ^
|
= help: consider extracting the value of the `static` to a `const`, and referring to that
error[E0764]: mutable references are not allowed in constants
--> $DIR/issue-17718-const-bad-values.rs:5:41
|
LL | const C2: &'static mut usize = unsafe { &mut S };
| ^^^^^^ `&mut` is only allowed in `const fn`
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0013, E0764.
For more information about an error, try `rustc --explain E0013`.

View file

@ -1,14 +0,0 @@
use std::cell::UnsafeCell;
const A: UnsafeCell<usize> = UnsafeCell::new(1);
const B: &'static UnsafeCell<usize> = &A;
//~^ ERROR: cannot refer to interior mutable
struct C { a: UnsafeCell<usize> }
const D: C = C { a: UnsafeCell::new(1) };
const E: &'static UnsafeCell<usize> = &D.a;
//~^ ERROR: cannot refer to interior mutable
const F: &'static C = &D;
//~^ ERROR: cannot refer to interior mutable
fn main() {}

View file

@ -1,21 +0,0 @@
error[E0492]: constants cannot refer to interior mutable data
--> $DIR/issue-17718-const-borrow.rs:4:39
|
LL | const B: &'static UnsafeCell<usize> = &A;
| ^^ this borrow of an interior mutable value may end up in the final value
error[E0492]: constants cannot refer to interior mutable data
--> $DIR/issue-17718-const-borrow.rs:9:39
|
LL | const E: &'static UnsafeCell<usize> = &D.a;
| ^^^^ this borrow of an interior mutable value may end up in the final value
error[E0492]: constants cannot refer to interior mutable data
--> $DIR/issue-17718-const-borrow.rs:11:23
|
LL | const F: &'static C = &D;
| ^^ this borrow of an interior mutable value may end up in the final value
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0492`.

View file

@ -1,8 +0,0 @@
#![warn(unused)]
#![deny(warnings)]
const foo: isize = 3;
//~^ ERROR: should have an upper case name
//~^^ ERROR: constant is never used
fn main() {}

View file

@ -1,28 +0,0 @@
error: constant is never used: `foo`
--> $DIR/issue-17718-const-naming.rs:4:1
|
LL | const foo: isize = 3;
| ^^^^^^^^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/issue-17718-const-naming.rs:2:9
|
LL | #![deny(warnings)]
| ^^^^^^^^
= note: `#[deny(dead_code)]` implied by `#[deny(warnings)]`
error: constant `foo` should have an upper case name
--> $DIR/issue-17718-const-naming.rs:4:7
|
LL | const foo: isize = 3;
| ^^^ help: convert the identifier to upper case (notice the capitalization): `FOO`
|
note: the lint level is defined here
--> $DIR/issue-17718-const-naming.rs:2:9
|
LL | #![deny(warnings)]
| ^^^^^^^^
= note: `#[deny(non_upper_case_globals)]` implied by `#[deny(warnings)]`
error: aborting due to 2 previous errors

View file

@ -1,36 +0,0 @@
// We need all these 9 issue-20616-N.rs files
// because we can only catch one parsing error at a time
type Type_1_<'a, T> = &'a T;
type Type_1<'a T> = &'a T; //~ error: expected one of `,`, `:`, or `>`, found `T`
//type Type_2 = Type_1_<'static ()>; // error: expected `,` or `>` after lifetime name, found `(`
//type Type_3<T> = Box<T,,>; // error: expected type, found `,`
//type Type_4<T> = Type_1_<'static,, T>; // error: expected type, found `,`
type Type_5_<'a> = Type_1_<'a, ()>;
//type Type_5<'a> = Type_1_<'a, (),,>; // error: expected type, found `,`
//type Type_6 = Type_5_<'a,,>; // error: expected type, found `,`
//type Type_7 = Box<(),,>; // error: expected type, found `,`
//type Type_8<'a,,> = &'a (); // error: expected ident, found `,`
//type Type_9<T,,> = Box<T>; // error: expected ident, found `,`

View file

@ -1,8 +0,0 @@
error: expected one of `,`, `:`, or `>`, found `T`
--> $DIR/issue-20616-1.rs:9:16
|
LL | type Type_1<'a T> = &'a T;
| ^ expected one of `,`, `:`, or `>`
error: aborting due to previous error

View file

@ -1,36 +0,0 @@
// We need all these 9 issue-20616-N.rs files
// because we can only catch one parsing error at a time
type Type_1_<'a, T> = &'a T;
//type Type_1<'a T> = &'a T; // error: expected `,` or `>` after lifetime name, found `T`
type Type_2 = Type_1_<'static ()>; //~ error: expected one of `,`, `:`, `=`, or `>`, found `(`
//type Type_3<T> = Box<T,,>; // error: expected type, found `,`
//type Type_4<T> = Type_1_<'static,, T>; // error: expected type, found `,`
type Type_5_<'a> = Type_1_<'a, ()>;
//type Type_5<'a> = Type_1_<'a, (),,>; // error: expected type, found `,`
//type Type_6 = Type_5_<'a,,>; // error: expected type, found `,`
//type Type_7 = Box<(),,>; // error: expected type, found `,`
//type Type_8<'a,,> = &'a (); // error: expected ident, found `,`
//type Type_9<T,,> = Box<T>; // error: expected ident, found `,`

View file

@ -1,8 +0,0 @@
error: expected one of `,`, `:`, `=`, or `>`, found `(`
--> $DIR/issue-20616-2.rs:12:31
|
LL | type Type_2 = Type_1_<'static ()>;
| ^ expected one of `,`, `:`, `=`, or `>`
error: aborting due to previous error

View file

@ -1,37 +0,0 @@
// We used to ICE when moving out of a `*mut T` or `*const T`.
struct T(u8);
static mut GLOBAL_MUT_T: T = T(0);
static GLOBAL_T: T = T(0);
fn imm_ref() -> &'static T {
unsafe { &GLOBAL_T }
}
fn mut_ref() -> &'static mut T {
unsafe { &mut GLOBAL_MUT_T }
}
fn mut_ptr() -> *mut T {
unsafe { core::ptr::null_mut() }
}
fn const_ptr() -> *const T {
unsafe { core::ptr::null() }
}
pub fn main() {
let a = unsafe { *mut_ref() };
//~^ ERROR cannot move out of a mutable reference
let b = unsafe { *imm_ref() };
//~^ ERROR cannot move out of a shared reference
let c = unsafe { *mut_ptr() };
//~^ ERROR cannot move out of a raw pointer
let d = unsafe { *const_ptr() };
//~^ ERROR cannot move out of a raw pointer
}

View file

@ -1,39 +0,0 @@
error[E0507]: cannot move out of a mutable reference
--> $DIR/issue-20801.rs:26:22
|
LL | let a = unsafe { *mut_ref() };
| ^^^^^^^^^^
| |
| move occurs because value has type `T`, which does not implement the `Copy` trait
| help: consider borrowing here: `&*mut_ref()`
error[E0507]: cannot move out of a shared reference
--> $DIR/issue-20801.rs:29:22
|
LL | let b = unsafe { *imm_ref() };
| ^^^^^^^^^^
| |
| move occurs because value has type `T`, which does not implement the `Copy` trait
| help: consider borrowing here: `&*imm_ref()`
error[E0507]: cannot move out of a raw pointer
--> $DIR/issue-20801.rs:32:22
|
LL | let c = unsafe { *mut_ptr() };
| ^^^^^^^^^^
| |
| move occurs because value has type `T`, which does not implement the `Copy` trait
| help: consider borrowing here: `&*mut_ptr()`
error[E0507]: cannot move out of a raw pointer
--> $DIR/issue-20801.rs:35:22
|
LL | let d = unsafe { *const_ptr() };
| ^^^^^^^^^^^^
| |
| move occurs because value has type `T`, which does not implement the `Copy` trait
| help: consider borrowing here: `&*const_ptr()`
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0507`.

View file

@ -1,3 +0,0 @@
// error-pattern: expected one of `!` or `::`, found `<eof>`
include!("auxiliary/issue-21146-inc.rs");
fn main() {}

View file

@ -1,8 +0,0 @@
error: expected one of `!` or `::`, found `<eof>`
--> $DIR/auxiliary/issue-21146-inc.rs:3:1
|
LL | parse_error
| ^^^^^^^^^^^ expected one of `!` or `::`
error: aborting due to previous error

View file

@ -1,19 +0,0 @@
// build-pass
#![allow(dead_code)]
#![allow(non_upper_case_globals)]
extern crate core;
use core::marker::Sync;
static SARRAY: [i32; 1] = [11];
struct MyStruct {
pub arr: *const [i32],
}
unsafe impl Sync for MyStruct {}
static mystruct: MyStruct = MyStruct {
arr: &SARRAY
};
fn main() {}

View file

@ -1,9 +0,0 @@
// run-pass
fn main() {
static NONE: Option<((), &'static u8)> = None;
let ptr = unsafe {
*(&NONE as *const _ as *const *const u8)
};
assert!(ptr.is_null());
}

View file

@ -1,52 +0,0 @@
// run-pass
#![allow(unused_variables)]
// Parsing patterns with paths with type parameters (issue #22544)
use std::default::Default;
#[derive(Default)]
pub struct Foo<T>(T, T);
impl<T: ::std::fmt::Display> Foo<T> {
fn foo(&self) {
match *self {
Foo::<T>(ref x, ref y) => println!("Goodbye, World! {} {}", x, y)
}
}
}
trait Tr {
type U;
}
impl<T> Tr for Foo<T> {
type U = T;
}
struct Wrapper<T> {
value: T
}
fn main() {
let Foo::<i32>(a, b) = Default::default();
let f = Foo(2,3);
f.foo();
let w = Wrapper { value: Foo(10u8, 11u8) };
match w {
Wrapper::<Foo<u8>> { value: Foo(10, 11) } => {},
::Wrapper::<<Foo<_> as Tr>::U> { value: Foo::<u8>(11, 16) } => { panic!() },
_ => { panic!() }
}
if let None::<u8> = Some(8) {
panic!();
}
if let None::<u8> { .. } = Some(8) {
panic!();
}
if let Option::None::<u8> { .. } = Some(8) {
panic!();
}
}

View file

@ -1,19 +0,0 @@
// check-pass
#![allow(dead_code)]
// Regression test for #24085. Errors were occurring in region
// inference due to the requirement that `'a:b'`, which was getting
// incorrectly codegened in connection with the closure below.
#[derive(Copy,Clone)]
struct Path<'a:'b, 'b> {
x: &'a i32,
tail: Option<&'b Path<'a, 'b>>
}
#[allow(dead_code, unconditional_recursion)]
fn foo<'a,'b,F>(p: Path<'a, 'b>, mut f: F)
where F: for<'c> FnMut(Path<'a, 'c>) {
foo(p, |x| f(x))
}
fn main() { }

View file

@ -1,19 +0,0 @@
// Ensure that we reject code when a nonlocal exit (`break`,
// `continue`) causes us to pop over a needed assignment.
pub fn main() {
foo1();
foo2();
}
pub fn foo1() {
let x: i32;
loop { x = break; }
println!("{}", x); //~ ERROR borrow of possibly-uninitialized variable: `x`
}
pub fn foo2() {
let x: i32;
for _ in 0..10 { x = continue; }
println!("{}", x); //~ ERROR borrow of possibly-uninitialized variable: `x`
}

View file

@ -1,15 +0,0 @@
error[E0381]: borrow of possibly-uninitialized variable: `x`
--> $DIR/issue-24267-flow-exit.rs:12:20
|
LL | println!("{}", x);
| ^ use of possibly-uninitialized `x`
error[E0381]: borrow of possibly-uninitialized variable: `x`
--> $DIR/issue-24267-flow-exit.rs:18:20
|
LL | println!("{}", x);
| ^ use of possibly-uninitialized `x`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0381`.

View file

@ -1,21 +0,0 @@
//
// check-pass
trait DictLike<'a> {
type ItemsIterator: Iterator<Item=u8>;
fn get(c: Self::ItemsIterator) {
c.into_iter();
}
}
trait DictLike2<'a> {
type ItemsIterator: Iterator<Item=u8>;
fn items(&self) -> Self::ItemsIterator;
fn get(&self) {
for _ in self.items() {}
}
}
fn main() {}

View file

@ -1,26 +0,0 @@
#![feature(rustc_attrs)]
macro_rules! width(
($this:expr) => {
$this.width.unwrap()
//~^ ERROR cannot use `self.width` because it was mutably borrowed
}
);
struct HasInfo {
width: Option<usize>
}
impl HasInfo {
fn get_size(&mut self, n: usize) -> usize {
n
}
fn get_other(&mut self) -> usize {
let r = &mut *self;
r.get_size(width!(self))
}
// Above is like `self.get_size(width!(self))`, but it
// deliberately avoids NLL's two phase borrow feature.
}
fn main() { }

View file

@ -1,18 +0,0 @@
error[E0503]: cannot use `self.width` because it was mutably borrowed
--> $DIR/issue-25793.rs:4:9
|
LL | $this.width.unwrap()
| ^^^^^^^^^^^ use of borrowed `*self`
...
LL | let r = &mut *self;
| ---------- borrow of `*self` occurs here
LL | r.get_size(width!(self))
| -------- ------------ in this macro invocation
| |
| borrow later used by call
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error
For more information about this error, try `rustc --explain E0503`.

View file

@ -1,28 +0,0 @@
// run-pass
#![allow(unused_must_use)]
fn main() {
macro_rules! f {
() => { 0 + 0 }
}
// 16 per line
f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();
f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();
f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();
f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();
f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();
f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();
f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();
f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();
f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();
f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();
f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();
f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();
f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();
f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();
f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();
f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();f!();
}

View file

@ -1,30 +0,0 @@
// run-pass
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
macro_rules! columnline {
() => (
(column!(), line!())
)
}
macro_rules! indirectcolumnline {
() => (
(||{ columnline!() })()
)
}
fn main() {
let closure = || {
columnline!()
};
let iflet = if let Some(_) = Some(0) {
columnline!()
} else { (0, 0) };
let cl = columnline!();
assert_eq!(closure(), (9, 19));
assert_eq!(iflet, (9, 22));
assert_eq!(cl, (14, 24));
let indirect = indirectcolumnline!();
assert_eq!(indirect, (20, 28));
}

View file

@ -1,25 +0,0 @@
// run-pass
#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(non_snake_case)]
mod A {
pub mod B {
use super::*;
pub struct S;
}
pub mod C {
use super::*;
use super::B::S;
pub struct T;
}
pub use self::C::T;
}
use A::*;
fn main() {}

View file

@ -1,327 +0,0 @@
// run-pass
#![allow(dead_code)]
#![allow(unused_unsafe)]
#![allow(unused_imports)]
#![allow(non_camel_case_types)]
pub type Task = isize;
// tjc: I don't know why
pub mod pipes {
use self::state::{empty, full, blocked, terminated};
use super::Task;
use std::mem::{forget, transmute};
use std::mem::{replace, swap};
use std::mem;
use std::thread;
use std::marker::Send;
pub struct Stuff<T> {
state: state,
blocked_task: Option<Task>,
payload: Option<T>
}
#[derive(PartialEq, Debug)]
#[repr(isize)]
pub enum state {
empty,
full,
blocked,
terminated
}
pub struct packet<T> {
state: state,
blocked_task: Option<Task>,
payload: Option<T>
}
unsafe impl<T:Send> Send for packet<T> {}
pub fn packet<T:Send>() -> *const packet<T> {
unsafe {
let p: *const packet<T> = mem::transmute(Box::new(Stuff{
state: empty,
blocked_task: None::<Task>,
payload: None::<T>
}));
p
}
}
mod rusti {
pub fn atomic_xchg(_dst: &mut isize, _src: isize) -> isize { panic!(); }
pub fn atomic_xchg_acq(_dst: &mut isize, _src: isize) -> isize { panic!(); }
pub fn atomic_xchg_rel(_dst: &mut isize, _src: isize) -> isize { panic!(); }
}
// We should consider moving this to ::std::unsafe, although I
// suspect graydon would want us to use void pointers instead.
pub unsafe fn uniquify<T>(x: *const T) -> Box<T> {
mem::transmute(x)
}
pub fn swap_state_acq(dst: &mut state, src: state) -> state {
unsafe {
transmute(rusti::atomic_xchg_acq(transmute(dst), src as isize))
}
}
pub fn swap_state_rel(dst: &mut state, src: state) -> state {
unsafe {
transmute(rusti::atomic_xchg_rel(transmute(dst), src as isize))
}
}
pub fn send<T:Send>(mut p: send_packet<T>, payload: T) {
let p = p.unwrap();
let mut p = unsafe { uniquify(p) };
assert!((*p).payload.is_none());
(*p).payload = Some(payload);
let old_state = swap_state_rel(&mut (*p).state, full);
match old_state {
empty => {
// Yay, fastpath.
// The receiver will eventually clean this up.
unsafe { forget(p); }
}
full => { panic!("duplicate send") }
blocked => {
// The receiver will eventually clean this up.
unsafe { forget(p); }
}
terminated => {
// The receiver will never receive this. Rely on drop_glue
// to clean everything up.
}
}
}
pub fn recv<T:Send>(mut p: recv_packet<T>) -> Option<T> {
let p = p.unwrap();
let mut p = unsafe { uniquify(p) };
loop {
let old_state = swap_state_acq(&mut (*p).state,
blocked);
match old_state {
empty | blocked => { thread::yield_now(); }
full => {
let payload = replace(&mut p.payload, None);
return Some(payload.unwrap())
}
terminated => {
assert_eq!(old_state, terminated);
return None;
}
}
}
}
pub fn sender_terminate<T:Send>(p: *const packet<T>) {
let mut p = unsafe { uniquify(p) };
match swap_state_rel(&mut (*p).state, terminated) {
empty | blocked => {
// The receiver will eventually clean up.
unsafe { forget(p) }
}
full => {
// This is impossible
panic!("you dun goofed")
}
terminated => {
// I have to clean up, use drop_glue
}
}
}
pub fn receiver_terminate<T:Send>(p: *const packet<T>) {
let mut p = unsafe { uniquify(p) };
match swap_state_rel(&mut (*p).state, terminated) {
empty => {
// the sender will clean up
unsafe { forget(p) }
}
blocked => {
// this shouldn't happen.
panic!("terminating a blocked packet")
}
terminated | full => {
// I have to clean up, use drop_glue
}
}
}
pub struct send_packet<T:Send> {
p: Option<*const packet<T>>,
}
impl<T:Send> Drop for send_packet<T> {
fn drop(&mut self) {
unsafe {
if self.p != None {
let self_p: &mut Option<*const packet<T>> =
mem::transmute(&mut self.p);
let p = replace(self_p, None);
sender_terminate(p.unwrap())
}
}
}
}
impl<T:Send> send_packet<T> {
pub fn unwrap(&mut self) -> *const packet<T> {
replace(&mut self.p, None).unwrap()
}
}
pub fn send_packet<T:Send>(p: *const packet<T>) -> send_packet<T> {
send_packet {
p: Some(p)
}
}
pub struct recv_packet<T:Send> {
p: Option<*const packet<T>>,
}
impl<T:Send> Drop for recv_packet<T> {
fn drop(&mut self) {
unsafe {
if self.p != None {
let self_p: &mut Option<*const packet<T>> =
mem::transmute(&mut self.p);
let p = replace(self_p, None);
receiver_terminate(p.unwrap())
}
}
}
}
impl<T:Send> recv_packet<T> {
pub fn unwrap(&mut self) -> *const packet<T> {
replace(&mut self.p, None).unwrap()
}
}
pub fn recv_packet<T:Send>(p: *const packet<T>) -> recv_packet<T> {
recv_packet {
p: Some(p)
}
}
pub fn entangle<T:Send>() -> (send_packet<T>, recv_packet<T>) {
let p = packet();
(send_packet(p), recv_packet(p))
}
}
pub mod pingpong {
use std::mem;
pub struct ping(::pipes::send_packet<pong>);
unsafe impl Send for ping {}
pub struct pong(::pipes::send_packet<ping>);
unsafe impl Send for pong {}
pub fn liberate_ping(p: ping) -> ::pipes::send_packet<pong> {
unsafe {
let _addr : *const ::pipes::send_packet<pong> = match &p {
&ping(ref x) => { mem::transmute(x) }
};
panic!()
}
}
pub fn liberate_pong(p: pong) -> ::pipes::send_packet<ping> {
unsafe {
let _addr : *const ::pipes::send_packet<ping> = match &p {
&pong(ref x) => { mem::transmute(x) }
};
panic!()
}
}
pub fn init() -> (client::ping, server::ping) {
::pipes::entangle()
}
pub mod client {
use pingpong;
pub type ping = ::pipes::send_packet<pingpong::ping>;
pub type pong = ::pipes::recv_packet<pingpong::pong>;
pub fn do_ping(c: ping) -> pong {
let (sp, rp) = ::pipes::entangle();
::pipes::send(c, pingpong::ping(sp));
rp
}
pub fn do_pong(c: pong) -> (ping, ()) {
let packet = ::pipes::recv(c);
if packet.is_none() {
panic!("sender closed the connection")
}
(pingpong::liberate_pong(packet.unwrap()), ())
}
}
pub mod server {
use pingpong;
pub type ping = ::pipes::recv_packet<pingpong::ping>;
pub type pong = ::pipes::send_packet<pingpong::pong>;
pub fn do_ping(c: ping) -> (pong, ()) {
let packet = ::pipes::recv(c);
if packet.is_none() {
panic!("sender closed the connection")
}
(pingpong::liberate_ping(packet.unwrap()), ())
}
pub fn do_pong(c: pong) -> ping {
let (sp, rp) = ::pipes::entangle();
::pipes::send(c, pingpong::pong(sp));
rp
}
}
}
fn client(chan: pingpong::client::ping) {
let chan = pingpong::client::do_ping(chan);
println!("Sent ping");
let (_chan, _data) = pingpong::client::do_pong(chan);
println!("Received pong");
}
fn server(chan: pingpong::server::ping) {
let (chan, _data) = pingpong::server::do_ping(chan);
println!("Received ping");
let _chan = pingpong::server::do_pong(chan);
println!("Sent pong");
}
pub fn main() {
/*
// Commented out because of option::get error
let (client_, server_) = pingpong::init();
task::spawn {|client_|
let client__ = client_.take();
client(client__);
};
task::spawn {|server_|
let server__ = server_.take();
server(server_ˊ);
};
*/
}

View file

@ -1,20 +0,0 @@
// Issue 27282: Example 2: This sidesteps the AST checks disallowing
// mutable borrows in match guards by hiding the mutable borrow in a
// guard behind a move (of the mutably borrowed match input) within a
// closure.
//
// This example is not rejected by AST borrowck (and then reliably
// reaches the panic code when executed, despite the compiler warning
// about that match arm being unreachable.
fn main() {
let b = &mut true;
match b {
&mut false => {},
_ if { (|| { let bar = b; *bar = false; })();
false } => { },
&mut true => { println!("You might think we should get here"); },
//~^ ERROR use of moved value: `b` [E0382]
_ => panic!("surely we could never get here, since rustc warns it is unreachable."),
}
}

View file

@ -1,17 +0,0 @@
error[E0382]: use of moved value: `b`
--> $DIR/issue-27282-move-match-input-into-guard.rs:16:14
|
LL | let b = &mut true;
| - move occurs because `b` has type `&mut bool`, which does not implement the `Copy` trait
...
LL | _ if { (|| { let bar = b; *bar = false; })();
| -- - variable moved due to use in closure
| |
| value moved into closure here
LL | false } => { },
LL | &mut true => { println!("You might think we should get here"); },
| ^^^^ value used here after move
error: aborting due to previous error
For more information about this error, try `rustc --explain E0382`.

View file

@ -1,40 +0,0 @@
// This is testing an attempt to corrupt the discriminant of the match
// arm in a guard, followed by an attempt to continue matching on that
// corrupted discriminant in the remaining match arms.
//
// Basically this is testing that our new NLL feature of emitting a
// fake read on each match arm is catching cases like this.
//
// This case is interesting because it includes a guard that
// diverges, and therefore a single final fake-read at the very end
// after the final match arm would not suffice.
//
// It is also interesting because the access to the corrupted data
// occurs in the pattern-match itself, and not in the guard
// expression.
struct ForceFnOnce;
fn main() {
let mut x = &mut Some(&2);
let force_fn_once = ForceFnOnce;
match x {
&mut None => panic!("unreachable"),
&mut Some(&_)
if {
// ForceFnOnce needed to exploit #27282
(|| { *x = None; drop(force_fn_once); })();
//~^ ERROR cannot mutably borrow `x` in match guard [E0510]
false
} => {}
// this segfaults if we corrupted the discriminant, because
// the compiler gets to *assume* that it cannot be the `None`
// case, even though that was the effect of the guard.
&mut Some(&2)
if {
panic!()
} => {}
_ => panic!("unreachable"),
}
}

View file

@ -1,14 +0,0 @@
error[E0510]: cannot mutably borrow `x` in match guard
--> $DIR/issue-27282-mutate-before-diverging-arm-2.rs:26:18
|
LL | match x {
| - value is immutable in match guard
...
LL | (|| { *x = None; drop(force_fn_once); })();
| ^^ - borrow occurs due to use of `x` in closure
| |
| cannot mutably borrow
error: aborting due to previous error
For more information about this error, try `rustc --explain E0510`.

View file

@ -1,18 +0,0 @@
// Issue 27282: This is a variation on issue-27282-move-ref-mut-into-guard.rs
//
// It reborrows instead of moving the `ref mut` pattern borrow. This
// means that our conservative check for mutation in guards will
// reject it. But I want to make sure that we continue to reject it
// (under NLL) even when that conservaive check goes away.
fn main() {
let mut b = &mut true;
match b {
&mut false => {},
ref mut r if { (|| { let bar = &mut *r; **bar = false; })();
//~^ ERROR cannot borrow `r` as mutable, as it is immutable for the pattern guard
false } => { &mut *r; },
&mut true => { println!("You might think we should get here"); },
_ => panic!("surely we could never get here, since rustc warns it is unreachable."),
}
}

View file

@ -1,13 +0,0 @@
error[E0596]: cannot borrow `r` as mutable, as it is immutable for the pattern guard
--> $DIR/issue-27282-reborrow-ref-mut-in-guard.rs:12:25
|
LL | ref mut r if { (|| { let bar = &mut *r; **bar = false; })();
| ^^ - mutable borrow occurs due to use of `r` in closure
| |
| cannot borrow as mutable
|
= note: variables bound in patterns are immutable until the end of the pattern guard
error: aborting due to previous error
For more information about this error, try `rustc --explain E0596`.

View file

@ -1,7 +0,0 @@
// run-pass
static PLUS_ONE: &'static (dyn Fn(i32) -> i32 + Sync) = (&|x: i32| { x + 1 })
as &'static (dyn Fn(i32) -> i32 + Sync);
fn main() {
assert_eq!(PLUS_ONE(2), 3);
}

View file

@ -1,8 +0,0 @@
#![allow(warnings)]
const X: u8 =
|| -> u8 { 5 }()
//~^ ERROR calls in constants are limited to constant functions
;
fn main() {}

View file

@ -1,9 +0,0 @@
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
--> $DIR/issue-28113.rs:4:5
|
LL | || -> u8 { 5 }()
| ^^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0015`.

View file

@ -1,38 +0,0 @@
// run-pass
// Demonstrate the use of the unguarded escape hatch with a lifetime param
// to assert that destructor will not access any dead data.
//
// Compare with ui/span/issue28498-reject-lifetime-param.rs
#![feature(dropck_eyepatch)]
#[derive(Debug)]
struct ScribbleOnDrop(String);
impl Drop for ScribbleOnDrop {
fn drop(&mut self) {
self.0 = format!("DROPPED");
}
}
struct Foo<'a>(u32, &'a ScribbleOnDrop);
unsafe impl<#[may_dangle] 'a> Drop for Foo<'a> {
fn drop(&mut self) {
// Use of `may_dangle` is sound, because destructor never accesses `self.1`.
println!("Dropping Foo({}, _)", self.0);
}
}
fn main() {
let (last_dropped, foo0);
let (foo1, first_dropped);
last_dropped = ScribbleOnDrop(format!("last"));
first_dropped = ScribbleOnDrop(format!("first"));
foo0 = Foo(0, &last_dropped);
foo1 = Foo(1, &first_dropped);
println!("foo0.1: {:?} foo1.1: {:?}", foo0.1, foo1.1);
}

View file

@ -1,41 +0,0 @@
// run-pass
// Demonstrate the use of the unguarded escape hatch with a trait bound
// to assert that destructor will not access any dead data.
//
// Compare with ui/span/issue28498-reject-trait-bound.rs
#![feature(dropck_eyepatch)]
use std::fmt;
#[derive(Debug)]
struct ScribbleOnDrop(String);
impl Drop for ScribbleOnDrop {
fn drop(&mut self) {
self.0 = format!("DROPPED");
}
}
struct Foo<T: fmt::Debug>(u32, T);
unsafe impl<#[may_dangle] T: fmt::Debug> Drop for Foo<T> {
fn drop(&mut self) {
// Use of `may_dangle` is sound, because destructor never accesses
// the `Debug::fmt` method of `T`, despite having it available.
println!("Dropping Foo({}, _)", self.0);
}
}
fn main() {
let (last_dropped, foo0);
let (foo1, first_dropped);
last_dropped = ScribbleOnDrop(format!("last"));
first_dropped = ScribbleOnDrop(format!("first"));
foo0 = Foo(0, &last_dropped);
foo1 = Foo(1, &first_dropped);
println!("foo0.1: {:?} foo1.1: {:?}", foo0.1, foo1.1);
}

View file

@ -1,40 +0,0 @@
// run-pass
#![allow(dead_code)]
#![allow(improper_ctypes)]
// ignore-wasm32-bare no libc to test ffi with
#[derive(Copy, Clone)]
pub struct Quad {
a: u64,
b: u64,
c: u64,
d: u64,
}
mod rustrt {
use super::Quad;
#[link(name = "rust_test_helpers", kind = "static")]
extern "C" {
pub fn get_c_many_params(
_: *const (),
_: *const (),
_: *const (),
_: *const (),
f: Quad,
) -> u64;
}
}
fn test() {
unsafe {
let null = std::ptr::null();
let q = Quad { a: 1, b: 2, c: 3, d: 4 };
assert_eq!(rustrt::get_c_many_params(null, null, null, null, q), q.c);
}
}
pub fn main() {
test();
}

View file

@ -1,35 +0,0 @@
struct A;
fn main() {
let a = A;
a + a; //~ ERROR cannot add `A` to `A`
a - a; //~ ERROR cannot subtract `A` from `A`
a * a; //~ ERROR cannot multiply `A` by `A`
a / a; //~ ERROR cannot divide `A` by `A`
a % a; //~ ERROR cannot mod `A` by `A`
a & a; //~ ERROR no implementation for `A & A`
a | a; //~ ERROR no implementation for `A | A`
a << a; //~ ERROR no implementation for `A << A`
a >> a; //~ ERROR no implementation for `A >> A`
a == a; //~ ERROR binary operation `==` cannot be applied to type `A`
a != a; //~ ERROR binary operation `!=` cannot be applied to type `A`
a < a; //~ ERROR binary operation `<` cannot be applied to type `A`
a <= a; //~ ERROR binary operation `<=` cannot be applied to type `A`
a > a; //~ ERROR binary operation `>` cannot be applied to type `A`
a >= a; //~ ERROR binary operation `>=` cannot be applied to type `A`
}

View file

@ -1,153 +0,0 @@
error[E0369]: cannot add `A` to `A`
--> $DIR/issue-28837.rs:6:7
|
LL | a + a;
| - ^ - A
| |
| A
|
= note: an implementation of `std::ops::Add` might be missing for `A`
error[E0369]: cannot subtract `A` from `A`
--> $DIR/issue-28837.rs:8:7
|
LL | a - a;
| - ^ - A
| |
| A
|
= note: an implementation of `std::ops::Sub` might be missing for `A`
error[E0369]: cannot multiply `A` by `A`
--> $DIR/issue-28837.rs:10:7
|
LL | a * a;
| - ^ - A
| |
| A
|
= note: an implementation of `std::ops::Mul` might be missing for `A`
error[E0369]: cannot divide `A` by `A`
--> $DIR/issue-28837.rs:12:7
|
LL | a / a;
| - ^ - A
| |
| A
|
= note: an implementation of `std::ops::Div` might be missing for `A`
error[E0369]: cannot mod `A` by `A`
--> $DIR/issue-28837.rs:14:7
|
LL | a % a;
| - ^ - A
| |
| A
|
= note: an implementation of `std::ops::Rem` might be missing for `A`
error[E0369]: no implementation for `A & A`
--> $DIR/issue-28837.rs:16:7
|
LL | a & a;
| - ^ - A
| |
| A
|
= note: an implementation of `std::ops::BitAnd` might be missing for `A`
error[E0369]: no implementation for `A | A`
--> $DIR/issue-28837.rs:18:7
|
LL | a | a;
| - ^ - A
| |
| A
|
= note: an implementation of `std::ops::BitOr` might be missing for `A`
error[E0369]: no implementation for `A << A`
--> $DIR/issue-28837.rs:20:7
|
LL | a << a;
| - ^^ - A
| |
| A
|
= note: an implementation of `std::ops::Shl` might be missing for `A`
error[E0369]: no implementation for `A >> A`
--> $DIR/issue-28837.rs:22:7
|
LL | a >> a;
| - ^^ - A
| |
| A
|
= note: an implementation of `std::ops::Shr` might be missing for `A`
error[E0369]: binary operation `==` cannot be applied to type `A`
--> $DIR/issue-28837.rs:24:7
|
LL | a == a;
| - ^^ - A
| |
| A
|
= note: an implementation of `std::cmp::PartialEq` might be missing for `A`
error[E0369]: binary operation `!=` cannot be applied to type `A`
--> $DIR/issue-28837.rs:26:7
|
LL | a != a;
| - ^^ - A
| |
| A
|
= note: an implementation of `std::cmp::PartialEq` might be missing for `A`
error[E0369]: binary operation `<` cannot be applied to type `A`
--> $DIR/issue-28837.rs:28:7
|
LL | a < a;
| - ^ - A
| |
| A
|
= note: an implementation of `std::cmp::PartialOrd` might be missing for `A`
error[E0369]: binary operation `<=` cannot be applied to type `A`
--> $DIR/issue-28837.rs:30:7
|
LL | a <= a;
| - ^^ - A
| |
| A
|
= note: an implementation of `std::cmp::PartialOrd` might be missing for `A`
error[E0369]: binary operation `>` cannot be applied to type `A`
--> $DIR/issue-28837.rs:32:7
|
LL | a > a;
| - ^ - A
| |
| A
|
= note: an implementation of `std::cmp::PartialOrd` might be missing for `A`
error[E0369]: binary operation `>=` cannot be applied to type `A`
--> $DIR/issue-28837.rs:34:7
|
LL | a >= a;
| - ^^ - A
| |
| A
|
= note: an implementation of `std::cmp::PartialOrd` might be missing for `A`
error: aborting due to 15 previous errors
For more information about this error, try `rustc --explain E0369`.

View file

@ -1,14 +0,0 @@
error: lifetime may not live long enough
--> $DIR/issue-28848.rs:10:5
|
LL | pub fn foo<'a, 'b>(u: &'b ()) -> &'a () {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
LL | Foo::<'a, 'b>::xmute(u)
| ^^^^^^^^^^^^^^^^^^^^ requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'b: 'a`
error: aborting due to previous error

View file

@ -1,13 +0,0 @@
struct Foo<'a, 'b: 'a>(&'a &'b ());
impl<'a, 'b> Foo<'a, 'b> {
fn xmute(a: &'b ()) -> &'a () {
unreachable!()
}
}
pub fn foo<'a, 'b>(u: &'b ()) -> &'a () {
Foo::<'a, 'b>::xmute(u) //~ ERROR lifetime bound not satisfied
}
fn main() {}

View file

@ -1,20 +0,0 @@
error[E0478]: lifetime bound not satisfied
--> $DIR/issue-28848.rs:10:5
|
LL | Foo::<'a, 'b>::xmute(u)
| ^^^^^^^^^^^^^^^^^^^^
|
note: lifetime parameter instantiated with the lifetime `'b` as defined on the function body at 9:16
--> $DIR/issue-28848.rs:9:16
|
LL | pub fn foo<'a, 'b>(u: &'b ()) -> &'a () {
| ^^
note: but lifetime parameter must outlive the lifetime `'a` as defined on the function body at 9:12
--> $DIR/issue-28848.rs:9:12
|
LL | pub fn foo<'a, 'b>(u: &'b ()) -> &'a () {
| ^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0478`.

View file

@ -1,15 +0,0 @@
mod a {
struct A;
impl Default for A {
pub fn default() -> A { //~ ERROR unnecessary visibility qualifier
A
}
}
}
fn main() {
a::A::default();
//~^ ERROR struct `A` is private
}

View file

@ -1,22 +0,0 @@
error[E0449]: unnecessary visibility qualifier
--> $DIR/issue-29161.rs:5:9
|
LL | pub fn default() -> A {
| ^^^ `pub` not permitted here because it's implied
error[E0603]: struct `A` is private
--> $DIR/issue-29161.rs:13:8
|
LL | a::A::default();
| ^ private struct
|
note: the struct `A` is defined here
--> $DIR/issue-29161.rs:2:5
|
LL | struct A;
| ^^^^^^^^^
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0449, E0603.
For more information about an error, try `rustc --explain E0449`.

View file

@ -1,31 +0,0 @@
// run-pass
#![allow(non_camel_case_types)]
trait bar<T> {
fn get_bar(&self) -> T;
}
fn foo<T, U: bar<T>>(b: U) -> T {
b.get_bar()
}
struct cbar {
x: isize,
}
impl bar<isize> for cbar {
fn get_bar(&self) -> isize {
self.x
}
}
fn cbar(x: isize) -> cbar {
cbar {
x: x
}
}
pub fn main() {
let x: isize = foo::<isize, cbar>(cbar(5));
assert_eq!(x, 5);
}

View file

@ -1,24 +0,0 @@
// run-pass
use std::sync::Arc;
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(Arc<R::DescriptorSet>)
}
fn main() {
let _x = DescriptorSet {slots: Vec::new()};
}

View file

@ -1,6 +0,0 @@
// run-pass
const ARR: [usize; 5] = [5, 4, 3, 2, 1];
fn main() {
assert_eq!(3, ARR[ARR[3]]);
}

View file

@ -1,7 +0,0 @@
// run-pass
const ARR: [usize; 5] = [5, 4, 3, 2, 1];
const BLA: usize = ARR[ARR[3]];
fn main() {
assert_eq!(3, BLA);
}

View file

@ -1,10 +0,0 @@
// run-pass
#![allow(stable_features)]
#![feature(const_indexing)]
const ARR: [usize; 5] = [5, 4, 3, 2, 1];
fn main() {
assert_eq!(3, ARR[ARR[3]]);
}

View file

@ -1,11 +0,0 @@
// run-pass
#![allow(dead_code)]
const fn f() -> usize {
5
}
struct A {
field: usize,
}
fn main() {
let _ = [0; f()];
}

View file

@ -1,11 +0,0 @@
// run-pass
#![allow(dead_code)]
struct A {
field: usize,
}
const fn f() -> usize {
5
}
fn main() {
let _ = [0; f()];
}

View file

@ -1,103 +0,0 @@
// run-pass
#![allow(unreachable_code)]
// More thorough regression test for Issues #30018 and #30822. This
// attempts to explore different ways that array element construction
// (for both scratch arrays and non-scratch ones) interacts with
// breaks in the control-flow, in terms of the order of evaluation of
// the destructors (which may change; see RFC Issue 744) and the
// number of times that the destructor evaluates for each value (which
// should never exceed 1; this latter case is what #30822 is about).
use std::cell::RefCell;
struct D<'a>(&'a RefCell<Vec<i32>>, i32);
impl<'a> Drop for D<'a> {
fn drop(&mut self) {
println!("Dropping D({})", self.1);
(self.0).borrow_mut().push(self.1);
}
}
fn main() {
println!("Start");
break_during_elem();
break_after_whole();
println!("Finis");
}
fn break_during_elem() {
let log = &RefCell::new(Vec::new());
// CASE 1: Fixed-size array itself is stored in _r slot.
loop {
let _r = [D(log, 10),
D(log, 11),
{ D(log, 12); break; },
D(log, 13)];
}
assert_eq!(&log.borrow()[..], &[12, 11, 10]);
log.borrow_mut().clear();
// CASE 2: Slice (borrow of array) is stored in _r slot.
// This is the case that is actually being reported in #30018.
loop {
let _r = &[D(log, 20),
D(log, 21),
{ D(log, 22); break; },
D(log, 23)];
}
assert_eq!(&log.borrow()[..], &[22, 21, 20]);
log.borrow_mut().clear();
// CASE 3: (Borrow of) slice-index of array is stored in _r slot.
loop {
let _r = &[D(log, 30),
D(log, 31),
{ D(log, 32); break; },
D(log, 33)][..];
}
assert_eq!(&log.borrow()[..], &[32, 31, 30]);
log.borrow_mut().clear();
}
// The purpose of these functions is to test what happens when we
// panic after an array has been constructed in its entirety.
//
// It is meant to act as proof that we still need to continue
// scheduling the destruction of an array even after we've scheduling
// drop for its elements during construction; the latter is tested by
// `fn break_during_elem()`.
fn break_after_whole() {
let log = &RefCell::new(Vec::new());
// CASE 1: Fixed-size array itself is stored in _r slot.
loop {
let _r = [D(log, 10),
D(log, 11),
D(log, 12)];
break;
}
assert_eq!(&log.borrow()[..], &[10, 11, 12]);
log.borrow_mut().clear();
// CASE 2: Slice (borrow of array) is stored in _r slot.
loop {
let _r = &[D(log, 20),
D(log, 21),
D(log, 22)];
break;
}
assert_eq!(&log.borrow()[..], &[20, 21, 22]);
log.borrow_mut().clear();
// CASE 3: (Borrow of) slice-index of array is stored in _r slot.
loop {
let _r = &[D(log, 30),
D(log, 31),
D(log, 32)][..];
break;
}
assert_eq!(&log.borrow()[..], &[30, 31, 32]);
log.borrow_mut().clear();
}

View file

@ -1,39 +0,0 @@
struct SemiPriv;
mod m1 {
struct Priv;
impl ::SemiPriv {
pub fn f(_: Priv) {} //~ WARN private type `m1::Priv` in public interface
//~^ WARNING hard error
}
impl Priv {
pub fn f(_: Priv) {} // ok
}
}
mod m2 {
struct Priv;
impl ::std::ops::Deref for ::SemiPriv {
type Target = Priv; //~ ERROR private type `m2::Priv` in public interface
fn deref(&self) -> &Self::Target { unimplemented!() }
}
impl ::std::ops::Deref for Priv {
type Target = Priv; // ok
fn deref(&self) -> &Self::Target { unimplemented!() }
}
}
trait SemiPrivTrait {
type Assoc;
}
mod m3 {
struct Priv;
impl ::SemiPrivTrait for () {
type Assoc = Priv; //~ ERROR private type `m3::Priv` in public interface
}
}
fn main() {}

View file

@ -1,31 +0,0 @@
warning: private type `m1::Priv` in public interface (error E0446)
--> $DIR/issue-30079.rs:6:9
|
LL | pub fn f(_: Priv) {}
| ^^^^^^^^^^^^^^^^^
|
= note: `#[warn(private_in_public)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
error[E0446]: private type `m2::Priv` in public interface
--> $DIR/issue-30079.rs:18:9
|
LL | struct Priv;
| ------------ `m2::Priv` declared as private
LL | impl ::std::ops::Deref for ::SemiPriv {
LL | type Target = Priv;
| ^^^^^^^^^^^^^^^^^^^ can't leak private type
error[E0446]: private type `m3::Priv` in public interface
--> $DIR/issue-30079.rs:35:9
|
LL | struct Priv;
| ------------ `m3::Priv` declared as private
LL | impl ::SemiPrivTrait for () {
LL | type Assoc = Priv;
| ^^^^^^^^^^^^^^^^^^ can't leak private type
error: aborting due to 2 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0446`.

View file

@ -1,20 +0,0 @@
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
#![deny(unreachable_patterns)]
enum Stack<T> {
Nil,
Cons(T, Box<Stack<T>>)
}
fn is_empty<T>(s: Stack<T>) -> bool {
match s {
Nil => true,
//~^ WARN pattern binding `Nil` is named the same as one of the variants of the type `Stack`
_ => false
//~^ ERROR unreachable pattern
}
}
fn main() {}

View file

@ -1,26 +0,0 @@
warning[E0170]: pattern binding `Nil` is named the same as one of the variants of the type `Stack`
--> $DIR/issue-30302.rs:13:9
|
LL | Nil => true,
| ^^^ help: to match on the variant, qualify the path: `Stack::Nil`
|
= note: `#[warn(bindings_with_variant_name)]` on by default
error: unreachable pattern
--> $DIR/issue-30302.rs:15:9
|
LL | Nil => true,
| --- matches any value
LL |
LL | _ => false
| ^ unreachable pattern
|
note: the lint level is defined here
--> $DIR/issue-30302.rs:4:9
|
LL | #![deny(unreachable_patterns)]
| ^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0170`.

View file

@ -1,17 +0,0 @@
// check-pass
pub type T = ();
mod foo { pub use super::T; }
mod bar { pub use super::T; }
pub use foo::*;
pub use bar::*;
mod baz {
pub type T = ();
mod foo { pub use super::T as S; }
mod bar { pub use super::foo::S as T; }
pub use self::bar::*;
}
fn main() {}

View file

@ -1,22 +0,0 @@
// check-pass
mod foo {
pub fn bar() {}
}
pub use foo::*;
use b::bar;
mod foobar {
use super::*;
}
mod a {
pub mod bar {}
}
mod b {
pub use a::bar;
}
fn main() {}

View file

@ -1,73 +0,0 @@
// ignore-tidy-linelength
const bad : u32 = {
{
5;
0
}
};
const bad_two : u32 = {
{
invalid();
//~^ ERROR: calls in constants are limited to constant functions, tuple structs and tuple variants
0
}
};
const bad_three : u32 = {
{
valid();
0
}
};
static bad_four : u32 = {
{
5;
0
}
};
static bad_five : u32 = {
{
invalid();
//~^ ERROR: calls in statics are limited to constant functions, tuple structs and tuple variants
0
}
};
static bad_six : u32 = {
{
valid();
0
}
};
static mut bad_seven : u32 = {
{
5;
0
}
};
static mut bad_eight : u32 = {
{
invalid();
//~^ ERROR: calls in statics are limited to constant functions, tuple structs and tuple variants
0
}
};
static mut bad_nine : u32 = {
{
valid();
0
}
};
fn invalid() {}
const fn valid() {}
fn main() {}

View file

@ -1,21 +0,0 @@
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
--> $DIR/issue-32829-2.rs:12:9
|
LL | invalid();
| ^^^^^^^^^
error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants
--> $DIR/issue-32829-2.rs:34:9
|
LL | invalid();
| ^^^^^^^^^
error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants
--> $DIR/issue-32829-2.rs:56:9
|
LL | invalid();
| ^^^^^^^^^
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0015`.

View file

@ -1,3 +0,0 @@
fn main() {
/// comment //~ ERROR found a documentation comment that doesn't document anything
}

View file

@ -1,11 +0,0 @@
error[E0585]: found a documentation comment that doesn't document anything
--> $DIR/issue-34222-1.rs:2:5
|
LL | /// comment
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: doc comments must come before what they document, maybe a comment was intended with `//`?
error: aborting due to previous error
For more information about this error, try `rustc --explain E0585`.

View file

@ -1,25 +0,0 @@
// run-pass
#![forbid(improper_ctypes)]
#![allow(dead_code)]
#[repr(C)]
pub struct Foo {
size: u8,
__value: ::std::marker::PhantomData<i32>,
}
#[repr(C)]
pub struct ZeroSizeWithPhantomData<T>(::std::marker::PhantomData<T>);
#[repr(C)]
pub struct Bar {
size: u8,
baz: ZeroSizeWithPhantomData<i32>,
}
extern "C" {
pub fn bar(_: *mut Foo, _: *mut Bar);
}
fn main() {
}

View file

@ -1,7 +0,0 @@
const A: isize = Foo::B as isize;
enum Foo {
B = A, //~ ERROR E0391
}
fn main() {}

View file

@ -1,49 +0,0 @@
error[E0391]: cycle detected when simplifying constant for the type system `Foo::B::{constant#0}`
--> $DIR/issue-36163.rs:4:9
|
LL | B = A,
| ^
|
note: ...which requires simplifying constant for the type system `Foo::B::{constant#0}`...
--> $DIR/issue-36163.rs:4:9
|
LL | B = A,
| ^
note: ...which requires const-evaluating + checking `Foo::B::{constant#0}`...
--> $DIR/issue-36163.rs:4:9
|
LL | B = A,
| ^
= note: ...which requires normalizing `A`...
note: ...which requires simplifying constant for the type system `A`...
--> $DIR/issue-36163.rs:1:1
|
LL | const A: isize = Foo::B as isize;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires simplifying constant for the type system `A`...
--> $DIR/issue-36163.rs:1:1
|
LL | const A: isize = Foo::B as isize;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires const-evaluating + checking `A`...
--> $DIR/issue-36163.rs:1:1
|
LL | const A: isize = Foo::B as isize;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: ...which requires normalizing `A`...
= note: ...which again requires simplifying constant for the type system `Foo::B::{constant#0}`, completing the cycle
note: cycle used when collecting item types in top-level module
--> $DIR/issue-36163.rs:1:1
|
LL | / const A: isize = Foo::B as isize;
LL | |
LL | | enum Foo {
LL | | B = A,
LL | | }
LL | |
LL | | fn main() {}
| |____________^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0391`.

View file

@ -1,46 +0,0 @@
// issue-38940: error printed twice for deref recursion limit exceeded
// Test that the recursion limit can be changed. In this case, we have
// deeply nested types that will fail the `Send` check by overflow
// when the recursion limit is set very low.
#![allow(dead_code)]
#![recursion_limit="10"]
macro_rules! link {
($outer:ident, $inner:ident) => {
struct $outer($inner);
impl $outer {
fn new() -> $outer {
$outer($inner::new())
}
}
impl std::ops::Deref for $outer {
type Target = $inner;
fn deref(&self) -> &$inner {
&self.0
}
}
}
}
struct Bottom;
impl Bottom {
fn new() -> Bottom {
Bottom
}
}
link!(Top, A);
link!(A, B);
link!(B, C);
link!(C, D);
link!(D, E);
link!(E, F);
link!(F, G);
link!(G, H);
link!(H, I);
link!(I, J);
link!(J, K);
link!(K, Bottom);
fn main() {
let t = Top::new();
let x: &Bottom = &t;
//~^ ERROR mismatched types
//~| ERROR reached the recursion limit while auto-dereferencing `J`
}

View file

@ -1,23 +0,0 @@
error[E0055]: reached the recursion limit while auto-dereferencing `J`
--> $DIR/issue-38940.rs:43:22
|
LL | let x: &Bottom = &t;
| ^^ deref recursion limit reached
|
= help: consider adding a `#![recursion_limit="20"]` attribute to your crate (`issue_38940`)
error[E0308]: mismatched types
--> $DIR/issue-38940.rs:43:22
|
LL | let x: &Bottom = &t;
| ------- ^^ expected struct `Bottom`, found struct `Top`
| |
| expected due to this
|
= note: expected reference `&Bottom`
found reference `&Top`
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0055, E0308.
For more information about an error, try `rustc --explain E0055`.

View file

@ -1,9 +0,0 @@
// run-pass
// ignore-pretty issue #37195
#![allow(dead_code)]
include!("auxiliary/issue-40469.rs");
fn f() { m!(); }
fn main() {}

View file

@ -1,21 +0,0 @@
// run-pass
/// A compile-time map from identifiers to arbitrary (heterogeneous) expressions
macro_rules! ident_map {
( $name:ident = { $($key:ident => $e:expr,)* } ) => {
macro_rules! $name {
$(
( $key ) => { $e };
)*
// Empty invocation expands to nothing. Needed when the map is empty.
() => {};
}
};
}
ident_map!(my_map = {
main => 0,
});
fn main() {
my_map!(main);
}

View file

@ -1,13 +0,0 @@
fn xyz() -> u8 { 42 }
const NUM: u8 = xyz();
//~^ ERROR calls in constants are limited to constant functions, tuple structs and tuple variants
fn main() {
match 1 {
NUM => unimplemented!(),
//~^ ERROR could not evaluate constant pattern
//~| ERROR could not evaluate constant pattern
_ => unimplemented!(),
}
}

View file

@ -1,21 +0,0 @@
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
--> $DIR/issue-43105.rs:3:17
|
LL | const NUM: u8 = xyz();
| ^^^^^
error: could not evaluate constant pattern
--> $DIR/issue-43105.rs:8:9
|
LL | NUM => unimplemented!(),
| ^^^
error: could not evaluate constant pattern
--> $DIR/issue-43105.rs:8:9
|
LL | NUM => unimplemented!(),
| ^^^
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0015`.

View file

@ -1,6 +0,0 @@
fn main() {
|
}
//~^ ERROR expected `|`, found `}`
|
//~^ ERROR expected item, found `|`

View file

@ -1,16 +0,0 @@
error: expected `|`, found `}`
--> $DIR/issue-43196.rs:3:1
|
LL | |
| - expected `|`
LL | }
| ^ unexpected token
error: expected item, found `|`
--> $DIR/issue-43196.rs:5:1
|
LL | |
| ^ expected item
error: aborting due to 2 previous errors

View file

@ -1,14 +0,0 @@
// run-pass
#![feature(core_intrinsics)]
#![feature(repr128)]
//~^ WARN the feature `repr128` is incomplete
#[repr(i128)]
enum Big { A, B }
fn main() {
println!("{} {:?}",
std::intrinsics::discriminant_value(&Big::A),
std::mem::discriminant(&Big::B));
}

View file

@ -1,11 +0,0 @@
warning: the feature `repr128` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/issue-43398.rs:4:12
|
LL | #![feature(repr128)]
| ^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #56071 <https://github.com/rust-lang/rust/issues/56071> for more information
warning: 1 warning emitted

View file

@ -1,6 +0,0 @@
struct MyStruct;
impl MyStruct {
fn f() {|x, y} //~ ERROR expected one of `:`, `@`, or `|`, found `}`
}
fn main() {}

View file

@ -1,8 +0,0 @@
error: expected one of `:`, `@`, or `|`, found `}`
--> $DIR/issue-44021.rs:3:18
|
LL | fn f() {|x, y}
| ^ expected one of `:`, `@`, or `|`
error: aborting due to previous error

View file

@ -1,5 +0,0 @@
fn main() {
return;
*(1 as *mut u32) = 42;
//~^ ERROR dereference of raw pointer is unsafe
}

View file

@ -1,11 +0,0 @@
error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
--> $DIR/issue-45087-unreachable-unsafe.rs:3:5
|
LL | *(1 as *mut u32) = 42;
| ^^^^^^^^^^^^^^^^^^^^^ dereference of raw pointer
|
= note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
error: aborting due to previous error
For more information about this error, try `rustc --explain E0133`.

View file

@ -1,24 +0,0 @@
fn test_drop_replace() {
let b: Box<isize>;
//~^ HELP make this binding mutable
//~| SUGGESTION mut b
b = Box::new(1); //~ NOTE first assignment
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
//~| NOTE cannot assign twice to immutable
}
fn test_call() {
let b = Box::new(1); //~ NOTE first assignment
//~| HELP make this binding mutable
//~| SUGGESTION mut b
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
//~| NOTE cannot assign twice to immutable
}
fn test_args(b: Box<i32>) { //~ HELP make this binding mutable
//~| SUGGESTION mut b
b = Box::new(2); //~ ERROR cannot assign to immutable argument `b`
//~| NOTE cannot assign to immutable argument
}
fn main() {}

View file

@ -1,35 +0,0 @@
error[E0384]: cannot assign twice to immutable variable `b`
--> $DIR/issue-45199.rs:6:5
|
LL | let b: Box<isize>;
| - help: make this binding mutable: `mut b`
...
LL | b = Box::new(1);
| - first assignment to `b`
LL | b = Box::new(2);
| ^ cannot assign twice to immutable variable
error[E0384]: cannot assign twice to immutable variable `b`
--> $DIR/issue-45199.rs:14:5
|
LL | let b = Box::new(1);
| -
| |
| first assignment to `b`
| help: make this binding mutable: `mut b`
...
LL | b = Box::new(2);
| ^ cannot assign twice to immutable variable
error[E0384]: cannot assign to immutable argument `b`
--> $DIR/issue-45199.rs:20:5
|
LL | fn test_args(b: Box<i32>) {
| - help: make this binding mutable: `mut b`
LL |
LL | b = Box::new(2);
| ^ cannot assign to immutable argument
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0384`.

View file

@ -1,5 +0,0 @@
fn main() {
let unused = ();
#![allow(unused_variables)] //~ ERROR not permitted in this context
}

View file

@ -1,10 +0,0 @@
error: an inner attribute is not permitted in this context
--> $DIR/issue-45296.rs:4:5
|
LL | #![allow(unused_variables)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them.
error: aborting due to previous error

View file

@ -1,114 +0,0 @@
// rust-lang/rust#45696: This test is checking that we can return
// mutable borrows owned by boxes even when the boxes are dropped.
// run-pass
// This function shows quite directly what is going on: We have a
// reborrow of contents within the box.
fn return_borrow_from_dropped_box_1(x: Box<&mut u32>) -> &mut u32 { &mut **x }
// This function is the way you'll probably see this in practice (the
// reborrow is now implicit).
fn return_borrow_from_dropped_box_2(x: Box<&mut u32>) -> &mut u32 { *x }
// For the remaining tests we just add some fields or other
// indirection to ensure that the compiler isn't just special-casing
// the above `Box<&mut T>` as the only type that would work.
// Here we add a tuple of indirection between the box and the
// reference.
type BoxedTup<'a, 'b> = Box<(&'a mut u32, &'b mut u32)>;
fn return_borrow_of_field_from_dropped_box_1<'a>(x: BoxedTup<'a, '_>) -> &'a mut u32 {
&mut *x.0
}
fn return_borrow_of_field_from_dropped_box_2<'a>(x: BoxedTup<'a, '_>) -> &'a mut u32 {
x.0
}
fn return_borrow_from_dropped_tupled_box_1<'a>(x: (BoxedTup<'a, '_>, &mut u32)) -> &'a mut u32 {
&mut *(x.0).0
}
fn return_borrow_from_dropped_tupled_box_2<'a>(x: (BoxedTup<'a, '_>, &mut u32)) -> &'a mut u32 {
(x.0).0
}
fn basic_tests() {
let mut x = 2;
let mut y = 3;
let mut z = 4;
*return_borrow_from_dropped_box_1(Box::new(&mut x)) += 10;
assert_eq!((x, y, z), (12, 3, 4));
*return_borrow_from_dropped_box_2(Box::new(&mut x)) += 10;
assert_eq!((x, y, z), (22, 3, 4));
*return_borrow_of_field_from_dropped_box_1(Box::new((&mut x, &mut y))) += 10;
assert_eq!((x, y, z), (32, 3, 4));
*return_borrow_of_field_from_dropped_box_2(Box::new((&mut x, &mut y))) += 10;
assert_eq!((x, y, z), (42, 3, 4));
*return_borrow_from_dropped_tupled_box_1((Box::new((&mut x, &mut y)), &mut z)) += 10;
assert_eq!((x, y, z), (52, 3, 4));
*return_borrow_from_dropped_tupled_box_2((Box::new((&mut x, &mut y)), &mut z)) += 10;
assert_eq!((x, y, z), (62, 3, 4));
}
// These scribbling tests have been transcribed from
// issue-45696-scribble-on-boxed-borrow.rs
//
// In the context of that file, these tests are meant to show cases
// that should be *accepted* by the compiler, so here we are actually
// checking that the code we get when they are compiled matches our
// expectations.
struct Scribble<'a>(&'a mut u32);
impl<'a> Drop for Scribble<'a> { fn drop(&mut self) { *self.0 = 42; } }
// this is okay, in both AST-borrowck and NLL: The `Scribble` here *has*
// to strictly outlive `'a`
fn borrowed_scribble<'a>(s: &'a mut Scribble) -> &'a mut u32 {
&mut *s.0
}
// this, by analogy to previous case, is also okay.
fn boxed_borrowed_scribble<'a>(s: Box<&'a mut Scribble>) -> &'a mut u32 {
&mut *(*s).0
}
// this, by analogy to previous case, is also okay.
fn boxed_boxed_borrowed_scribble<'a>(s: Box<Box<&'a mut Scribble>>) -> &'a mut u32 {
&mut *(**s).0
}
fn scribbling_tests() {
let mut x = 1;
{
let mut long_lived = Scribble(&mut x);
*borrowed_scribble(&mut long_lived) += 10;
assert_eq!(*long_lived.0, 11);
// (Scribble dtor runs here, after `&mut`-borrow above ends)
}
assert_eq!(x, 42);
x = 1;
{
let mut long_lived = Scribble(&mut x);
*boxed_borrowed_scribble(Box::new(&mut long_lived)) += 10;
assert_eq!(*long_lived.0, 11);
// (Scribble dtor runs here, after `&mut`-borrow above ends)
}
assert_eq!(x, 42);
x = 1;
{
let mut long_lived = Scribble(&mut x);
*boxed_boxed_borrowed_scribble(Box::new(Box::new(&mut long_lived))) += 10;
assert_eq!(*long_lived.0, 11);
// (Scribble dtor runs here, after `&mut`-borrow above ends)
}
assert_eq!(x, 42);
}
fn main() {
basic_tests();
scribbling_tests();
}

Some files were not shown because too many files have changed in this diff Show more