-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove allow(pedantic)
from formatter
#6549
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,15 +7,15 @@ use std::any::{Any, TypeId}; | |
use std::fmt::Debug; | ||
use std::ops::{Deref, DerefMut}; | ||
|
||
/// A trait for writing or formatting into [FormatElement]-accepting buffers or streams. | ||
/// A trait for writing or formatting into [`FormatElement`]-accepting buffers or streams. | ||
pub trait Buffer { | ||
/// The context used during formatting | ||
type Context; | ||
|
||
/// Writes a [crate::FormatElement] into this buffer, returning whether the write succeeded. | ||
/// Writes a [`crate::FormatElement`] into this buffer, returning whether the write succeeded. | ||
/// | ||
/// # Errors | ||
/// This function will return an instance of [crate::FormatError] on error. | ||
/// This function will return an instance of [`crate::FormatError`] on error. | ||
/// | ||
/// # Examples | ||
/// | ||
|
@@ -122,7 +122,7 @@ impl BufferSnapshot { | |
Err(err) => { | ||
panic!( | ||
"Tried to unwrap snapshot of type {:?} as {:?}", | ||
err.type_id(), | ||
(*err).type_id(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you know which rule triggered here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it was calling |
||
TypeId::of::<T>() | ||
) | ||
} | ||
|
@@ -160,7 +160,7 @@ impl<W: Buffer<Context = Context> + ?Sized, Context> Buffer for &mut W { | |
} | ||
|
||
fn restore_snapshot(&mut self, snapshot: BufferSnapshot) { | ||
(**self).restore_snapshot(snapshot) | ||
(**self).restore_snapshot(snapshot); | ||
} | ||
} | ||
|
||
|
@@ -426,7 +426,7 @@ where | |
} | ||
|
||
fn restore_snapshot(&mut self, snapshot: BufferSnapshot) { | ||
self.inner.restore_snapshot(snapshot) | ||
self.inner.restore_snapshot(snapshot); | ||
} | ||
} | ||
|
||
|
@@ -508,59 +508,58 @@ fn clean_interned( | |
interned: &Interned, | ||
interned_cache: &mut FxHashMap<Interned, Interned>, | ||
) -> Interned { | ||
match interned_cache.get(interned) { | ||
Some(cleaned) => cleaned.clone(), | ||
None => { | ||
// Find the first soft line break element or interned element that must be changed | ||
let result = interned | ||
.iter() | ||
.enumerate() | ||
.find_map(|(index, element)| match element { | ||
FormatElement::Line(LineMode::Soft | LineMode::SoftOrSpace) => { | ||
let mut cleaned = Vec::new(); | ||
cleaned.extend_from_slice(&interned[..index]); | ||
Some((cleaned, &interned[index..])) | ||
} | ||
FormatElement::Interned(inner) => { | ||
let cleaned_inner = clean_interned(inner, interned_cache); | ||
|
||
if &cleaned_inner != inner { | ||
let mut cleaned = Vec::with_capacity(interned.len()); | ||
cleaned.extend_from_slice(&interned[..index]); | ||
cleaned.push(FormatElement::Interned(cleaned_inner)); | ||
Some((cleaned, &interned[index + 1..])) | ||
} else { | ||
None | ||
} | ||
} | ||
if let Some(cleaned) = interned_cache.get(interned) { | ||
cleaned.clone() | ||
} else { | ||
// Find the first soft line break element or interned element that must be changed | ||
let result = interned | ||
.iter() | ||
.enumerate() | ||
.find_map(|(index, element)| match element { | ||
FormatElement::Line(LineMode::Soft | LineMode::SoftOrSpace) => { | ||
let mut cleaned = Vec::new(); | ||
cleaned.extend_from_slice(&interned[..index]); | ||
Some((cleaned, &interned[index..])) | ||
} | ||
FormatElement::Interned(inner) => { | ||
let cleaned_inner = clean_interned(inner, interned_cache); | ||
|
||
_ => None, | ||
}); | ||
|
||
let result = match result { | ||
// Copy the whole interned buffer so that becomes possible to change the necessary elements. | ||
Some((mut cleaned, rest)) => { | ||
for element in rest { | ||
let element = match element { | ||
FormatElement::Line(LineMode::Soft) => continue, | ||
FormatElement::Line(LineMode::SoftOrSpace) => FormatElement::Space, | ||
FormatElement::Interned(interned) => { | ||
FormatElement::Interned(clean_interned(interned, interned_cache)) | ||
} | ||
element => element.clone(), | ||
}; | ||
cleaned.push(element) | ||
if &cleaned_inner == inner { | ||
None | ||
} else { | ||
let mut cleaned = Vec::with_capacity(interned.len()); | ||
cleaned.extend_from_slice(&interned[..index]); | ||
cleaned.push(FormatElement::Interned(cleaned_inner)); | ||
Some((cleaned, &interned[index + 1..])) | ||
} | ||
} | ||
|
||
Interned::new(cleaned) | ||
_ => None, | ||
}); | ||
|
||
let result = match result { | ||
// Copy the whole interned buffer so that becomes possible to change the necessary elements. | ||
Some((mut cleaned, rest)) => { | ||
for element in rest { | ||
let element = match element { | ||
FormatElement::Line(LineMode::Soft) => continue, | ||
FormatElement::Line(LineMode::SoftOrSpace) => FormatElement::Space, | ||
FormatElement::Interned(interned) => { | ||
FormatElement::Interned(clean_interned(interned, interned_cache)) | ||
} | ||
element => element.clone(), | ||
}; | ||
cleaned.push(element); | ||
} | ||
// No change necessary, return existing interned element | ||
None => interned.clone(), | ||
}; | ||
|
||
interned_cache.insert(interned.clone(), result.clone()); | ||
result | ||
} | ||
Interned::new(cleaned) | ||
} | ||
// No change necessary, return existing interned element | ||
None => interned.clone(), | ||
}; | ||
|
||
interned_cache.insert(interned.clone(), result.clone()); | ||
result | ||
} | ||
} | ||
|
||
|
@@ -597,7 +596,7 @@ impl<Context> Buffer for RemoveSoftLinesBuffer<'_, Context> { | |
} | ||
|
||
fn restore_snapshot(&mut self, snapshot: BufferSnapshot) { | ||
self.inner.restore_snapshot(snapshot) | ||
self.inner.restore_snapshot(snapshot); | ||
} | ||
} | ||
|
||
|
@@ -658,7 +657,7 @@ pub trait BufferExtensions: Buffer + Sized { | |
where | ||
I: IntoIterator<Item = FormatElement>, | ||
{ | ||
for element in elements.into_iter() { | ||
for element in elements { | ||
self.write_element(element)?; | ||
} | ||
|
||
|
@@ -685,12 +684,12 @@ where | |
} | ||
} | ||
|
||
#[inline(always)] | ||
#[inline] | ||
pub fn write_fmt(&mut self, arguments: Arguments<B::Context>) -> FormatResult<()> { | ||
self.buffer.write_fmt(arguments) | ||
} | ||
|
||
#[inline(always)] | ||
#[inline] | ||
pub fn write_element(&mut self, element: FormatElement) -> FormatResult<()> { | ||
self.buffer.write_element(element) | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs says (https://rust-lang.github.io/rust-clippy/v0.0.212/index.html#inline_always):
Do we have measurements that
#[inline(always)]
is better than#[inline]
?