Fix warnings for rust 1.85

This commit is contained in:
Noa committed 2025-02-20 14:58:59 -06:00
1 parent 65dcf1ce1c
commit a9331bb34d
12 files changed
+95 -95

No files matched your search

Generated
+1 -1
View File
@@ -1322,7 +1322,7 @@ version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df7151a832e54d2d6b2c827a20e5bcdd80359281cd2c354e725d4b82e7c471de"
dependencies = [
"rand_core 0.9.0",
"rand_core 0.9.1",
]
[[package]]
+1 -1
View File
@@ -104,7 +104,7 @@ members = [
version = "0.4.0"
authors = ["RustPython Team"]
edition = "2021"
rust-version = "1.83.0"
rust-version = "1.85.0"
repository = "https://github.com/RustPython/RustPython"
license = "MIT"
+2 -2
View File
@@ -114,7 +114,7 @@ pub fn hash_float(value: f64) -> Option<PyHash> {
let mut e = frexp.1;
let mut x: PyUHash = 0;
while m != 0.0 {
x = ((x << 28) & MODULUS) | x >> (BITS - 28);
x = ((x << 28) & MODULUS) | (x >> (BITS - 28));
m *= 268_435_456.0; // 2**28
e -= 28;
let y = m as PyUHash; // pull out integer part
@@ -132,7 +132,7 @@ pub fn hash_float(value: f64) -> Option<PyHash> {
} else {
BITS32 - 1 - ((-1 - e) % BITS32)
};
x = ((x << e) & MODULUS) | x >> (BITS32 - e);
x = ((x << e) & MODULUS) | (x >> (BITS32 - e));
Some(fix_sentinel(x as PyHash * value.signum() as PyHash))
}
+1 -1
View File
@@ -197,7 +197,7 @@ impl OpArgState {
}
#[inline(always)]
pub fn extend(&mut self, arg: OpArgByte) -> OpArg {
self.state = self.state << 8 | u32::from(arg.0);
self.state = (self.state << 8) | u32::from(arg.0);
OpArg(self.state)
}
#[inline(always)]
+1 -1
View File
@@ -107,7 +107,7 @@ impl<'vm> ShellHelper<'vm> {
.filter(|res| {
res.as_ref()
.ok()
.map_or(true, |s| s.as_str().starts_with(word_start))
.is_none_or(|s| s.as_str().starts_with(word_start))
})
.collect::<Result<Vec<_>, _>>()
.ok()?;
+7 -7
View File
@@ -76,7 +76,7 @@ mod decl {
let mut unhex = Vec::<u8>::with_capacity(hex_bytes.len() / 2);
for (n1, n2) in hex_bytes.iter().tuples() {
if let (Some(n1), Some(n2)) = (unhex_nibble(*n1), unhex_nibble(*n2)) {
unhex.push(n1 << 4 | n2);
unhex.push((n1 << 4) | n2);
} else {
return Err(super::new_binascii_error(
"Non-hexadecimal digit found".to_owned(),
@@ -343,7 +343,7 @@ mod decl {
if let (Some(ch1), Some(ch2)) =
(unhex_nibble(buffer[idx]), unhex_nibble(buffer[idx + 1]))
{
out_data.push(ch1 << 4 | ch2);
out_data.push((ch1 << 4) | ch2);
}
idx += 2;
} else {
@@ -661,19 +661,19 @@ mod decl {
};
if res.len() < length {
res.push(char_a << 2 | char_b >> 4);
res.push((char_a << 2) | (char_b >> 4));
} else if char_a != 0 || char_b != 0 {
return trailing_garbage_error();
}
if res.len() < length {
res.push((char_b & 0xf) << 4 | char_c >> 2);
res.push(((char_b & 0xf) << 4) | (char_c >> 2));
} else if char_c != 0 {
return trailing_garbage_error();
}
if res.len() < length {
res.push((char_c & 0x3) << 6 | char_d);
res.push(((char_c & 0x3) << 6) | char_d);
} else if char_d != 0 {
return trailing_garbage_error();
}
@@ -725,8 +725,8 @@ mod decl {
let char_c = *chunk.get(2).unwrap_or(&0);
res.push(uu_b2a(char_a >> 2, backtick));
res.push(uu_b2a((char_a & 0x3) << 4 | char_b >> 4, backtick));
res.push(uu_b2a((char_b & 0xf) << 2 | char_c >> 6, backtick));
res.push(uu_b2a(((char_a & 0x3) << 4) | (char_b >> 4), backtick));
res.push(uu_b2a(((char_b & 0xf) << 2) | (char_c >> 6), backtick));
res.push(uu_b2a(char_c & 0x3f, backtick));
}
+1 -1
View File
@@ -113,7 +113,7 @@ fn object_getstate_default(obj: &PyObject, required: bool, vm: &VirtualMachine)
// ));
// }
let state = if obj.dict().map_or(true, |d| d.is_empty()) {
let state = if obj.dict().is_none_or(|d| d.is_empty()) {
vm.ctx.none()
} else {
// let state = object_get_dict(obj.clone(), obj.ctx()).unwrap();
+74 -74
View File
@@ -1565,80 +1565,6 @@ impl AsRef<str> for PyExact<PyStr> {
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::Interpreter;
#[test]
fn str_title() {
let tests = vec![
(" Hello ", " hello "),
("Hello ", "hello "),
("Hello ", "Hello "),
("Format This As Title String", "fOrMaT thIs aS titLe String"),
("Format,This-As*Title;String", "fOrMaT,thIs-aS*titLe;String"),
("Getint", "getInt"),
("Greek Ωppercases ...", "greek ωppercases ..."),
("Greek ῼitlecases ...", "greek ῳitlecases ..."),
];
for (title, input) in tests {
assert_eq!(PyStr::from(input).title().as_str(), title);
}
}
#[test]
fn str_istitle() {
let pos = vec![
"A",
"A Titlecased Line",
"A\nTitlecased Line",
"A Titlecased, Line",
"Greek Ωppercases ...",
"Greek ῼitlecases ...",
];
for s in pos {
assert!(PyStr::from(s).istitle());
}
let neg = vec![
"",
"a",
"\n",
"Not a capitalized String",
"Not\ta Titlecase String",
"Not--a Titlecase String",
"NOT",
];
for s in neg {
assert!(!PyStr::from(s).istitle());
}
}
#[test]
fn str_maketrans_and_translate() {
Interpreter::without_stdlib(Default::default()).enter(|vm| {
let table = vm.ctx.new_dict();
table
.set_item("a", vm.ctx.new_str("🎅").into(), vm)
.unwrap();
table.set_item("b", vm.ctx.none(), vm).unwrap();
table
.set_item("c", vm.ctx.new_str(ascii!("xda")).into(), vm)
.unwrap();
let translated =
PyStr::maketrans(table.into(), OptionalArg::Missing, OptionalArg::Missing, vm)
.unwrap();
let text = PyStr::from("abc");
let translated = text.translate(translated, vm).unwrap();
assert_eq!(translated, "🎅xda".to_owned());
let translated = text.translate(vm.ctx.new_int(3).into(), vm);
assert_eq!("TypeError", &*translated.unwrap_err().class().name(),);
})
}
}
impl AnyStrWrapper for PyStrRef {
type Str = str;
fn as_ref(&self) -> &str {
@@ -1780,3 +1706,77 @@ impl AsRef<str> for PyStrInterned {
self.as_str()
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::Interpreter;
#[test]
fn str_title() {
let tests = vec![
(" Hello ", " hello "),
("Hello ", "hello "),
("Hello ", "Hello "),
("Format This As Title String", "fOrMaT thIs aS titLe String"),
("Format,This-As*Title;String", "fOrMaT,thIs-aS*titLe;String"),
("Getint", "getInt"),
("Greek Ωppercases ...", "greek ωppercases ..."),
("Greek ῼitlecases ...", "greek ῳitlecases ..."),
];
for (title, input) in tests {
assert_eq!(PyStr::from(input).title().as_str(), title);
}
}
#[test]
fn str_istitle() {
let pos = vec![
"A",
"A Titlecased Line",
"A\nTitlecased Line",
"A Titlecased, Line",
"Greek Ωppercases ...",
"Greek ῼitlecases ...",
];
for s in pos {
assert!(PyStr::from(s).istitle());
}
let neg = vec![
"",
"a",
"\n",
"Not a capitalized String",
"Not\ta Titlecase String",
"Not--a Titlecase String",
"NOT",
];
for s in neg {
assert!(!PyStr::from(s).istitle());
}
}
#[test]
fn str_maketrans_and_translate() {
Interpreter::without_stdlib(Default::default()).enter(|vm| {
let table = vm.ctx.new_dict();
table
.set_item("a", vm.ctx.new_str("🎅").into(), vm)
.unwrap();
table.set_item("b", vm.ctx.none(), vm).unwrap();
table
.set_item("c", vm.ctx.new_str(ascii!("xda")).into(), vm)
.unwrap();
let translated =
PyStr::maketrans(table.into(), OptionalArg::Missing, OptionalArg::Missing, vm)
.unwrap();
let text = PyStr::from("abc");
let translated = text.translate(translated, vm).unwrap();
assert_eq!(translated, "🎅xda".to_owned());
let translated = text.translate(vm.ctx.new_int(3).into(), vm);
assert_eq!("TypeError", &*translated.unwrap_err().class().name(),);
})
}
}
+2 -2
View File
@@ -637,10 +637,10 @@ fn surrogatepass_errors(err: PyObjectRef, vm: &VirtualMachine) -> PyResult<(PyOb
}
}
StandardEncoding::Utf16Le => {
c = (p[1] as u32) << 8 | p[0] as u32;
c = ((p[1] as u32) << 8) | p[0] as u32;
}
StandardEncoding::Utf16Be => {
c = (p[0] as u32) << 8 | p[1] as u32;
c = ((p[0] as u32) << 8) | p[1] as u32;
}
StandardEncoding::Utf32Le => {
c = ((p[3] as u32) << 24)
+1 -1
View File
@@ -482,7 +482,7 @@ mod _io {
let size = size.to_usize();
let read = instance.get_attr("read", vm)?;
let mut res = Vec::new();
while size.map_or(true, |s| res.len() < s) {
while size.is_none_or(|s| res.len() < s) {
let read_res = ArgBytesLike::try_from_object(vm, read.call((1,), vm)?)?;
if read_res.with_ref(|b| b.is_empty()) {
break;
+2 -2
View File
@@ -298,8 +298,8 @@ impl VirtualMachine {
}
if let Some(slot_c) = class_c.slots.as_number.left_ternary_op(op_slot) {
if slot_a.is_some_and(|slot_a| slot_a != slot_c)
&& slot_b.is_some_and(|slot_b| slot_b != slot_c)
if slot_a.is_some_and(|slot_a| !std::ptr::fn_addr_eq(slot_a, slot_c))
&& slot_b.is_some_and(|slot_b| !std::ptr::fn_addr_eq(slot_b, slot_c))
{
let ret = slot_c(a, b, c, self)?;
if !ret.is(&self.ctx.not_implemented) {
+2 -2
View File
@@ -181,7 +181,7 @@ unsafe fn next_code_point(ptr: &mut *const u8) -> u32 {
let z = **ptr;
*ptr = ptr.offset(1);
let y_z = utf8_acc_cont_byte((y & CONT_MASK) as u32, z);
ch = init << 12 | y_z;
ch = (init << 12) | y_z;
if x >= 0xF0 {
// [x y z w] case
// use only the lower 3 bits of `init`
@@ -189,7 +189,7 @@ unsafe fn next_code_point(ptr: &mut *const u8) -> u32 {
// so the iterator must produce a value here.
let w = **ptr;
*ptr = ptr.offset(1);
ch = (init & 7) << 18 | utf8_acc_cont_byte(y_z, w);
ch = ((init & 7) << 18) | utf8_acc_cont_byte(y_z, w);
}
}