Skip to content

Commit d1ed52b

Browse files
committed
Auto merge of #146572 - matthiaskrgr:rollup-gotklb6, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #143314 (add reference id to test, and fix filename) - #146284 (Remove `div_rem` from `core::num::bignum`) - #146416 (Tidy dependency checks cleanups + QoL) - #146471 (bootstrap: Show target in "No such target exists" message) - #146478 (Improve `core::fmt` coverage) - #146480 (tests: update new test to accept new lifetime format) - #146488 (Improve `core::ptr` coverage) - #146501 (compiletest: Fix `--exact` test filtering) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 52618eb + 0a14ae0 commit d1ed52b

File tree

16 files changed

+261
-116
lines changed

16 files changed

+261
-116
lines changed

library/core/src/num/bignum.rs

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -335,43 +335,6 @@ macro_rules! define_bignum {
335335
}
336336
(self, borrow)
337337
}
338-
339-
/// Divide self by another bignum, overwriting `q` with the quotient and `r` with the
340-
/// remainder.
341-
pub fn div_rem(&self, d: &$name, q: &mut $name, r: &mut $name) {
342-
// Stupid slow base-2 long division taken from
343-
// https://en.wikipedia.org/wiki/Division_algorithm
344-
// FIXME use a greater base ($ty) for the long division.
345-
assert!(!d.is_zero());
346-
let digitbits = <$ty>::BITS as usize;
347-
for digit in &mut q.base[..] {
348-
*digit = 0;
349-
}
350-
for digit in &mut r.base[..] {
351-
*digit = 0;
352-
}
353-
r.size = d.size;
354-
q.size = 1;
355-
let mut q_is_zero = true;
356-
let end = self.bit_length();
357-
for i in (0..end).rev() {
358-
r.mul_pow2(1);
359-
r.base[0] |= self.get_bit(i) as $ty;
360-
if &*r >= d {
361-
r.sub(d);
362-
// Set bit `i` of q to 1.
363-
let digit_idx = i / digitbits;
364-
let bit_idx = i % digitbits;
365-
if q_is_zero {
366-
q.size = digit_idx + 1;
367-
q_is_zero = false;
368-
}
369-
q.base[digit_idx] |= 1 << bit_idx;
370-
}
371-
}
372-
debug_assert!(q.base[q.size..].iter().all(|&d| d == 0));
373-
debug_assert!(r.base[r.size..].iter().all(|&d| d == 0));
374-
}
375338
}
376339

377340
impl crate::cmp::PartialEq for $name {

library/coretests/tests/fmt/builders.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,21 @@ mod debug_struct {
173173
format!("{Bar:#?}")
174174
);
175175
}
176+
177+
#[test]
178+
fn test_field_with() {
179+
struct Foo;
180+
impl fmt::Debug for Foo {
181+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
182+
fmt.debug_struct("Foo")
183+
.field_with("bar", |f| f.write_str("true"))
184+
.field_with("baz", |f| f.write_str("false"))
185+
.finish()
186+
}
187+
}
188+
189+
assert_eq!("Foo {\n bar: true,\n baz: false,\n}", format!("{Foo:#?}"))
190+
}
176191
}
177192

178193
mod debug_tuple {

library/coretests/tests/fmt/mod.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,36 @@ fn test_fmt_debug_of_raw_pointers() {
5757
check_fmt(vtable as *const dyn Debug, "Pointer { addr: ", ", metadata: DynMetadata(");
5858
}
5959

60+
#[test]
61+
fn test_fmt_debug_of_mut_reference() {
62+
let mut x: u32 = 0;
63+
64+
assert_eq!(format!("{:?}", &mut x), "0");
65+
}
66+
67+
#[test]
68+
fn test_default_write_impls() {
69+
use core::fmt::Write;
70+
71+
struct Buf(String);
72+
73+
impl Write for Buf {
74+
fn write_str(&mut self, s: &str) -> core::fmt::Result {
75+
self.0.write_str(s)
76+
}
77+
}
78+
79+
let mut buf = Buf(String::new());
80+
buf.write_char('a').unwrap();
81+
82+
assert_eq!(buf.0, "a");
83+
84+
let mut buf = Buf(String::new());
85+
buf.write_fmt(format_args!("a")).unwrap();
86+
87+
assert_eq!(buf.0, "a");
88+
}
89+
6090
#[test]
6191
fn test_estimated_capacity() {
6292
assert_eq!(format_args!("").estimated_capacity(), 0);

library/coretests/tests/fmt/num.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,9 @@ fn test_format_debug_hex() {
323323
assert_eq!(format!("{:02x?}", b"Foo\0"), "[46, 6f, 6f, 00]");
324324
assert_eq!(format!("{:02X?}", b"Foo\0"), "[46, 6F, 6F, 00]");
325325
}
326+
327+
#[test]
328+
#[should_panic = "Formatting argument out of range"]
329+
fn test_rt_width_too_long() {
330+
let _ = format!("Hello {:width$}!", "x", width = u16::MAX as usize + 1);
331+
}

library/coretests/tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#![feature(core_private_bignum)]
3434
#![feature(core_private_diy_float)]
3535
#![feature(cstr_display)]
36+
#![feature(debug_closure_helpers)]
3637
#![feature(dec2flt)]
3738
#![feature(drop_guard)]
3839
#![feature(duration_constants)]

library/coretests/tests/num/bignum.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -167,25 +167,6 @@ fn test_div_rem_small() {
167167
);
168168
}
169169

170-
#[test]
171-
fn test_div_rem() {
172-
fn div_rem(n: u64, d: u64) -> (Big, Big) {
173-
let mut q = Big::from_small(42);
174-
let mut r = Big::from_small(42);
175-
Big::from_u64(n).div_rem(&Big::from_u64(d), &mut q, &mut r);
176-
(q, r)
177-
}
178-
assert_eq!(div_rem(1, 1), (Big::from_small(1), Big::from_small(0)));
179-
assert_eq!(div_rem(4, 3), (Big::from_small(1), Big::from_small(1)));
180-
assert_eq!(div_rem(1, 7), (Big::from_small(0), Big::from_small(1)));
181-
assert_eq!(div_rem(45, 9), (Big::from_small(5), Big::from_small(0)));
182-
assert_eq!(div_rem(103, 9), (Big::from_small(11), Big::from_small(4)));
183-
assert_eq!(div_rem(123456, 77), (Big::from_u64(1603), Big::from_small(25)));
184-
assert_eq!(div_rem(0xffff, 1), (Big::from_u64(0xffff), Big::from_small(0)));
185-
assert_eq!(div_rem(0xeeee, 0xffff), (Big::from_small(0), Big::from_u64(0xeeee)));
186-
assert_eq!(div_rem(2_000_000, 2), (Big::from_u64(1_000_000), Big::from_u64(0)));
187-
}
188-
189170
#[test]
190171
fn test_is_zero() {
191172
assert!(Big::from_small(0).is_zero());

library/coretests/tests/ptr.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,14 @@ fn is_aligned() {
489489
assert_ne!(ptr.is_aligned_to(8), ptr.wrapping_add(1).is_aligned_to(8));
490490
}
491491

492+
#[test]
493+
#[should_panic = "is_aligned_to: align is not a power-of-two"]
494+
fn invalid_is_aligned() {
495+
let data = 42;
496+
let ptr: *const i32 = &data;
497+
assert!(ptr.is_aligned_to(3));
498+
}
499+
492500
#[test]
493501
fn offset_from() {
494502
let mut a = [0; 5];

src/bootstrap/src/core/sanity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ than building it.
287287

288288
if !has_target {
289289
panic!(
290-
"No such target exists in the target list,\n\
290+
"{target_str}: No such target exists in the target list,\n\
291291
make sure to correctly specify the location \
292292
of the JSON specification file \
293293
for custom targets!\n\

src/tools/compiletest/src/directives.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,7 @@ pub(crate) fn make_test_description<R: Read>(
14461446
cache: &DirectivesCache,
14471447
name: String,
14481448
path: &Utf8Path,
1449+
filterable_path: &Utf8Path,
14491450
src: R,
14501451
test_revision: Option<&str>,
14511452
poisoned: &mut bool,
@@ -1520,7 +1521,13 @@ pub(crate) fn make_test_description<R: Read>(
15201521
_ => ShouldPanic::No,
15211522
};
15221523

1523-
CollectedTestDesc { name, ignore, ignore_message, should_panic }
1524+
CollectedTestDesc {
1525+
name,
1526+
filterable_path: filterable_path.to_owned(),
1527+
ignore,
1528+
ignore_message,
1529+
should_panic,
1530+
}
15241531
}
15251532

15261533
fn ignore_cdb(config: &Config, line: &str) -> IgnoreDecision {

src/tools/compiletest/src/directives/tests.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ fn make_test_description<R: Read>(
1414
config: &Config,
1515
name: String,
1616
path: &Utf8Path,
17+
filterable_path: &Utf8Path,
1718
src: R,
1819
revision: Option<&str>,
1920
) -> CollectedTestDesc {
@@ -24,6 +25,7 @@ fn make_test_description<R: Read>(
2425
&cache,
2526
name,
2627
path,
28+
filterable_path,
2729
src,
2830
revision,
2931
&mut poisoned,
@@ -221,7 +223,7 @@ fn parse_rs(config: &Config, contents: &str) -> EarlyProps {
221223
fn check_ignore(config: &Config, contents: &str) -> bool {
222224
let tn = String::new();
223225
let p = Utf8Path::new("a.rs");
224-
let d = make_test_description(&config, tn, p, std::io::Cursor::new(contents), None);
226+
let d = make_test_description(&config, tn, p, p, std::io::Cursor::new(contents), None);
225227
d.ignore
226228
}
227229

@@ -231,9 +233,9 @@ fn should_fail() {
231233
let tn = String::new();
232234
let p = Utf8Path::new("a.rs");
233235

234-
let d = make_test_description(&config, tn.clone(), p, std::io::Cursor::new(""), None);
236+
let d = make_test_description(&config, tn.clone(), p, p, std::io::Cursor::new(""), None);
235237
assert_eq!(d.should_panic, ShouldPanic::No);
236-
let d = make_test_description(&config, tn, p, std::io::Cursor::new("//@ should-fail"), None);
238+
let d = make_test_description(&config, tn, p, p, std::io::Cursor::new("//@ should-fail"), None);
237239
assert_eq!(d.should_panic, ShouldPanic::Yes);
238240
}
239241

0 commit comments

Comments
 (0)