about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-03-16 02:02:45 +0000
committerbors <bors@rust-lang.org>2025-03-16 02:02:45 +0000
commit66678e68227913a42438afc7320a2849dffd4d51 (patch)
tree53b60463906a2137e02ed8fc2c56528b1710ae11 /tests
parent9f274ba3997030a2b7656755a6810fd26cb709f3 (diff)
parentf4372f5d121d2b2a8aa39b432aeef7127e17497f (diff)
downloadrust-66678e68227913a42438afc7320a2849dffd4d51.tar.gz
rust-66678e68227913a42438afc7320a2849dffd4d51.zip
Auto merge of #138548 - jieyouxu:rollup-xpslct5, r=jieyouxu
Rollup of 16 pull requests

Successful merges:

 - #133055 (Expand `CloneToUninit` documentation.)
 - #137147 (Add exclude to config.toml)
 - #137864 (Don't drop `Rvalue::WrapUnsafeBinder` during GVN)
 - #137890 (doc: clarify that consume can be called after BufReader::peek)
 - #137956 (Add RTN support to rustdoc)
 - #137968 (Properly escape regexes in Python scripts)
 - #138082 (Remove `#[cfg(not(test))]` gates in `core`)
 - #138275 (expose `is_s390x_feature_detected!` from `std::arch`)
 - #138303 (Fix Ptr inconsistency in {Rc,Arc})
 - #138309 (Add missing doc for intrinsic (Fix PR135334))
 - #138323 (Expand and organize `offset_of!` documentation.)
 - #138329 (debug-assert that the size_hint is well-formed in `collect`)
 - #138465 (linkchecker: bump html5ever)
 - #138471 (Clean up some tests in tests/ui)
 - #138472 (Add codegen test for #129795)
 - #138484 (Use lit span when suggesting suffix lit cast)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'tests')
-rw-r--r--tests/codegen/issues/issue-129795.rs17
-rw-r--r--tests/mir-opt/gvn_on_unsafe_binder.propagate.GVN.diff35
-rw-r--r--tests/mir-opt/gvn_on_unsafe_binder.rs29
-rw-r--r--tests/mir-opt/gvn_on_unsafe_binder.test.GVN.diff30
-rw-r--r--tests/rustdoc-json/return-type-notation.rs18
-rw-r--r--tests/rustdoc/return-type-notation.rs18
-rw-r--r--tests/ui/attributes/outer-mod-attr-applies-only-to-first.rs16
-rw-r--r--tests/ui/cast/cast_lit_suffix-issue-138392.fixed6
-rw-r--r--tests/ui/cast/cast_lit_suffix-issue-138392.rs6
-rw-r--r--tests/ui/cast/cast_lit_suffix-issue-138392.stderr31
-rw-r--r--tests/ui/dupe-first-attr.rs25
-rw-r--r--tests/ui/duplicate_entry_error.rs18
-rw-r--r--tests/ui/error-codes/E0152-duplicate-lang-items.rs20
-rw-r--r--tests/ui/error-codes/E0152-duplicate-lang-items.stderr (renamed from tests/ui/duplicate_entry_error.stderr)6
-rw-r--r--tests/ui/error-codes/E0381-duplicated-label.rs (renamed from tests/ui/duplicate-label-E0381-issue-129274.rs)3
-rw-r--r--tests/ui/error-codes/E0381-duplicated-label.stderr (renamed from tests/ui/duplicate-label-E0381-issue-129274.stderr)2
16 files changed, 233 insertions, 47 deletions
diff --git a/tests/codegen/issues/issue-129795.rs b/tests/codegen/issues/issue-129795.rs
new file mode 100644
index 00000000000..dc64ee35c97
--- /dev/null
+++ b/tests/codegen/issues/issue-129795.rs
@@ -0,0 +1,17 @@
+//@ compile-flags: -Copt-level=3
+//@ min-llvm-version: 20
+#![crate_type = "lib"]
+
+// Ensure that a modulo operation with an operand that is known to be
+// a power-of-two is properly optimized.
+
+// CHECK-LABEL: @modulo_with_power_of_two_divisor
+// CHECK: add i64 %divisor, -1
+// CHECK-NEXT: and i64
+// CHECK-NEXT: ret i64
+#[no_mangle]
+pub fn modulo_with_power_of_two_divisor(dividend: u64, divisor: u64) -> u64 {
+    assert!(divisor.is_power_of_two());
+    // should be optimized to (dividend & (divisor - 1))
+    dividend % divisor
+}
diff --git a/tests/mir-opt/gvn_on_unsafe_binder.propagate.GVN.diff b/tests/mir-opt/gvn_on_unsafe_binder.propagate.GVN.diff
new file mode 100644
index 00000000000..e28d04f1d58
--- /dev/null
+++ b/tests/mir-opt/gvn_on_unsafe_binder.propagate.GVN.diff
@@ -0,0 +1,35 @@
+- // MIR for `propagate` before GVN
++ // MIR for `propagate` after GVN
+  
+  fn propagate() -> unsafe<> i32 {
+      let mut _0: unsafe<> i32;
+      let _1: i32;
+      let mut _3: i32;
+      scope 1 {
+          debug x => _1;
+          let _2: unsafe<> i32;
+          scope 2 {
+              debug binder => _2;
+          }
+      }
+  
+      bb0: {
+-         StorageLive(_1);
++         nop;
+          _1 = const 1_i32;
+          StorageLive(_2);
+          StorageLive(_3);
+-         _3 = copy _1;
+-         _2 = wrap_binder!(move _3; unsafe<> i32);
++         _3 = const 1_i32;
++         _2 = const {transmute(0x00000001): unsafe<> i32};
+          StorageDead(_3);
+-         _0 = move _2;
++         _0 = const {transmute(0x00000001): unsafe<> i32};
+          StorageDead(_2);
+-         StorageDead(_1);
++         nop;
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/gvn_on_unsafe_binder.rs b/tests/mir-opt/gvn_on_unsafe_binder.rs
new file mode 100644
index 00000000000..b3c0576f990
--- /dev/null
+++ b/tests/mir-opt/gvn_on_unsafe_binder.rs
@@ -0,0 +1,29 @@
+// skip-filecheck
+//@ test-mir-pass: GVN
+
+// EMIT_MIR gvn_on_unsafe_binder.test.GVN.diff
+// EMIT_MIR gvn_on_unsafe_binder.propagate.GVN.diff
+
+#![feature(unsafe_binders)]
+
+use std::unsafe_binder::wrap_binder;
+
+// Test for ICE <https://github.com/rust-lang/rust/issues/137846>.
+fn test() {
+    unsafe {
+        let x = 1;
+        let binder: unsafe<'a> &'a i32 = wrap_binder!(&x);
+    }
+}
+
+// Test that GVN propagates const values through unsafe binders.
+//
+// The lifetime `'a` is redundant (and doesn't print when we print out the type).
+// However, we need it so that rustfmt doesn't rip out the `unsafe<>` part for now.
+fn propagate() -> unsafe<'a> i32 {
+    unsafe {
+        let x = 1;
+        let binder: unsafe<'a> i32 = wrap_binder!(x);
+        binder
+    }
+}
diff --git a/tests/mir-opt/gvn_on_unsafe_binder.test.GVN.diff b/tests/mir-opt/gvn_on_unsafe_binder.test.GVN.diff
new file mode 100644
index 00000000000..33814fb34f3
--- /dev/null
+++ b/tests/mir-opt/gvn_on_unsafe_binder.test.GVN.diff
@@ -0,0 +1,30 @@
+- // MIR for `test` before GVN
++ // MIR for `test` after GVN
+  
+  fn test() -> () {
+      let mut _0: ();
+      let _1: i32;
+      let mut _3: &i32;
+      scope 1 {
+          debug x => _1;
+          let _2: unsafe<'a> &'a i32;
+          scope 2 {
+              debug binder => _2;
+          }
+      }
+  
+      bb0: {
+          StorageLive(_1);
+          _1 = const 1_i32;
+          StorageLive(_2);
+          StorageLive(_3);
+          _3 = &_1;
+          _2 = wrap_binder!(move _3; unsafe<'a> &'a i32);
+          StorageDead(_3);
+          _0 = const ();
+          StorageDead(_2);
+          StorageDead(_1);
+          return;
+      }
+  }
+  
diff --git a/tests/rustdoc-json/return-type-notation.rs b/tests/rustdoc-json/return-type-notation.rs
new file mode 100644
index 00000000000..2219642bfc5
--- /dev/null
+++ b/tests/rustdoc-json/return-type-notation.rs
@@ -0,0 +1,18 @@
+//@ edition: 2021
+// ignore-tidy-linelength
+
+#![crate_type = "lib"]
+#![feature(return_type_notation)]
+
+pub trait Foo {
+    async fn bar();
+}
+
+//@ is "$.index[*][?(@.name=='foo')].inner.function.generics.params[0].kind.type.bounds[0].trait_bound.trait.args.angle_bracketed.constraints[0].args" '"return_type_notation"'
+//@ ismany "$.index[*][?(@.name=='foo')].inner.function.generics.where_predicates[*].bound_predicate.type.qualified_path.args" '"return_type_notation"' '"return_type_notation"'
+pub fn foo<T: Foo<bar(..): Send>>()
+where
+    <T as Foo>::bar(..): 'static,
+    T::bar(..): Sync,
+{
+}
diff --git a/tests/rustdoc/return-type-notation.rs b/tests/rustdoc/return-type-notation.rs
new file mode 100644
index 00000000000..405e98eb28d
--- /dev/null
+++ b/tests/rustdoc/return-type-notation.rs
@@ -0,0 +1,18 @@
+//@ edition: 2021
+
+#![crate_type = "lib"]
+#![feature(return_type_notation)]
+
+pub trait Foo {
+    async fn bar();
+}
+
+//@ has "return_type_notation/fn.foo.html"
+//@ has - '//pre[@class="rust item-decl"]' "pub fn foo<T: Foo<bar(..): Send>>()"
+//@ has - '//pre[@class="rust item-decl"]' "where <T as Foo>::bar(..): 'static, T::bar(..): Sync"
+pub fn foo<T: Foo<bar(..): Send>>()
+where
+    <T as Foo>::bar(..): 'static,
+    T::bar(..): Sync,
+{
+}
diff --git a/tests/ui/attributes/outer-mod-attr-applies-only-to-first.rs b/tests/ui/attributes/outer-mod-attr-applies-only-to-first.rs
new file mode 100644
index 00000000000..ec521c1afb5
--- /dev/null
+++ b/tests/ui/attributes/outer-mod-attr-applies-only-to-first.rs
@@ -0,0 +1,16 @@
+//! Regression test to check that outer attributes applied to the first module item is applied to
+//! its attached module item only, and not also to other subsequent module items
+//!
+//! Commit: <https://github.com/rust-lang/rust/commit/7aee9f7b56f8d96f9444ebb1d06e32e024b81974>
+
+//@ check-pass
+//@ compile-flags: --cfg=first
+//@ no-auto-check-cfg
+
+#[cfg(first)]
+mod hello {}
+
+#[cfg(not_set)]
+mod hello {}
+
+fn main() {}
diff --git a/tests/ui/cast/cast_lit_suffix-issue-138392.fixed b/tests/ui/cast/cast_lit_suffix-issue-138392.fixed
new file mode 100644
index 00000000000..c6fbd09f89c
--- /dev/null
+++ b/tests/ui/cast/cast_lit_suffix-issue-138392.fixed
@@ -0,0 +1,6 @@
+//@ run-rustfix
+#![allow(unused_parens)]
+fn main() {
+    let _x: u8 = (4u8); //~ ERROR: mismatched types
+    let _y: u8 = (4u8); //~ ERROR: mismatched types
+}
diff --git a/tests/ui/cast/cast_lit_suffix-issue-138392.rs b/tests/ui/cast/cast_lit_suffix-issue-138392.rs
new file mode 100644
index 00000000000..86dbbbbf126
--- /dev/null
+++ b/tests/ui/cast/cast_lit_suffix-issue-138392.rs
@@ -0,0 +1,6 @@
+//@ run-rustfix
+#![allow(unused_parens)]
+fn main() {
+    let _x: u8 = (4i32); //~ ERROR: mismatched types
+    let _y: u8 = (4.0f32); //~ ERROR: mismatched types
+}
diff --git a/tests/ui/cast/cast_lit_suffix-issue-138392.stderr b/tests/ui/cast/cast_lit_suffix-issue-138392.stderr
new file mode 100644
index 00000000000..998fcfc36dc
--- /dev/null
+++ b/tests/ui/cast/cast_lit_suffix-issue-138392.stderr
@@ -0,0 +1,31 @@
+error[E0308]: mismatched types
+  --> $DIR/cast_lit_suffix-issue-138392.rs:4:18
+   |
+LL |     let _x: u8 = (4i32);
+   |             --   ^^^^^^ expected `u8`, found `i32`
+   |             |
+   |             expected due to this
+   |
+help: change the type of the numeric literal from `i32` to `u8`
+   |
+LL -     let _x: u8 = (4i32);
+LL +     let _x: u8 = (4u8);
+   |
+
+error[E0308]: mismatched types
+  --> $DIR/cast_lit_suffix-issue-138392.rs:5:18
+   |
+LL |     let _y: u8 = (4.0f32);
+   |             --   ^^^^^^^^ expected `u8`, found `f32`
+   |             |
+   |             expected due to this
+   |
+help: change the type of the numeric literal from `f32` to `u8`
+   |
+LL -     let _y: u8 = (4.0f32);
+LL +     let _y: u8 = (4u8);
+   |
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/dupe-first-attr.rs b/tests/ui/dupe-first-attr.rs
deleted file mode 100644
index c254df050c1..00000000000
--- a/tests/ui/dupe-first-attr.rs
+++ /dev/null
@@ -1,25 +0,0 @@
-//@ run-pass
-
-// Regression test for a problem with the first mod attribute
-// being applied to every mod
-
-
-#[cfg(target_os = "linux")]
-mod hello {}
-
-#[cfg(target_os = "macos")]
-mod hello {}
-
-#[cfg(target_os = "windows")]
-mod hello {}
-
-#[cfg(target_os = "freebsd")]
-mod hello {}
-
-#[cfg(target_os = "dragonfly")]
-mod hello {}
-
-#[cfg(target_os = "android")]
-mod hello {}
-
-fn main() {}
diff --git a/tests/ui/duplicate_entry_error.rs b/tests/ui/duplicate_entry_error.rs
deleted file mode 100644
index 5a25802c6e7..00000000000
--- a/tests/ui/duplicate_entry_error.rs
+++ /dev/null
@@ -1,18 +0,0 @@
-//@ normalize-stderr: "loaded from .*libstd-.*.rlib" -> "loaded from SYSROOT/libstd-*.rlib"
-// note-pattern: first defined in crate `std`.
-
-// Test for issue #31788 and E0152
-
-#![feature(lang_items)]
-
-extern crate core;
-
-use core::panic::PanicInfo;
-
-#[lang = "panic_impl"]
-fn panic_impl(info: &PanicInfo) -> ! {
-//~^ ERROR: found duplicate lang item `panic_impl`
-    loop {}
-}
-
-fn main() {}
diff --git a/tests/ui/error-codes/E0152-duplicate-lang-items.rs b/tests/ui/error-codes/E0152-duplicate-lang-items.rs
new file mode 100644
index 00000000000..089810b1ad2
--- /dev/null
+++ b/tests/ui/error-codes/E0152-duplicate-lang-items.rs
@@ -0,0 +1,20 @@
+//! Validates the correct printing of E0152 in the case of duplicate "lang_item" function
+//! definitions.
+//!
+//! Issue: <https://github.com/rust-lang/rust/issues/31788>
+
+//@ error-pattern: first defined in crate `std`
+//@ normalize-stderr: "loaded from .*libstd-.*.rlib" -> "loaded from SYSROOT/libstd-*.rlib"
+#![feature(lang_items)]
+
+extern crate core;
+
+use core::panic::PanicInfo;
+
+#[lang = "panic_impl"]
+fn panic_impl(info: &PanicInfo) -> ! {
+    //~^ ERROR: found duplicate lang item `panic_impl`
+    loop {}
+}
+
+fn main() {}
diff --git a/tests/ui/duplicate_entry_error.stderr b/tests/ui/error-codes/E0152-duplicate-lang-items.stderr
index 958e9c7527d..3c3d64322f3 100644
--- a/tests/ui/duplicate_entry_error.stderr
+++ b/tests/ui/error-codes/E0152-duplicate-lang-items.stderr
@@ -1,5 +1,5 @@
 error[E0152]: found duplicate lang item `panic_impl`
-  --> $DIR/duplicate_entry_error.rs:13:1
+  --> $DIR/E0152-duplicate-lang-items.rs:15:1
    |
 LL | / fn panic_impl(info: &PanicInfo) -> ! {
 LL | |
@@ -7,9 +7,9 @@ LL | |     loop {}
 LL | | }
    | |_^
    |
-   = note: the lang item is first defined in crate `std` (which `duplicate_entry_error` depends on)
+   = note: the lang item is first defined in crate `std` (which `E0152_duplicate_lang_items` depends on)
    = note: first definition in `std` loaded from SYSROOT/libstd-*.rlib
-   = note: second definition in the local crate (`duplicate_entry_error`)
+   = note: second definition in the local crate (`E0152_duplicate_lang_items`)
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/duplicate-label-E0381-issue-129274.rs b/tests/ui/error-codes/E0381-duplicated-label.rs
index b2156e630c8..84a85caa65d 100644
--- a/tests/ui/duplicate-label-E0381-issue-129274.rs
+++ b/tests/ui/error-codes/E0381-duplicated-label.rs
@@ -1,3 +1,6 @@
+//! Regression test for duplicated label in E0381 error message.
+//!
+//! Issue: <https://github.com/rust-lang/rust/issues/129274>
 fn main() {
     fn test() {
         loop {
diff --git a/tests/ui/duplicate-label-E0381-issue-129274.stderr b/tests/ui/error-codes/E0381-duplicated-label.stderr
index 7f8bddb17c5..36e6d966f09 100644
--- a/tests/ui/duplicate-label-E0381-issue-129274.stderr
+++ b/tests/ui/error-codes/E0381-duplicated-label.stderr
@@ -1,5 +1,5 @@
 error[E0381]: used binding `blah` is possibly-uninitialized
-  --> $DIR/duplicate-label-E0381-issue-129274.rs:8:33
+  --> $DIR/E0381-duplicated-label.rs:11:33
    |
 LL |             let blah: Option<String>;
    |                 ---- binding declared here but left uninitialized