-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// 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 DynSized cannot be implemented manually. | ||
|
||
#![feature(extern_types)] | ||
#![feature(dynsized)] | ||
|
||
use std::marker::DynSized; | ||
|
||
extern { | ||
type foo; | ||
} | ||
|
||
impl DynSized for foo { } | ||
//~^ ERROR explicit impls for the `DynSized` trait are not permitted | ||
|
||
fn main() { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// 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. | ||
|
||
// Ensure `size_of_val` / `align_of_val` can't be used on !DynSized types | ||
|
||
#![feature(extern_types)] | ||
|
||
use std::mem::{size_of_val, align_of_val}; | ||
|
||
extern { | ||
type A; | ||
} | ||
|
||
fn main() { | ||
let x: &A = unsafe { | ||
&*(1usize as *const A) | ||
}; | ||
|
||
size_of_val(x); //~ERROR the trait bound `A: std::marker::DynSized` is not satisfied | ||
|
||
align_of_val(x); //~ERROR the trait bound `A: std::marker::DynSized` is not satisfied | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// 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. | ||
|
||
// Ensure !DynSized fields can't be used in structs, even as the last field. | ||
|
||
#![feature(extern_types)] | ||
#![feature(dynsized)] | ||
|
||
use std::marker::DynSized; | ||
|
||
extern { | ||
type foo; | ||
} | ||
|
||
struct A { | ||
x: foo, //~ERROR the trait bound `foo: std::marker::DynSized` is not satisfied | ||
} | ||
|
||
struct B { | ||
x: usize, | ||
y: foo, //~ERROR the trait bound `foo: std::marker::DynSized` is not satisfied | ||
} | ||
|
||
struct C<T: ?DynSized> { | ||
x: usize, | ||
y: T, //~ERROR the trait bound `T: std::marker::DynSized` is not satisfied | ||
} | ||
|
||
fn main() { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// 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 traits can opt-out of being DynSized by default. | ||
// See also run-pass/dynsized/supertrait-default.rs | ||
|
||
#![feature(dynsized)] | ||
|
||
use std::marker::DynSized; | ||
|
||
fn assert_dynsized<T: ?Sized>() { } | ||
|
||
trait Tr: ?DynSized { | ||
fn foo() { | ||
assert_dynsized::<Self>(); | ||
//~^ ERROR the trait bound `Self: std::marker::DynSized` is not satisfied | ||
} | ||
} | ||
|
||
fn main() { } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// 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. | ||
|
||
// Ensure !DynSized fields can't be used in tuples, even as the last field. | ||
|
||
#![feature(extern_types)] | ||
#![feature(dynsized)] | ||
|
||
use std::marker::DynSized; | ||
|
||
extern { | ||
type foo; | ||
} | ||
|
||
fn baz<T: ?DynSized>() { | ||
let x: &(u8, foo); //~ERROR the trait bound `foo: std::marker::DynSized` is not satisfied | ||
|
||
let y: &(u8, T); //~ERROR the trait bound `T: std::marker::DynSized` is not satisfied | ||
} | ||
|
||
fn main() { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// 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(dynsized)] | ||
|
||
use std::marker::DynSized; | ||
|
||
fn foo<T: ?DynSized>() { | ||
} | ||
|
||
fn bar<T: ?Sized>() { | ||
foo::<T>(); | ||
} | ||
|
||
fn baz<T>() { | ||
bar::<T>(); | ||
} | ||
|
||
fn main() { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// 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 traits have DynSized as a super trait by default. | ||
// See also compile-fail/dynsized/supertrait-unbound.rs | ||
|
||
#![feature(dynsized)] | ||
|
||
use std::marker::DynSized; | ||
|
||
fn assert_dynsized<T: ?Sized>() { } | ||
|
||
trait Tr { | ||
fn foo() { | ||
assert_dynsized::<Self>(); | ||
} | ||
} | ||
|
||
fn main() { } | ||
|