Remove allow(pedantic) from formatter (#6549)

This commit is contained in:
Micha Reiser 2023-08-14 14:02:06 +02:00 committed by GitHub
parent c39bcbadff
commit 9584f613b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 348 additions and 316 deletions

View file

@ -21,9 +21,9 @@ pub struct Document {
impl Document {
/// Sets [`expand`](tag::Group::expand) to [`GroupMode::Propagated`] if the group contains any of:
/// - a group with [`expand`](tag::Group::expand) set to [GroupMode::Propagated] or [GroupMode::Expand].
/// - a non-soft [line break](FormatElement::Line) with mode [LineMode::Hard], [LineMode::Empty], or [LineMode::Literal].
/// - a [FormatElement::ExpandParent]
/// - a group with [`expand`](tag::Group::expand) set to [`GroupMode::Propagated`] or [`GroupMode::Expand`].
/// - a non-soft [line break](FormatElement::Line) with mode [`LineMode::Hard`], [`LineMode::Empty`], or [`LineMode::Literal`].
/// - a [`FormatElement::ExpandParent`]
///
/// [`BestFitting`] elements act as expand boundaries, meaning that the fact that a
/// [`BestFitting`]'s content expands is not propagated past the [`BestFitting`] element.
@ -71,15 +71,16 @@ impl Document {
Some(Enclosing::ConditionalGroup(group)) => !group.mode().is_flat(),
_ => false,
},
FormatElement::Interned(interned) => match checked_interned.get(interned) {
Some(interned_expands) => *interned_expands,
None => {
FormatElement::Interned(interned) => {
if let Some(interned_expands) = checked_interned.get(interned) {
*interned_expands
} else {
let interned_expands =
propagate_expands(interned, enclosing, checked_interned);
checked_interned.insert(interned, interned_expands);
interned_expands
}
},
}
FormatElement::BestFitting { variants } => {
enclosing.push(Enclosing::BestFitting);
@ -114,7 +115,7 @@ impl Document {
if element_expands {
expands = true;
expand_parent(enclosing)
expand_parent(enclosing);
}
}
@ -226,6 +227,7 @@ impl FormatOptions for IrFormatOptions {
impl Format<IrFormatContext<'_>> for &[FormatElement] {
fn fmt(&self, f: &mut Formatter<IrFormatContext>) -> FormatResult<()> {
#[allow(clippy::enum_glob_use)]
use Tag::*;
write!(f, [ContentArrayStart])?;
@ -245,16 +247,10 @@ impl Format<IrFormatContext<'_>> for &[FormatElement] {
first_element = false;
match element {
element @ FormatElement::Space
| element @ FormatElement::StaticText { .. }
| element @ FormatElement::DynamicText { .. }
| element @ FormatElement::SourceCodeSlice { .. } => {
if !in_text {
write!(f, [text("\"")])?;
}
in_text = true;
element @ (FormatElement::Space
| FormatElement::StaticText { .. }
| FormatElement::DynamicText { .. }
| FormatElement::SourceCodeSlice { .. }) => {
fn write_escaped(
element: &FormatElement,
f: &mut Formatter<IrFormatContext>,
@ -277,6 +273,12 @@ impl Format<IrFormatContext<'_>> for &[FormatElement] {
}
}
if !in_text {
write!(f, [text("\"")])?;
}
in_text = true;
match element {
FormatElement::Space => {
write!(f, [text(" ")])?;
@ -317,7 +319,7 @@ impl Format<IrFormatContext<'_>> for &[FormatElement] {
write!(
f,
[dynamic_text(
&std::format!("source_position({:?})", position),
&std::format!("source_position({position:?})"),
None
)]
)?;
@ -335,7 +337,7 @@ impl Format<IrFormatContext<'_>> for &[FormatElement] {
])?;
for variant in variants {
write!(f, [variant.deref(), hard_line_break()])?;
write!(f, [&**variant, hard_line_break()])?;
}
f.write_elements([
@ -359,7 +361,7 @@ impl Format<IrFormatContext<'_>> for &[FormatElement] {
[
dynamic_text(&std::format!("<interned {index}>"), None),
space(),
&interned.deref(),
&&**interned,
]
)?;
}
@ -621,7 +623,7 @@ struct ContentArrayStart;
impl Format<IrFormatContext<'_>> for ContentArrayStart {
fn fmt(&self, f: &mut Formatter<IrFormatContext>) -> FormatResult<()> {
use Tag::*;
use Tag::{StartGroup, StartIndent};
write!(f, [text("[")])?;
@ -637,7 +639,7 @@ struct ContentArrayEnd;
impl Format<IrFormatContext<'_>> for ContentArrayEnd {
fn fmt(&self, f: &mut Formatter<IrFormatContext>) -> FormatResult<()> {
use Tag::*;
use Tag::{EndGroup, EndIndent};
f.write_elements([
FormatElement::Tag(EndIndent),
FormatElement::Line(LineMode::Soft),
@ -650,7 +652,7 @@ impl Format<IrFormatContext<'_>> for ContentArrayEnd {
impl FormatElements for [FormatElement] {
fn will_break(&self) -> bool {
use Tag::*;
use Tag::{EndLineSuffix, StartLineSuffix};
let mut ignore_depth = 0usize;
for element in self {
@ -687,9 +689,6 @@ impl FormatElements for [FormatElement] {
}
fn start_tag(&self, kind: TagKind) -> Option<&Tag> {
// Assert that the document ends at a tag with the specified kind;
let _ = self.end_tag(kind)?;
fn traverse_slice<'a>(
slice: &'a [FormatElement],
kind: TagKind,
@ -704,9 +703,8 @@ impl FormatElements for [FormatElement] {
return None;
} else if *depth == 1 {
return Some(tag);
} else {
*depth -= 1;
}
*depth -= 1;
} else {
*depth += 1;
}
@ -731,6 +729,8 @@ impl FormatElements for [FormatElement] {
None
}
// Assert that the document ends at a tag with the specified kind;
let _ = self.end_tag(kind)?;
let mut depth = 0usize;

View file

@ -109,6 +109,7 @@ impl Tag {
}
pub const fn kind(&self) -> TagKind {
#[allow(clippy::enum_glob_use)]
use Tag::*;
match self {
@ -180,13 +181,14 @@ impl FitsExpanded {
Self::default()
}
#[must_use]
pub fn with_condition(mut self, condition: Option<Condition>) -> Self {
self.condition = condition;
self
}
pub fn propagate_expand(&self) {
self.propagate_expand.set(true)
self.propagate_expand.set(true);
}
}
@ -204,11 +206,13 @@ impl Group {
}
}
#[must_use]
pub fn with_id(mut self, id: Option<GroupId>) -> Self {
self.id = id;
self
}
#[must_use]
pub fn with_mode(mut self, mode: GroupMode) -> Self {
self.mode = Cell::new(mode);
self
@ -220,7 +224,7 @@ impl Group {
pub fn propagate_expand(&self) {
if self.mode.get() == GroupMode::Flat {
self.mode.set(GroupMode::Propagated)
self.mode.set(GroupMode::Propagated);
}
}
@ -248,7 +252,7 @@ impl ConditionalGroup {
}
pub fn propagate_expand(&self) {
self.mode.set(GroupMode::Propagated)
self.mode.set(GroupMode::Propagated);
}
pub fn mode(&self) -> GroupMode {
@ -312,6 +316,7 @@ impl Condition {
}
}
#[must_use]
pub fn with_group_id(mut self, id: Option<GroupId>) -> Self {
self.group_id = id;
self
@ -350,6 +355,7 @@ impl PartialEq for LabelId {
}
impl LabelId {
#[allow(clippy::needless_pass_by_value)]
pub fn of<T: LabelDefinition>(label: T) -> Self {
Self {
value: label.value(),