Adress new clippy::large_enum_variant diagnostics

This commit is contained in:
Lukas Wirth 2024-08-17 19:18:56 +02:00
parent 07c1b83e98
commit 1013bf36dc
3 changed files with 10 additions and 7 deletions

View file

@ -75,7 +75,7 @@ impl DiagnosticCollection {
flycheck_id: usize, flycheck_id: usize,
file_id: FileId, file_id: FileId,
diagnostic: lsp_types::Diagnostic, diagnostic: lsp_types::Diagnostic,
fix: Option<Fix>, fix: Option<Box<Fix>>,
) { ) {
let diagnostics = self.check.entry(flycheck_id).or_default().entry(file_id).or_default(); let diagnostics = self.check.entry(flycheck_id).or_default().entry(file_id).or_default();
for existing_diagnostic in diagnostics.iter() { for existing_diagnostic in diagnostics.iter() {
@ -84,8 +84,10 @@ impl DiagnosticCollection {
} }
} }
let check_fixes = Arc::make_mut(&mut self.check_fixes); if let Some(fix) = fix {
check_fixes.entry(flycheck_id).or_default().entry(file_id).or_default().extend(fix); let check_fixes = Arc::make_mut(&mut self.check_fixes);
check_fixes.entry(flycheck_id).or_default().entry(file_id).or_default().push(*fix);
}
diagnostics.push(diagnostic); diagnostics.push(diagnostic);
self.changes.insert(file_id); self.changes.insert(file_id);
} }

View file

@ -170,7 +170,7 @@ fn resolve_path(
struct SubDiagnostic { struct SubDiagnostic {
related: lsp_types::DiagnosticRelatedInformation, related: lsp_types::DiagnosticRelatedInformation,
suggested_fix: Option<Fix>, suggested_fix: Option<Box<Fix>>,
} }
enum MappedRustChildDiagnostic { enum MappedRustChildDiagnostic {
@ -241,7 +241,7 @@ fn map_rust_child_diagnostic(
location: location(config, workspace_root, spans[0], snap), location: location(config, workspace_root, spans[0], snap),
message: message.clone(), message: message.clone(),
}, },
suggested_fix: Some(Fix { suggested_fix: Some(Box::new(Fix {
ranges: spans ranges: spans
.iter() .iter()
.map(|&span| location(config, workspace_root, span, snap).range) .map(|&span| location(config, workspace_root, span, snap).range)
@ -260,7 +260,7 @@ fn map_rust_child_diagnostic(
data: None, data: None,
command: None, command: None,
}, },
}), })),
}) })
} }
} }
@ -269,7 +269,7 @@ fn map_rust_child_diagnostic(
pub(crate) struct MappedRustDiagnostic { pub(crate) struct MappedRustDiagnostic {
pub(crate) url: lsp_types::Url, pub(crate) url: lsp_types::Url,
pub(crate) diagnostic: lsp_types::Diagnostic, pub(crate) diagnostic: lsp_types::Diagnostic,
pub(crate) fix: Option<Fix>, pub(crate) fix: Option<Box<Fix>>,
} }
/// Converts a Rust root diagnostic to LSP form /// Converts a Rust root diagnostic to LSP form

View file

@ -218,6 +218,7 @@ struct FlycheckActor {
status: FlycheckStatus, status: FlycheckStatus,
} }
#[allow(clippy::large_enum_variant)]
enum Event { enum Event {
RequestStateChange(StateChange), RequestStateChange(StateChange),
CheckEvent(Option<CargoCheckMessage>), CheckEvent(Option<CargoCheckMessage>),