Skip to content

Commit 4cb86c9

Browse files
author
Guanqun Lu
committed
comment fixes
1 parent bb3c030 commit 4cb86c9

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

src/librustc/ty/sty.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,10 @@ impl<'tcx> TyS<'tcx> {
17761776
#[inline]
17771777
pub fn is_bool(&self) -> bool { self.kind == Bool }
17781778

1779+
/// Returns `true` if this type is a `str`.
1780+
#[inline]
1781+
pub fn is_str(&self) -> bool { self.sty == Str }
1782+
17791783
#[inline]
17801784
pub fn is_param(&self, index: u32) -> bool {
17811785
match self.kind {

src/librustc_typeck/check/method/suggest.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -518,17 +518,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
518518
}
519519
}
520520

521-
fn is_str_ref(ty: Ty<'_>) -> bool {
522-
match ty.sty {
523-
ty::Str => true,
524-
ty::Ref(_, ty, _) => is_str_ref(&ty),
525-
_ => false,
526-
}
527-
}
528-
if item_name.as_str() == "as_str" && is_str_ref(&actual) {
521+
if item_name.as_str() == "as_str" && actual.peel_refs().is_str() {
529522
err.span_suggestion(
530523
span,
531-
"try to remove `as_str`",
524+
"try removing `as_str`",
532525
String::new(),
533526
Applicability::MaybeIncorrect,
534527
);

src/test/ui/suggestions/remove-as_str.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@ error[E0599]: no method named `as_str` found for type `&str` in the current scop
22
--> $DIR/remove-as_str.rs:2:7
33
|
44
LL | s.as_str();
5-
| ^^^^^^ help: try to remove `as_str`
5+
| ^^^^^^ help: try removing `as_str`
66

77
error[E0599]: no method named `as_str` found for type `&'a str` in the current scope
88
--> $DIR/remove-as_str.rs:7:7
99
|
1010
LL | s.as_str();
11-
| ^^^^^^ help: try to remove `as_str`
11+
| ^^^^^^ help: try removing `as_str`
1212

1313
error[E0599]: no method named `as_str` found for type `&mut str` in the current scope
1414
--> $DIR/remove-as_str.rs:12:7
1515
|
1616
LL | s.as_str();
17-
| ^^^^^^ help: try to remove `as_str`
17+
| ^^^^^^ help: try removing `as_str`
1818

1919
error[E0599]: no method named `as_str` found for type `&&str` in the current scope
2020
--> $DIR/remove-as_str.rs:17:7
2121
|
2222
LL | s.as_str();
23-
| ^^^^^^ help: try to remove `as_str`
23+
| ^^^^^^ help: try removing `as_str`
2424

2525
error: aborting due to 4 previous errors
2626

0 commit comments

Comments
 (0)