Skip to content

Commit ff7906b

Browse files
committed
Auto merge of #134096 - fmease:rollup-0asgoo8, r=fmease
Rollup of 9 pull requests Successful merges: - #133996 (Move most tests for `-l` and `#[link(..)]` into `tests/ui/link-native-libs`) - #134012 (Grammar fixes) - #134032 (docs: better examples for `std::ops::ControlFlow`) - #134040 (bootstrap: print{ln}! -> eprint{ln}! (take 2)) - #134043 (Add test to check unicode identifier version) - #134053 (rustdoc: rename `issue-\d+.rs` tests to have meaningful names (part 10)) - #134055 (interpret: clean up deduplicating allocation functions) - #134073 (dataflow_const_prop: do not eval a ptr address in SwitchInt) - #134084 (Fix typo in RFC mention 3598 -> 3593) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 974ccc1 + 5a33ab0 commit ff7906b

File tree

125 files changed

+412
-465
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+412
-465
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ standard library, and documentation.
2121

2222
## Why Rust?
2323

24-
- **Performance:** Fast and memory-efficient, suitable for critical services, embedded devices, and easily integrate with other languages.
24+
- **Performance:** Fast and memory-efficient, suitable for critical services, embedded devices, and easily integrated with other languages.
2525

2626
- **Reliability:** Our rich type system and ownership model ensure memory and thread safety, reducing bugs at compile-time.
2727

compiler/rustc_const_eval/src/interpret/place.rs

+17-27
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
use std::assert_matches::assert_matches;
66

77
use either::{Either, Left, Right};
8-
use rustc_abi::{Align, BackendRepr, HasDataLayout, Size};
9-
use rustc_ast::Mutability;
8+
use rustc_abi::{BackendRepr, HasDataLayout, Size};
109
use rustc_middle::ty::Ty;
1110
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
1211
use rustc_middle::{bug, mir, span_bug};
@@ -1018,40 +1017,31 @@ where
10181017
self.allocate_dyn(layout, kind, MemPlaceMeta::None)
10191018
}
10201019

1021-
/// Allocates a sequence of bytes in the interpreter's memory.
1022-
/// For immutable allocations, uses deduplication to reuse existing memory.
1023-
/// For mutable allocations, creates a new unique allocation.
1024-
pub fn allocate_bytes(
1020+
/// Allocates a sequence of bytes in the interpreter's memory with alignment 1.
1021+
/// This is allocated in immutable global memory and deduplicated.
1022+
pub fn allocate_bytes_dedup(
10251023
&mut self,
10261024
bytes: &[u8],
1027-
align: Align,
1028-
kind: MemoryKind<M::MemoryKind>,
1029-
mutbl: Mutability,
10301025
) -> InterpResult<'tcx, Pointer<M::Provenance>> {
1031-
// Use cache for immutable strings.
1032-
if mutbl.is_not() {
1033-
// Use dedup'd allocation function.
1034-
let salt = M::get_global_alloc_salt(self, None);
1035-
let id = self.tcx.allocate_bytes_dedup(bytes, salt);
1036-
1037-
// Turn untagged "global" pointers (obtained via `tcx`) into the machine pointer to the allocation.
1038-
M::adjust_alloc_root_pointer(&self, Pointer::from(id), Some(kind))
1039-
} else {
1040-
// Allocate new memory for mutable data.
1041-
self.allocate_bytes_ptr(bytes, align, kind, mutbl)
1042-
}
1026+
let salt = M::get_global_alloc_salt(self, None);
1027+
let id = self.tcx.allocate_bytes_dedup(bytes, salt);
1028+
1029+
// Turn untagged "global" pointers (obtained via `tcx`) into the machine pointer to the allocation.
1030+
M::adjust_alloc_root_pointer(
1031+
&self,
1032+
Pointer::from(id),
1033+
M::GLOBAL_KIND.map(MemoryKind::Machine),
1034+
)
10431035
}
10441036

1045-
/// Allocates a string in the interpreter's memory with metadata for length.
1046-
/// Uses `allocate_bytes` internally but adds string-specific metadata handling.
1047-
pub fn allocate_str(
1037+
/// Allocates a string in the interpreter's memory, returning it as a (wide) place.
1038+
/// This is allocated in immutable global memory and deduplicated.
1039+
pub fn allocate_str_dedup(
10481040
&mut self,
10491041
str: &str,
1050-
kind: MemoryKind<M::MemoryKind>,
1051-
mutbl: Mutability,
10521042
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {
10531043
let bytes = str.as_bytes();
1054-
let ptr = self.allocate_bytes(bytes, Align::ONE, kind, mutbl)?;
1044+
let ptr = self.allocate_bytes_dedup(bytes)?;
10551045

10561046
// Create length metadata for the string.
10571047
let meta = Scalar::from_target_usize(u64::try_from(bytes.len()).unwrap(), self);

compiler/rustc_const_eval/src/util/caller_location.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_hir::LangItem;
22
use rustc_middle::query::TyCtxtAt;
33
use rustc_middle::ty::layout::LayoutOf;
4-
use rustc_middle::ty::{self, Mutability};
4+
use rustc_middle::ty::{self};
55
use rustc_middle::{bug, mir};
66
use rustc_span::symbol::Symbol;
77
use tracing::trace;
@@ -20,12 +20,9 @@ fn alloc_caller_location<'tcx>(
2020
// This can fail if rustc runs out of memory right here. Trying to emit an error would be
2121
// pointless, since that would require allocating more memory than these short strings.
2222
let file = if loc_details.file {
23-
ecx.allocate_str(filename.as_str(), MemoryKind::CallerLocation, Mutability::Not).unwrap()
23+
ecx.allocate_str_dedup(filename.as_str()).unwrap()
2424
} else {
25-
// FIXME: This creates a new allocation each time. It might be preferable to
26-
// perform this allocation only once, and re-use the `MPlaceTy`.
27-
// See https://github.com/rust-lang/rust/pull/89920#discussion_r730012398
28-
ecx.allocate_str("<redacted>", MemoryKind::CallerLocation, Mutability::Not).unwrap()
25+
ecx.allocate_str_dedup("<redacted>").unwrap()
2926
};
3027
let file = file.map_provenance(CtfeProvenance::as_immutable);
3128
let line = if loc_details.line { Scalar::from_u32(line) } else { Scalar::from_u32(0) };

compiler/rustc_lexer/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub mod unescape;
3333
mod tests;
3434

3535
use unicode_properties::UnicodeEmoji;
36+
pub use unicode_xid::UNICODE_VERSION as UNICODE_XID_VERSION;
3637

3738
use self::LiteralKind::*;
3839
use self::TokenKind::*;

compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1479,7 +1479,7 @@ impl<'tcx> TyCtxt<'tcx> {
14791479
self.mk_adt_def_from_data(ty::AdtDefData::new(self, did, kind, variants, repr))
14801480
}
14811481

1482-
/// Allocates a read-only byte or string literal for `mir::interpret`.
1482+
/// Allocates a read-only byte or string literal for `mir::interpret` with alignment 1.
14831483
/// Returns the same `AllocId` if called again with the same bytes.
14841484
pub fn allocate_bytes_dedup(self, bytes: &[u8], salt: usize) -> interpret::AllocId {
14851485
// Create an allocation that just contains these bytes.

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,13 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> {
534534
// This allows the set of visited edges to grow monotonically with the lattice.
535535
FlatSet::Bottom => TerminatorEdges::None,
536536
FlatSet::Elem(scalar) => {
537-
let choice = scalar.assert_scalar_int().to_bits_unchecked();
538-
TerminatorEdges::Single(targets.target_for_value(choice))
537+
if let Ok(scalar_int) = scalar.try_to_scalar_int() {
538+
TerminatorEdges::Single(
539+
targets.target_for_value(scalar_int.to_bits_unchecked()),
540+
)
541+
} else {
542+
TerminatorEdges::SwitchInt { discr, targets }
543+
}
539544
}
540545
FlatSet::Top => TerminatorEdges::SwitchInt { discr, targets },
541546
}

compiler/rustc_parse/src/lexer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
822822

823823
/// Detect guarded string literal syntax
824824
///
825-
/// RFC 3598 reserved this syntax for future use. As of Rust 2024,
825+
/// RFC 3593 reserved this syntax for future use. As of Rust 2024,
826826
/// using this syntax produces an error. In earlier editions, however, it
827827
/// only results in an (allowed by default) lint, and is treated as
828828
/// separate tokens.

compiler/rustc_parse/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use rustc_data_structures::sync::Lrc;
2424
use rustc_errors::{Diag, FatalError, PResult};
2525
use rustc_session::parse::ParseSess;
2626
use rustc_span::{FileName, SourceFile, Span};
27+
pub use unicode_normalization::UNICODE_VERSION as UNICODE_NORMALIZATION_VERSION;
2728

2829
pub const MACRO_ARGUMENTS: Option<&str> = Some("macro arguments");
2930

library/core/src/ops/control_flow.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ impl<B, C> ControlFlow<B, C> {
141141
/// ```
142142
/// use std::ops::ControlFlow;
143143
///
144-
/// assert!(ControlFlow::<i32, String>::Break(3).is_break());
145-
/// assert!(!ControlFlow::<String, i32>::Continue(3).is_break());
144+
/// assert!(ControlFlow::<&str, i32>::Break("Stop right there!").is_break());
145+
/// assert!(!ControlFlow::<&str, i32>::Continue(3).is_break());
146146
/// ```
147147
#[inline]
148148
#[stable(feature = "control_flow_enum_is", since = "1.59.0")]
@@ -157,8 +157,8 @@ impl<B, C> ControlFlow<B, C> {
157157
/// ```
158158
/// use std::ops::ControlFlow;
159159
///
160-
/// assert!(!ControlFlow::<i32, String>::Break(3).is_continue());
161-
/// assert!(ControlFlow::<String, i32>::Continue(3).is_continue());
160+
/// assert!(!ControlFlow::<&str, i32>::Break("Stop right there!").is_continue());
161+
/// assert!(ControlFlow::<&str, i32>::Continue(3).is_continue());
162162
/// ```
163163
#[inline]
164164
#[stable(feature = "control_flow_enum_is", since = "1.59.0")]
@@ -174,8 +174,8 @@ impl<B, C> ControlFlow<B, C> {
174174
/// ```
175175
/// use std::ops::ControlFlow;
176176
///
177-
/// assert_eq!(ControlFlow::<i32, String>::Break(3).break_value(), Some(3));
178-
/// assert_eq!(ControlFlow::<String, i32>::Continue(3).break_value(), None);
177+
/// assert_eq!(ControlFlow::<&str, i32>::Break("Stop right there!").break_value(), Some("Stop right there!"));
178+
/// assert_eq!(ControlFlow::<&str, i32>::Continue(3).break_value(), None);
179179
/// ```
180180
#[inline]
181181
#[stable(feature = "control_flow_enum", since = "1.83.0")]
@@ -205,8 +205,8 @@ impl<B, C> ControlFlow<B, C> {
205205
/// ```
206206
/// use std::ops::ControlFlow;
207207
///
208-
/// assert_eq!(ControlFlow::<i32, String>::Break(3).continue_value(), None);
209-
/// assert_eq!(ControlFlow::<String, i32>::Continue(3).continue_value(), Some(3));
208+
/// assert_eq!(ControlFlow::<&str, i32>::Break("Stop right there!").continue_value(), None);
209+
/// assert_eq!(ControlFlow::<&str, i32>::Continue(3).continue_value(), Some(3));
210210
/// ```
211211
#[inline]
212212
#[stable(feature = "control_flow_enum", since = "1.83.0")]

src/bootstrap/src/bin/main.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ fn main() {
4848
err => {
4949
drop(err);
5050
if let Ok(pid) = pid {
51-
println!("WARNING: build directory locked by process {pid}, waiting for lock");
51+
eprintln!("WARNING: build directory locked by process {pid}, waiting for lock");
5252
} else {
53-
println!("WARNING: build directory locked, waiting for lock");
53+
eprintln!("WARNING: build directory locked, waiting for lock");
5454
}
5555
let mut lock = t!(build_lock.write());
5656
t!(lock.write(process::id().to_string().as_ref()));
@@ -70,13 +70,13 @@ fn main() {
7070
// changelog warning, not the `x.py setup` message.
7171
let suggest_setup = config.config.is_none() && !matches!(config.cmd, Subcommand::Setup { .. });
7272
if suggest_setup {
73-
println!("WARNING: you have not made a `config.toml`");
74-
println!(
73+
eprintln!("WARNING: you have not made a `config.toml`");
74+
eprintln!(
7575
"HELP: consider running `./x.py setup` or copying `config.example.toml` by running \
7676
`cp config.example.toml config.toml`"
7777
);
7878
} else if let Some(suggestion) = &changelog_suggestion {
79-
println!("{suggestion}");
79+
eprintln!("{suggestion}");
8080
}
8181

8282
let pre_commit = config.src.join(".git").join("hooks").join("pre-commit");
@@ -86,13 +86,13 @@ fn main() {
8686
Build::new(config).build();
8787

8888
if suggest_setup {
89-
println!("WARNING: you have not made a `config.toml`");
90-
println!(
89+
eprintln!("WARNING: you have not made a `config.toml`");
90+
eprintln!(
9191
"HELP: consider running `./x.py setup` or copying `config.example.toml` by running \
9292
`cp config.example.toml config.toml`"
9393
);
9494
} else if let Some(suggestion) = &changelog_suggestion {
95-
println!("{suggestion}");
95+
eprintln!("{suggestion}");
9696
}
9797

9898
// Give a warning if the pre-commit script is in pre-commit and not pre-push.
@@ -102,14 +102,14 @@ fn main() {
102102
if fs::read_to_string(pre_commit).is_ok_and(|contents| {
103103
contents.contains("https://github.com/rust-lang/rust/issues/77620#issuecomment-705144570")
104104
}) {
105-
println!(
105+
eprintln!(
106106
"WARNING: You have the pre-push script installed to .git/hooks/pre-commit. \
107107
Consider moving it to .git/hooks/pre-push instead, which runs less often."
108108
);
109109
}
110110

111111
if suggest_setup || changelog_suggestion.is_some() {
112-
println!("NOTE: this message was printed twice to make it more likely to be seen");
112+
eprintln!("NOTE: this message was printed twice to make it more likely to be seen");
113113
}
114114

115115
if dump_bootstrap_shims {

src/bootstrap/src/bin/rustc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ fn main() {
306306
// should run on success, after this block.
307307
}
308308
if verbose > 0 {
309-
println!("\nDid not run successfully: {status}\n{cmd:?}\n-------------");
309+
eprintln!("\nDid not run successfully: {status}\n{cmd:?}\n-------------");
310310
}
311311

312312
if let Some(mut on_fail) = on_fail {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl Step for CodegenBackend {
287287
fn run(self, builder: &Builder<'_>) {
288288
// FIXME: remove once https://github.com/rust-lang/rust/issues/112393 is resolved
289289
if builder.build.config.vendor && self.backend == "gcc" {
290-
println!("Skipping checking of `rustc_codegen_gcc` with vendoring enabled.");
290+
eprintln!("Skipping checking of `rustc_codegen_gcc` with vendoring enabled.");
291291
return;
292292
}
293293

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,7 @@ impl Step for Sysroot {
16111611
let sysroot = sysroot_dir(compiler.stage);
16121612

16131613
builder
1614-
.verbose(|| println!("Removing sysroot {} to avoid caching bugs", sysroot.display()));
1614+
.verbose(|| eprintln!("Removing sysroot {} to avoid caching bugs", sysroot.display()));
16151615
let _ = fs::remove_dir_all(&sysroot);
16161616
t!(fs::create_dir_all(&sysroot));
16171617

@@ -1681,7 +1681,7 @@ impl Step for Sysroot {
16811681
return true;
16821682
}
16831683
if !filtered_files.iter().all(|f| f != path.file_name().unwrap()) {
1684-
builder.verbose_than(1, || println!("ignoring {}", path.display()));
1684+
builder.verbose_than(1, || eprintln!("ignoring {}", path.display()));
16851685
false
16861686
} else {
16871687
true
@@ -2240,7 +2240,7 @@ pub fn stream_cargo(
22402240
cargo.arg(arg);
22412241
}
22422242

2243-
builder.verbose(|| println!("running: {cargo:?}"));
2243+
builder.verbose(|| eprintln!("running: {cargo:?}"));
22442244

22452245
if builder.config.dry_run() {
22462246
return true;
@@ -2261,12 +2261,12 @@ pub fn stream_cargo(
22612261
Ok(msg) => {
22622262
if builder.config.json_output {
22632263
// Forward JSON to stdout.
2264-
println!("{line}");
2264+
eprintln!("{line}");
22652265
}
22662266
cb(msg)
22672267
}
22682268
// If this was informational, just print it out and continue
2269-
Err(_) => println!("{line}"),
2269+
Err(_) => eprintln!("{line}"),
22702270
}
22712271
}
22722272

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2080,7 +2080,7 @@ fn maybe_install_llvm(
20802080
{
20812081
let mut cmd = command(llvm_config);
20822082
cmd.arg("--libfiles");
2083-
builder.verbose(|| println!("running {cmd:?}"));
2083+
builder.verbose(|| eprintln!("running {cmd:?}"));
20842084
let files = cmd.run_capture_stdout(builder).stdout();
20852085
let build_llvm_out = &builder.llvm_out(builder.config.build);
20862086
let target_llvm_out = &builder.llvm_out(target);

src/bootstrap/src/core/build_steps/format.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ fn print_paths(verb: &str, adjective: Option<&str>, paths: &[String]) {
107107
if let Some(adjective) = adjective { format!("{adjective} ") } else { String::new() };
108108
if len <= 10 {
109109
for path in paths {
110-
println!("fmt: {verb} {adjective}file {path}");
110+
eprintln!("fmt: {verb} {adjective}file {path}");
111111
}
112112
} else {
113-
println!("fmt: {verb} {len} {adjective}files");
113+
eprintln!("fmt: {verb} {len} {adjective}files");
114114
}
115115
}
116116

@@ -199,7 +199,7 @@ pub fn format(build: &Builder<'_>, check: bool, all: bool, paths: &[PathBuf]) {
199199
match get_modified_rs_files(build) {
200200
Ok(Some(files)) => {
201201
if files.is_empty() {
202-
println!("fmt info: No modified files detected for formatting.");
202+
eprintln!("fmt info: No modified files detected for formatting.");
203203
return;
204204
}
205205

0 commit comments

Comments
 (0)