Skip to content

Commit 7d9bce3

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

17 files changed

+78
-35
lines changed

compiler/rustc_middle/src/ty/structural_impls.rs

+20-6
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

+2-2
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

+2-2
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

+9-5
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

+2-2
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

+1-1
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

+3-3
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

+25-1
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

+1-1
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

+3-3
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];

src/bootstrap/setup.rs

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ static SETTINGS_HASHES: &[&str] = &[
3333
"af1b5efe196aed007577899db9dae15d6dbc923d6fa42fa0934e68617ba9bbe0",
3434
"3468fea433c25fff60be6b71e8a215a732a7b1268b6a83bf10d024344e140541",
3535
"47d227f424bf889b0d899b9cc992d5695e1b78c406e183cd78eafefbe5488923",
36+
"b526bd58d0262dd4dda2bff5bc5515b705fb668a46235ace3e057f807963a11a",
3637
];
3738
static RUST_ANALYZER_SETTINGS: &str = include_str!("../etc/rust_analyzer_settings.json");
3839

src/etc/rust_analyzer_settings.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
"compiler/rustc_codegen_gcc/Cargo.toml"
1717
],
1818
"rust-analyzer.rustfmt.overrideCommand": [
19-
"./build/host/rustfmt/bin/rustfmt",
19+
"${workspaceFolder}/build/host/rustfmt/bin/rustfmt",
2020
"--edition=2021"
2121
],
22-
"rust-analyzer.procMacro.server": "./build/host/stage0/libexec/rust-analyzer-proc-macro-srv",
22+
"rust-analyzer.procMacro.server": "${workspaceFolder}/build/host/stage0/libexec/rust-analyzer-proc-macro-srv",
2323
"rust-analyzer.procMacro.enable": true,
2424
"rust-analyzer.cargo.buildScripts.enable": true,
2525
"rust-analyzer.cargo.buildScripts.invocationLocation": "root",

tests/mir-opt/issue_99325.main.built.after.32bit.mir

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// MIR for `main` after built
22

33
| User Type Annotations
4-
| 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserArgs { args: [Const { ty: &ReStatic [u8; Const { ty: usize, kind: Leaf(0x00000004) }], kind: Branch([Leaf(0x41), Leaf(0x41), Leaf(0x41), Leaf(0x41)]) }], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:12:16: 12:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
5-
| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserArgs { args: [Const { ty: &ReStatic [u8; Const { ty: usize, kind: Leaf(0x00000004) }], kind: UnevaluatedConst { def: DefId(0:8 ~ issue_99325[22bb]::main::{constant#1}), args: [] } }], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:13:16: 13:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
4+
| 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserArgs { args: [&*b"AAAA"], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:12:16: 12:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
5+
| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserArgs { args: [UnevaluatedConst { def: DefId(0:8 ~ issue_99325[22bb]::main::{constant#1}), args: [] }: &ReStatic [u8; 4_usize]], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:13:16: 13:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
66
|
77
fn main() -> () {
88
let mut _0: ();

tests/mir-opt/issue_99325.main.built.after.64bit.mir

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// MIR for `main` after built
22

33
| User Type Annotations
4-
| 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserArgs { args: [Const { ty: &ReStatic [u8; Const { ty: usize, kind: Leaf(0x0000000000000004) }], kind: Branch([Leaf(0x41), Leaf(0x41), Leaf(0x41), Leaf(0x41)]) }], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:12:16: 12:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
5-
| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserArgs { args: [Const { ty: &ReStatic [u8; Const { ty: usize, kind: Leaf(0x0000000000000004) }], kind: UnevaluatedConst { def: DefId(0:8 ~ issue_99325[22bb]::main::{constant#1}), args: [] } }], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:13:16: 13:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
4+
| 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserArgs { args: [&*b"AAAA"], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:12:16: 12:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
5+
| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserArgs { args: [UnevaluatedConst { def: DefId(0:8 ~ issue_99325[22bb]::main::{constant#1}), args: [] }: &ReStatic [u8; 4_usize]], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:13:16: 13:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
66
|
77
fn main() -> () {
88
let mut _0: ();

tests/mir-opt/nll/region_subtyping_basic.main.nll.0.32bit.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
|
2323
fn main() -> () {
2424
let mut _0: ();
25-
let mut _1: [usize; Const { ty: usize, kind: Leaf(0x00000003) }];
25+
let mut _1: [usize; ValTree(Leaf(0x00000003): usize)];
2626
let _3: usize;
2727
let mut _4: usize;
2828
let mut _5: bool;

tests/mir-opt/nll/region_subtyping_basic.main.nll.0.64bit.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
|
2323
fn main() -> () {
2424
let mut _0: ();
25-
let mut _1: [usize; Const { ty: usize, kind: Leaf(0x0000000000000003) }];
25+
let mut _1: [usize; ValTree(Leaf(0x0000000000000003): usize)];
2626
let _3: usize;
2727
let mut _4: usize;
2828
let mut _5: bool;

tests/rustdoc-gui/search-result-color.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ assert-css: (
151151
)
152152
assert-css: (
153153
"//*[@class='result-name']//*[text()='test_docs::']/ancestor::a",
154-
{"color": "#fff", "background-color": "rgb(60, 60, 60)"},
154+
{"color": "#fff", "background-color": "#3c3c3c"},
155155
)
156156

157157
// Dark theme

0 commit comments

Comments
 (0)