Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c40e004
gai: remove typo from test file, and add a reference id
tshepang Jul 2, 2025
a2d66db
remove unsused div_rem method from bignum
Kivooeo Sep 6, 2025
cb81972
tidy: Introduce `WorkspaceInfo` struct for deps information
clubby789 Sep 10, 2025
ba874d3
tidy: Print crate name on dependency error
clubby789 Sep 10, 2025
adfb6ec
tidy: More accurate permitted dependencies location
clubby789 Sep 10, 2025
11a22b3
tidy: Add specific line info for allowed dependencies
clubby789 Sep 10, 2025
fefc979
bootstrap: Show target in "No such target exists" message
neuschaefer Sep 12, 2025
2e652d7
Improve `core::fmt` coverage
pvdrz Sep 12, 2025
dd4562a
tests: update new test to accept new lifetime format
durin42 Sep 12, 2025
87ae4db
Improve `core::ptr` coverage
pvdrz Sep 12, 2025
a48c8e3
compiletest: Fix `--exact` test filtering
Enselic Sep 13, 2025
37d058f
tidy: Remove `WorkspaceInfo` constructor
clubby789 Sep 14, 2025
f96bc5c
Rollup merge of #143314 - tshepang:fix-filename, r=compiler-errors
matthiaskrgr Sep 15, 2025
fa63dbf
Rollup merge of #146284 - Kivooeo:blazing-fast-division-bignum, r=Mar…
matthiaskrgr Sep 15, 2025
b59f0a2
Rollup merge of #146416 - clubby789:tidy-deps-qol, r=jieyouxu
matthiaskrgr Sep 15, 2025
d316cfd
Rollup merge of #146471 - neuschaefer:no-target, r=Mark-Simulacrum
matthiaskrgr Sep 15, 2025
9070e95
Rollup merge of #146478 - ferrocene:pvdrz/improve-fmt-coverage, r=Mar…
matthiaskrgr Sep 15, 2025
b82698b
Rollup merge of #146480 - durin42:llvm-22-more-lifetime, r=Mark-Simul…
matthiaskrgr Sep 15, 2025
32c045e
Rollup merge of #146488 - ferrocene:pvdrz/improve-ptr-coverage, r=Mar…
matthiaskrgr Sep 15, 2025
0a14ae0
Rollup merge of #146501 - Enselic:x-test-filter, r=Mark-Simulacrum
matthiaskrgr Sep 15, 2025
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
37 changes: 0 additions & 37 deletions library/core/src/num/bignum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,43 +335,6 @@ macro_rules! define_bignum {
}
(self, borrow)
}

/// Divide self by another bignum, overwriting `q` with the quotient and `r` with the
/// remainder.
pub fn div_rem(&self, d: &$name, q: &mut $name, r: &mut $name) {
// Stupid slow base-2 long division taken from
// https://en.wikipedia.org/wiki/Division_algorithm
// FIXME use a greater base ($ty) for the long division.
assert!(!d.is_zero());
let digitbits = <$ty>::BITS as usize;
for digit in &mut q.base[..] {
*digit = 0;
}
for digit in &mut r.base[..] {
*digit = 0;
}
r.size = d.size;
q.size = 1;
let mut q_is_zero = true;
let end = self.bit_length();
for i in (0..end).rev() {
r.mul_pow2(1);
r.base[0] |= self.get_bit(i) as $ty;
if &*r >= d {
r.sub(d);
// Set bit `i` of q to 1.
let digit_idx = i / digitbits;
let bit_idx = i % digitbits;
if q_is_zero {
q.size = digit_idx + 1;
q_is_zero = false;
}
q.base[digit_idx] |= 1 << bit_idx;
}
}
debug_assert!(q.base[q.size..].iter().all(|&d| d == 0));
debug_assert!(r.base[r.size..].iter().all(|&d| d == 0));
}
}

impl crate::cmp::PartialEq for $name {
Expand Down
15 changes: 15 additions & 0 deletions library/coretests/tests/fmt/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,21 @@ mod debug_struct {
format!("{Bar:#?}")
);
}

#[test]
fn test_field_with() {
struct Foo;
impl fmt::Debug for Foo {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("Foo")
.field_with("bar", |f| f.write_str("true"))
.field_with("baz", |f| f.write_str("false"))
.finish()
}
}

assert_eq!("Foo {\n bar: true,\n baz: false,\n}", format!("{Foo:#?}"))
}
}

mod debug_tuple {
Expand Down
30 changes: 30 additions & 0 deletions library/coretests/tests/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,36 @@ fn test_fmt_debug_of_raw_pointers() {
check_fmt(vtable as *const dyn Debug, "Pointer { addr: ", ", metadata: DynMetadata(");
}

#[test]
fn test_fmt_debug_of_mut_reference() {
let mut x: u32 = 0;

assert_eq!(format!("{:?}", &mut x), "0");
}

#[test]
fn test_default_write_impls() {
use core::fmt::Write;

struct Buf(String);

impl Write for Buf {
fn write_str(&mut self, s: &str) -> core::fmt::Result {
self.0.write_str(s)
}
}

let mut buf = Buf(String::new());
buf.write_char('a').unwrap();

assert_eq!(buf.0, "a");

let mut buf = Buf(String::new());
buf.write_fmt(format_args!("a")).unwrap();

assert_eq!(buf.0, "a");
}

#[test]
fn test_estimated_capacity() {
assert_eq!(format_args!("").estimated_capacity(), 0);
Expand Down
6 changes: 6 additions & 0 deletions library/coretests/tests/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,9 @@ fn test_format_debug_hex() {
assert_eq!(format!("{:02x?}", b"Foo\0"), "[46, 6f, 6f, 00]");
assert_eq!(format!("{:02X?}", b"Foo\0"), "[46, 6F, 6F, 00]");
}

#[test]
#[should_panic = "Formatting argument out of range"]
fn test_rt_width_too_long() {
let _ = format!("Hello {:width$}!", "x", width = u16::MAX as usize + 1);
}
1 change: 1 addition & 0 deletions library/coretests/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#![feature(core_private_bignum)]
#![feature(core_private_diy_float)]
#![feature(cstr_display)]
#![feature(debug_closure_helpers)]
#![feature(dec2flt)]
#![feature(drop_guard)]
#![feature(duration_constants)]
Expand Down
19 changes: 0 additions & 19 deletions library/coretests/tests/num/bignum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,25 +167,6 @@ fn test_div_rem_small() {
);
}

#[test]
fn test_div_rem() {
fn div_rem(n: u64, d: u64) -> (Big, Big) {
let mut q = Big::from_small(42);
let mut r = Big::from_small(42);
Big::from_u64(n).div_rem(&Big::from_u64(d), &mut q, &mut r);
(q, r)
}
assert_eq!(div_rem(1, 1), (Big::from_small(1), Big::from_small(0)));
assert_eq!(div_rem(4, 3), (Big::from_small(1), Big::from_small(1)));
assert_eq!(div_rem(1, 7), (Big::from_small(0), Big::from_small(1)));
assert_eq!(div_rem(45, 9), (Big::from_small(5), Big::from_small(0)));
assert_eq!(div_rem(103, 9), (Big::from_small(11), Big::from_small(4)));
assert_eq!(div_rem(123456, 77), (Big::from_u64(1603), Big::from_small(25)));
assert_eq!(div_rem(0xffff, 1), (Big::from_u64(0xffff), Big::from_small(0)));
assert_eq!(div_rem(0xeeee, 0xffff), (Big::from_small(0), Big::from_u64(0xeeee)));
assert_eq!(div_rem(2_000_000, 2), (Big::from_u64(1_000_000), Big::from_u64(0)));
}

#[test]
fn test_is_zero() {
assert!(Big::from_small(0).is_zero());
Expand Down
8 changes: 8 additions & 0 deletions library/coretests/tests/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,14 @@ fn is_aligned() {
assert_ne!(ptr.is_aligned_to(8), ptr.wrapping_add(1).is_aligned_to(8));
}

#[test]
#[should_panic = "is_aligned_to: align is not a power-of-two"]
fn invalid_is_aligned() {
let data = 42;
let ptr: *const i32 = &data;
assert!(ptr.is_aligned_to(3));
}

#[test]
fn offset_from() {
let mut a = [0; 5];
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ than building it.

if !has_target {
panic!(
"No such target exists in the target list,\n\
"{target_str}: No such target exists in the target list,\n\
make sure to correctly specify the location \
of the JSON specification file \
for custom targets!\n\
Expand Down
9 changes: 8 additions & 1 deletion src/tools/compiletest/src/directives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,7 @@ pub(crate) fn make_test_description<R: Read>(
cache: &DirectivesCache,
name: String,
path: &Utf8Path,
filterable_path: &Utf8Path,
src: R,
test_revision: Option<&str>,
poisoned: &mut bool,
Expand Down Expand Up @@ -1520,7 +1521,13 @@ pub(crate) fn make_test_description<R: Read>(
_ => ShouldPanic::No,
};

CollectedTestDesc { name, ignore, ignore_message, should_panic }
CollectedTestDesc {
name,
filterable_path: filterable_path.to_owned(),
ignore,
ignore_message,
should_panic,
}
}

fn ignore_cdb(config: &Config, line: &str) -> IgnoreDecision {
Expand Down
8 changes: 5 additions & 3 deletions src/tools/compiletest/src/directives/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ fn make_test_description<R: Read>(
config: &Config,
name: String,
path: &Utf8Path,
filterable_path: &Utf8Path,
src: R,
revision: Option<&str>,
) -> CollectedTestDesc {
Expand All @@ -24,6 +25,7 @@ fn make_test_description<R: Read>(
&cache,
name,
path,
filterable_path,
src,
revision,
&mut poisoned,
Expand Down Expand Up @@ -221,7 +223,7 @@ fn parse_rs(config: &Config, contents: &str) -> EarlyProps {
fn check_ignore(config: &Config, contents: &str) -> bool {
let tn = String::new();
let p = Utf8Path::new("a.rs");
let d = make_test_description(&config, tn, p, std::io::Cursor::new(contents), None);
let d = make_test_description(&config, tn, p, p, std::io::Cursor::new(contents), None);
d.ignore
}

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

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

Expand Down
11 changes: 9 additions & 2 deletions src/tools/compiletest/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use std::num::NonZero;
use std::sync::{Arc, Mutex, mpsc};
use std::{env, hint, io, mem, panic, thread};

use camino::Utf8PathBuf;

use crate::common::{Config, TestPaths};
use crate::output_capture::{self, ConsoleOut};
use crate::panic_hook;
Expand Down Expand Up @@ -293,8 +295,12 @@ fn filter_tests(opts: &Config, tests: Vec<CollectedTest>) -> Vec<CollectedTest>
let mut filtered = tests;

let matches_filter = |test: &CollectedTest, filter_str: &str| {
let test_name = &test.desc.name;
if opts.filter_exact { test_name == filter_str } else { test_name.contains(filter_str) }
let filterable_path = test.desc.filterable_path.as_str();
if opts.filter_exact {
filterable_path == filter_str
} else {
filterable_path.contains(filter_str)
}
};

// Remove tests that don't match the test filter
Expand Down Expand Up @@ -339,6 +345,7 @@ pub(crate) struct CollectedTest {
/// Information that was historically needed to create a libtest `TestDesc`.
pub(crate) struct CollectedTestDesc {
pub(crate) name: String,
pub(crate) filterable_path: Utf8PathBuf,
pub(crate) ignore: bool,
pub(crate) ignore_message: Option<Cow<'static, str>>,
pub(crate) should_panic: ShouldPanic,
Expand Down
37 changes: 32 additions & 5 deletions src/tools/compiletest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,18 +317,30 @@ pub fn parse_config(args: Vec<String>) -> Config {
.free
.iter()
.map(|f| {
// Here `f` is relative to `./tests/run-make`. So if you run
//
// ./x test tests/run-make/crate-loading
//
// then `f` is "crate-loading".
let path = Utf8Path::new(f);
let mut iter = path.iter().skip(1);

// We skip the test folder and check if the user passed `rmake.rs`.
if iter.next().is_some_and(|s| s == "rmake.rs") && iter.next().is_none() {
// Strip the "rmake.rs" suffix. For example, if `f` is
// "crate-loading/rmake.rs" then this gives us "crate-loading".
path.parent().unwrap().to_string()
} else {
f.to_string()
}
})
.collect::<Vec<_>>()
} else {
// Note that the filters are relative to the root dir of the different test
// suites. For example, with:
//
// ./x test tests/ui/lint/unused
//
// the filter is "lint/unused".
matches.free.clone()
};
let compare_mode = matches.opt_str("compare-mode").map(|s| {
Expand Down Expand Up @@ -911,7 +923,8 @@ fn make_test(cx: &TestCollectorCx, collector: &mut TestCollector, testpaths: &Te
collector.tests.extend(revisions.into_iter().map(|revision| {
// Create a test name and description to hand over to the executor.
let src_file = fs::File::open(&test_path).expect("open test file to parse ignores");
let test_name = make_test_name(&cx.config, testpaths, revision);
let (test_name, filterable_path) =
make_test_name_and_filterable_path(&cx.config, testpaths, revision);
// Create a description struct for the test/revision.
// This is where `ignore-*`/`only-*`/`needs-*` directives are handled,
// because they historically needed to set the libtest ignored flag.
Expand All @@ -920,6 +933,7 @@ fn make_test(cx: &TestCollectorCx, collector: &mut TestCollector, testpaths: &Te
&cx.cache,
test_name,
&test_path,
&filterable_path,
src_file,
revision,
&mut collector.poisoned,
Expand Down Expand Up @@ -1072,7 +1086,11 @@ impl Stamp {
}

/// Creates a name for this test/revision that can be handed over to the executor.
fn make_test_name(config: &Config, testpaths: &TestPaths, revision: Option<&str>) -> String {
fn make_test_name_and_filterable_path(
config: &Config,
testpaths: &TestPaths,
revision: Option<&str>,
) -> (String, Utf8PathBuf) {
// Print the name of the file, relative to the sources root.
let path = testpaths.file.strip_prefix(&config.src_root).unwrap();
let debugger = match config.debugger {
Expand All @@ -1084,14 +1102,23 @@ fn make_test_name(config: &Config, testpaths: &TestPaths, revision: Option<&str>
None => String::new(),
};

format!(
let name = format!(
"[{}{}{}] {}{}",
config.mode,
debugger,
mode_suffix,
path,
revision.map_or("".to_string(), |rev| format!("#{}", rev))
)
);

// `path` is the full path from the repo root like, `tests/ui/foo/bar.rs`.
// Filtering is applied without the `tests/ui/` part, so strip that off.
// First strip off "tests" to make sure we don't have some unexpected path.
let mut filterable_path = path.strip_prefix("tests").unwrap().to_owned();
// Now strip off e.g. "ui" or "run-make" component.
filterable_path = filterable_path.components().skip(1).collect();

(name, filterable_path)
}

/// Checks that test discovery didn't find any tests whose name stem is a prefix
Expand Down
Loading
Loading