Skip to content

Commit ed6ed73

Browse files
committed
transpile: some minor cleanups from #1452
1 parent 3918150 commit ed6ed73

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

c2rust-transpile/src/rust_ast/item_store.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use indexmap::{IndexMap, IndexSet};
33
use syn::{ForeignItem, Ident, Item};
44

55
use std::borrow::Cow;
6+
use std::collections::HashSet;
67
use std::mem::swap;
78

89
#[derive(Debug)]
@@ -79,19 +80,14 @@ impl PathedMultiImports {
7980
.collect()
8081
}
8182

82-
/// Remove all imports covered by the other `PathedMultiImports`.
83+
/// Remove all imports covered by the other [`PathedMultiImports`].
8384
pub fn remove(&mut self, other: &PathedMultiImports) {
8485
for (k, v) in &mut self.0 {
8586
// We don't consider attributes, just subtract leaf sets.
8687
let other_items = other
8788
.0
8889
.get(k)
89-
.map(|imports| {
90-
imports
91-
.leaves
92-
.iter()
93-
.collect::<std::collections::HashSet<_>>()
94-
})
90+
.map(|imports| imports.leaves.iter().collect::<HashSet<_>>())
9591
.unwrap_or_default();
9692
v.leaves.retain(|leaf| !other_items.contains(leaf));
9793
}

c2rust-transpile/src/translator/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ pub fn translate(
664664
if t.tcfg.reorganize_definitions
665665
&& decl_file_id.map_or(false, |id| id != t.main_file)
666666
{
667-
let name: Option<&String> = t
667+
let name = t
668668
.ast_context
669669
.get_decl(&decl_id)
670670
.and_then(|x| x.kind.get_name());
@@ -941,12 +941,13 @@ impl<'a> IdentsOrGlob<'a> {
941941

942942
/// Extract the set of names made visible by a `use`.
943943
fn use_idents<'a>(i: &'a UseTree) -> IdentsOrGlob<'a> {
944+
use UseTree::*;
944945
match i {
945-
UseTree::Path(up) => use_idents(&up.tree),
946-
UseTree::Name(un) => IdentsOrGlob::Idents(vec![&un.ident]),
947-
UseTree::Rename(ur) => IdentsOrGlob::Idents(vec![&ur.rename]),
948-
UseTree::Glob(_ugl) => IdentsOrGlob::Glob,
949-
UseTree::Group(ugr) => ugr
946+
Path(up) => use_idents(&up.tree),
947+
Name(un) => IdentsOrGlob::Idents(vec![&un.ident]),
948+
Rename(ur) => IdentsOrGlob::Idents(vec![&ur.rename]),
949+
Glob(_ugl) => IdentsOrGlob::Glob,
950+
Group(ugr) => ugr
950951
.items
951952
.iter()
952953
.map(|tree| use_idents(tree))

tests/items/src/test_fn_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub fn test_fn_attrs() {
88

99
// Remove the c2rust::src_loc annotation, which is only produced if
1010
// --reorganize-definitions is enabled.
11-
let mut lines: Vec<&str> = src.lines().collect();
11+
let mut lines = src.lines().collect::<Vec<_>>();
1212
lines.retain(|x| !x.contains("#[c2rust::src_loc"));
1313
let src = lines.join("\n");
1414

tests/statics/src/test_sections.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub fn test_sectioned_used_static() {
3636
// directly at the source file
3737
let src = include_str!("attributes.rs");
3838

39-
let mut lines: Vec<&str> = src.lines().collect();
39+
let mut lines = src.lines().collect::<Vec<_>>();
4040

4141
// Remove the c2rust::src_loc annotation, which is only produced if
4242
// --reorganize-definitions is enabled.

0 commit comments

Comments
 (0)