Lint layout_2020 with clippy (#31169)

cargo clippy --fix -p layout_2020 --allow-dirty --broken-code
This commit is contained in:
Oriol Brufau 2024-01-25 10:03:31 +01:00 committed by GitHub
parent 886f6c58d4
commit 50f56affe3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 224 additions and 244 deletions

View file

@ -48,7 +48,7 @@ struct ScopeData {
name: String,
pre: TreeValues,
post: TreeValues,
children: Vec<Box<ScopeData>>,
children: Vec<ScopeData>,
}
impl ScopeData {
@ -71,19 +71,19 @@ impl ScopeData {
struct State {
fragment_tree: Arc<FragmentTree>,
box_tree: Arc<BoxTree>,
scope_stack: Vec<Box<ScopeData>>,
scope_stack: Vec<ScopeData>,
}
/// A layout debugging scope. The entire state of the box and fragment trees
/// will be output at the beginning and end of this scope.
impl Scope {
pub fn new(name: String) -> Scope {
STATE_KEY.with(|ref r| {
STATE_KEY.with(|r| {
if let Some(ref mut state) = *r.borrow_mut() {
let box_tree = to_value(&state.box_tree).unwrap();
let fragment_tree = to_value(&state.fragment_tree).unwrap();
let data = Box::new(ScopeData::new(name.clone(), box_tree, fragment_tree));
state.scope_stack.push(data);
state.scope_stack.push(*data);
}
});
Scope
@ -93,7 +93,7 @@ impl Scope {
#[cfg(debug_assertions)]
impl Drop for Scope {
fn drop(&mut self) {
STATE_KEY.with(|ref r| {
STATE_KEY.with(|r| {
if let Some(ref mut state) = *r.borrow_mut() {
let mut current_scope = state.scope_stack.pop().unwrap();
current_scope.post = TreeValues {
@ -110,13 +110,13 @@ impl Drop for Scope {
/// Begin a layout debug trace. If this has not been called,
/// creating debug scopes has no effect.
pub fn begin_trace(box_tree: Arc<BoxTree>, fragment_tree: Arc<FragmentTree>) {
assert!(STATE_KEY.with(|ref r| r.borrow().is_none()));
assert!(STATE_KEY.with(|r| r.borrow().is_none()));
STATE_KEY.with(|ref r| {
STATE_KEY.with(|r| {
let box_tree_value = to_value(&box_tree).unwrap();
let fragment_tree_value = to_value(&fragment_tree).unwrap();
let state = State {
scope_stack: vec![Box::new(ScopeData::new(
scope_stack: vec![*Box::new(ScopeData::new(
"root".to_owned(),
box_tree_value,
fragment_tree_value,
@ -132,7 +132,7 @@ pub fn begin_trace(box_tree: Arc<BoxTree>, fragment_tree: Arc<FragmentTree>) {
/// trace to disk in the current directory. The output
/// file can then be viewed with an external tool.
pub fn end_trace(generation: u32) {
let mut thread_state = STATE_KEY.with(|ref r| r.borrow_mut().take().unwrap());
let mut thread_state = STATE_KEY.with(|r| r.borrow_mut().take().unwrap());
assert_eq!(thread_state.scope_stack.len(), 1);
let mut root_scope = thread_state.scope_stack.pop().unwrap();
root_scope.post = TreeValues {
@ -170,6 +170,12 @@ impl DebugId {
}
}
impl Default for DebugId {
fn default() -> Self {
Self::new()
}
}
#[cfg(not(debug_assertions))]
impl Serialize for DebugId {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {