Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #122190

Merged
merged 20 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift click to select a range
e760c44
Use `ControlFlow` in AST visitors.
Jarcho Feb 24, 2024
822b10d
Use `ControlFlow` in HIR visitors
Jarcho Feb 24, 2024
63091b1
Make `arg_expand_all` not short-circuit on first error
beetrees May 15, 2023
fb87e60
Refactor argument UTF-8 checking into `rustc_driver::args::raw_args()`
beetrees May 15, 2023
d626d13
Use `rustc_driver::args::raw_args()` in Clippy
beetrees May 15, 2023
2d7d0bd
Use `rustc_driver::args::raw_args()` in Miri
beetrees May 15, 2023
bed9d1f
Add known-bug tests for `derive(PartialEq)` mismatches with `#[repr(p…
oli-obk Mar 7, 2024
025ad40
Don't ICE in CTFE if raw/fn-ptr types differ
compiler-errors Mar 8, 2024
ece20f0
Bless tidy issues order
chenyukang Mar 8, 2024
c2f13db
rustc: Fix typo
heiher Mar 8, 2024
2e5f86c
interpret: update comment about read_discriminant on uninhabited vari…
RalfJung Mar 8, 2024
c81521a
Fix crash in late internal checking
chenyukang Mar 8, 2024
075f1c3
Rollup merge of #121025 - oli-obk:taint_after_errors, r=petrochenkov
matthiaskrgr Mar 8, 2024
a8e3543
Rollup merge of #121194 - beetrees:rustc-raw-args, r=petrochenkov
matthiaskrgr Mar 8, 2024
3e634f8
Rollup merge of #121563 - Jarcho:use_cf, r=petrochenkov
matthiaskrgr Mar 8, 2024
3d71bad
Rollup merge of #122173 - compiler-errors:ptr-equality-in-ctfe, r=lcnr
matthiaskrgr Mar 8, 2024
af3d06c
Rollup merge of #122175 - chenyukang:yukang-fix-tidy-issues, r=workin…
matthiaskrgr Mar 8, 2024
9fd60c5
Rollup merge of #122179 - heiher:fix-typo, r=lcnr
matthiaskrgr Mar 8, 2024
a08a5d4
Rollup merge of #122181 - chenyukang:yukang-fix-late-lint-crash, r=ol…
matthiaskrgr Mar 8, 2024
8abeac2
Rollup merge of #122183 - RalfJung:read-discriminant-uninhabited-vari…
matthiaskrgr Mar 8, 2024
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
Prev Previous commit
Next Next commit
Refactor argument UTF-8 checking into rustc_driver::args::raw_args()
  • Loading branch information
beetrees committed Mar 7, 2024
commit fb87e606cc6951cb41044b23f8f723abd9ad7fce
28 changes: 24 additions & 4 deletions compiler/rustc_driver_impl/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,7 1,4 @@
use std::error;
use std::fmt;
use std::fs;
use std::io;
use std::{env, error, fmt, fs, io};

use rustc_session::EarlyDiagCtxt;
use rustc_span::ErrorGuaranteed;
Expand Down Expand Up @@ -116,6 113,29 @@ pub fn arg_expand_all(
result.map(|()| expander.finish())
}

/// Gets the raw unprocessed command-line arguments as Unicode strings, without doing any further
/// processing (e.g., without `@file` expansion).
///
/// This function is identical to [`env::args()`] except that it emits an error when it encounters
/// non-Unicode arguments instead of panicking.
pub fn raw_args(early_dcx: &EarlyDiagCtxt) -> Result<Vec<String>, ErrorGuaranteed> {
let mut res = Ok(Vec::new());
for (i, arg) in env::args_os().enumerate() {
match arg.into_string() {
Ok(arg) => {
if let Ok(args) = &mut res {
args.push(arg);
}
}
Err(arg) => {
res =
Err(early_dcx.early_err(format!("argument {i} is not valid Unicode: {arg:?}")))
}
}
}
res
}

#[derive(Debug)]
enum Error {
Utf8Error(String),
Expand Down
10 changes: 1 addition & 9 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1515,15 1515,7 @@ pub fn main() -> ! {
let mut callbacks = TimePassesCallbacks::default();
let using_internal_features = install_ice_hook(DEFAULT_BUG_REPORT_URL, |_| ());
let exit_code = catch_with_exit_code(|| {
let args = env::args_os()
.enumerate()
.map(|(i, arg)| {
arg.into_string().unwrap_or_else(|arg| {
early_dcx.early_fatal(format!("argument {i} is not valid Unicode: {arg:?}"))
})
})
.collect::<Vec<_>>();
RunCompiler::new(&args, &mut callbacks)
RunCompiler::new(&args::raw_args(&early_dcx)?, &mut callbacks)
.set_using_internal_features(using_internal_features)
.run()
});
Expand Down
13 changes: 3 additions & 10 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 179,14 @@ pub fn main() {
rustc_driver::init_logger(&early_dcx, rustc_log::LoggerConfig::from_env("RUSTDOC_LOG"));

let exit_code = rustc_driver::catch_with_exit_code(|| {
let args = env::args_os()
.enumerate()
.map(|(i, arg)| {
arg.into_string().unwrap_or_else(|arg| {
early_dcx.early_fatal(format!("argument {i} is not valid Unicode: {arg:?}"))
})
})
.collect::<Vec<_>>();
main_args(&mut early_dcx, &args, using_internal_features)
let at_args = rustc_driver::args::raw_args(&early_dcx)?;
main_args(&mut early_dcx, &at_args, using_internal_features)
});
process::exit(exit_code);
}

fn init_logging(early_dcx: &EarlyDiagCtxt) {
let color_logs = match std::env::var("RUSTDOC_LOG_COLOR").as_deref() {
let color_logs = match env::var("RUSTDOC_LOG_COLOR").as_deref() {
Ok("always") => true,
Ok("never") => false,
Ok("auto") | Err(VarError::NotPresent) => io::stdout().is_terminal(),
Expand Down