about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-06-24 05:06:31 +0000
committerbors <bors@rust-lang.org>2024-06-24 05:06:31 +0000
commit2c243d957008f5909f7a4af19e486ea8a3814be7 (patch)
tree0f504fdb9bfca03ccde3dbef5f5f4b4dfcabf6cb /tests
parentd49994b060684af423339b55769439b2f444a7b9 (diff)
parentb94d2754b595220167c7ab4b7e4b68f4efa8dc34 (diff)
downloadrust-2c243d957008f5909f7a4af19e486ea8a3814be7.tar.gz
rust-2c243d957008f5909f7a4af19e486ea8a3814be7.zip
Auto merge of #126891 - matthiaskrgr:rollup-p6dl1gk, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #126177 (Add hard error and migration lint for unsafe attrs)
 - #126298 (Promote loongarch64-unknown-linux-musl to Tier 2 with host tools)
 - #126455 (For [E0308]: mismatched types, when expr is in an arm's body, not add semicolon ';' at the end of it.)
 - #126754 (Implement `use<>` formatting in rustfmt)
 - #126807 (std::unix::fs: copy simplification for apple.)
 - #126845 (Weekly `cargo update`)
 - #126849 (Fix 32-bit Arm reg classes by hierarchically sorting them)
 - #126854 (std::unix::os::home_dir: fallback's optimisation.)
 - #126888 (Remove stray println from rustfmt's `rewrite_static`)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/asm/arm-low-dreg.rs33
-rw-r--r--tests/ui/attributes/unsafe/double-unsafe-attributes.stderr12
-rw-r--r--tests/ui/mismatched_types/mismatched-types-issue-126222.fixed34
-rw-r--r--tests/ui/mismatched_types/mismatched-types-issue-126222.rs34
-rw-r--r--tests/ui/mismatched_types/mismatched-types-issue-126222.stderr51
-rw-r--r--tests/ui/rust-2024/unsafe-attributes/in_2024_compatibility.rs9
-rw-r--r--tests/ui/rust-2024/unsafe-attributes/in_2024_compatibility.stderr21
-rw-r--r--tests/ui/rust-2024/unsafe-attributes/unsafe-attribute-marked.rs12
-rw-r--r--tests/ui/rust-2024/unsafe-attributes/unsafe-attributes-fix.fixed61
-rw-r--r--tests/ui/rust-2024/unsafe-attributes/unsafe-attributes-fix.rs61
-rw-r--r--tests/ui/rust-2024/unsafe-attributes/unsafe-attributes-fix.stderr93
-rw-r--r--tests/ui/rust-2024/unsafe-attributes/unsafe-attributes.edition2024.stderr13
-rw-r--r--tests/ui/rust-2024/unsafe-attributes/unsafe-attributes.rs12
13 files changed, 440 insertions, 6 deletions
diff --git a/tests/ui/asm/arm-low-dreg.rs b/tests/ui/asm/arm-low-dreg.rs
new file mode 100644
index 00000000000..e9ff0117e2d
--- /dev/null
+++ b/tests/ui/asm/arm-low-dreg.rs
@@ -0,0 +1,33 @@
+//@ build-pass
+//@ compile-flags: --target=armv7-unknown-linux-gnueabihf
+//@ needs-llvm-components: arm
+#![feature(no_core, rustc_attrs, decl_macro, lang_items)]
+#![crate_type = "rlib"]
+#![no_std]
+#![no_core]
+
+// We accidentally classified "d0"..="d15" as dregs, even though they are in dreg_low16,
+// and thus didn't compile them on platforms with only 16 dregs.
+// Highlighted in https://github.com/rust-lang/rust/issues/126797
+
+#[lang = "sized"]
+trait Sized {}
+
+#[lang = "copy"]
+trait Copy {}
+
+impl Copy for f64 {}
+
+#[rustc_builtin_macro]
+pub macro asm("assembly template", $(operands,)* $(options($(option),*))?) {
+    /* compiler built-in */
+}
+
+
+fn f(x: f64) -> f64 {
+    let out: f64;
+    unsafe {
+        asm!("vmov.f64 d1, d0", out("d1") out, in("d0") x);
+    }
+    out
+}
diff --git a/tests/ui/attributes/unsafe/double-unsafe-attributes.stderr b/tests/ui/attributes/unsafe/double-unsafe-attributes.stderr
index 1c07a5bf8ba..ea82bac6df0 100644
--- a/tests/ui/attributes/unsafe/double-unsafe-attributes.stderr
+++ b/tests/ui/attributes/unsafe/double-unsafe-attributes.stderr
@@ -9,12 +9,6 @@ help: escape `unsafe` to use it as an identifier
 LL | #[unsafe(r#unsafe(no_mangle))]
    |          ++
 
-error: cannot find attribute `r#unsafe` in this scope
-  --> $DIR/double-unsafe-attributes.rs:3:10
-   |
-LL | #[unsafe(unsafe(no_mangle))]
-   |          ^^^^^^
-
 error: `r#unsafe` is not an unsafe attribute
   --> $DIR/double-unsafe-attributes.rs:3:3
    |
@@ -23,5 +17,11 @@ LL | #[unsafe(unsafe(no_mangle))]
    |
    = note: extraneous unsafe is not allowed in attributes
 
+error: cannot find attribute `r#unsafe` in this scope
+  --> $DIR/double-unsafe-attributes.rs:3:10
+   |
+LL | #[unsafe(unsafe(no_mangle))]
+   |          ^^^^^^
+
 error: aborting due to 3 previous errors
 
diff --git a/tests/ui/mismatched_types/mismatched-types-issue-126222.fixed b/tests/ui/mismatched_types/mismatched-types-issue-126222.fixed
new file mode 100644
index 00000000000..30fd0028f19
--- /dev/null
+++ b/tests/ui/mismatched_types/mismatched-types-issue-126222.fixed
@@ -0,0 +1,34 @@
+//@ run-rustfix
+#![allow(unreachable_code, dead_code)]
+
+fn main() {
+    fn mismatch_types1() -> i32 {
+        match 1 {
+            x => return dbg!(x), //~ ERROR mismatched types
+        }
+        todo!()
+    }
+
+    fn mismatch_types2() -> i32 {
+        match 2 {
+            x => {
+                return dbg!(x) //~ ERROR mismatched types
+            }
+        }
+        todo!()
+    }
+
+    fn mismatch_types3() -> i32 {
+        match 1 {
+            _ => return dbg!(1) //~ ERROR mismatched types
+        }
+        todo!()
+    }
+
+    fn mismatch_types4() -> i32 {
+        match 1 {
+            _ => {return dbg!(1)} //~ ERROR mismatched types
+        }
+        todo!()
+    }
+}
diff --git a/tests/ui/mismatched_types/mismatched-types-issue-126222.rs b/tests/ui/mismatched_types/mismatched-types-issue-126222.rs
new file mode 100644
index 00000000000..59178702489
--- /dev/null
+++ b/tests/ui/mismatched_types/mismatched-types-issue-126222.rs
@@ -0,0 +1,34 @@
+//@ run-rustfix
+#![allow(unreachable_code, dead_code)]
+
+fn main() {
+    fn mismatch_types1() -> i32 {
+        match 1 {
+            x => dbg!(x), //~ ERROR mismatched types
+        }
+        todo!()
+    }
+
+    fn mismatch_types2() -> i32 {
+        match 2 {
+            x => {
+                dbg!(x) //~ ERROR mismatched types
+            }
+        }
+        todo!()
+    }
+
+    fn mismatch_types3() -> i32 {
+        match 1 {
+            _ => dbg!(1) //~ ERROR mismatched types
+        }
+        todo!()
+    }
+
+    fn mismatch_types4() -> i32 {
+        match 1 {
+            _ => {dbg!(1)} //~ ERROR mismatched types
+        }
+        todo!()
+    }
+}
diff --git a/tests/ui/mismatched_types/mismatched-types-issue-126222.stderr b/tests/ui/mismatched_types/mismatched-types-issue-126222.stderr
new file mode 100644
index 00000000000..2a8f9867abb
--- /dev/null
+++ b/tests/ui/mismatched_types/mismatched-types-issue-126222.stderr
@@ -0,0 +1,51 @@
+error[E0308]: mismatched types
+  --> $DIR/mismatched-types-issue-126222.rs:7:18
+   |
+LL |             x => dbg!(x),
+   |                  ^^^^^^^ expected `()`, found integer
+   |
+   = note: this error originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: you might have meant to return this value
+   |
+LL |             x => return dbg!(x),
+   |                  ++++++
+
+error[E0308]: mismatched types
+  --> $DIR/mismatched-types-issue-126222.rs:15:17
+   |
+LL |                 dbg!(x)
+   |                 ^^^^^^^ expected `()`, found integer
+   |
+   = note: this error originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: you might have meant to return this value
+   |
+LL |                 return dbg!(x)
+   |                 ++++++
+
+error[E0308]: mismatched types
+  --> $DIR/mismatched-types-issue-126222.rs:23:18
+   |
+LL |             _ => dbg!(1)
+   |                  ^^^^^^^ expected `()`, found integer
+   |
+   = note: this error originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: you might have meant to return this value
+   |
+LL |             _ => return dbg!(1)
+   |                  ++++++
+
+error[E0308]: mismatched types
+  --> $DIR/mismatched-types-issue-126222.rs:30:19
+   |
+LL |             _ => {dbg!(1)}
+   |                   ^^^^^^^ expected `()`, found integer
+   |
+   = note: this error originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: you might have meant to return this value
+   |
+LL |             _ => {return dbg!(1)}
+   |                   ++++++
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/rust-2024/unsafe-attributes/in_2024_compatibility.rs b/tests/ui/rust-2024/unsafe-attributes/in_2024_compatibility.rs
new file mode 100644
index 00000000000..c6f9115cde7
--- /dev/null
+++ b/tests/ui/rust-2024/unsafe-attributes/in_2024_compatibility.rs
@@ -0,0 +1,9 @@
+#![deny(rust_2024_compatibility)]
+#![feature(unsafe_attributes)]
+
+#[no_mangle]
+//~^ ERROR: unsafe attribute used without unsafe
+//~| WARN this is accepted in the current edition
+extern "C" fn foo() {}
+
+fn main() {}
diff --git a/tests/ui/rust-2024/unsafe-attributes/in_2024_compatibility.stderr b/tests/ui/rust-2024/unsafe-attributes/in_2024_compatibility.stderr
new file mode 100644
index 00000000000..f0689d9883c
--- /dev/null
+++ b/tests/ui/rust-2024/unsafe-attributes/in_2024_compatibility.stderr
@@ -0,0 +1,21 @@
+error: unsafe attribute used without unsafe
+  --> $DIR/in_2024_compatibility.rs:4:3
+   |
+LL | #[no_mangle]
+   |   ^^^^^^^^^ usage of unsafe attribute
+   |
+   = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
+   = note: for more information, see issue #123757 <https://github.com/rust-lang/rust/issues/123757>
+note: the lint level is defined here
+  --> $DIR/in_2024_compatibility.rs:1:9
+   |
+LL | #![deny(rust_2024_compatibility)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^
+   = note: `#[deny(unsafe_attr_outside_unsafe)]` implied by `#[deny(rust_2024_compatibility)]`
+help: wrap the attribute in `unsafe(...)`
+   |
+LL | #[unsafe(no_mangle)]
+   |   +++++++         +
+
+error: aborting due to 1 previous error
+
diff --git a/tests/ui/rust-2024/unsafe-attributes/unsafe-attribute-marked.rs b/tests/ui/rust-2024/unsafe-attributes/unsafe-attribute-marked.rs
new file mode 100644
index 00000000000..279ced2525a
--- /dev/null
+++ b/tests/ui/rust-2024/unsafe-attributes/unsafe-attribute-marked.rs
@@ -0,0 +1,12 @@
+//@ revisions: edition2021 edition2024
+//@[edition2021] edition:2021
+//@[edition2024] edition:2024
+//@[edition2024] compile-flags: -Zunstable-options
+//@ check-pass
+
+#![feature(unsafe_attributes)]
+
+#[unsafe(no_mangle)]
+extern "C" fn foo() {}
+
+fn main() {}
diff --git a/tests/ui/rust-2024/unsafe-attributes/unsafe-attributes-fix.fixed b/tests/ui/rust-2024/unsafe-attributes/unsafe-attributes-fix.fixed
new file mode 100644
index 00000000000..6ebdff0334c
--- /dev/null
+++ b/tests/ui/rust-2024/unsafe-attributes/unsafe-attributes-fix.fixed
@@ -0,0 +1,61 @@
+//@ run-rustfix
+#![feature(unsafe_attributes)]
+#![deny(unsafe_attr_outside_unsafe)]
+
+macro_rules! tt {
+    ($e:tt) => {
+        #$e
+        extern fn foo() {}
+    }
+}
+
+macro_rules! ident {
+    ($e:ident) => {
+        #[unsafe($e)]
+        //~^ ERROR: unsafe attribute used without unsafe
+        //~| WARN this is accepted in the current edition
+        extern fn bar() {}
+    }
+}
+
+macro_rules! ident2 {
+    ($e:ident, $l:literal) => {
+        #[unsafe($e = $l)]
+        //~^ ERROR: unsafe attribute used without unsafe
+        //~| WARN this is accepted in the current edition
+        extern fn bars() {}
+    }
+}
+
+macro_rules! meta {
+    ($m:meta) => {
+        #[$m]
+        extern fn baz() {}
+    }
+}
+
+macro_rules! meta2 {
+    ($m:meta) => {
+        #[$m]
+        extern fn baw() {}
+    }
+}
+
+tt!([unsafe(no_mangle)]);
+//~^ ERROR: unsafe attribute used without unsafe
+//~| WARN this is accepted in the current edition
+ident!(no_mangle);
+meta!(unsafe(no_mangle));
+//~^ ERROR: unsafe attribute used without unsafe
+//~| WARN this is accepted in the current edition
+meta2!(unsafe(export_name = "baw"));
+//~^ ERROR: unsafe attribute used without unsafe
+//~| WARN this is accepted in the current edition
+ident2!(export_name, "bars");
+
+#[unsafe(no_mangle)]
+//~^ ERROR: unsafe attribute used without unsafe
+//~| WARN this is accepted in the current edition
+extern "C" fn one() {}
+
+fn main() {}
diff --git a/tests/ui/rust-2024/unsafe-attributes/unsafe-attributes-fix.rs b/tests/ui/rust-2024/unsafe-attributes/unsafe-attributes-fix.rs
new file mode 100644
index 00000000000..c78ff45ea4c
--- /dev/null
+++ b/tests/ui/rust-2024/unsafe-attributes/unsafe-attributes-fix.rs
@@ -0,0 +1,61 @@
+//@ run-rustfix
+#![feature(unsafe_attributes)]
+#![deny(unsafe_attr_outside_unsafe)]
+
+macro_rules! tt {
+    ($e:tt) => {
+        #$e
+        extern fn foo() {}
+    }
+}
+
+macro_rules! ident {
+    ($e:ident) => {
+        #[$e]
+        //~^ ERROR: unsafe attribute used without unsafe
+        //~| WARN this is accepted in the current edition
+        extern fn bar() {}
+    }
+}
+
+macro_rules! ident2 {
+    ($e:ident, $l:literal) => {
+        #[$e = $l]
+        //~^ ERROR: unsafe attribute used without unsafe
+        //~| WARN this is accepted in the current edition
+        extern fn bars() {}
+    }
+}
+
+macro_rules! meta {
+    ($m:meta) => {
+        #[$m]
+        extern fn baz() {}
+    }
+}
+
+macro_rules! meta2 {
+    ($m:meta) => {
+        #[$m]
+        extern fn baw() {}
+    }
+}
+
+tt!([no_mangle]);
+//~^ ERROR: unsafe attribute used without unsafe
+//~| WARN this is accepted in the current edition
+ident!(no_mangle);
+meta!(no_mangle);
+//~^ ERROR: unsafe attribute used without unsafe
+//~| WARN this is accepted in the current edition
+meta2!(export_name = "baw");
+//~^ ERROR: unsafe attribute used without unsafe
+//~| WARN this is accepted in the current edition
+ident2!(export_name, "bars");
+
+#[no_mangle]
+//~^ ERROR: unsafe attribute used without unsafe
+//~| WARN this is accepted in the current edition
+extern "C" fn one() {}
+
+fn main() {}
diff --git a/tests/ui/rust-2024/unsafe-attributes/unsafe-attributes-fix.stderr b/tests/ui/rust-2024/unsafe-attributes/unsafe-attributes-fix.stderr
new file mode 100644
index 00000000000..c95984f58ec
--- /dev/null
+++ b/tests/ui/rust-2024/unsafe-attributes/unsafe-attributes-fix.stderr
@@ -0,0 +1,93 @@
+error: unsafe attribute used without unsafe
+  --> $DIR/unsafe-attributes-fix.rs:44:6
+   |
+LL | tt!([no_mangle]);
+   |      ^^^^^^^^^ usage of unsafe attribute
+   |
+   = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
+   = note: for more information, see issue #123757 <https://github.com/rust-lang/rust/issues/123757>
+note: the lint level is defined here
+  --> $DIR/unsafe-attributes-fix.rs:3:9
+   |
+LL | #![deny(unsafe_attr_outside_unsafe)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: wrap the attribute in `unsafe(...)`
+   |
+LL | tt!([unsafe(no_mangle)]);
+   |      +++++++         +
+
+error: unsafe attribute used without unsafe
+  --> $DIR/unsafe-attributes-fix.rs:14:11
+   |
+LL |         #[$e]
+   |           ^^ usage of unsafe attribute
+...
+LL | ident!(no_mangle);
+   | ----------------- in this macro invocation
+   |
+   = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
+   = note: for more information, see issue #123757 <https://github.com/rust-lang/rust/issues/123757>
+   = note: this error originates in the macro `ident` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: wrap the attribute in `unsafe(...)`
+   |
+LL |         #[unsafe($e)]
+   |           +++++++  +
+
+error: unsafe attribute used without unsafe
+  --> $DIR/unsafe-attributes-fix.rs:48:7
+   |
+LL | meta!(no_mangle);
+   |       ^^^^^^^^^ usage of unsafe attribute
+   |
+   = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
+   = note: for more information, see issue #123757 <https://github.com/rust-lang/rust/issues/123757>
+help: wrap the attribute in `unsafe(...)`
+   |
+LL | meta!(unsafe(no_mangle));
+   |       +++++++         +
+
+error: unsafe attribute used without unsafe
+  --> $DIR/unsafe-attributes-fix.rs:51:8
+   |
+LL | meta2!(export_name = "baw");
+   |        ^^^^^^^^^^^ usage of unsafe attribute
+   |
+   = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
+   = note: for more information, see issue #123757 <https://github.com/rust-lang/rust/issues/123757>
+help: wrap the attribute in `unsafe(...)`
+   |
+LL | meta2!(unsafe(export_name = "baw"));
+   |        +++++++                   +
+
+error: unsafe attribute used without unsafe
+  --> $DIR/unsafe-attributes-fix.rs:23:11
+   |
+LL |         #[$e = $l]
+   |           ^^ usage of unsafe attribute
+...
+LL | ident2!(export_name, "bars");
+   | ---------------------------- in this macro invocation
+   |
+   = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
+   = note: for more information, see issue #123757 <https://github.com/rust-lang/rust/issues/123757>
+   = note: this error originates in the macro `ident2` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: wrap the attribute in `unsafe(...)`
+   |
+LL |         #[unsafe($e = $l)]
+   |           +++++++       +
+
+error: unsafe attribute used without unsafe
+  --> $DIR/unsafe-attributes-fix.rs:56:3
+   |
+LL | #[no_mangle]
+   |   ^^^^^^^^^ usage of unsafe attribute
+   |
+   = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
+   = note: for more information, see issue #123757 <https://github.com/rust-lang/rust/issues/123757>
+help: wrap the attribute in `unsafe(...)`
+   |
+LL | #[unsafe(no_mangle)]
+   |   +++++++         +
+
+error: aborting due to 6 previous errors
+
diff --git a/tests/ui/rust-2024/unsafe-attributes/unsafe-attributes.edition2024.stderr b/tests/ui/rust-2024/unsafe-attributes/unsafe-attributes.edition2024.stderr
new file mode 100644
index 00000000000..35475d66716
--- /dev/null
+++ b/tests/ui/rust-2024/unsafe-attributes/unsafe-attributes.edition2024.stderr
@@ -0,0 +1,13 @@
+error: unsafe attribute used without unsafe
+  --> $DIR/unsafe-attributes.rs:9:3
+   |
+LL | #[no_mangle]
+   |   ^^^^^^^^^ usage of unsafe attribute
+   |
+help: wrap the attribute in `unsafe(...)`
+   |
+LL | #[unsafe(no_mangle)]
+   |   +++++++         +
+
+error: aborting due to 1 previous error
+
diff --git a/tests/ui/rust-2024/unsafe-attributes/unsafe-attributes.rs b/tests/ui/rust-2024/unsafe-attributes/unsafe-attributes.rs
new file mode 100644
index 00000000000..3a6af9dfb2b
--- /dev/null
+++ b/tests/ui/rust-2024/unsafe-attributes/unsafe-attributes.rs
@@ -0,0 +1,12 @@
+//@ revisions: edition2021 edition2024
+//@[edition2021] edition:2021
+//@[edition2021] check-pass
+//@[edition2024] edition:2024
+//@[edition2024] compile-flags: -Zunstable-options
+
+#![feature(unsafe_attributes)]
+
+#[no_mangle] //[edition2024]~ ERROR: unsafe attribute used without unsafe
+extern "C" fn foo() {}
+
+fn main() {}