diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/auxiliary | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/auxiliary')
24 files changed, 515 insertions, 0 deletions
diff --git a/src/test/ui/auxiliary/augmented_assignments.rs b/src/test/ui/auxiliary/augmented_assignments.rs new file mode 100644 index 000000000..d0d3f5745 --- /dev/null +++ b/src/test/ui/auxiliary/augmented_assignments.rs @@ -0,0 +1,8 @@ +use std::ops::AddAssign; + +pub struct Int(pub i32); + +impl AddAssign<i32> for Int { + fn add_assign(&mut self, _: i32) { + } +} diff --git a/src/test/ui/auxiliary/check_static_recursion_foreign_helper.rs b/src/test/ui/auxiliary/check_static_recursion_foreign_helper.rs new file mode 100644 index 000000000..5330b7a92 --- /dev/null +++ b/src/test/ui/auxiliary/check_static_recursion_foreign_helper.rs @@ -0,0 +1,11 @@ +// Helper definition for test/run-pass/check-static-recursion-foreign.rs. + +#![feature(rustc_private)] + +#![crate_name = "check_static_recursion_foreign_helper"] +#![crate_type = "lib"] + +extern crate libc; + +#[no_mangle] +pub static test_static: libc::c_int = 0; diff --git a/src/test/ui/auxiliary/crate-method-reexport-grrrrrrr2.rs b/src/test/ui/auxiliary/crate-method-reexport-grrrrrrr2.rs new file mode 100644 index 000000000..d08504005 --- /dev/null +++ b/src/test/ui/auxiliary/crate-method-reexport-grrrrrrr2.rs @@ -0,0 +1,31 @@ +#![crate_name="crate_method_reexport_grrrrrrr2"] + +pub use name_pool::add; + +pub mod name_pool { + pub type name_pool = (); + + pub trait add { + fn add(&self, s: String); + } + + impl add for name_pool { + fn add(&self, _s: String) { + } + } +} + +pub mod rust { + pub use name_pool::add; + + pub type rt = Box<()>; + + pub trait cx { + fn cx(&self); + } + + impl cx for rt { + fn cx(&self) { + } + } +} diff --git a/src/test/ui/auxiliary/default-ty-param-cross-crate-crate.rs b/src/test/ui/auxiliary/default-ty-param-cross-crate-crate.rs new file mode 100644 index 000000000..d722b7876 --- /dev/null +++ b/src/test/ui/auxiliary/default-ty-param-cross-crate-crate.rs @@ -0,0 +1,9 @@ +#![crate_type = "lib"] +#![crate_name = "default_param_test"] +#![feature(default_type_parameter_fallback)] + +use std::marker::PhantomData; + +pub struct Foo<A, B>(PhantomData<(A, B)>); + +pub fn bleh<A=i32, X=char>() -> Foo<A, X> { Foo(PhantomData) } diff --git a/src/test/ui/auxiliary/edition-kw-macro-2015.rs b/src/test/ui/auxiliary/edition-kw-macro-2015.rs new file mode 100644 index 000000000..553ba6930 --- /dev/null +++ b/src/test/ui/auxiliary/edition-kw-macro-2015.rs @@ -0,0 +1,26 @@ +// edition:2015 + +#[macro_export] +macro_rules! produces_async { + () => (pub fn async() {}) +} + +#[macro_export] +macro_rules! produces_async_raw { + () => (pub fn r#async() {}) +} + +#[macro_export] +macro_rules! consumes_async { + (async) => (1) +} + +#[macro_export] +macro_rules! consumes_async_raw { + (r#async) => (1) +} + +#[macro_export] +macro_rules! passes_ident { + ($i: ident) => ($i) +} diff --git a/src/test/ui/auxiliary/edition-kw-macro-2018.rs b/src/test/ui/auxiliary/edition-kw-macro-2018.rs new file mode 100644 index 000000000..f1f4ee280 --- /dev/null +++ b/src/test/ui/auxiliary/edition-kw-macro-2018.rs @@ -0,0 +1,26 @@ +// edition:2018 + +#[macro_export] +macro_rules! produces_async { + () => (pub fn async() {}) +} + +#[macro_export] +macro_rules! produces_async_raw { + () => (pub fn r#async() {}) +} + +#[macro_export] +macro_rules! consumes_async { + (async) => (1) +} + +#[macro_export] +macro_rules! consumes_async_raw { + (r#async) => (1) +} + +#[macro_export] +macro_rules! passes_ident { + ($i: ident) => ($i) +} diff --git a/src/test/ui/auxiliary/fancy-panic.rs b/src/test/ui/auxiliary/fancy-panic.rs new file mode 100644 index 000000000..35be93b05 --- /dev/null +++ b/src/test/ui/auxiliary/fancy-panic.rs @@ -0,0 +1,9 @@ +#[macro_export] +macro_rules! fancy_panic { + () => { + panic!("{}"); + }; + ($msg:expr) => { + panic!($msg) + }; +} diff --git a/src/test/ui/auxiliary/hello_macro.rs b/src/test/ui/auxiliary/hello_macro.rs new file mode 100644 index 000000000..a05b8d54d --- /dev/null +++ b/src/test/ui/auxiliary/hello_macro.rs @@ -0,0 +1,21 @@ +// force-host +// no-prefer-dynamic + +#![crate_type = "proc-macro"] +#![feature(proc_macro_quote)] + +extern crate proc_macro; + +use proc_macro::{TokenStream, quote}; + +// This macro is not very interesting, but it does contain delimited tokens with +// no content - `()` and `{}` - which has caused problems in the past. +// Also, it tests that we can escape `$` via `$$`. +#[proc_macro] +pub fn hello(_: TokenStream) -> TokenStream { + quote!({ + fn hello() {} + macro_rules! m { ($$($$t:tt)*) => { $$($$t)* } } + m!(hello()); + }) +} diff --git a/src/test/ui/auxiliary/impl_privacy_xc_1.rs b/src/test/ui/auxiliary/impl_privacy_xc_1.rs new file mode 100644 index 000000000..367b8ec8b --- /dev/null +++ b/src/test/ui/auxiliary/impl_privacy_xc_1.rs @@ -0,0 +1,9 @@ +#![crate_type = "lib"] + +pub struct Fish { + pub x: isize +} + +impl Fish { + pub fn swim(&self) {} +} diff --git a/src/test/ui/auxiliary/inner_static.rs b/src/test/ui/auxiliary/inner_static.rs new file mode 100644 index 000000000..42dcd379d --- /dev/null +++ b/src/test/ui/auxiliary/inner_static.rs @@ -0,0 +1,51 @@ +pub struct A<T> { pub v: T } +pub struct B<T> { pub v: T } + +pub mod test { + pub struct A<T> { pub v: T } + + impl<T> A<T> { + pub fn foo(&self) -> isize { + static a: isize = 5; + return a + } + + pub fn bar(&self) -> isize { + static a: isize = 6; + return a; + } + } +} + +impl<T> A<T> { + pub fn foo(&self) -> isize { + static a: isize = 1; + return a + } + + pub fn bar(&self) -> isize { + static a: isize = 2; + return a; + } +} + +impl<T> B<T> { + pub fn foo(&self) -> isize { + static a: isize = 3; + return a + } + + pub fn bar(&self) -> isize { + static a: isize = 4; + return a; + } +} + +pub fn foo() -> isize { + let a = A { v: () }; + let b = B { v: () }; + let c = test::A { v: () }; + return a.foo() + a.bar() + + b.foo() + b.bar() + + c.foo() + c.bar(); +} diff --git a/src/test/ui/auxiliary/issue-76387.rs b/src/test/ui/auxiliary/issue-76387.rs new file mode 100644 index 000000000..873d2bedd --- /dev/null +++ b/src/test/ui/auxiliary/issue-76387.rs @@ -0,0 +1,29 @@ +// compile-flags: -C opt-level=3 + +pub struct FatPtr { + ptr: *mut u8, + len: usize, +} + +impl FatPtr { + pub fn new(len: usize) -> FatPtr { + let ptr = Box::into_raw(vec![42u8; len].into_boxed_slice()) as *mut u8; + + FatPtr { ptr, len } + } +} + +impl std::ops::Deref for FatPtr { + type Target = [u8]; + + #[inline] + fn deref(&self) -> &[u8] { + unsafe { std::slice::from_raw_parts(self.ptr, self.len) } + } +} + +impl std::ops::Drop for FatPtr { + fn drop(&mut self) { + println!("Drop"); + } +} diff --git a/src/test/ui/auxiliary/kinds_in_metadata.rs b/src/test/ui/auxiliary/kinds_in_metadata.rs new file mode 100644 index 000000000..2a2106ff7 --- /dev/null +++ b/src/test/ui/auxiliary/kinds_in_metadata.rs @@ -0,0 +1,8 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Tests that metadata serialization works for the `Copy` kind. + +#![crate_type="lib"] + +pub fn f<T:Copy>() {} diff --git a/src/test/ui/auxiliary/msvc-data-only-lib.rs b/src/test/ui/auxiliary/msvc-data-only-lib.rs new file mode 100644 index 000000000..ccaa6d8ed --- /dev/null +++ b/src/test/ui/auxiliary/msvc-data-only-lib.rs @@ -0,0 +1,5 @@ +// no-prefer-dynamic + +#![crate_type = "rlib"] + +pub static FOO: i32 = 42; diff --git a/src/test/ui/auxiliary/noexporttypelib.rs b/src/test/ui/auxiliary/noexporttypelib.rs new file mode 100644 index 000000000..67889cc5f --- /dev/null +++ b/src/test/ui/auxiliary/noexporttypelib.rs @@ -0,0 +1,2 @@ +pub type oint = Option<isize>; +pub fn foo() -> oint { Some(3) } diff --git a/src/test/ui/auxiliary/orphan-check-diagnostics.rs b/src/test/ui/auxiliary/orphan-check-diagnostics.rs new file mode 100644 index 000000000..6b2c42b69 --- /dev/null +++ b/src/test/ui/auxiliary/orphan-check-diagnostics.rs @@ -0,0 +1 @@ +pub trait RemoteTrait { fn dummy(&self) { } } diff --git a/src/test/ui/auxiliary/pub-and-stability.rs b/src/test/ui/auxiliary/pub-and-stability.rs new file mode 100644 index 000000000..ee05a07db --- /dev/null +++ b/src/test/ui/auxiliary/pub-and-stability.rs @@ -0,0 +1,133 @@ +// This crate attempts to enumerate the various scenarios for how a +// type can define fields and methods with various visibilities and +// stabilities. +// +// The basic stability pattern in this file has four cases: +// 1. no stability attribute at all +// 2. a stable attribute (feature "unit_test") +// 3. an unstable attribute that unit test declares (feature "unstable_declared") +// 4. an unstable attribute that unit test fails to declare (feature "unstable_undeclared") +// +// This file also covers four kinds of visibility: private, +// pub(module), pub(crate), and pub. +// +// However, since stability attributes can only be observed in +// cross-crate linkage scenarios, there is little reason to take the +// cross-product (4 stability cases * 4 visibility cases), because the +// first three visibility cases cannot be accessed outside this crate, +// and therefore stability is only relevant when the visibility is pub +// to the whole universe. +// +// (The only reason to do so would be if one were worried about the +// compiler having some subtle bug where adding a stability attribute +// introduces a privacy violation. As a way to provide evidence that +// this is not occurring, I have put stability attributes on some +// non-pub fields, marked with SILLY below) + +#![feature(staged_api)] + +#![stable(feature = "unit_test", since = "1.0.0")] + +#[stable(feature = "unit_test", since = "1.0.0")] +pub use m::{Record, Trait, Tuple}; + +mod m { + #[derive(Default)] + #[stable(feature = "unit_test", since = "1.0.0")] + pub struct Record { + #[stable(feature = "unit_test", since = "1.0.0")] + pub a_stable_pub: i32, + #[unstable(feature = "unstable_declared", issue = "38412")] + pub a_unstable_declared_pub: i32, + #[unstable(feature = "unstable_undeclared", issue = "38412")] + pub a_unstable_undeclared_pub: i32, + #[unstable(feature = "unstable_undeclared", issue = "38412")] // SILLY + pub(crate) b_crate: i32, + #[unstable(feature = "unstable_declared", issue = "38412")] // SILLY + pub(in m) c_mod: i32, + #[stable(feature = "unit_test", since = "1.0.0")] // SILLY + d_priv: i32 + } + + #[derive(Default)] + #[stable(feature = "unit_test", since = "1.0.0")] + pub struct Tuple( + #[stable(feature = "unit_test", since = "1.0.0")] + pub i32, + #[unstable(feature = "unstable_declared", issue = "38412")] + pub i32, + #[unstable(feature = "unstable_undeclared", issue = "38412")] + pub i32, + + pub(crate) i32, + pub(in m) i32, + i32); + + impl Record { + #[stable(feature = "unit_test", since = "1.0.0")] + pub fn new() -> Self { Default::default() } + } + + impl Tuple { + #[stable(feature = "unit_test", since = "1.0.0")] + pub fn new() -> Self { Default::default() } + } + + + #[stable(feature = "unit_test", since = "1.0.0")] + pub trait Trait { + #[stable(feature = "unit_test", since = "1.0.0")] + type Type; + #[stable(feature = "unit_test", since = "1.0.0")] + fn stable_trait_method(&self) -> Self::Type; + #[unstable(feature = "unstable_undeclared", issue = "38412")] + fn unstable_undeclared_trait_method(&self) -> Self::Type; + #[unstable(feature = "unstable_declared", issue = "38412")] + fn unstable_declared_trait_method(&self) -> Self::Type; + } + + #[stable(feature = "unit_test", since = "1.0.0")] + impl Trait for Record { + type Type = i32; + fn stable_trait_method(&self) -> i32 { self.d_priv } + fn unstable_undeclared_trait_method(&self) -> i32 { self.d_priv } + fn unstable_declared_trait_method(&self) -> i32 { self.d_priv } + } + + #[stable(feature = "unit_test", since = "1.0.0")] + impl Trait for Tuple { + type Type = i32; + fn stable_trait_method(&self) -> i32 { self.3 } + fn unstable_undeclared_trait_method(&self) -> i32 { self.3 } + fn unstable_declared_trait_method(&self) -> i32 { self.3 } + } + + impl Record { + #[unstable(feature = "unstable_undeclared", issue = "38412")] + pub fn unstable_undeclared(&self) -> i32 { self.d_priv } + #[unstable(feature = "unstable_declared", issue = "38412")] + pub fn unstable_declared(&self) -> i32 { self.d_priv } + #[stable(feature = "unit_test", since = "1.0.0")] + pub fn stable(&self) -> i32 { self.d_priv } + + #[unstable(feature = "unstable_undeclared", issue = "38412")] // SILLY + pub(crate) fn pub_crate(&self) -> i32 { self.d_priv } + #[unstable(feature = "unstable_declared", issue = "38412")] // SILLY + pub(in m) fn pub_mod(&self) -> i32 { self.d_priv } + #[stable(feature = "unit_test", since = "1.0.0")] // SILLY + fn private(&self) -> i32 { self.d_priv } + } + + impl Tuple { + #[unstable(feature = "unstable_undeclared", issue = "38412")] + pub fn unstable_undeclared(&self) -> i32 { self.0 } + #[unstable(feature = "unstable_declared", issue = "38412")] + pub fn unstable_declared(&self) -> i32 { self.0 } + #[stable(feature = "unit_test", since = "1.0.0")] + pub fn stable(&self) -> i32 { self.0 } + + pub(crate) fn pub_crate(&self) -> i32 { self.0 } + pub(in m) fn pub_mod(&self) -> i32 { self.0 } + fn private(&self) -> i32 { self.0 } + } +} diff --git a/src/test/ui/auxiliary/removing-extern-crate.rs b/src/test/ui/auxiliary/removing-extern-crate.rs new file mode 100644 index 000000000..65e2cc340 --- /dev/null +++ b/src/test/ui/auxiliary/removing-extern-crate.rs @@ -0,0 +1 @@ +// intentionally blank diff --git a/src/test/ui/auxiliary/rustc-rust-log-aux.rs b/src/test/ui/auxiliary/rustc-rust-log-aux.rs new file mode 100644 index 000000000..daa8e9f49 --- /dev/null +++ b/src/test/ui/auxiliary/rustc-rust-log-aux.rs @@ -0,0 +1 @@ +// rustc-env:RUSTC_LOG=debug diff --git a/src/test/ui/auxiliary/svh-a-base.rs b/src/test/ui/auxiliary/svh-a-base.rs new file mode 100644 index 000000000..36b41fc81 --- /dev/null +++ b/src/test/ui/auxiliary/svh-a-base.rs @@ -0,0 +1,25 @@ +//! The `svh-a-*.rs` files are all deviations from the base file +//! svh-a-base.rs with some difference (usually in `fn foo`) that +//! should not affect the strict version hash (SVH) computation +//! (#14132). + +#![crate_name = "a"] + +macro_rules! three { + () => { 3 } +} + +pub trait U {} +pub trait V {} +impl U for () {} +impl V for () {} + +static A_CONSTANT : isize = 2; + +pub fn foo<T:U>(_: isize) -> isize { + 3 +} + +pub fn an_unused_name() -> isize { + 4 +} diff --git a/src/test/ui/auxiliary/svh-b.rs b/src/test/ui/auxiliary/svh-b.rs new file mode 100644 index 000000000..57029f708 --- /dev/null +++ b/src/test/ui/auxiliary/svh-b.rs @@ -0,0 +1,13 @@ +//! This is a client of the `a` crate defined in `svn-a-base.rs`. The +//! rpass and cfail tests (such as `run-pass/svh-add-comment.rs`) use +//! it by swapping in a different object code library crate built from +//! some variant of `svn-a-base.rs`, and then we are checking if the +//! compiler properly ignores or accepts the change, based on whether +//! the change could affect the downstream crate content or not +//! (#14132). + +#![crate_name = "b"] + +extern crate a; + +pub fn foo() { assert_eq!(a::foo::<()>(0), 3); } diff --git a/src/test/ui/auxiliary/typeid-intrinsic-aux1.rs b/src/test/ui/auxiliary/typeid-intrinsic-aux1.rs new file mode 100644 index 000000000..281c07968 --- /dev/null +++ b/src/test/ui/auxiliary/typeid-intrinsic-aux1.rs @@ -0,0 +1,29 @@ +use std::any::{Any, TypeId}; + +pub struct A; +pub struct B(Option<A>); +pub struct C(Option<isize>); +pub struct D(Option<&'static str>); +pub struct E(Result<&'static str, isize>); + +pub type F = Option<isize>; +pub type G = usize; +pub type H = &'static str; +pub type I = Box<Fn()>; +pub type I32Iterator = Iterator<Item=i32>; +pub type U32Iterator = Iterator<Item=u32>; + +pub fn id_A() -> TypeId { TypeId::of::<A>() } +pub fn id_B() -> TypeId { TypeId::of::<B>() } +pub fn id_C() -> TypeId { TypeId::of::<C>() } +pub fn id_D() -> TypeId { TypeId::of::<D>() } +pub fn id_E() -> TypeId { TypeId::of::<E>() } +pub fn id_F() -> TypeId { TypeId::of::<F>() } +pub fn id_G() -> TypeId { TypeId::of::<G>() } +pub fn id_H() -> TypeId { TypeId::of::<H>() } +pub fn id_I() -> TypeId { TypeId::of::<I>() } + +pub fn foo<T: Any>() -> TypeId { TypeId::of::<T>() } + +pub fn id_i32_iterator() -> TypeId { TypeId::of::<I32Iterator>() } +pub fn id_u32_iterator() -> TypeId { TypeId::of::<U32Iterator>() } diff --git a/src/test/ui/auxiliary/typeid-intrinsic-aux2.rs b/src/test/ui/auxiliary/typeid-intrinsic-aux2.rs new file mode 100644 index 000000000..281c07968 --- /dev/null +++ b/src/test/ui/auxiliary/typeid-intrinsic-aux2.rs @@ -0,0 +1,29 @@ +use std::any::{Any, TypeId}; + +pub struct A; +pub struct B(Option<A>); +pub struct C(Option<isize>); +pub struct D(Option<&'static str>); +pub struct E(Result<&'static str, isize>); + +pub type F = Option<isize>; +pub type G = usize; +pub type H = &'static str; +pub type I = Box<Fn()>; +pub type I32Iterator = Iterator<Item=i32>; +pub type U32Iterator = Iterator<Item=u32>; + +pub fn id_A() -> TypeId { TypeId::of::<A>() } +pub fn id_B() -> TypeId { TypeId::of::<B>() } +pub fn id_C() -> TypeId { TypeId::of::<C>() } +pub fn id_D() -> TypeId { TypeId::of::<D>() } +pub fn id_E() -> TypeId { TypeId::of::<E>() } +pub fn id_F() -> TypeId { TypeId::of::<F>() } +pub fn id_G() -> TypeId { TypeId::of::<G>() } +pub fn id_H() -> TypeId { TypeId::of::<H>() } +pub fn id_I() -> TypeId { TypeId::of::<I>() } + +pub fn foo<T: Any>() -> TypeId { TypeId::of::<T>() } + +pub fn id_i32_iterator() -> TypeId { TypeId::of::<I32Iterator>() } +pub fn id_u32_iterator() -> TypeId { TypeId::of::<U32Iterator>() } diff --git a/src/test/ui/auxiliary/using-target-feature-unstable.rs b/src/test/ui/auxiliary/using-target-feature-unstable.rs new file mode 100644 index 000000000..268202893 --- /dev/null +++ b/src/test/ui/auxiliary/using-target-feature-unstable.rs @@ -0,0 +1,5 @@ +#![feature(avx512_target_feature)] + +#[inline] +#[target_feature(enable = "avx512ifma")] +pub unsafe fn foo() {} diff --git a/src/test/ui/auxiliary/xc-private-method-lib.rs b/src/test/ui/auxiliary/xc-private-method-lib.rs new file mode 100644 index 000000000..4d5ec6de3 --- /dev/null +++ b/src/test/ui/auxiliary/xc-private-method-lib.rs @@ -0,0 +1,33 @@ +#![crate_type="lib"] + +pub struct Struct { + pub x: isize +} + +impl Struct { + fn static_meth_struct() -> Struct { + Struct { x: 1 } + } + + fn meth_struct(&self) -> isize { + self.x + } +} + +pub enum Enum { + Variant1(isize), + Variant2(isize) +} + +impl Enum { + fn static_meth_enum() -> Enum { + Enum::Variant2(10) + } + + fn meth_enum(&self) -> isize { + match *self { + Enum::Variant1(x) | + Enum::Variant2(x) => x + } + } +} |