← Rule catalog

rust-doctor · Performance

string-from-literal

Flags `String::from("literal")` and `"literal".to_string()`. These allocate on the heap when a `&str` reference might suffice.

Severity
info
Confidence
medium
Analyzer
syn-ast
Default policy
Opt-in

Tags

  • heuristic
  • performance

Framework requirements

No framework requirement.

Limitations

  • Syntactic analysis does not have rustc name resolution or inferred type information.

Remediation

Use `&str` for function parameters and constants. Owned `String` is correct for struct fields, HashMap keys, error messages, and APIs requiring ownership.

Fix capability: guidance