about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSuyash458 <suyash.behera458@gmail.com>2020-12-09 16:39:33 +0530
committerSuyash458 <suyash.behera458@gmail.com>2020-12-11 11:00:29 +0530
commit9f27b7428307ecc6995a06f3bd666eccdbed6c99 (patch)
tree58a84574d6dfde4ac1622f016a94976a5a93b8a6
parent8df11e431b71caa7b4c891c70e9cc48144603067 (diff)
downloadrust-9f27b7428307ecc6995a06f3bd666eccdbed6c99.tar.gz
rust-9f27b7428307ecc6995a06f3bd666eccdbed6c99.zip
add test for missing_const_for_fn. fix test stderr
-rw-r--r--tests/ui/min_rust_version_attr.rs12
-rw-r--r--tests/ui/min_rust_version_attr.stderr51
2 files changed, 41 insertions, 22 deletions
diff --git a/tests/ui/min_rust_version_attr.rs b/tests/ui/min_rust_version_attr.rs
index ac75f5e46c3..3848bca3207 100644
--- a/tests/ui/min_rust_version_attr.rs
+++ b/tests/ui/min_rust_version_attr.rs
@@ -73,7 +73,11 @@ pub fn filter_map_next() {
         .next();
 }
 
+#[allow(clippy::no_effect)]
+#[allow(clippy::short_circuit_statement)]
+#[allow(clippy::unnecessary_operation)]
 pub fn manual_range_contains() {
+    let x = 5;
     x >= 8 && x < 12;
 }
 
@@ -92,7 +96,7 @@ pub fn use_self() {
 
 fn replace_with_default() {
     let mut s = String::from("foo");
-    let _ = std::mem::replace(s, String::default());
+    let _ = std::mem::replace(&mut s, String::default());
 }
 
 fn map_unwrap_or() {
@@ -106,6 +110,11 @@ fn map_unwrap_or() {
         .unwrap_or(0);
 }
 
+// Could be const
+fn missing_const_for_fn() -> i32 {
+    1
+}
+
 fn main() {
     filter_map_next();
     checked_conversion();
@@ -120,6 +129,7 @@ fn main() {
     use_self();
     replace_with_default();
     map_unwrap_or();
+    missing_const_for_fn();
 }
 
 mod meets_msrv {
diff --git a/tests/ui/min_rust_version_attr.stderr b/tests/ui/min_rust_version_attr.stderr
index d3eafe7312f..34805263104 100644
--- a/tests/ui/min_rust_version_attr.stderr
+++ b/tests/ui/min_rust_version_attr.stderr
@@ -1,28 +1,37 @@
-error[E0425]: cannot find value `x` in this scope
-  --> $DIR/min_rust_version_attr.rs:77:5
+error: stripping a prefix manually
+  --> $DIR/min_rust_version_attr.rs:142:24
    |
-LL |     x >= 8 && x < 12;
-   |     ^ not found in this scope
-
-error[E0425]: cannot find value `x` in this scope
-  --> $DIR/min_rust_version_attr.rs:77:15
+LL |             assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!");
+   |                        ^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: `-D clippy::manual-strip` implied by `-D warnings`
+note: the prefix was tested here
+  --> $DIR/min_rust_version_attr.rs:141:9
+   |
+LL |         if s.starts_with("hello, ") {
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: try using the `strip_prefix` method
+   |
+LL |         if let Some(<stripped>) = s.strip_prefix("hello, ") {
+LL |             assert_eq!(<stripped>.to_uppercase(), "WORLD!");
    |
-LL |     x >= 8 && x < 12;
-   |               ^ not found in this scope
 
-error[E0308]: mismatched types
-  --> $DIR/min_rust_version_attr.rs:95:31
+error: stripping a prefix manually
+  --> $DIR/min_rust_version_attr.rs:154:24
+   |
+LL |             assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!");
+   |                        ^^^^^^^^^^^^^^^^^^^^
+   |
+note: the prefix was tested here
+  --> $DIR/min_rust_version_attr.rs:153:9
+   |
+LL |         if s.starts_with("hello, ") {
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: try using the `strip_prefix` method
    |
-LL |     let _ = std::mem::replace(s, String::default());
-   |                               ^
-   |                               |
-   |                               expected `&mut _`, found struct `std::string::String`
-   |                               help: consider mutably borrowing here: `&mut s`
+LL |         if let Some(<stripped>) = s.strip_prefix("hello, ") {
+LL |             assert_eq!(<stripped>.to_uppercase(), "WORLD!");
    |
-   = note: expected mutable reference `&mut _`
-                         found struct `std::string::String`
 
-error: aborting due to 3 previous errors
+error: aborting due to 2 previous errors
 
-Some errors have detailed explanations: E0308, E0425.
-For more information about an error, try `rustc --explain E0308`.