Skip to content

Commit a9331bb

Browse files
committed
Fix warnings for rust 1.85
1 parent 65dcf1c commit a9331bb

File tree

12 files changed

+95
-95
lines changed

12 files changed

+95
-95
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ members = [
104104
version = "0.4.0"
105105
authors = ["RustPython Team"]
106106
edition = "2021"
107-
rust-version = "1.83.0"
107+
rust-version = "1.85.0"
108108
repository = "https://github.com/RustPython/RustPython"
109109
license = "MIT"
110110

common/src/hash.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub fn hash_float(value: f64) -> Option<PyHash> {
114114
let mut e = frexp.1;
115115
let mut x: PyUHash = 0;
116116
while m != 0.0 {
117-
x = ((x << 28) & MODULUS) | x >> (BITS - 28);
117+
x = ((x << 28) & MODULUS) | (x >> (BITS - 28));
118118
m *= 268_435_456.0; // 2**28
119119
e -= 28;
120120
let y = m as PyUHash; // pull out integer part
@@ -132,7 +132,7 @@ pub fn hash_float(value: f64) -> Option<PyHash> {
132132
} else {
133133
BITS32 - 1 - ((-1 - e) % BITS32)
134134
};
135-
x = ((x << e) & MODULUS) | x >> (BITS32 - e);
135+
x = ((x << e) & MODULUS) | (x >> (BITS32 - e));
136136

137137
Some(fix_sentinel(x as PyHash * value.signum() as PyHash))
138138
}

compiler/core/src/bytecode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl OpArgState {
197197
}
198198
#[inline(always)]
199199
pub fn extend(&mut self, arg: OpArgByte) -> OpArg {
200-
self.state = self.state << 8 | u32::from(arg.0);
200+
self.state = (self.state << 8) | u32::from(arg.0);
201201
OpArg(self.state)
202202
}
203203
#[inline(always)]

src/shell/helper.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<'vm> ShellHelper<'vm> {
107107
.filter(|res| {
108108
res.as_ref()
109109
.ok()
110-
.map_or(true, |s| s.as_str().starts_with(word_start))
110+
.is_none_or(|s| s.as_str().starts_with(word_start))
111111
})
112112
.collect::<Result<Vec<_>, _>>()
113113
.ok()?;

stdlib/src/binascii.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ mod decl {
7676
let mut unhex = Vec::<u8>::with_capacity(hex_bytes.len() / 2);
7777
for (n1, n2) in hex_bytes.iter().tuples() {
7878
if let (Some(n1), Some(n2)) = (unhex_nibble(*n1), unhex_nibble(*n2)) {
79-
unhex.push(n1 << 4 | n2);
79+
unhex.push((n1 << 4) | n2);
8080
} else {
8181
return Err(super::new_binascii_error(
8282
"Non-hexadecimal digit found".to_owned(),
@@ -343,7 +343,7 @@ mod decl {
343343
if let (Some(ch1), Some(ch2)) =
344344
(unhex_nibble(buffer[idx]), unhex_nibble(buffer[idx + 1]))
345345
{
346-
out_data.push(ch1 << 4 | ch2);
346+
out_data.push((ch1 << 4) | ch2);
347347
}
348348
idx += 2;
349349
} else {
@@ -661,19 +661,19 @@ mod decl {
661661
};
662662

663663
if res.len() < length {
664-
res.push(char_a << 2 | char_b >> 4);
664+
res.push((char_a << 2) | (char_b >> 4));
665665
} else if char_a != 0 || char_b != 0 {
666666
return trailing_garbage_error();
667667
}
668668

669669
if res.len() < length {
670-
res.push((char_b & 0xf) << 4 | char_c >> 2);
670+
res.push(((char_b & 0xf) << 4) | (char_c >> 2));
671671
} else if char_c != 0 {
672672
return trailing_garbage_error();
673673
}
674674

675675
if res.len() < length {
676-
res.push((char_c & 0x3) << 6 | char_d);
676+
res.push(((char_c & 0x3) << 6) | char_d);
677677
} else if char_d != 0 {
678678
return trailing_garbage_error();
679679
}
@@ -725,8 +725,8 @@ mod decl {
725725
let char_c = *chunk.get(2).unwrap_or(&0);
726726

727727
res.push(uu_b2a(char_a >> 2, backtick));
728-
res.push(uu_b2a((char_a & 0x3) << 4 | char_b >> 4, backtick));
729-
res.push(uu_b2a((char_b & 0xf) << 2 | char_c >> 6, backtick));
728+
res.push(uu_b2a(((char_a & 0x3) << 4) | (char_b >> 4), backtick));
729+
res.push(uu_b2a(((char_b & 0xf) << 2) | (char_c >> 6), backtick));
730730
res.push(uu_b2a(char_c & 0x3f, backtick));
731731
}
732732

vm/src/builtins/object.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ fn object_getstate_default(obj: &PyObject, required: bool, vm: &VirtualMachine)
113113
// ));
114114
// }
115115

116-
let state = if obj.dict().map_or(true, |d| d.is_empty()) {
116+
let state = if obj.dict().is_none_or(|d| d.is_empty()) {
117117
vm.ctx.none()
118118
} else {
119119
// let state = object_get_dict(obj.clone(), obj.ctx()).unwrap();

vm/src/builtins/str.rs

+74-74
Original file line numberDiff line numberDiff line change
@@ -1565,80 +1565,6 @@ impl AsRef<str> for PyExact<PyStr> {
15651565
}
15661566
}
15671567

1568-
#[cfg(test)]
1569-
mod tests {
1570-
use super::*;
1571-
use crate::Interpreter;
1572-
1573-
#[test]
1574-
fn str_title() {
1575-
let tests = vec![
1576-
(" Hello ", " hello "),
1577-
("Hello ", "hello "),
1578-
("Hello ", "Hello "),
1579-
("Format This As Title String", "fOrMaT thIs aS titLe String"),
1580-
("Format,This-As*Title;String", "fOrMaT,thIs-aS*titLe;String"),
1581-
("Getint", "getInt"),
1582-
("Greek Ωppercases ...", "greek ωppercases ..."),
1583-
("Greek ῼitlecases ...", "greek ῳitlecases ..."),
1584-
];
1585-
for (title, input) in tests {
1586-
assert_eq!(PyStr::from(input).title().as_str(), title);
1587-
}
1588-
}
1589-
1590-
#[test]
1591-
fn str_istitle() {
1592-
let pos = vec![
1593-
"A",
1594-
"A Titlecased Line",
1595-
"A\nTitlecased Line",
1596-
"A Titlecased, Line",
1597-
"Greek Ωppercases ...",
1598-
"Greek ῼitlecases ...",
1599-
];
1600-
1601-
for s in pos {
1602-
assert!(PyStr::from(s).istitle());
1603-
}
1604-
1605-
let neg = vec![
1606-
"",
1607-
"a",
1608-
"\n",
1609-
"Not a capitalized String",
1610-
"Not\ta Titlecase String",
1611-
"Not--a Titlecase String",
1612-
"NOT",
1613-
];
1614-
for s in neg {
1615-
assert!(!PyStr::from(s).istitle());
1616-
}
1617-
}
1618-
1619-
#[test]
1620-
fn str_maketrans_and_translate() {
1621-
Interpreter::without_stdlib(Default::default()).enter(|vm| {
1622-
let table = vm.ctx.new_dict();
1623-
table
1624-
.set_item("a", vm.ctx.new_str("🎅").into(), vm)
1625-
.unwrap();
1626-
table.set_item("b", vm.ctx.none(), vm).unwrap();
1627-
table
1628-
.set_item("c", vm.ctx.new_str(ascii!("xda")).into(), vm)
1629-
.unwrap();
1630-
let translated =
1631-
PyStr::maketrans(table.into(), OptionalArg::Missing, OptionalArg::Missing, vm)
1632-
.unwrap();
1633-
let text = PyStr::from("abc");
1634-
let translated = text.translate(translated, vm).unwrap();
1635-
assert_eq!(translated, "🎅xda".to_owned());
1636-
let translated = text.translate(vm.ctx.new_int(3).into(), vm);
1637-
assert_eq!("TypeError", &*translated.unwrap_err().class().name(),);
1638-
})
1639-
}
1640-
}
1641-
16421568
impl AnyStrWrapper for PyStrRef {
16431569
type Str = str;
16441570
fn as_ref(&self) -> &str {
@@ -1780,3 +1706,77 @@ impl AsRef<str> for PyStrInterned {
17801706
self.as_str()
17811707
}
17821708
}
1709+
1710+
#[cfg(test)]
1711+
mod tests {
1712+
use super::*;
1713+
use crate::Interpreter;
1714+
1715+
#[test]
1716+
fn str_title() {
1717+
let tests = vec![
1718+
(" Hello ", " hello "),
1719+
("Hello ", "hello "),
1720+
("Hello ", "Hello "),
1721+
("Format This As Title String", "fOrMaT thIs aS titLe String"),
1722+
("Format,This-As*Title;String", "fOrMaT,thIs-aS*titLe;String"),
1723+
("Getint", "getInt"),
1724+
("Greek Ωppercases ...", "greek ωppercases ..."),
1725+
("Greek ῼitlecases ...", "greek ῳitlecases ..."),
1726+
];
1727+
for (title, input) in tests {
1728+
assert_eq!(PyStr::from(input).title().as_str(), title);
1729+
}
1730+
}
1731+
1732+
#[test]
1733+
fn str_istitle() {
1734+
let pos = vec![
1735+
"A",
1736+
"A Titlecased Line",
1737+
"A\nTitlecased Line",
1738+
"A Titlecased, Line",
1739+
"Greek Ωppercases ...",
1740+
"Greek ῼitlecases ...",
1741+
];
1742+
1743+
for s in pos {
1744+
assert!(PyStr::from(s).istitle());
1745+
}
1746+
1747+
let neg = vec![
1748+
"",
1749+
"a",
1750+
"\n",
1751+
"Not a capitalized String",
1752+
"Not\ta Titlecase String",
1753+
"Not--a Titlecase String",
1754+
"NOT",
1755+
];
1756+
for s in neg {
1757+
assert!(!PyStr::from(s).istitle());
1758+
}
1759+
}
1760+
1761+
#[test]
1762+
fn str_maketrans_and_translate() {
1763+
Interpreter::without_stdlib(Default::default()).enter(|vm| {
1764+
let table = vm.ctx.new_dict();
1765+
table
1766+
.set_item("a", vm.ctx.new_str("🎅").into(), vm)
1767+
.unwrap();
1768+
table.set_item("b", vm.ctx.none(), vm).unwrap();
1769+
table
1770+
.set_item("c", vm.ctx.new_str(ascii!("xda")).into(), vm)
1771+
.unwrap();
1772+
let translated =
1773+
PyStr::maketrans(table.into(), OptionalArg::Missing, OptionalArg::Missing, vm)
1774+
.unwrap();
1775+
let text = PyStr::from("abc");
1776+
let translated = text.translate(translated, vm).unwrap();
1777+
assert_eq!(translated, "🎅xda".to_owned());
1778+
let translated = text.translate(vm.ctx.new_int(3).into(), vm);
1779+
assert_eq!("TypeError", &*translated.unwrap_err().class().name(),);
1780+
})
1781+
}
1782+
}

vm/src/codecs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -637,10 +637,10 @@ fn surrogatepass_errors(err: PyObjectRef, vm: &VirtualMachine) -> PyResult<(PyOb
637637
}
638638
}
639639
StandardEncoding::Utf16Le => {
640-
c = (p[1] as u32) << 8 | p[0] as u32;
640+
c = ((p[1] as u32) << 8) | p[0] as u32;
641641
}
642642
StandardEncoding::Utf16Be => {
643-
c = (p[0] as u32) << 8 | p[1] as u32;
643+
c = ((p[0] as u32) << 8) | p[1] as u32;
644644
}
645645
StandardEncoding::Utf32Le => {
646646
c = ((p[3] as u32) << 24)

vm/src/stdlib/io.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ mod _io {
482482
let size = size.to_usize();
483483
let read = instance.get_attr("read", vm)?;
484484
let mut res = Vec::new();
485-
while size.map_or(true, |s| res.len() < s) {
485+
while size.is_none_or(|s| res.len() < s) {
486486
let read_res = ArgBytesLike::try_from_object(vm, read.call((1,), vm)?)?;
487487
if read_res.with_ref(|b| b.is_empty()) {
488488
break;

vm/src/vm/vm_ops.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ impl VirtualMachine {
298298
}
299299

300300
if let Some(slot_c) = class_c.slots.as_number.left_ternary_op(op_slot) {
301-
if slot_a.is_some_and(|slot_a| slot_a != slot_c)
302-
&& slot_b.is_some_and(|slot_b| slot_b != slot_c)
301+
if slot_a.is_some_and(|slot_a| !std::ptr::fn_addr_eq(slot_a, slot_c))
302+
&& slot_b.is_some_and(|slot_b| !std::ptr::fn_addr_eq(slot_b, slot_c))
303303
{
304304
let ret = slot_c(a, b, c, self)?;
305305
if !ret.is(&self.ctx.not_implemented) {

vm/sre_engine/src/string.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,15 @@ unsafe fn next_code_point(ptr: &mut *const u8) -> u32 {
181181
let z = **ptr;
182182
*ptr = ptr.offset(1);
183183
let y_z = utf8_acc_cont_byte((y & CONT_MASK) as u32, z);
184-
ch = init << 12 | y_z;
184+
ch = (init << 12) | y_z;
185185
if x >= 0xF0 {
186186
// [x y z w] case
187187
// use only the lower 3 bits of `init`
188188
// SAFETY: `bytes` produces an UTF-8-like string,
189189
// so the iterator must produce a value here.
190190
let w = **ptr;
191191
*ptr = ptr.offset(1);
192-
ch = (init & 7) << 18 | utf8_acc_cont_byte(y_z, w);
192+
ch = ((init & 7) << 18) | utf8_acc_cont_byte(y_z, w);
193193
}
194194
}
195195

0 commit comments

Comments
 (0)