Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
return_self_not_must_use
  • Loading branch information
ShaharNaveh committed Jun 5, 2026
commit 3b462daa12d9bb7376795aeeb7a31a00517e9d48
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ needless_for_each = "warn"
option_as_ref_cloned = "warn"
ptr_offset_by_literal = "warn"
redundant_else = "warn"
return_self_not_must_use = "warn"
uninlined_format_args = "warn"
unnecessary_wraps = "warn"
unnested_or_patterns = "warn"
6 changes: 6 additions & 0 deletions crates/common/src/cformat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,22 @@ pub trait FormatBuf:
Extend<Self::Char> + Default + FromIterator<Self::Char> + From<String>
{
type Char: FormatChar;

fn chars(&self) -> impl Iterator<Item = Self::Char>;

fn len(&self) -> usize;

fn is_empty(&self) -> bool {
self.len() == 0
}

#[must_use]
fn concat(self, other: Self) -> Self;
}

pub trait FormatChar: Copy + Into<CodePoint> + From<u8> {
fn to_char_lossy(self) -> char;

fn eq_char(self, c: char) -> bool;
}

Expand Down
9 changes: 5 additions & 4 deletions crates/vm/src/builtins/dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,10 @@ impl PyDict {
default: OptionalArg<PyObjectRef>,
vm: &VirtualMachine,
) -> PyResult {
match self.entries.get(vm, &*key)? {
Some(value) => Ok(value),
None => Ok(default.unwrap_or_none(vm)),
}
Ok(self
.entries
.get(vm, &*key)?
.unwrap_or_else(|| default.unwrap_or_none(vm)))
}

#[pymethod]
Expand All @@ -360,6 +360,7 @@ impl PyDict {
}

#[pymethod]
#[must_use]
pub fn copy(&self) -> Self {
Self {
entries: self.entries.clone(),
Expand Down
3 changes: 3 additions & 0 deletions crates/vm/src/builtins/getset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ impl GetDescriptor for PyGetSet {
}

impl PyGetSet {
#[must_use]
pub fn new(name: String, class: &'static Py<PyType>) -> Self {
Self {
name,
Expand All @@ -79,6 +80,7 @@ impl PyGetSet {
}
}

#[must_use]
pub fn with_get<G, X>(mut self, getter: G) -> Self
where
G: IntoPyGetterFunc<X>,
Expand All @@ -87,6 +89,7 @@ impl PyGetSet {
self
}

#[must_use]
pub fn with_set<S, X>(mut self, setter: S) -> Self
where
S: IntoPySetterFunc<X>,
Expand Down
3 changes: 2 additions & 1 deletion crates/vm/src/builtins/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ impl PyMemoryView {
Ok(zelf)
}

/// this should be the only way to create a memoryview from another memoryview
/// this should be the only way to create a memoryview from another memoryview.
#[must_use]
pub fn new_view(&self) -> Self {
let zelf = Self {
buffer: self.buffer.clone(),
Expand Down
2 changes: 2 additions & 0 deletions crates/vm/src/vm/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ impl InterpreterBuilder {
/// })
/// .build();
/// ```
#[must_use]
pub fn init_hook<F>(mut self, init: F) -> Self
where
F: FnOnce(&mut VirtualMachine) + 'static,
Expand All @@ -250,6 +251,7 @@ impl InterpreterBuilder {
/// // In practice: .add_frozen_modules(rustpython_pylib::FROZEN_STDLIB)
/// .build();
/// ```
#[must_use]
pub fn add_frozen_modules<I>(mut self, frozen: I) -> Self
where
I: IntoIterator<Item = (&'static str, FrozenModule)>,
Expand Down