Skip to content

Commit 30457be

Browse files
committed
cargo clippy --fix
1 parent 202dbd0 commit 30457be

File tree

16 files changed

+86
-92
lines changed

16 files changed

+86
-92
lines changed

Diff for: c2rust-analyze/src/analyze.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ fn mark_foreign_fixed<'tcx>(
370370
make_ty_fixed(gasn, lty);
371371

372372
// Also fix the `addr_of_static` permissions.
373-
let ptr = gacx.addr_of_static[&did];
373+
let ptr = gacx.addr_of_static[did];
374374
gasn.flags[ptr].insert(FlagSet::FIXED);
375375
}
376376
}
@@ -397,7 +397,7 @@ fn mark_all_statics_fixed<'tcx>(gacx: &mut GlobalAnalysisCtxt<'tcx>, gasn: &mut
397397
make_ty_fixed(gasn, lty);
398398

399399
// Also fix the `addr_of_static` permissions.
400-
let ptr = gacx.addr_of_static[&did];
400+
let ptr = gacx.addr_of_static[did];
401401
gasn.flags[ptr].insert(FlagSet::FIXED);
402402
}
403403
}
@@ -425,7 +425,7 @@ fn parse_def_id(s: &str) -> Result<DefId, String> {
425425
let s = s
426426
.strip_prefix("DefId(")
427427
.ok_or("does not start with `DefId(`")?;
428-
let s = s.strip_suffix(")").ok_or("does not end with `)`")?;
428+
let s = s.strip_suffix(')').ok_or("does not end with `)`")?;
429429
let s = match s.find(" ~ ") {
430430
Some(i) => &s[..i],
431431
None => s,
@@ -459,11 +459,11 @@ fn read_fixed_defs_list(fixed_defs: &mut HashSet<DefId>, path: &str) -> io::Resu
459459
for (i, line) in f.lines().enumerate() {
460460
let line = line?;
461461
let line = line.trim();
462-
if line.len() == 0 || line.starts_with('#') {
462+
if line.is_empty() || line.starts_with('#') {
463463
continue;
464464
}
465465

466-
let def_id = parse_def_id(&line).unwrap_or_else(|e| {
466+
let def_id = parse_def_id(line).unwrap_or_else(|e| {
467467
panic!("failed to parse {} line {}: {}", path, i + 1, e);
468468
});
469469
fixed_defs.insert(def_id);
@@ -481,7 +481,7 @@ fn check_rewrite_path_prefixes(tcx: TyCtxt, fixed_defs: &mut HashSet<DefId>, pre
481481
.split(',')
482482
// Exclude empty paths. This allows for leading/trailing commas or double commas within
483483
// the list, which may result when building the list programmatically.
484-
.filter(|prefix| prefix.len() > 0)
484+
.filter(|prefix| !prefix.is_empty())
485485
.map(|prefix| prefix.split("::").map(Symbol::intern).collect::<Vec<_>>())
486486
.collect();
487487
let sym_impl = Symbol::intern("{impl}");
@@ -1510,8 +1510,7 @@ fn run2<'tcx>(
15101510
continue;
15111511
}
15121512

1513-
let adt_rewrites =
1514-
rewrite::gen_adt_ty_rewrites(&gacx, &gasn, &global_pointee_types, def_id);
1513+
let adt_rewrites = rewrite::gen_adt_ty_rewrites(&gacx, &gasn, global_pointee_types, def_id);
15151514
let report = adt_reports.entry(def_id).or_default();
15161515
writeln!(
15171516
report,
@@ -1691,7 +1690,7 @@ fn run2<'tcx>(
16911690
ptrs.push(ptr);
16921691
format!("{{{}}}", ptr)
16931692
});
1694-
if ptrs.len() == 0 {
1693+
if ptrs.is_empty() {
16951694
continue;
16961695
}
16971696
ann.emit(span, format_args!("typeof({}) = {}", name, ty_str));
@@ -1789,7 +1788,7 @@ fn run2<'tcx>(
17891788
all_fn_ldids.len()
17901789
);
17911790

1792-
if known_perm_error_fns.len() > 0 {
1791+
if !known_perm_error_fns.is_empty() {
17931792
eprintln!(
17941793
"saw permission errors in {} known fns",
17951794
known_perm_error_fns.len()
@@ -1893,7 +1892,7 @@ fn apply_test_attr_force_non_null_args(
18931892
let mut updates_forbidden = g_updates_forbidden.and_mut(&mut info.l_updates_forbidden);
18941893

18951894
let lsig = &gacx.fn_sigs[&ldid.to_def_id()];
1896-
for arg_lty in lsig.inputs.iter().copied() {
1895+
for arg_lty in lsig.inputs {
18971896
for lty in arg_lty.iter() {
18981897
let ptr = lty.label;
18991898
if !ptr.is_none() {
@@ -2014,7 +2013,7 @@ fn print_function_pointee_types<'tcx>(
20142013

20152014
for ptr in all_pointer_ids {
20162015
let tys = &pointee_types[ptr];
2017-
if tys.ltys.len() == 0 && !tys.incomplete {
2016+
if tys.ltys.is_empty() && !tys.incomplete {
20182017
continue;
20192018
}
20202019
eprintln!(

Diff for: c2rust-analyze/src/borrowck/type_check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl<'tcx> TypeChecker<'tcx, '_> {
177177
self.facts,
178178
self.maps,
179179
&self.acx.gacx.adt_metadata,
180-
&self.acx.gacx.static_tys[&did],
180+
self.acx.gacx.static_tys[&did],
181181
);
182182

183183
for l in lty.iter() {
@@ -585,7 +585,7 @@ impl<'tcx> TypeChecker<'tcx, '_> {
585585
}
586586
Callee::Memcpy => {
587587
let _pl_lty = self.visit_place(destination);
588-
let _rv_lty = assert_matches!(&args[..], [dest, src, _] => {
588+
assert_matches!(&args[..], [dest, src, _] => {
589589
self.visit_operand(dest);
590590
self.visit_operand(src);
591591
});

Diff for: c2rust-analyze/src/context.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,7 @@ pub fn print_ty_with_pointer_labels_into<L: Copy>(
15031503
// Types with arguments
15041504
Adt(adt_def, _substs) => {
15051505
write!(dest, "{:?}", adt_def.did()).unwrap();
1506-
if lty.args.len() != 0 {
1506+
if !lty.args.is_empty() {
15071507
dest.push('<');
15081508
// TODO: region args
15091509
for (i, &arg_lty) in lty.args.iter().enumerate() {
@@ -1532,31 +1532,31 @@ pub fn print_ty_with_pointer_labels_into<L: Copy>(
15321532
dest.push_str("*mut ");
15331533
}
15341534
let s = f(lty.label);
1535-
if s.len() > 0 {
1535+
if !s.is_empty() {
15361536
dest.push_str(&s);
1537-
dest.push_str(" ");
1537+
dest.push(' ');
15381538
}
15391539
print_ty_with_pointer_labels_into(dest, lty.args[0], f);
15401540
}
15411541
&Ref(_rg, _ty, mutbl) => {
15421542
let s = f(lty.label);
15431543
if mutbl == Mutability::Not {
1544-
dest.push_str("&");
1545-
if s.len() > 0 {
1544+
dest.push('&');
1545+
if !s.is_empty() {
15461546
dest.push(' ');
15471547
}
15481548
} else {
15491549
dest.push_str("&mut ");
15501550
}
1551-
if s.len() > 0 {
1551+
if !s.is_empty() {
15521552
dest.push_str(&s);
1553-
dest.push_str(" ");
1553+
dest.push(' ');
15541554
}
15551555
print_ty_with_pointer_labels_into(dest, lty.args[0], f);
15561556
}
15571557
FnDef(def_id, _substs) => {
15581558
write!(dest, "{:?}", def_id).unwrap();
1559-
if lty.args.len() != 0 {
1559+
if !lty.args.is_empty() {
15601560
dest.push('<');
15611561
// TODO: region args
15621562
for (i, &arg_lty) in lty.args.iter().enumerate() {
@@ -1581,14 +1581,14 @@ pub fn print_ty_with_pointer_labels_into<L: Copy>(
15811581
print_ty_with_pointer_labels_into(dest, ret_lty, f);
15821582
}
15831583
Tuple(_) => {
1584-
dest.push_str("(");
1584+
dest.push('(');
15851585
for (i, &arg_lty) in lty.args.iter().enumerate() {
15861586
if i > 0 {
15871587
dest.push_str(", ");
15881588
}
15891589
print_ty_with_pointer_labels_into(dest, arg_lty, f);
15901590
}
1591-
dest.push_str(")");
1591+
dest.push(')');
15921592
}
15931593

15941594
// Types that aren't actually supported by this code yet

Diff for: c2rust-analyze/src/dataflow/type_check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ impl<'tcx> TypeChecker<'tcx, '_> {
603603
self.visit_operand(&args[0]);
604604
}
605605
Callee::Null { .. } => {
606-
assert!(args.len() == 0);
606+
assert!(args.is_empty());
607607
self.visit_place(destination, Mutability::Mut);
608608
let pl_lty = self.acx.type_of(destination);
609609
// We are assigning a null pointer to `destination`, so it must not have the

Diff for: c2rust-analyze/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ fn cargo_wrapper(rustc_wrapper: &Path) -> anyhow::Result<()> {
438438
cmd.env("C2RUST_ANALYZE_FIXED_DEFS_LIST", fixed_defs_list);
439439
}
440440

441-
if rewrite_paths.len() > 0 {
441+
if !rewrite_paths.is_empty() {
442442
let rewrite_paths = rewrite_paths.join(OsStr::new(","));
443443
cmd.env("C2RUST_ANALYZE_REWRITE_PATHS", rewrite_paths);
444444
}

Diff for: c2rust-analyze/src/pointee_type/solve.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub fn propagate_types<'tcx>(
5656
if new && !ty_sets[ptr1].is_subset(&ty_sets[ptr2]) {
5757
let (tys1, tys2) = index_both(&mut ty_sets, ptr1, ptr2);
5858
for cty in tys1.iter() {
59-
tys2.insert(cty.clone());
59+
tys2.insert(*cty);
6060
}
6161
// Since `ty_sets[ptr2]` was not a subset of `ty_sets[ptr1]`, we must have added at
6262
// least one element to `ty_sets[ptr2]`.
@@ -75,7 +75,7 @@ pub fn propagate_types<'tcx>(
7575
if !ty_sets[ptr1].is_subset(&ty_sets[ptr2]) {
7676
let (tys1, tys2) = index_both(&mut ty_sets, ptr1, ptr2);
7777
for cty in tys1.iter() {
78-
tys2.insert(cty.clone());
78+
tys2.insert(*cty);
7979
}
8080
// Since `ty_sets[ptr2]` was not a subset of `ty_sets[ptr1]`, we must have added at
8181
// least one element to `ty_sets[ptr2]`.

Diff for: c2rust-analyze/src/pointee_type/type_check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<'tcx> TypeChecker<'tcx, '_> {
7676
}
7777
_ => {}
7878
}
79-
lty = self.acx.projection_lty(lty, &proj);
79+
lty = self.acx.projection_lty(lty, proj);
8080
}
8181
debug_assert_eq!(lty, self.acx.type_of(pl));
8282
lty

Diff for: c2rust-analyze/src/pointer_id.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,11 @@ impl<'a, T> PointerTable<'a, T> {
332332
}
333333

334334
pub fn global(&self) -> &'a GlobalPointerTable<T> {
335-
&self.global
335+
self.global
336336
}
337337

338338
pub fn local(&self) -> &'a LocalPointerTable<T> {
339-
&self.local
339+
self.local
340340
}
341341

342342
pub fn iter(&self) -> impl Iterator<Item = (PointerId, &T)> {
@@ -386,19 +386,19 @@ impl<'a, T> PointerTableMut<'a, T> {
386386
}
387387

388388
pub fn global(&self) -> &GlobalPointerTable<T> {
389-
&self.global
389+
self.global
390390
}
391391

392392
pub fn global_mut(&mut self) -> &mut GlobalPointerTable<T> {
393-
&mut self.global
393+
self.global
394394
}
395395

396396
pub fn local(&self) -> &LocalPointerTable<T> {
397-
&self.local
397+
self.local
398398
}
399399

400400
pub fn local_mut(&mut self) -> &mut LocalPointerTable<T> {
401-
&mut self.local
401+
self.local
402402
}
403403

404404
pub fn iter(&self) -> impl Iterator<Item = (PointerId, &T)> {

Diff for: c2rust-analyze/src/rewrite/expr/convert.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ impl<'tcx> ConvertVisitor<'tcx> {
372372
let closure = Rewrite::Closure1("__ptr".into(), Box::new(body));
373373
hir_rw = Rewrite::MethodCall("map".into(), Box::new(hir_rw), vec![closure]);
374374
}
375-
return Ok((hir_rw, mir_rws));
375+
Ok((hir_rw, mir_rws))
376376
}
377377

378378
fn rewrite_from_mir_rws(
@@ -423,7 +423,7 @@ impl<'tcx> Visitor<'tcx> for ConvertVisitor<'tcx> {
423423
let mut mir_rws = &mir_rws as &[_];
424424

425425
// Emit rewrites on subexpressions up front so we can access them in `get_subexpr`.
426-
self.with_materialize_adjustments(mir_rws.len() > 0, |this| {
426+
self.with_materialize_adjustments(!mir_rws.is_empty(), |this| {
427427
intravisit::walk_expr(this, ex);
428428
});
429429

@@ -579,16 +579,16 @@ fn generate_zeroize_code(zero_ty: &ZeroizeType, lv: &str) -> String {
579579
ZeroizeType::Struct(ref fields) => {
580580
eprintln!("zeroize: {} fields on {lv}: {fields:?}", fields.len());
581581
let mut s = String::new();
582-
write!(s, "{{\n").unwrap();
582+
writeln!(s, "{{").unwrap();
583583
for (name, field_zero_ty) in fields {
584-
write!(
584+
writeln!(
585585
s,
586-
"{};\n",
586+
"{};",
587587
generate_zeroize_code(field_zero_ty, &format!("{lv}.{name}"))
588588
)
589589
.unwrap();
590590
}
591-
write!(s, "}}\n").unwrap();
591+
writeln!(s, "}}").unwrap();
592592
s
593593
}
594594
}
@@ -653,12 +653,10 @@ pub fn convert_cast_rewrite(kind: &mir_op::RewriteKind, hir_rw: Rewrite) -> Rewr
653653
} else {
654654
"as_deref".into()
655655
}
656+
} else if mutbl {
657+
"as_mut".into()
656658
} else {
657-
if mutbl {
658-
"as_mut".into()
659-
} else {
660-
"as_ref".into()
661-
}
659+
"as_ref".into()
662660
};
663661
Rewrite::MethodCall(ref_method, Box::new(hir_rw), vec![])
664662
}
@@ -696,7 +694,7 @@ pub fn convert_cast_rewrite(kind: &mir_op::RewriteKind, hir_rw: Rewrite) -> Rewr
696694
Box::new(Rewrite::TyPtr(
697695
Box::new(Rewrite::TyCtor(
698696
"std::cell::Cell".into(),
699-
vec![Rewrite::Print(format!("{}", ty))],
697+
vec![Rewrite::Print(ty.to_string())],
700698
)),
701699
hir::Mutability::Not,
702700
)),

Diff for: c2rust-analyze/src/rewrite/expr/hir_only_casts.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,15 @@ where
111111
if let hir::ExprKind::Cast(src_expr, _dest_ty) = ex.kind {
112112
let src_adjusts = self.typeck_results.expr_adjustments(src_expr);
113113
if let Some(last_adjust) = src_adjusts.last() {
114-
if matches!(last_adjust.kind, Adjust::Pointer(_)) {
115-
if last_adjust.target == self.typeck_results.expr_ty(ex) {
116-
// `ex` has the form `x as T`, where `x` has a pointer adjustment and its
117-
// final adjusted type is identical to `T`. In this case, rustc skips
118-
// generating MIR for this cast.
119-
if (self.filter)(src_expr) {
120-
self.rewrites
121-
.push((ex.span, Rewrite::Sub(0, src_expr.span)));
122-
}
114+
if matches!(last_adjust.kind, Adjust::Pointer(_))
115+
&& last_adjust.target == self.typeck_results.expr_ty(ex)
116+
{
117+
// `ex` has the form `x as T`, where `x` has a pointer adjustment and its
118+
// final adjusted type is identical to `T`. In this case, rustc skips
119+
// generating MIR for this cast.
120+
if (self.filter)(src_expr) {
121+
self.rewrites
122+
.push((ex.span, Rewrite::Sub(0, src_expr.span)));
123123
}
124124
}
125125
}

0 commit comments

Comments
 (0)