summaryrefslogtreecommitdiffstats
path: root/tests/ui/lint
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /tests/ui/lint
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/lint')
-rw-r--r--tests/ui/lint/invalid-nan-comparison-suggestion.fixed36
-rw-r--r--tests/ui/lint/invalid-nan-comparison-suggestion.rs39
-rw-r--r--tests/ui/lint/invalid-nan-comparison-suggestion.stderr114
-rw-r--r--tests/ui/lint/invalid-nan-comparison.rs51
-rw-r--r--tests/ui/lint/invalid-nan-comparison.stderr159
-rw-r--r--tests/ui/lint/invalid_from_utf8.rs93
-rw-r--r--tests/ui/lint/invalid_from_utf8.stderr110
-rw-r--r--tests/ui/lint/issue-99387.rs4
-rw-r--r--tests/ui/lint/issue-99387.stderr15
-rw-r--r--tests/ui/lint/lint-attr-everywhere-early.rs2
-rw-r--r--tests/ui/lint/lint-attr-everywhere-late.rs2
-rw-r--r--tests/ui/lint/lint-ctypes-113436-1.rs28
-rw-r--r--tests/ui/lint/lint-ctypes-113436-1.stderr35
-rw-r--r--tests/ui/lint/lint-ctypes-113436.rs34
-rw-r--r--tests/ui/lint/lint-ctypes-113900.rs12
-rw-r--r--tests/ui/lint/lint-ctypes-73249-2.rs8
-rw-r--r--tests/ui/lint/lint-ctypes-73249-2.stderr6
-rw-r--r--tests/ui/lint/lint-ctypes-73251-1.rs6
-rw-r--r--tests/ui/lint/lint-ctypes-73251-1.stderr6
-rw-r--r--tests/ui/lint/lint-ctypes-73251-2.rs2
-rw-r--r--tests/ui/lint/lint-ctypes-73251-2.stderr6
-rw-r--r--tests/ui/lint/lint-ctypes-73251.rs4
-rw-r--r--tests/ui/lint/lint-ctypes-94223.rs42
-rw-r--r--tests/ui/lint/lint-ctypes-94223.stderr126
-rw-r--r--tests/ui/lint/lint-unnecessary-parens.fixed8
-rw-r--r--tests/ui/lint/lint-unnecessary-parens.rs8
-rw-r--r--tests/ui/lint/lint-unnecessary-parens.stderr86
-rw-r--r--tests/ui/lint/opaque-ty-ffi-unsafe.rs4
-rw-r--r--tests/ui/lint/opaque-ty-ffi-unsafe.stderr6
-rw-r--r--tests/ui/lint/reference_casting.rs51
-rw-r--r--tests/ui/lint/reference_casting.stderr68
-rw-r--r--tests/ui/lint/trivial-casts-featuring-type-ascription.stderr4
-rw-r--r--tests/ui/lint/type-overflow.stderr28
-rw-r--r--tests/ui/lint/undropped_manually_drops.rs19
-rw-r--r--tests/ui/lint/undropped_manually_drops.stderr42
-rw-r--r--tests/ui/lint/unused/lint-unused-extern-crate.rs2
-rw-r--r--tests/ui/lint/unused/lint-unused-imports.rs2
-rw-r--r--tests/ui/lint/unused/lint-unused-variables.rs4
-rw-r--r--tests/ui/lint/unused/must-use-block-expr.fixed36
-rw-r--r--tests/ui/lint/unused/must-use-block-expr.rs36
-rw-r--r--tests/ui/lint/unused/must-use-block-expr.stderr51
-rw-r--r--tests/ui/lint/unused_import_warning_issue_45268.rs8
42 files changed, 1351 insertions, 52 deletions
diff --git a/tests/ui/lint/invalid-nan-comparison-suggestion.fixed b/tests/ui/lint/invalid-nan-comparison-suggestion.fixed
new file mode 100644
index 000000000..feafc6c1b
--- /dev/null
+++ b/tests/ui/lint/invalid-nan-comparison-suggestion.fixed
@@ -0,0 +1,36 @@
+// check-pass
+// run-rustfix
+
+fn main() {
+ let x = 5f32;
+ let _ = x.is_nan();
+ //~^ WARN incorrect NaN comparison
+ let _ = !x.is_nan();
+ //~^ WARN incorrect NaN comparison
+
+ let x = 5f64;
+ let _ = x.is_nan();
+ //~^ WARN incorrect NaN comparison
+ let _ = !x.is_nan();
+ //~^ WARN incorrect NaN comparison
+
+ let b = &2.3f32;
+ if !b.is_nan() {}
+ //~^ WARN incorrect NaN comparison
+
+ let b = &2.3f32;
+ if !b.is_nan() {}
+ //~^ WARN incorrect NaN comparison
+
+ let _ =
+ !b.is_nan();
+
+ #[allow(unused_macros)]
+ macro_rules! nan { () => { f32::NAN }; }
+ macro_rules! number { () => { 5f32 }; }
+
+ let _ = number!().is_nan();
+ //~^ WARN incorrect NaN comparison
+ let _ = !number!().is_nan();
+ //~^ WARN incorrect NaN comparison
+}
diff --git a/tests/ui/lint/invalid-nan-comparison-suggestion.rs b/tests/ui/lint/invalid-nan-comparison-suggestion.rs
new file mode 100644
index 000000000..ad5eb66e5
--- /dev/null
+++ b/tests/ui/lint/invalid-nan-comparison-suggestion.rs
@@ -0,0 +1,39 @@
+// check-pass
+// run-rustfix
+
+fn main() {
+ let x = 5f32;
+ let _ = x == f32::NAN;
+ //~^ WARN incorrect NaN comparison
+ let _ = x != f32::NAN;
+ //~^ WARN incorrect NaN comparison
+
+ let x = 5f64;
+ let _ = x == f64::NAN;
+ //~^ WARN incorrect NaN comparison
+ let _ = x != f64::NAN;
+ //~^ WARN incorrect NaN comparison
+
+ let b = &2.3f32;
+ if b != &f32::NAN {}
+ //~^ WARN incorrect NaN comparison
+
+ let b = &2.3f32;
+ if b != { &f32::NAN } {}
+ //~^ WARN incorrect NaN comparison
+
+ let _ =
+ b != {
+ //~^ WARN incorrect NaN comparison
+ &f32::NAN
+ };
+
+ #[allow(unused_macros)]
+ macro_rules! nan { () => { f32::NAN }; }
+ macro_rules! number { () => { 5f32 }; }
+
+ let _ = nan!() == number!();
+ //~^ WARN incorrect NaN comparison
+ let _ = number!() != nan!();
+ //~^ WARN incorrect NaN comparison
+}
diff --git a/tests/ui/lint/invalid-nan-comparison-suggestion.stderr b/tests/ui/lint/invalid-nan-comparison-suggestion.stderr
new file mode 100644
index 000000000..c310341de
--- /dev/null
+++ b/tests/ui/lint/invalid-nan-comparison-suggestion.stderr
@@ -0,0 +1,114 @@
+warning: incorrect NaN comparison, NaN cannot be directly compared to itself
+ --> $DIR/invalid-nan-comparison-suggestion.rs:6:13
+ |
+LL | let _ = x == f32::NAN;
+ | ^^^^^^^^^^^^^
+ |
+ = note: `#[warn(invalid_nan_comparisons)]` on by default
+help: use `f32::is_nan()` or `f64::is_nan()` instead
+ |
+LL - let _ = x == f32::NAN;
+LL + let _ = x.is_nan();
+ |
+
+warning: incorrect NaN comparison, NaN cannot be directly compared to itself
+ --> $DIR/invalid-nan-comparison-suggestion.rs:8:13
+ |
+LL | let _ = x != f32::NAN;
+ | ^^^^^^^^^^^^^
+ |
+help: use `f32::is_nan()` or `f64::is_nan()` instead
+ |
+LL - let _ = x != f32::NAN;
+LL + let _ = !x.is_nan();
+ |
+
+warning: incorrect NaN comparison, NaN cannot be directly compared to itself
+ --> $DIR/invalid-nan-comparison-suggestion.rs:12:13
+ |
+LL | let _ = x == f64::NAN;
+ | ^^^^^^^^^^^^^
+ |
+help: use `f32::is_nan()` or `f64::is_nan()` instead
+ |
+LL - let _ = x == f64::NAN;
+LL + let _ = x.is_nan();
+ |
+
+warning: incorrect NaN comparison, NaN cannot be directly compared to itself
+ --> $DIR/invalid-nan-comparison-suggestion.rs:14:13
+ |
+LL | let _ = x != f64::NAN;
+ | ^^^^^^^^^^^^^
+ |
+help: use `f32::is_nan()` or `f64::is_nan()` instead
+ |
+LL - let _ = x != f64::NAN;
+LL + let _ = !x.is_nan();
+ |
+
+warning: incorrect NaN comparison, NaN cannot be directly compared to itself
+ --> $DIR/invalid-nan-comparison-suggestion.rs:18:8
+ |
+LL | if b != &f32::NAN {}
+ | ^^^^^^^^^^^^^^
+ |
+help: use `f32::is_nan()` or `f64::is_nan()` instead
+ |
+LL - if b != &f32::NAN {}
+LL + if !b.is_nan() {}
+ |
+
+warning: incorrect NaN comparison, NaN cannot be directly compared to itself
+ --> $DIR/invalid-nan-comparison-suggestion.rs:22:8
+ |
+LL | if b != { &f32::NAN } {}
+ | ^^^^^^^^^^^^^^^^^^
+ |
+help: use `f32::is_nan()` or `f64::is_nan()` instead
+ |
+LL - if b != { &f32::NAN } {}
+LL + if !b.is_nan() {}
+ |
+
+warning: incorrect NaN comparison, NaN cannot be directly compared to itself
+ --> $DIR/invalid-nan-comparison-suggestion.rs:26:9
+ |
+LL | / b != {
+LL | |
+LL | | &f32::NAN
+LL | | };
+ | |_________^
+ |
+help: use `f32::is_nan()` or `f64::is_nan()` instead
+ |
+LL - b != {
+LL + !b.is_nan();
+ |
+
+warning: incorrect NaN comparison, NaN cannot be directly compared to itself
+ --> $DIR/invalid-nan-comparison-suggestion.rs:35:13
+ |
+LL | let _ = nan!() == number!();
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+help: use `f32::is_nan()` or `f64::is_nan()` instead
+ |
+LL - let _ = nan!() == number!();
+LL + let _ = number!().is_nan();
+ |
+
+warning: incorrect NaN comparison, NaN cannot be directly compared to itself
+ --> $DIR/invalid-nan-comparison-suggestion.rs:37:13
+ |
+LL | let _ = number!() != nan!();
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+help: use `f32::is_nan()` or `f64::is_nan()` instead
+ |
+LL - let _ = number!() != nan!();
+LL + let _ = !number!().is_nan();
+ |
+
+warning: 9 warnings emitted
+
diff --git a/tests/ui/lint/invalid-nan-comparison.rs b/tests/ui/lint/invalid-nan-comparison.rs
new file mode 100644
index 000000000..d7e793ca5
--- /dev/null
+++ b/tests/ui/lint/invalid-nan-comparison.rs
@@ -0,0 +1,51 @@
+// check-pass
+
+fn main() {
+ f32();
+ f64();
+}
+
+const TEST: bool = 5f32 == f32::NAN;
+//~^ WARN incorrect NaN comparison
+
+fn f32() {
+ macro_rules! number { () => { 5f32 }; }
+ let x = number!();
+ x == f32::NAN;
+ //~^ WARN incorrect NaN comparison
+ x != f32::NAN;
+ //~^ WARN incorrect NaN comparison
+ x < f32::NAN;
+ //~^ WARN incorrect NaN comparison
+ x > f32::NAN;
+ //~^ WARN incorrect NaN comparison
+ x <= f32::NAN;
+ //~^ WARN incorrect NaN comparison
+ x >= f32::NAN;
+ //~^ WARN incorrect NaN comparison
+ number!() == f32::NAN;
+ //~^ WARN incorrect NaN comparison
+ f32::NAN != number!();
+ //~^ WARN incorrect NaN comparison
+}
+
+fn f64() {
+ macro_rules! number { () => { 5f64 }; }
+ let x = number!();
+ x == f64::NAN;
+ //~^ WARN incorrect NaN comparison
+ x != f64::NAN;
+ //~^ WARN incorrect NaN comparison
+ x < f64::NAN;
+ //~^ WARN incorrect NaN comparison
+ x > f64::NAN;
+ //~^ WARN incorrect NaN comparison
+ x <= f64::NAN;
+ //~^ WARN incorrect NaN comparison
+ x >= f64::NAN;
+ //~^ WARN incorrect NaN comparison
+ number!() == f64::NAN;
+ //~^ WARN incorrect NaN comparison
+ f64::NAN != number!();
+ //~^ WARN incorrect NaN comparison
+}
diff --git a/tests/ui/lint/invalid-nan-comparison.stderr b/tests/ui/lint/invalid-nan-comparison.stderr
new file mode 100644
index 000000000..054c06d38
--- /dev/null
+++ b/tests/ui/lint/invalid-nan-comparison.stderr
@@ -0,0 +1,159 @@
+warning: incorrect NaN comparison, NaN cannot be directly compared to itself
+ --> $DIR/invalid-nan-comparison.rs:8:20
+ |
+LL | const TEST: bool = 5f32 == f32::NAN;
+ | ^^^^^^^^^^^^^^^^
+ |
+ = note: `#[warn(invalid_nan_comparisons)]` on by default
+help: use `f32::is_nan()` or `f64::is_nan()` instead
+ |
+LL - const TEST: bool = 5f32 == f32::NAN;
+LL + const TEST: bool = 5f32.is_nan();
+ |
+
+warning: incorrect NaN comparison, NaN cannot be directly compared to itself
+ --> $DIR/invalid-nan-comparison.rs:14:5
+ |
+LL | x == f32::NAN;
+ | ^^^^^^^^^^^^^
+ |
+help: use `f32::is_nan()` or `f64::is_nan()` instead
+ |
+LL - x == f32::NAN;
+LL + x.is_nan();
+ |
+
+warning: incorrect NaN comparison, NaN cannot be directly compared to itself
+ --> $DIR/invalid-nan-comparison.rs:16:5
+ |
+LL | x != f32::NAN;
+ | ^^^^^^^^^^^^^
+ |
+help: use `f32::is_nan()` or `f64::is_nan()` instead
+ |
+LL - x != f32::NAN;
+LL + !x.is_nan();
+ |
+
+warning: incorrect NaN comparison, NaN is not orderable
+ --> $DIR/invalid-nan-comparison.rs:18:5
+ |
+LL | x < f32::NAN;
+ | ^^^^^^^^^^^^
+
+warning: incorrect NaN comparison, NaN is not orderable
+ --> $DIR/invalid-nan-comparison.rs:20:5
+ |
+LL | x > f32::NAN;
+ | ^^^^^^^^^^^^
+
+warning: incorrect NaN comparison, NaN is not orderable
+ --> $DIR/invalid-nan-comparison.rs:22:5
+ |
+LL | x <= f32::NAN;
+ | ^^^^^^^^^^^^^
+
+warning: incorrect NaN comparison, NaN is not orderable
+ --> $DIR/invalid-nan-comparison.rs:24:5
+ |
+LL | x >= f32::NAN;
+ | ^^^^^^^^^^^^^
+
+warning: incorrect NaN comparison, NaN cannot be directly compared to itself
+ --> $DIR/invalid-nan-comparison.rs:26:5
+ |
+LL | number!() == f32::NAN;
+ | ^^^^^^^^^^^^^^^^^^^^^
+ |
+help: use `f32::is_nan()` or `f64::is_nan()` instead
+ |
+LL - number!() == f32::NAN;
+LL + number!().is_nan();
+ |
+
+warning: incorrect NaN comparison, NaN cannot be directly compared to itself
+ --> $DIR/invalid-nan-comparison.rs:28:5
+ |
+LL | f32::NAN != number!();
+ | ^^^^^^^^^^^^^^^^^^^^^
+ |
+help: use `f32::is_nan()` or `f64::is_nan()` instead
+ |
+LL - f32::NAN != number!();
+LL + !number!().is_nan();
+ |
+
+warning: incorrect NaN comparison, NaN cannot be directly compared to itself
+ --> $DIR/invalid-nan-comparison.rs:35:5
+ |
+LL | x == f64::NAN;
+ | ^^^^^^^^^^^^^
+ |
+help: use `f32::is_nan()` or `f64::is_nan()` instead
+ |
+LL - x == f64::NAN;
+LL + x.is_nan();
+ |
+
+warning: incorrect NaN comparison, NaN cannot be directly compared to itself
+ --> $DIR/invalid-nan-comparison.rs:37:5
+ |
+LL | x != f64::NAN;
+ | ^^^^^^^^^^^^^
+ |
+help: use `f32::is_nan()` or `f64::is_nan()` instead
+ |
+LL - x != f64::NAN;
+LL + !x.is_nan();
+ |
+
+warning: incorrect NaN comparison, NaN is not orderable
+ --> $DIR/invalid-nan-comparison.rs:39:5
+ |
+LL | x < f64::NAN;
+ | ^^^^^^^^^^^^
+
+warning: incorrect NaN comparison, NaN is not orderable
+ --> $DIR/invalid-nan-comparison.rs:41:5
+ |
+LL | x > f64::NAN;
+ | ^^^^^^^^^^^^
+
+warning: incorrect NaN comparison, NaN is not orderable
+ --> $DIR/invalid-nan-comparison.rs:43:5
+ |
+LL | x <= f64::NAN;
+ | ^^^^^^^^^^^^^
+
+warning: incorrect NaN comparison, NaN is not orderable
+ --> $DIR/invalid-nan-comparison.rs:45:5
+ |
+LL | x >= f64::NAN;
+ | ^^^^^^^^^^^^^
+
+warning: incorrect NaN comparison, NaN cannot be directly compared to itself
+ --> $DIR/invalid-nan-comparison.rs:47:5
+ |
+LL | number!() == f64::NAN;
+ | ^^^^^^^^^^^^^^^^^^^^^
+ |
+help: use `f32::is_nan()` or `f64::is_nan()` instead
+ |
+LL - number!() == f64::NAN;
+LL + number!().is_nan();
+ |
+
+warning: incorrect NaN comparison, NaN cannot be directly compared to itself
+ --> $DIR/invalid-nan-comparison.rs:49:5
+ |
+LL | f64::NAN != number!();
+ | ^^^^^^^^^^^^^^^^^^^^^
+ |
+help: use `f32::is_nan()` or `f64::is_nan()` instead
+ |
+LL - f64::NAN != number!();
+LL + !number!().is_nan();
+ |
+
+warning: 17 warnings emitted
+
diff --git a/tests/ui/lint/invalid_from_utf8.rs b/tests/ui/lint/invalid_from_utf8.rs
new file mode 100644
index 000000000..9c8c63681
--- /dev/null
+++ b/tests/ui/lint/invalid_from_utf8.rs
@@ -0,0 +1,93 @@
+// check-pass
+
+#![feature(concat_bytes)]
+#![warn(invalid_from_utf8_unchecked)]
+#![warn(invalid_from_utf8)]
+
+pub fn from_utf8_unchecked_mut() {
+ // Valid
+ unsafe {
+ std::str::from_utf8_unchecked_mut(&mut [99, 108, 105, 112, 112, 121]);
+ std::str::from_utf8_unchecked_mut(&mut [b'c', b'l', b'i', b'p', b'p', b'y']);
+
+ let x = 0xA0;
+ std::str::from_utf8_unchecked_mut(&mut [0xC0, x]);
+ }
+
+ // Invalid
+ unsafe {
+ std::str::from_utf8_unchecked_mut(&mut [99, 108, 130, 105, 112, 112, 121]);
+ //~^ WARN calls to `std::str::from_utf8_unchecked_mut`
+ std::str::from_utf8_unchecked_mut(&mut [b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']);
+ //~^ WARN calls to `std::str::from_utf8_unchecked_mut`
+ }
+}
+
+pub fn from_utf8_unchecked() {
+ // Valid
+ unsafe {
+ std::str::from_utf8_unchecked(&[99, 108, 105, 112, 112, 121]);
+ std::str::from_utf8_unchecked(&[b'c', b'l', b'i', b'p', b'p', b'y']);
+ std::str::from_utf8_unchecked(b"clippy");
+
+ let x = 0xA0;
+ std::str::from_utf8_unchecked(&[0xC0, x]);
+ }
+
+ // Invalid
+ unsafe {
+ std::str::from_utf8_unchecked(&[99, 108, 130, 105, 112, 112, 121]);
+ //~^ WARN calls to `std::str::from_utf8_unchecked`
+ std::str::from_utf8_unchecked(&[b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']);
+ //~^ WARN calls to `std::str::from_utf8_unchecked`
+ std::str::from_utf8_unchecked(b"cl\x82ippy");
+ //~^ WARN calls to `std::str::from_utf8_unchecked`
+ std::str::from_utf8_unchecked(concat_bytes!(b"cl", b"\x82ippy"));
+ //~^ WARN calls to `std::str::from_utf8_unchecked`
+ }
+}
+
+pub fn from_utf8_mut() {
+ // Valid
+ {
+ std::str::from_utf8_mut(&mut [99, 108, 105, 112, 112, 121]);
+ std::str::from_utf8_mut(&mut [b'c', b'l', b'i', b'p', b'p', b'y']);
+
+ let x = 0xa0;
+ std::str::from_utf8_mut(&mut [0xc0, x]);
+ }
+
+ // Invalid
+ {
+ std::str::from_utf8_mut(&mut [99, 108, 130, 105, 112, 112, 121]);
+ //~^ WARN calls to `std::str::from_utf8_mut`
+ std::str::from_utf8_mut(&mut [b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']);
+ //~^ WARN calls to `std::str::from_utf8_mut`
+ }
+}
+
+pub fn from_utf8() {
+ // Valid
+ {
+ std::str::from_utf8(&[99, 108, 105, 112, 112, 121]);
+ std::str::from_utf8(&[b'c', b'l', b'i', b'p', b'p', b'y']);
+ std::str::from_utf8(b"clippy");
+
+ let x = 0xA0;
+ std::str::from_utf8(&[0xC0, x]);
+ }
+
+ // Invalid
+ {
+ std::str::from_utf8(&[99, 108, 130, 105, 112, 112, 121]);
+ //~^ WARN calls to `std::str::from_utf8`
+ std::str::from_utf8(&[b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']);
+ //~^ WARN calls to `std::str::from_utf8`
+ std::str::from_utf8(b"cl\x82ippy");
+ //~^ WARN calls to `std::str::from_utf8`
+ std::str::from_utf8(concat_bytes!(b"cl", b"\x82ippy"));
+ //~^ WARN calls to `std::str::from_utf8`
+ }
+}
+
+fn main() {}
diff --git a/tests/ui/lint/invalid_from_utf8.stderr b/tests/ui/lint/invalid_from_utf8.stderr
new file mode 100644
index 000000000..8e00d3bf8
--- /dev/null
+++ b/tests/ui/lint/invalid_from_utf8.stderr
@@ -0,0 +1,110 @@
+warning: calls to `std::str::from_utf8_unchecked_mut` with a invalid literal are undefined behavior
+ --> $DIR/invalid_from_utf8.rs:19:9
+ |
+LL | std::str::from_utf8_unchecked_mut(&mut [99, 108, 130, 105, 112, 112, 121]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------------------------------^
+ | |
+ | the literal was valid UTF-8 up to the 2 bytes
+ |
+note: the lint level is defined here
+ --> $DIR/invalid_from_utf8.rs:4:9
+ |
+LL | #![warn(invalid_from_utf8_unchecked)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+warning: calls to `std::str::from_utf8_unchecked_mut` with a invalid literal are undefined behavior
+ --> $DIR/invalid_from_utf8.rs:21:9
+ |
+LL | std::str::from_utf8_unchecked_mut(&mut [b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--------------------------------------------------^
+ | |
+ | the literal was valid UTF-8 up to the 2 bytes
+
+warning: calls to `std::str::from_utf8_unchecked` with a invalid literal are undefined behavior
+ --> $DIR/invalid_from_utf8.rs:39:9
+ |
+LL | std::str::from_utf8_unchecked(&[99, 108, 130, 105, 112, 112, 121]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------------------------^
+ | |
+ | the literal was valid UTF-8 up to the 2 bytes
+
+warning: calls to `std::str::from_utf8_unchecked` with a invalid literal are undefined behavior
+ --> $DIR/invalid_from_utf8.rs:41:9
+ |
+LL | std::str::from_utf8_unchecked(&[b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------------------------------------^
+ | |
+ | the literal was valid UTF-8 up to the 2 bytes
+
+warning: calls to `std::str::from_utf8_unchecked` with a invalid literal are undefined behavior
+ --> $DIR/invalid_from_utf8.rs:43:9
+ |
+LL | std::str::from_utf8_unchecked(b"cl\x82ippy");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------------^
+ | |
+ | the literal was valid UTF-8 up to the 2 bytes
+
+warning: calls to `std::str::from_utf8_unchecked` with a invalid literal are undefined behavior
+ --> $DIR/invalid_from_utf8.rs:45:9
+ |
+LL | std::str::from_utf8_unchecked(concat_bytes!(b"cl", b"\x82ippy"));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------------------------^
+ | |
+ | the literal was valid UTF-8 up to the 2 bytes
+
+warning: calls to `std::str::from_utf8_mut` with a invalid literal always return an error
+ --> $DIR/invalid_from_utf8.rs:62:9
+ |
+LL | std::str::from_utf8_mut(&mut [99, 108, 130, 105, 112, 112, 121]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^---------------------------------------^
+ | |
+ | the literal was valid UTF-8 up to the 2 bytes
+ |
+note: the lint level is defined here
+ --> $DIR/invalid_from_utf8.rs:5:9
+ |
+LL | #![warn(invalid_from_utf8)]
+ | ^^^^^^^^^^^^^^^^^
+
+warning: calls to `std::str::from_utf8_mut` with a invalid literal always return an error
+ --> $DIR/invalid_from_utf8.rs:64:9
+ |
+LL | std::str::from_utf8_mut(&mut [b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^--------------------------------------------------^
+ | |
+ | the literal was valid UTF-8 up to the 2 bytes
+
+warning: calls to `std::str::from_utf8` with a invalid literal always return an error
+ --> $DIR/invalid_from_utf8.rs:82:9
+ |
+LL | std::str::from_utf8(&[99, 108, 130, 105, 112, 112, 121]);
+ | ^^^^^^^^^^^^^^^^^^^^-----------------------------------^
+ | |
+ | the literal was valid UTF-8 up to the 2 bytes
+
+warning: calls to `std::str::from_utf8` with a invalid literal always return an error
+ --> $DIR/invalid_from_utf8.rs:84:9
+ |
+LL | std::str::from_utf8(&[b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']);
+ | ^^^^^^^^^^^^^^^^^^^^----------------------------------------------^
+ | |
+ | the literal was valid UTF-8 up to the 2 bytes
+
+warning: calls to `std::str::from_utf8` with a invalid literal always return an error
+ --> $DIR/invalid_from_utf8.rs:86:9
+ |
+LL | std::str::from_utf8(b"cl\x82ippy");
+ | ^^^^^^^^^^^^^^^^^^^^-------------^
+ | |
+ | the literal was valid UTF-8 up to the 2 bytes
+
+warning: calls to `std::str::from_utf8` with a invalid literal always return an error
+ --> $DIR/invalid_from_utf8.rs:88:9
+ |
+LL | std::str::from_utf8(concat_bytes!(b"cl", b"\x82ippy"));
+ | ^^^^^^^^^^^^^^^^^^^^---------------------------------^
+ | |
+ | the literal was valid UTF-8 up to the 2 bytes
+
+warning: 12 warnings emitted
+
diff --git a/tests/ui/lint/issue-99387.rs b/tests/ui/lint/issue-99387.rs
index 616eb935e..ba5031167 100644
--- a/tests/ui/lint/issue-99387.rs
+++ b/tests/ui/lint/issue-99387.rs
@@ -1,4 +1,5 @@
-// check-pass
+//! Test that we don't follow through projections to find
+//! opaque types.
#![feature(type_alias_impl_trait)]
#![allow(private_in_public)]
@@ -18,6 +19,7 @@ impl<'a> Tr for &'a () {
}
pub fn ohno<'a>() -> <&'a () as Tr>::Item {
+ //~^ ERROR item constrains opaque type that is not in its signature
None.into_iter()
}
diff --git a/tests/ui/lint/issue-99387.stderr b/tests/ui/lint/issue-99387.stderr
new file mode 100644
index 000000000..3a46ce7e1
--- /dev/null
+++ b/tests/ui/lint/issue-99387.stderr
@@ -0,0 +1,15 @@
+error: item constrains opaque type that is not in its signature
+ --> $DIR/issue-99387.rs:21:22
+ |
+LL | pub fn ohno<'a>() -> <&'a () as Tr>::Item {
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: this item must mention the opaque type in its signature in order to be able to register hidden types
+note: this item must mention the opaque type in its signature in order to be able to register hidden types
+ --> $DIR/issue-99387.rs:21:8
+ |
+LL | pub fn ohno<'a>() -> <&'a () as Tr>::Item {
+ | ^^^^
+
+error: aborting due to previous error
+
diff --git a/tests/ui/lint/lint-attr-everywhere-early.rs b/tests/ui/lint/lint-attr-everywhere-early.rs
index 0c820ef9a..ae32ec426 100644
--- a/tests/ui/lint/lint-attr-everywhere-early.rs
+++ b/tests/ui/lint/lint-attr-everywhere-early.rs
@@ -147,7 +147,7 @@ fn expressions() {
#![deny(unsafe_code)]
unsafe {} //~ ERROR usage of an `unsafe` block
}
- let block_tail = {
+ let block_tail: () = {
#[deny(unsafe_code)]
unsafe {} //~ ERROR usage of an `unsafe` block
};
diff --git a/tests/ui/lint/lint-attr-everywhere-late.rs b/tests/ui/lint/lint-attr-everywhere-late.rs
index a24355bab..c3acdeda4 100644
--- a/tests/ui/lint/lint-attr-everywhere-late.rs
+++ b/tests/ui/lint/lint-attr-everywhere-late.rs
@@ -172,7 +172,7 @@ fn expressions() {
#![deny(enum_intrinsics_non_enums)]
discriminant::<i32>(&123); //~ ERROR the return value of
}
- let block_tail = {
+ let block_tail: () = {
#[deny(enum_intrinsics_non_enums)]
discriminant::<i32>(&123); //~ ERROR the return value of
};
diff --git a/tests/ui/lint/lint-ctypes-113436-1.rs b/tests/ui/lint/lint-ctypes-113436-1.rs
new file mode 100644
index 000000000..1ca59c686
--- /dev/null
+++ b/tests/ui/lint/lint-ctypes-113436-1.rs
@@ -0,0 +1,28 @@
+#![deny(improper_ctypes_definitions)]
+
+#[repr(C)]
+pub struct Foo {
+ a: u8,
+ b: (),
+}
+
+extern "C" fn foo(x: Foo) -> Foo {
+ todo!()
+}
+
+struct NotSafe(u32);
+
+#[repr(C)]
+pub struct Bar {
+ a: u8,
+ b: (),
+ c: NotSafe,
+}
+
+extern "C" fn bar(x: Bar) -> Bar {
+ //~^ ERROR `extern` fn uses type `NotSafe`, which is not FFI-safe
+ //~^^ ERROR `extern` fn uses type `NotSafe`, which is not FFI-safe
+ todo!()
+}
+
+fn main() {}
diff --git a/tests/ui/lint/lint-ctypes-113436-1.stderr b/tests/ui/lint/lint-ctypes-113436-1.stderr
new file mode 100644
index 000000000..7b63043f0
--- /dev/null
+++ b/tests/ui/lint/lint-ctypes-113436-1.stderr
@@ -0,0 +1,35 @@
+error: `extern` fn uses type `NotSafe`, which is not FFI-safe
+ --> $DIR/lint-ctypes-113436-1.rs:22:22
+ |
+LL | extern "C" fn bar(x: Bar) -> Bar {
+ | ^^^ not FFI-safe
+ |
+ = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
+ = note: this struct has unspecified layout
+note: the type is defined here
+ --> $DIR/lint-ctypes-113436-1.rs:13:1
+ |
+LL | struct NotSafe(u32);
+ | ^^^^^^^^^^^^^^
+note: the lint level is defined here
+ --> $DIR/lint-ctypes-113436-1.rs:1:9
+ |
+LL | #![deny(improper_ctypes_definitions)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: `extern` fn uses type `NotSafe`, which is not FFI-safe
+ --> $DIR/lint-ctypes-113436-1.rs:22:30
+ |
+LL | extern "C" fn bar(x: Bar) -> Bar {
+ | ^^^ not FFI-safe
+ |
+ = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
+ = note: this struct has unspecified layout
+note: the type is defined here
+ --> $DIR/lint-ctypes-113436-1.rs:13:1
+ |
+LL | struct NotSafe(u32);
+ | ^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
diff --git a/tests/ui/lint/lint-ctypes-113436.rs b/tests/ui/lint/lint-ctypes-113436.rs
new file mode 100644
index 000000000..4f733b5bb
--- /dev/null
+++ b/tests/ui/lint/lint-ctypes-113436.rs
@@ -0,0 +1,34 @@
+// check-pass
+#![deny(improper_ctypes_definitions)]
+
+#[repr(C)]
+pub struct Wrap<T>(T);
+
+#[repr(transparent)]
+pub struct TransparentWrap<T>(T);
+
+pub extern "C" fn f() -> Wrap<()> {
+ todo!()
+}
+
+const _: extern "C" fn() -> Wrap<()> = f;
+
+pub extern "C" fn ff() -> Wrap<Wrap<()>> {
+ todo!()
+}
+
+const _: extern "C" fn() -> Wrap<Wrap<()>> = ff;
+
+pub extern "C" fn g() -> TransparentWrap<()> {
+ todo!()
+}
+
+const _: extern "C" fn() -> TransparentWrap<()> = g;
+
+pub extern "C" fn gg() -> TransparentWrap<TransparentWrap<()>> {
+ todo!()
+}
+
+const _: extern "C" fn() -> TransparentWrap<TransparentWrap<()>> = gg;
+
+fn main() {}
diff --git a/tests/ui/lint/lint-ctypes-113900.rs b/tests/ui/lint/lint-ctypes-113900.rs
new file mode 100644
index 000000000..ac4ff1ae2
--- /dev/null
+++ b/tests/ui/lint/lint-ctypes-113900.rs
@@ -0,0 +1,12 @@
+// check-pass
+
+// Extending `improper_ctypes` to check external-ABI fn-ptrs means that it can encounter
+// projections which cannot be normalized - unsurprisingly, this shouldn't crash the compiler.
+
+trait Bar {
+ type Assoc;
+}
+
+type Foo<T> = extern "C" fn() -> <T as Bar>::Assoc;
+
+fn main() {}
diff --git a/tests/ui/lint/lint-ctypes-73249-2.rs b/tests/ui/lint/lint-ctypes-73249-2.rs
index 691047c8a..f30377d6c 100644
--- a/tests/ui/lint/lint-ctypes-73249-2.rs
+++ b/tests/ui/lint/lint-ctypes-73249-2.rs
@@ -1,7 +1,7 @@
#![feature(type_alias_impl_trait)]
#![deny(improper_ctypes)]
-pub trait Baz {}
+trait Baz {}
impl Baz for () {}
@@ -9,7 +9,7 @@ type Qux = impl Baz;
fn assign() -> Qux {}
-pub trait Foo {
+trait Foo {
type Assoc: 'static;
}
@@ -18,12 +18,12 @@ impl Foo for () {
}
#[repr(transparent)]
-pub struct A<T: Foo> {
+struct A<T: Foo> {
x: &'static <T as Foo>::Assoc,
}
extern "C" {
- pub fn lint_me() -> A<()>; //~ ERROR: uses type `Qux`
+ fn lint_me() -> A<()>; //~ ERROR: uses type `Qux`
}
fn main() {}
diff --git a/tests/ui/lint/lint-ctypes-73249-2.stderr b/tests/ui/lint/lint-ctypes-73249-2.stderr
index 8073c33dd..49fa54114 100644
--- a/tests/ui/lint/lint-ctypes-73249-2.stderr
+++ b/tests/ui/lint/lint-ctypes-73249-2.stderr
@@ -1,8 +1,8 @@
error: `extern` block uses type `Qux`, which is not FFI-safe
- --> $DIR/lint-ctypes-73249-2.rs:26:25
+ --> $DIR/lint-ctypes-73249-2.rs:26:21
|
-LL | pub fn lint_me() -> A<()>;
- | ^^^^^ not FFI-safe
+LL | fn lint_me() -> A<()>;
+ | ^^^^^ not FFI-safe
|
= note: opaque types have no C equivalent
note: the lint level is defined here
diff --git a/tests/ui/lint/lint-ctypes-73251-1.rs b/tests/ui/lint/lint-ctypes-73251-1.rs
index 145ba784f..fc11f23a1 100644
--- a/tests/ui/lint/lint-ctypes-73251-1.rs
+++ b/tests/ui/lint/lint-ctypes-73251-1.rs
@@ -1,13 +1,13 @@
#![feature(type_alias_impl_trait)]
#![deny(improper_ctypes)]
-pub trait Baz {}
+trait Baz {}
impl Baz for u32 {}
type Qux = impl Baz;
-pub trait Foo {
+trait Foo {
type Assoc;
}
@@ -20,7 +20,7 @@ fn assign() -> Qux {
}
extern "C" {
- pub fn lint_me() -> <u32 as Foo>::Assoc; //~ ERROR: uses type `Qux`
+ fn lint_me() -> <u32 as Foo>::Assoc; //~ ERROR: uses type `Qux`
}
fn main() {}
diff --git a/tests/ui/lint/lint-ctypes-73251-1.stderr b/tests/ui/lint/lint-ctypes-73251-1.stderr
index 9f43576ad..b4eb921b9 100644
--- a/tests/ui/lint/lint-ctypes-73251-1.stderr
+++ b/tests/ui/lint/lint-ctypes-73251-1.stderr
@@ -1,8 +1,8 @@
error: `extern` block uses type `Qux`, which is not FFI-safe
- --> $DIR/lint-ctypes-73251-1.rs:23:25
+ --> $DIR/lint-ctypes-73251-1.rs:23:21
|
-LL | pub fn lint_me() -> <u32 as Foo>::Assoc;
- | ^^^^^^^^^^^^^^^^^^^ not FFI-safe
+LL | fn lint_me() -> <u32 as Foo>::Assoc;
+ | ^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
= note: opaque types have no C equivalent
note: the lint level is defined here
diff --git a/tests/ui/lint/lint-ctypes-73251-2.rs b/tests/ui/lint/lint-ctypes-73251-2.rs
index df71a9457..fbe0a58f3 100644
--- a/tests/ui/lint/lint-ctypes-73251-2.rs
+++ b/tests/ui/lint/lint-ctypes-73251-2.rs
@@ -33,7 +33,7 @@ fn use_of_b() -> AliasB {
}
extern "C" {
- pub fn lint_me() -> <AliasB as TraitB>::Assoc; //~ ERROR: uses type `AliasA`
+ fn lint_me() -> <AliasB as TraitB>::Assoc; //~ ERROR: uses type `AliasA`
}
fn main() {}
diff --git a/tests/ui/lint/lint-ctypes-73251-2.stderr b/tests/ui/lint/lint-ctypes-73251-2.stderr
index 0b3de379c..e44cd45bd 100644
--- a/tests/ui/lint/lint-ctypes-73251-2.stderr
+++ b/tests/ui/lint/lint-ctypes-73251-2.stderr
@@ -1,8 +1,8 @@
error: `extern` block uses type `AliasA`, which is not FFI-safe
- --> $DIR/lint-ctypes-73251-2.rs:36:25
+ --> $DIR/lint-ctypes-73251-2.rs:36:21
|
-LL | pub fn lint_me() -> <AliasB as TraitB>::Assoc;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
+LL | fn lint_me() -> <AliasB as TraitB>::Assoc;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
= note: opaque types have no C equivalent
note: the lint level is defined here
diff --git a/tests/ui/lint/lint-ctypes-73251.rs b/tests/ui/lint/lint-ctypes-73251.rs
index ebc2ca77b..a00d1a75a 100644
--- a/tests/ui/lint/lint-ctypes-73251.rs
+++ b/tests/ui/lint/lint-ctypes-73251.rs
@@ -3,7 +3,7 @@
#![feature(type_alias_impl_trait)]
#![deny(improper_ctypes)]
-pub trait Foo {
+trait Foo {
type Assoc;
}
@@ -16,7 +16,7 @@ type Bar = impl Foo<Assoc = u32>;
fn assign() -> Bar {}
extern "C" {
- pub fn lint_me() -> <Bar as Foo>::Assoc;
+ fn lint_me() -> <Bar as Foo>::Assoc;
}
fn main() {}
diff --git a/tests/ui/lint/lint-ctypes-94223.rs b/tests/ui/lint/lint-ctypes-94223.rs
new file mode 100644
index 000000000..70dd2a71f
--- /dev/null
+++ b/tests/ui/lint/lint-ctypes-94223.rs
@@ -0,0 +1,42 @@
+#![crate_type = "lib"]
+#![deny(improper_ctypes_definitions)]
+
+pub fn bad(f: extern "C" fn([u8])) {}
+//~^ ERROR `extern` fn uses type `[u8]`, which is not FFI-safe
+
+pub fn bad_twice(f: Result<extern "C" fn([u8]), extern "C" fn([u8])>) {}
+//~^ ERROR `extern` fn uses type `[u8]`, which is not FFI-safe
+//~^^ ERROR `extern` fn uses type `[u8]`, which is not FFI-safe
+
+struct BadStruct(extern "C" fn([u8]));
+//~^ ERROR `extern` fn uses type `[u8]`, which is not FFI-safe
+
+enum BadEnum {
+ A(extern "C" fn([u8])),
+ //~^ ERROR `extern` fn uses type `[u8]`, which is not FFI-safe
+}
+
+enum BadUnion {
+ A(extern "C" fn([u8])),
+ //~^ ERROR `extern` fn uses type `[u8]`, which is not FFI-safe
+}
+
+type Foo = extern "C" fn([u8]);
+//~^ ERROR `extern` fn uses type `[u8]`, which is not FFI-safe
+
+pub struct FfiUnsafe;
+
+#[allow(improper_ctypes_definitions)]
+extern "C" fn f(_: FfiUnsafe) {
+ unimplemented!()
+}
+
+pub static BAD: extern "C" fn(FfiUnsafe) = f;
+//~^ ERROR `extern` fn uses type `FfiUnsafe`, which is not FFI-safe
+
+pub static BAD_TWICE: Result<extern "C" fn(FfiUnsafe), extern "C" fn(FfiUnsafe)> = Ok(f);
+//~^ ERROR `extern` fn uses type `FfiUnsafe`, which is not FFI-safe
+//~^^ ERROR `extern` fn uses type `FfiUnsafe`, which is not FFI-safe
+
+pub const BAD_CONST: extern "C" fn(FfiUnsafe) = f;
+//~^ ERROR `extern` fn uses type `FfiUnsafe`, which is not FFI-safe
diff --git a/tests/ui/lint/lint-ctypes-94223.stderr b/tests/ui/lint/lint-ctypes-94223.stderr
new file mode 100644
index 000000000..49e64ed51
--- /dev/null
+++ b/tests/ui/lint/lint-ctypes-94223.stderr
@@ -0,0 +1,126 @@
+error: `extern` fn uses type `[u8]`, which is not FFI-safe
+ --> $DIR/lint-ctypes-94223.rs:4:15
+ |
+LL | pub fn bad(f: extern "C" fn([u8])) {}
+ | ^^^^^^^^^^^^^^^^^^^ not FFI-safe
+ |
+ = help: consider using a raw pointer instead
+ = note: slices have no C equivalent
+note: the lint level is defined here
+ --> $DIR/lint-ctypes-94223.rs:2:9
+ |
+LL | #![deny(improper_ctypes_definitions)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: `extern` fn uses type `[u8]`, which is not FFI-safe
+ --> $DIR/lint-ctypes-94223.rs:7:28
+ |
+LL | pub fn bad_twice(f: Result<extern "C" fn([u8]), extern "C" fn([u8])>) {}
+ | ^^^^^^^^^^^^^^^^^^^ not FFI-safe
+ |
+ = help: consider using a raw pointer instead
+ = note: slices have no C equivalent
+
+error: `extern` fn uses type `[u8]`, which is not FFI-safe
+ --> $DIR/lint-ctypes-94223.rs:7:49
+ |
+LL | pub fn bad_twice(f: Result<extern "C" fn([u8]), extern "C" fn([u8])>) {}
+ | ^^^^^^^^^^^^^^^^^^^ not FFI-safe
+ |
+ = help: consider using a raw pointer instead
+ = note: slices have no C equivalent
+
+error: `extern` fn uses type `[u8]`, which is not FFI-safe
+ --> $DIR/lint-ctypes-94223.rs:11:18
+ |
+LL | struct BadStruct(extern "C" fn([u8]));
+ | ^^^^^^^^^^^^^^^^^^^ not FFI-safe
+ |
+ = help: consider using a raw pointer instead
+ = note: slices have no C equivalent
+
+error: `extern` fn uses type `[u8]`, which is not FFI-safe
+ --> $DIR/lint-ctypes-94223.rs:15:7
+ |
+LL | A(extern "C" fn([u8])),
+ | ^^^^^^^^^^^^^^^^^^^ not FFI-safe
+ |
+ = help: consider using a raw pointer instead
+ = note: slices have no C equivalent
+
+error: `extern` fn uses type `[u8]`, which is not FFI-safe
+ --> $DIR/lint-ctypes-94223.rs:20:7
+ |
+LL | A(extern "C" fn([u8])),
+ | ^^^^^^^^^^^^^^^^^^^ not FFI-safe
+ |
+ = help: consider using a raw pointer instead
+ = note: slices have no C equivalent
+
+error: `extern` fn uses type `[u8]`, which is not FFI-safe
+ --> $DIR/lint-ctypes-94223.rs:24:12
+ |
+LL | type Foo = extern "C" fn([u8]);
+ | ^^^^^^^^^^^^^^^^^^^ not FFI-safe
+ |
+ = help: consider using a raw pointer instead
+ = note: slices have no C equivalent
+
+error: `extern` fn uses type `FfiUnsafe`, which is not FFI-safe
+ --> $DIR/lint-ctypes-94223.rs:34:17
+ |
+LL | pub static BAD: extern "C" fn(FfiUnsafe) = f;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
+ |
+ = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
+ = note: this struct has unspecified layout
+note: the type is defined here
+ --> $DIR/lint-ctypes-94223.rs:27:1
+ |
+LL | pub struct FfiUnsafe;
+ | ^^^^^^^^^^^^^^^^^^^^
+
+error: `extern` fn uses type `FfiUnsafe`, which is not FFI-safe
+ --> $DIR/lint-ctypes-94223.rs:37:30
+ |
+LL | pub static BAD_TWICE: Result<extern "C" fn(FfiUnsafe), extern "C" fn(FfiUnsafe)> = Ok(f);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
+ |
+ = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
+ = note: this struct has unspecified layout
+note: the type is defined here
+ --> $DIR/lint-ctypes-94223.rs:27:1
+ |
+LL | pub struct FfiUnsafe;
+ | ^^^^^^^^^^^^^^^^^^^^
+
+error: `extern` fn uses type `FfiUnsafe`, which is not FFI-safe
+ --> $DIR/lint-ctypes-94223.rs:37:56
+ |
+LL | pub static BAD_TWICE: Result<extern "C" fn(FfiUnsafe), extern "C" fn(FfiUnsafe)> = Ok(f);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
+ |
+ = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
+ = note: this struct has unspecified layout
+note: the type is defined here
+ --> $DIR/lint-ctypes-94223.rs:27:1
+ |
+LL | pub struct FfiUnsafe;
+ | ^^^^^^^^^^^^^^^^^^^^
+
+error: `extern` fn uses type `FfiUnsafe`, which is not FFI-safe
+ --> $DIR/lint-ctypes-94223.rs:41:22
+ |
+LL | pub const BAD_CONST: extern "C" fn(FfiUnsafe) = f;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
+ |
+ = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
+ = note: this struct has unspecified layout
+note: the type is defined here
+ --> $DIR/lint-ctypes-94223.rs:27:1
+ |
+LL | pub struct FfiUnsafe;
+ | ^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 11 previous errors
+
diff --git a/tests/ui/lint/lint-unnecessary-parens.fixed b/tests/ui/lint/lint-unnecessary-parens.fixed
index 9c144324f..bafac05d8 100644
--- a/tests/ui/lint/lint-unnecessary-parens.fixed
+++ b/tests/ui/lint/lint-unnecessary-parens.fixed
@@ -35,6 +35,14 @@ pub fn passes_unused_parens_lint() -> &'static (dyn Trait) {
panic!()
}
+pub fn parens_with_keyword(e: &[()]) -> i32 {
+ if true {} //~ ERROR unnecessary parentheses around `if`
+ while true {} //~ ERROR unnecessary parentheses around `while`
+ for _ in e {} //~ ERROR unnecessary parentheses around `for`
+ match 1 { _ => ()} //~ ERROR unnecessary parentheses around `match`
+ return 1; //~ ERROR unnecessary parentheses around `return` value
+}
+
macro_rules! baz {
($($foo:expr),+) => {
($($foo),*)
diff --git a/tests/ui/lint/lint-unnecessary-parens.rs b/tests/ui/lint/lint-unnecessary-parens.rs
index 4fd9cabb3..ce537a4dc 100644
--- a/tests/ui/lint/lint-unnecessary-parens.rs
+++ b/tests/ui/lint/lint-unnecessary-parens.rs
@@ -35,6 +35,14 @@ pub fn passes_unused_parens_lint() -> &'static (dyn Trait) {
panic!()
}
+pub fn parens_with_keyword(e: &[()]) -> i32 {
+ if(true) {} //~ ERROR unnecessary parentheses around `if`
+ while(true) {} //~ ERROR unnecessary parentheses around `while`
+ for _ in(e) {} //~ ERROR unnecessary parentheses around `for`
+ match(1) { _ => ()} //~ ERROR unnecessary parentheses around `match`
+ return(1); //~ ERROR unnecessary parentheses around `return` value
+}
+
macro_rules! baz {
($($foo:expr),+) => {
($($foo),*)
diff --git a/tests/ui/lint/lint-unnecessary-parens.stderr b/tests/ui/lint/lint-unnecessary-parens.stderr
index e13620f06..2ad07530f 100644
--- a/tests/ui/lint/lint-unnecessary-parens.stderr
+++ b/tests/ui/lint/lint-unnecessary-parens.stderr
@@ -63,8 +63,68 @@ LL - (5)
LL + 5
|
+error: unnecessary parentheses around `if` condition
+ --> $DIR/lint-unnecessary-parens.rs:39:7
+ |
+LL | if(true) {}
+ | ^ ^
+ |
+help: remove these parentheses
+ |
+LL - if(true) {}
+LL + if true {}
+ |
+
+error: unnecessary parentheses around `while` condition
+ --> $DIR/lint-unnecessary-parens.rs:40:10
+ |
+LL | while(true) {}
+ | ^ ^
+ |
+help: remove these parentheses
+ |
+LL - while(true) {}
+LL + while true {}
+ |
+
+error: unnecessary parentheses around `for` iterator expression
+ --> $DIR/lint-unnecessary-parens.rs:41:13
+ |
+LL | for _ in(e) {}
+ | ^ ^
+ |
+help: remove these parentheses
+ |
+LL - for _ in(e) {}
+LL + for _ in e {}
+ |
+
+error: unnecessary parentheses around `match` scrutinee expression
+ --> $DIR/lint-unnecessary-parens.rs:42:10
+ |
+LL | match(1) { _ => ()}
+ | ^ ^
+ |
+help: remove these parentheses
+ |
+LL - match(1) { _ => ()}
+LL + match 1 { _ => ()}
+ |
+
+error: unnecessary parentheses around `return` value
+ --> $DIR/lint-unnecessary-parens.rs:43:11
+ |
+LL | return(1);
+ | ^ ^
+ |
+help: remove these parentheses
+ |
+LL - return(1);
+LL + return 1;
+ |
+
error: unnecessary parentheses around assigned value
- --> $DIR/lint-unnecessary-parens.rs:44:31
+ --> $DIR/lint-unnecessary-parens.rs:52:31
|
LL | pub const CONST_ITEM: usize = (10);
| ^ ^
@@ -76,7 +136,7 @@ LL + pub const CONST_ITEM: usize = 10;
|
error: unnecessary parentheses around assigned value
- --> $DIR/lint-unnecessary-parens.rs:45:33
+ --> $DIR/lint-unnecessary-parens.rs:53:33
|
LL | pub static STATIC_ITEM: usize = (10);
| ^ ^
@@ -88,7 +148,7 @@ LL + pub static STATIC_ITEM: usize = 10;
|
error: unnecessary parentheses around function argument
- --> $DIR/lint-unnecessary-parens.rs:49:9
+ --> $DIR/lint-unnecessary-parens.rs:57:9
|
LL | bar((true));
| ^ ^
@@ -100,7 +160,7 @@ LL + bar(true);
|
error: unnecessary parentheses around `if` condition
- --> $DIR/lint-unnecessary-parens.rs:51:8
+ --> $DIR/lint-unnecessary-parens.rs:59:8
|
LL | if (true) {}
| ^ ^
@@ -112,7 +172,7 @@ LL + if true {}
|
error: unnecessary parentheses around `while` condition
- --> $DIR/lint-unnecessary-parens.rs:52:11
+ --> $DIR/lint-unnecessary-parens.rs:60:11
|
LL | while (true) {}
| ^ ^
@@ -124,7 +184,7 @@ LL + while true {}
|
error: unnecessary parentheses around `match` scrutinee expression
- --> $DIR/lint-unnecessary-parens.rs:53:11
+ --> $DIR/lint-unnecessary-parens.rs:61:11
|
LL | match (true) {
| ^ ^
@@ -136,7 +196,7 @@ LL + match true {
|
error: unnecessary parentheses around `let` scrutinee expression
- --> $DIR/lint-unnecessary-parens.rs:56:16
+ --> $DIR/lint-unnecessary-parens.rs:64:16
|
LL | if let 1 = (1) {}
| ^ ^
@@ -148,7 +208,7 @@ LL + if let 1 = 1 {}
|
error: unnecessary parentheses around `let` scrutinee expression
- --> $DIR/lint-unnecessary-parens.rs:57:19
+ --> $DIR/lint-unnecessary-parens.rs:65:19
|
LL | while let 1 = (2) {}
| ^ ^
@@ -160,7 +220,7 @@ LL + while let 1 = 2 {}
|
error: unnecessary parentheses around method argument
- --> $DIR/lint-unnecessary-parens.rs:73:24
+ --> $DIR/lint-unnecessary-parens.rs:81:24
|
LL | X { y: false }.foo((true));
| ^ ^
@@ -172,7 +232,7 @@ LL + X { y: false }.foo(true);
|
error: unnecessary parentheses around assigned value
- --> $DIR/lint-unnecessary-parens.rs:75:18
+ --> $DIR/lint-unnecessary-parens.rs:83:18
|
LL | let mut _a = (0);
| ^ ^
@@ -184,7 +244,7 @@ LL + let mut _a = 0;
|
error: unnecessary parentheses around assigned value
- --> $DIR/lint-unnecessary-parens.rs:76:10
+ --> $DIR/lint-unnecessary-parens.rs:84:10
|
LL | _a = (0);
| ^ ^
@@ -196,7 +256,7 @@ LL + _a = 0;
|
error: unnecessary parentheses around assigned value
- --> $DIR/lint-unnecessary-parens.rs:77:11
+ --> $DIR/lint-unnecessary-parens.rs:85:11
|
LL | _a += (1);
| ^ ^
@@ -207,5 +267,5 @@ LL - _a += (1);
LL + _a += 1;
|
-error: aborting due to 17 previous errors
+error: aborting due to 22 previous errors
diff --git a/tests/ui/lint/opaque-ty-ffi-unsafe.rs b/tests/ui/lint/opaque-ty-ffi-unsafe.rs
index b7cc38e99..5faeac9ed 100644
--- a/tests/ui/lint/opaque-ty-ffi-unsafe.rs
+++ b/tests/ui/lint/opaque-ty-ffi-unsafe.rs
@@ -3,12 +3,12 @@
type A = impl Fn();
-pub fn ret_closure() -> A {
+pub(crate) fn ret_closure() -> A {
|| {}
}
extern "C" {
- pub fn a(_: A);
+ pub(crate) fn a(_: A);
//~^ ERROR `extern` block uses type `A`, which is not FFI-safe [improper_ctypes]
}
diff --git a/tests/ui/lint/opaque-ty-ffi-unsafe.stderr b/tests/ui/lint/opaque-ty-ffi-unsafe.stderr
index 33aa95854..ba9e18bcc 100644
--- a/tests/ui/lint/opaque-ty-ffi-unsafe.stderr
+++ b/tests/ui/lint/opaque-ty-ffi-unsafe.stderr
@@ -1,8 +1,8 @@
error: `extern` block uses type `A`, which is not FFI-safe
- --> $DIR/opaque-ty-ffi-unsafe.rs:11:17
+ --> $DIR/opaque-ty-ffi-unsafe.rs:11:24
|
-LL | pub fn a(_: A);
- | ^ not FFI-safe
+LL | pub(crate) fn a(_: A);
+ | ^ not FFI-safe
|
= note: opaque types have no C equivalent
note: the lint level is defined here
diff --git a/tests/ui/lint/reference_casting.rs b/tests/ui/lint/reference_casting.rs
new file mode 100644
index 000000000..996382049
--- /dev/null
+++ b/tests/ui/lint/reference_casting.rs
@@ -0,0 +1,51 @@
+// check-fail
+
+#![feature(ptr_from_ref)]
+#![deny(invalid_reference_casting)]
+
+extern "C" {
+ // N.B., mutability can be easily incorrect in FFI calls -- as
+ // in C, the default is mutable pointers.
+ fn ffi(c: *mut u8);
+ fn int_ffi(c: *mut i32);
+}
+
+fn main() {
+ let s = String::from("Hello");
+ let a = &s;
+ unsafe {
+ let num = &3i32;
+ let mut_num = &mut 3i32;
+
+ (*(a as *const _ as *mut String)).push_str(" world");
+ //~^ ERROR casting `&T` to `&mut T` is undefined behavior
+ *(a as *const _ as *mut _) = String::from("Replaced");
+ //~^ ERROR casting `&T` to `&mut T` is undefined behavior
+ *(a as *const _ as *mut String) += " world";
+ //~^ ERROR casting `&T` to `&mut T` is undefined behavior
+ let _num = &mut *(num as *const i32 as *mut i32);
+ //~^ ERROR casting `&T` to `&mut T` is undefined behavior
+ let _num = &mut *(num as *const i32).cast_mut();
+ //~^ ERROR casting `&T` to `&mut T` is undefined behavior
+ let _num = *{ num as *const i32 }.cast_mut();
+ //~^ ERROR casting `&T` to `&mut T` is undefined behavior
+ *std::ptr::from_ref(num).cast_mut() += 1;
+ //~^ ERROR casting `&T` to `&mut T` is undefined behavior
+ *std::ptr::from_ref({ num }).cast_mut() += 1;
+ //~^ ERROR casting `&T` to `&mut T` is undefined behavior
+ *{ std::ptr::from_ref(num) }.cast_mut() += 1;
+ //~^ ERROR casting `&T` to `&mut T` is undefined behavior
+ *(std::ptr::from_ref({ num }) as *mut i32) += 1;
+ //~^ ERROR casting `&T` to `&mut T` is undefined behavior
+
+ // Shouldn't be warned against
+ println!("{}", *(num as *const _ as *const i16));
+ println!("{}", *(mut_num as *mut _ as *mut i16));
+ ffi(a.as_ptr() as *mut _);
+ int_ffi(num as *const _ as *mut _);
+ int_ffi(&3 as *const _ as *mut _);
+ let mut value = 3;
+ let value: *const i32 = &mut value;
+ *(value as *const i16 as *mut i16) = 42;
+ }
+}
diff --git a/tests/ui/lint/reference_casting.stderr b/tests/ui/lint/reference_casting.stderr
new file mode 100644
index 000000000..d5b9bbef6
--- /dev/null
+++ b/tests/ui/lint/reference_casting.stderr
@@ -0,0 +1,68 @@
+error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
+ --> $DIR/reference_casting.rs:20:9
+ |
+LL | (*(a as *const _ as *mut String)).push_str(" world");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: the lint level is defined here
+ --> $DIR/reference_casting.rs:4:9
+ |
+LL | #![deny(invalid_reference_casting)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
+ --> $DIR/reference_casting.rs:22:9
+ |
+LL | *(a as *const _ as *mut _) = String::from("Replaced");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
+ --> $DIR/reference_casting.rs:24:9
+ |
+LL | *(a as *const _ as *mut String) += " world";
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
+ --> $DIR/reference_casting.rs:26:25
+ |
+LL | let _num = &mut *(num as *const i32 as *mut i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
+ --> $DIR/reference_casting.rs:28:25
+ |
+LL | let _num = &mut *(num as *const i32).cast_mut();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
+ --> $DIR/reference_casting.rs:30:20
+ |
+LL | let _num = *{ num as *const i32 }.cast_mut();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
+ --> $DIR/reference_casting.rs:32:9
+ |
+LL | *std::ptr::from_ref(num).cast_mut() += 1;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
+ --> $DIR/reference_casting.rs:34:9
+ |
+LL | *std::ptr::from_ref({ num }).cast_mut() += 1;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
+ --> $DIR/reference_casting.rs:36:9
+ |
+LL | *{ std::ptr::from_ref(num) }.cast_mut() += 1;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
+ --> $DIR/reference_casting.rs:38:9
+ |
+LL | *(std::ptr::from_ref({ num }) as *mut i32) += 1;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 10 previous errors
+
diff --git a/tests/ui/lint/trivial-casts-featuring-type-ascription.stderr b/tests/ui/lint/trivial-casts-featuring-type-ascription.stderr
index 5087807b6..159a54873 100644
--- a/tests/ui/lint/trivial-casts-featuring-type-ascription.stderr
+++ b/tests/ui/lint/trivial-casts-featuring-type-ascription.stderr
@@ -4,7 +4,7 @@ error: trivial numeric cast: `i32` as `i32`
LL | let lugubrious = 12i32 as i32;
| ^^^^^^^^^^^^
|
- = help: cast can be replaced by coercion; this might require type ascription or a temporary variable
+ = help: cast can be replaced by coercion; this might require a temporary variable
note: the lint level is defined here
--> $DIR/trivial-casts-featuring-type-ascription.rs:1:24
|
@@ -17,7 +17,7 @@ error: trivial cast: `&u32` as `*const u32`
LL | let _ = haunted as *const u32;
| ^^^^^^^^^^^^^^^^^^^^^
|
- = help: cast can be replaced by coercion; this might require type ascription or a temporary variable
+ = help: cast can be replaced by coercion; this might require a temporary variable
note: the lint level is defined here
--> $DIR/trivial-casts-featuring-type-ascription.rs:1:9
|
diff --git a/tests/ui/lint/type-overflow.stderr b/tests/ui/lint/type-overflow.stderr
index 62cb1f7f4..e7c90dcc8 100644
--- a/tests/ui/lint/type-overflow.stderr
+++ b/tests/ui/lint/type-overflow.stderr
@@ -16,17 +16,33 @@ warning: literal out of range for `i8`
--> $DIR/type-overflow.rs:10:16
|
LL | let fail = 0b1000_0001i8;
- | ^^^^^^^^^^^^^ help: consider using the type `u8` instead: `0b1000_0001u8`
+ | ^^^^^^^^^^^^^
|
= note: the literal `0b1000_0001i8` (decimal `129`) does not fit into the type `i8` and will become `-127i8`
+help: consider using the type `u8` instead
+ |
+LL | let fail = 0b1000_0001u8;
+ | ~~~~~~~~~~~~~
+help: to use as a negative number (decimal `-127`), consider using the type `u8` for the literal and cast it to `i8`
+ |
+LL | let fail = 0b1000_0001u8 as i8;
+ | ~~~~~~~~~~~~~~~~~~~
warning: literal out of range for `i64`
--> $DIR/type-overflow.rs:12:16
|
LL | let fail = 0x8000_0000_0000_0000i64;
- | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the type `u64` instead: `0x8000_0000_0000_0000u64`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the literal `0x8000_0000_0000_0000i64` (decimal `9223372036854775808`) does not fit into the type `i64` and will become `-9223372036854775808i64`
+help: consider using the type `u64` instead
+ |
+LL | let fail = 0x8000_0000_0000_0000u64;
+ | ~~~~~~~~~~~~~~~~~~~~~~~~
+help: to use as a negative number (decimal `-9223372036854775808`), consider using the type `u64` for the literal and cast it to `i64`
+ |
+LL | let fail = 0x8000_0000_0000_0000u64 as i64;
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
warning: literal out of range for `u32`
--> $DIR/type-overflow.rs:14:16
@@ -44,6 +60,10 @@ LL | let fail: i128 = 0x8000_0000_0000_0000_0000_0000_0000_0000;
|
= note: the literal `0x8000_0000_0000_0000_0000_0000_0000_0000` (decimal `170141183460469231731687303715884105728`) does not fit into the type `i128` and will become `-170141183460469231731687303715884105728i128`
= help: consider using the type `u128` instead
+help: to use as a negative number (decimal `-170141183460469231731687303715884105728`), consider using the type `u128` for the literal and cast it to `i128`
+ |
+LL | let fail: i128 = 0x8000_0000_0000_0000_0000_0000_0000_0000u128 as i128;
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
warning: literal out of range for `i32`
--> $DIR/type-overflow.rs:19:16
@@ -53,6 +73,10 @@ LL | let fail = 0x8FFF_FFFF_FFFF_FFFE;
|
= note: the literal `0x8FFF_FFFF_FFFF_FFFE` (decimal `10376293541461622782`) does not fit into the type `i32` and will become `-2i32`
= help: consider using the type `i128` instead
+help: to use as a negative number (decimal `-2`), consider using the type `u32` for the literal and cast it to `i32`
+ |
+LL | let fail = 0x8FFF_FFFF_FFFF_FFFEu32 as i32;
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
warning: literal out of range for `i8`
--> $DIR/type-overflow.rs:21:17
diff --git a/tests/ui/lint/undropped_manually_drops.rs b/tests/ui/lint/undropped_manually_drops.rs
new file mode 100644
index 000000000..7286121a4
--- /dev/null
+++ b/tests/ui/lint/undropped_manually_drops.rs
@@ -0,0 +1,19 @@
+// check-fail
+
+struct S;
+
+fn main() {
+ let mut manual1 = std::mem::ManuallyDrop::new(S);
+ let mut manual2 = std::mem::ManuallyDrop::new(S);
+ let mut manual3 = std::mem::ManuallyDrop::new(S);
+
+ drop(std::mem::ManuallyDrop::new(S)); //~ ERROR calls to `std::mem::drop`
+ drop(manual1); //~ ERROR calls to `std::mem::drop`
+ drop({ manual3 }); //~ ERROR calls to `std::mem::drop`
+
+ // These lines will drop `S` and should be okay.
+ unsafe {
+ std::mem::ManuallyDrop::drop(&mut std::mem::ManuallyDrop::new(S));
+ std::mem::ManuallyDrop::drop(&mut manual2);
+ }
+}
diff --git a/tests/ui/lint/undropped_manually_drops.stderr b/tests/ui/lint/undropped_manually_drops.stderr
new file mode 100644
index 000000000..156b647eb
--- /dev/null
+++ b/tests/ui/lint/undropped_manually_drops.stderr
@@ -0,0 +1,42 @@
+error: calls to `std::mem::drop` with `std::mem::ManuallyDrop` instead of the inner value does nothing
+ --> $DIR/undropped_manually_drops.rs:10:5
+ |
+LL | drop(std::mem::ManuallyDrop::new(S));
+ | ^^^^^------------------------------^
+ | |
+ | argument has type `ManuallyDrop<S>`
+ |
+ = note: `#[deny(undropped_manually_drops)]` on by default
+help: use `std::mem::ManuallyDrop::into_inner` to get the inner value
+ |
+LL | drop(std::mem::ManuallyDrop::into_inner(std::mem::ManuallyDrop::new(S)));
+ | +++++++++++++++++++++++++++++++++++ +
+
+error: calls to `std::mem::drop` with `std::mem::ManuallyDrop` instead of the inner value does nothing
+ --> $DIR/undropped_manually_drops.rs:11:5
+ |
+LL | drop(manual1);
+ | ^^^^^-------^
+ | |
+ | argument has type `ManuallyDrop<S>`
+ |
+help: use `std::mem::ManuallyDrop::into_inner` to get the inner value
+ |
+LL | drop(std::mem::ManuallyDrop::into_inner(manual1));
+ | +++++++++++++++++++++++++++++++++++ +
+
+error: calls to `std::mem::drop` with `std::mem::ManuallyDrop` instead of the inner value does nothing
+ --> $DIR/undropped_manually_drops.rs:12:5
+ |
+LL | drop({ manual3 });
+ | ^^^^^-----------^
+ | |
+ | argument has type `ManuallyDrop<S>`
+ |
+help: use `std::mem::ManuallyDrop::into_inner` to get the inner value
+ |
+LL | drop(std::mem::ManuallyDrop::into_inner({ manual3 }));
+ | +++++++++++++++++++++++++++++++++++ +
+
+error: aborting due to 3 previous errors
+
diff --git a/tests/ui/lint/unused/lint-unused-extern-crate.rs b/tests/ui/lint/unused/lint-unused-extern-crate.rs
index d5e4da526..79df58b70 100644
--- a/tests/ui/lint/unused/lint-unused-extern-crate.rs
+++ b/tests/ui/lint/unused/lint-unused-extern-crate.rs
@@ -31,5 +31,5 @@ mod foo {
fn main() {
lint_unused_extern_crate3::foo();
- let y = foo();
+ foo();
}
diff --git a/tests/ui/lint/unused/lint-unused-imports.rs b/tests/ui/lint/unused/lint-unused-imports.rs
index 4754d8880..953992ecf 100644
--- a/tests/ui/lint/unused/lint-unused-imports.rs
+++ b/tests/ui/lint/unused/lint-unused-imports.rs
@@ -86,5 +86,5 @@ fn main() {
let mut b = 4;
swap(&mut a, &mut b);
test::C.b();
- let _a = foo();
+ foo();
}
diff --git a/tests/ui/lint/unused/lint-unused-variables.rs b/tests/ui/lint/unused/lint-unused-variables.rs
index 6850e9992..621c6ef84 100644
--- a/tests/ui/lint/unused/lint-unused-variables.rs
+++ b/tests/ui/lint/unused/lint-unused-variables.rs
@@ -74,6 +74,6 @@ fn main() {
b: i32,
//~^ ERROR unused variable: `b`
| {};
- let _ = a(1, 2);
- let _ = b(1, 2);
+ a(1, 2);
+ b(1, 2);
}
diff --git a/tests/ui/lint/unused/must-use-block-expr.fixed b/tests/ui/lint/unused/must-use-block-expr.fixed
new file mode 100644
index 000000000..642012812
--- /dev/null
+++ b/tests/ui/lint/unused/must-use-block-expr.fixed
@@ -0,0 +1,36 @@
+// run-rustfix
+// check-pass
+
+#![warn(unused_must_use)]
+
+#[must_use]
+fn foo() -> i32 {
+ 42
+}
+
+fn bar() {
+ {
+ let _ = foo();
+ //~^ WARN unused return value
+ }
+}
+
+fn baz() {
+ {
+ let _ = foo();
+ //~^ WARN unused return value
+ };
+}
+
+fn main() {
+ bar();
+ baz();
+ {
+ let _ = 1 + 2;
+ //~^ WARN unused arithmetic operation
+ }
+ {
+ let _ = 1 + 2;
+ //~^ WARN unused arithmetic operation
+ };
+}
diff --git a/tests/ui/lint/unused/must-use-block-expr.rs b/tests/ui/lint/unused/must-use-block-expr.rs
new file mode 100644
index 000000000..e0a680aa0
--- /dev/null
+++ b/tests/ui/lint/unused/must-use-block-expr.rs
@@ -0,0 +1,36 @@
+// run-rustfix
+// check-pass
+
+#![warn(unused_must_use)]
+
+#[must_use]
+fn foo() -> i32 {
+ 42
+}
+
+fn bar() {
+ {
+ foo();
+ //~^ WARN unused return value
+ }
+}
+
+fn baz() {
+ {
+ foo()
+ //~^ WARN unused return value
+ };
+}
+
+fn main() {
+ bar();
+ baz();
+ {
+ 1 + 2;
+ //~^ WARN unused arithmetic operation
+ }
+ {
+ 1 + 2
+ //~^ WARN unused arithmetic operation
+ };
+}
diff --git a/tests/ui/lint/unused/must-use-block-expr.stderr b/tests/ui/lint/unused/must-use-block-expr.stderr
new file mode 100644
index 000000000..d821beb1d
--- /dev/null
+++ b/tests/ui/lint/unused/must-use-block-expr.stderr
@@ -0,0 +1,51 @@
+warning: unused return value of `foo` that must be used
+ --> $DIR/must-use-block-expr.rs:13:9
+ |
+LL | foo();
+ | ^^^^^
+ |
+note: the lint level is defined here
+ --> $DIR/must-use-block-expr.rs:4:9
+ |
+LL | #![warn(unused_must_use)]
+ | ^^^^^^^^^^^^^^^
+help: use `let _ = ...` to ignore the resulting value
+ |
+LL | let _ = foo();
+ | +++++++
+
+warning: unused return value of `foo` that must be used
+ --> $DIR/must-use-block-expr.rs:20:9
+ |
+LL | foo()
+ | ^^^^^
+ |
+help: use `let _ = ...` to ignore the resulting value
+ |
+LL | let _ = foo();
+ | +++++++ +
+
+warning: unused arithmetic operation that must be used
+ --> $DIR/must-use-block-expr.rs:29:9
+ |
+LL | 1 + 2;
+ | ^^^^^ the arithmetic operation produces a value
+ |
+help: use `let _ = ...` to ignore the resulting value
+ |
+LL | let _ = 1 + 2;
+ | +++++++
+
+warning: unused arithmetic operation that must be used
+ --> $DIR/must-use-block-expr.rs:33:9
+ |
+LL | 1 + 2
+ | ^^^^^ the arithmetic operation produces a value
+ |
+help: use `let _ = ...` to ignore the resulting value
+ |
+LL | let _ = 1 + 2;
+ | +++++++ +
+
+warning: 4 warnings emitted
+
diff --git a/tests/ui/lint/unused_import_warning_issue_45268.rs b/tests/ui/lint/unused_import_warning_issue_45268.rs
index 5ae482863..7aa4d4959 100644
--- a/tests/ui/lint/unused_import_warning_issue_45268.rs
+++ b/tests/ui/lint/unused_import_warning_issue_45268.rs
@@ -31,15 +31,15 @@ use test::B; // This is used by the test2::func() through import of super
mod test2 {
use super::*;
pub fn func() {
- let _ = <()>::a();
- let _ = ().b();
+ <()>::a();
+ ().b();
test3::inner_func();
}
mod test3 {
use super::*;
pub fn inner_func() {
- let _ = <()>::a();
- let _ = ().b();
+ <()>::a();
+ ().b();
}
}
}