cleaned up some tests
This commit is contained in:
parent
36b21637e9
commit
d0bd27924e
15 changed files with 157 additions and 98 deletions
|
|
@ -1368,7 +1368,6 @@ ui/infinite/issue-41731-infinite-macro-println.rs
|
|||
ui/intrinsics/issue-28575.rs
|
||||
ui/intrinsics/issue-84297-reifying-copy.rs
|
||||
ui/invalid/issue-114435-layout-type-err.rs
|
||||
ui/issue-11881.rs
|
||||
ui/issue-15924.rs
|
||||
ui/issue-16822.rs
|
||||
ui/issues-71798.rs
|
||||
|
|
|
|||
36
tests/ui/attributes/inner-attrs-impl-cfg.rs
Normal file
36
tests/ui/attributes/inner-attrs-impl-cfg.rs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
//! Test inner attributes (#![...]) behavior in impl blocks with cfg conditions.
|
||||
//!
|
||||
//! This test verifies that:
|
||||
//! - Inner attributes can conditionally exclude entire impl blocks
|
||||
//! - Regular attributes within impl blocks work independently
|
||||
//! - Attribute parsing doesn't consume too eagerly
|
||||
|
||||
//@ run-pass
|
||||
|
||||
struct Foo;
|
||||
|
||||
impl Foo {
|
||||
#![cfg(false)]
|
||||
|
||||
fn method(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
impl Foo {
|
||||
#![cfg(not(FALSE))]
|
||||
|
||||
// Check that we don't eat attributes too eagerly.
|
||||
#[cfg(false)]
|
||||
fn method(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn method(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
assert!(Foo.method());
|
||||
}
|
||||
|
|
@ -1,16 +1,20 @@
|
|||
//! Test that only usize can be used for indexing arrays and slices.
|
||||
|
||||
pub fn main() {
|
||||
let v: Vec<isize> = vec![0, 1, 2, 3, 4, 5];
|
||||
let s: String = "abcdef".to_string();
|
||||
|
||||
// Valid indexing with usize
|
||||
v[3_usize];
|
||||
v[3];
|
||||
v[3u8]; //~ ERROR the type `[isize]` cannot be indexed by `u8`
|
||||
v[3i8]; //~ ERROR the type `[isize]` cannot be indexed by `i8`
|
||||
v[3u8]; //~ ERROR the type `[isize]` cannot be indexed by `u8`
|
||||
v[3i8]; //~ ERROR the type `[isize]` cannot be indexed by `i8`
|
||||
v[3u32]; //~ ERROR the type `[isize]` cannot be indexed by `u32`
|
||||
v[3i32]; //~ ERROR the type `[isize]` cannot be indexed by `i32`
|
||||
s.as_bytes()[3_usize];
|
||||
s.as_bytes()[3];
|
||||
s.as_bytes()[3u8]; //~ ERROR the type `[u8]` cannot be indexed by `u8`
|
||||
s.as_bytes()[3i8]; //~ ERROR the type `[u8]` cannot be indexed by `i8`
|
||||
s.as_bytes()[3u8]; //~ ERROR the type `[u8]` cannot be indexed by `u8`
|
||||
s.as_bytes()[3i8]; //~ ERROR the type `[u8]` cannot be indexed by `i8`
|
||||
s.as_bytes()[3u32]; //~ ERROR the type `[u8]` cannot be indexed by `u32`
|
||||
s.as_bytes()[3i32]; //~ ERROR the type `[u8]` cannot be indexed by `i32`
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
error[E0277]: the type `[isize]` cannot be indexed by `u8`
|
||||
--> $DIR/integral-indexing.rs:6:7
|
||||
--> $DIR/indexing-integral-types.rs:10:7
|
||||
|
|
||||
LL | v[3u8];
|
||||
| ^^^ slice indices are of type `usize` or ranges of `usize`
|
||||
|
|
@ -11,7 +11,7 @@ LL | v[3u8];
|
|||
= note: required for `Vec<isize>` to implement `Index<u8>`
|
||||
|
||||
error[E0277]: the type `[isize]` cannot be indexed by `i8`
|
||||
--> $DIR/integral-indexing.rs:7:7
|
||||
--> $DIR/indexing-integral-types.rs:11:7
|
||||
|
|
||||
LL | v[3i8];
|
||||
| ^^^ slice indices are of type `usize` or ranges of `usize`
|
||||
|
|
@ -23,7 +23,7 @@ LL | v[3i8];
|
|||
= note: required for `Vec<isize>` to implement `Index<i8>`
|
||||
|
||||
error[E0277]: the type `[isize]` cannot be indexed by `u32`
|
||||
--> $DIR/integral-indexing.rs:8:7
|
||||
--> $DIR/indexing-integral-types.rs:12:7
|
||||
|
|
||||
LL | v[3u32];
|
||||
| ^^^^ slice indices are of type `usize` or ranges of `usize`
|
||||
|
|
@ -35,7 +35,7 @@ LL | v[3u32];
|
|||
= note: required for `Vec<isize>` to implement `Index<u32>`
|
||||
|
||||
error[E0277]: the type `[isize]` cannot be indexed by `i32`
|
||||
--> $DIR/integral-indexing.rs:9:7
|
||||
--> $DIR/indexing-integral-types.rs:13:7
|
||||
|
|
||||
LL | v[3i32];
|
||||
| ^^^^ slice indices are of type `usize` or ranges of `usize`
|
||||
|
|
@ -47,7 +47,7 @@ LL | v[3i32];
|
|||
= note: required for `Vec<isize>` to implement `Index<i32>`
|
||||
|
||||
error[E0277]: the type `[u8]` cannot be indexed by `u8`
|
||||
--> $DIR/integral-indexing.rs:12:18
|
||||
--> $DIR/indexing-integral-types.rs:16:18
|
||||
|
|
||||
LL | s.as_bytes()[3u8];
|
||||
| ^^^ slice indices are of type `usize` or ranges of `usize`
|
||||
|
|
@ -59,7 +59,7 @@ LL | s.as_bytes()[3u8];
|
|||
= note: required for `[u8]` to implement `Index<u8>`
|
||||
|
||||
error[E0277]: the type `[u8]` cannot be indexed by `i8`
|
||||
--> $DIR/integral-indexing.rs:13:18
|
||||
--> $DIR/indexing-integral-types.rs:17:18
|
||||
|
|
||||
LL | s.as_bytes()[3i8];
|
||||
| ^^^ slice indices are of type `usize` or ranges of `usize`
|
||||
|
|
@ -71,7 +71,7 @@ LL | s.as_bytes()[3i8];
|
|||
= note: required for `[u8]` to implement `Index<i8>`
|
||||
|
||||
error[E0277]: the type `[u8]` cannot be indexed by `u32`
|
||||
--> $DIR/integral-indexing.rs:14:18
|
||||
--> $DIR/indexing-integral-types.rs:18:18
|
||||
|
|
||||
LL | s.as_bytes()[3u32];
|
||||
| ^^^^ slice indices are of type `usize` or ranges of `usize`
|
||||
|
|
@ -83,7 +83,7 @@ LL | s.as_bytes()[3u32];
|
|||
= note: required for `[u8]` to implement `Index<u32>`
|
||||
|
||||
error[E0277]: the type `[u8]` cannot be indexed by `i32`
|
||||
--> $DIR/integral-indexing.rs:15:18
|
||||
--> $DIR/indexing-integral-types.rs:19:18
|
||||
|
|
||||
LL | s.as_bytes()[3i32];
|
||||
| ^^^^ slice indices are of type `usize` or ranges of `usize`
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
//@ run-pass
|
||||
|
||||
struct Foo;
|
||||
|
||||
impl Foo {
|
||||
#![cfg(false)]
|
||||
|
||||
fn method(&self) -> bool { false }
|
||||
}
|
||||
|
||||
impl Foo {
|
||||
#![cfg(not(FALSE))]
|
||||
|
||||
// check that we don't eat attributes too eagerly.
|
||||
#[cfg(false)]
|
||||
fn method(&self) -> bool { false }
|
||||
|
||||
fn method(&self) -> bool { true }
|
||||
}
|
||||
|
||||
|
||||
pub fn main() {
|
||||
assert!(Foo.method());
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
//@ run-pass
|
||||
|
||||
mod inner {
|
||||
pub mod inner2 {
|
||||
pub fn hello() { println!("hello, modular world"); }
|
||||
}
|
||||
pub fn hello() { inner2::hello(); }
|
||||
}
|
||||
|
||||
pub fn main() { inner::hello(); inner::inner2::hello(); }
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
// see #9186
|
||||
|
||||
enum Bar<T> { What } //~ ERROR parameter `T` is never used
|
||||
|
||||
fn foo<T>() {
|
||||
static a: Bar<T> = Bar::What;
|
||||
//~^ ERROR can't use generic parameters from outer item
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
|
|
@ -1,3 +1,6 @@
|
|||
//! Check that a type mismatch error is reported when trying
|
||||
//! to unify a {float} value assignment to an {integer} variable.
|
||||
|
||||
fn main() {
|
||||
let mut x //~ NOTE expected due to the type of this binding
|
||||
=
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/integral-variable-unification-error.rs:5:9
|
||||
--> $DIR/int-float-type-mismatch.rs:8:9
|
||||
|
|
||||
LL | let mut x
|
||||
| ----- expected due to the type of this binding
|
||||
19
tests/ui/modules/nested-modules-basic.rs
Normal file
19
tests/ui/modules/nested-modules-basic.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
//! Basic test for nested module functionality and path resolution
|
||||
|
||||
//@ run-pass
|
||||
|
||||
mod inner {
|
||||
pub mod inner2 {
|
||||
pub fn hello() {
|
||||
println!("hello, modular world");
|
||||
}
|
||||
}
|
||||
pub fn hello() {
|
||||
inner2::hello();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
inner::hello();
|
||||
inner::inner2::hello();
|
||||
}
|
||||
20
tests/ui/statics/static-generic-param-soundness.rs
Normal file
20
tests/ui/statics/static-generic-param-soundness.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
//! Originally, inner statics in generic functions were generated only once, causing the same
|
||||
//! static to be shared across all generic instantiations. This created a soundness hole where
|
||||
//! different types could be coerced through thread-local storage in safe code.
|
||||
//!
|
||||
//! This test checks that generic parameters from outer scopes cannot be used in inner statics,
|
||||
//! preventing this soundness issue.
|
||||
//!
|
||||
//! See https://github.com/rust-lang/rust/issues/9186
|
||||
|
||||
enum Bar<T> {
|
||||
//~^ ERROR parameter `T` is never used
|
||||
What,
|
||||
}
|
||||
|
||||
fn foo<T>() {
|
||||
static a: Bar<T> = Bar::What;
|
||||
//~^ ERROR can't use generic parameters from outer item
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
error[E0401]: can't use generic parameters from outer item
|
||||
--> $DIR/inner-static-type-parameter.rs:6:19
|
||||
--> $DIR/static-generic-param-soundness.rs:16:19
|
||||
|
|
||||
LL | fn foo<T>() {
|
||||
| - type parameter from outer item
|
||||
|
|
@ -9,9 +9,9 @@ LL | static a: Bar<T> = Bar::What;
|
|||
= note: a `static` is a separate item from the item that contains it
|
||||
|
||||
error[E0392]: type parameter `T` is never used
|
||||
--> $DIR/inner-static-type-parameter.rs:3:10
|
||||
--> $DIR/static-generic-param-soundness.rs:10:10
|
||||
|
|
||||
LL | enum Bar<T> { What }
|
||||
LL | enum Bar<T> {
|
||||
| ^ unused type parameter
|
||||
|
|
||||
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
|
||||
|
|
@ -1,20 +1,30 @@
|
|||
//! Test various invalid implementations of DispatchFromDyn trait.
|
||||
//!
|
||||
//! DispatchFromDyn is a special trait used by the compiler for dyn-compatible dynamic dispatch.
|
||||
//! This checks that the compiler correctly rejects invalid implementations:
|
||||
//! - Structs with extra non-coercible fields
|
||||
//! - Structs with multiple pointer fields
|
||||
//! - Structs with no coercible fields
|
||||
//! - Structs with repr(C) or other incompatible representations
|
||||
//! - Structs with over-aligned fields
|
||||
|
||||
#![feature(unsize, dispatch_from_dyn)]
|
||||
|
||||
use std::{
|
||||
ops::DispatchFromDyn,
|
||||
marker::{Unsize, PhantomData},
|
||||
};
|
||||
use std::marker::{PhantomData, Unsize};
|
||||
use std::ops::DispatchFromDyn;
|
||||
|
||||
// Extra field prevents DispatchFromDyn
|
||||
struct WrapperWithExtraField<T>(T, i32);
|
||||
|
||||
impl<T, U> DispatchFromDyn<WrapperWithExtraField<U>> for WrapperWithExtraField<T>
|
||||
//~^ ERROR [E0378]
|
||||
where
|
||||
T: DispatchFromDyn<U>,
|
||||
{}
|
||||
T: DispatchFromDyn<U>
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
struct MultiplePointers<T: ?Sized>{
|
||||
// Multiple pointer fields create ambiguous coercion
|
||||
struct MultiplePointers<T: ?Sized> {
|
||||
ptr1: *const T,
|
||||
ptr2: *const T,
|
||||
}
|
||||
|
|
@ -22,10 +32,11 @@ struct MultiplePointers<T: ?Sized>{
|
|||
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<MultiplePointers<U>> for MultiplePointers<T>
|
||||
//~^ ERROR implementing `DispatchFromDyn` does not allow multiple fields to be coerced
|
||||
where
|
||||
T: Unsize<U>,
|
||||
{}
|
||||
|
||||
T: Unsize<U>
|
||||
{
|
||||
}
|
||||
|
||||
// No coercible fields (only PhantomData)
|
||||
struct NothingToCoerce<T: ?Sized> {
|
||||
data: PhantomData<T>,
|
||||
}
|
||||
|
|
@ -33,23 +44,28 @@ struct NothingToCoerce<T: ?Sized> {
|
|||
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<NothingToCoerce<T>> for NothingToCoerce<U> {}
|
||||
//~^ ERROR implementing `DispatchFromDyn` requires a field to be coerced
|
||||
|
||||
// repr(C) is incompatible with DispatchFromDyn
|
||||
#[repr(C)]
|
||||
struct HasReprC<T: ?Sized>(Box<T>);
|
||||
|
||||
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<HasReprC<U>> for HasReprC<T>
|
||||
//~^ ERROR [E0378]
|
||||
where
|
||||
T: Unsize<U>,
|
||||
{}
|
||||
T: Unsize<U>
|
||||
{
|
||||
}
|
||||
|
||||
// Over-aligned fields are incompatible
|
||||
#[repr(align(64))]
|
||||
struct OverAlignedZst;
|
||||
|
||||
struct OverAligned<T: ?Sized>(Box<T>, OverAlignedZst);
|
||||
|
||||
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<OverAligned<U>> for OverAligned<T>
|
||||
//~^ ERROR [E0378]
|
||||
where
|
||||
T: Unsize<U>,
|
||||
{}
|
||||
where
|
||||
T: Unsize<U>
|
||||
{
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,25 +1,25 @@
|
|||
error[E0378]: the trait `DispatchFromDyn` may only be implemented for structs containing the field being coerced, ZST fields with 1 byte alignment that don't mention type/const generics, and nothing else
|
||||
--> $DIR/invalid_dispatch_from_dyn_impls.rs:10:1
|
||||
--> $DIR/dispatch-from-dyn-invalid-impls.rs:19:1
|
||||
|
|
||||
LL | / impl<T, U> DispatchFromDyn<WrapperWithExtraField<U>> for WrapperWithExtraField<T>
|
||||
LL | |
|
||||
LL | | where
|
||||
LL | | T: DispatchFromDyn<U>,
|
||||
| |__________________________^
|
||||
LL | | T: DispatchFromDyn<U>
|
||||
| |_________________________^
|
||||
|
|
||||
= note: extra field `1` of type `i32` is not allowed
|
||||
|
||||
error[E0375]: implementing `DispatchFromDyn` does not allow multiple fields to be coerced
|
||||
--> $DIR/invalid_dispatch_from_dyn_impls.rs:22:1
|
||||
--> $DIR/dispatch-from-dyn-invalid-impls.rs:32:1
|
||||
|
|
||||
LL | / impl<T: ?Sized, U: ?Sized> DispatchFromDyn<MultiplePointers<U>> for MultiplePointers<T>
|
||||
LL | |
|
||||
LL | | where
|
||||
LL | | T: Unsize<U>,
|
||||
| |_________________^
|
||||
LL | | T: Unsize<U>
|
||||
| |________________^
|
||||
|
|
||||
note: the trait `DispatchFromDyn` may only be implemented when a single field is being coerced
|
||||
--> $DIR/invalid_dispatch_from_dyn_impls.rs:18:5
|
||||
--> $DIR/dispatch-from-dyn-invalid-impls.rs:28:5
|
||||
|
|
||||
LL | ptr1: *const T,
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
@ -27,7 +27,7 @@ LL | ptr2: *const T,
|
|||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error[E0374]: implementing `DispatchFromDyn` requires a field to be coerced
|
||||
--> $DIR/invalid_dispatch_from_dyn_impls.rs:33:1
|
||||
--> $DIR/dispatch-from-dyn-invalid-impls.rs:44:1
|
||||
|
|
||||
LL | impl<T: ?Sized, U: ?Sized> DispatchFromDyn<NothingToCoerce<T>> for NothingToCoerce<U> {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -35,22 +35,22 @@ LL | impl<T: ?Sized, U: ?Sized> DispatchFromDyn<NothingToCoerce<T>> for NothingT
|
|||
= note: expected a single field to be coerced, none found
|
||||
|
||||
error[E0378]: structs implementing `DispatchFromDyn` may not have `#[repr(packed)]` or `#[repr(C)]`
|
||||
--> $DIR/invalid_dispatch_from_dyn_impls.rs:39:1
|
||||
--> $DIR/dispatch-from-dyn-invalid-impls.rs:51:1
|
||||
|
|
||||
LL | / impl<T: ?Sized, U: ?Sized> DispatchFromDyn<HasReprC<U>> for HasReprC<T>
|
||||
LL | |
|
||||
LL | | where
|
||||
LL | | T: Unsize<U>,
|
||||
| |_________________^
|
||||
LL | | T: Unsize<U>
|
||||
| |________________^
|
||||
|
||||
error[E0378]: the trait `DispatchFromDyn` may only be implemented for structs containing the field being coerced, ZST fields with 1 byte alignment that don't mention type/const generics, and nothing else
|
||||
--> $DIR/invalid_dispatch_from_dyn_impls.rs:49:1
|
||||
--> $DIR/dispatch-from-dyn-invalid-impls.rs:64:1
|
||||
|
|
||||
LL | / impl<T: ?Sized, U: ?Sized> DispatchFromDyn<OverAligned<U>> for OverAligned<T>
|
||||
LL | |
|
||||
LL | | where
|
||||
LL | | T: Unsize<U>,
|
||||
| |_____________________^
|
||||
LL | | where
|
||||
LL | | T: Unsize<U>
|
||||
| |________________^
|
||||
|
|
||||
= note: extra field `1` of type `OverAlignedZst` is not allowed
|
||||
|
||||
|
|
@ -1,14 +1,23 @@
|
|||
//! Regression test for issue #11881
|
||||
//!
|
||||
//! Originally, the compiler would ICE when trying to parameterize on certain encoder types
|
||||
//! due to issues with higher-ranked trait bounds and lifetime inference. This test checks
|
||||
//! that various encoder patterns work correctly:
|
||||
//! - Generic encoders with associated error types
|
||||
//! - Higher-ranked trait bounds (for<'r> Encodable<JsonEncoder<'r>>)
|
||||
//! - Multiple encoder implementations for the same type
|
||||
//! - Polymorphic encoding functions
|
||||
|
||||
//@ run-pass
|
||||
|
||||
#![allow(unused_must_use)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use std::fmt;
|
||||
use std::io::prelude::*;
|
||||
use std::io::Cursor;
|
||||
use std::slice;
|
||||
use std::io::prelude::*;
|
||||
use std::marker::PhantomData;
|
||||
use std::{fmt, slice};
|
||||
|
||||
trait Encoder {
|
||||
type Error;
|
||||
|
|
@ -45,7 +54,6 @@ impl Encoder for OpaqueEncoder {
|
|||
type Error = ();
|
||||
}
|
||||
|
||||
|
||||
struct Foo {
|
||||
baz: bool,
|
||||
}
|
||||
|
|
@ -69,7 +77,6 @@ impl<S: Encoder> Encodable<S> for Bar {
|
|||
enum WireProtocol {
|
||||
JSON,
|
||||
Opaque,
|
||||
// ...
|
||||
}
|
||||
|
||||
fn encode_json<T: for<'a> Encodable<JsonEncoder<'a>>>(val: &T, wr: &mut Cursor<Vec<u8>>) {
|
||||
Loading…
Add table
Add a link
Reference in a new issue