]> git.lizzy.rs Git - rust.git/blob - src/test/run-make-fulldeps/issue-19371/foo.rs
Update const_forget.rs
[rust.git] / src / test / run-make-fulldeps / issue-19371 / foo.rs
1 #![feature(rustc_private)]
2
3 extern crate rustc;
4 extern crate rustc_interface;
5 extern crate rustc_driver;
6 extern crate rustc_span;
7
8 use rustc::session::DiagnosticOutput;
9 use rustc::session::config::{Input, Options,
10                              OutputType, OutputTypes};
11 use rustc_interface::interface;
12 use rustc_span::source_map::FileName;
13
14 use std::path::PathBuf;
15
16 fn main() {
17     let src = r#"
18     fn main() {}
19     "#;
20
21     let args: Vec<String> = std::env::args().collect();
22
23     if args.len() < 4 {
24         panic!("expected rustc path");
25     }
26
27     let tmpdir = PathBuf::from(&args[1]);
28
29     let mut sysroot = PathBuf::from(&args[3]);
30     sysroot.pop();
31     sysroot.pop();
32
33     compile(src.to_string(), tmpdir.join("out"), sysroot.clone());
34
35     compile(src.to_string(), tmpdir.join("out"), sysroot.clone());
36 }
37
38 fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
39     let mut opts = Options::default();
40     opts.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
41     opts.maybe_sysroot = Some(sysroot);
42
43     if let Ok(linker) = std::env::var("RUSTC_LINKER") {
44         opts.cg.linker = Some(linker.into());
45     }
46
47     let name = FileName::anon_source_code(&code);
48     let input = Input::Str { name, input: code };
49
50     let config = interface::Config {
51         opts,
52         crate_cfg: Default::default(),
53         input,
54         input_path: None,
55         output_file: Some(output),
56         output_dir: None,
57         file_loader: None,
58         diagnostic_output: DiagnosticOutput::Default,
59         stderr: None,
60         crate_name: None,
61         lint_caps: Default::default(),
62         register_lints: None,
63         override_queries: None,
64         registry: rustc_driver::diagnostics_registry(),
65     };
66
67     interface::run_compiler(config, |compiler| {
68         // This runs all the passes prior to linking, too.
69         let linker = compiler.enter(|queries| {
70             queries.linker()
71         });
72         if let Ok(linker) = linker {
73             linker.link();
74         }
75     });
76 }