Skip to content

Commit

Permalink
Use iter.next instead of for-break.
Browse files Browse the repository at this point in the history
  • Loading branch information
krk committed Apr 20, 2019
1 parent 32049d1 commit 6db7518
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions components/script_plugins/webidl_must_inherit.rs
Expand Up @@ -133,11 +133,11 @@ fn check_inherits(code: &str, name: &str, parent_name: &str) -> Result<(), Box<E
}))
}

fn check_webidl(name: &str, parent_name: Option<&str>) -> Result<(), Box<Error>> {
fn check_webidl(name: &str, parent_name: &Option<String>) -> Result<(), Box<Error>> {
let path = get_webidl_path(&name)?;
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(())
Expand Down Expand Up @@ -175,20 +175,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for WebIdlPass {
.expect_item_by_hir_id(cx.tcx.hir().get_parent_item(id)),
};

let ty: String;
let mut parent_name: Option<&str> = None;
for ref field in def.fields() {
let parent_name = def.fields().iter().next().map(|field| {
let def_id = cx.tcx.hir().local_def_id_from_hir_id(field.hir_id);
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;
}
let ty = cx.tcx.type_of(def_id).to_string();
get_ty_name(&ty).to_string()
});

let struct_name = n.to_string();
match check_webidl(&struct_name, parent_name) {
match check_webidl(&struct_name, &parent_name) {
Ok(()) => {},
Err(e) => {
let description = format!("{}", e);
Expand Down

0 comments on commit 6db7518

Please sign in to comment.