Auto merge of #118635 - nnethercote:fewer-early-errors, r=davidtwco
Fewer early errors r? `@davidtwco`
This commit is contained in:
commit
7df0c211ac
7 changed files with 66 additions and 48 deletions
|
@ -42,7 +42,7 @@ pub struct Compiler {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts strings provided as `--cfg [cfgspec]` into a `Cfg`.
|
/// Converts strings provided as `--cfg [cfgspec]` into a `Cfg`.
|
||||||
pub(crate) fn parse_cfg(handler: &EarlyErrorHandler, cfgs: Vec<String>) -> Cfg {
|
pub(crate) fn parse_cfg(handler: &Handler, cfgs: Vec<String>) -> Cfg {
|
||||||
cfgs.into_iter()
|
cfgs.into_iter()
|
||||||
.map(|s| {
|
.map(|s| {
|
||||||
let sess = ParseSess::with_silent_emitter(Some(format!(
|
let sess = ParseSess::with_silent_emitter(Some(format!(
|
||||||
|
@ -52,10 +52,14 @@ pub(crate) fn parse_cfg(handler: &EarlyErrorHandler, cfgs: Vec<String>) -> Cfg {
|
||||||
|
|
||||||
macro_rules! error {
|
macro_rules! error {
|
||||||
($reason: expr) => {
|
($reason: expr) => {
|
||||||
handler.early_error(format!(
|
#[allow(rustc::untranslatable_diagnostic)]
|
||||||
|
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||||
|
handler
|
||||||
|
.struct_fatal(format!(
|
||||||
concat!("invalid `--cfg` argument: `{}` (", $reason, ")"),
|
concat!("invalid `--cfg` argument: `{}` (", $reason, ")"),
|
||||||
s
|
s
|
||||||
));
|
))
|
||||||
|
.emit();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +101,7 @@ pub(crate) fn parse_cfg(handler: &EarlyErrorHandler, cfgs: Vec<String>) -> Cfg {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts strings provided as `--check-cfg [specs]` into a `CheckCfg`.
|
/// Converts strings provided as `--check-cfg [specs]` into a `CheckCfg`.
|
||||||
pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> CheckCfg {
|
pub(crate) fn parse_check_cfg(handler: &Handler, specs: Vec<String>) -> CheckCfg {
|
||||||
// If any --check-cfg is passed then exhaustive_values and exhaustive_names
|
// If any --check-cfg is passed then exhaustive_values and exhaustive_names
|
||||||
// are enabled by default.
|
// are enabled by default.
|
||||||
let exhaustive_names = !specs.is_empty();
|
let exhaustive_names = !specs.is_empty();
|
||||||
|
@ -112,10 +116,14 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
|
||||||
|
|
||||||
macro_rules! error {
|
macro_rules! error {
|
||||||
($reason:expr) => {
|
($reason:expr) => {
|
||||||
handler.early_error(format!(
|
#[allow(rustc::untranslatable_diagnostic)]
|
||||||
|
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||||
|
handler
|
||||||
|
.struct_fatal(format!(
|
||||||
concat!("invalid `--check-cfg` argument: `{}` (", $reason, ")"),
|
concat!("invalid `--check-cfg` argument: `{}` (", $reason, ")"),
|
||||||
s
|
s
|
||||||
))
|
))
|
||||||
|
.emit()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,13 +322,13 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
|
||||||
|| {
|
|| {
|
||||||
crate::callbacks::setup_callbacks();
|
crate::callbacks::setup_callbacks();
|
||||||
|
|
||||||
let handler = EarlyErrorHandler::new(config.opts.error_format);
|
let early_handler = EarlyErrorHandler::new(config.opts.error_format);
|
||||||
|
|
||||||
let codegen_backend = if let Some(make_codegen_backend) = config.make_codegen_backend {
|
let codegen_backend = if let Some(make_codegen_backend) = config.make_codegen_backend {
|
||||||
make_codegen_backend(&config.opts)
|
make_codegen_backend(&config.opts)
|
||||||
} else {
|
} else {
|
||||||
util::get_codegen_backend(
|
util::get_codegen_backend(
|
||||||
&handler,
|
&early_handler,
|
||||||
&config.opts.maybe_sysroot,
|
&config.opts.maybe_sysroot,
|
||||||
config.opts.unstable_opts.codegen_backend.as_deref(),
|
config.opts.unstable_opts.codegen_backend.as_deref(),
|
||||||
)
|
)
|
||||||
|
@ -337,7 +345,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
|
||||||
) {
|
) {
|
||||||
Ok(bundle) => bundle,
|
Ok(bundle) => bundle,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
handler.early_error(format!("failed to load fluent bundle: {e}"));
|
early_handler.early_error(format!("failed to load fluent bundle: {e}"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -348,7 +356,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
|
||||||
let target_override = codegen_backend.target_override(&config.opts);
|
let target_override = codegen_backend.target_override(&config.opts);
|
||||||
|
|
||||||
let mut sess = rustc_session::build_session(
|
let mut sess = rustc_session::build_session(
|
||||||
&handler,
|
early_handler,
|
||||||
config.opts,
|
config.opts,
|
||||||
CompilerIO {
|
CompilerIO {
|
||||||
input: config.input,
|
input: config.input,
|
||||||
|
@ -370,12 +378,12 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
|
||||||
|
|
||||||
codegen_backend.init(&sess);
|
codegen_backend.init(&sess);
|
||||||
|
|
||||||
let cfg = parse_cfg(&handler, config.crate_cfg);
|
let cfg = parse_cfg(&sess.diagnostic(), config.crate_cfg);
|
||||||
let mut cfg = config::build_configuration(&sess, cfg);
|
let mut cfg = config::build_configuration(&sess, cfg);
|
||||||
util::add_configuration(&mut cfg, &mut sess, &*codegen_backend);
|
util::add_configuration(&mut cfg, &mut sess, &*codegen_backend);
|
||||||
sess.parse_sess.config = cfg;
|
sess.parse_sess.config = cfg;
|
||||||
|
|
||||||
let mut check_cfg = parse_check_cfg(&handler, config.crate_check_cfg);
|
let mut check_cfg = parse_check_cfg(&sess.diagnostic(), config.crate_check_cfg);
|
||||||
check_cfg.fill_well_known(&sess.target);
|
check_cfg.fill_well_known(&sess.target);
|
||||||
sess.parse_sess.check_config = check_cfg;
|
sess.parse_sess.check_config = check_cfg;
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,10 @@ use std::num::NonZeroUsize;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
fn mk_session(handler: &mut EarlyErrorHandler, matches: getopts::Matches) -> (Session, Cfg) {
|
fn mk_session(matches: getopts::Matches) -> (Session, Cfg) {
|
||||||
|
let mut early_handler = EarlyErrorHandler::new(ErrorOutputType::default());
|
||||||
let registry = registry::Registry::new(&[]);
|
let registry = registry::Registry::new(&[]);
|
||||||
let sessopts = build_session_options(handler, &matches);
|
let sessopts = build_session_options(&mut early_handler, &matches);
|
||||||
let cfg = parse_cfg(handler, matches.opt_strs("cfg"));
|
|
||||||
let temps_dir = sessopts.unstable_opts.temps_dir.as_deref().map(PathBuf::from);
|
let temps_dir = sessopts.unstable_opts.temps_dir.as_deref().map(PathBuf::from);
|
||||||
let io = CompilerIO {
|
let io = CompilerIO {
|
||||||
input: Input::Str { name: FileName::Custom(String::new()), input: String::new() },
|
input: Input::Str { name: FileName::Custom(String::new()), input: String::new() },
|
||||||
|
@ -37,7 +37,7 @@ fn mk_session(handler: &mut EarlyErrorHandler, matches: getopts::Matches) -> (Se
|
||||||
temps_dir,
|
temps_dir,
|
||||||
};
|
};
|
||||||
let sess = build_session(
|
let sess = build_session(
|
||||||
handler,
|
early_handler,
|
||||||
sessopts,
|
sessopts,
|
||||||
io,
|
io,
|
||||||
None,
|
None,
|
||||||
|
@ -51,6 +51,7 @@ fn mk_session(handler: &mut EarlyErrorHandler, matches: getopts::Matches) -> (Se
|
||||||
Arc::default(),
|
Arc::default(),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
);
|
);
|
||||||
|
let cfg = parse_cfg(&sess.diagnostic(), matches.opt_strs("cfg"));
|
||||||
(sess, cfg)
|
(sess, cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,8 +118,7 @@ fn assert_non_crate_hash_different(x: &Options, y: &Options) {
|
||||||
fn test_switch_implies_cfg_test() {
|
fn test_switch_implies_cfg_test() {
|
||||||
rustc_span::create_default_session_globals_then(|| {
|
rustc_span::create_default_session_globals_then(|| {
|
||||||
let matches = optgroups().parse(&["--test".to_string()]).unwrap();
|
let matches = optgroups().parse(&["--test".to_string()]).unwrap();
|
||||||
let mut handler = EarlyErrorHandler::new(ErrorOutputType::default());
|
let (sess, cfg) = mk_session(matches);
|
||||||
let (sess, cfg) = mk_session(&mut handler, matches);
|
|
||||||
let cfg = build_configuration(&sess, cfg);
|
let cfg = build_configuration(&sess, cfg);
|
||||||
assert!(cfg.contains(&(sym::test, None)));
|
assert!(cfg.contains(&(sym::test, None)));
|
||||||
});
|
});
|
||||||
|
@ -129,8 +129,7 @@ fn test_switch_implies_cfg_test() {
|
||||||
fn test_switch_implies_cfg_test_unless_cfg_test() {
|
fn test_switch_implies_cfg_test_unless_cfg_test() {
|
||||||
rustc_span::create_default_session_globals_then(|| {
|
rustc_span::create_default_session_globals_then(|| {
|
||||||
let matches = optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]).unwrap();
|
let matches = optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]).unwrap();
|
||||||
let mut handler = EarlyErrorHandler::new(ErrorOutputType::default());
|
let (sess, cfg) = mk_session(matches);
|
||||||
let (sess, cfg) = mk_session(&mut handler, matches);
|
|
||||||
let cfg = build_configuration(&sess, cfg);
|
let cfg = build_configuration(&sess, cfg);
|
||||||
let mut test_items = cfg.iter().filter(|&&(name, _)| name == sym::test);
|
let mut test_items = cfg.iter().filter(|&&(name, _)| name == sym::test);
|
||||||
assert!(test_items.next().is_some());
|
assert!(test_items.next().is_some());
|
||||||
|
@ -142,23 +141,20 @@ fn test_switch_implies_cfg_test_unless_cfg_test() {
|
||||||
fn test_can_print_warnings() {
|
fn test_can_print_warnings() {
|
||||||
rustc_span::create_default_session_globals_then(|| {
|
rustc_span::create_default_session_globals_then(|| {
|
||||||
let matches = optgroups().parse(&["-Awarnings".to_string()]).unwrap();
|
let matches = optgroups().parse(&["-Awarnings".to_string()]).unwrap();
|
||||||
let mut handler = EarlyErrorHandler::new(ErrorOutputType::default());
|
let (sess, _) = mk_session(matches);
|
||||||
let (sess, _) = mk_session(&mut handler, matches);
|
|
||||||
assert!(!sess.diagnostic().can_emit_warnings());
|
assert!(!sess.diagnostic().can_emit_warnings());
|
||||||
});
|
});
|
||||||
|
|
||||||
rustc_span::create_default_session_globals_then(|| {
|
rustc_span::create_default_session_globals_then(|| {
|
||||||
let matches =
|
let matches =
|
||||||
optgroups().parse(&["-Awarnings".to_string(), "-Dwarnings".to_string()]).unwrap();
|
optgroups().parse(&["-Awarnings".to_string(), "-Dwarnings".to_string()]).unwrap();
|
||||||
let mut handler = EarlyErrorHandler::new(ErrorOutputType::default());
|
let (sess, _) = mk_session(matches);
|
||||||
let (sess, _) = mk_session(&mut handler, matches);
|
|
||||||
assert!(sess.diagnostic().can_emit_warnings());
|
assert!(sess.diagnostic().can_emit_warnings());
|
||||||
});
|
});
|
||||||
|
|
||||||
rustc_span::create_default_session_globals_then(|| {
|
rustc_span::create_default_session_globals_then(|| {
|
||||||
let matches = optgroups().parse(&["-Adead_code".to_string()]).unwrap();
|
let matches = optgroups().parse(&["-Adead_code".to_string()]).unwrap();
|
||||||
let mut handler = EarlyErrorHandler::new(ErrorOutputType::default());
|
let (sess, _) = mk_session(matches);
|
||||||
let (sess, _) = mk_session(&mut handler, matches);
|
|
||||||
assert!(sess.diagnostic().can_emit_warnings());
|
assert!(sess.diagnostic().can_emit_warnings());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@ session_crate_name_invalid = crate names cannot start with a `-`, but `{$s}` has
|
||||||
|
|
||||||
session_expr_parentheses_needed = parentheses are required to parse this as an expression
|
session_expr_parentheses_needed = parentheses are required to parse this as an expression
|
||||||
|
|
||||||
|
session_failed_to_create_profiler = failed to create profiler: {$err}
|
||||||
|
|
||||||
session_feature_diagnostic_for_issue =
|
session_feature_diagnostic_for_issue =
|
||||||
see issue #{$n} <https://github.com/rust-lang/rust/issues/{$n}> for more information
|
see issue #{$n} <https://github.com/rust-lang/rust/issues/{$n}> for more information
|
||||||
|
|
||||||
|
@ -73,6 +75,7 @@ session_not_supported = not supported
|
||||||
session_nul_in_c_str = null characters in C string literals are not supported
|
session_nul_in_c_str = null characters in C string literals are not supported
|
||||||
|
|
||||||
session_octal_float_literal_not_supported = octal float literal is not supported
|
session_octal_float_literal_not_supported = octal float literal is not supported
|
||||||
|
|
||||||
session_optimization_fuel_exhausted = optimization-fuel-exhausted: {$msg}
|
session_optimization_fuel_exhausted = optimization-fuel-exhausted: {$msg}
|
||||||
|
|
||||||
session_profile_sample_use_file_does_not_exist = file `{$path}` passed to `-C profile-sample-use` does not exist.
|
session_profile_sample_use_file_does_not_exist = file `{$path}` passed to `-C profile-sample-use` does not exist.
|
||||||
|
|
|
@ -444,3 +444,9 @@ pub(crate) struct FunctionReturnRequiresX86OrX8664;
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(session_function_return_thunk_extern_requires_non_large_code_model)]
|
#[diag(session_function_return_thunk_extern_requires_non_large_code_model)]
|
||||||
pub(crate) struct FunctionReturnThunkExternRequiresNonLargeCodeModel;
|
pub(crate) struct FunctionReturnThunkExternRequiresNonLargeCodeModel;
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(session_failed_to_create_profiler)]
|
||||||
|
pub struct FailedToCreateProfiler {
|
||||||
|
pub err: String,
|
||||||
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ use rustc_errors::registry::Registry;
|
||||||
use rustc_errors::{
|
use rustc_errors::{
|
||||||
error_code, fallback_fluent_bundle, DiagnosticBuilder, DiagnosticId, DiagnosticMessage,
|
error_code, fallback_fluent_bundle, DiagnosticBuilder, DiagnosticId, DiagnosticMessage,
|
||||||
ErrorGuaranteed, FluentBundle, Handler, IntoDiagnostic, LazyFallbackBundle, MultiSpan, Noted,
|
ErrorGuaranteed, FluentBundle, Handler, IntoDiagnostic, LazyFallbackBundle, MultiSpan, Noted,
|
||||||
SubdiagnosticMessage, TerminalUrl,
|
TerminalUrl,
|
||||||
};
|
};
|
||||||
use rustc_macros::HashStable_Generic;
|
use rustc_macros::HashStable_Generic;
|
||||||
pub use rustc_span::def_id::StableCrateId;
|
pub use rustc_span::def_id::StableCrateId;
|
||||||
|
@ -1349,7 +1349,7 @@ fn default_emitter(
|
||||||
// JUSTIFICATION: literally session construction
|
// JUSTIFICATION: literally session construction
|
||||||
#[allow(rustc::bad_opt_access)]
|
#[allow(rustc::bad_opt_access)]
|
||||||
pub fn build_session(
|
pub fn build_session(
|
||||||
handler: &EarlyErrorHandler,
|
early_handler: EarlyErrorHandler,
|
||||||
sopts: config::Options,
|
sopts: config::Options,
|
||||||
io: CompilerIO,
|
io: CompilerIO,
|
||||||
bundle: Option<Lrc<rustc_errors::FluentBundle>>,
|
bundle: Option<Lrc<rustc_errors::FluentBundle>>,
|
||||||
|
@ -1379,12 +1379,13 @@ pub fn build_session(
|
||||||
None => filesearch::get_or_default_sysroot().expect("Failed finding sysroot"),
|
None => filesearch::get_or_default_sysroot().expect("Failed finding sysroot"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let target_cfg = config::build_target_config(handler, &sopts, target_override, &sysroot);
|
let target_cfg = config::build_target_config(&early_handler, &sopts, target_override, &sysroot);
|
||||||
let host_triple = TargetTriple::from_triple(config::host_triple());
|
let host_triple = TargetTriple::from_triple(config::host_triple());
|
||||||
let (host, target_warnings) = Target::search(&host_triple, &sysroot)
|
let (host, target_warnings) = Target::search(&host_triple, &sysroot).unwrap_or_else(|e| {
|
||||||
.unwrap_or_else(|e| handler.early_error(format!("Error loading host specification: {e}")));
|
early_handler.early_error(format!("Error loading host specification: {e}"))
|
||||||
|
});
|
||||||
for warning in target_warnings.warning_messages() {
|
for warning in target_warnings.warning_messages() {
|
||||||
handler.early_warn(warning)
|
early_handler.early_warn(warning)
|
||||||
}
|
}
|
||||||
|
|
||||||
let loader = file_loader.unwrap_or_else(|| Box::new(RealFileLoader));
|
let loader = file_loader.unwrap_or_else(|| Box::new(RealFileLoader));
|
||||||
|
@ -1413,6 +1414,10 @@ pub fn build_session(
|
||||||
span_diagnostic = span_diagnostic.with_ice_file(ice_file);
|
span_diagnostic = span_diagnostic.with_ice_file(ice_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now that the proper handler has been constructed, drop the early handler
|
||||||
|
// to prevent accidental use.
|
||||||
|
drop(early_handler);
|
||||||
|
|
||||||
let self_profiler = if let SwitchWithOptPath::Enabled(ref d) = sopts.unstable_opts.self_profile
|
let self_profiler = if let SwitchWithOptPath::Enabled(ref d) = sopts.unstable_opts.self_profile
|
||||||
{
|
{
|
||||||
let directory =
|
let directory =
|
||||||
|
@ -1427,7 +1432,7 @@ pub fn build_session(
|
||||||
match profiler {
|
match profiler {
|
||||||
Ok(profiler) => Some(Arc::new(profiler)),
|
Ok(profiler) => Some(Arc::new(profiler)),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
handler.early_warn(format!("failed to create profiler: {e}"));
|
span_diagnostic.emit_warning(errors::FailedToCreateProfiler { err: e.to_string() });
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1471,7 +1476,13 @@ pub fn build_session(
|
||||||
|
|
||||||
// Check jobserver before getting `jobserver::client`.
|
// Check jobserver before getting `jobserver::client`.
|
||||||
jobserver::check(|err| {
|
jobserver::check(|err| {
|
||||||
handler.early_warn_with_note(err, "the build environment is likely misconfigured")
|
#[allow(rustc::untranslatable_diagnostic)]
|
||||||
|
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||||
|
parse_sess
|
||||||
|
.span_diagnostic
|
||||||
|
.struct_warn(err)
|
||||||
|
.note("the build environment is likely misconfigured")
|
||||||
|
.emit()
|
||||||
});
|
});
|
||||||
|
|
||||||
let sess = Session {
|
let sess = Session {
|
||||||
|
@ -1781,16 +1792,6 @@ impl EarlyErrorHandler {
|
||||||
pub fn early_warn(&self, msg: impl Into<DiagnosticMessage>) {
|
pub fn early_warn(&self, msg: impl Into<DiagnosticMessage>) {
|
||||||
self.handler.struct_warn(msg).emit()
|
self.handler.struct_warn(msg).emit()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(rustc::untranslatable_diagnostic)]
|
|
||||||
#[allow(rustc::diagnostic_outside_of_impl)]
|
|
||||||
pub fn early_warn_with_note(
|
|
||||||
&self,
|
|
||||||
msg: impl Into<DiagnosticMessage>,
|
|
||||||
note: impl Into<SubdiagnosticMessage>,
|
|
||||||
) {
|
|
||||||
self.handler.struct_warn(msg).note(note).emit()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mk_emitter(output: ErrorOutputType) -> Box<DynEmitter> {
|
fn mk_emitter(output: ErrorOutputType) -> Box<DynEmitter> {
|
||||||
|
|
|
@ -4,3 +4,5 @@ warning: failed to connect to jobserver from environment variable `MAKEFLAGS="--
|
||||||
|
|
||||||
error: no input filename given
|
error: no input filename given
|
||||||
|
|
||||||
|
warning: 1 warning emitted
|
||||||
|
|
||||||
|
|
|
@ -2,3 +2,5 @@ warning: failed to connect to jobserver from environment variable `MAKEFLAGS="--
|
||||||
|
|
|
|
||||||
= note: the build environment is likely misconfigured
|
= note: the build environment is likely misconfigured
|
||||||
|
|
||||||
|
warning: 1 warning emitted
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue