summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_interface/src/tests.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /compiler/rustc_interface/src/tests.rs
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_interface/src/tests.rs')
-rw-r--r--compiler/rustc_interface/src/tests.rs122
1 files changed, 75 insertions, 47 deletions
diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs
index 28e719a40..09141afd1 100644
--- a/compiler/rustc_interface/src/tests.rs
+++ b/compiler/rustc_interface/src/tests.rs
@@ -8,10 +8,11 @@ use rustc_session::config::rustc_optgroups;
use rustc_session::config::DebugInfo;
use rustc_session::config::Input;
use rustc_session::config::InstrumentXRay;
+use rustc_session::config::LinkSelfContained;
use rustc_session::config::TraitSolver;
use rustc_session::config::{build_configuration, build_session_options, to_crate_config};
use rustc_session::config::{
- BranchProtection, Externs, OomStrategy, OutputType, OutputTypes, PAuthKey, PacRet,
+ BranchProtection, Externs, OomStrategy, OutFileName, OutputType, OutputTypes, PAuthKey, PacRet,
ProcMacroExecutionStrategy, SymbolManglingVersion, WasiExecModel,
};
use rustc_session::config::{CFGuard, ExternEntry, LinkerPluginLto, LtoCli, SwitchWithOptPath};
@@ -21,8 +22,8 @@ use rustc_session::config::{InstrumentCoverage, Passes};
use rustc_session::lint::Level;
use rustc_session::search_paths::SearchPath;
use rustc_session::utils::{CanonicalizedPath, NativeLib, NativeLibKind};
-use rustc_session::CompilerIO;
use rustc_session::{build_session, getopts, Session};
+use rustc_session::{CompilerIO, EarlyErrorHandler};
use rustc_span::edition::{Edition, DEFAULT_EDITION};
use rustc_span::symbol::sym;
use rustc_span::FileName;
@@ -36,15 +37,18 @@ use std::path::{Path, PathBuf};
type CfgSpecs = FxHashSet<(String, Option<String>)>;
-fn build_session_options_and_crate_config(matches: getopts::Matches) -> (Options, CfgSpecs) {
- let sessopts = build_session_options(&matches);
- let cfg = parse_cfgspecs(matches.opt_strs("cfg"));
+fn build_session_options_and_crate_config(
+ handler: &mut EarlyErrorHandler,
+ matches: getopts::Matches,
+) -> (Options, CfgSpecs) {
+ let sessopts = build_session_options(handler, &matches);
+ let cfg = parse_cfgspecs(handler, matches.opt_strs("cfg"));
(sessopts, cfg)
}
-fn mk_session(matches: getopts::Matches) -> (Session, CfgSpecs) {
+fn mk_session(handler: &mut EarlyErrorHandler, matches: getopts::Matches) -> (Session, CfgSpecs) {
let registry = registry::Registry::new(&[]);
- let (sessopts, cfg) = build_session_options_and_crate_config(matches);
+ let (sessopts, cfg) = build_session_options_and_crate_config(handler, matches);
let temps_dir = sessopts.unstable_opts.temps_dir.as_deref().map(PathBuf::from);
let io = CompilerIO {
input: Input::Str { name: FileName::Custom(String::new()), input: String::new() },
@@ -52,8 +56,18 @@ fn mk_session(matches: getopts::Matches) -> (Session, CfgSpecs) {
output_file: None,
temps_dir,
};
- let sess =
- build_session(sessopts, io, None, registry, vec![], Default::default(), None, None, "");
+ let sess = build_session(
+ handler,
+ sessopts,
+ io,
+ None,
+ registry,
+ vec![],
+ Default::default(),
+ None,
+ None,
+ "",
+ );
(sess, cfg)
}
@@ -120,7 +134,8 @@ fn assert_non_crate_hash_different(x: &Options, y: &Options) {
fn test_switch_implies_cfg_test() {
rustc_span::create_default_session_globals_then(|| {
let matches = optgroups().parse(&["--test".to_string()]).unwrap();
- let (sess, cfg) = mk_session(matches);
+ let mut handler = EarlyErrorHandler::new(ErrorOutputType::default());
+ let (sess, cfg) = mk_session(&mut handler, matches);
let cfg = build_configuration(&sess, to_crate_config(cfg));
assert!(cfg.contains(&(sym::test, None)));
});
@@ -131,7 +146,8 @@ fn test_switch_implies_cfg_test() {
fn test_switch_implies_cfg_test_unless_cfg_test() {
rustc_span::create_default_session_globals_then(|| {
let matches = optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]).unwrap();
- let (sess, cfg) = mk_session(matches);
+ let mut handler = EarlyErrorHandler::new(ErrorOutputType::default());
+ let (sess, cfg) = mk_session(&mut handler, matches);
let cfg = build_configuration(&sess, to_crate_config(cfg));
let mut test_items = cfg.iter().filter(|&&(name, _)| name == sym::test);
assert!(test_items.next().is_some());
@@ -143,20 +159,23 @@ fn test_switch_implies_cfg_test_unless_cfg_test() {
fn test_can_print_warnings() {
rustc_span::create_default_session_globals_then(|| {
let matches = optgroups().parse(&["-Awarnings".to_string()]).unwrap();
- let (sess, _) = mk_session(matches);
+ let mut handler = EarlyErrorHandler::new(ErrorOutputType::default());
+ let (sess, _) = mk_session(&mut handler, matches);
assert!(!sess.diagnostic().can_emit_warnings());
});
rustc_span::create_default_session_globals_then(|| {
let matches =
optgroups().parse(&["-Awarnings".to_string(), "-Dwarnings".to_string()]).unwrap();
- let (sess, _) = mk_session(matches);
+ let mut handler = EarlyErrorHandler::new(ErrorOutputType::default());
+ let (sess, _) = mk_session(&mut handler, matches);
assert!(sess.diagnostic().can_emit_warnings());
});
rustc_span::create_default_session_globals_then(|| {
let matches = optgroups().parse(&["-Adead_code".to_string()]).unwrap();
- let (sess, _) = mk_session(matches);
+ let mut handler = EarlyErrorHandler::new(ErrorOutputType::default());
+ let (sess, _) = mk_session(&mut handler, matches);
assert!(sess.diagnostic().can_emit_warnings());
});
}
@@ -167,8 +186,14 @@ fn test_output_types_tracking_hash_different_paths() {
let mut v2 = Options::default();
let mut v3 = Options::default();
- v1.output_types = OutputTypes::new(&[(OutputType::Exe, Some(PathBuf::from("./some/thing")))]);
- v2.output_types = OutputTypes::new(&[(OutputType::Exe, Some(PathBuf::from("/some/thing")))]);
+ v1.output_types = OutputTypes::new(&[(
+ OutputType::Exe,
+ Some(OutFileName::Real(PathBuf::from("./some/thing"))),
+ )]);
+ v2.output_types = OutputTypes::new(&[(
+ OutputType::Exe,
+ Some(OutFileName::Real(PathBuf::from("/some/thing"))),
+ )]);
v3.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
assert_non_crate_hash_different(&v1, &v2);
@@ -182,13 +207,13 @@ fn test_output_types_tracking_hash_different_construction_order() {
let mut v2 = Options::default();
v1.output_types = OutputTypes::new(&[
- (OutputType::Exe, Some(PathBuf::from("./some/thing"))),
- (OutputType::Bitcode, Some(PathBuf::from("./some/thing.bc"))),
+ (OutputType::Exe, Some(OutFileName::Real(PathBuf::from("./some/thing")))),
+ (OutputType::Bitcode, Some(OutFileName::Real(PathBuf::from("./some/thing.bc")))),
]);
v2.output_types = OutputTypes::new(&[
- (OutputType::Bitcode, Some(PathBuf::from("./some/thing.bc"))),
- (OutputType::Exe, Some(PathBuf::from("./some/thing"))),
+ (OutputType::Bitcode, Some(OutFileName::Real(PathBuf::from("./some/thing.bc")))),
+ (OutputType::Exe, Some(OutFileName::Real(PathBuf::from("./some/thing")))),
]);
assert_same_hash(&v1, &v2);
@@ -296,35 +321,36 @@ fn test_search_paths_tracking_hash_different_order() {
let mut v3 = Options::default();
let mut v4 = Options::default();
+ let handler = EarlyErrorHandler::new(JSON);
const JSON: ErrorOutputType = ErrorOutputType::Json {
pretty: false,
json_rendered: HumanReadableErrorType::Default(ColorConfig::Never),
};
// Reference
- v1.search_paths.push(SearchPath::from_cli_opt("native=abc", JSON));
- v1.search_paths.push(SearchPath::from_cli_opt("crate=def", JSON));
- v1.search_paths.push(SearchPath::from_cli_opt("dependency=ghi", JSON));
- v1.search_paths.push(SearchPath::from_cli_opt("framework=jkl", JSON));
- v1.search_paths.push(SearchPath::from_cli_opt("all=mno", JSON));
-
- v2.search_paths.push(SearchPath::from_cli_opt("native=abc", JSON));
- v2.search_paths.push(SearchPath::from_cli_opt("dependency=ghi", JSON));
- v2.search_paths.push(SearchPath::from_cli_opt("crate=def", JSON));
- v2.search_paths.push(SearchPath::from_cli_opt("framework=jkl", JSON));
- v2.search_paths.push(SearchPath::from_cli_opt("all=mno", JSON));
-
- v3.search_paths.push(SearchPath::from_cli_opt("crate=def", JSON));
- v3.search_paths.push(SearchPath::from_cli_opt("framework=jkl", JSON));
- v3.search_paths.push(SearchPath::from_cli_opt("native=abc", JSON));
- v3.search_paths.push(SearchPath::from_cli_opt("dependency=ghi", JSON));
- v3.search_paths.push(SearchPath::from_cli_opt("all=mno", JSON));
-
- v4.search_paths.push(SearchPath::from_cli_opt("all=mno", JSON));
- v4.search_paths.push(SearchPath::from_cli_opt("native=abc", JSON));
- v4.search_paths.push(SearchPath::from_cli_opt("crate=def", JSON));
- v4.search_paths.push(SearchPath::from_cli_opt("dependency=ghi", JSON));
- v4.search_paths.push(SearchPath::from_cli_opt("framework=jkl", JSON));
+ v1.search_paths.push(SearchPath::from_cli_opt(&handler, "native=abc"));
+ v1.search_paths.push(SearchPath::from_cli_opt(&handler, "crate=def"));
+ v1.search_paths.push(SearchPath::from_cli_opt(&handler, "dependency=ghi"));
+ v1.search_paths.push(SearchPath::from_cli_opt(&handler, "framework=jkl"));
+ v1.search_paths.push(SearchPath::from_cli_opt(&handler, "all=mno"));
+
+ v2.search_paths.push(SearchPath::from_cli_opt(&handler, "native=abc"));
+ v2.search_paths.push(SearchPath::from_cli_opt(&handler, "dependency=ghi"));
+ v2.search_paths.push(SearchPath::from_cli_opt(&handler, "crate=def"));
+ v2.search_paths.push(SearchPath::from_cli_opt(&handler, "framework=jkl"));
+ v2.search_paths.push(SearchPath::from_cli_opt(&handler, "all=mno"));
+
+ v3.search_paths.push(SearchPath::from_cli_opt(&handler, "crate=def"));
+ v3.search_paths.push(SearchPath::from_cli_opt(&handler, "framework=jkl"));
+ v3.search_paths.push(SearchPath::from_cli_opt(&handler, "native=abc"));
+ v3.search_paths.push(SearchPath::from_cli_opt(&handler, "dependency=ghi"));
+ v3.search_paths.push(SearchPath::from_cli_opt(&handler, "all=mno"));
+
+ v4.search_paths.push(SearchPath::from_cli_opt(&handler, "all=mno"));
+ v4.search_paths.push(SearchPath::from_cli_opt(&handler, "native=abc"));
+ v4.search_paths.push(SearchPath::from_cli_opt(&handler, "crate=def"));
+ v4.search_paths.push(SearchPath::from_cli_opt(&handler, "dependency=ghi"));
+ v4.search_paths.push(SearchPath::from_cli_opt(&handler, "framework=jkl"));
assert_same_hash(&v1, &v2);
assert_same_hash(&v1, &v3);
@@ -554,7 +580,7 @@ fn test_codegen_options_tracking_hash() {
untracked!(incremental, Some(String::from("abc")));
// `link_arg` is omitted because it just forwards to `link_args`.
untracked!(link_args, vec![String::from("abc"), String::from("def")]);
- untracked!(link_self_contained, Some(true));
+ untracked!(link_self_contained, LinkSelfContained::on());
untracked!(linker, Some(PathBuf::from("linker")));
untracked!(linker_flavor, Some(LinkerFlavorCli::Gcc));
untracked!(no_stack_check, true);
@@ -679,7 +705,7 @@ fn test_unstable_options_tracking_hash() {
untracked!(ls, true);
untracked!(macro_backtrace, true);
untracked!(meta_stats, true);
- untracked!(mir_pretty_relative_line_numbers, true);
+ untracked!(mir_include_spans, true);
untracked!(nll_facts, true);
untracked!(no_analysis, true);
untracked!(no_leak_check, true);
@@ -815,7 +841,7 @@ fn test_unstable_options_tracking_hash() {
tracked!(thir_unsafeck, true);
tracked!(tiny_const_eval_limit, true);
tracked!(tls_model, Some(TlsModel::GeneralDynamic));
- tracked!(trait_solver, TraitSolver::Chalk);
+ tracked!(trait_solver, TraitSolver::NextCoherence);
tracked!(translate_remapped_path_to_local_path, false);
tracked!(trap_unreachable, Some(false));
tracked!(treat_err_as_bug, NonZeroUsize::new(1));
@@ -845,7 +871,9 @@ fn test_edition_parsing() {
let options = Options::default();
assert!(options.edition == DEFAULT_EDITION);
+ let mut handler = EarlyErrorHandler::new(ErrorOutputType::default());
+
let matches = optgroups().parse(&["--edition=2018".to_string()]).unwrap();
- let (sessopts, _) = build_session_options_and_crate_config(matches);
+ let (sessopts, _) = build_session_options_and_crate_config(&mut handler, matches);
assert!(sessopts.edition == Edition::Edition2018)
}