Skip to content

Commit 91d7c30

Browse files
committed
cleaned up some tests
1 parent 36b2163 commit 91d7c30

15 files changed

+157
-98
lines changed

src/tools/tidy/src/issues.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,6 @@ ui/infinite/issue-41731-infinite-macro-println.rs
13681368
ui/intrinsics/issue-28575.rs
13691369
ui/intrinsics/issue-84297-reifying-copy.rs
13701370
ui/invalid/issue-114435-layout-type-err.rs
1371-
ui/issue-11881.rs
13721371
ui/issue-15924.rs
13731372
ui/issue-16822.rs
13741373
ui/issues-71798.rs
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//! Test inner attributes (#![...]) behavior in impl blocks with cfg conditions.
2+
//!
3+
//! This test verifies that:
4+
//! - Inner attributes can conditionally exclude entire impl blocks
5+
//! - Regular attributes within impl blocks work independently
6+
//! - Attribute parsing doesn't consume too eagerly
7+
8+
//@ run-pass
9+
10+
struct Foo;
11+
12+
impl Foo {
13+
#![cfg(false)]
14+
15+
fn method(&self) -> bool {
16+
false
17+
}
18+
}
19+
20+
impl Foo {
21+
#![cfg(not(FALSE))]
22+
23+
// Check that we don't eat attributes too eagerly.
24+
#[cfg(false)]
25+
fn method(&self) -> bool {
26+
false
27+
}
28+
29+
fn method(&self) -> bool {
30+
true
31+
}
32+
}
33+
34+
pub fn main() {
35+
assert!(Foo.method());
36+
}
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1+
//! Test that only usize can be used for indexing arrays and slices.
2+
13
pub fn main() {
24
let v: Vec<isize> = vec![0, 1, 2, 3, 4, 5];
35
let s: String = "abcdef".to_string();
6+
7+
// Valid indexing with usize
48
v[3_usize];
59
v[3];
6-
v[3u8]; //~ ERROR the type `[isize]` cannot be indexed by `u8`
7-
v[3i8]; //~ ERROR the type `[isize]` cannot be indexed by `i8`
10+
v[3u8]; //~ ERROR the type `[isize]` cannot be indexed by `u8`
11+
v[3i8]; //~ ERROR the type `[isize]` cannot be indexed by `i8`
812
v[3u32]; //~ ERROR the type `[isize]` cannot be indexed by `u32`
913
v[3i32]; //~ ERROR the type `[isize]` cannot be indexed by `i32`
1014
s.as_bytes()[3_usize];
1115
s.as_bytes()[3];
12-
s.as_bytes()[3u8]; //~ ERROR the type `[u8]` cannot be indexed by `u8`
13-
s.as_bytes()[3i8]; //~ ERROR the type `[u8]` cannot be indexed by `i8`
16+
s.as_bytes()[3u8]; //~ ERROR the type `[u8]` cannot be indexed by `u8`
17+
s.as_bytes()[3i8]; //~ ERROR the type `[u8]` cannot be indexed by `i8`
1418
s.as_bytes()[3u32]; //~ ERROR the type `[u8]` cannot be indexed by `u32`
1519
s.as_bytes()[3i32]; //~ ERROR the type `[u8]` cannot be indexed by `i32`
1620
}

tests/ui/integral-indexing.stderr renamed to tests/ui/indexing/indexing-integral-types.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: the type `[isize]` cannot be indexed by `u8`
2-
--> $DIR/integral-indexing.rs:6:7
2+
--> $DIR/indexing-integral-types.rs:10:7
33
|
44
LL | v[3u8];
55
| ^^^ slice indices are of type `usize` or ranges of `usize`
@@ -11,7 +11,7 @@ LL | v[3u8];
1111
= note: required for `Vec<isize>` to implement `Index<u8>`
1212

1313
error[E0277]: the type `[isize]` cannot be indexed by `i8`
14-
--> $DIR/integral-indexing.rs:7:7
14+
--> $DIR/indexing-integral-types.rs:11:7
1515
|
1616
LL | v[3i8];
1717
| ^^^ slice indices are of type `usize` or ranges of `usize`
@@ -23,7 +23,7 @@ LL | v[3i8];
2323
= note: required for `Vec<isize>` to implement `Index<i8>`
2424

2525
error[E0277]: the type `[isize]` cannot be indexed by `u32`
26-
--> $DIR/integral-indexing.rs:8:7
26+
--> $DIR/indexing-integral-types.rs:12:7
2727
|
2828
LL | v[3u32];
2929
| ^^^^ slice indices are of type `usize` or ranges of `usize`
@@ -35,7 +35,7 @@ LL | v[3u32];
3535
= note: required for `Vec<isize>` to implement `Index<u32>`
3636

3737
error[E0277]: the type `[isize]` cannot be indexed by `i32`
38-
--> $DIR/integral-indexing.rs:9:7
38+
--> $DIR/indexing-integral-types.rs:13:7
3939
|
4040
LL | v[3i32];
4141
| ^^^^ slice indices are of type `usize` or ranges of `usize`
@@ -47,7 +47,7 @@ LL | v[3i32];
4747
= note: required for `Vec<isize>` to implement `Index<i32>`
4848

4949
error[E0277]: the type `[u8]` cannot be indexed by `u8`
50-
--> $DIR/integral-indexing.rs:12:18
50+
--> $DIR/indexing-integral-types.rs:16:18
5151
|
5252
LL | s.as_bytes()[3u8];
5353
| ^^^ slice indices are of type `usize` or ranges of `usize`
@@ -59,7 +59,7 @@ LL | s.as_bytes()[3u8];
5959
= note: required for `[u8]` to implement `Index<u8>`
6060

6161
error[E0277]: the type `[u8]` cannot be indexed by `i8`
62-
--> $DIR/integral-indexing.rs:13:18
62+
--> $DIR/indexing-integral-types.rs:17:18
6363
|
6464
LL | s.as_bytes()[3i8];
6565
| ^^^ slice indices are of type `usize` or ranges of `usize`
@@ -71,7 +71,7 @@ LL | s.as_bytes()[3i8];
7171
= note: required for `[u8]` to implement `Index<i8>`
7272

7373
error[E0277]: the type `[u8]` cannot be indexed by `u32`
74-
--> $DIR/integral-indexing.rs:14:18
74+
--> $DIR/indexing-integral-types.rs:18:18
7575
|
7676
LL | s.as_bytes()[3u32];
7777
| ^^^^ slice indices are of type `usize` or ranges of `usize`
@@ -83,7 +83,7 @@ LL | s.as_bytes()[3u32];
8383
= note: required for `[u8]` to implement `Index<u32>`
8484

8585
error[E0277]: the type `[u8]` cannot be indexed by `i32`
86-
--> $DIR/integral-indexing.rs:15:18
86+
--> $DIR/indexing-integral-types.rs:19:18
8787
|
8888
LL | s.as_bytes()[3i32];
8989
| ^^^^ slice indices are of type `usize` or ranges of `usize`

tests/ui/inner-attrs-on-impl.rs

Lines changed: 0 additions & 24 deletions
This file was deleted.

tests/ui/inner-module.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/ui/inner-static-type-parameter.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/ui/integral-variable-unification-error.rs renamed to tests/ui/mismatched_types/int-float-type-mismatch.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Check that a type mismatch error is reported when trying
2+
//! to unify a {float} value assignment to an {integer} variable.
3+
14
fn main() {
25
let mut x //~ NOTE expected due to the type of this binding
36
=

tests/ui/integral-variable-unification-error.stderr renamed to tests/ui/mismatched_types/int-float-type-mismatch.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/integral-variable-unification-error.rs:5:9
2+
--> $DIR/int-float-type-mismatch.rs:8:9
33
|
44
LL | let mut x
55
| ----- expected due to the type of this binding
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//! Basic test for nested module functionality and path resolution
2+
3+
//@ run-pass
4+
5+
mod inner {
6+
pub mod inner2 {
7+
pub fn hello() {
8+
println!("hello, modular world");
9+
}
10+
}
11+
pub fn hello() {
12+
inner2::hello();
13+
}
14+
}
15+
16+
pub fn main() {
17+
inner::hello();
18+
inner::inner2::hello();
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! Originally, inner statics in generic functions were generated only once, causing the same
2+
//! static to be shared across all generic instantiations. This created a soundness hole where
3+
//! different types could be coerced through thread-local storage in safe code.
4+
//!
5+
//! This test checks that generic parameters from outer scopes cannot be used in inner statics,
6+
//! preventing this soundness issue.
7+
//!
8+
//! See https://github.com/rust-lang/rust/issues/9186
9+
10+
enum Bar<T> {
11+
//~^ ERROR parameter `T` is never used
12+
What,
13+
}
14+
15+
fn foo<T>() {
16+
static a: Bar<T> = Bar::What;
17+
//~^ ERROR can't use generic parameters from outer item
18+
}
19+
20+
fn main() {}

tests/ui/inner-static-type-parameter.stderr renamed to tests/ui/statics/static-generic-param-soundness.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0401]: can't use generic parameters from outer item
2-
--> $DIR/inner-static-type-parameter.rs:6:19
2+
--> $DIR/static-generic-param-soundness.rs:16:19
33
|
44
LL | fn foo<T>() {
55
| - type parameter from outer item
@@ -9,9 +9,9 @@ LL | static a: Bar<T> = Bar::What;
99
= note: a `static` is a separate item from the item that contains it
1010

1111
error[E0392]: type parameter `T` is never used
12-
--> $DIR/inner-static-type-parameter.rs:3:10
12+
--> $DIR/static-generic-param-soundness.rs:10:10
1313
|
14-
LL | enum Bar<T> { What }
14+
LL | enum Bar<T> {
1515
| ^ unused type parameter
1616
|
1717
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,71 @@
1+
//! Test various invalid implementations of DispatchFromDyn trait.
2+
//!
3+
//! DispatchFromDyn is a special trait used by the compiler for dyn-compatible dynamic dispatch.
4+
//! This checks that the compiler correctly rejects invalid implementations:
5+
//! - Structs with extra non-coercible fields
6+
//! - Structs with multiple pointer fields
7+
//! - Structs with no coercible fields
8+
//! - Structs with repr(C) or other incompatible representations
9+
//! - Structs with over-aligned fields
10+
111
#![feature(unsize, dispatch_from_dyn)]
212

3-
use std::{
4-
ops::DispatchFromDyn,
5-
marker::{Unsize, PhantomData},
6-
};
13+
use std::marker::{PhantomData, Unsize};
14+
use std::ops::DispatchFromDyn;
715

16+
// Extra field prevents DispatchFromDyn
817
struct WrapperWithExtraField<T>(T, i32);
918

1019
impl<T, U> DispatchFromDyn<WrapperWithExtraField<U>> for WrapperWithExtraField<T>
1120
//~^ ERROR [E0378]
1221
where
13-
T: DispatchFromDyn<U>,
14-
{}
15-
22+
T: DispatchFromDyn<U>
23+
{
24+
}
1625

17-
struct MultiplePointers<T: ?Sized>{
26+
// Multiple pointer fields create ambiguous coercion
27+
struct MultiplePointers<T: ?Sized> {
1828
ptr1: *const T,
1929
ptr2: *const T,
2030
}
2131

2232
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<MultiplePointers<U>> for MultiplePointers<T>
2333
//~^ ERROR implementing `DispatchFromDyn` does not allow multiple fields to be coerced
2434
where
25-
T: Unsize<U>,
26-
{}
27-
35+
T: Unsize<U>
36+
{
37+
}
2838

39+
// Error: No coercible fields (only PhantomData)
2940
struct NothingToCoerce<T: ?Sized> {
3041
data: PhantomData<T>,
3142
}
3243

3344
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<NothingToCoerce<T>> for NothingToCoerce<U> {}
3445
//~^ ERROR implementing `DispatchFromDyn` requires a field to be coerced
3546

47+
// repr(C) is incompatible with DispatchFromDyn
3648
#[repr(C)]
3749
struct HasReprC<T: ?Sized>(Box<T>);
3850

3951
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<HasReprC<U>> for HasReprC<T>
4052
//~^ ERROR [E0378]
4153
where
42-
T: Unsize<U>,
43-
{}
54+
T: Unsize<U>
55+
{
56+
}
4457

58+
// Over-aligned fields are incompatible
4559
#[repr(align(64))]
4660
struct OverAlignedZst;
61+
4762
struct OverAligned<T: ?Sized>(Box<T>, OverAlignedZst);
4863

4964
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<OverAligned<U>> for OverAligned<T>
5065
//~^ ERROR [E0378]
51-
where
52-
T: Unsize<U>,
53-
{}
66+
where
67+
T: Unsize<U>
68+
{
69+
}
5470

5571
fn main() {}

0 commit comments

Comments
 (0)