Skip to content

Commit

Permalink
rustc/driver: whitespace & formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Oct 13, 2018
1 parent d838a7f commit b03a82c
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 86 deletions.
14 changes: 8 additions & 6 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,7 @@ where
.cloned()
.collect();
missing_fragment_specifiers.sort();

for span in missing_fragment_specifiers {
let lint = lint::builtin::MISSING_FRAGMENT_SPECIFIER;
let msg = "missing fragment specifier";
Expand Down Expand Up @@ -1517,6 +1518,7 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<c
Symbol::intern("proc-macro"),
Symbol::intern("bin")
];

if let ast::MetaItemKind::NameValue(spanned) = a.meta().unwrap().node {
let span = spanned.span;
let lev_candidate = find_best_match_for_name(
Expand Down Expand Up @@ -1587,12 +1589,12 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<c
base.retain(|crate_type| {
let res = !::rustc_codegen_utils::link::invalid_output_for_target(session, *crate_type);

if !res {
session.warn(&format!(
"dropping unsupported crate type `{}` for target `{}`",
*crate_type, session.opts.target_triple
));
}
if !res {
session.warn(&format!(
"dropping unsupported crate type `{}` for target `{}`",
*crate_type, session.opts.target_triple
));
}

res
});
Expand Down
44 changes: 20 additions & 24 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,16 @@ pub fn run<F>(run_compiler: F) -> isize
}
None => {
let emitter =
errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
None,
true,
false);
errors::emitter::EmitterWriter::stderr(
errors::ColorConfig::Auto,
None,
true,
false
);
let handler = errors::Handler::with_emitter(true, false, Box::new(emitter));
handler.emit(&MultiSpan::new(),
"aborting due to previous error(s)",
errors::Level::Fatal);
"aborting due to previous error(s)",
errors::Level::Fatal);
panic::resume_unwind(Box::new(errors::FatalErrorMarker));
}
}
Expand Down Expand Up @@ -316,9 +318,8 @@ fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend> {
let sysroot = sysroot_candidates.iter()
.map(|sysroot| {
let libdir = filesearch::relative_target_lib_path(&sysroot, &target);
sysroot.join(libdir)
.with_file_name(option_env!("CFG_CODEGEN_BACKENDS_DIR")
.unwrap_or("codegen-backends"))
sysroot.join(libdir).with_file_name(
option_env!("CFG_CODEGEN_BACKENDS_DIR").unwrap_or("codegen-backends"))
})
.filter(|f| {
info!("codegen backend candidate: {}", f.display());
Expand Down Expand Up @@ -360,8 +361,8 @@ fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend> {
}
if let Some(ref prev) = file {
let err = format!("duplicate codegen backends found\n\
first: {}\n\
second: {}\n\
first: {}\n\
second: {}\n\
", prev.display(), path.display());
early_error(ErrorOutputType::default(), &err);
}
Expand All @@ -373,7 +374,7 @@ fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend> {
None => {
let err = format!("failed to load default codegen backend for `{}`, \
no appropriate codegen dylib found in `{}`",
backend_name, sysroot.display());
backend_name, sysroot.display());
early_error(ErrorOutputType::default(), &err);
}
}
Expand Down Expand Up @@ -1010,7 +1011,7 @@ impl RustcDefaultCalls {
use rustc::session::config::PrintRequest::*;
// PrintRequest::NativeStaticLibs is special - printed during linking
// (empty iterator returns true)
if sess.opts.prints.iter().all(|&p| p==PrintRequest::NativeStaticLibs) {
if sess.opts.prints.iter().all(|&p| p == PrintRequest::NativeStaticLibs) {
return Compilation::Continue;
}

Expand Down Expand Up @@ -1054,10 +1055,7 @@ impl RustcDefaultCalls {
&id,
&t_outputs
);
println!("{}",
fname.file_name()
.unwrap()
.to_string_lossy());
println!("{}", fname.file_name().unwrap().to_string_lossy());
}
}
Cfg => {
Expand Down Expand Up @@ -1129,9 +1127,8 @@ fn commit_date_str() -> Option<&'static str> {
pub fn version(binary: &str, matches: &getopts::Matches) {
let verbose = matches.opt_present("verbose");

println!("{} {}",
binary,
option_env!("CFG_VERSION").unwrap_or("unknown version"));
println!("{} {}", binary, option_env!("CFG_VERSION").unwrap_or("unknown version"));

if verbose {
fn unw(x: Option<&str>) -> &str {
x.unwrap_or("unknown")
Expand Down Expand Up @@ -1252,8 +1249,6 @@ Available lint options:

print_lints(builtin);



let max_name_len = max("warnings".len(),
plugin_groups.iter()
.chain(&builtin_groups)
Expand Down Expand Up @@ -1429,6 +1424,7 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
}

let cg_flags = matches.opt_strs("C");

if cg_flags.iter().any(|x| *x == "help") {
describe_codegen_flags();
return None;
Expand Down Expand Up @@ -1477,7 +1473,7 @@ pub fn in_named_rustc_thread<F, R>(name: String, f: F) -> Result<R, Box<dyn Any
// Temporarily have stack size set to 16MB to deal with nom-using crates failing
const STACK_SIZE: usize = 16 * 1024 * 1024; // 16MB

#[cfg(all(unix,not(target_os = "haiku")))]
#[cfg(all(unix, not(target_os = "haiku")))]
let spawn_thread = unsafe {
// Fetch the current resource limits
let mut rlim = libc::rlimit {
Expand Down Expand Up @@ -1531,7 +1527,7 @@ pub fn in_named_rustc_thread<F, R>(name: String, f: F) -> Result<R, Box<dyn Any
}
};

#[cfg(not(any(windows,unix)))]
#[cfg(not(any(windows, unix)))]
let spawn_thread = true;

// The or condition is added from backward compatibility.
Expand Down
54 changes: 27 additions & 27 deletions src/librustc_driver/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ pub fn parse_pretty(sess: &Session,
impl PpSourceMode {
/// Constructs a `PrinterSupport` object and passes it to `f`.
fn call_with_pp_support<'tcx, A, F>(&self,
sess: &'tcx Session,
hir_map: Option<&hir_map::Map<'tcx>>,
f: F)
-> A
sess: &'tcx Session,
hir_map: Option<&hir_map::Map<'tcx>>,
f: F)
-> A
where F: FnOnce(&dyn PrinterSupport) -> A
{
match *self {
Expand Down Expand Up @@ -198,17 +198,18 @@ impl PpSourceMode {
_ => panic!("Should use call_with_pp_support_hir"),
}
}
fn call_with_pp_support_hir<'tcx, A, F>(&self,
sess: &'tcx Session,
cstore: &'tcx CStore,
hir_map: &hir_map::Map<'tcx>,
analysis: &ty::CrateAnalysis,
resolutions: &Resolutions,
arenas: &'tcx AllArenas<'tcx>,
output_filenames: &OutputFilenames,
id: &str,
f: F)
-> A
fn call_with_pp_support_hir<'tcx, A, F>(
&self,
sess: &'tcx Session,
cstore: &'tcx CStore,
hir_map: &hir_map::Map<'tcx>,
analysis: &ty::CrateAnalysis,
resolutions: &Resolutions,
arenas: &'tcx AllArenas<'tcx>,
output_filenames: &OutputFilenames,
id: &str,
f: F
) -> A
where F: FnOnce(&dyn HirPrinterSupport, &hir::Crate) -> A
{
match *self {
Expand Down Expand Up @@ -952,18 +953,17 @@ pub fn print_after_parsing(sess: &Session,
// Silently ignores an identified node.
let out: &mut dyn Write = &mut out;
s.call_with_pp_support(sess, None, move |annotation| {
debug!("pretty printing source code {:?}", s);
let sess = annotation.sess();
pprust::print_crate(sess.source_map(),
&sess.parse_sess,
krate,
src_name,
&mut rdr,
box out,
annotation.pp_ann(),
false)
})
.unwrap()
debug!("pretty printing source code {:?}", s);
let sess = annotation.sess();
pprust::print_crate(sess.source_map(),
&sess.parse_sess,
krate,
src_name,
&mut rdr,
box out,
annotation.pp_ann(),
false)
}).unwrap()
} else {
unreachable!();
};
Expand Down
24 changes: 11 additions & 13 deletions src/librustc_driver/profile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn begin(sess: &Session) {
use std::sync::mpsc::{channel};
let (tx, rx) = channel();
if profq_set_chan(sess, tx) {
thread::spawn(move||profile_queries_thread(rx));
thread::spawn(move || profile_queries_thread(rx));
}
}

Expand All @@ -34,11 +34,12 @@ pub fn begin(sess: &Session) {
pub fn dump(sess: &Session, path: String) {
use std::sync::mpsc::{channel};
let (tx, rx) = channel();
let params = ProfQDumpParams{
path, ack:tx,
let params = ProfQDumpParams {
path,
ack: tx,
// FIXME: Add another compiler flag to toggle whether this log
// is written; false for now
dump_profq_msg_log:true,
dump_profq_msg_log: true,
};
profq_msg(sess, ProfileQueriesMsg::Dump(params));
let _ = rx.recv().unwrap();
Expand All @@ -63,20 +64,20 @@ struct StackFrame {
}

fn total_duration(traces: &[trace::Rec]) -> Duration {
let mut sum : Duration = Duration::new(0,0);
let mut sum : Duration = Duration::new(0, 0);
for t in traces.iter() { sum += t.dur_total; }
return sum
}

// profiling thread; retains state (in local variables) and dump traces, upon request.
fn profile_queries_thread(r:Receiver<ProfileQueriesMsg>) {
fn profile_queries_thread(r: Receiver<ProfileQueriesMsg>) {
use self::trace::*;
use std::fs::File;
use std::time::{Instant};

let mut profq_msgs : Vec<ProfileQueriesMsg> = vec![];
let mut frame : StackFrame = StackFrame{ parse_st:ParseState::Clear, traces:vec![] };
let mut stack : Vec<StackFrame> = vec![];
let mut profq_msgs: Vec<ProfileQueriesMsg> = vec![];
let mut frame: StackFrame = StackFrame { parse_st: ParseState::Clear, traces: vec![] };
let mut stack: Vec<StackFrame> = vec![];
loop {
let msg = r.recv();
if let Err(_recv_err) = msg {
Expand Down Expand Up @@ -138,7 +139,7 @@ fn profile_queries_thread(r:Receiver<ProfileQueriesMsg>) {

// Parse State: Clear
(ParseState::Clear,
ProfileQueriesMsg::QueryBegin(span,querymsg)) => {
ProfileQueriesMsg::QueryBegin(span, querymsg)) => {
let start = Instant::now();
frame.parse_st = ParseState::HaveQuery
(Query { span, msg: querymsg }, start)
Expand Down Expand Up @@ -284,8 +285,6 @@ fn profile_queries_thread(r:Receiver<ProfileQueriesMsg>) {
frame = StackFrame{parse_st:ParseState::Clear, traces:vec![]};
},

//
//
// Parse errors:

(ParseState::HaveQuery(q,_),
Expand All @@ -307,7 +306,6 @@ fn profile_queries_thread(r:Receiver<ProfileQueriesMsg>) {
unreachable!()
},
}

}
}
}
Expand Down
Loading

0 comments on commit b03a82c

Please sign in to comment.