Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 21 additions & 8 deletions compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,29 @@ fn init_stack_size(early_dcx: &EarlyDiagCtxt) -> usize {
.filter(|s| !s.trim().is_empty())
// rustc is a batch program, so error early on inputs which are unlikely to be intended
// so no one thinks we parsed them setting `RUST_MIN_STACK="64 megabytes"`
// FIXME: we could accept `RUST_MIN_STACK=64MB`, perhaps?
.map(|s| {
let s = s.trim();
s.parse::<usize>().unwrap_or_else(|_| {
let mut err = early_dcx.early_struct_fatal(format!(
r#"`RUST_MIN_STACK` should be a number of bytes, but was "{s}""#,
));
err.note("you can also unset `RUST_MIN_STACK` to use the default stack size");
err.emit()
})
let pos = s.find(|c: char| !c.is_ascii_digit()).unwrap_or(s.len());
let (value, suffix) = s.split_at(pos);
if let Ok(value) = value.parse::<usize>() {
let suffix = suffix.trim();
if suffix.is_empty() {
return value;
} else if suffix.eq_ignore_ascii_case("MB")
|| suffix.eq_ignore_ascii_case("MiB")
{
if let Some(value) = value.checked_mul(1024 * 1024) {
return value;
}
}
}
let mut err = early_dcx.early_struct_fatal(format!(
r#"`RUST_MIN_STACK` should be a number of bytes, but was "{s}""#,
));
// `MiB` is the technically correct suffix so use that in the note.
err.note("the `MiB` suffix can be used to provide the number in megabytes");
err.note("you can also unset `RUST_MIN_STACK` to use the default stack size");
err.emit()
})
// otherwise pick a consistent default
.unwrap_or(DEFAULT_STACK_SIZE)
Expand Down
1 change: 1 addition & 0 deletions tests/ui/rustc-env/min-stack-banana.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
error: `RUST_MIN_STACK` should be a number of bytes, but was "banana"
|
= note: the `MiB` suffix can be used to provide the number in megabytes
= note: you can also unset `RUST_MIN_STACK` to use the default stack size

8 changes: 8 additions & 0 deletions tests/ui/rustc-env/min-stack-mib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//@ compile-flags: --crate-type rlib
//@ check-pass
//@ revisions: MB mb MiB MIB mib
//@[MB] rustc-env:RUST_MIN_STACK=16MB
//@[mb] rustc-env:RUST_MIN_STACK=16mb
//@[MiB] rustc-env:RUST_MIN_STACK=16MiB
//@[MIB] rustc-env:RUST_MIN_STACK=16MIB
//@[mib] rustc-env:RUST_MIN_STACK=16mib
Loading