Skip to content

Commit 12d757e

Browse files
committed
Auto merge of rust-lang#128319 - tgross35:rollup-ko07weh, r=tgross35
Rollup of 4 pull requests Successful merges: - rust-lang#109174 (Replace `io::Cursor::{remaining_slice, is_empty}`) - rust-lang#128147 (migrate fmt-write-bloat to rmake) - rust-lang#128182 (handle no_std targets on std builds) - rust-lang#128310 (Add missing periods on `BTreeMap` cursor `peek_next` docs) Failed merges: - rust-lang#128269 (improve cargo invocations on bootstrap) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2cbbe8b + 4f330b7 commit 12d757e

File tree

16 files changed

+157
-95
lines changed

16 files changed

+157
-95
lines changed

library/alloc/src/collections/btree/map.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2921,7 +2921,7 @@ impl<'a, K, V> Cursor<'a, K, V> {
29212921
/// Returns a reference to the key and value of the next element without
29222922
/// moving the cursor.
29232923
///
2924-
/// If the cursor is at the end of the map then `None` is returned
2924+
/// If the cursor is at the end of the map then `None` is returned.
29252925
#[unstable(feature = "btree_cursors", issue = "107540")]
29262926
pub fn peek_next(&self) -> Option<(&'a K, &'a V)> {
29272927
self.clone().next()
@@ -2963,7 +2963,7 @@ impl<'a, K, V, A> CursorMut<'a, K, V, A> {
29632963
/// Returns a reference to the key and value of the next element without
29642964
/// moving the cursor.
29652965
///
2966-
/// If the cursor is at the end of the map then `None` is returned
2966+
/// If the cursor is at the end of the map then `None` is returned.
29672967
#[unstable(feature = "btree_cursors", issue = "107540")]
29682968
pub fn peek_next(&mut self) -> Option<(&K, &mut V)> {
29692969
let (k, v) = self.inner.peek_next()?;
@@ -3061,7 +3061,7 @@ impl<'a, K, V, A> CursorMutKey<'a, K, V, A> {
30613061
/// Returns a reference to the key and value of the next element without
30623062
/// moving the cursor.
30633063
///
3064-
/// If the cursor is at the end of the map then `None` is returned
3064+
/// If the cursor is at the end of the map then `None` is returned.
30653065
#[unstable(feature = "btree_cursors", issue = "107540")]
30663066
pub fn peek_next(&mut self) -> Option<(&mut K, &mut V)> {
30673067
let current = self.current.as_mut()?;

library/std/src/io/cursor.rs

+35-30
Original file line numberDiff line numberDiff line change
@@ -210,55 +210,60 @@ impl<T> Cursor<T>
210210
where
211211
T: AsRef<[u8]>,
212212
{
213-
/// Returns the remaining slice.
213+
/// Splits the underlying slice at the cursor position and returns them.
214214
///
215215
/// # Examples
216216
///
217217
/// ```
218-
/// #![feature(cursor_remaining)]
218+
/// #![feature(cursor_split)]
219219
/// use std::io::Cursor;
220220
///
221221
/// let mut buff = Cursor::new(vec![1, 2, 3, 4, 5]);
222222
///
223-
/// assert_eq!(buff.remaining_slice(), &[1, 2, 3, 4, 5]);
223+
/// assert_eq!(buff.split(), ([].as_slice(), [1, 2, 3, 4, 5].as_slice()));
224224
///
225225
/// buff.set_position(2);
226-
/// assert_eq!(buff.remaining_slice(), &[3, 4, 5]);
227-
///
228-
/// buff.set_position(4);
229-
/// assert_eq!(buff.remaining_slice(), &[5]);
226+
/// assert_eq!(buff.split(), ([1, 2].as_slice(), [3, 4, 5].as_slice()));
230227
///
231228
/// buff.set_position(6);
232-
/// assert_eq!(buff.remaining_slice(), &[]);
229+
/// assert_eq!(buff.split(), ([1, 2, 3, 4, 5].as_slice(), [].as_slice()));
233230
/// ```
234-
#[unstable(feature = "cursor_remaining", issue = "86369")]
235-
pub fn remaining_slice(&self) -> &[u8] {
236-
let len = self.pos.min(self.inner.as_ref().len() as u64);
237-
&self.inner.as_ref()[(len as usize)..]
231+
#[unstable(feature = "cursor_split", issue = "86369")]
232+
pub fn split(&self) -> (&[u8], &[u8]) {
233+
let slice = self.inner.as_ref();
234+
let pos = self.pos.min(slice.len() as u64);
235+
slice.split_at(pos as usize)
238236
}
237+
}
239238

240-
/// Returns `true` if the remaining slice is empty.
239+
impl<T> Cursor<T>
240+
where
241+
T: AsMut<[u8]>,
242+
{
243+
/// Splits the underlying slice at the cursor position and returns them
244+
/// mutably.
241245
///
242246
/// # Examples
243247
///
244248
/// ```
245-
/// #![feature(cursor_remaining)]
249+
/// #![feature(cursor_split)]
246250
/// use std::io::Cursor;
247251
///
248252
/// let mut buff = Cursor::new(vec![1, 2, 3, 4, 5]);
249253
///
250-
/// buff.set_position(2);
251-
/// assert!(!buff.is_empty());
254+
/// assert_eq!(buff.split_mut(), ([].as_mut_slice(), [1, 2, 3, 4, 5].as_mut_slice()));
252255
///
253-
/// buff.set_position(5);
254-
/// assert!(buff.is_empty());
256+
/// buff.set_position(2);
257+
/// assert_eq!(buff.split_mut(), ([1, 2].as_mut_slice(), [3, 4, 5].as_mut_slice()));
255258
///
256-
/// buff.set_position(10);
257-
/// assert!(buff.is_empty());
259+
/// buff.set_position(6);
260+
/// assert_eq!(buff.split_mut(), ([1, 2, 3, 4, 5].as_mut_slice(), [].as_mut_slice()));
258261
/// ```
259-
#[unstable(feature = "cursor_remaining", issue = "86369")]
260-
pub fn is_empty(&self) -> bool {
261-
self.pos >= self.inner.as_ref().len() as u64
262+
#[unstable(feature = "cursor_split", issue = "86369")]
263+
pub fn split_mut(&mut self) -> (&mut [u8], &mut [u8]) {
264+
let slice = self.inner.as_mut();
265+
let pos = self.pos.min(slice.len() as u64);
266+
slice.split_at_mut(pos as usize)
262267
}
263268
}
264269

@@ -320,15 +325,15 @@ where
320325
T: AsRef<[u8]>,
321326
{
322327
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
323-
let n = Read::read(&mut self.remaining_slice(), buf)?;
328+
let n = Read::read(&mut Cursor::split(self).1, buf)?;
324329
self.pos += n as u64;
325330
Ok(n)
326331
}
327332

328333
fn read_buf(&mut self, mut cursor: BorrowedCursor<'_>) -> io::Result<()> {
329334
let prev_written = cursor.written();
330335

331-
Read::read_buf(&mut self.remaining_slice(), cursor.reborrow())?;
336+
Read::read_buf(&mut Cursor::split(self).1, cursor.reborrow())?;
332337

333338
self.pos += (cursor.written() - prev_written) as u64;
334339

@@ -352,7 +357,7 @@ where
352357
}
353358

354359
fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
355-
let result = Read::read_exact(&mut self.remaining_slice(), buf);
360+
let result = Read::read_exact(&mut Cursor::split(self).1, buf);
356361

357362
match result {
358363
Ok(_) => self.pos += buf.len() as u64,
@@ -366,14 +371,14 @@ where
366371
fn read_buf_exact(&mut self, mut cursor: BorrowedCursor<'_>) -> io::Result<()> {
367372
let prev_written = cursor.written();
368373

369-
let result = Read::read_buf_exact(&mut self.remaining_slice(), cursor.reborrow());
374+
let result = Read::read_buf_exact(&mut Cursor::split(self).1, cursor.reborrow());
370375
self.pos += (cursor.written() - prev_written) as u64;
371376

372377
result
373378
}
374379

375380
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
376-
let content = self.remaining_slice();
381+
let content = Cursor::split(self).1;
377382
let len = content.len();
378383
buf.try_reserve(len)?;
379384
buf.extend_from_slice(content);
@@ -384,7 +389,7 @@ where
384389

385390
fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
386391
let content =
387-
crate::str::from_utf8(self.remaining_slice()).map_err(|_| io::Error::INVALID_UTF8)?;
392+
crate::str::from_utf8(Cursor::split(self).1).map_err(|_| io::Error::INVALID_UTF8)?;
388393
let len = content.len();
389394
buf.try_reserve(len)?;
390395
buf.push_str(content);
@@ -400,7 +405,7 @@ where
400405
T: AsRef<[u8]>,
401406
{
402407
fn fill_buf(&mut self) -> io::Result<&[u8]> {
403-
Ok(self.remaining_slice())
408+
Ok(Cursor::split(self).1)
404409
}
405410
fn consume(&mut self, amt: usize) {
406411
self.pos += amt as u64;

library/std/src/io/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -675,13 +675,13 @@ fn cursor_read_exact_eof() {
675675

676676
let mut r = slice.clone();
677677
assert!(r.read_exact(&mut [0; 10]).is_err());
678-
assert!(r.is_empty());
678+
assert!(Cursor::split(&r).1.is_empty());
679679

680680
let mut r = slice;
681681
let buf = &mut [0; 10];
682682
let mut buf = BorrowedBuf::from(buf.as_mut_slice());
683683
assert!(r.read_buf_exact(buf.unfilled()).is_err());
684-
assert!(r.is_empty());
684+
assert!(Cursor::split(&r).1.is_empty());
685685
assert_eq!(buf.filled(), b"123456");
686686
}
687687

src/bootstrap/src/core/build_steps/check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Implementation of compiling the compiler and standard library, in "check"-based modes.
22
33
use crate::core::build_steps::compile::{
4-
add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo,
4+
add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo, std_crates_for_run_make,
55
};
66
use crate::core::build_steps::tool::{prepare_tool_cargo, SourceType};
77
use crate::core::builder::{
@@ -47,7 +47,7 @@ impl Step for Std {
4747
}
4848

4949
fn make_run(run: RunConfig<'_>) {
50-
let crates = run.make_run_crates(Alias::Library);
50+
let crates = std_crates_for_run_make(&run);
5151
run.builder.ensure(Std { target: run.target, crates });
5252
}
5353

src/bootstrap/src/core/build_steps/clippy.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use super::compile::libstd_stamp;
1919
use super::compile::run_cargo;
2020
use super::compile::rustc_cargo;
2121
use super::compile::std_cargo;
22+
use super::compile::std_crates_for_run_make;
2223
use super::tool::prepare_tool_cargo;
2324
use super::tool::SourceType;
2425

@@ -120,7 +121,7 @@ impl Step for Std {
120121
}
121122

122123
fn make_run(run: RunConfig<'_>) {
123-
let crates = run.make_run_crates(Alias::Library);
124+
let crates = std_crates_for_run_make(&run);
124125
run.builder.ensure(Std { target: run.target, crates });
125126
}
126127

src/bootstrap/src/core/build_steps/compile.rs

+23-5
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,7 @@ impl Step for Std {
127127
}
128128

129129
fn make_run(run: RunConfig<'_>) {
130-
// If the paths include "library", build the entire standard library.
131-
let has_alias =
132-
run.paths.iter().any(|set| set.assert_single_path().path.ends_with("library"));
133-
let crates = if has_alias { Default::default() } else { run.cargo_crates_in_set() };
134-
130+
let crates = std_crates_for_run_make(&run);
135131
run.builder.ensure(Std {
136132
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()),
137133
target: run.target,
@@ -429,6 +425,28 @@ fn copy_self_contained_objects(
429425
target_deps
430426
}
431427

428+
/// Resolves standard library crates for `Std::run_make` for any build kind (like check, build, clippy, etc.).
429+
pub fn std_crates_for_run_make(run: &RunConfig<'_>) -> Vec<String> {
430+
// FIXME: Extend builder tests to cover the `crates` field of `Std` instances.
431+
if cfg!(feature = "bootstrap-self-test") {
432+
return vec![];
433+
}
434+
435+
let has_alias = run.paths.iter().any(|set| set.assert_single_path().path.ends_with("library"));
436+
let target_is_no_std = run.builder.no_std(run.target).unwrap_or(false);
437+
438+
// For no_std targets, do not add any additional crates to the compilation other than what `compile::std_cargo` already adds for no_std targets.
439+
if target_is_no_std {
440+
vec![]
441+
}
442+
// If the paths include "library", build the entire standard library.
443+
else if has_alias {
444+
run.make_run_crates(builder::Alias::Library)
445+
} else {
446+
run.cargo_crates_in_set()
447+
}
448+
}
449+
432450
/// Configure cargo to compile the standard library, adding appropriate env vars
433451
/// and such.
434452
pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, cargo: &mut Cargo) {

src/bootstrap/src/core/build_steps/dist.rs

-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ impl Step for JsonDocs {
108108
builder.ensure(crate::core::build_steps::doc::Std::new(
109109
builder.top_stage,
110110
host,
111-
builder,
112111
DocumentationFormat::Json,
113112
));
114113

src/bootstrap/src/core/build_steps/doc.rs

+4-20
Original file line numberDiff line numberDiff line change
@@ -563,18 +563,8 @@ pub struct Std {
563563
}
564564

565565
impl Std {
566-
pub(crate) fn new(
567-
stage: u32,
568-
target: TargetSelection,
569-
builder: &Builder<'_>,
570-
format: DocumentationFormat,
571-
) -> Self {
572-
let crates = builder
573-
.in_tree_crates("sysroot", Some(target))
574-
.into_iter()
575-
.map(|krate| krate.name.to_string())
576-
.collect();
577-
Std { stage, target, format, crates }
566+
pub(crate) fn new(stage: u32, target: TargetSelection, format: DocumentationFormat) -> Self {
567+
Std { stage, target, format, crates: vec![] }
578568
}
579569
}
580570

@@ -588,6 +578,7 @@ impl Step for Std {
588578
}
589579

590580
fn make_run(run: RunConfig<'_>) {
581+
let crates = compile::std_crates_for_run_make(&run);
591582
run.builder.ensure(Std {
592583
stage: run.builder.top_stage,
593584
target: run.target,
@@ -596,7 +587,7 @@ impl Step for Std {
596587
} else {
597588
DocumentationFormat::Html
598589
},
599-
crates: run.make_run_crates(Alias::Library),
590+
crates,
600591
});
601592
}
602593

@@ -694,13 +685,6 @@ fn doc_std(
694685
extra_args: &[&str],
695686
requested_crates: &[String],
696687
) {
697-
if builder.no_std(target) == Some(true) {
698-
panic!(
699-
"building std documentation for no_std target {target} is not supported\n\
700-
Set `docs = false` in the config to disable documentation, or pass `--skip library`."
701-
);
702-
}
703-
704688
let compiler = builder.compiler(stage, builder.config.build);
705689

706690
let target_doc_dir_name = if format == DocumentationFormat::Json { "json-doc" } else { "doc" };

src/bootstrap/src/core/build_steps/test.rs

-1
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,6 @@ impl Step for RustdocJSStd {
852852
builder.ensure(crate::core::build_steps::doc::Std::new(
853853
builder.top_stage,
854854
self.target,
855-
builder,
856855
DocumentationFormat::Html,
857856
));
858857
let _guard = builder.msg(

src/bootstrap/src/core/builder/tests.rs

-4
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,9 @@ macro_rules! std {
7878

7979
macro_rules! doc_std {
8080
($host:ident => $target:ident, stage = $stage:literal) => {{
81-
let config = configure("doc", &["A-A"], &["A-A"]);
82-
let build = Build::new(config);
83-
let builder = Builder::new(&build);
8481
doc::Std::new(
8582
$stage,
8683
TargetSelection::from_user(concat!(stringify!($target), "-", stringify!($target))),
87-
&builder,
8884
DocumentationFormat::Html,
8985
)
9086
}};

src/tools/run-make-support/src/env.rs

+7
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@ pub fn env_var_os(name: &str) -> OsString {
1717
None => panic!("failed to retrieve environment variable {name:?}"),
1818
}
1919
}
20+
21+
/// Check if `NO_DEBUG_ASSERTIONS` is set (usually this may be set in CI jobs).
22+
#[track_caller]
23+
#[must_use]
24+
pub fn no_debug_assertions() -> bool {
25+
std::env::var_os("NO_DEBUG_ASSERTIONS").is_some()
26+
}

src/tools/run-make-support/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub mod run;
2121
pub mod scoped_run;
2222
pub mod string;
2323
pub mod targets;
24+
pub mod symbols;
2425

2526
// Internally we call our fs-related support module as `fs`, but re-export its content as `rfs`
2627
// to tests to avoid colliding with commonly used `use std::fs;`.

0 commit comments

Comments
 (0)