use std::any::Any;
use std::env;
-use std::ffi::{OsStr, OsString};
+use std::ffi::OsString;
use std::fs;
use std::io::{self, Write};
use std::iter;
use syntax::fold::Folder;
use syntax::parse::{self, PResult};
use syntax::util::node_count::NodeCounter;
+use syntax::util::lev_distance::find_best_match_for_name;
+use syntax::symbol::Symbol;
use syntax_pos::{FileName, hygiene};
use syntax_ext;
trait_map: resolver.trait_map,
maybe_unused_trait_imports: resolver.maybe_unused_trait_imports,
maybe_unused_extern_crates: resolver.maybe_unused_extern_crates,
+ extern_prelude: resolver.extern_prelude,
},
analysis: ty::CrateAnalysis {
.cloned()
.collect();
missing_fragment_specifiers.sort();
+
for span in missing_fragment_specifiers {
let lint = lint::builtin::MISSING_FRAGMENT_SPECIFIER;
let msg = "missing fragment specifier";
.collect();
let mut file = fs::File::create(&deps_filename)?;
for path in out_filenames {
- write!(file, "{}: {}\n\n", path.display(), files.join(" "))?;
+ writeln!(file, "{}: {}\n", path.display(), files.join(" "))?;
}
// Emit a fake target for each input file to the compilation. This
Ok(())
})();
- match result {
- Ok(()) => {}
- Err(e) => {
- sess.fatal(&format!(
- "error writing dependencies to `{}`: {}",
- deps_filename.display(),
- e
- ));
- }
+ if let Err(e) = result {
+ sess.fatal(&format!(
+ "error writing dependencies to `{}`: {}",
+ deps_filename.display(),
+ e
+ ));
}
}
Some(ref n) if *n == "staticlib" => Some(config::CrateType::Staticlib),
Some(ref n) if *n == "proc-macro" => Some(config::CrateType::ProcMacro),
Some(ref n) if *n == "bin" => Some(config::CrateType::Executable),
- Some(_) => {
- session.buffer_lint(
- lint::builtin::UNKNOWN_CRATE_TYPES,
- ast::CRATE_NODE_ID,
- a.span,
- "invalid `crate_type` value",
- );
+ Some(ref n) => {
+ let crate_types = vec![
+ Symbol::intern("rlib"),
+ Symbol::intern("dylib"),
+ Symbol::intern("cdylib"),
+ Symbol::intern("lib"),
+ Symbol::intern("staticlib"),
+ 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(
+ crate_types.iter(),
+ &n.as_str(),
+ None
+ );
+ if let Some(candidate) = lev_candidate {
+ session.buffer_lint_with_diagnostic(
+ lint::builtin::UNKNOWN_CRATE_TYPES,
+ ast::CRATE_NODE_ID,
+ span,
+ "invalid `crate_type` value",
+ lint::builtin::BuiltinLintDiagnostics::
+ UnknownCrateTypes(
+ span,
+ "did you mean".to_string(),
+ format!("\"{}\"", candidate)
+ )
+ );
+ } else {
+ session.buffer_lint(
+ lint::builtin::UNKNOWN_CRATE_TYPES,
+ ast::CRATE_NODE_ID,
+ span,
+ "invalid `crate_type` value"
+ );
+ }
+ }
None
}
- _ => {
+ None => {
session
.struct_span_err(a.span, "`crate_type` requires a value")
.note("for example: `#![crate_type=\"lib\"]`")
base.push(::rustc_codegen_utils::link::default_output_for_target(
session,
));
+ } else {
+ base.sort();
+ base.dedup();
}
- base.sort();
- base.dedup();
}
- base.into_iter()
- .filter(|crate_type| {
- let res = !::rustc_codegen_utils::link::invalid_output_for_target(session, *crate_type);
+ 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
- })
- .collect()
+ res
+ });
+
+ base
}
pub fn compute_crate_disambiguator(session: &Session) -> CrateDisambiguator {
// "-" as input file will cause the parser to read from stdin so we
// have to make up a name
// We want to toss everything after the final '.'
- let dirpath = match *odir {
- Some(ref d) => d.clone(),
- None => PathBuf::new(),
- };
+ let dirpath = (*odir).as_ref().cloned().unwrap_or_default();
// If a crate name is present, we use it as the link name
let stem = sess.opts
.crate_name
.clone()
.or_else(|| attr::find_crate_name(attrs).map(|n| n.to_string()))
- .unwrap_or(input.filestem());
+ .unwrap_or_else(|| input.filestem().to_owned());
OutputFilenames {
out_directory: dirpath,
sess.warn("ignoring -C extra-filename flag due to -o flag");
}
- let cur_dir = Path::new("");
-
OutputFilenames {
- out_directory: out_file.parent().unwrap_or(cur_dir).to_path_buf(),
+ out_directory: out_file.parent().unwrap_or_else(|| Path::new("")).to_path_buf(),
out_filestem: out_file
.file_stem()
- .unwrap_or(OsStr::new(""))
+ .unwrap_or_default()
.to_str()
.unwrap()
.to_string(),