Skip to content

Commit c2b69a9

Browse files
committed
change rustfmt heuristic
Add a `rustfmt.toml` so that rustfmt prefers to keep things on fewer lines. Signed-off-by: David Wood <david.wood@huawei.com>
1 parent cf2bb2b commit c2b69a9

File tree

3 files changed

+29
-99
lines changed

3 files changed

+29
-99
lines changed

rustfmt.toml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use_small_heuristics = "Max"

src/main.rs

+26-91
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,7 @@ impl<E: gimli::Endianity> DwpStringTable<E> {
154154
let (index, is_new) = self.strings.insert_full(bytes.clone());
155155
let index = DwpStringId(index);
156156
if !is_new {
157-
return Ok(*self
158-
.offsets
159-
.get(&index)
160-
.expect("insert exists but no offset"));
157+
return Ok(*self.offsets.get(&index).expect("insert exists but no offset"));
161158
}
162159

163160
// Keep track of the offset for this string, it might be referenced by the next compilation
@@ -280,11 +277,7 @@ fn load_file_section<'input, 'arena: 'input>(
280277
arena_relocations: &'arena Arena<RelocationMap>,
281278
) -> Result<DwpReader<'arena>> {
282279
let mut relocations = RelocationMap::default();
283-
let name = if is_dwo {
284-
id.dwo_name()
285-
} else {
286-
Some(id.name())
287-
};
280+
let name = if is_dwo { id.dwo_name() } else { Some(id.name()) };
288281

289282
let data = match name.and_then(|name| obj.section_by_name(&name)) {
290283
Some(ref section) => {
@@ -301,11 +294,7 @@ fn load_file_section<'input, 'arena: 'input>(
301294
let reader = gimli::EndianSlice::new(data_ref, runtime_endian_of_object(obj));
302295
let section = reader;
303296
let relocations = (*arena_relocations.alloc(relocations)).borrow();
304-
Ok(Relocate {
305-
relocations,
306-
section,
307-
reader,
308-
})
297+
Ok(Relocate { relocations, section, reader })
309298
}
310299

311300
/// Returns the `DwoId` of a DIE.
@@ -358,10 +347,7 @@ fn dwo_id_and_path_of_unit<R: gimli::Reader>(
358347
return Err(anyhow!(DwpError::DwoIdWithoutDwoName));
359348
};
360349

361-
dwarf
362-
.attr_string(&unit, dwo_name)?
363-
.to_string()?
364-
.into_owned()
350+
dwarf.attr_string(&unit, dwo_name)?.to_string()?.into_owned()
365351
};
366352

367353
// Prepend the compilation directory if it exists.
@@ -466,10 +452,7 @@ fn append_str_offsets<'input, 'output, 'arena: 'input, Endian: gimli::Endianity>
466452

467453
let mut data = EndianVec::new(runtime_endian_of_object(dwo_obj));
468454

469-
let root_header = dwo_dwarf
470-
.units()
471-
.next()?
472-
.context(DwpError::DwarfObjectWithNoUnits)?;
455+
let root_header = dwo_dwarf.units().next()?.context(DwpError::DwarfObjectWithNoUnits)?;
473456
let encoding = root_header.encoding();
474457
let base = DebugStrOffsetsBase::default_for_encoding_and_file(encoding, DwarfFileType::Dwo);
475458

@@ -478,52 +461,29 @@ fn append_str_offsets<'input, 'output, 'arena: 'input, Endian: gimli::Endianity>
478461
Format::Dwarf64 => 8,
479462
};
480463

481-
debug!(
482-
?section_size,
483-
str_offset_size_num_elements = section_size / entry_size
484-
);
464+
debug!(?section_size, str_offset_size_num_elements = section_size / entry_size);
485465
for i in 0..(section_size / entry_size) {
486466
let dwo_index = DebugStrOffsetsIndex(i as usize);
487467
let dwo_offset =
488-
dwo_dwarf
489-
.debug_str_offsets
490-
.get_str_offset(encoding.format, base, dwo_index)?;
468+
dwo_dwarf.debug_str_offsets.get_str_offset(encoding.format, base, dwo_index)?;
491469
let dwo_str = dwo_dwarf.debug_str.get_str(dwo_offset)?;
492470
let dwo_str = dwo_str.to_string()?;
493471

494472
let dwp_offset = string_table.get_or_insert(dwo_str.as_ref())?;
495-
debug!(
496-
?i,
497-
?dwo_str,
498-
"dwo_offset={:#x} dwp_offset={:#x}",
499-
dwo_offset.0,
500-
dwp_offset.0
501-
);
473+
debug!(?i, ?dwo_str, "dwo_offset={:#x} dwp_offset={:#x}", dwo_offset.0, dwp_offset.0);
502474

503475
match encoding.format {
504476
Format::Dwarf32 => {
505-
data.write_u32(
506-
dwp_offset
507-
.0
508-
.try_into()
509-
.context(DwpError::DwpStrOffsetOutOfRange)?,
510-
)?;
477+
data.write_u32(dwp_offset.0.try_into().context(DwpError::DwpStrOffsetOutOfRange)?)?;
511478
}
512479
Format::Dwarf64 => {
513-
data.write_u64(
514-
dwp_offset
515-
.0
516-
.try_into()
517-
.context(DwpError::DwpStrOffsetOutOfRange)?,
518-
)?;
480+
data.write_u64(dwp_offset.0.try_into().context(DwpError::DwpStrOffsetOutOfRange)?)?;
519481
}
520482
}
521483
}
522484

523485
let offset =
524-
output
525-
.obj
526-
.append_section_data(output.debug_str_offsets, &data.into_vec(), section.align());
486+
output.obj.append_section_data(output.debug_str_offsets, &data.into_vec(), section.align());
527487
Ok(Some(Contribution {
528488
offset: ContributionOffset(offset),
529489
size: section_size.try_into().expect("too large for u32"),
@@ -557,23 +517,16 @@ where
557517
.data_range(dwo_offset.try_into().unwrap(), dwo_length)?
558518
.ok_or(DwpError::CompilationUnitWithNoData)?;
559519
let dwp_offset =
560-
output
561-
.obj
562-
.append_section_data(output.debug_info, dwo_data, debug_info.align());
520+
output.obj.append_section_data(output.debug_info, dwo_data, debug_info.align());
563521

564522
create_cu_entry(
565523
dwo_id,
566-
Contribution {
567-
offset: ContributionOffset(dwp_offset),
568-
size: dwo_length,
569-
},
524+
Contribution { offset: ContributionOffset(dwp_offset), size: dwo_length },
570525
);
571526

572527
Ok(())
573528
}
574-
(Some(..), _) => Err(anyhow!(
575-
DwpError::DwarfObjectCompilationUnitWithDwoIdNotSplitUnit
576-
)),
529+
(Some(..), _) => Err(anyhow!(DwpError::DwarfObjectCompilationUnitWithDwoIdNotSplitUnit)),
577530
_ => Ok(()),
578531
}
579532
}
@@ -596,9 +549,7 @@ fn append_section<'input, 'output>(
596549

597550
Ok(Some(Contribution { offset: ContributionOffset(offset), size }))
598551
}
599-
None if required => Err(anyhow!(DwpError::DwarfObjectMissingSection(
600-
name.to_string()
601-
))),
552+
None if required => Err(anyhow!(DwpError::DwarfObjectMissingSection(name.to_string()))),
602553
None => Ok(None),
603554
}
604555
}
@@ -607,14 +558,7 @@ fn append_section<'input, 'output>(
607558
/// object into output object.
608559
#[tracing::instrument(
609560
level = "trace",
610-
skip(
611-
parent_debug_addr,
612-
string_table,
613-
output,
614-
arena_data,
615-
arena_mmap,
616-
arena_relocations
617-
)
561+
skip(parent_debug_addr, string_table, output, arena_data, arena_mmap, arena_relocations)
618562
)]
619563
fn process_dwarf_object<'input, 'output, 'arena: 'input, Endian: gimli::Endianity>(
620564
parent_debug_addr: DebugAddr<DwpReader<'arena>>,
@@ -709,10 +653,7 @@ fn next_pow2(mut val: u32) -> u32 {
709653
/// Returns a hash table computed for `elements`. Used in the `.debug_{cu,tu}_index` sections.
710654
#[tracing::instrument(level = "trace", skip_all)]
711655
fn bucket<B: Bucketable + fmt::Debug>(elements: &[B]) -> Vec<u32> {
712-
let unit_count: u32 = elements
713-
.len()
714-
.try_into()
715-
.expect("unit count too big for u32");
656+
let unit_count: u32 = elements.len().try_into().expect("unit count too big for u32");
716657
let num_buckets = next_pow2(3 * unit_count / 2);
717658
let mask: u64 = num_buckets as u64 - 1;
718659

@@ -753,9 +694,7 @@ fn write_indices<'output, E: gimli::Endianity>(
753694
debug!(?has_loc, ?has_line, ?has_str_off, ?has_rng);
754695

755696
let num_columns = cu_index_entries.first().unwrap().number_of_columns();
756-
assert!(cu_index_entries
757-
.iter()
758-
.all(|e| e.number_of_columns() == num_columns));
697+
assert!(cu_index_entries.iter().all(|e| e.number_of_columns() == num_columns));
759698
debug!(?num_columns);
760699

761700
// DWARF 5
@@ -841,22 +780,18 @@ fn write_indices<'output, E: gimli::Endianity>(
841780
}
842781

843782
// FIXME: use the correct alignment here
844-
let _ = output
845-
.obj
846-
.append_section_data(output.debug_cu_index, &cu_index_data.into_vec(), 1);
783+
let _ = output.obj.append_section_data(output.debug_cu_index, &cu_index_data.into_vec(), 1);
847784
Ok(())
848785
}
849786

850787
fn main() -> Result<()> {
851-
let subscriber = Registry::default()
852-
.with(EnvFilter::from_env("RUST_DWP_LOG"))
853-
.with(
854-
HierarchicalLayer::default()
855-
.with_writer(io::stderr)
856-
.with_indent_lines(true)
857-
.with_targets(true)
858-
.with_indent_amount(2),
859-
);
788+
let subscriber = Registry::default().with(EnvFilter::from_env("RUST_DWP_LOG")).with(
789+
HierarchicalLayer::default()
790+
.with_writer(io::stderr)
791+
.with_indent_lines(true)
792+
.with_targets(true)
793+
.with_indent_amount(2),
794+
);
860795
tracing::subscriber::set_global_default(subscriber).unwrap();
861796

862797
let opt = Opt::from_args();

src/relocate.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -172,19 +172,13 @@ pub(crate) fn add_relocations(
172172

173173
if relocations.insert(offset, relocation).is_some() {
174174
return Err(anyhow!(DwpError::MultipleRelocations(
175-
section
176-
.name()
177-
.context(DwpError::SectionWithoutName(offset))?
178-
.to_string(),
175+
section.name().context(DwpError::SectionWithoutName(offset))?.to_string(),
179176
offset,
180177
)));
181178
}
182179
} else {
183180
return Err(anyhow!(DwpError::UnsupportedRelocation(
184-
section
185-
.name()
186-
.context(DwpError::SectionWithoutName(offset))?
187-
.to_string(),
181+
section.name().context(DwpError::SectionWithoutName(offset))?.to_string(),
188182
offset,
189183
)));
190184
}

0 commit comments

Comments
 (0)