Skip to content

Commit

Permalink
Resolve manual_strip clippy lint
Browse files Browse the repository at this point in the history
    warning: stripping a prefix manually
      --> src/ident_fragment.rs:53:31
       |
    53 |             fmt::Display::fmt(&id[2..], f)
       |                               ^^^^^^^^
       |
    note: the prefix was tested here
      --> src/ident_fragment.rs:52:9
       |
    52 |         if id.starts_with("r#") {
       |         ^^^^^^^^^^^^^^^^^^^^^^^^
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip
       = note: `-W clippy::manual-strip` implied by `-W clippy::all`
    help: try using the `strip_prefix` method
       |
    52 ~         if let Some(<stripped>) = id.strip_prefix("r#") {
    53 ~             fmt::Display::fmt(<stripped>, f)
       |

    warning: stripping a prefix manually
       --> src/runtime.rs:447:24
        |
    447 |         Ident::new_raw(&id[2..], span)
        |                        ^^^^^^^^
        |
    note: the prefix was tested here
       --> src/runtime.rs:446:5
        |
    446 |     if id.starts_with("r#") {
        |     ^^^^^^^^^^^^^^^^^^^^^^^^
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip
    help: try using the `strip_prefix` method
        |
    446 ~     if let Some(<stripped>) = id.strip_prefix("r#") {
    447 ~         Ident::new_raw(<stripped>, span)
        |
  • Loading branch information
dtolnay committed Jul 16, 2023
1 parent 2b4591e commit 3d94d95
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/ident_fragment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ impl IdentFragment for Ident {

fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let id = self.to_string();
if id.starts_with("r#") {
fmt::Display::fmt(&id[2..], f)
if let Some(id) = id.strip_prefix("r#") {
fmt::Display::fmt(id, f)
} else {
fmt::Display::fmt(&id[..], f)
}
Expand Down
4 changes: 2 additions & 2 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,8 @@ pub fn mk_ident(id: &str, span: Option<Span>) -> Ident {
}

fn ident_maybe_raw(id: &str, span: Span) -> Ident {
if id.starts_with("r#") {
Ident::new_raw(&id[2..], span)
if let Some(id) = id.strip_prefix("r#") {
Ident::new_raw(id, span)
} else {
Ident::new(id, span)
}
Expand Down

0 comments on commit 3d94d95

Please sign in to comment.