From 4cb86c908989087dca7d3ad2b5c9029c62aaf852 Mon Sep 17 00:00:00 2001 From: Guanqun Lu Date: Wed, 25 Sep 2019 12:31:52 +0800 Subject: [PATCH] comment fixes --- src/librustc/ty/sty.rs | 4 ++++ src/librustc_typeck/check/method/suggest.rs | 11 ++--------- src/test/ui/suggestions/remove-as_str.stderr | 8 ++++---- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index e105c44d09ae..dfd8168985c0 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 6efa30455921..89055628342b 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 090a359fa68d..47196aa2c8ea 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