mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-19 11:05:24 +00:00
Use #[expect(lint)]
over #[allow(lint)]
where possible (#17822)
This commit is contained in:
parent
8535af8516
commit
fa628018b2
148 changed files with 221 additions and 268 deletions
|
@ -43,7 +43,7 @@ pub struct AstNodeRef<T> {
|
|||
node: std::ptr::NonNull<T>,
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
#[expect(unsafe_code)]
|
||||
impl<T> AstNodeRef<T> {
|
||||
/// Creates a new `AstNodeRef` that references `node`. The `parsed` is the [`ParsedModule`] to
|
||||
/// which the `AstNodeRef` belongs.
|
||||
|
@ -112,7 +112,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
#[expect(unsafe_code)]
|
||||
unsafe impl<T> salsa::Update for AstNodeRef<T> {
|
||||
unsafe fn maybe_update(old_pointer: *mut Self, new_value: Self) -> bool {
|
||||
let old_ref = &mut (*old_pointer);
|
||||
|
@ -126,9 +126,9 @@ unsafe impl<T> salsa::Update for AstNodeRef<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
#[expect(unsafe_code)]
|
||||
unsafe impl<T> Send for AstNodeRef<T> where T: Send {}
|
||||
#[allow(unsafe_code)]
|
||||
#[expect(unsafe_code)]
|
||||
unsafe impl<T> Sync for AstNodeRef<T> where T: Sync {}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -139,7 +139,7 @@ mod tests {
|
|||
use ruff_python_parser::parse_unchecked_source;
|
||||
|
||||
#[test]
|
||||
#[allow(unsafe_code)]
|
||||
#[expect(unsafe_code)]
|
||||
fn equality() {
|
||||
let parsed_raw = parse_unchecked_source("1 + 2", PySourceType::Python);
|
||||
let parsed = ParsedModule::new(parsed_raw.clone());
|
||||
|
@ -167,7 +167,7 @@ mod tests {
|
|||
assert_ne!(node1, other_node);
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
#[expect(unsafe_code)]
|
||||
#[test]
|
||||
fn inequality() {
|
||||
let parsed_raw = parse_unchecked_source("1 + 2", PySourceType::Python);
|
||||
|
@ -186,7 +186,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[allow(unsafe_code)]
|
||||
#[expect(unsafe_code)]
|
||||
fn debug() {
|
||||
let parsed_raw = parse_unchecked_source("1 + 2", PySourceType::Python);
|
||||
let parsed = ParsedModule::new(parsed_raw);
|
||||
|
|
|
@ -244,7 +244,7 @@ macro_rules! declare_lint {
|
|||
}
|
||||
) => {
|
||||
$( #[doc = $doc] )+
|
||||
#[allow(clippy::needless_update)]
|
||||
#[expect(clippy::needless_update)]
|
||||
$vis static $name: $crate::lint::LintMetadata = $crate::lint::LintMetadata {
|
||||
name: ruff_db::diagnostic::LintName::of(ruff_macros::kebab_case!($name)),
|
||||
summary: $summary,
|
||||
|
|
|
@ -180,7 +180,7 @@ impl<K, V> ListBuilder<K, V> {
|
|||
/// as our return type, since we never return `None`. However, for consistency with our other
|
||||
/// methods, we always use `Option<I>` as the return type for any method that can return a
|
||||
/// list.
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
#[expect(clippy::unnecessary_wraps)]
|
||||
fn add_cell(&mut self, rest: Option<ListCellId>, key: K, value: V) -> Option<ListCellId> {
|
||||
Some(self.storage.cells.push(ListCell { rest, key, value }))
|
||||
}
|
||||
|
@ -319,7 +319,7 @@ impl<K, V> ListBuilder<K, V> {
|
|||
/// Returns the intersection of two lists. The result will contain an entry for any key that
|
||||
/// appears in both lists. The corresponding values will be combined using the `combine`
|
||||
/// function that you provide.
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
#[expect(clippy::needless_pass_by_value)]
|
||||
pub(crate) fn intersect_with<F>(
|
||||
&mut self,
|
||||
a: List<K, V>,
|
||||
|
@ -372,7 +372,7 @@ impl<K, V> ListBuilder<K, V> {
|
|||
|
||||
impl<K> ListStorage<K, ()> {
|
||||
/// Iterates through the elements in a set _in reverse order_.
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
#[expect(clippy::needless_pass_by_value)]
|
||||
pub(crate) fn iter_set_reverse(&self, set: List<K, ()>) -> ListSetReverseIterator<K> {
|
||||
ListSetReverseIterator {
|
||||
storage: self,
|
||||
|
@ -513,7 +513,7 @@ mod tests {
|
|||
|
||||
impl<K, V> ListStorage<K, V> {
|
||||
/// Iterates through the entries in a list _in reverse order by key_.
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
#[expect(clippy::needless_pass_by_value)]
|
||||
pub(crate) fn iter_reverse(&self, list: List<K, V>) -> ListReverseIterator<'_, K, V> {
|
||||
ListReverseIterator {
|
||||
storage: self,
|
||||
|
@ -649,7 +649,7 @@ mod property_tests {
|
|||
|
||||
#[quickcheck_macros::quickcheck]
|
||||
#[ignore]
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
#[expect(clippy::needless_pass_by_value)]
|
||||
fn roundtrip_set_from_vec(elements: Vec<u16>) -> bool {
|
||||
let mut builder = ListBuilder::default();
|
||||
let set = builder.set_from_elements(&elements);
|
||||
|
@ -660,7 +660,7 @@ mod property_tests {
|
|||
|
||||
#[quickcheck_macros::quickcheck]
|
||||
#[ignore]
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
#[expect(clippy::needless_pass_by_value)]
|
||||
fn roundtrip_set_intersection(a_elements: Vec<u16>, b_elements: Vec<u16>) -> bool {
|
||||
let mut builder = ListBuilder::default();
|
||||
let a = builder.set_from_elements(&a_elements);
|
||||
|
@ -712,7 +712,7 @@ mod property_tests {
|
|||
|
||||
#[quickcheck_macros::quickcheck]
|
||||
#[ignore]
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
#[expect(clippy::needless_pass_by_value)]
|
||||
fn roundtrip_list_from_vec(pairs: Vec<(u16, u16)>) -> bool {
|
||||
let mut builder = ListBuilder::default();
|
||||
let list = builder.set_from_pairs(&pairs);
|
||||
|
@ -723,7 +723,7 @@ mod property_tests {
|
|||
|
||||
#[quickcheck_macros::quickcheck]
|
||||
#[ignore]
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
#[expect(clippy::needless_pass_by_value)]
|
||||
fn roundtrip_list_intersection(
|
||||
a_elements: Vec<(u16, u16)>,
|
||||
b_elements: Vec<(u16, u16)>,
|
||||
|
|
|
@ -257,7 +257,7 @@ impl<'db> SemanticIndex<'db> {
|
|||
}
|
||||
|
||||
/// Returns the parent scope of `scope_id`.
|
||||
#[allow(unused)]
|
||||
#[expect(unused)]
|
||||
#[track_caller]
|
||||
pub(crate) fn parent_scope(&self, scope_id: FileScopeId) -> Option<&Scope> {
|
||||
Some(&self.scopes[self.parent_scope_id(scope_id)?])
|
||||
|
|
|
@ -239,7 +239,7 @@ impl<'db> SemanticIndexBuilder<'db> {
|
|||
let children_start = self.scopes.next_index() + 1;
|
||||
|
||||
// SAFETY: `node` is guaranteed to be a child of `self.module`
|
||||
#[allow(unsafe_code)]
|
||||
#[expect(unsafe_code)]
|
||||
let node_with_kind = unsafe { node.to_kind(self.module.clone()) };
|
||||
|
||||
let scope = Scope::new(
|
||||
|
@ -457,7 +457,7 @@ impl<'db> SemanticIndexBuilder<'db> {
|
|||
definition_node: impl Into<DefinitionNodeRef<'db>>,
|
||||
) -> (Definition<'db>, usize) {
|
||||
let definition_node: DefinitionNodeRef<'_> = definition_node.into();
|
||||
#[allow(unsafe_code)]
|
||||
#[expect(unsafe_code)]
|
||||
// SAFETY: `definition_node` is guaranteed to be a child of `self.module`
|
||||
let kind = unsafe { definition_node.into_owned(self.module.clone()) };
|
||||
let category = kind.category(self.source_type.is_stub());
|
||||
|
@ -801,11 +801,11 @@ impl<'db> SemanticIndexBuilder<'db> {
|
|||
self.db,
|
||||
self.file,
|
||||
self.current_scope(),
|
||||
#[allow(unsafe_code)]
|
||||
#[expect(unsafe_code)]
|
||||
unsafe {
|
||||
AstNodeRef::new(self.module.clone(), expression_node)
|
||||
},
|
||||
#[allow(unsafe_code)]
|
||||
#[expect(unsafe_code)]
|
||||
assigned_to
|
||||
.map(|assigned_to| unsafe { AstNodeRef::new(self.module.clone(), assigned_to) }),
|
||||
expression_kind,
|
||||
|
@ -1009,7 +1009,7 @@ impl<'db> SemanticIndexBuilder<'db> {
|
|||
value_file_scope,
|
||||
self.current_scope(),
|
||||
// SAFETY: `target` belongs to the `self.module` tree
|
||||
#[allow(unsafe_code)]
|
||||
#[expect(unsafe_code)]
|
||||
unsafe {
|
||||
AstNodeRef::new(self.module.clone(), target)
|
||||
},
|
||||
|
@ -2188,7 +2188,7 @@ where
|
|||
match self.current_assignment() {
|
||||
Some(CurrentAssignment::Assign { node, unpack, .. }) => {
|
||||
// SAFETY: `value` and `expr` belong to the `self.module` tree
|
||||
#[allow(unsafe_code)]
|
||||
#[expect(unsafe_code)]
|
||||
let assignment = AssignmentDefinitionKind::new(
|
||||
TargetKind::from(unpack),
|
||||
unsafe { AstNodeRef::new(self.module.clone(), &node.value) },
|
||||
|
@ -2203,7 +2203,7 @@ where
|
|||
Some(CurrentAssignment::AnnAssign(ann_assign)) => {
|
||||
self.add_standalone_type_expression(&ann_assign.annotation);
|
||||
// SAFETY: `annotation`, `value` and `expr` belong to the `self.module` tree
|
||||
#[allow(unsafe_code)]
|
||||
#[expect(unsafe_code)]
|
||||
let assignment = AnnotatedAssignmentDefinitionKind::new(
|
||||
unsafe {
|
||||
AstNodeRef::new(self.module.clone(), &ann_assign.annotation)
|
||||
|
@ -2221,7 +2221,7 @@ where
|
|||
}
|
||||
Some(CurrentAssignment::For { node, unpack, .. }) => {
|
||||
// // SAFETY: `iter` and `expr` belong to the `self.module` tree
|
||||
#[allow(unsafe_code)]
|
||||
#[expect(unsafe_code)]
|
||||
let assignment = ForStmtDefinitionKind::new(
|
||||
TargetKind::from(unpack),
|
||||
unsafe { AstNodeRef::new(self.module.clone(), &node.iter) },
|
||||
|
@ -2241,7 +2241,7 @@ where
|
|||
..
|
||||
}) => {
|
||||
// SAFETY: `context_expr` and `expr` belong to the `self.module` tree
|
||||
#[allow(unsafe_code)]
|
||||
#[expect(unsafe_code)]
|
||||
let assignment = WithItemDefinitionKind::new(
|
||||
TargetKind::from(unpack),
|
||||
unsafe { AstNodeRef::new(self.module.clone(), &item.context_expr) },
|
||||
|
@ -2260,7 +2260,7 @@ where
|
|||
first,
|
||||
}) => {
|
||||
// SAFETY: `iter` and `expr` belong to the `self.module` tree
|
||||
#[allow(unsafe_code)]
|
||||
#[expect(unsafe_code)]
|
||||
let assignment = ComprehensionDefinitionKind {
|
||||
target_kind: TargetKind::from(unpack),
|
||||
iterable: unsafe {
|
||||
|
|
|
@ -300,7 +300,7 @@ pub(crate) struct MatchPatternDefinitionNodeRef<'a> {
|
|||
}
|
||||
|
||||
impl<'db> DefinitionNodeRef<'db> {
|
||||
#[allow(unsafe_code)]
|
||||
#[expect(unsafe_code)]
|
||||
pub(super) unsafe fn into_owned(self, parsed: ParsedModule) -> DefinitionKind<'db> {
|
||||
match self {
|
||||
DefinitionNodeRef::Import(ImportDefinitionNodeRef {
|
||||
|
|
|
@ -287,7 +287,7 @@ impl SymbolTable {
|
|||
&self.symbols[symbol_id.into()]
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
#[expect(unused)]
|
||||
pub(crate) fn symbol_ids(&self) -> impl Iterator<Item = ScopedSymbolId> {
|
||||
self.symbols.indices()
|
||||
}
|
||||
|
@ -420,7 +420,7 @@ impl NodeWithScopeRef<'_> {
|
|||
///
|
||||
/// # Safety
|
||||
/// The node wrapped by `self` must be a child of `module`.
|
||||
#[allow(unsafe_code)]
|
||||
#[expect(unsafe_code)]
|
||||
pub(super) unsafe fn to_kind(self, module: ParsedModule) -> NodeWithScopeKind {
|
||||
match self {
|
||||
NodeWithScopeRef::Module => NodeWithScopeKind::Module,
|
||||
|
|
|
@ -267,7 +267,7 @@ impl Idx for ScopedVisibilityConstraintId {
|
|||
#[inline]
|
||||
fn new(value: usize) -> Self {
|
||||
assert!(value <= (SMALLEST_TERMINAL.0 as usize));
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
#[expect(clippy::cast_possible_truncation)]
|
||||
Self(value as u32)
|
||||
}
|
||||
|
||||
|
|
|
@ -5617,7 +5617,6 @@ impl<'db> TypeVarInstance<'db> {
|
|||
matches!(self.kind(db), TypeVarKind::Legacy)
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub(crate) fn upper_bound(self, db: &'db dyn Db) -> Option<Type<'db>> {
|
||||
if let Some(TypeVarBoundOrConstraints::UpperBound(ty)) = self.bound_or_constraints(db) {
|
||||
Some(ty)
|
||||
|
@ -5626,7 +5625,6 @@ impl<'db> TypeVarInstance<'db> {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub(crate) fn constraints(self, db: &'db dyn Db) -> Option<&'db [Type<'db>]> {
|
||||
if let Some(TypeVarBoundOrConstraints::Constraints(tuple)) = self.bound_or_constraints(db) {
|
||||
Some(tuple.elements(db))
|
||||
|
@ -5856,7 +5854,7 @@ impl<'db> IterationError<'db> {
|
|||
/// Emit a diagnostic that is certain that `iterable_type` is not iterable.
|
||||
///
|
||||
/// `because` should explain why `iterable_type` is not iterable.
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
#[expect(clippy::wrong_self_convention)]
|
||||
fn is_not(self, because: impl std::fmt::Display) -> LintDiagnosticGuard<'a, 'a> {
|
||||
let mut diag = self.builder.into_diagnostic(format_args!(
|
||||
"Object of type `{iterable_type}` is not iterable",
|
||||
|
@ -6787,7 +6785,7 @@ impl<'db> FunctionType<'db> {
|
|||
/// 3. third `foo` definition, it would contain both overloads and the implementation which is
|
||||
/// itself
|
||||
fn to_overloaded(self, db: &'db dyn Db) -> Option<&'db OverloadedFunction<'db>> {
|
||||
#[allow(clippy::ref_option)] // TODO: Remove once salsa supports deref (https://github.com/salsa-rs/salsa/pull/772)
|
||||
#[allow(clippy::ref_option)]
|
||||
#[salsa::tracked(return_ref)]
|
||||
fn to_overloaded_impl<'db>(
|
||||
db: &'db dyn Db,
|
||||
|
|
|
@ -70,7 +70,7 @@ fn try_mro_cycle_recover<'db>(
|
|||
salsa::CycleRecoveryAction::Iterate
|
||||
}
|
||||
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
#[expect(clippy::unnecessary_wraps)]
|
||||
fn try_mro_cycle_initial<'db>(
|
||||
db: &'db dyn Db,
|
||||
self_: ClassLiteral<'db>,
|
||||
|
@ -82,7 +82,7 @@ fn try_mro_cycle_initial<'db>(
|
|||
))
|
||||
}
|
||||
|
||||
#[allow(clippy::ref_option, clippy::trivially_copy_pass_by_ref)]
|
||||
#[expect(clippy::ref_option, clippy::trivially_copy_pass_by_ref)]
|
||||
fn inheritance_cycle_recover<'db>(
|
||||
_db: &'db dyn Db,
|
||||
_value: &Option<InheritanceCycle>,
|
||||
|
|
|
@ -4078,7 +4078,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::unused_self)]
|
||||
#[expect(clippy::unused_self)]
|
||||
fn infer_boolean_literal_expression(&mut self, literal: &ast::ExprBooleanLiteral) -> Type<'db> {
|
||||
let ast::ExprBooleanLiteral { range: _, value } = literal;
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ fn constraints_for_expression_cycle_initial<'db>(
|
|||
None
|
||||
}
|
||||
|
||||
#[allow(clippy::ref_option)]
|
||||
#[expect(clippy::ref_option)]
|
||||
fn negative_constraints_for_expression_cycle_recover<'db>(
|
||||
_db: &'db dyn Db,
|
||||
_value: &Option<NarrowingConstraints<'db>>,
|
||||
|
|
|
@ -127,7 +127,7 @@ impl<T> PySlice for [T] {
|
|||
if len == 0 {
|
||||
// The iterator needs to have the same type as the step>0 case below,
|
||||
// so we need to use `.skip(0)`.
|
||||
#[allow(clippy::iter_skip_zero)]
|
||||
#[expect(clippy::iter_skip_zero)]
|
||||
return Ok(Either::Left(self.iter().skip(0).take(0).step_by(1)));
|
||||
}
|
||||
|
||||
|
@ -192,7 +192,7 @@ impl<T> PySlice for [T] {
|
|||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[allow(clippy::redundant_clone)]
|
||||
#[expect(clippy::redundant_clone)]
|
||||
mod tests {
|
||||
use crate::util::subscript::{OutOfBoundsError, StepSizeZeroError};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue