about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuanqun Lu <guanqun.lu@gmail.com>2019-09-25 12:31:52 +0800
committerGuanqun Lu <guanqun.lu@gmail.com>2019-10-02 09:06:37 +0800
commit4cb86c908989087dca7d3ad2b5c9029c62aaf852 (patch)
treeb35ffeba54ad1c4c4f92981d4900eed178068442
parentbb3c03049dbef28d18a7ca17b5b9d25f7c276b8e (diff)
downloadrust-4cb86c908989087dca7d3ad2b5c9029c62aaf852.tar.gz
rust-4cb86c908989087dca7d3ad2b5c9029c62aaf852.zip
comment fixes
-rw-r--r--src/librustc/ty/sty.rs4
-rw-r--r--src/librustc_typeck/check/method/suggest.rs11
-rw-r--r--src/test/ui/suggestions/remove-as_str.stderr8
3 files changed, 10 insertions, 13 deletions
diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs
index e105c44d09a..dfd8168985c 100644
--- a/src/librustc/ty/sty.rs
+++ b/src/librustc/ty/sty.rs
@@ -1776,6 +1776,10 @@ impl<'tcx> TyS<'tcx> {
     #[inline]
     pub fn is_bool(&self) -> bool { self.kind == Bool }
 
+    /// Returns `true` if this type is a `str`.
+    #[inline]
+    pub fn is_str(&self) -> bool { self.sty == Str }
+
     #[inline]
     pub fn is_param(&self, index: u32) -> bool {
         match self.kind {
diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs
index 6efa3045592..89055628342 100644
--- a/src/librustc_typeck/check/method/suggest.rs
+++ b/src/librustc_typeck/check/method/suggest.rs
@@ -518,17 +518,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                     }
                 }
 
-                fn is_str_ref(ty: Ty<'_>) -> bool {
-                    match ty.sty {
-                        ty::Str => true,
-                        ty::Ref(_, ty, _) => is_str_ref(&ty),
-                        _ => false,
-                    }
-                }
-                if item_name.as_str() == "as_str" && is_str_ref(&actual) {
+                if item_name.as_str() == "as_str" && actual.peel_refs().is_str() {
                     err.span_suggestion(
                         span,
-                        "try to remove `as_str`",
+                        "try removing `as_str`",
                         String::new(),
                         Applicability::MaybeIncorrect,
                     );
diff --git a/src/test/ui/suggestions/remove-as_str.stderr b/src/test/ui/suggestions/remove-as_str.stderr
index 090a359fa68..47196aa2c8e 100644
--- a/src/test/ui/suggestions/remove-as_str.stderr
+++ b/src/test/ui/suggestions/remove-as_str.stderr
@@ -2,25 +2,25 @@ error[E0599]: no method named `as_str` found for type `&str` in the current scop
   --> $DIR/remove-as_str.rs:2:7
    |
 LL |     s.as_str();
-   |       ^^^^^^ help: try to remove `as_str`
+   |       ^^^^^^ help: try removing `as_str`
 
 error[E0599]: no method named `as_str` found for type `&'a str` in the current scope
   --> $DIR/remove-as_str.rs:7:7
    |
 LL |     s.as_str();
-   |       ^^^^^^ help: try to remove `as_str`
+   |       ^^^^^^ help: try removing `as_str`
 
 error[E0599]: no method named `as_str` found for type `&mut str` in the current scope
   --> $DIR/remove-as_str.rs:12:7
    |
 LL |     s.as_str();
-   |       ^^^^^^ help: try to remove `as_str`
+   |       ^^^^^^ help: try removing `as_str`
 
 error[E0599]: no method named `as_str` found for type `&&str` in the current scope
   --> $DIR/remove-as_str.rs:17:7
    |
 LL |     s.as_str();
-   |       ^^^^^^ help: try to remove `as_str`
+   |       ^^^^^^ help: try removing `as_str`
 
 error: aborting due to 4 previous errors