about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/tools/tidy/src/issues.txt1
-rw-r--r--tests/ui/attributes/inner-attrs-impl-cfg.rs36
-rw-r--r--tests/ui/indexing/indexing-integral-types.rs (renamed from tests/ui/integral-indexing.rs)12
-rw-r--r--tests/ui/indexing/indexing-integral-types.stderr (renamed from tests/ui/integral-indexing.stderr)16
-rw-r--r--tests/ui/inner-attrs-on-impl.rs24
-rw-r--r--tests/ui/inner-module.rs10
-rw-r--r--tests/ui/inner-static-type-parameter.rs11
-rw-r--r--tests/ui/mismatched_types/int-float-type-mismatch.rs (renamed from tests/ui/integral-variable-unification-error.rs)3
-rw-r--r--tests/ui/mismatched_types/int-float-type-mismatch.stderr (renamed from tests/ui/integral-variable-unification-error.stderr)2
-rw-r--r--tests/ui/modules/nested-modules-basic.rs19
-rw-r--r--tests/ui/statics/static-generic-param-soundness.rs20
-rw-r--r--tests/ui/statics/static-generic-param-soundness.stderr (renamed from tests/ui/inner-static-type-parameter.stderr)6
-rw-r--r--tests/ui/traits/dispatch-from-dyn-invalid-impls.rs (renamed from tests/ui/invalid_dispatch_from_dyn_impls.rs)48
-rw-r--r--tests/ui/traits/dispatch-from-dyn-invalid-impls.stderr (renamed from tests/ui/invalid_dispatch_from_dyn_impls.stderr)30
-rw-r--r--tests/ui/traits/encoder-trait-bounds-regression.rs (renamed from tests/ui/issue-11881.rs)17
15 files changed, 157 insertions, 98 deletions
diff --git a/src/tools/tidy/src/issues.txt b/src/tools/tidy/src/issues.txt
index b3517b2e9da..38c6da5ba96 100644
--- a/src/tools/tidy/src/issues.txt
+++ b/src/tools/tidy/src/issues.txt
@@ -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
diff --git a/tests/ui/attributes/inner-attrs-impl-cfg.rs b/tests/ui/attributes/inner-attrs-impl-cfg.rs
new file mode 100644
index 00000000000..e7a5cfa9e2f
--- /dev/null
+++ b/tests/ui/attributes/inner-attrs-impl-cfg.rs
@@ -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());
+}
diff --git a/tests/ui/integral-indexing.rs b/tests/ui/indexing/indexing-integral-types.rs
index e20553af8a2..a91696a6fd5 100644
--- a/tests/ui/integral-indexing.rs
+++ b/tests/ui/indexing/indexing-integral-types.rs
@@ -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`
 }
diff --git a/tests/ui/integral-indexing.stderr b/tests/ui/indexing/indexing-integral-types.stderr
index 26253e078cb..b63991ec2c4 100644
--- a/tests/ui/integral-indexing.stderr
+++ b/tests/ui/indexing/indexing-integral-types.stderr
@@ -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`
diff --git a/tests/ui/inner-attrs-on-impl.rs b/tests/ui/inner-attrs-on-impl.rs
deleted file mode 100644
index 1dce1cdd261..00000000000
--- a/tests/ui/inner-attrs-on-impl.rs
+++ /dev/null
@@ -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());
-}
diff --git a/tests/ui/inner-module.rs b/tests/ui/inner-module.rs
deleted file mode 100644
index 111f2cab857..00000000000
--- a/tests/ui/inner-module.rs
+++ /dev/null
@@ -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(); }
diff --git a/tests/ui/inner-static-type-parameter.rs b/tests/ui/inner-static-type-parameter.rs
deleted file mode 100644
index a1994e7529c..00000000000
--- a/tests/ui/inner-static-type-parameter.rs
+++ /dev/null
@@ -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() {
-}
diff --git a/tests/ui/integral-variable-unification-error.rs b/tests/ui/mismatched_types/int-float-type-mismatch.rs
index 8d1621321e8..b45d02730d9 100644
--- a/tests/ui/integral-variable-unification-error.rs
+++ b/tests/ui/mismatched_types/int-float-type-mismatch.rs
@@ -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
         =
diff --git a/tests/ui/integral-variable-unification-error.stderr b/tests/ui/mismatched_types/int-float-type-mismatch.stderr
index 1caa6042fd2..43b8609a49d 100644
--- a/tests/ui/integral-variable-unification-error.stderr
+++ b/tests/ui/mismatched_types/int-float-type-mismatch.stderr
@@ -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
diff --git a/tests/ui/modules/nested-modules-basic.rs b/tests/ui/modules/nested-modules-basic.rs
new file mode 100644
index 00000000000..12eccec2808
--- /dev/null
+++ b/tests/ui/modules/nested-modules-basic.rs
@@ -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();
+}
diff --git a/tests/ui/statics/static-generic-param-soundness.rs b/tests/ui/statics/static-generic-param-soundness.rs
new file mode 100644
index 00000000000..aabcca514d3
--- /dev/null
+++ b/tests/ui/statics/static-generic-param-soundness.rs
@@ -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() {}
diff --git a/tests/ui/inner-static-type-parameter.stderr b/tests/ui/statics/static-generic-param-soundness.stderr
index 88d33b44c59..47554c7fcb0 100644
--- a/tests/ui/inner-static-type-parameter.stderr
+++ b/tests/ui/statics/static-generic-param-soundness.stderr
@@ -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`
diff --git a/tests/ui/invalid_dispatch_from_dyn_impls.rs b/tests/ui/traits/dispatch-from-dyn-invalid-impls.rs
index b1d4b261bab..f5f66ca69cf 100644
--- a/tests/ui/invalid_dispatch_from_dyn_impls.rs
+++ b/tests/ui/traits/dispatch-from-dyn-invalid-impls.rs
@@ -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() {}
diff --git a/tests/ui/invalid_dispatch_from_dyn_impls.stderr b/tests/ui/traits/dispatch-from-dyn-invalid-impls.stderr
index 93ec6bbe089..676da0ce81f 100644
--- a/tests/ui/invalid_dispatch_from_dyn_impls.stderr
+++ b/tests/ui/traits/dispatch-from-dyn-invalid-impls.stderr
@@ -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
 
diff --git a/tests/ui/issue-11881.rs b/tests/ui/traits/encoder-trait-bounds-regression.rs
index 1abe0797203..292b921cdf7 100644
--- a/tests/ui/issue-11881.rs
+++ b/tests/ui/traits/encoder-trait-bounds-regression.rs
@@ -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>>) {