diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-04-08 10:50:18 +0530 |
---|---|---|
committer | bors-servo <lbergstrom+bors@mozilla.com> | 2016-04-08 10:50:18 +0530 |
commit | f31aa5cb86857a7479096e7dadf8dcac12151f76 (patch) | |
tree | e02777922c34206350d9cf7480453ab9ef182de1 /components/plugins/lints/str_to_string.rs | |
parent | bd2051d06a4b5f5a261b1c816c5ce9960d3e9b23 (diff) | |
parent | efa84862af9ba2659120fa16687c8d3b294a88e2 (diff) | |
download | servo-f31aa5cb86857a7479096e7dadf8dcac12151f76.tar.gz servo-f31aa5cb86857a7479096e7dadf8dcac12151f76.zip |
Auto merge of #10470 - Manishearth:kill-str-string, r=KiChjang
Remove str_to_string lint
Specialization makes all of the options equally efficient.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10470)
<!-- Reviewable:end -->
Diffstat (limited to 'components/plugins/lints/str_to_string.rs')
-rw-r--r-- | components/plugins/lints/str_to_string.rs | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/components/plugins/lints/str_to_string.rs b/components/plugins/lints/str_to_string.rs deleted file mode 100644 index 8a1f1530898..00000000000 --- a/components/plugins/lints/str_to_string.rs +++ /dev/null @@ -1,48 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -use rustc::lint::{LateContext, LintPass, LintArray, LateLintPass, LintContext}; -use rustc::ty; -use rustc_front::hir; - -declare_lint!(STR_TO_STRING, Deny, - "Warn when a String could use to_owned() instead of to_string()"); - -/// Prefer str.to_owned() over str.to_string() -/// -/// The latter creates a `Formatter` and is 5x slower than the former -pub struct StrToStringPass; - -impl LintPass for StrToStringPass { - fn get_lints(&self) -> LintArray { - lint_array!(STR_TO_STRING) - } -} - -impl LateLintPass for StrToStringPass { - fn check_expr(&mut self, cx: &LateContext, expr: &hir::Expr) { - match expr.node { - hir::ExprMethodCall(ref method, _, ref args) - if method.node.as_str() == "to_string" - && is_str(cx, &*args[0]) => { - cx.span_lint(STR_TO_STRING, expr.span, - "str.to_owned() is more efficient than str.to_string(), please use it instead"); - }, - _ => () - } - - fn is_str(cx: &LateContext, expr: &hir::Expr) -> bool { - fn walk_ty<'t>(ty: ty::Ty<'t>) -> ty::Ty<'t> { - match ty.sty { - ty::TyRef(_, ref tm) | ty::TyRawPtr(ref tm) => walk_ty(tm.ty), - _ => ty - } - } - match walk_ty(cx.tcx.expr_ty(expr)).sty { - ty::TyStr => true, - _ => false - } - } - } -} |