Skip to content

Commit 440a46d

Browse files
committed
Auto merge of rust-lang#5608 - flip1995:rustup, r=phansch
Rustup with git subtree The commits from the last rustup rust-lang#5587, are again included in this rustup, since I rebased the rustup. Lesson learned: never rebase, only merge when working with git subtree. changelog: none
2 parents cfd720d + 7f317b7 commit 440a46d

File tree

3 files changed

+114
-132
lines changed

3 files changed

+114
-132
lines changed

clippy_lints/src/utils/mod.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,12 @@ use rustc_hir::{
4040
use rustc_infer::infer::TyCtxtInferExt;
4141
use rustc_lint::{LateContext, Level, Lint, LintContext};
4242
use rustc_middle::hir::map::Map;
43-
use rustc_middle::traits;
4443
use rustc_middle::ty::{self, layout::IntegerExt, subst::GenericArg, Binder, Ty, TyCtxt, TypeFoldable};
4544
use rustc_span::hygiene::{ExpnKind, MacroKind};
4645
use rustc_span::source_map::original_sp;
4746
use rustc_span::symbol::{self, kw, Symbol};
4847
use rustc_span::{BytePos, Pos, Span, DUMMY_SP};
4948
use rustc_target::abi::Integer;
50-
use rustc_trait_selection::traits::predicate_for_trait_def;
51-
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
5249
use rustc_trait_selection::traits::query::normalize::AtExt;
5350
use smallvec::SmallVec;
5451

@@ -326,19 +323,8 @@ pub fn implements_trait<'a, 'tcx>(
326323
trait_id: DefId,
327324
ty_params: &[GenericArg<'tcx>],
328325
) -> bool {
329-
let ty = cx.tcx.erase_regions(&ty);
330-
let obligation = predicate_for_trait_def(
331-
cx.tcx,
332-
cx.param_env,
333-
traits::ObligationCause::dummy(),
334-
trait_id,
335-
0,
336-
ty,
337-
ty_params,
338-
);
339-
cx.tcx
340-
.infer_ctxt()
341-
.enter(|infcx| infcx.predicate_must_hold_modulo_regions(&obligation))
326+
let ty_params = cx.tcx.mk_substs(ty_params.iter());
327+
cx.tcx.type_implements_trait((trait_id, ty, ty_params, cx.param_env))
342328
}
343329

344330
/// Gets the `hir::TraitRef` of the trait the given method is implemented for.

clippy_lints/src/write.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,8 @@ fn check_newlines(fmtstr: &StrLit) -> bool {
483483
};
484484

485485
match fmtstr.style {
486-
StrStyle::Cooked => unescape::unescape_str(contents, &mut cb),
487-
StrStyle::Raw(_) => unescape::unescape_raw_str(contents, &mut cb),
486+
StrStyle::Cooked => unescape::unescape_literal(contents, unescape::Mode::Str, &mut cb),
487+
StrStyle::Raw(_) => unescape::unescape_literal(contents, unescape::Mode::RawStr, &mut cb),
488488
}
489489

490490
should_lint

src/driver.rs

Lines changed: 110 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -295,123 +295,119 @@ fn toolchain_path(home: Option<String>, toolchain: Option<String>) -> Option<Pat
295295
pub fn main() {
296296
rustc_driver::init_rustc_env_logger();
297297
lazy_static::initialize(&ICE_HOOK);
298-
exit(
299-
rustc_driver::catch_fatal_errors(move || {
300-
let mut orig_args: Vec<String> = env::args().collect();
301-
302-
if orig_args.iter().any(|a| a == "--version" || a == "-V") {
303-
let version_info = rustc_tools_util::get_version_info!();
304-
println!("{}", version_info);
305-
exit(0);
306-
}
298+
exit(rustc_driver::catch_with_exit_code(move || {
299+
let mut orig_args: Vec<String> = env::args().collect();
307300

308-
// Get the sysroot, looking from most specific to this invocation to the least:
309-
// - command line
310-
// - runtime environment
311-
// - SYSROOT
312-
// - RUSTUP_HOME, MULTIRUST_HOME, RUSTUP_TOOLCHAIN, MULTIRUST_TOOLCHAIN
313-
// - sysroot from rustc in the path
314-
// - compile-time environment
315-
// - SYSROOT
316-
// - RUSTUP_HOME, MULTIRUST_HOME, RUSTUP_TOOLCHAIN, MULTIRUST_TOOLCHAIN
317-
let sys_root_arg = arg_value(&orig_args, "--sysroot", |_| true);
318-
let have_sys_root_arg = sys_root_arg.is_some();
319-
let sys_root = sys_root_arg
320-
.map(PathBuf::from)
321-
.or_else(|| std::env::var("SYSROOT").ok().map(PathBuf::from))
322-
.or_else(|| {
323-
let home = std::env::var("RUSTUP_HOME")
324-
.or_else(|_| std::env::var("MULTIRUST_HOME"))
325-
.ok();
326-
let toolchain = std::env::var("RUSTUP_TOOLCHAIN")
327-
.or_else(|_| std::env::var("MULTIRUST_TOOLCHAIN"))
328-
.ok();
329-
toolchain_path(home, toolchain)
330-
})
331-
.or_else(|| {
332-
Command::new("rustc")
333-
.arg("--print")
334-
.arg("sysroot")
335-
.output()
336-
.ok()
337-
.and_then(|out| String::from_utf8(out.stdout).ok())
338-
.map(|s| PathBuf::from(s.trim()))
339-
})
340-
.or_else(|| option_env!("SYSROOT").map(PathBuf::from))
341-
.or_else(|| {
342-
let home = option_env!("RUSTUP_HOME")
343-
.or(option_env!("MULTIRUST_HOME"))
344-
.map(ToString::to_string);
345-
let toolchain = option_env!("RUSTUP_TOOLCHAIN")
346-
.or(option_env!("MULTIRUST_TOOLCHAIN"))
347-
.map(ToString::to_string);
348-
toolchain_path(home, toolchain)
349-
})
350-
.map(|pb| pb.to_string_lossy().to_string())
351-
.expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust");
352-
353-
// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
354-
// We're invoking the compiler programmatically, so we ignore this/
355-
let wrapper_mode = orig_args.get(1).map(Path::new).and_then(Path::file_stem) == Some("rustc".as_ref());
356-
357-
if wrapper_mode {
358-
// we still want to be able to invoke it normally though
359-
orig_args.remove(1);
360-
}
301+
if orig_args.iter().any(|a| a == "--version" || a == "-V") {
302+
let version_info = rustc_tools_util::get_version_info!();
303+
println!("{}", version_info);
304+
exit(0);
305+
}
361306

362-
if !wrapper_mode && (orig_args.iter().any(|a| a == "--help" || a == "-h") || orig_args.len() == 1) {
363-
display_help();
364-
exit(0);
365-
}
307+
// Get the sysroot, looking from most specific to this invocation to the least:
308+
// - command line
309+
// - runtime environment
310+
// - SYSROOT
311+
// - RUSTUP_HOME, MULTIRUST_HOME, RUSTUP_TOOLCHAIN, MULTIRUST_TOOLCHAIN
312+
// - sysroot from rustc in the path
313+
// - compile-time environment
314+
// - SYSROOT
315+
// - RUSTUP_HOME, MULTIRUST_HOME, RUSTUP_TOOLCHAIN, MULTIRUST_TOOLCHAIN
316+
let sys_root_arg = arg_value(&orig_args, "--sysroot", |_| true);
317+
let have_sys_root_arg = sys_root_arg.is_some();
318+
let sys_root = sys_root_arg
319+
.map(PathBuf::from)
320+
.or_else(|| std::env::var("SYSROOT").ok().map(PathBuf::from))
321+
.or_else(|| {
322+
let home = std::env::var("RUSTUP_HOME")
323+
.or_else(|_| std::env::var("MULTIRUST_HOME"))
324+
.ok();
325+
let toolchain = std::env::var("RUSTUP_TOOLCHAIN")
326+
.or_else(|_| std::env::var("MULTIRUST_TOOLCHAIN"))
327+
.ok();
328+
toolchain_path(home, toolchain)
329+
})
330+
.or_else(|| {
331+
Command::new("rustc")
332+
.arg("--print")
333+
.arg("sysroot")
334+
.output()
335+
.ok()
336+
.and_then(|out| String::from_utf8(out.stdout).ok())
337+
.map(|s| PathBuf::from(s.trim()))
338+
})
339+
.or_else(|| option_env!("SYSROOT").map(PathBuf::from))
340+
.or_else(|| {
341+
let home = option_env!("RUSTUP_HOME")
342+
.or(option_env!("MULTIRUST_HOME"))
343+
.map(ToString::to_string);
344+
let toolchain = option_env!("RUSTUP_TOOLCHAIN")
345+
.or(option_env!("MULTIRUST_TOOLCHAIN"))
346+
.map(ToString::to_string);
347+
toolchain_path(home, toolchain)
348+
})
349+
.map(|pb| pb.to_string_lossy().to_string())
350+
.expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust");
366351

367-
let should_describe_lints = || {
368-
let args: Vec<_> = env::args().collect();
369-
args.windows(2).any(|args| {
370-
args[1] == "help"
371-
&& match args[0].as_str() {
372-
"-W" | "-A" | "-D" | "-F" => true,
373-
_ => false,
374-
}
375-
})
376-
};
377-
378-
if !wrapper_mode && should_describe_lints() {
379-
describe_lints();
380-
exit(0);
381-
}
352+
// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
353+
// We're invoking the compiler programmatically, so we ignore this/
354+
let wrapper_mode = orig_args.get(1).map(Path::new).and_then(Path::file_stem) == Some("rustc".as_ref());
355+
356+
if wrapper_mode {
357+
// we still want to be able to invoke it normally though
358+
orig_args.remove(1);
359+
}
360+
361+
if !wrapper_mode && (orig_args.iter().any(|a| a == "--help" || a == "-h") || orig_args.len() == 1) {
362+
display_help();
363+
exit(0);
364+
}
365+
366+
let should_describe_lints = || {
367+
let args: Vec<_> = env::args().collect();
368+
args.windows(2).any(|args| {
369+
args[1] == "help"
370+
&& match args[0].as_str() {
371+
"-W" | "-A" | "-D" | "-F" => true,
372+
_ => false,
373+
}
374+
})
375+
};
382376

383-
// this conditional check for the --sysroot flag is there so users can call
384-
// `clippy_driver` directly
385-
// without having to pass --sysroot or anything
386-
let mut args: Vec<String> = orig_args.clone();
387-
if !have_sys_root_arg {
388-
args.extend(vec!["--sysroot".into(), sys_root]);
389-
};
390-
391-
// this check ensures that dependencies are built but not linted and the final
392-
// crate is linted but not built
393-
let clippy_enabled = env::var("CLIPPY_TESTS").map_or(false, |val| val == "true")
394-
|| arg_value(&orig_args, "--cap-lints", |val| val == "allow").is_none();
395-
396-
if clippy_enabled {
397-
args.extend(vec!["--cfg".into(), r#"feature="cargo-clippy""#.into()]);
398-
if let Ok(extra_args) = env::var("CLIPPY_ARGS") {
399-
args.extend(extra_args.split("__CLIPPY_HACKERY__").filter_map(|s| {
400-
if s.is_empty() {
401-
None
402-
} else {
403-
Some(s.to_string())
404-
}
405-
}));
406-
}
377+
if !wrapper_mode && should_describe_lints() {
378+
describe_lints();
379+
exit(0);
380+
}
381+
382+
// this conditional check for the --sysroot flag is there so users can call
383+
// `clippy_driver` directly
384+
// without having to pass --sysroot or anything
385+
let mut args: Vec<String> = orig_args.clone();
386+
if !have_sys_root_arg {
387+
args.extend(vec!["--sysroot".into(), sys_root]);
388+
};
389+
390+
// this check ensures that dependencies are built but not linted and the final
391+
// crate is linted but not built
392+
let clippy_enabled = env::var("CLIPPY_TESTS").map_or(false, |val| val == "true")
393+
|| arg_value(&orig_args, "--cap-lints", |val| val == "allow").is_none();
394+
395+
if clippy_enabled {
396+
args.extend(vec!["--cfg".into(), r#"feature="cargo-clippy""#.into()]);
397+
if let Ok(extra_args) = env::var("CLIPPY_ARGS") {
398+
args.extend(extra_args.split("__CLIPPY_HACKERY__").filter_map(|s| {
399+
if s.is_empty() {
400+
None
401+
} else {
402+
Some(s.to_string())
403+
}
404+
}));
407405
}
408-
let mut clippy = ClippyCallbacks;
409-
let mut default = DefaultCallbacks;
410-
let callbacks: &mut (dyn rustc_driver::Callbacks + Send) =
411-
if clippy_enabled { &mut clippy } else { &mut default };
412-
rustc_driver::run_compiler(&args, callbacks, None, None)
413-
})
414-
.and_then(|result| result)
415-
.is_err() as i32,
416-
)
406+
}
407+
let mut clippy = ClippyCallbacks;
408+
let mut default = DefaultCallbacks;
409+
let callbacks: &mut (dyn rustc_driver::Callbacks + Send) =
410+
if clippy_enabled { &mut clippy } else { &mut default };
411+
rustc_driver::run_compiler(&args, callbacks, None, None)
412+
}))
417413
}

0 commit comments

Comments
 (0)