Skip to content

Commit 35ac281

Browse files
committed
Factor out some repeated code.
1 parent 317d14a commit 35ac281

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

compiler/rustc_interface/src/tests.rs

+10-14
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ use std::num::NonZeroUsize;
2525
use std::path::{Path, PathBuf};
2626
use std::sync::Arc;
2727

28-
fn mk_session(handler: &mut EarlyErrorHandler, matches: getopts::Matches) -> (Session, Cfg) {
28+
fn mk_session(matches: getopts::Matches) -> (Session, Cfg) {
29+
let mut handler = EarlyErrorHandler::new(ErrorOutputType::default());
2930
let registry = registry::Registry::new(&[]);
30-
let sessopts = build_session_options(handler, &matches);
31-
let cfg = parse_cfg(handler, matches.opt_strs("cfg"));
31+
let sessopts = build_session_options(&mut handler, &matches);
32+
let cfg = parse_cfg(&handler, matches.opt_strs("cfg"));
3233
let temps_dir = sessopts.unstable_opts.temps_dir.as_deref().map(PathBuf::from);
3334
let io = CompilerIO {
3435
input: Input::Str { name: FileName::Custom(String::new()), input: String::new() },
@@ -37,7 +38,7 @@ fn mk_session(handler: &mut EarlyErrorHandler, matches: getopts::Matches) -> (Se
3738
temps_dir,
3839
};
3940
let sess = build_session(
40-
handler,
41+
&handler,
4142
sessopts,
4243
io,
4344
None,
@@ -117,8 +118,7 @@ fn assert_non_crate_hash_different(x: &Options, y: &Options) {
117118
fn test_switch_implies_cfg_test() {
118119
rustc_span::create_default_session_globals_then(|| {
119120
let matches = optgroups().parse(&["--test".to_string()]).unwrap();
120-
let mut handler = EarlyErrorHandler::new(ErrorOutputType::default());
121-
let (sess, cfg) = mk_session(&mut handler, matches);
121+
let (sess, cfg) = mk_session(matches);
122122
let cfg = build_configuration(&sess, cfg);
123123
assert!(cfg.contains(&(sym::test, None)));
124124
});
@@ -129,8 +129,7 @@ fn test_switch_implies_cfg_test() {
129129
fn test_switch_implies_cfg_test_unless_cfg_test() {
130130
rustc_span::create_default_session_globals_then(|| {
131131
let matches = optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]).unwrap();
132-
let mut handler = EarlyErrorHandler::new(ErrorOutputType::default());
133-
let (sess, cfg) = mk_session(&mut handler, matches);
132+
let (sess, cfg) = mk_session(matches);
134133
let cfg = build_configuration(&sess, cfg);
135134
let mut test_items = cfg.iter().filter(|&&(name, _)| name == sym::test);
136135
assert!(test_items.next().is_some());
@@ -142,23 +141,20 @@ fn test_switch_implies_cfg_test_unless_cfg_test() {
142141
fn test_can_print_warnings() {
143142
rustc_span::create_default_session_globals_then(|| {
144143
let matches = optgroups().parse(&["-Awarnings".to_string()]).unwrap();
145-
let mut handler = EarlyErrorHandler::new(ErrorOutputType::default());
146-
let (sess, _) = mk_session(&mut handler, matches);
144+
let (sess, _) = mk_session(matches);
147145
assert!(!sess.diagnostic().can_emit_warnings());
148146
});
149147

150148
rustc_span::create_default_session_globals_then(|| {
151149
let matches =
152150
optgroups().parse(&["-Awarnings".to_string(), "-Dwarnings".to_string()]).unwrap();
153-
let mut handler = EarlyErrorHandler::new(ErrorOutputType::default());
154-
let (sess, _) = mk_session(&mut handler, matches);
151+
let (sess, _) = mk_session(matches);
155152
assert!(sess.diagnostic().can_emit_warnings());
156153
});
157154

158155
rustc_span::create_default_session_globals_then(|| {
159156
let matches = optgroups().parse(&["-Adead_code".to_string()]).unwrap();
160-
let mut handler = EarlyErrorHandler::new(ErrorOutputType::default());
161-
let (sess, _) = mk_session(&mut handler, matches);
157+
let (sess, _) = mk_session(matches);
162158
assert!(sess.diagnostic().can_emit_warnings());
163159
});
164160
}

0 commit comments

Comments
 (0)