Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 7d9bce3

Browse files
committed
Auto merge of rust-lang#115900 - matthiaskrgr:rollup-3ba15da, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#115247 (Document std limitations before/after main) - rust-lang#115329 (fix std::primitive doc: homogenous -> homogeneous) - rust-lang#115487 (Improve documentation on when signes are printed by default) - rust-lang#115560 (Update doc for `alloc::format!` and `core::concat!`) - rust-lang#115836 (update rust_analyzer_settings.json) - rust-lang#115884 (make ty::Const debug printing less verbose) - rust-lang#115890 (Migrate GUI colors test to original CSS color format) - rust-lang#115895 (Improve Vec(Deque)::truncate documentation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 341ef15 + e2ea347 commit 7d9bce3

File tree

17 files changed

+78
-35
lines changed

17 files changed

+78
-35
lines changed

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use std::ops::ControlFlow;
1818
use std::rc::Rc;
1919
use std::sync::Arc;
2020

21+
use super::print::PrettyPrinter;
2122
use super::{GenericArg, GenericArgKind, Region};
2223

2324
impl fmt::Debug for ty::TraitDef {
@@ -343,14 +344,27 @@ impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::Const<'tcx> {
343344
this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
344345
f: &mut core::fmt::Formatter<'_>,
345346
) -> core::fmt::Result {
346-
// This reflects what `Const` looked liked before `Interned` was
347-
// introduced. We print it like this to avoid having to update expected
348-
// output in a lot of tests.
347+
// If this is a value, we spend some effort to make it look nice.
348+
if let ConstKind::Value(_) = this.data.kind() {
349+
return ty::tls::with(move |tcx| {
350+
// Somehow trying to lift the valtree results in lifetime errors, so we lift the
351+
// entire constant.
352+
let lifted = tcx.lift(*this.data).unwrap();
353+
let ConstKind::Value(valtree) = lifted.kind() else {
354+
bug!("we checked that this is a valtree")
355+
};
356+
let cx = FmtPrinter::new(tcx, Namespace::ValueNS);
357+
let cx =
358+
cx.pretty_print_const_valtree(valtree, lifted.ty(), /*print_ty*/ true)?;
359+
f.write_str(&cx.into_buffer())
360+
});
361+
}
362+
// Fall back to something verbose.
349363
write!(
350364
f,
351-
"Const {{ ty: {:?}, kind: {:?} }}",
352-
&this.map(|data| data.ty()),
353-
&this.map(|data| data.kind())
365+
"{kind:?}: {ty:?}",
366+
ty = &this.map(|data| data.ty()),
367+
kind = &this.map(|data| data.kind())
354368
)
355369
}
356370
}

library/alloc/src/collections/vec_deque/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,8 +1015,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
10151015
/// Shortens the deque, keeping the first `len` elements and dropping
10161016
/// the rest.
10171017
///
1018-
/// If `len` is greater than the deque's current length, this has no
1019-
/// effect.
1018+
/// If `len` is greater or equal to the deque's current length, this has
1019+
/// no effect.
10201020
///
10211021
/// # Examples
10221022
///

library/alloc/src/fmt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@
177177
//! These are all flags altering the behavior of the formatter.
178178
//!
179179
//! * `+` - This is intended for numeric types and indicates that the sign
180-
//! should always be printed. Positive signs are never printed by
181-
//! default, and the negative sign is only printed by default for signed values.
180+
//! should always be printed. By default only the negative sign of signed values
181+
//! is printed, and the sign of positive or unsigned values is omitted.
182182
//! This flag indicates that the correct sign (`+` or `-`) should always be printed.
183183
//! * `-` - Currently not used
184184
//! * `#` - This flag indicates that the "alternate" form of printing should

library/alloc/src/macros.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,19 @@ macro_rules! vec {
8888
///
8989
/// A common use for `format!` is concatenation and interpolation of strings.
9090
/// The same convention is used with [`print!`] and [`write!`] macros,
91-
/// depending on the intended destination of the string.
91+
/// depending on the intended destination of the string; all these macros internally use [`format_args!`].
9292
///
9393
/// To convert a single value to a string, use the [`to_string`] method. This
9494
/// will use the [`Display`] formatting trait.
9595
///
96+
/// To concatenate literals into a `&'static str`, use the [`concat!`] macro.
97+
///
9698
/// [`print!`]: ../std/macro.print.html
9799
/// [`write!`]: core::write
100+
/// [`format_args!`]: core::format_args
98101
/// [`to_string`]: crate::string::ToString
99102
/// [`Display`]: core::fmt::Display
103+
/// [`concat!`]: core::concat
100104
///
101105
/// # Panics
102106
///
@@ -107,11 +111,11 @@ macro_rules! vec {
107111
/// # Examples
108112
///
109113
/// ```
110-
/// format!("test");
111-
/// format!("hello {}", "world!");
112-
/// format!("x = {}, y = {y}", 10, y = 30);
114+
/// format!("test"); // => "test"
115+
/// format!("hello {}", "world!"); // => "hello world!"
116+
/// format!("x = {}, y = {val}", 10, val = 30); // => "x = 10, y = 30"
113117
/// let (x, y) = (1, 2);
114-
/// format!("{x} + {y} = 3");
118+
/// format!("{x} + {y} = 3"); // => "1 + 2 = 3"
115119
/// ```
116120
#[macro_export]
117121
#[stable(feature = "rust1", since = "1.0.0")]

library/alloc/src/vec/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,8 +1110,8 @@ impl<T, A: Allocator> Vec<T, A> {
11101110
/// Shortens the vector, keeping the first `len` elements and dropping
11111111
/// the rest.
11121112
///
1113-
/// If `len` is greater than the vector's current length, this has no
1114-
/// effect.
1113+
/// If `len` is greater or equal to the vector's current length, this has
1114+
/// no effect.
11151115
///
11161116
/// The [`drain`] method can emulate `truncate`, but causes the excess
11171117
/// elements to be returned instead of dropped.

library/core/src/macros/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ pub(crate) mod builtin {
10441044
/// expression of type `&'static str` which represents all of the literals
10451045
/// concatenated left-to-right.
10461046
///
1047-
/// Integer and floating point literals are stringified in order to be
1047+
/// Integer and floating point literals are [stringified](core::stringify) in order to be
10481048
/// concatenated.
10491049
///
10501050
/// # Examples

library/core/src/primitive_docs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ mod prim_pointer {}
612612
/// statically generated up to size 32.
613613
///
614614
/// Arrays of sizes from 1 to 12 (inclusive) implement [`From<Tuple>`], where `Tuple`
615-
/// is a homogenous [prim@tuple] of appropriate length.
615+
/// is a homogeneous [prim@tuple] of appropriate length.
616616
///
617617
/// Arrays coerce to [slices (`[T]`)][slice], so a slice method may be called on
618618
/// an array. Indeed, this provides most of the API for working with arrays.
@@ -676,7 +676,7 @@ mod prim_pointer {}
676676
/// move_away(roa);
677677
/// ```
678678
///
679-
/// Arrays can be created from homogenous tuples of appropriate length:
679+
/// Arrays can be created from homogeneous tuples of appropriate length:
680680
///
681681
/// ```
682682
/// let tuple: (u32, u32, u32) = (1, 2, 3);
@@ -1065,7 +1065,7 @@ mod prim_str {}
10651065
/// assert_eq!(y, 5);
10661066
/// ```
10671067
///
1068-
/// Homogenous tuples can be created from arrays of appropriate length:
1068+
/// Homogeneous tuples can be created from arrays of appropriate length:
10691069
///
10701070
/// ```
10711071
/// let array: [u32; 3] = [1, 2, 3];

library/std/src/lib.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,31 @@
152152
//! contains further primitive shared memory types, including [`atomic`] and
153153
//! [`mpsc`], which contains the channel types for message passing.
154154
//!
155+
//! # Use before and after `main()`
156+
//!
157+
//! Many parts of the standard library are expected to work before and after `main()`;
158+
//! but this is not guaranteed or ensured by tests. It is recommended that you write your own tests
159+
//! and run them on each platform you wish to support.
160+
//! This means that use of `std` before/after main, especially of features that interact with the
161+
//! OS or global state, is exempted from stability and portability guarantees and instead only
162+
//! provided on a best-effort basis. Nevertheless bug reports are appreciated.
163+
//!
164+
//! On the other hand `core` and `alloc` are most likely to work in such environments with
165+
//! the caveat that any hookable behavior such as panics, oom handling or allocators will also
166+
//! depend on the compatibility of the hooks.
167+
//!
168+
//! Some features may also behave differently outside main, e.g. stdio could become unbuffered,
169+
//! some panics might turn into aborts, backtraces might not get symbolicated or similar.
170+
//!
171+
//! Non-exhaustive list of known limitations:
172+
//!
173+
//! - after-main use of thread-locals, which also affects additional features:
174+
//! - [`thread::current()`]
175+
//! - [`thread::scope()`]
176+
//! - [`sync::mpsc`]
177+
//! - before-main stdio file descriptors are not guaranteed to be open on unix platforms
178+
//!
179+
//!
155180
//! [I/O]: io
156181
//! [`MIN`]: i32::MIN
157182
//! [`MAX`]: i32::MAX
@@ -187,7 +212,6 @@
187212
//! [rust-discord]: https://discord.gg/rust-lang
188213
//! [array]: prim@array
189214
//! [slice]: prim@slice
190-
191215
// To run std tests without x.py without ending up with two copies of std, Miri needs to be
192216
// able to "empty" this crate. See <https://github.com/rust-lang/miri-test-libstd/issues/4>.
193217
// rustc itself never sets the feature, so this line has no effect there.

library/std/src/os/unix/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub trait FileExt {
155155
/// flag fail to respect the offset parameter, always appending to the end
156156
/// of the file instead.
157157
///
158-
/// It is possible to inadvertantly set this flag, like in the example below.
158+
/// It is possible to inadvertently set this flag, like in the example below.
159159
/// Therefore, it is important to be vigilant while changing options to mitigate
160160
/// unexpected behaviour.
161161
///

library/std/src/primitive_docs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ mod prim_pointer {}
612612
/// statically generated up to size 32.
613613
///
614614
/// Arrays of sizes from 1 to 12 (inclusive) implement [`From<Tuple>`], where `Tuple`
615-
/// is a homogenous [prim@tuple] of appropriate length.
615+
/// is a homogeneous [prim@tuple] of appropriate length.
616616
///
617617
/// Arrays coerce to [slices (`[T]`)][slice], so a slice method may be called on
618618
/// an array. Indeed, this provides most of the API for working with arrays.
@@ -676,7 +676,7 @@ mod prim_pointer {}
676676
/// move_away(roa);
677677
/// ```
678678
///
679-
/// Arrays can be created from homogenous tuples of appropriate length:
679+
/// Arrays can be created from homogeneous tuples of appropriate length:
680680
///
681681
/// ```
682682
/// let tuple: (u32, u32, u32) = (1, 2, 3);
@@ -1065,7 +1065,7 @@ mod prim_str {}
10651065
/// assert_eq!(y, 5);
10661066
/// ```
10671067
///
1068-
/// Homogenous tuples can be created from arrays of appropriate length:
1068+
/// Homogeneous tuples can be created from arrays of appropriate length:
10691069
///
10701070
/// ```
10711071
/// let array: [u32; 3] = [1, 2, 3];

0 commit comments

Comments
 (0)