aboutsummaryrefslogtreecommitdiffstats
path: root/components/script_plugins/webidl_must_inherit.rs
diff options
context:
space:
mode:
authorkrk <keremkat@gmail.com>2019-04-16 21:17:38 +0200
committerkrk <keremkat@gmail.com>2019-04-20 22:39:37 +0200
commit2384e5f4a256536b23a2ff0c1846dc394743f5e7 (patch)
treee84d333a3f1e1fce58b06a0a39cfcc0590a99cd3 /components/script_plugins/webidl_must_inherit.rs
parent3878fe86e70c8e10dc4f600333ee3672b0de0abb (diff)
downloadservo-2384e5f4a256536b23a2ff0c1846dc394743f5e7.tar.gz
servo-2384e5f4a256536b23a2ff0c1846dc394743f5e7.zip
Rename typ to ty and use &str where possible.
Diffstat (limited to 'components/script_plugins/webidl_must_inherit.rs')
-rw-r--r--components/script_plugins/webidl_must_inherit.rs23
1 files changed, 12 insertions, 11 deletions
diff --git a/components/script_plugins/webidl_must_inherit.rs b/components/script_plugins/webidl_must_inherit.rs
index 74256ce75aa..2fb45f4cdc5 100644
--- a/components/script_plugins/webidl_must_inherit.rs
+++ b/components/script_plugins/webidl_must_inherit.rs
@@ -65,11 +65,11 @@ impl WebIdlPass {
}
}
-fn get_typ_name(typ: String) -> String {
- if let Some(i) = typ.rfind(':') {
- typ[i + 1..].to_string()
+fn get_ty_name(ty: &str) -> &str {
+ if let Some(i) = ty.rfind(':') {
+ &ty[i + 1..]
} else {
- typ
+ ty
}
}
@@ -118,13 +118,13 @@ fn check_inherits(code: &str, name: &str, parent_name: &str) -> Result<(), Box<E
}))
}
-fn check_webidl(name: &str, parent_name: Option<String>) -> Result<(), Box<Error>> {
+fn check_webidl(name: &str, parent_name: Option<&str>) -> Result<(), Box<Error>> {
let path = get_webidl_path(&name)?;
println!("struct_webidl_path: {:?}", &path);
if let Some(parent) = parent_name {
let code = fs::read_to_string(path)?;
- return check_inherits(&code, &name, &parent);
+ return check_inherits(&code, &name, parent);
}
Ok(())
@@ -165,18 +165,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for WebIdlPass {
let struct_name = n.to_string();
println!("struct_name: {:?}", struct_name);
- let mut parent_typ_name: Option<String> = None;
+ let ty: String;
+ let mut parent_name: Option<&str> = None;
for ref field in def.fields() {
let def_id = cx.tcx.hir().local_def_id_from_hir_id(field.hir_id);
- let ty = cx.tcx.type_of(def_id);
- let typ_name = get_typ_name(ty.to_string());
- parent_typ_name = Some(typ_name);
+ ty = cx.tcx.type_of(def_id).to_string();
+ let name = get_ty_name(&ty);
+ parent_name = Some(name);
// Only first field is relevant.
break;
}
- match check_webidl(&struct_name, parent_typ_name) {
+ match check_webidl(&struct_name, parent_name) {
Ok(()) => {},
Err(e) => {
let description = format!("{}", e);