From adf53d4b068e216f0705ba2baae4cc21dd0988a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Fri, 16 Dec 2022 00:00:00 +0000 Subject: [PATCH 1/7] Remove dead code after destination propagation --- compiler/rustc_mir_transform/src/dest_prop.rs | 7 ++ .../unreachable.f.DestinationPropagation.diff | 86 +++++++++++++++++++ src/test/mir-opt/dest-prop/unreachable.rs | 18 ++++ 3 files changed, 111 insertions(+) create mode 100644 src/test/mir-opt/dest-prop/unreachable.f.DestinationPropagation.diff create mode 100644 src/test/mir-opt/dest-prop/unreachable.rs diff --git a/compiler/rustc_mir_transform/src/dest_prop.rs b/compiler/rustc_mir_transform/src/dest_prop.rs index 3e45319431cec..74d8337653f03 100644 --- a/compiler/rustc_mir_transform/src/dest_prop.rs +++ b/compiler/rustc_mir_transform/src/dest_prop.rs @@ -129,6 +129,7 @@ use std::collections::hash_map::{Entry, OccupiedEntry}; +use crate::simplify::remove_dead_blocks; use crate::MirPass; use rustc_data_structures::fx::FxHashMap; use rustc_index::bit_set::BitSet; @@ -235,6 +236,12 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation { apply_merges(body, tcx, &merges, &merged_locals); } + if round_count != 0 { + // Merging can introduce overlap between moved arguments and/or call destination in an + // unreachable code, which validator considers to be ill-formed. + remove_dead_blocks(tcx, body); + } + trace!(round_count); } } diff --git a/src/test/mir-opt/dest-prop/unreachable.f.DestinationPropagation.diff b/src/test/mir-opt/dest-prop/unreachable.f.DestinationPropagation.diff new file mode 100644 index 0000000000000..9ea756c271298 --- /dev/null +++ b/src/test/mir-opt/dest-prop/unreachable.f.DestinationPropagation.diff @@ -0,0 +1,86 @@ +- // MIR for `f` before DestinationPropagation ++ // MIR for `f` after DestinationPropagation + + fn f(_1: T) -> () { + debug a => _1; // in scope 0 at $DIR/unreachable.rs:+0:19: +0:20 + let mut _0: (); // return place in scope 0 at $DIR/unreachable.rs:+0:25: +0:25 + let _2: T; // in scope 0 at $DIR/unreachable.rs:+1:9: +1:10 + let mut _3: bool; // in scope 0 at $DIR/unreachable.rs:+2:8: +2:13 + let _4: (); // in scope 0 at $DIR/unreachable.rs:+3:9: +3:16 + let mut _5: T; // in scope 0 at $DIR/unreachable.rs:+3:11: +3:12 + let mut _6: T; // in scope 0 at $DIR/unreachable.rs:+3:14: +3:15 + let _7: (); // in scope 0 at $DIR/unreachable.rs:+5:9: +5:16 + let mut _8: T; // in scope 0 at $DIR/unreachable.rs:+5:11: +5:12 + let mut _9: T; // in scope 0 at $DIR/unreachable.rs:+5:14: +5:15 + scope 1 { +- debug b => _2; // in scope 1 at $DIR/unreachable.rs:+1:9: +1:10 ++ debug b => _1; // in scope 1 at $DIR/unreachable.rs:+1:9: +1:10 + } + + bb0: { +- StorageLive(_2); // scope 0 at $DIR/unreachable.rs:+1:9: +1:10 +- _2 = _1; // scope 0 at $DIR/unreachable.rs:+1:13: +1:14 ++ nop; // scope 0 at $DIR/unreachable.rs:+1:9: +1:10 ++ nop; // scope 0 at $DIR/unreachable.rs:+1:13: +1:14 + StorageLive(_3); // scope 1 at $DIR/unreachable.rs:+2:8: +2:13 + _3 = const false; // scope 1 at $DIR/unreachable.rs:+2:8: +2:13 +- goto -> bb3; // scope 1 at $DIR/unreachable.rs:+2:8: +2:13 ++ goto -> bb1; // scope 1 at $DIR/unreachable.rs:+2:8: +2:13 + } + + bb1: { +- StorageLive(_4); // scope 1 at $DIR/unreachable.rs:+3:9: +3:16 +- StorageLive(_5); // scope 1 at $DIR/unreachable.rs:+3:11: +3:12 +- _5 = _1; // scope 1 at $DIR/unreachable.rs:+3:11: +3:12 +- StorageLive(_6); // scope 1 at $DIR/unreachable.rs:+3:14: +3:15 +- _6 = _2; // scope 1 at $DIR/unreachable.rs:+3:14: +3:15 +- _4 = g::(move _5, move _6) -> bb2; // scope 1 at $DIR/unreachable.rs:+3:9: +3:16 +- // mir::Constant +- // + span: $DIR/unreachable.rs:11:9: 11:10 +- // + literal: Const { ty: fn(T, T) {g::}, val: Value() } +- } +- +- bb2: { +- StorageDead(_6); // scope 1 at $DIR/unreachable.rs:+3:15: +3:16 +- StorageDead(_5); // scope 1 at $DIR/unreachable.rs:+3:15: +3:16 +- StorageDead(_4); // scope 1 at $DIR/unreachable.rs:+3:16: +3:17 +- _0 = const (); // scope 1 at $DIR/unreachable.rs:+2:14: +4:6 +- goto -> bb5; // scope 1 at $DIR/unreachable.rs:+2:5: +6:6 +- } +- +- bb3: { + StorageLive(_7); // scope 1 at $DIR/unreachable.rs:+5:9: +5:16 +- StorageLive(_8); // scope 1 at $DIR/unreachable.rs:+5:11: +5:12 +- _8 = _2; // scope 1 at $DIR/unreachable.rs:+5:11: +5:12 ++ nop; // scope 1 at $DIR/unreachable.rs:+5:11: +5:12 ++ nop; // scope 1 at $DIR/unreachable.rs:+5:11: +5:12 + StorageLive(_9); // scope 1 at $DIR/unreachable.rs:+5:14: +5:15 +- _9 = _2; // scope 1 at $DIR/unreachable.rs:+5:14: +5:15 +- _7 = g::(move _8, move _9) -> bb4; // scope 1 at $DIR/unreachable.rs:+5:9: +5:16 ++ _9 = _1; // scope 1 at $DIR/unreachable.rs:+5:14: +5:15 ++ _7 = g::(move _1, move _9) -> bb2; // scope 1 at $DIR/unreachable.rs:+5:9: +5:16 + // mir::Constant + // + span: $DIR/unreachable.rs:13:9: 13:10 + // + literal: Const { ty: fn(T, T) {g::}, val: Value() } + } + +- bb4: { ++ bb2: { + StorageDead(_9); // scope 1 at $DIR/unreachable.rs:+5:15: +5:16 +- StorageDead(_8); // scope 1 at $DIR/unreachable.rs:+5:15: +5:16 ++ nop; // scope 1 at $DIR/unreachable.rs:+5:15: +5:16 + StorageDead(_7); // scope 1 at $DIR/unreachable.rs:+5:16: +5:17 + _0 = const (); // scope 1 at $DIR/unreachable.rs:+4:12: +6:6 +- goto -> bb5; // scope 1 at $DIR/unreachable.rs:+2:5: +6:6 ++ goto -> bb3; // scope 1 at $DIR/unreachable.rs:+2:5: +6:6 + } + +- bb5: { ++ bb3: { + StorageDead(_3); // scope 1 at $DIR/unreachable.rs:+6:5: +6:6 +- StorageDead(_2); // scope 0 at $DIR/unreachable.rs:+7:1: +7:2 ++ nop; // scope 0 at $DIR/unreachable.rs:+7:1: +7:2 + return; // scope 0 at $DIR/unreachable.rs:+7:2: +7:2 + } + } + diff --git a/src/test/mir-opt/dest-prop/unreachable.rs b/src/test/mir-opt/dest-prop/unreachable.rs new file mode 100644 index 0000000000000..32b5def984a80 --- /dev/null +++ b/src/test/mir-opt/dest-prop/unreachable.rs @@ -0,0 +1,18 @@ +// Check that unreachable code is removed after the destination propagation. +// Regression test for issue #105428. +// +// compile-flags: --crate-type=lib -Zmir-opt-level=0 +// compile-flags: -Zmir-enable-passes=+ConstProp,+SimplifyConstCondition-after-const-prop,+DestinationPropagation + +// EMIT_MIR unreachable.f.DestinationPropagation.diff +pub fn f(a: T) { + let b = a; + if false { + g(a, b); + } else { + g(b, b); + } +} + +#[inline(never)] +pub fn g(_: T, _: T) {} From fca829075fd76385ac6aa7bff957e7eebbf89ae1 Mon Sep 17 00:00:00 2001 From: Benjamin Tong Date: Sun, 1 May 2022 00:50:00 +0800 Subject: [PATCH 2/7] Remove special cases for setup subcommand - Remove setup special-casing in Flags::parse --- src/bootstrap/builder.rs | 15 +++++++-- src/bootstrap/flags.rs | 6 ++-- src/bootstrap/lib.rs | 4 --- src/bootstrap/setup.rs | 70 +++++++++++++++++++++++++++++++++------- 4 files changed, 74 insertions(+), 21 deletions(-) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 8ee6d49da8f0e..8f701b7d0a176 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -19,6 +19,7 @@ use crate::flags::{Color, Subcommand}; use crate::install; use crate::native; use crate::run; +use crate::setup; use crate::test; use crate::tool::{self, SourceType}; use crate::util::{self, add_dylib_path, add_link_lib_path, exe, libdir, output, t}; @@ -433,8 +434,11 @@ impl<'a> ShouldRun<'a> { // single alias, which does not correspond to any on-disk path pub fn alias(mut self, alias: &str) -> Self { + // exceptional case for `Kind::Setup` because its `library` + // and `compiler` options would otherwise naively match with + // `compiler` and `library` folders respectively. assert!( - !self.builder.src.join(alias).exists(), + self.kind == Kind::Setup || !self.builder.src.join(alias).exists(), "use `builder.path()` for real paths: {}", alias ); @@ -757,8 +761,9 @@ impl<'a> Builder<'a> { run::CollectLicenseMetadata, run::GenerateCopyright, ), + Kind::Setup => describe!(setup::Profile), // These commands either don't use paths, or they're special-cased in Build::build() - Kind::Clean | Kind::Format | Kind::Setup => vec![], + Kind::Clean | Kind::Format => vec![], } } @@ -821,7 +826,11 @@ impl<'a> Builder<'a> { Subcommand::Install { ref paths } => (Kind::Install, &paths[..]), Subcommand::Run { ref paths, .. } => (Kind::Run, &paths[..]), Subcommand::Format { .. } => (Kind::Format, &[][..]), - Subcommand::Clean { .. } | Subcommand::Setup { .. } => { + Subcommand::Setup { profile: ref path } => ( + Kind::Setup, + path.as_ref().map_or([].as_slice(), |path| std::slice::from_ref(path)), + ), + Subcommand::Clean { .. } => { panic!() } }; diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs index 37a8eb884efb0..851cb5ecf4c26 100644 --- a/src/bootstrap/flags.rs +++ b/src/bootstrap/flags.rs @@ -143,7 +143,7 @@ pub enum Subcommand { args: Vec, }, Setup { - profile: Option, + profile: Option, }, } @@ -351,7 +351,7 @@ To learn more about a subcommand, run `./x.py -h`", // fn usage() let usage = |exit_code: i32, opts: &Options, verbose: bool, subcommand_help: &str| -> ! { - let config = Config::parse(&["build".to_string()]); + let config = Config::parse(&["setup".to_string()]); let build = Build::new(config); let paths = Builder::get_help(&build, subcommand); @@ -621,7 +621,7 @@ Arguments: } Kind::Setup => { let profile = if paths.len() > 1 { - println!("\nat most one profile can be passed to setup\n"); + eprintln!("\nerror: At most one profile can be passed to setup\n"); usage(1, &opts, verbose, &subcommand_help) } else if let Some(path) = paths.pop() { let profile_string = t!(path.into_os_string().into_string().map_err( diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 570fe6484e3db..651e8dded68eb 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -713,10 +713,6 @@ impl Build { return clean::clean(self, all); } - if let Subcommand::Setup { profile } = &self.config.cmd { - return setup::setup(&self.config, *profile); - } - // Download rustfmt early so that it can be used in rust-analyzer configs. let _ = &builder::Builder::new(&self).initial_rustfmt(); diff --git a/src/bootstrap/setup.rs b/src/bootstrap/setup.rs index c7f98a7d0d149..57426ce3d5109 100644 --- a/src/bootstrap/setup.rs +++ b/src/bootstrap/setup.rs @@ -1,3 +1,4 @@ +use crate::builder::{Builder, RunConfig, ShouldRun, Step}; use crate::Config; use crate::{t, VERSION}; use std::env::consts::EXE_SUFFIX; @@ -9,7 +10,7 @@ use std::process::Command; use std::str::FromStr; use std::{fmt, fs, io}; -#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] pub enum Profile { Compiler, Codegen, @@ -48,6 +49,16 @@ impl Profile { } out } + + pub fn as_str(&self) -> &'static str { + match self { + Profile::Compiler => "compiler", + Profile::Codegen => "codegen", + Profile::Library => "library", + Profile::Tools => "tools", + Profile::User => "user", + } + } } impl FromStr for Profile { @@ -69,24 +80,58 @@ impl FromStr for Profile { impl fmt::Display for Profile { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Profile::Compiler => write!(f, "compiler"), - Profile::Codegen => write!(f, "codegen"), - Profile::Library => write!(f, "library"), - Profile::User => write!(f, "user"), - Profile::Tools => write!(f, "tools"), + f.write_str(self.as_str()) + } +} + +impl Step for Profile { + type Output = (); + const DEFAULT: bool = true; + + fn should_run(mut run: ShouldRun<'_>) -> ShouldRun<'_> { + for choice in Profile::all() { + run = run.alias(choice.as_str()); } + run + } + + fn make_run(run: RunConfig<'_>) { + // for Profile, `run.paths` will have 1 and only 1 element + // this is because we only accept at most 1 path from user input. + // If user calls `x.py setup` without arguments, the interactive TUI + // will guide user to provide one. + let profile = if run.paths.len() > 1 { + // HACK: `builder` runs this step with all paths if no path was passed. + t!(interactive_path()) + } else { + run.paths + .first() + .unwrap() + .assert_single_path() + .path + .as_path() + .as_os_str() + .to_str() + .unwrap() + .parse() + .unwrap() + }; + + run.builder.ensure(profile); + } + + fn run(self, builder: &Builder<'_>) { + setup(&builder.build.config, self) } } -pub fn setup(config: &Config, profile: Option) { - let profile = profile.unwrap_or_else(|| t!(interactive_path())); +pub fn setup(config: &Config, profile: Profile) { let stage_path = ["build", config.build.rustc_target_arg(), "stage1"].join(&MAIN_SEPARATOR.to_string()); if !rustup_installed() && profile != Profile::User { eprintln!("`rustup` is not installed; cannot link `stage1` toolchain"); - } else if stage_dir_exists(&stage_path[..]) { + } else if stage_dir_exists(&stage_path[..]) && !config.dry_run() { attempt_toolchain_link(&stage_path[..]); } @@ -104,7 +149,9 @@ pub fn setup(config: &Config, profile: Option) { Profile::User => &["dist", "build"], }; - t!(install_git_hook_maybe(&config)); + if !config.dry_run() { + t!(install_git_hook_maybe(&config)); + } println!(); @@ -144,6 +191,7 @@ fn setup_config_toml(path: &PathBuf, profile: Profile, config: &Config) { changelog-seen = {}\n", profile, VERSION ); + t!(fs::write(path, settings)); let include_path = profile.include_path(&config.src); From 1ade25491e8849d521fdb655c40102b1ffa15ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 18 Dec 2022 00:29:25 +0100 Subject: [PATCH 3/7] remove redundant clone --- compiler/rustc_builtin_macros/src/global_allocator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_builtin_macros/src/global_allocator.rs b/compiler/rustc_builtin_macros/src/global_allocator.rs index 41531580c1987..f8761653bf5b7 100644 --- a/compiler/rustc_builtin_macros/src/global_allocator.rs +++ b/compiler/rustc_builtin_macros/src/global_allocator.rs @@ -35,7 +35,7 @@ pub fn expand( (item, true, ecx.with_def_site_ctxt(ty.span)) } else { ecx.sess.parse_sess.span_diagnostic.span_err(item.span(), "allocators must be statics"); - return vec![orig_item.clone()] + return vec![orig_item]; }; // Generate a bunch of new items using the AllocFnFactory From a37d42133cddf1f82bf8c3d29b48b6ec694f6f8d Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sat, 17 Dec 2022 18:41:14 -0800 Subject: [PATCH 4/7] Another `as_chunks` example I really liked this structure that dtolney brought up in #105316, so wanted to put it in the docs to help others use it. --- library/core/src/slice/mod.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 8bd2ed45c0a2a..2c469f61854f3 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -1002,6 +1002,17 @@ impl [T] { /// assert_eq!(chunks, &[['l', 'o'], ['r', 'e']]); /// assert_eq!(remainder, &['m']); /// ``` + /// + /// If you expect the slice to be an exact multiple, you can combine + /// `let`-`else` with an empty slice pattern: + /// ``` + /// #![feature(slice_as_chunks)] + /// let slice = ['R', 'u', 's', 't']; + /// let (chunks, []) = slice.as_chunks::<2>() else { + /// panic!("slice didn't have even length") + /// }; + /// assert_eq!(chunks, &[['R', 'u'], ['s', 't']]); + /// ``` #[unstable(feature = "slice_as_chunks", issue = "74985")] #[inline] #[must_use] From 0aa4cde747bccb1d1277f9203cfe2021feec341f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 18 Dec 2022 15:01:26 +0100 Subject: [PATCH 5/7] avoid .into() conversion to identical types --- compiler/rustc_builtin_macros/src/test.rs | 3 +-- compiler/rustc_const_eval/src/interpret/operand.rs | 11 ++++------- compiler/rustc_const_eval/src/interpret/operator.rs | 2 +- compiler/rustc_const_eval/src/interpret/place.rs | 2 +- compiler/rustc_infer/src/infer/mod.rs | 2 +- compiler/rustc_middle/src/ty/vtable.rs | 4 ++-- compiler/rustc_mir_build/src/build/expr/as_place.rs | 2 +- compiler/rustc_mir_transform/src/const_prop.rs | 4 ++-- compiler/rustc_parse/src/parser/mod.rs | 8 ++------ compiler/rustc_passes/src/lang_items.rs | 2 -- .../src/traits/error_reporting/mod.rs | 4 ++-- 11 files changed, 17 insertions(+), 27 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs index f5f02fc772ab6..729ae4071e200 100644 --- a/compiler/rustc_builtin_macros/src/test.rs +++ b/compiler/rustc_builtin_macros/src/test.rs @@ -239,8 +239,7 @@ pub fn expand_test_or_bench( cx.attr_nested_word(sym::cfg, sym::test, attr_sp), // #[rustc_test_marker = "test_case_sort_key"] cx.attr_name_value_str(sym::rustc_test_marker, test_path_symbol, attr_sp), - ] - .into(), + ], // const $ident: test::TestDescAndFn = ast::ItemKind::Const( ast::Defaultness::Final, diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs index 221e359d24ab8..f9e3a2bdc06fe 100644 --- a/compiler/rustc_const_eval/src/interpret/operand.rs +++ b/compiler/rustc_const_eval/src/interpret/operand.rs @@ -39,7 +39,7 @@ pub enum Immediate { impl From> for Immediate { #[inline(always)] fn from(val: Scalar) -> Self { - Immediate::Scalar(val.into()) + Immediate::Scalar(val) } } @@ -53,7 +53,7 @@ impl Immediate { } pub fn new_slice(val: Scalar, len: u64, cx: &impl HasDataLayout) -> Self { - Immediate::ScalarPair(val.into(), Scalar::from_machine_usize(len, cx).into()) + Immediate::ScalarPair(val, Scalar::from_machine_usize(len, cx)) } pub fn new_dyn_trait( @@ -61,7 +61,7 @@ impl Immediate { vtable: Pointer>, cx: &impl HasDataLayout, ) -> Self { - Immediate::ScalarPair(val.into(), Scalar::from_maybe_pointer(vtable, cx)) + Immediate::ScalarPair(val, Scalar::from_maybe_pointer(vtable, cx)) } #[inline] @@ -341,10 +341,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { alloc_range(b_offset, b_size), /*read_provenance*/ b.is_ptr(), )?; - Some(ImmTy { - imm: Immediate::ScalarPair(a_val.into(), b_val.into()), - layout: mplace.layout, - }) + Some(ImmTy { imm: Immediate::ScalarPair(a_val, b_val), layout: mplace.layout }) } _ => { // Neither a scalar nor scalar pair. diff --git a/compiler/rustc_const_eval/src/interpret/operator.rs b/compiler/rustc_const_eval/src/interpret/operator.rs index 949f95c5fa81c..e8ff70e3a4095 100644 --- a/compiler/rustc_const_eval/src/interpret/operator.rs +++ b/compiler/rustc_const_eval/src/interpret/operator.rs @@ -36,7 +36,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { if let Abi::ScalarPair(..) = dest.layout.abi { // We can use the optimized path and avoid `place_field` (which might do // `force_allocation`). - let pair = Immediate::ScalarPair(val.into(), Scalar::from_bool(overflowed).into()); + let pair = Immediate::ScalarPair(val, Scalar::from_bool(overflowed)); self.write_immediate(pair, dest)?; } else { assert!(self.tcx.sess.opts.unstable_opts.randomize_layout); diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs index 905eb71bb18ed..97a73e98abcbc 100644 --- a/compiler/rustc_const_eval/src/interpret/place.rs +++ b/compiler/rustc_const_eval/src/interpret/place.rs @@ -141,7 +141,7 @@ impl MemPlace { match self.meta { MemPlaceMeta::None => Immediate::from(Scalar::from_maybe_pointer(self.ptr, cx)), MemPlaceMeta::Meta(meta) => { - Immediate::ScalarPair(Scalar::from_maybe_pointer(self.ptr, cx).into(), meta.into()) + Immediate::ScalarPair(Scalar::from_maybe_pointer(self.ptr, cx), meta) } } } diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 996148a709087..268b3bf1dcd4b 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -1920,7 +1920,7 @@ impl<'tcx> TypeTrace<'tcx> { ) -> TypeTrace<'tcx> { TypeTrace { cause: cause.clone(), - values: PolyTraitRefs(ExpectedFound::new(a_is_expected, a.into(), b.into())), + values: PolyTraitRefs(ExpectedFound::new(a_is_expected, a, b)), } } diff --git a/compiler/rustc_middle/src/ty/vtable.rs b/compiler/rustc_middle/src/ty/vtable.rs index 802925dfb043e..f77bd9f0c6ffc 100644 --- a/compiler/rustc_middle/src/ty/vtable.rs +++ b/compiler/rustc_middle/src/ty/vtable.rs @@ -88,8 +88,8 @@ pub(super) fn vtable_allocation_provider<'tcx>( let fn_ptr = Pointer::from(fn_alloc_id); Scalar::from_pointer(fn_ptr, &tcx) } - VtblEntry::MetadataSize => Scalar::from_uint(size, ptr_size).into(), - VtblEntry::MetadataAlign => Scalar::from_uint(align, ptr_size).into(), + VtblEntry::MetadataSize => Scalar::from_uint(size, ptr_size), + VtblEntry::MetadataAlign => Scalar::from_uint(align, ptr_size), VtblEntry::Vacant => continue, VtblEntry::Method(instance) => { // Prepare the fn ptr we write into the vtable. diff --git a/compiler/rustc_mir_build/src/build/expr/as_place.rs b/compiler/rustc_mir_build/src/build/expr/as_place.rs index 8a35478dd8b34..23a4f85386b8d 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_place.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_place.rs @@ -356,7 +356,7 @@ impl<'tcx> PlaceBuilder<'tcx> { match self { PlaceBuilder::Local { local, projection } => PlaceBuilder::Local { local: *local, - projection: Vec::from_iter(projection.iter().copied().chain([elem.into()])), + projection: Vec::from_iter(projection.iter().copied().chain([elem])), }, PlaceBuilder::Upvar { upvar, projection } => PlaceBuilder::Upvar { upvar: *upvar, diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index 044b7ce65bd71..e384cfe165990 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -701,8 +701,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { BinOp::Mul if const_arg.layout.ty.is_integral() && arg_value == 0 => { if let Rvalue::CheckedBinaryOp(_, _) = rvalue { let val = Immediate::ScalarPair( - const_arg.to_scalar().into(), - Scalar::from_bool(false).into(), + const_arg.to_scalar(), + Scalar::from_bool(false), ); this.ecx.write_immediate(val, &dest) } else { diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index bebb012660a16..40b88788caa67 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -25,7 +25,7 @@ use rustc_ast::tokenstream::{TokenStream, TokenTree}; use rustc_ast::util::case::Case; use rustc_ast::AttrId; use rustc_ast::DUMMY_NODE_ID; -use rustc_ast::{self as ast, AnonConst, AttrStyle, AttrVec, Const, DelimArgs, Extern}; +use rustc_ast::{self as ast, AnonConst, AttrStyle, Const, DelimArgs, Extern}; use rustc_ast::{Async, AttrArgs, AttrArgsEq, Expr, ExprKind, MacDelimiter, Mutability, StrLit}; use rustc_ast::{HasAttrs, HasTokens, Unsafe, Visibility, VisibilityKind}; use rustc_ast_pretty::pprust; @@ -1217,11 +1217,7 @@ impl<'a> Parser<'a> { value: self.mk_expr(blk.span, ExprKind::Block(blk, None)), }; let blk_span = anon_const.value.span; - Ok(self.mk_expr_with_attrs( - span.to(blk_span), - ExprKind::ConstBlock(anon_const), - AttrVec::from(attrs), - )) + Ok(self.mk_expr_with_attrs(span.to(blk_span), ExprKind::ConstBlock(anon_const), attrs)) } /// Parses mutability (`mut` or nothing). diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs index 99efed0b7fb46..9a40b847d8552 100644 --- a/compiler/rustc_passes/src/lang_items.rs +++ b/compiler/rustc_passes/src/lang_items.rs @@ -83,7 +83,6 @@ impl<'tcx> LanguageItemCollector<'tcx> { .map(|p| p.display().to_string()) .collect::>() .join(", ") - .into() }; let first_defined_span = self.tcx.hir().span_if_local(original_def_id); let mut orig_crate_name = Empty; @@ -98,7 +97,6 @@ impl<'tcx> LanguageItemCollector<'tcx> { .map(|p| p.display().to_string()) .collect::>() .join(", ") - .into() }; if first_defined_span.is_none() { orig_crate_name = self.tcx.crate_name(original_def_id.krate); diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 2dd2c568bab97..3b1be1a7f995e 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -1735,8 +1735,8 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { values.map(|(_, is_normalized_ty_expected, normalized_ty, expected_ty)| { infer::ValuePairs::Terms(ExpectedFound::new( is_normalized_ty_expected, - normalized_ty.into(), - expected_ty.into(), + normalized_ty, + expected_ty, )) }), err, From a108d55ce634b6f71462c82966b791f18136360e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 18 Dec 2022 17:01:58 +0100 Subject: [PATCH 6/7] don't restuct references just to reborrow --- compiler/rustc_codegen_llvm/src/back/lto.rs | 2 +- compiler/rustc_codegen_ssa/src/back/link.rs | 2 +- compiler/rustc_codegen_ssa/src/back/linker.rs | 2 +- compiler/rustc_const_eval/src/interpret/cast.rs | 2 +- compiler/rustc_expand/src/mbe/macro_check.rs | 4 ++-- compiler/rustc_expand/src/mbe/macro_rules.rs | 2 +- compiler/rustc_hir_typeck/src/demand.rs | 10 +++++----- compiler/rustc_hir_typeck/src/expr.rs | 2 +- .../rustc_hir_typeck/src/fn_ctxt/suggestions.rs | 2 +- .../rustc_incremental/src/assert_dep_graph.rs | 2 +- compiler/rustc_infer/src/traits/project.rs | 2 +- compiler/rustc_lint/src/context.rs | 10 +++++----- compiler/rustc_lint/src/unused.rs | 2 +- compiler/rustc_metadata/src/rmeta/encoder.rs | 4 ++-- compiler/rustc_middle/src/mir/tcx.rs | 2 +- compiler/rustc_middle/src/ty/flags.rs | 4 ++-- compiler/rustc_middle/src/ty/relate.rs | 2 +- .../rustc_mir_build/src/build/matches/test.rs | 17 ++++++++--------- compiler/rustc_passes/src/hir_stats.rs | 4 ++-- .../rustc_resolve/src/build_reduced_graph.rs | 2 +- compiler/rustc_session/src/session.rs | 2 +- .../src/traits/error_reporting/mod.rs | 2 +- 22 files changed, 41 insertions(+), 42 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/back/lto.rs b/compiler/rustc_codegen_llvm/src/back/lto.rs index e20dc906bce9a..6c0faf37a63ce 100644 --- a/compiler/rustc_codegen_llvm/src/back/lto.rs +++ b/compiler/rustc_codegen_llvm/src/back/lto.rs @@ -425,7 +425,7 @@ fn thin_lto( info!("going for that thin, thin LTO"); let green_modules: FxHashMap<_, _> = - cached_modules.iter().map(|&(_, ref wp)| (wp.cgu_name.clone(), wp.clone())).collect(); + cached_modules.iter().map(|(_, wp)| (wp.cgu_name.clone(), wp.clone())).collect(); let full_scope_len = modules.len() + serialized_modules.len() + cached_modules.len(); let mut thin_buffers = Vec::with_capacity(modules.len()); diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index fe2e4b36cd0f1..a1c77ec0cfca7 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -722,7 +722,7 @@ fn link_natively<'a>( linker::disable_localization(&mut cmd); - for &(ref k, ref v) in sess.target.link_env.as_ref() { + for (k, v) in sess.target.link_env.as_ref() { cmd.env(k.as_ref(), v.as_ref()); } for k in sess.target.link_env_remove.as_ref() { diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index f087d903e5568..0268659d3b9a1 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -108,7 +108,7 @@ pub fn get_linker<'a>( if sess.target.is_like_msvc { if let Some(ref tool) = msvc_tool { cmd.args(tool.args()); - for &(ref k, ref v) in tool.env() { + for (k, v) in tool.env() { if k == "PATH" { new_path.extend(env::split_paths(v)); msvc_changed_path = true; diff --git a/compiler/rustc_const_eval/src/interpret/cast.rs b/compiler/rustc_const_eval/src/interpret/cast.rs index b1fdeb01b100a..986b6d6553001 100644 --- a/compiler/rustc_const_eval/src/interpret/cast.rs +++ b/compiler/rustc_const_eval/src/interpret/cast.rs @@ -332,7 +332,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { Immediate::new_slice(ptr, length.eval_usize(*self.tcx, self.param_env), self); self.write_immediate(val, dest) } - (&ty::Dynamic(ref data_a, ..), &ty::Dynamic(ref data_b, ..)) => { + (ty::Dynamic(data_a, ..), ty::Dynamic(data_b, ..)) => { let val = self.read_immediate(src)?; if data_a.principal() == data_b.principal() { // A NOP cast that doesn't actually change anything, should be allowed even with mismatching vtables. diff --git a/compiler/rustc_expand/src/mbe/macro_check.rs b/compiler/rustc_expand/src/mbe/macro_check.rs index 8994a2f78919f..0b8847f827df1 100644 --- a/compiler/rustc_expand/src/mbe/macro_check.rs +++ b/compiler/rustc_expand/src/mbe/macro_check.rs @@ -468,7 +468,7 @@ fn check_nested_occurrences( // We check that the meta-variable is correctly used. check_occurrences(sess, node_id, tt, macros, binders, ops, valid); } - (NestedMacroState::MacroName, &TokenTree::Delimited(_, ref del)) + (NestedMacroState::MacroName, TokenTree::Delimited(_, del)) if del.delim == Delimiter::Parenthesis => { state = NestedMacroState::MacroNameParen; @@ -483,7 +483,7 @@ fn check_nested_occurrences( valid, ); } - (NestedMacroState::MacroNameParen, &TokenTree::Delimited(_, ref del)) + (NestedMacroState::MacroNameParen, TokenTree::Delimited(_, del)) if del.delim == Delimiter::Brace => { state = NestedMacroState::Empty; diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index 2dbb90e2190f0..320c533a66e5d 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -792,7 +792,7 @@ impl<'tt> FirstSets<'tt> { TokenTree::Sequence(sp, ref seq_rep) => { let subfirst_owned; let subfirst = match self.first.get(&sp.entire()) { - Some(&Some(ref subfirst)) => subfirst, + Some(Some(subfirst)) => subfirst, Some(&None) => { subfirst_owned = self.first(&seq_rep.tts); &subfirst_owned diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index 6763e06c0cfee..87abd01c7fd8f 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -1275,7 +1275,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; match (&expected_ty.kind(), &checked_ty.kind()) { - (&ty::Int(ref exp), &ty::Int(ref found)) => { + (ty::Int(exp), ty::Int(found)) => { let (f2e_is_fallible, e2f_is_fallible) = match (exp.bit_width(), found.bit_width()) { (Some(exp), Some(found)) if exp < found => (true, false), @@ -1288,7 +1288,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { suggest_to_change_suffix_or_into(err, f2e_is_fallible, e2f_is_fallible); true } - (&ty::Uint(ref exp), &ty::Uint(ref found)) => { + (ty::Uint(exp), ty::Uint(found)) => { let (f2e_is_fallible, e2f_is_fallible) = match (exp.bit_width(), found.bit_width()) { (Some(exp), Some(found)) if exp < found => (true, false), @@ -1321,7 +1321,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { suggest_to_change_suffix_or_into(err, f2e_is_fallible, e2f_is_fallible); true } - (&ty::Float(ref exp), &ty::Float(ref found)) => { + (ty::Float(exp), ty::Float(found)) => { if found.bit_width() < exp.bit_width() { suggest_to_change_suffix_or_into(err, false, true); } else if literal_is_ty_suffixed(expr) { @@ -1357,7 +1357,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } true } - (&ty::Float(ref exp), &ty::Uint(ref found)) => { + (ty::Float(exp), ty::Uint(found)) => { // if `found` is `None` (meaning found is `usize`), don't suggest `.into()` if exp.bit_width() > found.bit_width().unwrap_or(256) { err.multipart_suggestion_verbose( @@ -1386,7 +1386,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } true } - (&ty::Float(ref exp), &ty::Int(ref found)) => { + (ty::Float(exp), ty::Int(found)) => { // if `found` is `None` (meaning found is `isize`), don't suggest `.into()` if exp.bit_width() > found.bit_width().unwrap_or(256) { err.multipart_suggestion_verbose( diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 866090260b272..edbbb7272ac77 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -1874,7 +1874,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // I don't use 'is_range_literal' because only double-sided, half-open ranges count. if let ExprKind::Struct( QPath::LangItem(LangItem::Range, ..), - &[ref range_start, ref range_end], + [range_start, range_end], _, ) = last_expr_field.expr.kind && let variant_field = diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 407d6ac8544c2..ca4c50c49aae2 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -754,7 +754,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return true } } - &hir::FnRetTy::Return(ref ty) => { + hir::FnRetTy::Return(ty) => { // Only point to return type if the expected type is the return type, as if they // are not, the expectation must have been caused by something else. debug!("suggest_missing_return_type: return type {:?} node {:?}", ty, ty.kind); diff --git a/compiler/rustc_incremental/src/assert_dep_graph.rs b/compiler/rustc_incremental/src/assert_dep_graph.rs index 69e482ce854c0..b4bf9f4bcc767 100644 --- a/compiler/rustc_incremental/src/assert_dep_graph.rs +++ b/compiler/rustc_incremental/src/assert_dep_graph.rs @@ -249,7 +249,7 @@ fn dump_graph(query: &DepGraphQuery) { // dump a .txt file with just the edges: let txt_path = format!("{}.txt", path); let mut file = BufWriter::new(File::create(&txt_path).unwrap()); - for &(ref source, ref target) in &edges { + for (source, target) in &edges { write!(file, "{:?} -> {:?}\n", source, target).unwrap(); } } diff --git a/compiler/rustc_infer/src/traits/project.rs b/compiler/rustc_infer/src/traits/project.rs index aade57be9fe6e..ac455055b4303 100644 --- a/compiler/rustc_infer/src/traits/project.rs +++ b/compiler/rustc_infer/src/traits/project.rs @@ -200,7 +200,7 @@ impl<'tcx> ProjectionCache<'_, 'tcx> { pub fn complete(&mut self, key: ProjectionCacheKey<'tcx>, result: EvaluationResult) { let mut map = self.map(); match map.get(&key) { - Some(&ProjectionCacheEntry::NormalizedTy { ref ty, complete: _ }) => { + Some(ProjectionCacheEntry::NormalizedTy { ty, complete: _ }) => { info!("ProjectionCacheEntry::complete({:?}) - completing {:?}", key, ty); let mut ty = ty.clone(); if result.must_apply_considering_regions() { diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 40b2588388d66..0417f375588cc 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -438,18 +438,18 @@ impl LintStore { return CheckLintNameResult::Tool(Ok(&lint_ids)); } }, - Some(&Id(ref id)) => return CheckLintNameResult::Tool(Ok(slice::from_ref(id))), + Some(Id(id)) => return CheckLintNameResult::Tool(Ok(slice::from_ref(id))), // If the lint was registered as removed or renamed by the lint tool, we don't need // to treat tool_lints and rustc lints different and can use the code below. _ => {} } } match self.by_name.get(&complete_name) { - Some(&Renamed(ref new_name, _)) => CheckLintNameResult::Warning( + Some(Renamed(new_name, _)) => CheckLintNameResult::Warning( format!("lint `{}` has been renamed to `{}`", complete_name, new_name), Some(new_name.to_owned()), ), - Some(&Removed(ref reason)) => CheckLintNameResult::Warning( + Some(Removed(reason)) => CheckLintNameResult::Warning( format!("lint `{}` has been removed: {}", complete_name, reason), None, ), @@ -470,7 +470,7 @@ impl LintStore { CheckLintNameResult::Ok(&lint_ids) } }, - Some(&Id(ref id)) => CheckLintNameResult::Ok(slice::from_ref(id)), + Some(Id(id)) => CheckLintNameResult::Ok(slice::from_ref(id)), Some(&Ignored) => CheckLintNameResult::Ok(&[]), } } @@ -513,7 +513,7 @@ impl LintStore { CheckLintNameResult::Tool(Err((Some(&lint_ids), complete_name))) } }, - Some(&Id(ref id)) => { + Some(Id(id)) => { CheckLintNameResult::Tool(Err((Some(slice::from_ref(id)), complete_name))) } Some(other) => { diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index d628a18dd01c5..3b8df61a0eab7 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -1279,7 +1279,7 @@ impl UnusedImportBraces { fn check_use_tree(&self, cx: &EarlyContext<'_>, use_tree: &ast::UseTree, item: &ast::Item) { if let ast::UseTreeKind::Nested(ref items) = use_tree.kind { // Recursively check nested UseTrees - for &(ref tree, _) in items { + for (tree, _) in items { self.check_use_tree(cx, tree, item); } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 856f5bc4645fd..96f15a6f758f2 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1849,7 +1849,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { // the assumption that they are numbered 1 to n. // FIXME (#2166): This is not nearly enough to support correct versioning // but is enough to get transitive crate dependencies working. - self.lazy_array(deps.iter().map(|&(_, ref dep)| dep)) + self.lazy_array(deps.iter().map(|(_, dep)| dep)) } fn encode_lib_features(&mut self) -> LazyArray<(Symbol, Option)> { @@ -1986,7 +1986,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { self.lazy_array( exported_symbols .iter() - .filter(|&&(ref exported_symbol, _)| match *exported_symbol { + .filter(|&(exported_symbol, _)| match *exported_symbol { ExportedSymbol::NoDefId(symbol_name) => symbol_name != metadata_symbol_name, _ => true, }) diff --git a/compiler/rustc_middle/src/mir/tcx.rs b/compiler/rustc_middle/src/mir/tcx.rs index e3ca1f41d7ea1..1e289fc4abec3 100644 --- a/compiler/rustc_middle/src/mir/tcx.rs +++ b/compiler/rustc_middle/src/mir/tcx.rs @@ -235,7 +235,7 @@ impl<'tcx> Operand<'tcx> { { match self { &Operand::Copy(ref l) | &Operand::Move(ref l) => l.ty(local_decls, tcx).ty, - &Operand::Constant(ref c) => c.literal.ty(), + Operand::Constant(c) => c.literal.ty(), } } } diff --git a/compiler/rustc_middle/src/ty/flags.rs b/compiler/rustc_middle/src/ty/flags.rs index d283ccc3ad8a2..042b89bc4b01f 100644 --- a/compiler/rustc_middle/src/ty/flags.rs +++ b/compiler/rustc_middle/src/ty/flags.rs @@ -95,7 +95,7 @@ impl FlagComputation { self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE); } - &ty::Generator(_, ref substs, _) => { + ty::Generator(_, substs, _) => { let substs = substs.as_generator(); let should_remove_further_specializable = !self.flags.contains(TypeFlags::STILL_FURTHER_SPECIALIZABLE); @@ -186,7 +186,7 @@ impl FlagComputation { &ty::Slice(tt) => self.add_ty(tt), - &ty::RawPtr(ref m) => { + ty::RawPtr(m) => { self.add_ty(m.ty); } diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index c4116558bd27b..4d34ca3d66b5f 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -428,7 +428,7 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>( Ok(a) } - (&ty::Param(ref a_p), &ty::Param(ref b_p)) if a_p.index == b_p.index => Ok(a), + (ty::Param(a_p), ty::Param(b_p)) if a_p.index == b_p.index => Ok(a), (ty::Placeholder(p1), ty::Placeholder(p2)) if p1 == p2 => Ok(a), diff --git a/compiler/rustc_mir_build/src/build/matches/test.rs b/compiler/rustc_mir_build/src/build/matches/test.rs index 65a027111d789..6c10704c5db51 100644 --- a/compiler/rustc_mir_build/src/build/matches/test.rs +++ b/compiler/rustc_mir_build/src/build/matches/test.rs @@ -551,16 +551,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // // FIXME(#29623) we could use PatKind::Range to rule // things out here, in some cases. - ( - &TestKind::SwitchInt { switch_ty: _, ref options }, - &PatKind::Constant { ref value }, - ) if is_switch_ty(match_pair.pattern.ty) => { + (TestKind::SwitchInt { switch_ty: _, options }, PatKind::Constant { value }) + if is_switch_ty(match_pair.pattern.ty) => + { let index = options.get_index_of(value).unwrap(); self.candidate_without_match_pair(match_pair_index, candidate); Some(index) } - (&TestKind::SwitchInt { switch_ty: _, ref options }, &PatKind::Range(ref range)) => { + (TestKind::SwitchInt { switch_ty: _, options }, PatKind::Range(range)) => { let not_contained = self.values_not_contained_in_range(&*range, options).unwrap_or(false); @@ -578,7 +577,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ( &TestKind::Len { len: test_len, op: BinOp::Eq }, - &PatKind::Slice { ref prefix, ref slice, ref suffix }, + PatKind::Slice { prefix, slice, suffix }, ) => { let pat_len = (prefix.len() + suffix.len()) as u64; match (test_len.cmp(&pat_len), slice) { @@ -615,7 +614,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ( &TestKind::Len { len: test_len, op: BinOp::Ge }, - &PatKind::Slice { ref prefix, ref slice, ref suffix }, + PatKind::Slice { prefix, slice, suffix }, ) => { // the test is `$actual_len >= test_len` let pat_len = (prefix.len() + suffix.len()) as u64; @@ -651,7 +650,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } - (&TestKind::Range(ref test), &PatKind::Range(ref pat)) => { + (TestKind::Range(test), PatKind::Range(pat)) => { use std::cmp::Ordering::*; if test == pat { @@ -678,7 +677,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { no_overlap } - (&TestKind::Range(ref range), &PatKind::Constant { value }) => { + (TestKind::Range(range), &PatKind::Constant { value }) => { if let Some(false) = self.const_range_contains(&*range, value) { // `value` is not contained in the testing range, // so `value` can be matched only if this test fails. diff --git a/compiler/rustc_passes/src/hir_stats.rs b/compiler/rustc_passes/src/hir_stats.rs index a7854cd49988f..272386f313e8d 100644 --- a/compiler/rustc_passes/src/hir_stats.rs +++ b/compiler/rustc_passes/src/hir_stats.rs @@ -121,7 +121,7 @@ impl<'k> StatCollector<'k> { fn print(&self, title: &str, prefix: &str) { let mut nodes: Vec<_> = self.nodes.iter().collect(); - nodes.sort_by_key(|&(_, ref node)| node.stats.count * node.stats.size); + nodes.sort_by_key(|(_, node)| node.stats.count * node.stats.size); let total_size = nodes.iter().map(|(_, node)| node.stats.count * node.stats.size).sum(); @@ -147,7 +147,7 @@ impl<'k> StatCollector<'k> { ); if !node.subnodes.is_empty() { let mut subnodes: Vec<_> = node.subnodes.iter().collect(); - subnodes.sort_by_key(|&(_, ref subnode)| subnode.count * subnode.size); + subnodes.sort_by_key(|(_, subnode)| subnode.count * subnode.size); for (label, subnode) in subnodes { let size = subnode.count * subnode.size; diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index f4a6a08df1c85..cf63599626866 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -576,7 +576,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { // Ensure there is at most one `self` in the list let self_spans = items .iter() - .filter_map(|&(ref use_tree, _)| { + .filter_map(|(use_tree, _)| { if let ast::UseTreeKind::Simple(..) = use_tree.kind { if use_tree.ident().name == kw::SelfLower { return Some(use_tree.span); diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index fdd883fbeed5a..01a9b1000882b 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1323,7 +1323,7 @@ pub fn build_session( let warnings_allow = sopts .lint_opts .iter() - .rfind(|&&(ref key, _)| *key == "warnings") + .rfind(|&(key, _)| *key == "warnings") .map_or(false, |&(_, level)| level == lint::Allow); let cap_lints_allow = sopts.lint_cap.map_or(false, |cap| cap == lint::Allow); let can_emit_warnings = !(warnings_allow || cap_lints_allow); diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 2dd2c568bab97..d0c842a0b890b 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -226,7 +226,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> { let arg_length = arguments.len(); let distinct = matches!(other, &[ArgKind::Tuple(..)]); match (arg_length, arguments.get(0)) { - (1, Some(&ArgKind::Tuple(_, ref fields))) => { + (1, Some(ArgKind::Tuple(_, fields))) => { format!("a single {}-tuple as argument", fields.len()) } _ => format!( From 8348e05644777d08d1fa3d245f9be4040e6dcb16 Mon Sep 17 00:00:00 2001 From: Albert Larsan <74931857+albertlarsan68@users.noreply.github.com> Date: Sun, 18 Dec 2022 18:07:48 +0100 Subject: [PATCH 7/7] Make x use the x and x.ps1 scripts This removes another python search from bootstrap. --- src/tools/x/src/main.rs | 72 ++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 40 deletions(-) diff --git a/src/tools/x/src/main.rs b/src/tools/x/src/main.rs index 02c364dabf960..f07ff43efe987 100644 --- a/src/tools/x/src/main.rs +++ b/src/tools/x/src/main.rs @@ -1,51 +1,43 @@ -//! Run `x.py` from any subdirectory of a rust compiler checkout. +//! Run bootstrap from any subdirectory of a rust compiler checkout. //! //! We prefer `exec`, to avoid adding an extra process in the process tree. //! However, since `exec` isn't available on Windows, we indirect through //! `exec_or_status`, which will call `exec` on unix and `status` on Windows. //! -//! We use `python`, `python3`, or `python2` as the python interpreter to run -//! `x.py`, in that order of preference. +//! We use `powershell.exe x.ps1` on Windows, and `sh -c x` on Unix, those are +//! the ones that call `x.py`. We use `sh -c` on Unix, because it is a standard. +//! We also don't use `pwsh` on Windows, because it is not installed by default; use std::{ - env::{self, consts::EXE_EXTENSION}, - io, + env, io, + path::Path, process::{self, Command, ExitStatus}, }; -const PYTHON: &str = "python"; -const PYTHON2: &str = "python2"; -const PYTHON3: &str = "python3"; - -fn python() -> &'static str { - let val = match env::var_os("PATH") { - Some(val) => val, - None => return PYTHON, - }; - - let mut python2 = false; - let mut python3 = false; - - for dir in env::split_paths(&val) { - // `python` should always take precedence over python2 / python3 if it exists - if dir.join(PYTHON).with_extension(EXE_EXTENSION).exists() { - return PYTHON; - } +#[cfg(windows)] +fn x_command(dir: &Path) -> Command { + let mut cmd = Command::new("powershell.exe"); + cmd.args([ + "-NoLogo", + "-NoProfile", + "-NonInteractive", + "-ExecutionPolicy", + "RemoteSigned", + "-Command", + "./x.ps1", + ]) + .current_dir(dir); + cmd +} - python2 |= dir.join(PYTHON2).with_extension(EXE_EXTENSION).exists(); - python3 |= dir.join(PYTHON3).with_extension(EXE_EXTENSION).exists(); - } +#[cfg(unix)] +fn x_command(dir: &Path) -> Command { + Command::new(dir.join("x")) +} - // try 3 before 2 - if python3 { - PYTHON3 - } else if python2 { - PYTHON2 - } else { - // Python was not found on path, so exit - eprintln!("Unable to find python in your PATH. Please check it is installed."); - process::exit(1); - } +#[cfg(not(any(windows, unix)))] +fn x_command(_dir: &Path) -> Command { + compile_error!("Unsupported platform"); } #[cfg(unix)] @@ -72,15 +64,15 @@ fn main() { let candidate = dir.join("x.py"); if candidate.exists() { - let mut python = Command::new(python()); + let mut cmd = x_command(dir); - python.arg(&candidate).args(env::args().skip(1)).current_dir(dir); + cmd.args(env::args().skip(1)).current_dir(dir); - let result = exec_or_status(&mut python); + let result = exec_or_status(&mut cmd); match result { Err(error) => { - eprintln!("Failed to invoke `{}`: {}", candidate.display(), error); + eprintln!("Failed to invoke `{:?}`: {}", cmd, error); } Ok(status) => { process::exit(status.code().unwrap_or(1));