mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 14:21:24 +00:00
Remove Fix::from(Edit)
and add deprecated replacement methods to Diagnostic
s (#4275)
This commit is contained in:
parent
0801f14046
commit
4d5a339d9e
51 changed files with 205 additions and 144 deletions
|
@ -5,7 +5,7 @@ use ruff_text_size::{TextRange, TextSize};
|
|||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::Fix;
|
||||
use crate::{Edit, Fix};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
|
@ -40,14 +40,21 @@ impl Diagnostic {
|
|||
|
||||
/// Set the [`Fix`] used to fix the diagnostic.
|
||||
#[inline]
|
||||
pub fn set_fix<T: Into<Fix>>(&mut self, fix: T) {
|
||||
self.fix = Some(fix.into());
|
||||
pub fn set_fix(&mut self, fix: Fix) {
|
||||
self.fix = Some(fix);
|
||||
}
|
||||
|
||||
/// Set the [`Fix`] used to fix the diagnostic.
|
||||
#[inline]
|
||||
#[deprecated(note = "Use `Diagnostic::set_fix` instead.")]
|
||||
pub fn set_fix_from_edit(&mut self, edit: Edit) {
|
||||
self.fix = Some(Fix::unspecified(edit));
|
||||
}
|
||||
|
||||
/// Consumes `self` and returns a new `Diagnostic` with the given `fix`.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn with_fix<T: Into<Fix>>(mut self, fix: T) -> Self {
|
||||
pub fn with_fix(mut self, fix: Fix) -> Self {
|
||||
self.set_fix(fix);
|
||||
self
|
||||
}
|
||||
|
@ -55,9 +62,20 @@ impl Diagnostic {
|
|||
/// Set the [`Fix`] used to fix the diagnostic, if the provided function returns `Ok`.
|
||||
/// Otherwise, log the error.
|
||||
#[inline]
|
||||
pub fn try_set_fix<T: Into<Fix>>(&mut self, func: impl FnOnce() -> Result<T>) {
|
||||
pub fn try_set_fix(&mut self, func: impl FnOnce() -> Result<Fix>) {
|
||||
match func() {
|
||||
Ok(fix) => self.fix = Some(fix.into()),
|
||||
Ok(fix) => self.fix = Some(fix),
|
||||
Err(err) => error!("Failed to create fix: {}", err),
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets an [`Edit`] used to fix the diagnostic, if the provided function returns `Ok`.
|
||||
/// Otherwise, log the error.
|
||||
#[inline]
|
||||
#[deprecated(note = "Use Diagnostic::try_set_fix instead")]
|
||||
pub fn try_set_fix_from_edit(&mut self, func: impl FnOnce() -> Result<Edit>) {
|
||||
match func() {
|
||||
Ok(edit) => self.fix = Some(Fix::unspecified(edit)),
|
||||
Err(err) => error!("Failed to create fix: {}", err),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,9 +38,3 @@ impl Fix {
|
|||
self.edits
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Edit> for Fix {
|
||||
fn from(edit: Edit) -> Self {
|
||||
Self { edits: vec![edit] }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue