diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 5c5b1239fea77..7a925705806fc 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -563,11 +563,11 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { } = move_spans && can_suggest_clone { - self.suggest_cloning(err, ty, expr, None, Some(move_spans)); + self.suggest_cloning(err, ty, expr, Some(move_spans)); } else if self.suggest_hoisting_call_outside_loop(err, expr) && can_suggest_clone { // The place where the type moves would be misleading to suggest clone. // #121466 - self.suggest_cloning(err, ty, expr, None, Some(move_spans)); + self.suggest_cloning(err, ty, expr, Some(move_spans)); } } @@ -1229,8 +1229,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { &self, err: &mut Diag<'_>, ty: Ty<'tcx>, - mut expr: &'tcx hir::Expr<'tcx>, - mut other_expr: Option<&'tcx hir::Expr<'tcx>>, + expr: &'tcx hir::Expr<'tcx>, use_spans: Option>, ) { if let hir::ExprKind::Struct(_, _, Some(_)) = expr.kind { @@ -1242,66 +1241,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { return; } - if let Some(some_other_expr) = other_expr - && let Some(parent_binop) = - self.infcx.tcx.hir().parent_iter(expr.hir_id).find_map(|n| { - if let (hir_id, hir::Node::Expr(e)) = n - && let hir::ExprKind::AssignOp(_binop, target, _arg) = e.kind - && target.hir_id == expr.hir_id - { - Some(hir_id) - } else { - None - } - }) - && let Some(other_parent_binop) = - self.infcx.tcx.hir().parent_iter(some_other_expr.hir_id).find_map(|n| { - if let (hir_id, hir::Node::Expr(expr)) = n - && let hir::ExprKind::AssignOp(..) = expr.kind - { - Some(hir_id) - } else { - None - } - }) - && parent_binop == other_parent_binop - { - // Explicitly look for `expr += other_expr;` and avoid suggesting - // `expr.clone() += other_expr;`, instead suggesting `expr += other_expr.clone();`. - other_expr = Some(expr); - expr = some_other_expr; - } - 'outer: { - if let ty::Ref(..) = ty.kind() { - // We check for either `let binding = foo(expr, other_expr);` or - // `foo(expr, other_expr);` and if so we don't suggest an incorrect - // `foo(expr, other_expr).clone()` - if let Some(other_expr) = other_expr - && let Some(parent_let) = - self.infcx.tcx.hir().parent_iter(expr.hir_id).find_map(|n| { - if let (hir_id, hir::Node::LetStmt(_) | hir::Node::Stmt(_)) = n { - Some(hir_id) - } else { - None - } - }) - && let Some(other_parent_let) = - self.infcx.tcx.hir().parent_iter(other_expr.hir_id).find_map(|n| { - if let (hir_id, hir::Node::LetStmt(_) | hir::Node::Stmt(_)) = n { - Some(hir_id) - } else { - None - } - }) - && parent_let == other_parent_let - { - // Explicitly check that we don't have `foo(&*expr, other_expr)`, as cloning the - // result of `foo(...)` won't help. - break 'outer; - } - } - } - let ty = ty.peel_refs(); if self.implements_clone(ty) { self.suggest_cloning_inner(err, ty, expr); } else if let ty::Adt(def, args) = ty.kind() @@ -1573,10 +1512,27 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { ); self.suggest_copy_for_type_in_cloned_ref(&mut err, place); let typeck_results = self.infcx.tcx.typeck(self.mir_def_id()); - if let Some(expr) = self.find_expr(borrow_span) - && let Some(ty) = typeck_results.node_type_opt(expr.hir_id) - { - self.suggest_cloning(&mut err, ty, expr, self.find_expr(span), Some(move_spans)); + if let Some(expr) = self.find_expr(borrow_span) { + // This is a borrow span, so we want to suggest cloning the referent. + if let hir::ExprKind::AddrOf(_, _, borrowed_expr) = expr.kind + && let Some(ty) = typeck_results.expr_ty_opt(borrowed_expr) + { + self.suggest_cloning(&mut err, ty, borrowed_expr, Some(move_spans)); + } else if typeck_results.expr_adjustments(expr).first().is_some_and(|adj| { + matches!( + adj.kind, + ty::adjustment::Adjust::Borrow(ty::adjustment::AutoBorrow::Ref( + _, + ty::adjustment::AutoBorrowMutability::Not + | ty::adjustment::AutoBorrowMutability::Mut { + allow_two_phase_borrow: ty::adjustment::AllowTwoPhase::No + } + )) + ) + }) && let Some(ty) = typeck_results.expr_ty_opt(expr) + { + self.suggest_cloning(&mut err, ty, expr, Some(move_spans)); + } } self.buffer_error(err); } diff --git a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs index 636ae7b626809..792f1548e081e 100644 --- a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs @@ -564,9 +564,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { fn add_move_hints(&self, error: GroupedMoveError<'tcx>, err: &mut Diag<'_>, span: Span) { match error { - GroupedMoveError::MovesFromPlace { - mut binds_to, move_from, span: other_span, .. - } => { + GroupedMoveError::MovesFromPlace { mut binds_to, move_from, .. } => { self.add_borrow_suggestions(err, span); if binds_to.is_empty() { let place_ty = move_from.ty(self.body, self.infcx.tcx).ty; @@ -576,7 +574,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { }; if let Some(expr) = self.find_expr(span) { - self.suggest_cloning(err, place_ty, expr, self.find_expr(other_span), None); + self.suggest_cloning(err, place_ty, expr, None); } err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label { @@ -608,13 +606,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { }; if let Some(expr) = self.find_expr(use_span) { - self.suggest_cloning( - err, - place_ty, - expr, - self.find_expr(span), - Some(use_spans), - ); + self.suggest_cloning(err, place_ty, expr, Some(use_spans)); } err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label { @@ -739,7 +731,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { let place_desc = &format!("`{}`", self.local_names[*local].unwrap()); if let Some(expr) = self.find_expr(binding_span) { - self.suggest_cloning(err, bind_to.ty, expr, None, None); + self.suggest_cloning(err, bind_to.ty, expr, None); } err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label { diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index 987dbf6db630a..7e4feb0a82716 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -700,10 +700,10 @@ lint_reason_must_be_string_literal = reason must be a string literal lint_reason_must_come_last = reason in lint attribute must come last lint_redundant_import = the item `{$ident}` is imported redundantly - .label_imported_here = the item `{ident}` is already imported here - .label_defined_here = the item `{ident}` is already defined here - .label_imported_prelude = the item `{ident}` is already imported by the extern prelude - .label_defined_prelude = the item `{ident}` is already defined by the extern prelude + .label_imported_here = the item `{$ident}` is already imported here + .label_defined_here = the item `{$ident}` is already defined here + .label_imported_prelude = the item `{$ident}` is already imported by the extern prelude + .label_defined_prelude = the item `{$ident}` is already defined by the extern prelude lint_redundant_import_visibility = glob import doesn't reexport anything with visibility `{$import_vis}` because no imported item is public enough .note = the most public imported item is `{$max_vis}` diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index ca61132e24970..7172a47fb854d 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -82,6 +82,7 @@ declare_lint_pass! { PROC_MACRO_DERIVE_RESOLUTION_FALLBACK, PTR_CAST_ADD_AUTO_TO_OBJECT, PUB_USE_OF_PRIVATE_EXTERN_CRATE, + REDUNDANT_IMPORTS, REDUNDANT_LIFETIMES, REFINING_IMPL_TRAIT_INTERNAL, REFINING_IMPL_TRAIT_REACHABLE, @@ -426,6 +427,31 @@ declare_lint! { "imports that are never used" } +declare_lint! { + /// The `redundant_imports` lint detects imports that are redundant due to being + /// imported already; either through a previous import, or being present in + /// the prelude. + /// + /// ### Example + /// + /// ```rust,compile_fail + /// #![deny(redundant_imports)] + /// use std::option::Option::None; + /// fn foo() -> Option { None } + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// Redundant imports are unnecessary and can be removed to simplify code. + /// If you intended to re-export the item to make it available outside of the + /// module, add a visibility modifier like `pub`. + pub REDUNDANT_IMPORTS, + Allow, + "imports that are redundant due to being imported already" +} + declare_lint! { /// The `must_not_suspend` lint guards against values that shouldn't be held across suspend points /// (`.await`) diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs index 6c34978a29c96..cae4aa7bad3d2 100644 --- a/compiler/rustc_mir_build/src/build/matches/mod.rs +++ b/compiler/rustc_mir_build/src/build/matches/mod.rs @@ -17,7 +17,6 @@ use rustc_span::symbol::Symbol; use rustc_span::{BytePos, Pos, Span}; use rustc_target::abi::VariantIdx; use tracing::{debug, instrument}; -use util::visit_bindings; use crate::build::expr::as_place::PlaceBuilder; use crate::build::scope::DropKind; @@ -366,28 +365,22 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let scrutinee_place = unpack!(block = self.lower_scrutinee(block, scrutinee_id, scrutinee_span)); - let mut arm_candidates = self.create_match_candidates(&scrutinee_place, arms); - - let match_has_guard = arm_candidates.iter().any(|(_, candidate)| candidate.has_guard); - let mut candidates = - arm_candidates.iter_mut().map(|(_, candidate)| candidate).collect::>(); - + let arms = arms.iter().map(|arm| &self.thir[*arm]); let match_start_span = span.shrink_to_lo().to(scrutinee_span); - - // The set of places that we are creating fake borrows of. If there are no match guards then - // we don't need any fake borrows, so don't track them. - let fake_borrow_temps: Vec<(Place<'tcx>, Local, FakeBorrowKind)> = if match_has_guard { - util::collect_fake_borrows(self, &candidates, scrutinee_span, scrutinee_place.base()) - } else { - Vec::new() - }; - - self.lower_match_tree( + let patterns = arms + .clone() + .map(|arm| { + let has_match_guard = + if arm.guard.is_some() { HasMatchGuard::Yes } else { HasMatchGuard::No }; + (&*arm.pattern, has_match_guard) + }) + .collect(); + let built_tree = self.lower_match_tree( block, scrutinee_span, &scrutinee_place, match_start_span, - &mut candidates, + patterns, false, ); @@ -395,9 +388,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { destination, scrutinee_place, scrutinee_span, - arm_candidates, + arms, + built_tree, self.source_info(span), - fake_borrow_temps, ) } @@ -417,51 +410,29 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block.and(scrutinee_place_builder) } - /// Create the initial `Candidate`s for a `match` expression. - fn create_match_candidates<'pat>( - &mut self, - scrutinee: &PlaceBuilder<'tcx>, - arms: &'pat [ArmId], - ) -> Vec<(&'pat Arm<'tcx>, Candidate<'pat, 'tcx>)> - where - 'a: 'pat, - { - // Assemble the initial list of candidates. These top-level candidates - // are 1:1 with the original match arms, but other parts of match - // lowering also introduce subcandidates (for subpatterns), and will - // also flatten candidates in some cases. So in general a list of - // candidates does _not_ necessarily correspond to a list of arms. - arms.iter() - .copied() - .map(|arm| { - let arm = &self.thir[arm]; - let arm_has_guard = arm.guard.is_some(); - let arm_candidate = - Candidate::new(scrutinee.clone(), &arm.pattern, arm_has_guard, self); - (arm, arm_candidate) - }) - .collect() - } - /// Lower the bindings, guards and arm bodies of a `match` expression. /// /// The decision tree should have already been created /// (by [Builder::lower_match_tree]). /// /// `outer_source_info` is the SourceInfo for the whole match. - fn lower_match_arms( + fn lower_match_arms<'pat>( &mut self, destination: Place<'tcx>, scrutinee_place_builder: PlaceBuilder<'tcx>, scrutinee_span: Span, - arm_candidates: Vec<(&'_ Arm<'tcx>, Candidate<'_, 'tcx>)>, + arms: impl IntoIterator>, + built_match_tree: BuiltMatchTree<'tcx>, outer_source_info: SourceInfo, - fake_borrow_temps: Vec<(Place<'tcx>, Local, FakeBorrowKind)>, - ) -> BlockAnd<()> { - let arm_end_blocks: Vec = arm_candidates + ) -> BlockAnd<()> + where + 'tcx: 'pat, + { + let arm_end_blocks: Vec = arms .into_iter() - .map(|(arm, candidate)| { - debug!("lowering arm {:?}\ncandidate = {:?}", arm, candidate); + .zip(built_match_tree.branches) + .map(|(arm, branch)| { + debug!("lowering arm {:?}\ncorresponding branch = {:?}", arm, branch); let arm_source_info = self.source_info(arm.span); let arm_scope = (arm.scope, arm_source_info); @@ -494,8 +465,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let arm_block = this.bind_pattern( outer_source_info, - candidate, - &fake_borrow_temps, + branch, + &built_match_tree.fake_borrow_temps, scrutinee_span, Some((arm, match_scope)), EmitStorageLive::Yes, @@ -548,18 +519,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { fn bind_pattern( &mut self, outer_source_info: SourceInfo, - candidate: Candidate<'_, 'tcx>, + branch: MatchTreeBranch<'tcx>, fake_borrow_temps: &[(Place<'tcx>, Local, FakeBorrowKind)], scrutinee_span: Span, arm_match_scope: Option<(&Arm<'tcx>, region::Scope)>, emit_storage_live: EmitStorageLive, ) -> BasicBlock { - if candidate.subcandidates.is_empty() { - // Avoid generating another `BasicBlock` when we only have one - // candidate. + if branch.sub_branches.len() == 1 { + let [sub_branch] = branch.sub_branches.try_into().unwrap(); + // Avoid generating another `BasicBlock` when we only have one sub branch. self.bind_and_guard_matched_candidate( - candidate, - &[], + sub_branch, fake_borrow_temps, scrutinee_span, arm_match_scope, @@ -587,35 +557,23 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // We keep a stack of all of the bindings and type ascriptions // from the parent candidates that we visit, that also need to // be bound for each candidate. - traverse_candidate( - candidate, - &mut Vec::new(), - &mut |leaf_candidate, parent_data| { - if let Some(arm) = arm { - self.clear_top_scope(arm.scope); - } - let binding_end = self.bind_and_guard_matched_candidate( - leaf_candidate, - parent_data, - fake_borrow_temps, - scrutinee_span, - arm_match_scope, - schedule_drops, - emit_storage_live, - ); - if arm.is_none() { - schedule_drops = ScheduleDrops::No; - } - self.cfg.goto(binding_end, outer_source_info, target_block); - }, - |inner_candidate, parent_data| { - parent_data.push(inner_candidate.extra_data); - inner_candidate.subcandidates.into_iter() - }, - |parent_data| { - parent_data.pop(); - }, - ); + for sub_branch in branch.sub_branches { + if let Some(arm) = arm { + self.clear_top_scope(arm.scope); + } + let binding_end = self.bind_and_guard_matched_candidate( + sub_branch, + fake_borrow_temps, + scrutinee_span, + arm_match_scope, + schedule_drops, + emit_storage_live, + ); + if arm.is_none() { + schedule_drops = ScheduleDrops::No; + } + self.cfg.goto(binding_end, outer_source_info, target_block); + } target_block } @@ -725,7 +683,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { initializer: PlaceBuilder<'tcx>, set_match_place: bool, ) -> BlockAnd<()> { - let mut candidate = Candidate::new(initializer.clone(), irrefutable_pat, false, self); + let built_tree = self.lower_match_tree( + block, + irrefutable_pat.span, + &initializer, + irrefutable_pat.span, + vec![(irrefutable_pat, HasMatchGuard::No)], + false, + ); + let [branch] = built_tree.branches.try_into().unwrap(); // For matches and function arguments, the place that is being matched // can be set when creating the variables. But the place for @@ -746,7 +712,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // }; // ``` if let Some(place) = initializer.try_to_place(self) { - visit_bindings(&[&mut candidate], |binding: &Binding<'_>| { + // Because or-alternatives bind the same variables, we only explore the first one. + let first_sub_branch = branch.sub_branches.first().unwrap(); + for binding in &first_sub_branch.bindings { let local = self.var_local_id(binding.var_id, OutsideGuard); if let LocalInfo::User(BindingForm::Var(VarBindingForm { opt_match_place: Some((ref mut match_place, _)), @@ -757,21 +725,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } else { bug!("Let binding to non-user variable.") }; - }); + } } } - self.lower_match_tree( - block, - irrefutable_pat.span, - &initializer, - irrefutable_pat.span, - &mut [&mut candidate], - false, - ); self.bind_pattern( self.source_info(irrefutable_pat.span), - candidate, + branch, &[], irrefutable_pat.span, None, @@ -1152,20 +1112,21 @@ struct Candidate<'pat, 'tcx> { /// The earliest block that has only candidates >= this one as descendents. Used for false /// edges, see the doc for [`Builder::match_expr`]. false_edge_start_block: Option, - /// The `false_edge_start_block` of the next candidate. - next_candidate_start_block: Option, } impl<'tcx, 'pat> Candidate<'pat, 'tcx> { fn new( place: PlaceBuilder<'tcx>, pattern: &'pat Pat<'tcx>, - has_guard: bool, + has_guard: HasMatchGuard, cx: &mut Builder<'_, 'tcx>, ) -> Self { // Use `FlatPat` to build simplified match pairs, then immediately // incorporate them into a new candidate. - Self::from_flat_pat(FlatPat::new(place, pattern, cx), has_guard) + Self::from_flat_pat( + FlatPat::new(place, pattern, cx), + matches!(has_guard, HasMatchGuard::Yes), + ) } /// Incorporates an already-simplified [`FlatPat`] into a new candidate. @@ -1179,7 +1140,6 @@ impl<'tcx, 'pat> Candidate<'pat, 'tcx> { otherwise_block: None, pre_binding_block: None, false_edge_start_block: None, - next_candidate_start_block: None, } } @@ -1199,6 +1159,17 @@ impl<'tcx, 'pat> Candidate<'pat, 'tcx> { |_| {}, ); } + + /// Visit the leaf candidates in reverse order. + fn visit_leaves_rev<'a>(&'a mut self, mut visit_leaf: impl FnMut(&'a mut Self)) { + traverse_candidate( + self, + &mut (), + &mut move |c, _| visit_leaf(c), + move |c, _| c.subcandidates.iter_mut().rev(), + |_| {}, + ); + } } /// A depth-first traversal of the `Candidate` and all of its recursive @@ -1409,12 +1380,114 @@ pub(crate) struct ArmHasGuard(pub(crate) bool); /////////////////////////////////////////////////////////////////////////// // Main matching algorithm +/// A sub-branch in the output of match lowering. Match lowering has generated MIR code that will +/// branch to `success_block` when the matched value matches the corresponding pattern. If there is +/// a guard, its failure must continue to `otherwise_block`, which will resume testing patterns. +#[derive(Debug)] +struct MatchTreeSubBranch<'tcx> { + span: Span, + /// The block that is branched to if the corresponding subpattern matches. + success_block: BasicBlock, + /// The block to branch to if this arm had a guard and the guard fails. + otherwise_block: BasicBlock, + /// The bindings to set up in this sub-branch. + bindings: Vec>, + /// The ascriptions to set up in this sub-branch. + ascriptions: Vec>, + /// Whether the sub-branch corresponds to a never pattern. + is_never: bool, +} + +/// A branch in the output of match lowering. +#[derive(Debug)] +struct MatchTreeBranch<'tcx> { + sub_branches: Vec>, +} + +/// The result of generating MIR for a pattern-matching expression. Each input branch/arm/pattern +/// gives rise to an output `MatchTreeBranch`. If one of the patterns matches, we branch to the +/// corresponding `success_block`. If none of the patterns matches, we branch to `otherwise_block`. +/// +/// Each branch is made of one of more sub-branches, corresponding to or-patterns. E.g. +/// ```ignore(illustrative) +/// match foo { +/// (x, false) | (false, x) => {} +/// (true, true) => {} +/// } +/// ``` +/// Here the first arm gives the first `MatchTreeBranch`, which has two sub-branches, one for each +/// alternative of the or-pattern. They are kept separate because each needs to bind `x` to a +/// different place. +#[derive(Debug)] +struct BuiltMatchTree<'tcx> { + branches: Vec>, + otherwise_block: BasicBlock, + /// If any of the branches had a guard, we collect here the places and locals to fakely borrow + /// to ensure match guards can't modify the values as we match them. For more details, see + /// [`util::collect_fake_borrows`]. + fake_borrow_temps: Vec<(Place<'tcx>, Local, FakeBorrowKind)>, +} + +impl<'tcx> MatchTreeSubBranch<'tcx> { + fn from_sub_candidate( + candidate: Candidate<'_, 'tcx>, + parent_data: &Vec>, + ) -> Self { + debug_assert!(candidate.match_pairs.is_empty()); + MatchTreeSubBranch { + span: candidate.extra_data.span, + success_block: candidate.pre_binding_block.unwrap(), + otherwise_block: candidate.otherwise_block.unwrap(), + bindings: parent_data + .iter() + .flat_map(|d| &d.bindings) + .chain(&candidate.extra_data.bindings) + .cloned() + .collect(), + ascriptions: parent_data + .iter() + .flat_map(|d| &d.ascriptions) + .cloned() + .chain(candidate.extra_data.ascriptions) + .collect(), + is_never: candidate.extra_data.is_never, + } + } +} + +impl<'tcx> MatchTreeBranch<'tcx> { + fn from_candidate(candidate: Candidate<'_, 'tcx>) -> Self { + let mut sub_branches = Vec::new(); + traverse_candidate( + candidate, + &mut Vec::new(), + &mut |candidate: Candidate<'_, '_>, parent_data: &mut Vec>| { + sub_branches.push(MatchTreeSubBranch::from_sub_candidate(candidate, parent_data)); + }, + |inner_candidate, parent_data| { + parent_data.push(inner_candidate.extra_data); + inner_candidate.subcandidates.into_iter() + }, + |parent_data| { + parent_data.pop(); + }, + ); + MatchTreeBranch { sub_branches } + } +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +enum HasMatchGuard { + Yes, + No, +} + impl<'a, 'tcx> Builder<'a, 'tcx> { /// The entrypoint of the matching algorithm. Create the decision tree for the match expression, /// starting from `block`. /// - /// Modifies `candidates` to store the bindings and type ascriptions for - /// that candidate. + /// `patterns` is a list of patterns, one for each arm. The associated boolean indicates whether + /// the arm has a guard. /// /// `refutable` indicates whether the candidate list is refutable (for `if let` and `let else`) /// or not (for `let` and `match`). In the refutable case we return the block to which we branch @@ -1425,31 +1498,76 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { scrutinee_span: Span, scrutinee_place_builder: &PlaceBuilder<'tcx>, match_start_span: Span, - candidates: &mut [&mut Candidate<'pat, 'tcx>], + patterns: Vec<(&'pat Pat<'tcx>, HasMatchGuard)>, refutable: bool, - ) -> BasicBlock { + ) -> BuiltMatchTree<'tcx> + where + 'tcx: 'pat, + { + // Assemble the initial list of candidates. These top-level candidates are 1:1 with the + // input patterns, but other parts of match lowering also introduce subcandidates (for + // sub-or-patterns). So inside the algorithm, the candidates list may not correspond to + // match arms directly. + let mut candidates: Vec> = patterns + .into_iter() + .map(|(pat, has_guard)| { + Candidate::new(scrutinee_place_builder.clone(), pat, has_guard, self) + }) + .collect(); + + let fake_borrow_temps = util::collect_fake_borrows( + self, + &candidates, + scrutinee_span, + scrutinee_place_builder.base(), + ); + // This will generate code to test scrutinee_place and branch to the appropriate arm block. - // See the doc comment on `match_candidates` for why we have an otherwise block. + // If none of the arms match, we branch to `otherwise_block`. When lowering a `match` + // expression, exhaustiveness checking ensures that this block is unreachable. + let mut candidate_refs = candidates.iter_mut().collect::>(); let otherwise_block = - self.match_candidates(match_start_span, scrutinee_span, block, candidates); - - // Link each leaf candidate to the `false_edge_start_block` of the next one. - let mut previous_candidate: Option<&mut Candidate<'_, '_>> = None; - for candidate in candidates { - candidate.visit_leaves(|leaf_candidate| { - if let Some(ref mut prev) = previous_candidate { - assert!(leaf_candidate.false_edge_start_block.is_some()); - prev.next_candidate_start_block = leaf_candidate.false_edge_start_block; + self.match_candidates(match_start_span, scrutinee_span, block, &mut candidate_refs); + + // Set up false edges so that the borrow-checker cannot make use of the specific CFG we + // generated. We falsely branch from each candidate to the one below it to make it as if we + // were testing match branches one by one in order. In the refutable case we also want a + // false edge to the final failure block. + let mut next_candidate_start_block = if refutable { Some(otherwise_block) } else { None }; + for candidate in candidates.iter_mut().rev() { + let has_guard = candidate.has_guard; + candidate.visit_leaves_rev(|leaf_candidate| { + if let Some(next_candidate_start_block) = next_candidate_start_block { + let source_info = self.source_info(leaf_candidate.extra_data.span); + // Falsely branch to `next_candidate_start_block` before reaching pre_binding. + let old_pre_binding = leaf_candidate.pre_binding_block.unwrap(); + let new_pre_binding = self.cfg.start_new_block(); + self.false_edges( + old_pre_binding, + new_pre_binding, + next_candidate_start_block, + source_info, + ); + leaf_candidate.pre_binding_block = Some(new_pre_binding); + if has_guard { + // Falsely branch to `next_candidate_start_block` also if the guard fails. + let new_otherwise = self.cfg.start_new_block(); + let old_otherwise = leaf_candidate.otherwise_block.unwrap(); + self.false_edges( + new_otherwise, + old_otherwise, + next_candidate_start_block, + source_info, + ); + leaf_candidate.otherwise_block = Some(new_otherwise); + } } - previous_candidate = Some(leaf_candidate); + assert!(leaf_candidate.false_edge_start_block.is_some()); + next_candidate_start_block = leaf_candidate.false_edge_start_block; }); } - if refutable { - // In refutable cases there's always at least one candidate, and we want a false edge to - // the failure block. - previous_candidate.as_mut().unwrap().next_candidate_start_block = Some(otherwise_block) - } else { + if !refutable { // Match checking ensures `otherwise_block` is actually unreachable in irrefutable // cases. let source_info = self.source_info(scrutinee_span); @@ -1479,7 +1597,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { self.cfg.terminate(otherwise_block, source_info, TerminatorKind::Unreachable); } - otherwise_block + BuiltMatchTree { + branches: candidates.into_iter().map(MatchTreeBranch::from_candidate).collect(), + otherwise_block, + fake_borrow_temps, + } } /// The main match algorithm. It begins with a set of candidates `candidates` and has the job of @@ -2229,17 +2351,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ) -> BlockAnd<()> { let expr_span = self.thir[expr_id].span; let scrutinee = unpack!(block = self.lower_scrutinee(block, expr_id, expr_span)); - let mut candidate = Candidate::new(scrutinee.clone(), pat, false, self); - let otherwise_block = self.lower_match_tree( + let built_tree = self.lower_match_tree( block, expr_span, &scrutinee, pat.span, - &mut [&mut candidate], + vec![(pat, HasMatchGuard::No)], true, ); + let [branch] = built_tree.branches.try_into().unwrap(); - self.break_for_else(otherwise_block, self.source_info(expr_span)); + self.break_for_else(built_tree.otherwise_block, self.source_info(expr_span)); match declare_let_bindings { DeclareLetBindings::Yes => { @@ -2261,7 +2383,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let success = self.bind_pattern( self.source_info(pat.span), - candidate, + branch, &[], expr_span, None, @@ -2269,7 +2391,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ); // If branch coverage is enabled, record this branch. - self.visit_coverage_conditional_let(pat, success, otherwise_block); + self.visit_coverage_conditional_let(pat, success, built_tree.otherwise_block); success.unit() } @@ -2282,52 +2404,28 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// Note: we do not check earlier that if there is a guard, /// there cannot be move bindings. We avoid a use-after-move by only /// moving the binding once the guard has evaluated to true (see below). - fn bind_and_guard_matched_candidate<'pat>( + fn bind_and_guard_matched_candidate( &mut self, - candidate: Candidate<'pat, 'tcx>, - parent_data: &[PatternExtraData<'tcx>], + sub_branch: MatchTreeSubBranch<'tcx>, fake_borrows: &[(Place<'tcx>, Local, FakeBorrowKind)], scrutinee_span: Span, arm_match_scope: Option<(&Arm<'tcx>, region::Scope)>, schedule_drops: ScheduleDrops, emit_storage_live: EmitStorageLive, ) -> BasicBlock { - debug!("bind_and_guard_matched_candidate(candidate={:?})", candidate); + debug!("bind_and_guard_matched_candidate(subbranch={:?})", sub_branch); - debug_assert!(candidate.match_pairs.is_empty()); - - let candidate_source_info = self.source_info(candidate.extra_data.span); - - let mut block = candidate.pre_binding_block.unwrap(); - - if candidate.next_candidate_start_block.is_some() { - let fresh_block = self.cfg.start_new_block(); - self.false_edges( - block, - fresh_block, - candidate.next_candidate_start_block, - candidate_source_info, - ); - block = fresh_block; - } + let block = sub_branch.success_block; - if candidate.extra_data.is_never { + if sub_branch.is_never { // This arm has a dummy body, we don't need to generate code for it. `block` is already // unreachable (except via false edge). - let source_info = self.source_info(candidate.extra_data.span); + let source_info = self.source_info(sub_branch.span); self.cfg.terminate(block, source_info, TerminatorKind::Unreachable); return self.cfg.start_new_block(); } - let ascriptions = parent_data - .iter() - .flat_map(|d| &d.ascriptions) - .cloned() - .chain(candidate.extra_data.ascriptions); - let bindings = - parent_data.iter().flat_map(|d| &d.bindings).chain(&candidate.extra_data.bindings); - - self.ascribe_types(block, ascriptions); + self.ascribe_types(block, sub_branch.ascriptions); // Lower an instance of the arm guard (if present) for this candidate, // and then perform bindings for the arm body. @@ -2338,9 +2436,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // Bindings for guards require some extra handling to automatically // insert implicit references/dereferences. - self.bind_matched_candidate_for_guard(block, schedule_drops, bindings.clone()); + self.bind_matched_candidate_for_guard( + block, + schedule_drops, + sub_branch.bindings.iter(), + ); let guard_frame = GuardFrame { - locals: bindings.clone().map(|b| GuardFrameLocal::new(b.var_id)).collect(), + locals: sub_branch + .bindings + .iter() + .map(|b| GuardFrameLocal::new(b.var_id)) + .collect(), }; debug!("entering guard building context: {:?}", guard_frame); self.guard_context.push(guard_frame); @@ -2376,17 +2482,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { self.cfg.push_fake_read(post_guard_block, guard_end, cause, Place::from(temp)); } - let otherwise_block = candidate.otherwise_block.unwrap_or_else(|| { - let unreachable = self.cfg.start_new_block(); - self.cfg.terminate(unreachable, source_info, TerminatorKind::Unreachable); - unreachable - }); - self.false_edges( - otherwise_post_guard_block, - otherwise_block, - candidate.next_candidate_start_block, - source_info, - ); + self.cfg.goto(otherwise_post_guard_block, source_info, sub_branch.otherwise_block); // We want to ensure that the matched candidates are bound // after we have confirmed this candidate *and* any @@ -2414,8 +2510,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // ``` // // and that is clearly not correct. - let by_value_bindings = - bindings.filter(|binding| matches!(binding.binding_mode.0, ByRef::No)); + let by_value_bindings = sub_branch + .bindings + .iter() + .filter(|binding| matches!(binding.binding_mode.0, ByRef::No)); // Read all of the by reference bindings to ensure that the // place they refer to can't be modified by the guard. for binding in by_value_bindings.clone() { @@ -2443,7 +2541,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { self.bind_matched_candidate_for_arm_body( block, schedule_drops, - bindings, + sub_branch.bindings.iter(), emit_storage_live, ); block diff --git a/compiler/rustc_mir_build/src/build/matches/util.rs b/compiler/rustc_mir_build/src/build/matches/util.rs index c80204c4ad171..8491b5fe380c7 100644 --- a/compiler/rustc_mir_build/src/build/matches/util.rs +++ b/compiler/rustc_mir_build/src/build/matches/util.rs @@ -1,5 +1,3 @@ -use std::marker::PhantomData; - use rustc_data_structures::fx::FxIndexMap; use rustc_middle::mir::*; use rustc_middle::ty::Ty; @@ -18,18 +16,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { &mut self, from_block: BasicBlock, real_target: BasicBlock, - imaginary_target: Option, + imaginary_target: BasicBlock, source_info: SourceInfo, ) { - match imaginary_target { - Some(target) if target != real_target => { - self.cfg.terminate( - from_block, - source_info, - TerminatorKind::FalseEdge { real_target, imaginary_target: target }, - ); - } - _ => self.cfg.goto(from_block, source_info, real_target), + if imaginary_target != real_target { + self.cfg.terminate( + from_block, + source_info, + TerminatorKind::FalseEdge { real_target, imaginary_target }, + ); + } else { + self.cfg.goto(from_block, source_info, real_target) } } } @@ -71,10 +68,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// a MIR pass run after borrow checking. pub(super) fn collect_fake_borrows<'tcx>( cx: &mut Builder<'_, 'tcx>, - candidates: &[&mut Candidate<'_, 'tcx>], + candidates: &[Candidate<'_, 'tcx>], temp_span: Span, scrutinee_base: PlaceBase, ) -> Vec<(Place<'tcx>, Local, FakeBorrowKind)> { + if candidates.iter().all(|candidate| !candidate.has_guard) { + // Fake borrows are only used when there is a guard. + return Vec::new(); + } let mut collector = FakeBorrowCollector { cx, scrutinee_base, fake_borrows: FxIndexMap::default() }; for candidate in candidates.iter() { @@ -222,57 +223,6 @@ impl<'a, 'b, 'tcx> FakeBorrowCollector<'a, 'b, 'tcx> { } } -/// Visit all the bindings of these candidates. Because or-alternatives bind the same variables, we -/// only explore the first one of each or-pattern. -pub(super) fn visit_bindings<'tcx>( - candidates: &[&mut Candidate<'_, 'tcx>], - f: impl FnMut(&Binding<'tcx>), -) { - let mut visitor = BindingsVisitor { f, phantom: PhantomData }; - for candidate in candidates.iter() { - visitor.visit_candidate(candidate); - } -} - -pub(super) struct BindingsVisitor<'tcx, F> { - f: F, - phantom: PhantomData<&'tcx ()>, -} - -impl<'tcx, F> BindingsVisitor<'tcx, F> -where - F: FnMut(&Binding<'tcx>), -{ - fn visit_candidate(&mut self, candidate: &Candidate<'_, 'tcx>) { - for binding in &candidate.extra_data.bindings { - (self.f)(binding) - } - for match_pair in &candidate.match_pairs { - self.visit_match_pair(match_pair); - } - } - - fn visit_flat_pat(&mut self, flat_pat: &FlatPat<'_, 'tcx>) { - for binding in &flat_pat.extra_data.bindings { - (self.f)(binding) - } - for match_pair in &flat_pat.match_pairs { - self.visit_match_pair(match_pair); - } - } - - fn visit_match_pair(&mut self, match_pair: &MatchPairTree<'_, 'tcx>) { - if let TestCase::Or { pats, .. } = &match_pair.test_case { - // All the or-alternatives should bind the same locals, so we only visit the first one. - self.visit_flat_pat(&pats[0]) - } else { - for subpair in &match_pair.subpairs { - self.visit_match_pair(subpair); - } - } - } -} - #[must_use] pub(crate) fn ref_pat_borrow_kind(ref_mutability: Mutability) -> BorrowKind { match ref_mutability { diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs index bd9d96ba573f7..999f6f0eeb0ce 100644 --- a/compiler/rustc_parse/src/parser/nonterminal.rs +++ b/compiler/rustc_parse/src/parser/nonterminal.rs @@ -39,6 +39,7 @@ impl<'a> Parser<'a> { } match kind { + // `expr_2021` and earlier NonterminalKind::Expr(Expr2021 { .. }) => { token.can_begin_expr() // This exception is here for backwards compatibility. @@ -46,8 +47,16 @@ impl<'a> Parser<'a> { // This exception is here for backwards compatibility. && !token.is_keyword(kw::Const) } + // Current edition expressions NonterminalKind::Expr(Expr) => { - token.can_begin_expr() + // In Edition 2024, `_` is considered an expression, so we + // need to allow it here because `token.can_begin_expr()` does + // not consider `_` to be an expression. + // + // Because `can_begin_expr` is used elsewhere, we need to reduce + // the scope of where the `_` is considered an expression to + // just macro parsing code. + (token.can_begin_expr() || token.is_keyword(kw::Underscore)) // This exception is here for backwards compatibility. && !token.is_keyword(kw::Let) } diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index f76fa62a0094f..0fa5cde9424b5 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -14,7 +14,7 @@ use rustc_middle::metadata::{ModChild, Reexport}; use rustc_middle::{span_bug, ty}; use rustc_session::lint::builtin::{ AMBIGUOUS_GLOB_REEXPORTS, HIDDEN_GLOB_REEXPORTS, PUB_USE_OF_PRIVATE_EXTERN_CRATE, - UNUSED_IMPORTS, + REDUNDANT_IMPORTS, UNUSED_IMPORTS, }; use rustc_session::lint::BuiltinLintDiag; use rustc_span::edit_distance::find_best_match_for_name; @@ -1387,14 +1387,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { let mut redundant_spans: Vec<_> = redundant_span.present_items().collect(); redundant_spans.sort(); redundant_spans.dedup(); - /* FIXME(unused_imports): Add this back as a new lint - self.lint_buffer.buffer_lint_with_diagnostic( - UNUSED_IMPORTS, + self.lint_buffer.buffer_lint( + REDUNDANT_IMPORTS, id, import.span, BuiltinLintDiag::RedundantImport(redundant_spans, source), ); - */ return true; } diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 6405cb82493b5..79d3bb685b384 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -178,8 +178,8 @@ enum ImplTraitContext { /// Used for tracking import use types which will be used for redundant import checking. /// ### Used::Scope Example -/// ```rust,ignore (redundant_imports) -/// #![deny(unused_imports)] +/// ```rust,compile_fail +/// #![deny(redundant_imports)] /// use std::mem::drop; /// fn main() { /// let s = Box::new(32); diff --git a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs index 37a16a43acdeb..d3a1ed52d2e62 100644 --- a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs +++ b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs @@ -42,8 +42,15 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { | ty::Foreign(..) | ty::Error(_) => true, - // `T is PAT`, `[T; N]`, and `[T]` have same properties as T. - ty::Pat(ty, _) | ty::Array(ty, _) | ty::Slice(ty) => trivial_dropck_outlives(tcx, *ty), + // `T is PAT` and `[T]` have same properties as T. + ty::Pat(ty, _) | ty::Slice(ty) => trivial_dropck_outlives(tcx, *ty), + ty::Array(ty, size) => { + // Empty array never has a dtor. See issue #110288. + match size.try_to_target_usize(tcx) { + Some(0) => true, + _ => trivial_dropck_outlives(tcx, *ty), + } + } // (T1..Tn) and closures have same properties as T1..Tn -- // check if *all* of them are trivial. diff --git a/library/std/src/sync/once_lock.rs b/library/std/src/sync/once_lock.rs index 60e43a1cde10e..f8946aa9d42f3 100644 --- a/library/std/src/sync/once_lock.rs +++ b/library/std/src/sync/once_lock.rs @@ -281,9 +281,7 @@ impl OnceLock { /// Gets the mutable reference of the contents of the cell, initializing /// it with `f` if the cell was empty. /// - /// Many threads may call `get_mut_or_init` concurrently with different - /// initializing functions, but it is guaranteed that only one function - /// will be executed. + /// This method never blocks. /// /// # Panics /// @@ -373,6 +371,8 @@ impl OnceLock { /// it with `f` if the cell was empty. If the cell was empty and `f` failed, /// an error is returned. /// + /// This method never blocks. + /// /// # Panics /// /// If `f` panics, the panic is propagated to the caller, and diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index 292b6032f8493..08460af15d4c7 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -74,6 +74,7 @@ - [*-unknown-openbsd](platform-support/openbsd.md) - [*-unknown-redox](platform-support/redox.md) - [\*-unknown-uefi](platform-support/unknown-uefi.md) + - [\*-wrs-vxworks](platform-support/vxworks.md) - [wasm32-wasip1](platform-support/wasm32-wasip1.md) - [wasm32-wasip1-threads](platform-support/wasm32-wasip1-threads.md) - [wasm32-wasip2](platform-support/wasm32-wasip2.md) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 0c7f4e7bf1b43..cbb338f481172 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -263,7 +263,7 @@ target | std | host | notes [`aarch64-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | ARM64 OpenBSD [`aarch64-unknown-redox`](platform-support/redox.md) | ✓ | | ARM64 Redox OS `aarch64-uwp-windows-msvc` | ✓ | | -`aarch64-wrs-vxworks` | ? | | +[`aarch64-wrs-vxworks`](platform-support/vxworks.md) | ✓ | | ARM64 VxWorks OS `aarch64_be-unknown-linux-gnu_ilp32` | ✓ | ✓ | ARM64 Linux (big-endian, ILP32 ABI) `aarch64_be-unknown-linux-gnu` | ✓ | ✓ | ARM64 Linux (big-endian) [`aarch64_be-unknown-netbsd`](platform-support/netbsd.md) | ✓ | ✓ | ARM64 NetBSD (big-endian) @@ -281,7 +281,7 @@ target | std | host | notes [`armv7-unknown-linux-uclibceabihf`](platform-support/armv7-unknown-linux-uclibceabihf.md) | ✓ | ? | Armv7-A Linux with uClibc, hardfloat `armv7-unknown-freebsd` | ✓ | ✓ | Armv7-A FreeBSD [`armv7-unknown-netbsd-eabihf`](platform-support/netbsd.md) | ✓ | ✓ | Armv7-A NetBSD w/hard-float -`armv7-wrs-vxworks-eabihf` | ? | | Armv7-A for VxWorks +[`armv7-wrs-vxworks-eabihf`](platform-support/vxworks.md) | ? | | Armv7-A for VxWorks [`armv7a-kmc-solid_asp3-eabi`](platform-support/kmc-solid.md) | ✓ | | ARM SOLID with TOPPERS/ASP3 [`armv7a-kmc-solid_asp3-eabihf`](platform-support/kmc-solid.md) | ✓ | | ARM SOLID with TOPPERS/ASP3, hardfloat [`armv7a-none-eabihf`](platform-support/arm-none-eabi.md) | * | | Bare Armv7-A, hardfloat @@ -307,7 +307,7 @@ target | std | host | notes `i686-uwp-windows-gnu` | ✓ | | [^x86_32-floats-return-ABI] `i686-uwp-windows-msvc` | ✓ | | [^x86_32-floats-return-ABI] [`i686-win7-windows-msvc`](platform-support/win7-windows-msvc.md) | ✓ | | 32-bit Windows 7 support [^x86_32-floats-return-ABI] -`i686-wrs-vxworks` | ? | | [^x86_32-floats-return-ABI] +[`i686-wrs-vxworks`](platform-support/vxworks.md) | ? | | [^x86_32-floats-return-ABI] [`m68k-unknown-linux-gnu`](platform-support/m68k-unknown-linux-gnu.md) | ? | | Motorola 680x0 Linux `mips-unknown-linux-gnu` | ✓ | ✓ | MIPS Linux (kernel 4.4, glibc 2.23) `mips-unknown-linux-musl` | ✓ | | MIPS Linux with musl 1.2.3 @@ -333,8 +333,8 @@ target | std | host | notes `powerpc-unknown-linux-musl` | ? | | PowerPC Linux with musl 1.2.3 [`powerpc-unknown-netbsd`](platform-support/netbsd.md) | ✓ | ✓ | NetBSD 32-bit powerpc systems [`powerpc-unknown-openbsd`](platform-support/powerpc-unknown-openbsd.md) | * | | -`powerpc-wrs-vxworks-spe` | ? | | -`powerpc-wrs-vxworks` | ? | | +[`powerpc-wrs-vxworks-spe`](platform-support/vxworks.md) | ? | | +[`powerpc-wrs-vxworks`](platform-support/vxworks.md) | ? | | `powerpc64-unknown-freebsd` | ✓ | ✓ | PPC64 FreeBSD (ELFv1 and ELFv2) `powerpc64le-unknown-freebsd` | | | PPC64LE FreeBSD `powerpc-unknown-freebsd` | | | PowerPC FreeBSD @@ -383,7 +383,7 @@ target | std | host | notes `x86_64-uwp-windows-gnu` | ✓ | | `x86_64-uwp-windows-msvc` | ✓ | | [`x86_64-win7-windows-msvc`](platform-support/win7-windows-msvc.md) | ✓ | | 64-bit Windows 7 support -`x86_64-wrs-vxworks` | ? | | +[`x86_64-wrs-vxworks`](platform-support/vxworks.md) | ? | | [`x86_64h-apple-darwin`](platform-support/x86_64h-apple-darwin.md) | ✓ | ✓ | macOS with late-gen Intel (at least Haswell) [`x86_64-unknown-linux-none`](platform-support/x86_64-unknown-linux-none.md) | * | | 64-bit Linux with no libc [`xtensa-esp32-none-elf`](platform-support/xtensa.md) | * | | Xtensa ESP32 diff --git a/src/doc/rustc/src/platform-support/vxworks.md b/src/doc/rustc/src/platform-support/vxworks.md new file mode 100644 index 0000000000000..c0a818558e0bf --- /dev/null +++ b/src/doc/rustc/src/platform-support/vxworks.md @@ -0,0 +1,51 @@ +# `*-wrs-vxworks` + +**Tier: 3** + +Targets for the VxWorks operating +system. + +Target triplets available: + +- `x86_64-wrs-vxworks` +- `aarch64-wrs-vxworks` +- `i686-wrs-vxworks` +- `armv7-wrs-vxworks-eabihf` +- `powerpc-wrs-vxworks` +- `powerpc-wrs-vxworks-spe` + +## Target maintainers + +- B I Mohammed Abbas ([@biabbas](https://github.com/biabbas)) + +## Requirements + +Rust for each target can be cross-compiled with its specific target vsb configuration. Std support is added but not yet fully tested. + +## Building the target + +You can build Rust with support for the targets by adding it to the `target` list in `config.toml`. In addition the workbench and wr-cc have to configured and activated. + +```toml +[build] +build-stage = 1 +target = [ + "", + "x86_64-wrs-vxworks", + "aarch64-wrs-vxworks", + "i686-wrs-vxworks", + "armv7-wrs-vxworks-eabihf", + "powerpc-wrs-vxworks", + "powerpc-wrs-vxworks-spe", +] +``` + +## Building Rust programs + +Rust does not yet ship pre-compiled artifacts for VxWorks. + +The easiest way to build and test programs for VxWorks is to use the shipped rustc and cargo in VxWorks workbench, following the official windriver guidelines. + +## Cross-compilation toolchains and C code + +The target supports C code. Pre-compiled C toolchains can be found in provided VxWorks workbench. diff --git a/tests/mir-opt/building/match/match_false_edges.full_tested_match.built.after.mir b/tests/mir-opt/building/match/match_false_edges.full_tested_match.built.after.mir index 9ebfff18f4830..a93743edfac73 100644 --- a/tests/mir-opt/building/match/match_false_edges.full_tested_match.built.after.mir +++ b/tests/mir-opt/building/match/match_false_edges.full_tested_match.built.after.mir @@ -37,11 +37,11 @@ fn full_tested_match() -> () { } bb2: { - falseEdge -> [real: bb7, imaginary: bb3]; + falseEdge -> [real: bb8, imaginary: bb3]; } bb3: { - falseEdge -> [real: bb12, imaginary: bb5]; + falseEdge -> [real: bb7, imaginary: bb5]; } bb4: { @@ -50,7 +50,7 @@ fn full_tested_match() -> () { bb5: { _1 = (const 3_i32, const 3_i32); - goto -> bb13; + goto -> bb14; } bb6: { @@ -58,18 +58,33 @@ fn full_tested_match() -> () { } bb7: { + StorageLive(_9); + _9 = ((_2 as Some).0: i32); + StorageLive(_10); + _10 = _9; + _1 = (const 2_i32, move _10); + StorageDead(_10); + StorageDead(_9); + goto -> bb14; + } + + bb8: { StorageLive(_6); _6 = &((_2 as Some).0: i32); _3 = &fake shallow _2; StorageLive(_7); - _7 = guard() -> [return: bb8, unwind: bb15]; + _7 = guard() -> [return: bb10, unwind: bb16]; } - bb8: { - switchInt(move _7) -> [0: bb10, otherwise: bb9]; + bb9: { + goto -> bb3; } - bb9: { + bb10: { + switchInt(move _7) -> [0: bb12, otherwise: bb11]; + } + + bb11: { StorageDead(_7); FakeRead(ForMatchGuard, _3); FakeRead(ForGuardBinding, _6); @@ -81,31 +96,20 @@ fn full_tested_match() -> () { StorageDead(_8); StorageDead(_5); StorageDead(_6); - goto -> bb13; + goto -> bb14; } - bb10: { - goto -> bb11; + bb12: { + goto -> bb13; } - bb11: { + bb13: { StorageDead(_7); StorageDead(_6); - goto -> bb3; - } - - bb12: { - StorageLive(_9); - _9 = ((_2 as Some).0: i32); - StorageLive(_10); - _10 = _9; - _1 = (const 2_i32, move _10); - StorageDead(_10); - StorageDead(_9); - goto -> bb13; + goto -> bb9; } - bb13: { + bb14: { PlaceMention(_1); StorageDead(_2); StorageDead(_1); @@ -113,12 +117,12 @@ fn full_tested_match() -> () { return; } - bb14: { + bb15: { FakeRead(ForMatchedPlace(None), _1); unreachable; } - bb15 (cleanup): { + bb16 (cleanup): { resume; } } diff --git a/tests/mir-opt/building/match/match_false_edges.full_tested_match2.built.after.mir b/tests/mir-opt/building/match/match_false_edges.full_tested_match2.built.after.mir index 4d2989ea93ece..0d0ea2be1b005 100644 --- a/tests/mir-opt/building/match/match_false_edges.full_tested_match2.built.after.mir +++ b/tests/mir-opt/building/match/match_false_edges.full_tested_match2.built.after.mir @@ -37,7 +37,7 @@ fn full_tested_match2() -> () { } bb2: { - falseEdge -> [real: bb7, imaginary: bb5]; + falseEdge -> [real: bb8, imaginary: bb5]; } bb3: { @@ -48,7 +48,7 @@ fn full_tested_match2() -> () { _1 = (const 2_i32, move _10); StorageDead(_10); StorageDead(_9); - goto -> bb13; + goto -> bb14; } bb4: { @@ -56,7 +56,7 @@ fn full_tested_match2() -> () { } bb5: { - falseEdge -> [real: bb12, imaginary: bb3]; + falseEdge -> [real: bb7, imaginary: bb3]; } bb6: { @@ -64,18 +64,27 @@ fn full_tested_match2() -> () { } bb7: { + _1 = (const 3_i32, const 3_i32); + goto -> bb14; + } + + bb8: { StorageLive(_6); _6 = &((_2 as Some).0: i32); _3 = &fake shallow _2; StorageLive(_7); - _7 = guard() -> [return: bb8, unwind: bb15]; + _7 = guard() -> [return: bb10, unwind: bb16]; } - bb8: { - switchInt(move _7) -> [0: bb10, otherwise: bb9]; + bb9: { + falseEdge -> [real: bb3, imaginary: bb5]; } - bb9: { + bb10: { + switchInt(move _7) -> [0: bb12, otherwise: bb11]; + } + + bb11: { StorageDead(_7); FakeRead(ForMatchGuard, _3); FakeRead(ForGuardBinding, _6); @@ -87,25 +96,20 @@ fn full_tested_match2() -> () { StorageDead(_8); StorageDead(_5); StorageDead(_6); - goto -> bb13; + goto -> bb14; } - bb10: { - goto -> bb11; + bb12: { + goto -> bb13; } - bb11: { + bb13: { StorageDead(_7); StorageDead(_6); - falseEdge -> [real: bb3, imaginary: bb5]; - } - - bb12: { - _1 = (const 3_i32, const 3_i32); - goto -> bb13; + goto -> bb9; } - bb13: { + bb14: { PlaceMention(_1); StorageDead(_2); StorageDead(_1); @@ -113,12 +117,12 @@ fn full_tested_match2() -> () { return; } - bb14: { + bb15: { FakeRead(ForMatchedPlace(None), _1); unreachable; } - bb15 (cleanup): { + bb16 (cleanup): { resume; } } diff --git a/tests/mir-opt/building/match/match_false_edges.main.built.after.mir b/tests/mir-opt/building/match/match_false_edges.main.built.after.mir index 4ed9361070662..87b7e29848f74 100644 --- a/tests/mir-opt/building/match/match_false_edges.main.built.after.mir +++ b/tests/mir-opt/building/match/match_false_edges.main.built.after.mir @@ -43,11 +43,11 @@ fn main() -> () { } bb1: { - falseEdge -> [real: bb14, imaginary: bb4]; + falseEdge -> [real: bb11, imaginary: bb4]; } bb2: { - falseEdge -> [real: bb9, imaginary: bb1]; + falseEdge -> [real: bb12, imaginary: bb1]; } bb3: { @@ -64,11 +64,11 @@ fn main() -> () { _14 = _2; _1 = const 4_i32; StorageDead(_14); - goto -> bb20; + goto -> bb22; } bb6: { - falseEdge -> [real: bb15, imaginary: bb5]; + falseEdge -> [real: bb9, imaginary: bb5]; } bb7: { @@ -81,62 +81,70 @@ fn main() -> () { } bb9: { - StorageLive(_7); - _7 = &((_2 as Some).0: i32); + StorageLive(_11); + _11 = &((_2 as Some).0: i32); _3 = &fake shallow _2; - StorageLive(_8); - _8 = guard() -> [return: bb10, unwind: bb22]; + StorageLive(_12); + StorageLive(_13); + _13 = (*_11); + _12 = guard2(move _13) -> [return: bb18, unwind: bb24]; } bb10: { - switchInt(move _8) -> [0: bb12, otherwise: bb11]; + falseEdge -> [real: bb7, imaginary: bb5]; } bb11: { - StorageDead(_8); - FakeRead(ForMatchGuard, _3); - FakeRead(ForGuardBinding, _7); - StorageLive(_6); - _6 = ((_2 as Some).0: i32); - _1 = const 1_i32; - StorageDead(_6); - StorageDead(_7); - goto -> bb20; + StorageLive(_9); + _9 = _2; + _1 = const 2_i32; + StorageDead(_9); + goto -> bb22; } bb12: { - goto -> bb13; + StorageLive(_7); + _7 = &((_2 as Some).0: i32); + _3 = &fake shallow _2; + StorageLive(_8); + _8 = guard() -> [return: bb14, unwind: bb24]; } bb13: { - StorageDead(_8); - StorageDead(_7); falseEdge -> [real: bb3, imaginary: bb1]; } bb14: { - StorageLive(_9); - _9 = _2; - _1 = const 2_i32; - StorageDead(_9); - goto -> bb20; + switchInt(move _8) -> [0: bb16, otherwise: bb15]; } bb15: { - StorageLive(_11); - _11 = &((_2 as Some).0: i32); - _3 = &fake shallow _2; - StorageLive(_12); - StorageLive(_13); - _13 = (*_11); - _12 = guard2(move _13) -> [return: bb16, unwind: bb22]; + StorageDead(_8); + FakeRead(ForMatchGuard, _3); + FakeRead(ForGuardBinding, _7); + StorageLive(_6); + _6 = ((_2 as Some).0: i32); + _1 = const 1_i32; + StorageDead(_6); + StorageDead(_7); + goto -> bb22; } bb16: { - switchInt(move _12) -> [0: bb18, otherwise: bb17]; + goto -> bb17; } bb17: { + StorageDead(_8); + StorageDead(_7); + goto -> bb13; + } + + bb18: { + switchInt(move _12) -> [0: bb20, otherwise: bb19]; + } + + bb19: { StorageDead(_13); StorageDead(_12); FakeRead(ForMatchGuard, _3); @@ -146,21 +154,21 @@ fn main() -> () { _1 = const 3_i32; StorageDead(_10); StorageDead(_11); - goto -> bb20; + goto -> bb22; } - bb18: { - goto -> bb19; + bb20: { + goto -> bb21; } - bb19: { + bb21: { StorageDead(_13); StorageDead(_12); StorageDead(_11); - falseEdge -> [real: bb7, imaginary: bb5]; + goto -> bb10; } - bb20: { + bb22: { PlaceMention(_1); StorageDead(_2); StorageDead(_1); @@ -168,12 +176,12 @@ fn main() -> () { return; } - bb21: { + bb23: { FakeRead(ForMatchedPlace(None), _1); unreachable; } - bb22 (cleanup): { + bb24 (cleanup): { resume; } } diff --git a/tests/mir-opt/building/match/sort_candidates.constant_eq.SimplifyCfg-initial.after.mir b/tests/mir-opt/building/match/sort_candidates.constant_eq.SimplifyCfg-initial.after.mir index 2b5dbacc2d928..2bce79a3ae799 100644 --- a/tests/mir-opt/building/match/sort_candidates.constant_eq.SimplifyCfg-initial.after.mir +++ b/tests/mir-opt/building/match/sort_candidates.constant_eq.SimplifyCfg-initial.after.mir @@ -31,7 +31,7 @@ fn constant_eq(_1: &str, _2: bool) -> u32 { } bb2: { - falseEdge -> [real: bb12, imaginary: bb5]; + falseEdge -> [real: bb15, imaginary: bb5]; } bb3: { @@ -39,7 +39,7 @@ fn constant_eq(_1: &str, _2: bool) -> u32 { } bb4: { - falseEdge -> [real: bb16, imaginary: bb1]; + falseEdge -> [real: bb13, imaginary: bb1]; } bb5: { @@ -51,7 +51,7 @@ fn constant_eq(_1: &str, _2: bool) -> u32 { } bb7: { - falseEdge -> [real: bb15, imaginary: bb3]; + falseEdge -> [real: bb14, imaginary: bb3]; } bb8: { @@ -68,43 +68,43 @@ fn constant_eq(_1: &str, _2: bool) -> u32 { } bb11: { - falseEdge -> [real: bb17, imaginary: bb10]; + falseEdge -> [real: bb12, imaginary: bb10]; } bb12: { - _6 = &fake shallow (_3.0: &str); - _7 = &fake shallow (_3.1: bool); - StorageLive(_10); - _10 = const true; - switchInt(move _10) -> [0: bb14, otherwise: bb13]; + _0 = const 4_u32; + goto -> bb18; } bb13: { - StorageDead(_10); - FakeRead(ForMatchGuard, _6); - FakeRead(ForMatchGuard, _7); - _0 = const 1_u32; + _0 = const 3_u32; goto -> bb18; } bb14: { - StorageDead(_10); - falseEdge -> [real: bb3, imaginary: bb5]; + _0 = const 2_u32; + goto -> bb18; } bb15: { - _0 = const 2_u32; - goto -> bb18; + _6 = &fake shallow (_3.0: &str); + _7 = &fake shallow (_3.1: bool); + StorageLive(_10); + _10 = const true; + switchInt(move _10) -> [0: bb17, otherwise: bb16]; } bb16: { - _0 = const 3_u32; + StorageDead(_10); + FakeRead(ForMatchGuard, _6); + FakeRead(ForMatchGuard, _7); + _0 = const 1_u32; goto -> bb18; } bb17: { - _0 = const 4_u32; - goto -> bb18; + StorageDead(_10); + falseEdge -> [real: bb3, imaginary: bb5]; } bb18: { diff --git a/tests/mir-opt/building/match/sort_candidates.disjoint_ranges.SimplifyCfg-initial.after.mir b/tests/mir-opt/building/match/sort_candidates.disjoint_ranges.SimplifyCfg-initial.after.mir index 07daa3eddfa2c..e521fb4509aa1 100644 --- a/tests/mir-opt/building/match/sort_candidates.disjoint_ranges.SimplifyCfg-initial.after.mir +++ b/tests/mir-opt/building/match/sort_candidates.disjoint_ranges.SimplifyCfg-initial.after.mir @@ -23,7 +23,7 @@ fn disjoint_ranges(_1: i32, _2: bool) -> u32 { } bb2: { - falseEdge -> [real: bb9, imaginary: bb3]; + falseEdge -> [real: bb11, imaginary: bb3]; } bb3: { @@ -32,7 +32,7 @@ fn disjoint_ranges(_1: i32, _2: bool) -> u32 { } bb4: { - falseEdge -> [real: bb12, imaginary: bb5]; + falseEdge -> [real: bb10, imaginary: bb5]; } bb5: { @@ -40,7 +40,7 @@ fn disjoint_ranges(_1: i32, _2: bool) -> u32 { } bb6: { - falseEdge -> [real: bb13, imaginary: bb1]; + falseEdge -> [real: bb9, imaginary: bb1]; } bb7: { @@ -54,32 +54,32 @@ fn disjoint_ranges(_1: i32, _2: bool) -> u32 { } bb9: { - _3 = &fake shallow _1; - StorageLive(_8); - _8 = _2; - switchInt(move _8) -> [0: bb11, otherwise: bb10]; + _0 = const 2_u32; + goto -> bb14; } bb10: { - StorageDead(_8); - FakeRead(ForMatchGuard, _3); - _0 = const 0_u32; + _0 = const 1_u32; goto -> bb14; } bb11: { - StorageDead(_8); - falseEdge -> [real: bb1, imaginary: bb3]; + _3 = &fake shallow _1; + StorageLive(_8); + _8 = _2; + switchInt(move _8) -> [0: bb13, otherwise: bb12]; } bb12: { - _0 = const 1_u32; + StorageDead(_8); + FakeRead(ForMatchGuard, _3); + _0 = const 0_u32; goto -> bb14; } bb13: { - _0 = const 2_u32; - goto -> bb14; + StorageDead(_8); + falseEdge -> [real: bb1, imaginary: bb3]; } bb14: { diff --git a/tests/mir-opt/coverage/branch_match_arms.main.InstrumentCoverage.diff b/tests/mir-opt/coverage/branch_match_arms.main.InstrumentCoverage.diff index e60f71f47b1ed..3d791734f4626 100644 --- a/tests/mir-opt/coverage/branch_match_arms.main.InstrumentCoverage.diff +++ b/tests/mir-opt/coverage/branch_match_arms.main.InstrumentCoverage.diff @@ -55,17 +55,17 @@ bb2: { + Coverage::CounterIncrement(3); - falseEdge -> [real: bb6, imaginary: bb3]; + falseEdge -> [real: bb8, imaginary: bb3]; } bb3: { + Coverage::CounterIncrement(2); - falseEdge -> [real: bb8, imaginary: bb4]; + falseEdge -> [real: bb7, imaginary: bb4]; } bb4: { + Coverage::CounterIncrement(1); - falseEdge -> [real: bb10, imaginary: bb5]; + falseEdge -> [real: bb6, imaginary: bb5]; } bb5: { @@ -78,39 +78,39 @@ } bb6: { - StorageLive(_3); - _3 = ((_1 as D).0: u32); - StorageLive(_4); - _4 = _3; - _0 = consume(move _4) -> [return: bb7, unwind: bb14]; + StorageLive(_7); + _7 = ((_1 as B).0: u32); + StorageLive(_8); + _8 = _7; + _0 = consume(move _8) -> [return: bb11, unwind: bb14]; } bb7: { - StorageDead(_4); - StorageDead(_3); - goto -> bb13; - } - - bb8: { StorageLive(_5); _5 = ((_1 as C).0: u32); StorageLive(_6); _6 = _5; - _0 = consume(move _6) -> [return: bb9, unwind: bb14]; + _0 = consume(move _6) -> [return: bb10, unwind: bb14]; + } + + bb8: { + StorageLive(_3); + _3 = ((_1 as D).0: u32); + StorageLive(_4); + _4 = _3; + _0 = consume(move _4) -> [return: bb9, unwind: bb14]; } bb9: { - StorageDead(_6); - StorageDead(_5); + StorageDead(_4); + StorageDead(_3); goto -> bb13; } bb10: { - StorageLive(_7); - _7 = ((_1 as B).0: u32); - StorageLive(_8); - _8 = _7; - _0 = consume(move _8) -> [return: bb11, unwind: bb14]; + StorageDead(_6); + StorageDead(_5); + goto -> bb13; } bb11: { diff --git a/tests/mir-opt/deduplicate_blocks.is_line_doc_comment_2.DeduplicateBlocks.panic-abort.diff b/tests/mir-opt/deduplicate_blocks.is_line_doc_comment_2.DeduplicateBlocks.panic-abort.diff index 3a5762e4f3d1e..efb28ba344b2b 100644 --- a/tests/mir-opt/deduplicate_blocks.is_line_doc_comment_2.DeduplicateBlocks.panic-abort.diff +++ b/tests/mir-opt/deduplicate_blocks.is_line_doc_comment_2.DeduplicateBlocks.panic-abort.diff @@ -33,7 +33,7 @@ _8 = const 3_usize; _9 = Ge(move _7, move _8); - switchInt(move _9) -> [0: bb7, otherwise: bb8]; -+ switchInt(move _9) -> [0: bb10, otherwise: bb7]; ++ switchInt(move _9) -> [0: bb11, otherwise: bb7]; } bb3: { @@ -49,48 +49,48 @@ } bb6: { -- switchInt((*_2)[3 of 4]) -> [47: bb11, otherwise: bb2]; -+ switchInt((*_2)[3 of 4]) -> [47: bb10, otherwise: bb2]; +- switchInt((*_2)[3 of 4]) -> [47: bb13, otherwise: bb2]; ++ switchInt((*_2)[3 of 4]) -> [47: bb11, otherwise: bb2]; } bb7: { - _0 = const false; - goto -> bb14; -+ switchInt((*_2)[0 of 3]) -> [47: bb8, otherwise: bb10]; ++ switchInt((*_2)[0 of 3]) -> [47: bb8, otherwise: bb11]; } bb8: { - switchInt((*_2)[0 of 3]) -> [47: bb9, otherwise: bb7]; -+ switchInt((*_2)[1 of 3]) -> [47: bb9, otherwise: bb10]; ++ switchInt((*_2)[1 of 3]) -> [47: bb9, otherwise: bb11]; } bb9: { - switchInt((*_2)[1 of 3]) -> [47: bb10, otherwise: bb7]; -+ switchInt((*_2)[2 of 3]) -> [47: bb11, 33: bb11, otherwise: bb10]; ++ switchInt((*_2)[2 of 3]) -> [47: bb10, 33: bb10, otherwise: bb11]; } bb10: { -- switchInt((*_2)[2 of 3]) -> [47: bb12, 33: bb13, otherwise: bb7]; +- switchInt((*_2)[2 of 3]) -> [47: bb12, 33: bb11, otherwise: bb7]; - } - - bb11: { - _0 = const false; + _0 = const true; - goto -> bb14; + goto -> bb12; } - bb12: { +- _0 = const true; +- goto -> bb14; +- } +- +- bb13: { + bb11: { - _0 = const true; + _0 = const false; - goto -> bb14; + goto -> bb12; } -- bb13: { -- _0 = const true; -- goto -> bb14; -- } -- - bb14: { + bb12: { StorageDead(_2); diff --git a/tests/mir-opt/deduplicate_blocks.is_line_doc_comment_2.DeduplicateBlocks.panic-unwind.diff b/tests/mir-opt/deduplicate_blocks.is_line_doc_comment_2.DeduplicateBlocks.panic-unwind.diff index 21b197d2f270c..c6e2d3a551259 100644 --- a/tests/mir-opt/deduplicate_blocks.is_line_doc_comment_2.DeduplicateBlocks.panic-unwind.diff +++ b/tests/mir-opt/deduplicate_blocks.is_line_doc_comment_2.DeduplicateBlocks.panic-unwind.diff @@ -33,7 +33,7 @@ _8 = const 3_usize; _9 = Ge(move _7, move _8); - switchInt(move _9) -> [0: bb7, otherwise: bb8]; -+ switchInt(move _9) -> [0: bb10, otherwise: bb7]; ++ switchInt(move _9) -> [0: bb11, otherwise: bb7]; } bb3: { @@ -49,48 +49,48 @@ } bb6: { -- switchInt((*_2)[3 of 4]) -> [47: bb11, otherwise: bb2]; -+ switchInt((*_2)[3 of 4]) -> [47: bb10, otherwise: bb2]; +- switchInt((*_2)[3 of 4]) -> [47: bb13, otherwise: bb2]; ++ switchInt((*_2)[3 of 4]) -> [47: bb11, otherwise: bb2]; } bb7: { - _0 = const false; - goto -> bb14; -+ switchInt((*_2)[0 of 3]) -> [47: bb8, otherwise: bb10]; ++ switchInt((*_2)[0 of 3]) -> [47: bb8, otherwise: bb11]; } bb8: { - switchInt((*_2)[0 of 3]) -> [47: bb9, otherwise: bb7]; -+ switchInt((*_2)[1 of 3]) -> [47: bb9, otherwise: bb10]; ++ switchInt((*_2)[1 of 3]) -> [47: bb9, otherwise: bb11]; } bb9: { - switchInt((*_2)[1 of 3]) -> [47: bb10, otherwise: bb7]; -+ switchInt((*_2)[2 of 3]) -> [47: bb11, 33: bb11, otherwise: bb10]; ++ switchInt((*_2)[2 of 3]) -> [47: bb10, 33: bb10, otherwise: bb11]; } bb10: { -- switchInt((*_2)[2 of 3]) -> [47: bb12, 33: bb13, otherwise: bb7]; +- switchInt((*_2)[2 of 3]) -> [47: bb12, 33: bb11, otherwise: bb7]; - } - - bb11: { - _0 = const false; + _0 = const true; - goto -> bb14; + goto -> bb12; } - bb12: { +- _0 = const true; +- goto -> bb14; +- } +- +- bb13: { + bb11: { - _0 = const true; + _0 = const false; - goto -> bb14; + goto -> bb12; } -- bb13: { -- _0 = const true; -- goto -> bb14; -- } -- - bb14: { + bb12: { StorageDead(_2); diff --git a/tests/mir-opt/early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff b/tests/mir-opt/early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff index 7776ff0fde794..41ae2fd3af3f4 100644 --- a/tests/mir-opt/early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff +++ b/tests/mir-opt/early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff @@ -38,15 +38,20 @@ bb2: { _6 = discriminant((_3.1: std::option::Option)); - switchInt(move _6) -> [1: bb4, 0: bb1, otherwise: bb7]; + switchInt(move _6) -> [1: bb5, 0: bb1, otherwise: bb7]; } bb3: { _7 = discriminant((_3.1: std::option::Option)); - switchInt(move _7) -> [0: bb5, 1: bb1, otherwise: bb7]; + switchInt(move _7) -> [0: bb4, 1: bb1, otherwise: bb7]; } bb4: { + _0 = const 2_u32; + goto -> bb6; + } + + bb5: { StorageLive(_9); _9 = (((_3.0: std::option::Option) as Some).0: u32); StorageLive(_10); @@ -57,11 +62,6 @@ goto -> bb6; } - bb5: { - _0 = const 2_u32; - goto -> bb6; - } - bb6: { StorageDead(_3); return; diff --git a/tests/mir-opt/early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff b/tests/mir-opt/early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff index b41e952d80f5a..302fd0bfded4b 100644 --- a/tests/mir-opt/early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff +++ b/tests/mir-opt/early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff @@ -49,7 +49,7 @@ bb2: { - _6 = discriminant((_3.1: Option2)); -- switchInt(move _6) -> [0: bb5, otherwise: bb1]; +- switchInt(move _6) -> [0: bb7, otherwise: bb1]; - } - - bb3: { @@ -59,17 +59,11 @@ - - bb4: { - _8 = discriminant((_3.1: Option2)); -- switchInt(move _8) -> [2: bb7, otherwise: bb1]; +- switchInt(move _8) -> [2: bb5, otherwise: bb1]; - } - - bb5: { - StorageLive(_10); - _10 = (((_3.0: Option2) as Some).0: u32); - StorageLive(_11); - _11 = (((_3.1: Option2) as Some).0: bool); - _0 = const 0_u32; - StorageDead(_11); - StorageDead(_10); + _0 = const 3_u32; - goto -> bb8; + goto -> bb5; } @@ -83,7 +77,13 @@ - bb7: { + bb4: { - _0 = const 3_u32; + StorageLive(_10); + _10 = (((_3.0: Option2) as Some).0: u32); + StorageLive(_11); + _11 = (((_3.1: Option2) as Some).0: bool); + _0 = const 0_u32; + StorageDead(_11); + StorageDead(_10); - goto -> bb8; + goto -> bb5; } @@ -101,7 +101,7 @@ + + bb7: { + StorageDead(_13); -+ switchInt(_9) -> [0: bb2, 1: bb3, 2: bb4, otherwise: bb6]; ++ switchInt(_9) -> [0: bb4, 1: bb3, 2: bb2, otherwise: bb6]; } } diff --git a/tests/mir-opt/early_otherwise_branch.opt4.EarlyOtherwiseBranch.diff b/tests/mir-opt/early_otherwise_branch.opt4.EarlyOtherwiseBranch.diff index 18dea56f4307c..eef4fb3278c1c 100644 --- a/tests/mir-opt/early_otherwise_branch.opt4.EarlyOtherwiseBranch.diff +++ b/tests/mir-opt/early_otherwise_branch.opt4.EarlyOtherwiseBranch.diff @@ -49,7 +49,7 @@ bb2: { - _6 = discriminant((_3.1: Option2)); -- switchInt(move _6) -> [0: bb5, otherwise: bb1]; +- switchInt(move _6) -> [0: bb7, otherwise: bb1]; - } - - bb3: { @@ -59,17 +59,11 @@ - - bb4: { - _8 = discriminant((_3.1: Option2)); -- switchInt(move _8) -> [2: bb7, otherwise: bb1]; +- switchInt(move _8) -> [2: bb5, otherwise: bb1]; - } - - bb5: { - StorageLive(_10); - _10 = (((_3.0: Option2) as Some).0: u32); - StorageLive(_11); - _11 = (((_3.1: Option2) as Some).0: u32); - _0 = const 0_u32; - StorageDead(_11); - StorageDead(_10); + _0 = const 3_u32; - goto -> bb8; + goto -> bb5; } @@ -83,7 +77,13 @@ - bb7: { + bb4: { - _0 = const 3_u32; + StorageLive(_10); + _10 = (((_3.0: Option2) as Some).0: u32); + StorageLive(_11); + _11 = (((_3.1: Option2) as Some).0: u32); + _0 = const 0_u32; + StorageDead(_11); + StorageDead(_10); - goto -> bb8; + goto -> bb5; } @@ -101,7 +101,7 @@ + + bb7: { + StorageDead(_13); -+ switchInt(_9) -> [0: bb2, 1: bb3, 2: bb4, otherwise: bb6]; ++ switchInt(_9) -> [0: bb4, 1: bb3, 2: bb2, otherwise: bb6]; } } diff --git a/tests/mir-opt/early_otherwise_branch_3_element_tuple.opt1.EarlyOtherwiseBranch.diff b/tests/mir-opt/early_otherwise_branch_3_element_tuple.opt1.EarlyOtherwiseBranch.diff index 4c3c717b52251..cb03e2697ccd3 100644 --- a/tests/mir-opt/early_otherwise_branch_3_element_tuple.opt1.EarlyOtherwiseBranch.diff +++ b/tests/mir-opt/early_otherwise_branch_3_element_tuple.opt1.EarlyOtherwiseBranch.diff @@ -52,7 +52,7 @@ bb3: { _8 = discriminant((_4.2: std::option::Option)); - switchInt(move _8) -> [1: bb6, 0: bb1, otherwise: bb9]; + switchInt(move _8) -> [1: bb7, 0: bb1, otherwise: bb9]; } bb4: { @@ -62,10 +62,15 @@ bb5: { _10 = discriminant((_4.2: std::option::Option)); - switchInt(move _10) -> [0: bb7, 1: bb1, otherwise: bb9]; + switchInt(move _10) -> [0: bb6, 1: bb1, otherwise: bb9]; } bb6: { + _0 = const 2_u32; + goto -> bb8; + } + + bb7: { StorageLive(_13); _13 = (((_4.0: std::option::Option) as Some).0: u32); StorageLive(_14); @@ -79,11 +84,6 @@ goto -> bb8; } - bb7: { - _0 = const 2_u32; - goto -> bb8; - } - bb8: { StorageDead(_4); return; diff --git a/tests/mir-opt/early_otherwise_branch_3_element_tuple.opt2.EarlyOtherwiseBranch.diff b/tests/mir-opt/early_otherwise_branch_3_element_tuple.opt2.EarlyOtherwiseBranch.diff index 0ea7a10baaadc..5634df253a5d0 100644 --- a/tests/mir-opt/early_otherwise_branch_3_element_tuple.opt2.EarlyOtherwiseBranch.diff +++ b/tests/mir-opt/early_otherwise_branch_3_element_tuple.opt2.EarlyOtherwiseBranch.diff @@ -64,8 +64,8 @@ - - bb3: { _8 = discriminant((_4.2: Option2)); -- switchInt(move _8) -> [0: bb8, otherwise: bb1]; -+ switchInt(move _8) -> [0: bb5, otherwise: bb1]; +- switchInt(move _8) -> [0: bb10, otherwise: bb1]; ++ switchInt(move _8) -> [0: bb7, otherwise: bb1]; } - bb4: { @@ -88,22 +88,13 @@ - bb7: { + bb4: { _12 = discriminant((_4.2: Option2)); -- switchInt(move _12) -> [2: bb10, otherwise: bb1]; -+ switchInt(move _12) -> [2: bb7, otherwise: bb1]; +- switchInt(move _12) -> [2: bb8, otherwise: bb1]; ++ switchInt(move _12) -> [2: bb5, otherwise: bb1]; } - bb8: { + bb5: { - StorageLive(_15); - _15 = (((_4.0: Option2) as Some).0: u32); - StorageLive(_16); - _16 = (((_4.1: Option2) as Some).0: u32); - StorageLive(_17); - _17 = (((_4.2: Option2) as Some).0: u32); - _0 = const 0_u32; - StorageDead(_17); - StorageDead(_16); - StorageDead(_15); + _0 = const 3_u32; - goto -> bb11; + goto -> bb8; } @@ -117,7 +108,16 @@ - bb10: { + bb7: { - _0 = const 3_u32; + StorageLive(_15); + _15 = (((_4.0: Option2) as Some).0: u32); + StorageLive(_16); + _16 = (((_4.1: Option2) as Some).0: u32); + StorageLive(_17); + _17 = (((_4.2: Option2) as Some).0: u32); + _0 = const 0_u32; + StorageDead(_17); + StorageDead(_16); + StorageDead(_15); - goto -> bb11; + goto -> bb8; } diff --git a/tests/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff b/tests/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff index de12fe8f120a7..8179d9dd11505 100644 --- a/tests/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff +++ b/tests/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff @@ -94,78 +94,56 @@ bb2: { _35 = deref_copy (_4.1: &ViewportPercentageLength); _7 = discriminant((*_35)); - switchInt(move _7) -> [0: bb6, otherwise: bb1]; + switchInt(move _7) -> [0: bb9, otherwise: bb1]; } bb3: { _36 = deref_copy (_4.1: &ViewportPercentageLength); _8 = discriminant((*_36)); - switchInt(move _8) -> [1: bb7, otherwise: bb1]; + switchInt(move _8) -> [1: bb8, otherwise: bb1]; } bb4: { _37 = deref_copy (_4.1: &ViewportPercentageLength); _9 = discriminant((*_37)); - switchInt(move _9) -> [2: bb8, otherwise: bb1]; + switchInt(move _9) -> [2: bb7, otherwise: bb1]; } bb5: { _38 = deref_copy (_4.1: &ViewportPercentageLength); _10 = discriminant((*_38)); - switchInt(move _10) -> [3: bb9, otherwise: bb1]; + switchInt(move _10) -> [3: bb6, otherwise: bb1]; } bb6: { - StorageLive(_12); + StorageLive(_27); _39 = deref_copy (_4.0: &ViewportPercentageLength); - _12 = (((*_39) as Vw).0: f32); - StorageLive(_13); + _27 = (((*_39) as Vmax).0: f32); + StorageLive(_28); _40 = deref_copy (_4.1: &ViewportPercentageLength); - _13 = (((*_40) as Vw).0: f32); - StorageLive(_14); - StorageLive(_15); - _15 = _12; - StorageLive(_16); - _16 = _13; - _14 = Add(move _15, move _16); - StorageDead(_16); - StorageDead(_15); - _3 = ViewportPercentageLength::Vw(move _14); - StorageDead(_14); - StorageDead(_13); - StorageDead(_12); + _28 = (((*_40) as Vmax).0: f32); + StorageLive(_29); + StorageLive(_30); + _30 = _27; + StorageLive(_31); + _31 = _28; + _29 = Add(move _30, move _31); + StorageDead(_31); + StorageDead(_30); + _3 = ViewportPercentageLength::Vmax(move _29); + StorageDead(_29); + StorageDead(_28); + StorageDead(_27); goto -> bb10; } bb7: { - StorageLive(_17); - _41 = deref_copy (_4.0: &ViewportPercentageLength); - _17 = (((*_41) as Vh).0: f32); - StorageLive(_18); - _42 = deref_copy (_4.1: &ViewportPercentageLength); - _18 = (((*_42) as Vh).0: f32); - StorageLive(_19); - StorageLive(_20); - _20 = _17; - StorageLive(_21); - _21 = _18; - _19 = Add(move _20, move _21); - StorageDead(_21); - StorageDead(_20); - _3 = ViewportPercentageLength::Vh(move _19); - StorageDead(_19); - StorageDead(_18); - StorageDead(_17); - goto -> bb10; - } - - bb8: { StorageLive(_22); - _43 = deref_copy (_4.0: &ViewportPercentageLength); - _22 = (((*_43) as Vmin).0: f32); + _41 = deref_copy (_4.0: &ViewportPercentageLength); + _22 = (((*_41) as Vmin).0: f32); StorageLive(_23); - _44 = deref_copy (_4.1: &ViewportPercentageLength); - _23 = (((*_44) as Vmin).0: f32); + _42 = deref_copy (_4.1: &ViewportPercentageLength); + _23 = (((*_42) as Vmin).0: f32); StorageLive(_24); StorageLive(_25); _25 = _22; @@ -181,25 +159,47 @@ goto -> bb10; } + bb8: { + StorageLive(_17); + _43 = deref_copy (_4.0: &ViewportPercentageLength); + _17 = (((*_43) as Vh).0: f32); + StorageLive(_18); + _44 = deref_copy (_4.1: &ViewportPercentageLength); + _18 = (((*_44) as Vh).0: f32); + StorageLive(_19); + StorageLive(_20); + _20 = _17; + StorageLive(_21); + _21 = _18; + _19 = Add(move _20, move _21); + StorageDead(_21); + StorageDead(_20); + _3 = ViewportPercentageLength::Vh(move _19); + StorageDead(_19); + StorageDead(_18); + StorageDead(_17); + goto -> bb10; + } + bb9: { - StorageLive(_27); + StorageLive(_12); _45 = deref_copy (_4.0: &ViewportPercentageLength); - _27 = (((*_45) as Vmax).0: f32); - StorageLive(_28); + _12 = (((*_45) as Vw).0: f32); + StorageLive(_13); _46 = deref_copy (_4.1: &ViewportPercentageLength); - _28 = (((*_46) as Vmax).0: f32); - StorageLive(_29); - StorageLive(_30); - _30 = _27; - StorageLive(_31); - _31 = _28; - _29 = Add(move _30, move _31); - StorageDead(_31); - StorageDead(_30); - _3 = ViewportPercentageLength::Vmax(move _29); - StorageDead(_29); - StorageDead(_28); - StorageDead(_27); + _13 = (((*_46) as Vw).0: f32); + StorageLive(_14); + StorageLive(_15); + _15 = _12; + StorageLive(_16); + _16 = _13; + _14 = Add(move _15, move _16); + StorageDead(_16); + StorageDead(_15); + _3 = ViewportPercentageLength::Vw(move _14); + StorageDead(_14); + StorageDead(_13); + StorageDead(_12); goto -> bb10; } diff --git a/tests/mir-opt/early_otherwise_branch_noopt.noopt1.EarlyOtherwiseBranch.diff b/tests/mir-opt/early_otherwise_branch_noopt.noopt1.EarlyOtherwiseBranch.diff index 350e5fe6db579..651b1de4ddd37 100644 --- a/tests/mir-opt/early_otherwise_branch_noopt.noopt1.EarlyOtherwiseBranch.diff +++ b/tests/mir-opt/early_otherwise_branch_noopt.noopt1.EarlyOtherwiseBranch.diff @@ -45,12 +45,12 @@ bb2: { _6 = discriminant((_3.1: std::option::Option)); - switchInt(move _6) -> [0: bb6, 1: bb5, otherwise: bb1]; + switchInt(move _6) -> [0: bb6, 1: bb7, otherwise: bb1]; } bb3: { _7 = discriminant((_3.1: std::option::Option)); - switchInt(move _7) -> [0: bb4, 1: bb7, otherwise: bb1]; + switchInt(move _7) -> [0: bb4, 1: bb5, otherwise: bb1]; } bb4: { @@ -59,13 +59,10 @@ } bb5: { - StorageLive(_9); - _9 = (((_3.0: std::option::Option) as Some).0: u32); - StorageLive(_10); - _10 = (((_3.1: std::option::Option) as Some).0: u32); - _0 = const 0_u32; - StorageDead(_10); - StorageDead(_9); + StorageLive(_12); + _12 = (((_3.1: std::option::Option) as Some).0: u32); + _0 = const 2_u32; + StorageDead(_12); goto -> bb8; } @@ -78,10 +75,13 @@ } bb7: { - StorageLive(_12); - _12 = (((_3.1: std::option::Option) as Some).0: u32); - _0 = const 2_u32; - StorageDead(_12); + StorageLive(_9); + _9 = (((_3.0: std::option::Option) as Some).0: u32); + StorageLive(_10); + _10 = (((_3.1: std::option::Option) as Some).0: u32); + _0 = const 0_u32; + StorageDead(_10); + StorageDead(_9); goto -> bb8; } diff --git a/tests/mir-opt/jump_threading.dfa.JumpThreading.panic-abort.diff b/tests/mir-opt/jump_threading.dfa.JumpThreading.panic-abort.diff index bbbfe90691f97..8009721fa5c58 100644 --- a/tests/mir-opt/jump_threading.dfa.JumpThreading.panic-abort.diff +++ b/tests/mir-opt/jump_threading.dfa.JumpThreading.panic-abort.diff @@ -24,7 +24,7 @@ bb1: { _4 = discriminant(_1); - switchInt(move _4) -> [0: bb4, 1: bb5, 2: bb6, 3: bb3, otherwise: bb2]; + switchInt(move _4) -> [0: bb6, 1: bb5, 2: bb4, 3: bb3, otherwise: bb2]; } bb2: { @@ -39,11 +39,11 @@ } bb4: { - StorageLive(_5); - _5 = DFA::B; - _1 = move _5; + StorageLive(_7); + _7 = DFA::D; + _1 = move _7; _3 = const (); - StorageDead(_5); + StorageDead(_7); goto -> bb1; } @@ -57,11 +57,11 @@ } bb6: { - StorageLive(_7); - _7 = DFA::D; - _1 = move _7; + StorageLive(_5); + _5 = DFA::B; + _1 = move _5; _3 = const (); - StorageDead(_7); + StorageDead(_5); goto -> bb1; } } diff --git a/tests/mir-opt/jump_threading.dfa.JumpThreading.panic-unwind.diff b/tests/mir-opt/jump_threading.dfa.JumpThreading.panic-unwind.diff index bbbfe90691f97..8009721fa5c58 100644 --- a/tests/mir-opt/jump_threading.dfa.JumpThreading.panic-unwind.diff +++ b/tests/mir-opt/jump_threading.dfa.JumpThreading.panic-unwind.diff @@ -24,7 +24,7 @@ bb1: { _4 = discriminant(_1); - switchInt(move _4) -> [0: bb4, 1: bb5, 2: bb6, 3: bb3, otherwise: bb2]; + switchInt(move _4) -> [0: bb6, 1: bb5, 2: bb4, 3: bb3, otherwise: bb2]; } bb2: { @@ -39,11 +39,11 @@ } bb4: { - StorageLive(_5); - _5 = DFA::B; - _1 = move _5; + StorageLive(_7); + _7 = DFA::D; + _1 = move _7; _3 = const (); - StorageDead(_5); + StorageDead(_7); goto -> bb1; } @@ -57,11 +57,11 @@ } bb6: { - StorageLive(_7); - _7 = DFA::D; - _1 = move _7; + StorageLive(_5); + _5 = DFA::B; + _1 = move _5; _3 = const (); - StorageDead(_7); + StorageDead(_5); goto -> bb1; } } diff --git a/tests/mir-opt/jump_threading.rs b/tests/mir-opt/jump_threading.rs index e5d8525dcac13..6486a321e693e 100644 --- a/tests/mir-opt/jump_threading.rs +++ b/tests/mir-opt/jump_threading.rs @@ -93,19 +93,19 @@ fn dfa() { // CHECK: {{_.*}} = DFA::A; // CHECK: goto -> bb1; // CHECK: bb1: { - // CHECK: switchInt({{.*}}) -> [0: bb4, 1: bb5, 2: bb6, 3: bb3, otherwise: bb2]; + // CHECK: switchInt({{.*}}) -> [0: bb6, 1: bb5, 2: bb4, 3: bb3, otherwise: bb2]; // CHECK: bb2: { // CHECK: unreachable; // CHECK: bb3: { // CHECK: return; // CHECK: bb4: { - // CHECK: {{_.*}} = DFA::B; + // CHECK: {{_.*}} = DFA::D; // CHECK: goto -> bb1; // CHECK: bb5: { // CHECK: {{_.*}} = DFA::C; // CHECK: goto -> bb1; // CHECK: bb6: { - // CHECK: {{_.*}} = DFA::D; + // CHECK: {{_.*}} = DFA::B; // CHECK: goto -> bb1; let mut state = DFA::A; loop { diff --git a/tests/mir-opt/match_arm_scopes.complicated_match.panic-abort.SimplifyCfg-initial.after-ElaborateDrops.after.diff b/tests/mir-opt/match_arm_scopes.complicated_match.panic-abort.SimplifyCfg-initial.after-ElaborateDrops.after.diff index 4f29e5244d7c2..3c4a84bc24368 100644 --- a/tests/mir-opt/match_arm_scopes.complicated_match.panic-abort.SimplifyCfg-initial.after-ElaborateDrops.after.diff +++ b/tests/mir-opt/match_arm_scopes.complicated_match.panic-abort.SimplifyCfg-initial.after-ElaborateDrops.after.diff @@ -33,17 +33,17 @@ bb0: { PlaceMention(_2); - switchInt((_2.0: bool)) -> [0: bb2, otherwise: bb1]; -+ switchInt((_2.0: bool)) -> [0: bb5, otherwise: bb1]; ++ switchInt((_2.0: bool)) -> [0: bb6, otherwise: bb1]; } bb1: { - switchInt((_2.1: bool)) -> [0: bb4, otherwise: bb3]; -+ switchInt((_2.1: bool)) -> [0: bb10, otherwise: bb2]; ++ switchInt((_2.1: bool)) -> [0: bb5, otherwise: bb2]; } bb2: { -- falseEdge -> [real: bb8, imaginary: bb1]; -+ switchInt((_2.0: bool)) -> [0: bb3, otherwise: bb17]; +- falseEdge -> [real: bb9, imaginary: bb1]; ++ switchInt((_2.0: bool)) -> [0: bb3, otherwise: bb4]; } bb3: { @@ -51,11 +51,11 @@ - } - - bb4: { -- falseEdge -> [real: bb13, imaginary: bb3]; +- falseEdge -> [real: bb8, imaginary: bb3]; - } - - bb5: { -- falseEdge -> [real: bb20, imaginary: bb6]; +- falseEdge -> [real: bb7, imaginary: bb6]; - } - - bb6: { @@ -63,19 +63,37 @@ _15 = (_2.1: bool); StorageLive(_16); _16 = move (_2.2: std::string::String); -- goto -> bb19; -+ goto -> bb16; +- goto -> bb20; ++ goto -> bb17; } - bb7: { + bb4: { - _0 = const 1_i32; -- drop(_7) -> [return: bb18, unwind: bb25]; -+ drop(_7) -> [return: bb15, unwind: bb22]; + StorageLive(_15); + _15 = (_2.1: bool); + StorageLive(_16); + _16 = move (_2.2: std::string::String); +- goto -> bb20; ++ goto -> bb17; } - bb8: { + bb5: { + StorageLive(_6); + _6 = &(_2.0: bool); + StorageLive(_8); + _8 = &(_2.2: std::string::String); +- _3 = &fake shallow (_2.0: bool); +- _4 = &fake shallow (_2.1: bool); + StorageLive(_12); + StorageLive(_13); + _13 = _1; +- switchInt(move _13) -> [0: bb16, otherwise: bb15]; ++ switchInt(move _13) -> [0: bb13, otherwise: bb12]; + } + +- bb9: { ++ bb6: { StorageLive(_6); _6 = &(_2.1: bool); StorageLive(_8); @@ -85,12 +103,19 @@ StorageLive(_9); StorageLive(_10); _10 = _1; -- switchInt(move _10) -> [0: bb10, otherwise: bb9]; -+ switchInt(move _10) -> [0: bb7, otherwise: bb6]; +- switchInt(move _10) -> [0: bb12, otherwise: bb11]; ++ switchInt(move _10) -> [0: bb9, otherwise: bb8]; } -- bb9: { -+ bb6: { +- bb10: { ++ bb7: { + _0 = const 1_i32; +- drop(_7) -> [return: bb19, unwind: bb25]; ++ drop(_7) -> [return: bb16, unwind: bb22]; + } + +- bb11: { ++ bb8: { _0 = const 3_i32; StorageDead(_10); StorageDead(_9); @@ -98,15 +123,15 @@ + goto -> bb20; } -- bb10: { -+ bb7: { +- bb12: { ++ bb9: { _9 = (*_6); -- switchInt(move _9) -> [0: bb12, otherwise: bb11]; -+ switchInt(move _9) -> [0: bb9, otherwise: bb8]; +- switchInt(move _9) -> [0: bb14, otherwise: bb13]; ++ switchInt(move _9) -> [0: bb11, otherwise: bb10]; } -- bb11: { -+ bb8: { +- bb13: { ++ bb10: { StorageDead(_10); StorageDead(_9); - FakeRead(ForMatchGuard, _3); @@ -117,12 +142,12 @@ _5 = (_2.1: bool); StorageLive(_7); _7 = move (_2.2: std::string::String); -- goto -> bb7; -+ goto -> bb4; +- goto -> bb10; ++ goto -> bb7; } -- bb12: { -+ bb9: { +- bb14: { ++ bb11: { StorageDead(_10); StorageDead(_9); StorageDead(_8); @@ -131,23 +156,8 @@ + goto -> bb1; } -- bb13: { -+ bb10: { - StorageLive(_6); - _6 = &(_2.0: bool); - StorageLive(_8); - _8 = &(_2.2: std::string::String); -- _3 = &fake shallow (_2.0: bool); -- _4 = &fake shallow (_2.1: bool); - StorageLive(_12); - StorageLive(_13); - _13 = _1; -- switchInt(move _13) -> [0: bb15, otherwise: bb14]; -+ switchInt(move _13) -> [0: bb12, otherwise: bb11]; - } - -- bb14: { -+ bb11: { +- bb15: { ++ bb12: { _0 = const 3_i32; StorageDead(_13); StorageDead(_12); @@ -155,15 +165,15 @@ + goto -> bb20; } -- bb15: { -+ bb12: { +- bb16: { ++ bb13: { _12 = (*_6); -- switchInt(move _12) -> [0: bb17, otherwise: bb16]; -+ switchInt(move _12) -> [0: bb14, otherwise: bb13]; +- switchInt(move _12) -> [0: bb18, otherwise: bb17]; ++ switchInt(move _12) -> [0: bb15, otherwise: bb14]; } -- bb16: { -+ bb13: { +- bb17: { ++ bb14: { StorageDead(_13); StorageDead(_12); - FakeRead(ForMatchGuard, _3); @@ -174,12 +184,12 @@ _5 = (_2.0: bool); StorageLive(_7); _7 = move (_2.2: std::string::String); -- goto -> bb7; -+ goto -> bb4; +- goto -> bb10; ++ goto -> bb7; } -- bb17: { -+ bb14: { +- bb18: { ++ bb15: { StorageDead(_13); StorageDead(_12); StorageDead(_8); @@ -188,8 +198,8 @@ + goto -> bb2; } -- bb18: { -+ bb15: { +- bb19: { ++ bb16: { StorageDead(_7); StorageDead(_5); StorageDead(_8); @@ -198,23 +208,13 @@ + goto -> bb19; } -- bb19: { -+ bb16: { +- bb20: { ++ bb17: { _0 = const 2_i32; - drop(_16) -> [return: bb21, unwind: bb25]; + drop(_16) -> [return: bb18, unwind: bb22]; } -- bb20: { -+ bb17: { - StorageLive(_15); - _15 = (_2.1: bool); - StorageLive(_16); - _16 = move (_2.2: std::string::String); -- goto -> bb19; -+ goto -> bb16; - } - - bb21: { + bb18: { StorageDead(_16); diff --git a/tests/mir-opt/match_arm_scopes.complicated_match.panic-unwind.SimplifyCfg-initial.after-ElaborateDrops.after.diff b/tests/mir-opt/match_arm_scopes.complicated_match.panic-unwind.SimplifyCfg-initial.after-ElaborateDrops.after.diff index 4f29e5244d7c2..3c4a84bc24368 100644 --- a/tests/mir-opt/match_arm_scopes.complicated_match.panic-unwind.SimplifyCfg-initial.after-ElaborateDrops.after.diff +++ b/tests/mir-opt/match_arm_scopes.complicated_match.panic-unwind.SimplifyCfg-initial.after-ElaborateDrops.after.diff @@ -33,17 +33,17 @@ bb0: { PlaceMention(_2); - switchInt((_2.0: bool)) -> [0: bb2, otherwise: bb1]; -+ switchInt((_2.0: bool)) -> [0: bb5, otherwise: bb1]; ++ switchInt((_2.0: bool)) -> [0: bb6, otherwise: bb1]; } bb1: { - switchInt((_2.1: bool)) -> [0: bb4, otherwise: bb3]; -+ switchInt((_2.1: bool)) -> [0: bb10, otherwise: bb2]; ++ switchInt((_2.1: bool)) -> [0: bb5, otherwise: bb2]; } bb2: { -- falseEdge -> [real: bb8, imaginary: bb1]; -+ switchInt((_2.0: bool)) -> [0: bb3, otherwise: bb17]; +- falseEdge -> [real: bb9, imaginary: bb1]; ++ switchInt((_2.0: bool)) -> [0: bb3, otherwise: bb4]; } bb3: { @@ -51,11 +51,11 @@ - } - - bb4: { -- falseEdge -> [real: bb13, imaginary: bb3]; +- falseEdge -> [real: bb8, imaginary: bb3]; - } - - bb5: { -- falseEdge -> [real: bb20, imaginary: bb6]; +- falseEdge -> [real: bb7, imaginary: bb6]; - } - - bb6: { @@ -63,19 +63,37 @@ _15 = (_2.1: bool); StorageLive(_16); _16 = move (_2.2: std::string::String); -- goto -> bb19; -+ goto -> bb16; +- goto -> bb20; ++ goto -> bb17; } - bb7: { + bb4: { - _0 = const 1_i32; -- drop(_7) -> [return: bb18, unwind: bb25]; -+ drop(_7) -> [return: bb15, unwind: bb22]; + StorageLive(_15); + _15 = (_2.1: bool); + StorageLive(_16); + _16 = move (_2.2: std::string::String); +- goto -> bb20; ++ goto -> bb17; } - bb8: { + bb5: { + StorageLive(_6); + _6 = &(_2.0: bool); + StorageLive(_8); + _8 = &(_2.2: std::string::String); +- _3 = &fake shallow (_2.0: bool); +- _4 = &fake shallow (_2.1: bool); + StorageLive(_12); + StorageLive(_13); + _13 = _1; +- switchInt(move _13) -> [0: bb16, otherwise: bb15]; ++ switchInt(move _13) -> [0: bb13, otherwise: bb12]; + } + +- bb9: { ++ bb6: { StorageLive(_6); _6 = &(_2.1: bool); StorageLive(_8); @@ -85,12 +103,19 @@ StorageLive(_9); StorageLive(_10); _10 = _1; -- switchInt(move _10) -> [0: bb10, otherwise: bb9]; -+ switchInt(move _10) -> [0: bb7, otherwise: bb6]; +- switchInt(move _10) -> [0: bb12, otherwise: bb11]; ++ switchInt(move _10) -> [0: bb9, otherwise: bb8]; } -- bb9: { -+ bb6: { +- bb10: { ++ bb7: { + _0 = const 1_i32; +- drop(_7) -> [return: bb19, unwind: bb25]; ++ drop(_7) -> [return: bb16, unwind: bb22]; + } + +- bb11: { ++ bb8: { _0 = const 3_i32; StorageDead(_10); StorageDead(_9); @@ -98,15 +123,15 @@ + goto -> bb20; } -- bb10: { -+ bb7: { +- bb12: { ++ bb9: { _9 = (*_6); -- switchInt(move _9) -> [0: bb12, otherwise: bb11]; -+ switchInt(move _9) -> [0: bb9, otherwise: bb8]; +- switchInt(move _9) -> [0: bb14, otherwise: bb13]; ++ switchInt(move _9) -> [0: bb11, otherwise: bb10]; } -- bb11: { -+ bb8: { +- bb13: { ++ bb10: { StorageDead(_10); StorageDead(_9); - FakeRead(ForMatchGuard, _3); @@ -117,12 +142,12 @@ _5 = (_2.1: bool); StorageLive(_7); _7 = move (_2.2: std::string::String); -- goto -> bb7; -+ goto -> bb4; +- goto -> bb10; ++ goto -> bb7; } -- bb12: { -+ bb9: { +- bb14: { ++ bb11: { StorageDead(_10); StorageDead(_9); StorageDead(_8); @@ -131,23 +156,8 @@ + goto -> bb1; } -- bb13: { -+ bb10: { - StorageLive(_6); - _6 = &(_2.0: bool); - StorageLive(_8); - _8 = &(_2.2: std::string::String); -- _3 = &fake shallow (_2.0: bool); -- _4 = &fake shallow (_2.1: bool); - StorageLive(_12); - StorageLive(_13); - _13 = _1; -- switchInt(move _13) -> [0: bb15, otherwise: bb14]; -+ switchInt(move _13) -> [0: bb12, otherwise: bb11]; - } - -- bb14: { -+ bb11: { +- bb15: { ++ bb12: { _0 = const 3_i32; StorageDead(_13); StorageDead(_12); @@ -155,15 +165,15 @@ + goto -> bb20; } -- bb15: { -+ bb12: { +- bb16: { ++ bb13: { _12 = (*_6); -- switchInt(move _12) -> [0: bb17, otherwise: bb16]; -+ switchInt(move _12) -> [0: bb14, otherwise: bb13]; +- switchInt(move _12) -> [0: bb18, otherwise: bb17]; ++ switchInt(move _12) -> [0: bb15, otherwise: bb14]; } -- bb16: { -+ bb13: { +- bb17: { ++ bb14: { StorageDead(_13); StorageDead(_12); - FakeRead(ForMatchGuard, _3); @@ -174,12 +184,12 @@ _5 = (_2.0: bool); StorageLive(_7); _7 = move (_2.2: std::string::String); -- goto -> bb7; -+ goto -> bb4; +- goto -> bb10; ++ goto -> bb7; } -- bb17: { -+ bb14: { +- bb18: { ++ bb15: { StorageDead(_13); StorageDead(_12); StorageDead(_8); @@ -188,8 +198,8 @@ + goto -> bb2; } -- bb18: { -+ bb15: { +- bb19: { ++ bb16: { StorageDead(_7); StorageDead(_5); StorageDead(_8); @@ -198,23 +208,13 @@ + goto -> bb19; } -- bb19: { -+ bb16: { +- bb20: { ++ bb17: { _0 = const 2_i32; - drop(_16) -> [return: bb21, unwind: bb25]; + drop(_16) -> [return: bb18, unwind: bb22]; } -- bb20: { -+ bb17: { - StorageLive(_15); - _15 = (_2.1: bool); - StorageLive(_16); - _16 = move (_2.2: std::string::String); -- goto -> bb19; -+ goto -> bb16; - } - - bb21: { + bb18: { StorageDead(_16); diff --git a/tests/mir-opt/matches_reduce_branches.match_i128_u128.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_i128_u128.MatchBranchSimplification.diff index 1f20349fdece4..dc50ae9547255 100644 --- a/tests/mir-opt/matches_reduce_branches.match_i128_u128.MatchBranchSimplification.diff +++ b/tests/mir-opt/matches_reduce_branches.match_i128_u128.MatchBranchSimplification.diff @@ -8,7 +8,7 @@ bb0: { _2 = discriminant(_1); - switchInt(move _2) -> [1: bb3, 2: bb4, 3: bb5, 340282366920938463463374607431768211455: bb2, otherwise: bb1]; + switchInt(move _2) -> [1: bb5, 2: bb4, 3: bb3, 340282366920938463463374607431768211455: bb2, otherwise: bb1]; } bb1: { @@ -21,7 +21,7 @@ } bb3: { - _0 = const 1_u128; + _0 = const 3_u128; goto -> bb6; } @@ -31,7 +31,7 @@ } bb5: { - _0 = const 3_u128; + _0 = const 1_u128; goto -> bb6; } diff --git a/tests/mir-opt/matches_reduce_branches.match_i16_i8.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_i16_i8.MatchBranchSimplification.diff index 4b435310916a7..3514914b8ecb0 100644 --- a/tests/mir-opt/matches_reduce_branches.match_i16_i8.MatchBranchSimplification.diff +++ b/tests/mir-opt/matches_reduce_branches.match_i16_i8.MatchBranchSimplification.diff @@ -8,7 +8,7 @@ bb0: { _2 = discriminant(_1); - switchInt(move _2) -> [65535: bb3, 2: bb4, 65533: bb2, otherwise: bb1]; + switchInt(move _2) -> [65535: bb4, 2: bb3, 65533: bb2, otherwise: bb1]; } bb1: { @@ -21,12 +21,12 @@ } bb3: { - _0 = const -1_i8; + _0 = const 2_i8; goto -> bb5; } bb4: { - _0 = const 2_i8; + _0 = const -1_i8; goto -> bb5; } diff --git a/tests/mir-opt/matches_reduce_branches.match_i8_i16.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_i8_i16.MatchBranchSimplification.diff index 8a390736add15..ff4255ec8cc97 100644 --- a/tests/mir-opt/matches_reduce_branches.match_i8_i16.MatchBranchSimplification.diff +++ b/tests/mir-opt/matches_reduce_branches.match_i8_i16.MatchBranchSimplification.diff @@ -8,7 +8,7 @@ bb0: { _2 = discriminant(_1); - switchInt(move _2) -> [255: bb3, 2: bb4, 253: bb2, otherwise: bb1]; + switchInt(move _2) -> [255: bb4, 2: bb3, 253: bb2, otherwise: bb1]; } bb1: { @@ -21,12 +21,12 @@ } bb3: { - _0 = const -1_i16; + _0 = const 2_i16; goto -> bb5; } bb4: { - _0 = const 2_i16; + _0 = const -1_i16; goto -> bb5; } diff --git a/tests/mir-opt/matches_reduce_branches.match_i8_i16_failed.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_i8_i16_failed.MatchBranchSimplification.diff index b021779229454..022039ecee629 100644 --- a/tests/mir-opt/matches_reduce_branches.match_i8_i16_failed.MatchBranchSimplification.diff +++ b/tests/mir-opt/matches_reduce_branches.match_i8_i16_failed.MatchBranchSimplification.diff @@ -8,7 +8,7 @@ bb0: { _2 = discriminant(_1); - switchInt(move _2) -> [255: bb3, 2: bb4, 253: bb2, otherwise: bb1]; + switchInt(move _2) -> [255: bb4, 2: bb3, 253: bb2, otherwise: bb1]; } bb1: { @@ -21,12 +21,12 @@ } bb3: { - _0 = const -1_i16; + _0 = const 2_i16; goto -> bb5; } bb4: { - _0 = const 2_i16; + _0 = const -1_i16; goto -> bb5; } diff --git a/tests/mir-opt/matches_reduce_branches.match_u8_i16_fallback.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_u8_i16_fallback.MatchBranchSimplification.diff index 8fa497fe89002..5690f17f24f65 100644 --- a/tests/mir-opt/matches_reduce_branches.match_u8_i16_fallback.MatchBranchSimplification.diff +++ b/tests/mir-opt/matches_reduce_branches.match_u8_i16_fallback.MatchBranchSimplification.diff @@ -6,7 +6,7 @@ let mut _0: i16; bb0: { - switchInt(_1) -> [1: bb2, 2: bb3, otherwise: bb1]; + switchInt(_1) -> [1: bb3, 2: bb2, otherwise: bb1]; } bb1: { @@ -15,12 +15,12 @@ } bb2: { - _0 = const 1_i16; + _0 = const 2_i16; goto -> bb4; } bb3: { - _0 = const 2_i16; + _0 = const 1_i16; goto -> bb4; } diff --git a/tests/mir-opt/matches_reduce_branches.match_u8_u16.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_u8_u16.MatchBranchSimplification.diff index 043fdb197a3ac..dc9c1c2b97f1f 100644 --- a/tests/mir-opt/matches_reduce_branches.match_u8_u16.MatchBranchSimplification.diff +++ b/tests/mir-opt/matches_reduce_branches.match_u8_u16.MatchBranchSimplification.diff @@ -8,7 +8,7 @@ bb0: { _2 = discriminant(_1); - switchInt(move _2) -> [1: bb3, 2: bb4, 5: bb2, otherwise: bb1]; + switchInt(move _2) -> [1: bb4, 2: bb3, 5: bb2, otherwise: bb1]; } bb1: { @@ -21,12 +21,12 @@ } bb3: { - _0 = const 1_u16; + _0 = const 2_u16; goto -> bb5; } bb4: { - _0 = const 2_u16; + _0 = const 1_u16; goto -> bb5; } diff --git a/tests/mir-opt/or_pattern.shortcut_second_or.SimplifyCfg-initial.after.mir b/tests/mir-opt/or_pattern.shortcut_second_or.SimplifyCfg-initial.after.mir index e357e785e33ee..6c76a72b77577 100644 --- a/tests/mir-opt/or_pattern.shortcut_second_or.SimplifyCfg-initial.after.mir +++ b/tests/mir-opt/or_pattern.shortcut_second_or.SimplifyCfg-initial.after.mir @@ -39,7 +39,7 @@ fn shortcut_second_or() -> () { } bb5: { - falseEdge -> [real: bb10, imaginary: bb6]; + falseEdge -> [real: bb12, imaginary: bb6]; } bb6: { @@ -47,18 +47,19 @@ fn shortcut_second_or() -> () { } bb7: { - falseEdge -> [real: bb12, imaginary: bb8]; + falseEdge -> [real: bb10, imaginary: bb8]; } bb8: { - falseEdge -> [real: bb13, imaginary: bb3]; + falseEdge -> [real: bb9, imaginary: bb3]; } bb9: { - _0 = const (); - StorageDead(_4); - StorageDead(_3); - goto -> bb14; + StorageLive(_3); + _3 = (_1.0: (i32, i32)); + StorageLive(_4); + _4 = (_1.1: i32); + goto -> bb13; } bb10: { @@ -66,7 +67,7 @@ fn shortcut_second_or() -> () { _3 = (_1.0: (i32, i32)); StorageLive(_4); _4 = (_1.1: i32); - goto -> bb9; + goto -> bb13; } bb11: { @@ -74,7 +75,7 @@ fn shortcut_second_or() -> () { _3 = (_1.0: (i32, i32)); StorageLive(_4); _4 = (_1.1: i32); - goto -> bb9; + goto -> bb13; } bb12: { @@ -82,15 +83,14 @@ fn shortcut_second_or() -> () { _3 = (_1.0: (i32, i32)); StorageLive(_4); _4 = (_1.1: i32); - goto -> bb9; + goto -> bb13; } bb13: { - StorageLive(_3); - _3 = (_1.0: (i32, i32)); - StorageLive(_4); - _4 = (_1.1: i32); - goto -> bb9; + _0 = const (); + StorageDead(_4); + StorageDead(_3); + goto -> bb14; } bb14: { diff --git a/tests/mir-opt/or_pattern.single_switchint.SimplifyCfg-initial.after.mir b/tests/mir-opt/or_pattern.single_switchint.SimplifyCfg-initial.after.mir index eafe95b4a11ea..8b0ef7b29d7be 100644 --- a/tests/mir-opt/or_pattern.single_switchint.SimplifyCfg-initial.after.mir +++ b/tests/mir-opt/or_pattern.single_switchint.SimplifyCfg-initial.after.mir @@ -22,7 +22,7 @@ fn single_switchint() -> () { } bb3: { - falseEdge -> [real: bb9, imaginary: bb4]; + falseEdge -> [real: bb12, imaginary: bb4]; } bb4: { @@ -30,11 +30,11 @@ fn single_switchint() -> () { } bb5: { - falseEdge -> [real: bb10, imaginary: bb6]; + falseEdge -> [real: bb11, imaginary: bb6]; } bb6: { - falseEdge -> [real: bb11, imaginary: bb1]; + falseEdge -> [real: bb10, imaginary: bb1]; } bb7: { @@ -43,26 +43,26 @@ fn single_switchint() -> () { } bb8: { - falseEdge -> [real: bb12, imaginary: bb7]; + falseEdge -> [real: bb9, imaginary: bb7]; } bb9: { - _1 = const 1_i32; + _1 = const 4_i32; goto -> bb13; } bb10: { - _1 = const 2_i32; + _1 = const 3_i32; goto -> bb13; } bb11: { - _1 = const 3_i32; + _1 = const 2_i32; goto -> bb13; } bb12: { - _1 = const 4_i32; + _1 = const 1_i32; goto -> bb13; } diff --git a/tests/mir-opt/single_use_consts.match_const.SingleUseConsts.panic-abort.diff b/tests/mir-opt/single_use_consts.match_const.SingleUseConsts.panic-abort.diff index 8d87438a47aec..998b89919d1bd 100644 --- a/tests/mir-opt/single_use_consts.match_const.SingleUseConsts.panic-abort.diff +++ b/tests/mir-opt/single_use_consts.match_const.SingleUseConsts.panic-abort.diff @@ -8,9 +8,9 @@ bb0: { StorageLive(_1); - _1 = const ::ASSOC_INT; -- switchInt(_1) -> [7: bb2, 42: bb3, otherwise: bb1]; +- switchInt(_1) -> [7: bb3, 42: bb2, otherwise: bb1]; + nop; -+ switchInt(const ::ASSOC_INT) -> [7: bb2, 42: bb3, otherwise: bb1]; ++ switchInt(const ::ASSOC_INT) -> [7: bb3, 42: bb2, otherwise: bb1]; } bb1: { @@ -19,12 +19,12 @@ } bb2: { - _0 = const "hello"; + _0 = const "towel"; goto -> bb4; } bb3: { - _0 = const "towel"; + _0 = const "hello"; goto -> bb4; } diff --git a/tests/mir-opt/single_use_consts.match_const.SingleUseConsts.panic-unwind.diff b/tests/mir-opt/single_use_consts.match_const.SingleUseConsts.panic-unwind.diff index 8d87438a47aec..998b89919d1bd 100644 --- a/tests/mir-opt/single_use_consts.match_const.SingleUseConsts.panic-unwind.diff +++ b/tests/mir-opt/single_use_consts.match_const.SingleUseConsts.panic-unwind.diff @@ -8,9 +8,9 @@ bb0: { StorageLive(_1); - _1 = const ::ASSOC_INT; -- switchInt(_1) -> [7: bb2, 42: bb3, otherwise: bb1]; +- switchInt(_1) -> [7: bb3, 42: bb2, otherwise: bb1]; + nop; -+ switchInt(const ::ASSOC_INT) -> [7: bb2, 42: bb3, otherwise: bb1]; ++ switchInt(const ::ASSOC_INT) -> [7: bb3, 42: bb2, otherwise: bb1]; } bb1: { @@ -19,12 +19,12 @@ } bb2: { - _0 = const "hello"; + _0 = const "towel"; goto -> bb4; } bb3: { - _0 = const "towel"; + _0 = const "hello"; goto -> bb4; } diff --git a/tests/mir-opt/single_use_consts.match_const_debug.SingleUseConsts.panic-abort.diff b/tests/mir-opt/single_use_consts.match_const_debug.SingleUseConsts.panic-abort.diff index f192f3feb96e5..30f66ef6b8237 100644 --- a/tests/mir-opt/single_use_consts.match_const_debug.SingleUseConsts.panic-abort.diff +++ b/tests/mir-opt/single_use_consts.match_const_debug.SingleUseConsts.panic-abort.diff @@ -20,8 +20,8 @@ bb1: { StorageDead(_2); -- switchInt(_1) -> [7: bb3, 42: bb4, otherwise: bb2]; -+ switchInt(const ::ASSOC_INT) -> [7: bb3, 42: bb4, otherwise: bb2]; +- switchInt(_1) -> [7: bb4, 42: bb3, otherwise: bb2]; ++ switchInt(const ::ASSOC_INT) -> [7: bb4, 42: bb3, otherwise: bb2]; } bb2: { @@ -30,12 +30,12 @@ } bb3: { - _0 = const "hello"; + _0 = const "towel"; goto -> bb5; } bb4: { - _0 = const "towel"; + _0 = const "hello"; goto -> bb5; } diff --git a/tests/mir-opt/single_use_consts.match_const_debug.SingleUseConsts.panic-unwind.diff b/tests/mir-opt/single_use_consts.match_const_debug.SingleUseConsts.panic-unwind.diff index 261faf415f3bc..ed12ad4b93e89 100644 --- a/tests/mir-opt/single_use_consts.match_const_debug.SingleUseConsts.panic-unwind.diff +++ b/tests/mir-opt/single_use_consts.match_const_debug.SingleUseConsts.panic-unwind.diff @@ -20,8 +20,8 @@ bb1: { StorageDead(_2); -- switchInt(_1) -> [7: bb3, 42: bb4, otherwise: bb2]; -+ switchInt(const ::ASSOC_INT) -> [7: bb3, 42: bb4, otherwise: bb2]; +- switchInt(_1) -> [7: bb4, 42: bb3, otherwise: bb2]; ++ switchInt(const ::ASSOC_INT) -> [7: bb4, 42: bb3, otherwise: bb2]; } bb2: { @@ -30,12 +30,12 @@ } bb3: { - _0 = const "hello"; + _0 = const "towel"; goto -> bb5; } bb4: { - _0 = const "towel"; + _0 = const "hello"; goto -> bb5; } diff --git a/tests/mir-opt/uninhabited_fallthrough_elimination.eliminate_fallthrough.UnreachableEnumBranching.diff b/tests/mir-opt/uninhabited_fallthrough_elimination.eliminate_fallthrough.UnreachableEnumBranching.diff index 098b620dfaab7..c0ea9fae7df5b 100644 --- a/tests/mir-opt/uninhabited_fallthrough_elimination.eliminate_fallthrough.UnreachableEnumBranching.diff +++ b/tests/mir-opt/uninhabited_fallthrough_elimination.eliminate_fallthrough.UnreachableEnumBranching.diff @@ -8,8 +8,8 @@ bb0: { _2 = discriminant(_1); -- switchInt(move _2) -> [1: bb3, 2: bb2, otherwise: bb1]; -+ switchInt(move _2) -> [1: bb3, 2: bb2, otherwise: bb5]; +- switchInt(move _2) -> [1: bb2, 2: bb3, otherwise: bb1]; ++ switchInt(move _2) -> [1: bb2, 2: bb3, otherwise: bb5]; } bb1: { @@ -18,12 +18,12 @@ } bb2: { - _0 = const 1_u32; + _0 = const 2_u32; goto -> bb4; } bb3: { - _0 = const 2_u32; + _0 = const 1_u32; goto -> bb4; } diff --git a/tests/mir-opt/uninhabited_fallthrough_elimination.keep_fallthrough.UnreachableEnumBranching.diff b/tests/mir-opt/uninhabited_fallthrough_elimination.keep_fallthrough.UnreachableEnumBranching.diff index 995e32b033f24..2082e8046ad0b 100644 --- a/tests/mir-opt/uninhabited_fallthrough_elimination.keep_fallthrough.UnreachableEnumBranching.diff +++ b/tests/mir-opt/uninhabited_fallthrough_elimination.keep_fallthrough.UnreachableEnumBranching.diff @@ -8,8 +8,8 @@ bb0: { _2 = discriminant(_1); -- switchInt(move _2) -> [0: bb2, 1: bb3, otherwise: bb1]; -+ switchInt(move _2) -> [0: bb5, 1: bb3, 2: bb1, otherwise: bb5]; +- switchInt(move _2) -> [0: bb3, 1: bb2, otherwise: bb1]; ++ switchInt(move _2) -> [0: bb5, 1: bb2, 2: bb1, otherwise: bb5]; } bb1: { @@ -18,12 +18,12 @@ } bb2: { - _0 = const 1_u32; + _0 = const 2_u32; goto -> bb4; } bb3: { - _0 = const 2_u32; + _0 = const 1_u32; goto -> bb4; } diff --git a/tests/mir-opt/unreachable_enum_branching.byref.UnreachableEnumBranching.panic-abort.diff b/tests/mir-opt/unreachable_enum_branching.byref.UnreachableEnumBranching.panic-abort.diff index e5dab5d52a6b7..ed54a38f70bdb 100644 --- a/tests/mir-opt/unreachable_enum_branching.byref.UnreachableEnumBranching.panic-abort.diff +++ b/tests/mir-opt/unreachable_enum_branching.byref.UnreachableEnumBranching.panic-abort.diff @@ -30,8 +30,8 @@ StorageLive(_4); _4 = &(_1.1: Test3); _5 = discriminant((*_4)); -- switchInt(move _5) -> [0: bb3, 1: bb4, 2: bb5, 3: bb2, otherwise: bb1]; -+ switchInt(move _5) -> [0: bb1, 1: bb1, 2: bb5, 3: bb2, otherwise: bb1]; +- switchInt(move _5) -> [0: bb5, 1: bb4, 2: bb3, 3: bb2, otherwise: bb1]; ++ switchInt(move _5) -> [0: bb1, 1: bb1, 2: bb3, 3: bb2, otherwise: bb1]; } bb1: { @@ -47,7 +47,10 @@ } bb3: { - _3 = const "A(Empty)"; + StorageLive(_7); + _7 = const "C"; + _3 = &(*_7); + StorageDead(_7); goto -> bb6; } @@ -60,10 +63,7 @@ } bb5: { - StorageLive(_7); - _7 = const "C"; - _3 = &(*_7); - StorageDead(_7); + _3 = const "A(Empty)"; goto -> bb6; } @@ -72,8 +72,8 @@ StorageDead(_3); StorageLive(_9); _10 = discriminant((_1.1: Test3)); -- switchInt(move _10) -> [0: bb8, 1: bb9, 2: bb10, 3: bb7, otherwise: bb1]; -+ switchInt(move _10) -> [0: bb1, 1: bb1, 2: bb10, 3: bb7, otherwise: bb1]; +- switchInt(move _10) -> [0: bb10, 1: bb9, 2: bb8, 3: bb7, otherwise: bb1]; ++ switchInt(move _10) -> [0: bb1, 1: bb1, 2: bb8, 3: bb7, otherwise: bb1]; } bb7: { @@ -85,7 +85,10 @@ } bb8: { - _9 = const "A(Empty)"; + StorageLive(_12); + _12 = const "C"; + _9 = &(*_12); + StorageDead(_12); goto -> bb11; } @@ -98,10 +101,7 @@ } bb10: { - StorageLive(_12); - _12 = const "C"; - _9 = &(*_12); - StorageDead(_12); + _9 = const "A(Empty)"; goto -> bb11; } diff --git a/tests/mir-opt/unreachable_enum_branching.byref.UnreachableEnumBranching.panic-unwind.diff b/tests/mir-opt/unreachable_enum_branching.byref.UnreachableEnumBranching.panic-unwind.diff index e5dab5d52a6b7..ed54a38f70bdb 100644 --- a/tests/mir-opt/unreachable_enum_branching.byref.UnreachableEnumBranching.panic-unwind.diff +++ b/tests/mir-opt/unreachable_enum_branching.byref.UnreachableEnumBranching.panic-unwind.diff @@ -30,8 +30,8 @@ StorageLive(_4); _4 = &(_1.1: Test3); _5 = discriminant((*_4)); -- switchInt(move _5) -> [0: bb3, 1: bb4, 2: bb5, 3: bb2, otherwise: bb1]; -+ switchInt(move _5) -> [0: bb1, 1: bb1, 2: bb5, 3: bb2, otherwise: bb1]; +- switchInt(move _5) -> [0: bb5, 1: bb4, 2: bb3, 3: bb2, otherwise: bb1]; ++ switchInt(move _5) -> [0: bb1, 1: bb1, 2: bb3, 3: bb2, otherwise: bb1]; } bb1: { @@ -47,7 +47,10 @@ } bb3: { - _3 = const "A(Empty)"; + StorageLive(_7); + _7 = const "C"; + _3 = &(*_7); + StorageDead(_7); goto -> bb6; } @@ -60,10 +63,7 @@ } bb5: { - StorageLive(_7); - _7 = const "C"; - _3 = &(*_7); - StorageDead(_7); + _3 = const "A(Empty)"; goto -> bb6; } @@ -72,8 +72,8 @@ StorageDead(_3); StorageLive(_9); _10 = discriminant((_1.1: Test3)); -- switchInt(move _10) -> [0: bb8, 1: bb9, 2: bb10, 3: bb7, otherwise: bb1]; -+ switchInt(move _10) -> [0: bb1, 1: bb1, 2: bb10, 3: bb7, otherwise: bb1]; +- switchInt(move _10) -> [0: bb10, 1: bb9, 2: bb8, 3: bb7, otherwise: bb1]; ++ switchInt(move _10) -> [0: bb1, 1: bb1, 2: bb8, 3: bb7, otherwise: bb1]; } bb7: { @@ -85,7 +85,10 @@ } bb8: { - _9 = const "A(Empty)"; + StorageLive(_12); + _12 = const "C"; + _9 = &(*_12); + StorageDead(_12); goto -> bb11; } @@ -98,10 +101,7 @@ } bb10: { - StorageLive(_12); - _12 = const "C"; - _9 = &(*_12); - StorageDead(_12); + _9 = const "A(Empty)"; goto -> bb11; } diff --git a/tests/mir-opt/unreachable_enum_branching.otherwise_t1.UnreachableEnumBranching.panic-abort.diff b/tests/mir-opt/unreachable_enum_branching.otherwise_t1.UnreachableEnumBranching.panic-abort.diff index 02b9f02f4c0ec..be934ac688bb5 100644 --- a/tests/mir-opt/unreachable_enum_branching.otherwise_t1.UnreachableEnumBranching.panic-abort.diff +++ b/tests/mir-opt/unreachable_enum_branching.otherwise_t1.UnreachableEnumBranching.panic-abort.diff @@ -14,7 +14,7 @@ StorageLive(_2); _2 = Test1::C; _3 = discriminant(_2); -- switchInt(move _3) -> [0: bb2, 1: bb3, otherwise: bb1]; +- switchInt(move _3) -> [0: bb3, 1: bb2, otherwise: bb1]; + switchInt(move _3) -> [0: bb5, 1: bb5, 2: bb1, otherwise: bb5]; } @@ -27,11 +27,6 @@ } bb2: { - _1 = const "A(Empty)"; - goto -> bb4; - } - - bb3: { StorageLive(_4); _4 = const "B(Empty)"; _1 = &(*_4); @@ -39,6 +34,11 @@ goto -> bb4; } + bb3: { + _1 = const "A(Empty)"; + goto -> bb4; + } + bb4: { StorageDead(_2); StorageDead(_1); diff --git a/tests/mir-opt/unreachable_enum_branching.otherwise_t1.UnreachableEnumBranching.panic-unwind.diff b/tests/mir-opt/unreachable_enum_branching.otherwise_t1.UnreachableEnumBranching.panic-unwind.diff index 02b9f02f4c0ec..be934ac688bb5 100644 --- a/tests/mir-opt/unreachable_enum_branching.otherwise_t1.UnreachableEnumBranching.panic-unwind.diff +++ b/tests/mir-opt/unreachable_enum_branching.otherwise_t1.UnreachableEnumBranching.panic-unwind.diff @@ -14,7 +14,7 @@ StorageLive(_2); _2 = Test1::C; _3 = discriminant(_2); -- switchInt(move _3) -> [0: bb2, 1: bb3, otherwise: bb1]; +- switchInt(move _3) -> [0: bb3, 1: bb2, otherwise: bb1]; + switchInt(move _3) -> [0: bb5, 1: bb5, 2: bb1, otherwise: bb5]; } @@ -27,11 +27,6 @@ } bb2: { - _1 = const "A(Empty)"; - goto -> bb4; - } - - bb3: { StorageLive(_4); _4 = const "B(Empty)"; _1 = &(*_4); @@ -39,6 +34,11 @@ goto -> bb4; } + bb3: { + _1 = const "A(Empty)"; + goto -> bb4; + } + bb4: { StorageDead(_2); StorageDead(_1); diff --git a/tests/mir-opt/unreachable_enum_branching.otherwise_t3.UnreachableEnumBranching.panic-abort.diff b/tests/mir-opt/unreachable_enum_branching.otherwise_t3.UnreachableEnumBranching.panic-abort.diff index d3376442376d3..120061841a02f 100644 --- a/tests/mir-opt/unreachable_enum_branching.otherwise_t3.UnreachableEnumBranching.panic-abort.diff +++ b/tests/mir-opt/unreachable_enum_branching.otherwise_t3.UnreachableEnumBranching.panic-abort.diff @@ -14,7 +14,7 @@ StorageLive(_2); _2 = Test3::C; _3 = discriminant(_2); -- switchInt(move _3) -> [0: bb2, 1: bb3, otherwise: bb1]; +- switchInt(move _3) -> [0: bb3, 1: bb2, otherwise: bb1]; + switchInt(move _3) -> [0: bb5, 1: bb5, otherwise: bb1]; } @@ -27,11 +27,6 @@ } bb2: { - _1 = const "A(Empty)"; - goto -> bb4; - } - - bb3: { StorageLive(_4); _4 = const "B(Empty)"; _1 = &(*_4); @@ -39,6 +34,11 @@ goto -> bb4; } + bb3: { + _1 = const "A(Empty)"; + goto -> bb4; + } + bb4: { StorageDead(_2); StorageDead(_1); diff --git a/tests/mir-opt/unreachable_enum_branching.otherwise_t3.UnreachableEnumBranching.panic-unwind.diff b/tests/mir-opt/unreachable_enum_branching.otherwise_t3.UnreachableEnumBranching.panic-unwind.diff index d3376442376d3..120061841a02f 100644 --- a/tests/mir-opt/unreachable_enum_branching.otherwise_t3.UnreachableEnumBranching.panic-unwind.diff +++ b/tests/mir-opt/unreachable_enum_branching.otherwise_t3.UnreachableEnumBranching.panic-unwind.diff @@ -14,7 +14,7 @@ StorageLive(_2); _2 = Test3::C; _3 = discriminant(_2); -- switchInt(move _3) -> [0: bb2, 1: bb3, otherwise: bb1]; +- switchInt(move _3) -> [0: bb3, 1: bb2, otherwise: bb1]; + switchInt(move _3) -> [0: bb5, 1: bb5, otherwise: bb1]; } @@ -27,11 +27,6 @@ } bb2: { - _1 = const "A(Empty)"; - goto -> bb4; - } - - bb3: { StorageLive(_4); _4 = const "B(Empty)"; _1 = &(*_4); @@ -39,6 +34,11 @@ goto -> bb4; } + bb3: { + _1 = const "A(Empty)"; + goto -> bb4; + } + bb4: { StorageDead(_2); StorageDead(_1); diff --git a/tests/mir-opt/unreachable_enum_branching.otherwise_t4.UnreachableEnumBranching.panic-abort.diff b/tests/mir-opt/unreachable_enum_branching.otherwise_t4.UnreachableEnumBranching.panic-abort.diff index 8f0d5b7cd99c4..b86814d611938 100644 --- a/tests/mir-opt/unreachable_enum_branching.otherwise_t4.UnreachableEnumBranching.panic-abort.diff +++ b/tests/mir-opt/unreachable_enum_branching.otherwise_t4.UnreachableEnumBranching.panic-abort.diff @@ -14,7 +14,7 @@ StorageLive(_2); _2 = Test4::C; _3 = discriminant(_2); - switchInt(move _3) -> [0: bb2, 1: bb3, otherwise: bb1]; + switchInt(move _3) -> [0: bb3, 1: bb2, otherwise: bb1]; } bb1: { @@ -26,11 +26,6 @@ } bb2: { - _1 = const "A(i32)"; - goto -> bb4; - } - - bb3: { StorageLive(_4); _4 = const "B(i32)"; _1 = &(*_4); @@ -38,6 +33,11 @@ goto -> bb4; } + bb3: { + _1 = const "A(i32)"; + goto -> bb4; + } + bb4: { StorageDead(_2); StorageDead(_1); diff --git a/tests/mir-opt/unreachable_enum_branching.otherwise_t4.UnreachableEnumBranching.panic-unwind.diff b/tests/mir-opt/unreachable_enum_branching.otherwise_t4.UnreachableEnumBranching.panic-unwind.diff index 8f0d5b7cd99c4..b86814d611938 100644 --- a/tests/mir-opt/unreachable_enum_branching.otherwise_t4.UnreachableEnumBranching.panic-unwind.diff +++ b/tests/mir-opt/unreachable_enum_branching.otherwise_t4.UnreachableEnumBranching.panic-unwind.diff @@ -14,7 +14,7 @@ StorageLive(_2); _2 = Test4::C; _3 = discriminant(_2); - switchInt(move _3) -> [0: bb2, 1: bb3, otherwise: bb1]; + switchInt(move _3) -> [0: bb3, 1: bb2, otherwise: bb1]; } bb1: { @@ -26,11 +26,6 @@ } bb2: { - _1 = const "A(i32)"; - goto -> bb4; - } - - bb3: { StorageLive(_4); _4 = const "B(i32)"; _1 = &(*_4); @@ -38,6 +33,11 @@ goto -> bb4; } + bb3: { + _1 = const "A(i32)"; + goto -> bb4; + } + bb4: { StorageDead(_2); StorageDead(_1); diff --git a/tests/mir-opt/unreachable_enum_branching.otherwise_t4_unreachable_default.UnreachableEnumBranching.panic-abort.diff b/tests/mir-opt/unreachable_enum_branching.otherwise_t4_unreachable_default.UnreachableEnumBranching.panic-abort.diff index b1ecd00858290..424ac6ba651c3 100644 --- a/tests/mir-opt/unreachable_enum_branching.otherwise_t4_unreachable_default.UnreachableEnumBranching.panic-abort.diff +++ b/tests/mir-opt/unreachable_enum_branching.otherwise_t4_unreachable_default.UnreachableEnumBranching.panic-abort.diff @@ -15,8 +15,8 @@ StorageLive(_2); _2 = Test4::C; _3 = discriminant(_2); -- switchInt(move _3) -> [0: bb2, 1: bb3, 2: bb4, otherwise: bb1]; -+ switchInt(move _3) -> [0: bb2, 1: bb3, 2: bb4, 3: bb1, otherwise: bb6]; +- switchInt(move _3) -> [0: bb4, 1: bb3, 2: bb2, otherwise: bb1]; ++ switchInt(move _3) -> [0: bb4, 1: bb3, 2: bb2, 3: bb1, otherwise: bb6]; } bb1: { @@ -28,7 +28,10 @@ } bb2: { - _1 = const "A(i32)"; + StorageLive(_5); + _5 = const "C"; + _1 = &(*_5); + StorageDead(_5); goto -> bb5; } @@ -41,10 +44,7 @@ } bb4: { - StorageLive(_5); - _5 = const "C"; - _1 = &(*_5); - StorageDead(_5); + _1 = const "A(i32)"; goto -> bb5; } diff --git a/tests/mir-opt/unreachable_enum_branching.otherwise_t4_unreachable_default.UnreachableEnumBranching.panic-unwind.diff b/tests/mir-opt/unreachable_enum_branching.otherwise_t4_unreachable_default.UnreachableEnumBranching.panic-unwind.diff index b1ecd00858290..424ac6ba651c3 100644 --- a/tests/mir-opt/unreachable_enum_branching.otherwise_t4_unreachable_default.UnreachableEnumBranching.panic-unwind.diff +++ b/tests/mir-opt/unreachable_enum_branching.otherwise_t4_unreachable_default.UnreachableEnumBranching.panic-unwind.diff @@ -15,8 +15,8 @@ StorageLive(_2); _2 = Test4::C; _3 = discriminant(_2); -- switchInt(move _3) -> [0: bb2, 1: bb3, 2: bb4, otherwise: bb1]; -+ switchInt(move _3) -> [0: bb2, 1: bb3, 2: bb4, 3: bb1, otherwise: bb6]; +- switchInt(move _3) -> [0: bb4, 1: bb3, 2: bb2, otherwise: bb1]; ++ switchInt(move _3) -> [0: bb4, 1: bb3, 2: bb2, 3: bb1, otherwise: bb6]; } bb1: { @@ -28,7 +28,10 @@ } bb2: { - _1 = const "A(i32)"; + StorageLive(_5); + _5 = const "C"; + _1 = &(*_5); + StorageDead(_5); goto -> bb5; } @@ -41,10 +44,7 @@ } bb4: { - StorageLive(_5); - _5 = const "C"; - _1 = &(*_5); - StorageDead(_5); + _1 = const "A(i32)"; goto -> bb5; } diff --git a/tests/mir-opt/unreachable_enum_branching.otherwise_t4_unreachable_default_2.UnreachableEnumBranching.panic-abort.diff b/tests/mir-opt/unreachable_enum_branching.otherwise_t4_unreachable_default_2.UnreachableEnumBranching.panic-abort.diff index 28c6d4fb67599..4cd6d3f56833e 100644 --- a/tests/mir-opt/unreachable_enum_branching.otherwise_t4_unreachable_default_2.UnreachableEnumBranching.panic-abort.diff +++ b/tests/mir-opt/unreachable_enum_branching.otherwise_t4_unreachable_default_2.UnreachableEnumBranching.panic-abort.diff @@ -16,8 +16,8 @@ StorageLive(_2); _2 = Test4::C; _3 = discriminant(_2); -- switchInt(move _3) -> [0: bb2, 1: bb5, 2: bb6, otherwise: bb1]; -+ switchInt(move _3) -> [0: bb2, 1: bb5, 2: bb6, 3: bb1, otherwise: bb8]; +- switchInt(move _3) -> [0: bb2, 1: bb4, 2: bb3, otherwise: bb1]; ++ switchInt(move _3) -> [0: bb2, 1: bb4, 2: bb3, 3: bb1, otherwise: bb8]; } bb1: { @@ -29,23 +29,18 @@ } bb2: { - switchInt(((_2 as A).0: i32)) -> [1: bb3, 2: bb4, otherwise: bb1]; + switchInt(((_2 as A).0: i32)) -> [1: bb6, 2: bb5, otherwise: bb1]; } bb3: { - _1 = const "A(1)"; + StorageLive(_6); + _6 = const "C"; + _1 = &(*_6); + StorageDead(_6); goto -> bb7; } bb4: { - StorageLive(_4); - _4 = const "A(2)"; - _1 = &(*_4); - StorageDead(_4); - goto -> bb7; - } - - bb5: { StorageLive(_5); _5 = const "B(i32)"; _1 = &(*_5); @@ -53,11 +48,16 @@ goto -> bb7; } + bb5: { + StorageLive(_4); + _4 = const "A(2)"; + _1 = &(*_4); + StorageDead(_4); + goto -> bb7; + } + bb6: { - StorageLive(_6); - _6 = const "C"; - _1 = &(*_6); - StorageDead(_6); + _1 = const "A(1)"; goto -> bb7; } diff --git a/tests/mir-opt/unreachable_enum_branching.otherwise_t4_unreachable_default_2.UnreachableEnumBranching.panic-unwind.diff b/tests/mir-opt/unreachable_enum_branching.otherwise_t4_unreachable_default_2.UnreachableEnumBranching.panic-unwind.diff index 28c6d4fb67599..4cd6d3f56833e 100644 --- a/tests/mir-opt/unreachable_enum_branching.otherwise_t4_unreachable_default_2.UnreachableEnumBranching.panic-unwind.diff +++ b/tests/mir-opt/unreachable_enum_branching.otherwise_t4_unreachable_default_2.UnreachableEnumBranching.panic-unwind.diff @@ -16,8 +16,8 @@ StorageLive(_2); _2 = Test4::C; _3 = discriminant(_2); -- switchInt(move _3) -> [0: bb2, 1: bb5, 2: bb6, otherwise: bb1]; -+ switchInt(move _3) -> [0: bb2, 1: bb5, 2: bb6, 3: bb1, otherwise: bb8]; +- switchInt(move _3) -> [0: bb2, 1: bb4, 2: bb3, otherwise: bb1]; ++ switchInt(move _3) -> [0: bb2, 1: bb4, 2: bb3, 3: bb1, otherwise: bb8]; } bb1: { @@ -29,23 +29,18 @@ } bb2: { - switchInt(((_2 as A).0: i32)) -> [1: bb3, 2: bb4, otherwise: bb1]; + switchInt(((_2 as A).0: i32)) -> [1: bb6, 2: bb5, otherwise: bb1]; } bb3: { - _1 = const "A(1)"; + StorageLive(_6); + _6 = const "C"; + _1 = &(*_6); + StorageDead(_6); goto -> bb7; } bb4: { - StorageLive(_4); - _4 = const "A(2)"; - _1 = &(*_4); - StorageDead(_4); - goto -> bb7; - } - - bb5: { StorageLive(_5); _5 = const "B(i32)"; _1 = &(*_5); @@ -53,11 +48,16 @@ goto -> bb7; } + bb5: { + StorageLive(_4); + _4 = const "A(2)"; + _1 = &(*_4); + StorageDead(_4); + goto -> bb7; + } + bb6: { - StorageLive(_6); - _6 = const "C"; - _1 = &(*_6); - StorageDead(_6); + _1 = const "A(1)"; goto -> bb7; } diff --git a/tests/mir-opt/unreachable_enum_branching.otherwise_t5_unreachable_default.UnreachableEnumBranching.panic-abort.diff b/tests/mir-opt/unreachable_enum_branching.otherwise_t5_unreachable_default.UnreachableEnumBranching.panic-abort.diff index f36a7efd80d45..2de1f77eeec9e 100644 --- a/tests/mir-opt/unreachable_enum_branching.otherwise_t5_unreachable_default.UnreachableEnumBranching.panic-abort.diff +++ b/tests/mir-opt/unreachable_enum_branching.otherwise_t5_unreachable_default.UnreachableEnumBranching.panic-abort.diff @@ -15,8 +15,8 @@ StorageLive(_2); _2 = Test5::::C; _3 = discriminant(_2); -- switchInt(move _3) -> [255: bb2, 0: bb3, 5: bb4, otherwise: bb1]; -+ switchInt(move _3) -> [255: bb2, 0: bb3, 5: bb4, 3: bb1, otherwise: bb7]; +- switchInt(move _3) -> [255: bb4, 0: bb3, 5: bb2, otherwise: bb1]; ++ switchInt(move _3) -> [255: bb4, 0: bb3, 5: bb2, 3: bb1, otherwise: bb7]; } bb1: { @@ -28,7 +28,10 @@ } bb2: { - _1 = const "A(T)"; + StorageLive(_5); + _5 = const "C"; + _1 = &(*_5); + StorageDead(_5); goto -> bb5; } @@ -41,10 +44,7 @@ } bb4: { - StorageLive(_5); - _5 = const "C"; - _1 = &(*_5); - StorageDead(_5); + _1 = const "A(T)"; goto -> bb5; } diff --git a/tests/mir-opt/unreachable_enum_branching.otherwise_t5_unreachable_default.UnreachableEnumBranching.panic-unwind.diff b/tests/mir-opt/unreachable_enum_branching.otherwise_t5_unreachable_default.UnreachableEnumBranching.panic-unwind.diff index 20e31c24c84b5..5afb78c58a3c1 100644 --- a/tests/mir-opt/unreachable_enum_branching.otherwise_t5_unreachable_default.UnreachableEnumBranching.panic-unwind.diff +++ b/tests/mir-opt/unreachable_enum_branching.otherwise_t5_unreachable_default.UnreachableEnumBranching.panic-unwind.diff @@ -15,8 +15,8 @@ StorageLive(_2); _2 = Test5::::C; _3 = discriminant(_2); -- switchInt(move _3) -> [255: bb2, 0: bb3, 5: bb4, otherwise: bb1]; -+ switchInt(move _3) -> [255: bb2, 0: bb3, 5: bb4, 3: bb1, otherwise: bb8]; +- switchInt(move _3) -> [255: bb4, 0: bb3, 5: bb2, otherwise: bb1]; ++ switchInt(move _3) -> [255: bb4, 0: bb3, 5: bb2, 3: bb1, otherwise: bb8]; } bb1: { @@ -28,7 +28,10 @@ } bb2: { - _1 = const "A(T)"; + StorageLive(_5); + _5 = const "C"; + _1 = &(*_5); + StorageDead(_5); goto -> bb5; } @@ -41,10 +44,7 @@ } bb4: { - StorageLive(_5); - _5 = const "C"; - _1 = &(*_5); - StorageDead(_5); + _1 = const "A(T)"; goto -> bb5; } diff --git a/tests/mir-opt/unreachable_enum_branching.rs b/tests/mir-opt/unreachable_enum_branching.rs index 6005dc546dc8b..fac14042b1075 100644 --- a/tests/mir-opt/unreachable_enum_branching.rs +++ b/tests/mir-opt/unreachable_enum_branching.rs @@ -120,7 +120,7 @@ fn otherwise_t3() { fn otherwise_t4_unreachable_default() { // CHECK-LABEL: fn otherwise_t4_unreachable_default( // CHECK: [[discr:_.*]] = discriminant( - // CHECK: switchInt(move [[discr]]) -> [0: bb2, 1: bb3, 2: bb4, 3: bb1, otherwise: [[unreachable:bb.*]]]; + // CHECK: switchInt(move [[discr]]) -> [0: {{bb.*}}, 1: {{bb.*}}, 2: {{bb.*}}, 3: {{bb.*}}, otherwise: [[unreachable:bb.*]]]; // CHECK: [[unreachable]]: { // CHECK-NEXT: unreachable; match Test4::C { @@ -135,7 +135,7 @@ fn otherwise_t4_unreachable_default() { fn otherwise_t4_unreachable_default_2() { // CHECK-LABEL: fn otherwise_t4_unreachable_default_2( // CHECK: [[discr:_.*]] = discriminant( - // CHECK: switchInt(move [[discr]]) -> [0: bb2, 1: bb5, 2: bb6, 3: bb1, otherwise: [[unreachable:bb.*]]]; + // CHECK: switchInt(move [[discr]]) -> [0: {{bb.*}}, 1: {{bb.*}}, 2: {{bb.*}}, 3: {{bb.*}}, otherwise: [[unreachable:bb.*]]]; // CHECK: [[unreachable]]: { // CHECK-NEXT: unreachable; match Test4::C { @@ -151,7 +151,7 @@ fn otherwise_t4_unreachable_default_2() { fn otherwise_t4() { // CHECK-LABEL: fn otherwise_t4( // CHECK: [[discr:_.*]] = discriminant( - // CHECK: switchInt(move [[discr]]) -> [0: bb2, 1: bb3, otherwise: [[unreachable:bb.*]]]; + // CHECK: switchInt(move [[discr]]) -> [0: {{bb.*}}, 1: {{bb.*}}, otherwise: [[unreachable:bb.*]]]; // CHECK: [[unreachable]]: { // CHECK-NOT: unreachable; // CHECK: } @@ -166,7 +166,7 @@ fn otherwise_t4() { fn otherwise_t5_unreachable_default() { // CHECK-LABEL: fn otherwise_t5_unreachable_default( // CHECK: [[discr:_.*]] = discriminant( - // CHECK: switchInt(move [[discr]]) -> [255: bb2, 0: bb3, 5: bb4, 3: bb1, otherwise: [[unreachable:bb.*]]]; + // CHECK: switchInt(move [[discr]]) -> [255: {{bb.*}}, 0: {{bb.*}}, 5: {{bb.*}}, 3: {{bb.*}}, otherwise: [[unreachable:bb.*]]]; // CHECK: [[unreachable]]: { // CHECK-NEXT: unreachable; match Test5::::C { @@ -183,7 +183,7 @@ fn byref() { let plop = Plop { xx: 51, test3: Test3::C }; // CHECK: [[ref_discr:_.*]] = discriminant((* - // CHECK: switchInt(move [[ref_discr]]) -> [0: [[unreachable:bb.*]], 1: [[unreachable]], 2: bb5, 3: bb2, otherwise: [[unreachable]]]; + // CHECK: switchInt(move [[ref_discr]]) -> [0: [[unreachable:bb.*]], 1: [[unreachable]], 2: {{bb.*}}, 3: {{bb.*}}, otherwise: [[unreachable]]]; match &plop.test3 { Test3::A(_) => "A(Empty)", Test3::B(_) => "B(Empty)", @@ -195,7 +195,7 @@ fn byref() { // CHECK-NEXT: unreachable; // CHECK: [[discr:_.*]] = discriminant( - // CHECK: switchInt(move [[discr]]) -> [0: [[unreachable]], 1: [[unreachable]], 2: bb10, 3: bb7, otherwise: [[unreachable]]]; + // CHECK: switchInt(move [[discr]]) -> [0: [[unreachable]], 1: [[unreachable]], 2: {{bb.*}}, 3: {{bb.*}}, otherwise: [[unreachable]]]; match plop.test3 { Test3::A(_) => "A(Empty)", Test3::B(_) => "B(Empty)", diff --git a/tests/mir-opt/unreachable_enum_branching.simple.UnreachableEnumBranching.panic-abort.diff b/tests/mir-opt/unreachable_enum_branching.simple.UnreachableEnumBranching.panic-abort.diff index a85fc0da99232..8aef991493672 100644 --- a/tests/mir-opt/unreachable_enum_branching.simple.UnreachableEnumBranching.panic-abort.diff +++ b/tests/mir-opt/unreachable_enum_branching.simple.UnreachableEnumBranching.panic-abort.diff @@ -14,7 +14,7 @@ StorageLive(_2); _2 = Test1::C; _3 = discriminant(_2); -- switchInt(move _3) -> [0: bb3, 1: bb4, 2: bb2, otherwise: bb1]; +- switchInt(move _3) -> [0: bb4, 1: bb3, 2: bb2, otherwise: bb1]; + switchInt(move _3) -> [0: bb1, 1: bb1, 2: bb2, otherwise: bb1]; } @@ -31,11 +31,6 @@ } bb3: { - _1 = const "A(Empty)"; - goto -> bb5; - } - - bb4: { StorageLive(_4); _4 = const "B(Empty)"; _1 = &(*_4); @@ -43,6 +38,11 @@ goto -> bb5; } + bb4: { + _1 = const "A(Empty)"; + goto -> bb5; + } + bb5: { StorageDead(_2); StorageDead(_1); diff --git a/tests/mir-opt/unreachable_enum_branching.simple.UnreachableEnumBranching.panic-unwind.diff b/tests/mir-opt/unreachable_enum_branching.simple.UnreachableEnumBranching.panic-unwind.diff index a85fc0da99232..8aef991493672 100644 --- a/tests/mir-opt/unreachable_enum_branching.simple.UnreachableEnumBranching.panic-unwind.diff +++ b/tests/mir-opt/unreachable_enum_branching.simple.UnreachableEnumBranching.panic-unwind.diff @@ -14,7 +14,7 @@ StorageLive(_2); _2 = Test1::C; _3 = discriminant(_2); -- switchInt(move _3) -> [0: bb3, 1: bb4, 2: bb2, otherwise: bb1]; +- switchInt(move _3) -> [0: bb4, 1: bb3, 2: bb2, otherwise: bb1]; + switchInt(move _3) -> [0: bb1, 1: bb1, 2: bb2, otherwise: bb1]; } @@ -31,11 +31,6 @@ } bb3: { - _1 = const "A(Empty)"; - goto -> bb5; - } - - bb4: { StorageLive(_4); _4 = const "B(Empty)"; _1 = &(*_4); @@ -43,6 +38,11 @@ goto -> bb5; } + bb4: { + _1 = const "A(Empty)"; + goto -> bb5; + } + bb5: { StorageDead(_2); StorageDead(_1); diff --git a/tests/ui/associated-types/associated-types-outlives.stderr b/tests/ui/associated-types/associated-types-outlives.stderr index 1164869bf1982..bd6022fcec655 100644 --- a/tests/ui/associated-types/associated-types-outlives.stderr +++ b/tests/ui/associated-types/associated-types-outlives.stderr @@ -18,7 +18,7 @@ LL | pub fn free_and_use Foo<'a>, | ^ consider constraining this type parameter with `Clone` ... LL | 's: loop { y = denormalise(&x); break } - | -- you could clone this value + | - you could clone this value error: aborting due to 1 previous error diff --git a/tests/ui/augmented-assignments.rs b/tests/ui/augmented-assignments.rs index 8b263e03593b8..440a4a7fd6500 100644 --- a/tests/ui/augmented-assignments.rs +++ b/tests/ui/augmented-assignments.rs @@ -17,7 +17,6 @@ fn main() { x; //~^ ERROR cannot move out of `x` because it is borrowed //~| move out of `x` occurs here - //~| HELP consider cloning let y = Int(2); //~^ HELP consider changing this to be mutable diff --git a/tests/ui/augmented-assignments.stderr b/tests/ui/augmented-assignments.stderr index 6b2900dd5d1bc..a4b75cbf6e8fc 100644 --- a/tests/ui/augmented-assignments.stderr +++ b/tests/ui/augmented-assignments.stderr @@ -8,14 +8,9 @@ LL | x ... LL | x; | ^ move out of `x` occurs here - | -help: consider cloning the value if the performance cost is acceptable - | -LL | x.clone(); - | ++++++++ error[E0596]: cannot borrow `y` as mutable, as it is not declared as mutable - --> $DIR/augmented-assignments.rs:25:5 + --> $DIR/augmented-assignments.rs:24:5 | LL | y | ^ cannot borrow as mutable diff --git a/tests/ui/binop/binop-move-semantics.stderr b/tests/ui/binop/binop-move-semantics.stderr index 83c27590e9014..45c7f11040616 100644 --- a/tests/ui/binop/binop-move-semantics.stderr +++ b/tests/ui/binop/binop-move-semantics.stderr @@ -65,7 +65,7 @@ help: if `T` implemented `Clone`, you could clone the value LL | fn move_borrowed>(x: T, mut y: T) { | ^ consider constraining this type parameter with `Clone` LL | let m = &x; - | -- you could clone this value + | - you could clone this value error[E0505]: cannot move out of `y` because it is borrowed --> $DIR/binop-move-semantics.rs:23:5 @@ -88,7 +88,7 @@ LL | fn move_borrowed>(x: T, mut y: T) { | ^ consider constraining this type parameter with `Clone` LL | let m = &x; LL | let n = &mut y; - | ------ you could clone this value + | - you could clone this value error[E0507]: cannot move out of `*m` which is behind a mutable reference --> $DIR/binop-move-semantics.rs:30:5 diff --git a/tests/ui/borrowck/borrow-tuple-fields.stderr b/tests/ui/borrowck/borrow-tuple-fields.stderr index 8ea7a9a498947..277c335cfccaa 100644 --- a/tests/ui/borrowck/borrow-tuple-fields.stderr +++ b/tests/ui/borrowck/borrow-tuple-fields.stderr @@ -13,9 +13,8 @@ LL | r.use_ref(); | help: consider cloning the value if the performance cost is acceptable | -LL - let r = &x.0; -LL + let r = x.0.clone(); - | +LL | let r = &x.0.clone(); + | ++++++++ error[E0502]: cannot borrow `x.0` as mutable because it is also borrowed as immutable --> $DIR/borrow-tuple-fields.rs:18:13 @@ -51,9 +50,8 @@ LL | r.use_ref(); | help: consider cloning the value if the performance cost is acceptable | -LL - let r = &x.0; -LL + let r = x.0.clone(); - | +LL | let r = &x.0.clone(); + | ++++++++ error[E0502]: cannot borrow `x.0` as mutable because it is also borrowed as immutable --> $DIR/borrow-tuple-fields.rs:33:13 diff --git a/tests/ui/borrowck/borrowck-bad-nested-calls-move.stderr b/tests/ui/borrowck/borrowck-bad-nested-calls-move.stderr index b96949fbb0e78..5e7eee0422ee2 100644 --- a/tests/ui/borrowck/borrowck-bad-nested-calls-move.stderr +++ b/tests/ui/borrowck/borrowck-bad-nested-calls-move.stderr @@ -14,7 +14,7 @@ LL | a); help: consider cloning the value if the performance cost is acceptable | LL - &*a, -LL + a.clone(), +LL + &a.clone(), | error[E0505]: cannot move out of `a` because it is borrowed @@ -32,7 +32,7 @@ LL | a); help: consider cloning the value if the performance cost is acceptable | LL - &*a, -LL + a.clone(), +LL + &a.clone(), | error: aborting due to 2 previous errors diff --git a/tests/ui/borrowck/borrowck-field-sensitivity.stderr b/tests/ui/borrowck/borrowck-field-sensitivity.stderr index ea552ff7820e2..b30dd144a4d80 100644 --- a/tests/ui/borrowck/borrowck-field-sensitivity.stderr +++ b/tests/ui/borrowck/borrowck-field-sensitivity.stderr @@ -52,9 +52,8 @@ LL | drop(**p); | help: consider cloning the value if the performance cost is acceptable | -LL - let p = &x.b; -LL + let p = x.b.clone(); - | +LL | let p = &x.b.clone(); + | ++++++++ error[E0505]: cannot move out of `x.b` because it is borrowed --> $DIR/borrowck-field-sensitivity.rs:41:14 @@ -70,9 +69,8 @@ LL | drop(**p); | help: consider cloning the value if the performance cost is acceptable | -LL - let p = &x.b; -LL + let p = x.b.clone(); - | +LL | let p = &x.b.clone(); + | ++++++++ error[E0499]: cannot borrow `x.a` as mutable more than once at a time --> $DIR/borrowck-field-sensitivity.rs:48:13 diff --git a/tests/ui/borrowck/borrowck-issue-48962.stderr b/tests/ui/borrowck/borrowck-issue-48962.stderr index 6e821a4c6b0b1..ee174f6736e1e 100644 --- a/tests/ui/borrowck/borrowck-issue-48962.stderr +++ b/tests/ui/borrowck/borrowck-issue-48962.stderr @@ -17,11 +17,6 @@ LL | {src}; | --- value moved here LL | src.0 = 66; | ^^^^^^^^^^ value used here after move - | -help: consider cloning the value if the performance cost is acceptable - | -LL | {src.clone()}; - | ++++++++ error: aborting due to 2 previous errors diff --git a/tests/ui/borrowck/borrowck-loan-blocks-move-cc.stderr b/tests/ui/borrowck/borrowck-loan-blocks-move-cc.stderr index 370ae058f444d..d9af5cf7d12e8 100644 --- a/tests/ui/borrowck/borrowck-loan-blocks-move-cc.stderr +++ b/tests/ui/borrowck/borrowck-loan-blocks-move-cc.stderr @@ -16,9 +16,8 @@ LL | w.use_ref(); | help: consider cloning the value if the performance cost is acceptable | -LL - let w = &v; -LL + let w = v.clone(); - | +LL | let w = &v.clone(); + | ++++++++ error[E0505]: cannot move out of `v` because it is borrowed --> $DIR/borrowck-loan-blocks-move-cc.rs:24:19 @@ -38,9 +37,8 @@ LL | w.use_ref(); | help: consider cloning the value if the performance cost is acceptable | -LL - let w = &v; -LL + let w = v.clone(); - | +LL | let w = &v.clone(); + | ++++++++ error: aborting due to 2 previous errors diff --git a/tests/ui/borrowck/borrowck-loan-blocks-move.stderr b/tests/ui/borrowck/borrowck-loan-blocks-move.stderr index 8a8005dbb8337..1698035f20ffb 100644 --- a/tests/ui/borrowck/borrowck-loan-blocks-move.stderr +++ b/tests/ui/borrowck/borrowck-loan-blocks-move.stderr @@ -12,9 +12,8 @@ LL | w.use_ref(); | help: consider cloning the value if the performance cost is acceptable | -LL - let w = &v; -LL + let w = v.clone(); - | +LL | let w = &v.clone(); + | ++++++++ error: aborting due to 1 previous error diff --git a/tests/ui/borrowck/borrowck-move-from-subpath-of-borrowed-path.stderr b/tests/ui/borrowck/borrowck-move-from-subpath-of-borrowed-path.stderr index a23a203d99978..b78c374c45620 100644 --- a/tests/ui/borrowck/borrowck-move-from-subpath-of-borrowed-path.stderr +++ b/tests/ui/borrowck/borrowck-move-from-subpath-of-borrowed-path.stderr @@ -13,9 +13,8 @@ LL | b.use_ref(); | help: consider cloning the value if the performance cost is acceptable | -LL - let b = &a; -LL + let b = a.clone(); - | +LL | let b = &a.clone(); + | ++++++++ error: aborting due to 1 previous error diff --git a/tests/ui/borrowck/borrowck-move-mut-base-ptr.stderr b/tests/ui/borrowck/borrowck-move-mut-base-ptr.stderr index acf426906c3b2..4b9351b64a038 100644 --- a/tests/ui/borrowck/borrowck-move-mut-base-ptr.stderr +++ b/tests/ui/borrowck/borrowck-move-mut-base-ptr.stderr @@ -14,7 +14,7 @@ LL | p.use_ref(); help: consider cloning the value if the performance cost is acceptable | LL - let p: &isize = &*t0; // Freezes `*t0` -LL + let p: &isize = t0.clone(); // Freezes `*t0` +LL + let p: &isize = &t0.clone(); // Freezes `*t0` | error: aborting due to 1 previous error diff --git a/tests/ui/borrowck/borrowck-move-subcomponent.stderr b/tests/ui/borrowck/borrowck-move-subcomponent.stderr index cc6c3bdeb1022..b5dc01f180b2f 100644 --- a/tests/ui/borrowck/borrowck-move-subcomponent.stderr +++ b/tests/ui/borrowck/borrowck-move-subcomponent.stderr @@ -17,7 +17,7 @@ LL | struct S { | ^^^^^^^^ consider implementing `Clone` for this type ... LL | let pb = &a; - | -- you could clone this value + | - you could clone this value error: aborting due to 1 previous error diff --git a/tests/ui/borrowck/borrowck-multiple-captures.stderr b/tests/ui/borrowck/borrowck-multiple-captures.stderr index fdac4c27cee3b..01b648ea64717 100644 --- a/tests/ui/borrowck/borrowck-multiple-captures.stderr +++ b/tests/ui/borrowck/borrowck-multiple-captures.stderr @@ -17,9 +17,8 @@ LL | borrow(&*p1); | help: consider cloning the value if the performance cost is acceptable | -LL - let p1 = &x1; -LL + let p1 = x1.clone(); - | +LL | let p1 = &x1.clone(); + | ++++++++ error[E0505]: cannot move out of `x2` because it is borrowed --> $DIR/borrowck-multiple-captures.rs:12:19 @@ -39,9 +38,8 @@ LL | borrow(&*p2); | help: consider cloning the value if the performance cost is acceptable | -LL - let p2 = &x2; -LL + let p2 = x2.clone(); - | +LL | let p2 = &x2.clone(); + | ++++++++ error[E0382]: use of moved value: `x1` --> $DIR/borrowck-multiple-captures.rs:27:19 @@ -108,9 +106,8 @@ LL | borrow(&*p); | help: consider cloning the value if the performance cost is acceptable | -LL - let p = &x; -LL + let p = x.clone(); - | +LL | let p = &x.clone(); + | ++++++++ error[E0382]: use of moved value: `x` --> $DIR/borrowck-multiple-captures.rs:52:14 diff --git a/tests/ui/borrowck/borrowck-overloaded-index-move-index.stderr b/tests/ui/borrowck/borrowck-overloaded-index-move-index.stderr index 7f8cc74a7157a..3366853b8e268 100644 --- a/tests/ui/borrowck/borrowck-overloaded-index-move-index.stderr +++ b/tests/ui/borrowck/borrowck-overloaded-index-move-index.stderr @@ -11,6 +11,11 @@ LL | println!("{}", f[s]); ... LL | use_mut(rs); | -- borrow later used here + | +help: consider cloning the value if the performance cost is acceptable + | +LL | let rs = &mut s.clone(); + | ++++++++ error[E0505]: cannot move out of `s` because it is borrowed --> $DIR/borrowck-overloaded-index-move-index.rs:53:7 @@ -25,6 +30,11 @@ LL | f[s] = 10; ... LL | use_mut(rs); | -- borrow later used here + | +help: consider cloning the value if the performance cost is acceptable + | +LL | let rs = &mut s.clone(); + | ++++++++ error[E0382]: use of moved value: `s` --> $DIR/borrowck-overloaded-index-move-index.rs:53:7 diff --git a/tests/ui/borrowck/borrowck-unary-move.stderr b/tests/ui/borrowck/borrowck-unary-move.stderr index 598ecb537780f..0aec6d426309f 100644 --- a/tests/ui/borrowck/borrowck-unary-move.stderr +++ b/tests/ui/borrowck/borrowck-unary-move.stderr @@ -13,7 +13,7 @@ LL | *y help: consider cloning the value if the performance cost is acceptable | LL - let y = &*x; -LL + let y = x.clone(); +LL + let y = &x.clone(); | error: aborting due to 1 previous error diff --git a/tests/ui/borrowck/clone-on-ref.stderr b/tests/ui/borrowck/clone-on-ref.stderr index 19f040556f8ae..d5d21296a3f96 100644 --- a/tests/ui/borrowck/clone-on-ref.stderr +++ b/tests/ui/borrowck/clone-on-ref.stderr @@ -38,7 +38,7 @@ help: if `T` implemented `Clone`, you could clone the value LL | fn bar(x: T) { | ^ consider constraining this type parameter with `Clone` LL | let a = &x; - | -- you could clone this value + | - you could clone this value help: consider further restricting this bound | LL | fn bar(x: T) { @@ -66,7 +66,7 @@ LL | struct A; | ^^^^^^^^ consider implementing `Clone` for this type LL | fn qux(x: A) { LL | let a = &x; - | -- you could clone this value + | - you could clone this value help: consider annotating `A` with `#[derive(Clone)]` | LL + #[derive(Clone)] diff --git a/tests/ui/borrowck/issue-101119.stderr b/tests/ui/borrowck/issue-101119.stderr index a894fa63ace28..7fec81b59b3a8 100644 --- a/tests/ui/borrowck/issue-101119.stderr +++ b/tests/ui/borrowck/issue-101119.stderr @@ -18,14 +18,6 @@ LL | fn fill_segment(_: &mut State) {} | ------------ ^^^^^^^^^^ this parameter takes ownership of the value | | | in this function -note: if `State` implemented `Clone`, you could clone the value - --> $DIR/issue-101119.rs:1:1 - | -LL | struct State; - | ^^^^^^^^^^^^ consider implementing `Clone` for this type -... -LL | fill_segment(state); - | ----- you could clone this value error: aborting due to 1 previous error diff --git a/tests/ui/btreemap/btreemap_dropck.stderr b/tests/ui/btreemap/btreemap_dropck.stderr index 873f8cf9a0147..e8f14552af26d 100644 --- a/tests/ui/btreemap/btreemap_dropck.stderr +++ b/tests/ui/btreemap/btreemap_dropck.stderr @@ -12,9 +12,8 @@ LL | } | help: consider cloning the value if the performance cost is acceptable | -LL - let _map = BTreeMap::from_iter([((), PrintOnDrop(&s))]); -LL + let _map = BTreeMap::from_iter([((), PrintOnDrop(s.clone()))]); - | +LL | let _map = BTreeMap::from_iter([((), PrintOnDrop(&s.clone()))]); + | ++++++++ error: aborting due to 1 previous error diff --git a/tests/ui/dropck/drop-with-active-borrows-1.stderr b/tests/ui/dropck/drop-with-active-borrows-1.stderr index 7d1633267f0e2..229514c6feef0 100644 --- a/tests/ui/dropck/drop-with-active-borrows-1.stderr +++ b/tests/ui/dropck/drop-with-active-borrows-1.stderr @@ -9,11 +9,6 @@ LL | drop(a); | ^ move out of `a` occurs here LL | for s in &b { | -- borrow later used here - | -help: consider cloning the value if the performance cost is acceptable - | -LL | let b: Vec<&str> = a.clone().lines().collect(); - | ++++++++ error: aborting due to 1 previous error diff --git a/tests/ui/dropck/dropck-empty-array.rs b/tests/ui/dropck/dropck-empty-array.rs new file mode 100644 index 0000000000000..f3eca6aed8d5e --- /dev/null +++ b/tests/ui/dropck/dropck-empty-array.rs @@ -0,0 +1,23 @@ +//@ run-pass + +#[allow(dead_code)] +struct Struct<'s>(&'s str); + +impl<'s> Drop for Struct<'s> { + fn drop(&mut self) {} +} + +fn to_array_zero(_: T) -> [T; 0] { + [] +} + +pub fn array_zero_in_tuple() { + let mut x = ([], String::new()); + { + let s = String::from("temporary"); + let p = Struct(&s); + x.0 = to_array_zero(p); + } +} + +fn main() {} diff --git a/tests/ui/error-codes/E0504.stderr b/tests/ui/error-codes/E0504.stderr index 343bca9a72e24..582669593336a 100644 --- a/tests/ui/error-codes/E0504.stderr +++ b/tests/ui/error-codes/E0504.stderr @@ -21,7 +21,7 @@ LL | struct FancyNum { | ^^^^^^^^^^^^^^^ consider implementing `Clone` for this type ... LL | let fancy_ref = &fancy_num; - | ---------- you could clone this value + | --------- you could clone this value error: aborting due to 1 previous error diff --git a/tests/ui/error-codes/E0505.stderr b/tests/ui/error-codes/E0505.stderr index 266df9ea32a71..3f2913e9fe3c6 100644 --- a/tests/ui/error-codes/E0505.stderr +++ b/tests/ui/error-codes/E0505.stderr @@ -18,7 +18,7 @@ LL | struct Value {} | ^^^^^^^^^^^^ consider implementing `Clone` for this type ... LL | let _ref_to_val: &Value = &x; - | -- you could clone this value + | - you could clone this value error: aborting due to 1 previous error diff --git a/tests/ui/fn/implied-bounds-unnorm-associated-type-4.stderr b/tests/ui/fn/implied-bounds-unnorm-associated-type-4.stderr index b8ec2e3b7e7b9..4e64ed6f482e0 100644 --- a/tests/ui/fn/implied-bounds-unnorm-associated-type-4.stderr +++ b/tests/ui/fn/implied-bounds-unnorm-associated-type-4.stderr @@ -13,9 +13,8 @@ LL | println!("{}", y); | help: consider cloning the value if the performance cost is acceptable | -LL - let y = f(&x, ()); -LL + let y = f(x.clone(), ()); - | +LL | let y = f(&x.clone(), ()); + | ++++++++ error: aborting due to 1 previous error diff --git a/tests/ui/fn/implied-bounds-unnorm-associated-type-5.stderr b/tests/ui/fn/implied-bounds-unnorm-associated-type-5.stderr index 382ab8636a294..b898df0835c2a 100644 --- a/tests/ui/fn/implied-bounds-unnorm-associated-type-5.stderr +++ b/tests/ui/fn/implied-bounds-unnorm-associated-type-5.stderr @@ -30,9 +30,8 @@ LL | println!("{}", y); | help: consider cloning the value if the performance cost is acceptable | -LL - let y = f(&x, ()); -LL + let y = f(x.clone(), ()); - | +LL | let y = f(&x.clone(), ()); + | ++++++++ error: aborting due to 2 previous errors diff --git a/tests/ui/fn/implied-bounds-unnorm-associated-type.stderr b/tests/ui/fn/implied-bounds-unnorm-associated-type.stderr index ce97d8527e857..2a7431305fed4 100644 --- a/tests/ui/fn/implied-bounds-unnorm-associated-type.stderr +++ b/tests/ui/fn/implied-bounds-unnorm-associated-type.stderr @@ -13,9 +13,8 @@ LL | println!("{}", y); | help: consider cloning the value if the performance cost is acceptable | -LL - let y = f(&x, ()); -LL + let y = f(x.clone(), ()); - | +LL | let y = f(&x.clone(), ()); + | ++++++++ error: aborting due to 1 previous error diff --git a/tests/ui/imports/redundant-import-extern-prelude.rs b/tests/ui/imports/redundant-import-extern-prelude.rs index f1de06417aa5d..0064eaa931882 100644 --- a/tests/ui/imports/redundant-import-extern-prelude.rs +++ b/tests/ui/imports/redundant-import-extern-prelude.rs @@ -1,16 +1,17 @@ -//@ check-pass // Check that we detect imports that are redundant due to the extern prelude // and that we emit a reasonable diagnostic. // issue: rust-lang/rust#121915 +//~^^^ NOTE the item `aux_issue_121915` is already defined by the extern prelude // See also the discussion in . //@ compile-flags: --extern aux_issue_121915 --edition 2018 //@ aux-build: aux-issue-121915.rs -#[deny(unused_imports)] +#[deny(redundant_imports)] +//~^ NOTE the lint level is defined here fn main() { use aux_issue_121915; - //FIXME(unused_imports): ~^ ERROR the item `aux_issue_121915` is imported redundantly + //~^ ERROR the item `aux_issue_121915` is imported redundantly aux_issue_121915::item(); } diff --git a/tests/ui/imports/redundant-import-extern-prelude.stderr b/tests/ui/imports/redundant-import-extern-prelude.stderr new file mode 100644 index 0000000000000..6d2518c1284b6 --- /dev/null +++ b/tests/ui/imports/redundant-import-extern-prelude.stderr @@ -0,0 +1,14 @@ +error: the item `aux_issue_121915` is imported redundantly + --> $DIR/redundant-import-extern-prelude.rs:14:9 + | +LL | use aux_issue_121915; + | ^^^^^^^^^^^^^^^^ the item `aux_issue_121915` is already defined by the extern prelude + | +note: the lint level is defined here + --> $DIR/redundant-import-extern-prelude.rs:11:8 + | +LL | #[deny(redundant_imports)] + | ^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/imports/redundant-import-issue-121915-2015.rs b/tests/ui/imports/redundant-import-issue-121915-2015.rs index be3b8209ada99..dc499bc40b616 100644 --- a/tests/ui/imports/redundant-import-issue-121915-2015.rs +++ b/tests/ui/imports/redundant-import-issue-121915-2015.rs @@ -1,12 +1,11 @@ -//@ check-pass //@ compile-flags: --extern aux_issue_121915 --edition 2015 //@ aux-build: aux-issue-121915.rs extern crate aux_issue_121915; -#[deny(unused_imports)] +#[deny(redundant_imports)] fn main() { use aux_issue_121915; - //FIXME(unused_imports): ~^ ERROR the item `aux_issue_121915` is imported redundantly + //~^ ERROR the item `aux_issue_121915` is imported redundantly aux_issue_121915::item(); } diff --git a/tests/ui/imports/redundant-import-issue-121915-2015.stderr b/tests/ui/imports/redundant-import-issue-121915-2015.stderr new file mode 100644 index 0000000000000..f4e9f604896ab --- /dev/null +++ b/tests/ui/imports/redundant-import-issue-121915-2015.stderr @@ -0,0 +1,17 @@ +error: the item `aux_issue_121915` is imported redundantly + --> $DIR/redundant-import-issue-121915-2015.rs:8:9 + | +LL | extern crate aux_issue_121915; + | ------------------------------ the item `aux_issue_121915` is already imported here +... +LL | use aux_issue_121915; + | ^^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/redundant-import-issue-121915-2015.rs:6:8 + | +LL | #[deny(redundant_imports)] + | ^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/imports/redundant-import-lang-prelude-attr.rs b/tests/ui/imports/redundant-import-lang-prelude-attr.rs index 59cd570f44c25..f7ee91880bad5 100644 --- a/tests/ui/imports/redundant-import-lang-prelude-attr.rs +++ b/tests/ui/imports/redundant-import-lang-prelude-attr.rs @@ -1,6 +1,6 @@ -//@ check-pass // Check that we detect imports (of built-in attributes) that are redundant due to // the language prelude and that we emit a reasonable diagnostic. +//~^^ NOTE the item `allow` is already defined by the extern prelude // Note that we use the term "extern prelude" in the label even though "language prelude" // would be more correct. However, it's not worth special-casing this. @@ -9,9 +9,10 @@ //@ edition: 2018 -#![deny(unused_imports)] +#![deny(redundant_imports)] +//~^ NOTE the lint level is defined here -use allow; //FIXME(unused_imports): ~ ERROR the item `allow` is imported redundantly +use allow; //~ ERROR the item `allow` is imported redundantly #[allow(unused)] fn main() {} diff --git a/tests/ui/imports/redundant-import-lang-prelude-attr.stderr b/tests/ui/imports/redundant-import-lang-prelude-attr.stderr new file mode 100644 index 0000000000000..f0016f5fab41f --- /dev/null +++ b/tests/ui/imports/redundant-import-lang-prelude-attr.stderr @@ -0,0 +1,14 @@ +error: the item `allow` is imported redundantly + --> $DIR/redundant-import-lang-prelude-attr.rs:15:5 + | +LL | use allow; + | ^^^^^ the item `allow` is already defined by the extern prelude + | +note: the lint level is defined here + --> $DIR/redundant-import-lang-prelude-attr.rs:12:9 + | +LL | #![deny(redundant_imports)] + | ^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/imports/redundant-import-lang-prelude.rs b/tests/ui/imports/redundant-import-lang-prelude.rs index 53d3b70996342..3f95ffbe02e7e 100644 --- a/tests/ui/imports/redundant-import-lang-prelude.rs +++ b/tests/ui/imports/redundant-import-lang-prelude.rs @@ -1,16 +1,17 @@ -//@ check-pass // Check that we detect imports that are redundant due to the language prelude // and that we emit a reasonable diagnostic. +//~^^ NOTE the item `u8` is already defined by the extern prelude // Note that we use the term "extern prelude" in the label even though "language prelude" // would be more correct. However, it's not worth special-casing this. // See also the discussion in . -#![deny(unused_imports)] +#![deny(redundant_imports)] +//~^ NOTE the lint level is defined here use std::primitive::u8; -//FIXME(unused_imports): ~^ ERROR the item `u8` is imported redundantly +//~^ ERROR the item `u8` is imported redundantly const _: u8 = 0; diff --git a/tests/ui/imports/redundant-import-lang-prelude.stderr b/tests/ui/imports/redundant-import-lang-prelude.stderr new file mode 100644 index 0000000000000..4fd576397812e --- /dev/null +++ b/tests/ui/imports/redundant-import-lang-prelude.stderr @@ -0,0 +1,14 @@ +error: the item `u8` is imported redundantly + --> $DIR/redundant-import-lang-prelude.rs:13:5 + | +LL | use std::primitive::u8; + | ^^^^^^^^^^^^^^^^^^ the item `u8` is already defined by the extern prelude + | +note: the lint level is defined here + --> $DIR/redundant-import-lang-prelude.rs:10:9 + | +LL | #![deny(redundant_imports)] + | ^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/imports/suggest-remove-issue-121315.rs b/tests/ui/imports/suggest-remove-issue-121315.rs index 2bb82833a5bc3..ee3ceb6e3a380 100644 --- a/tests/ui/imports/suggest-remove-issue-121315.rs +++ b/tests/ui/imports/suggest-remove-issue-121315.rs @@ -1,20 +1,19 @@ //@ compile-flags: --edition 2021 - -#![deny(unused_imports)] +#![deny(unused_imports, redundant_imports)] #![allow(dead_code)] fn test0() { // Test remove FlatUnused use std::convert::TryFrom; - //FIXME(unused_imports): ~^ ERROR the item `TryFrom` is imported redundantly + //~^ ERROR the item `TryFrom` is imported redundantly let _ = u32::try_from(5i32); } fn test1() { // FIXME(yukang) Test remove NestedFullUnused use std::convert::{TryFrom, TryInto}; - //FIXME(unused_imports): ~^ ERROR the item `TryFrom` is imported redundantly - //FIXME(unused_imports): ~| ERROR the item `TryInto` is imported redundantly + //~^ ERROR the item `TryFrom` is imported redundantly + //~| ERROR the item `TryInto` is imported redundantly let _ = u32::try_from(5i32); let _a: i32 = u32::try_into(5u32).unwrap(); @@ -24,7 +23,7 @@ fn test2() { // FIXME(yukang): Test remove both redundant and unused use std::convert::{AsMut, Into}; //~^ ERROR unused import: `AsMut` - //FIXME(unused_imports): ~| ERROR the item `Into` is imported redundantly + //~| ERROR the item `Into` is imported redundantly let _a: u32 = (5u8).into(); } diff --git a/tests/ui/imports/suggest-remove-issue-121315.stderr b/tests/ui/imports/suggest-remove-issue-121315.stderr index 5701514e1bd6e..5d0bf9bea6a94 100644 --- a/tests/ui/imports/suggest-remove-issue-121315.stderr +++ b/tests/ui/imports/suggest-remove-issue-121315.stderr @@ -1,20 +1,62 @@ +error: the item `TryFrom` is imported redundantly + --> $DIR/suggest-remove-issue-121315.rs:7:9 + | +LL | use std::convert::TryFrom; + | ^^^^^^^^^^^^^^^^^^^^^ + --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL + | + = note: the item `TryFrom` is already defined here + | +note: the lint level is defined here + --> $DIR/suggest-remove-issue-121315.rs:2:25 + | +LL | #![deny(unused_imports, redundant_imports)] + | ^^^^^^^^^^^^^^^^^ + +error: the item `TryFrom` is imported redundantly + --> $DIR/suggest-remove-issue-121315.rs:14:24 + | +LL | use std::convert::{TryFrom, TryInto}; + | ^^^^^^^ + --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL + | + = note: the item `TryFrom` is already defined here + +error: the item `TryInto` is imported redundantly + --> $DIR/suggest-remove-issue-121315.rs:14:33 + | +LL | use std::convert::{TryFrom, TryInto}; + | ^^^^^^^ + --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL + | + = note: the item `TryInto` is already defined here + error: unused import: `AsMut` - --> $DIR/suggest-remove-issue-121315.rs:25:24 + --> $DIR/suggest-remove-issue-121315.rs:24:24 | LL | use std::convert::{AsMut, Into}; | ^^^^^ | note: the lint level is defined here - --> $DIR/suggest-remove-issue-121315.rs:3:9 + --> $DIR/suggest-remove-issue-121315.rs:2:9 | -LL | #![deny(unused_imports)] +LL | #![deny(unused_imports, redundant_imports)] | ^^^^^^^^^^^^^^ +error: the item `Into` is imported redundantly + --> $DIR/suggest-remove-issue-121315.rs:24:31 + | +LL | use std::convert::{AsMut, Into}; + | ^^^^ + --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL + | + = note: the item `Into` is already defined here + error: unused import: `From` - --> $DIR/suggest-remove-issue-121315.rs:34:24 + --> $DIR/suggest-remove-issue-121315.rs:33:24 | LL | use std::convert::{From, Infallible}; | ^^^^ -error: aborting due to 2 previous errors +error: aborting due to 6 previous errors diff --git a/tests/ui/lint/unused/issue-59896.rs b/tests/ui/lint/unused/issue-59896.rs index a98017524f550..5624e7f02fb43 100644 --- a/tests/ui/lint/unused/issue-59896.rs +++ b/tests/ui/lint/unused/issue-59896.rs @@ -1,10 +1,9 @@ -//@ check-pass -#![deny(unused_imports)] +#![deny(redundant_imports)] struct S; fn main() { - use S; //FIXME(unused_imports): ~ ERROR the item `S` is imported redundantly + use S; //~ ERROR the item `S` is imported redundantly let _s = S; } diff --git a/tests/ui/lint/unused/issue-59896.stderr b/tests/ui/lint/unused/issue-59896.stderr new file mode 100644 index 0000000000000..363a6419d9c85 --- /dev/null +++ b/tests/ui/lint/unused/issue-59896.stderr @@ -0,0 +1,17 @@ +error: the item `S` is imported redundantly + --> $DIR/issue-59896.rs:6:9 + | +LL | struct S; + | --------- the item `S` is already defined here +... +LL | use S; + | ^ + | +note: the lint level is defined here + --> $DIR/issue-59896.rs:1:9 + | +LL | #![deny(redundant_imports)] + | ^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/lint/use-redundant/use-redundant-glob-parent.rs b/tests/ui/lint/use-redundant/use-redundant-glob-parent.rs index 797e57f48e9d2..c8c413dccd3f2 100644 --- a/tests/ui/lint/use-redundant/use-redundant-glob-parent.rs +++ b/tests/ui/lint/use-redundant/use-redundant-glob-parent.rs @@ -1,5 +1,5 @@ //@ check-pass -#![warn(unused_imports)] +#![warn(redundant_imports)] pub mod bar { pub struct Foo(pub Bar); @@ -9,7 +9,7 @@ pub mod bar { use bar::*; pub fn warning() -> Foo { - use bar::Foo; //FIXME(unused_imports): ~ WARNING imported redundantly + use bar::Foo; //~ WARNING imported redundantly Foo(Bar('a')) } diff --git a/tests/ui/lint/use-redundant/use-redundant-glob-parent.stderr b/tests/ui/lint/use-redundant/use-redundant-glob-parent.stderr new file mode 100644 index 0000000000000..3b06b2df67454 --- /dev/null +++ b/tests/ui/lint/use-redundant/use-redundant-glob-parent.stderr @@ -0,0 +1,17 @@ +warning: the item `Foo` is imported redundantly + --> $DIR/use-redundant-glob-parent.rs:12:9 + | +LL | use bar::*; + | ------ the item `Foo` is already imported here +... +LL | use bar::Foo; + | ^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/use-redundant-glob-parent.rs:2:9 + | +LL | #![warn(redundant_imports)] + | ^^^^^^^^^^^^^^^^^ + +warning: 1 warning emitted + diff --git a/tests/ui/lint/use-redundant/use-redundant-glob.rs b/tests/ui/lint/use-redundant/use-redundant-glob.rs index e5835be89d841..52383d4ceffc3 100644 --- a/tests/ui/lint/use-redundant/use-redundant-glob.rs +++ b/tests/ui/lint/use-redundant/use-redundant-glob.rs @@ -1,5 +1,5 @@ //@ check-pass -#![warn(unused_imports)] +#![warn(redundant_imports)] pub mod bar { pub struct Foo(pub Bar); @@ -8,7 +8,7 @@ pub mod bar { pub fn warning() -> bar::Foo { use bar::*; - use bar::Foo; //FIXME(unused_imports): ~ WARNING imported redundantly + use bar::Foo; //~ WARNING imported redundantly Foo(Bar('a')) } diff --git a/tests/ui/lint/use-redundant/use-redundant-glob.stderr b/tests/ui/lint/use-redundant/use-redundant-glob.stderr new file mode 100644 index 0000000000000..47b2ce54bb733 --- /dev/null +++ b/tests/ui/lint/use-redundant/use-redundant-glob.stderr @@ -0,0 +1,16 @@ +warning: the item `Foo` is imported redundantly + --> $DIR/use-redundant-glob.rs:11:9 + | +LL | use bar::*; + | ------ the item `Foo` is already imported here +LL | use bar::Foo; + | ^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/use-redundant-glob.rs:2:9 + | +LL | #![warn(redundant_imports)] + | ^^^^^^^^^^^^^^^^^ + +warning: 1 warning emitted + diff --git a/tests/ui/lint/use-redundant/use-redundant-issue-71450.rs b/tests/ui/lint/use-redundant/use-redundant-issue-71450.rs index 2db3435d46dbd..6a3ffa4522ae2 100644 --- a/tests/ui/lint/use-redundant/use-redundant-issue-71450.rs +++ b/tests/ui/lint/use-redundant/use-redundant-issue-71450.rs @@ -1,6 +1,6 @@ //@ check-pass -#![warn(unused_imports)] +#![warn(redundant_imports)] mod foo { use std::fmt; @@ -23,8 +23,7 @@ mod foo { fn main() { { - use std::string::String; - //FIXME(unused_imports): ~^ WARNING the item `String` is imported redundantly + use std::string::String; //~ WARNING the item `String` is imported redundantly // 'String' from 'std::string::String'. let s = String::new(); println!("{}", s); diff --git a/tests/ui/lint/use-redundant/use-redundant-issue-71450.stderr b/tests/ui/lint/use-redundant/use-redundant-issue-71450.stderr new file mode 100644 index 0000000000000..c14ab9e11e0fc --- /dev/null +++ b/tests/ui/lint/use-redundant/use-redundant-issue-71450.stderr @@ -0,0 +1,17 @@ +warning: the item `String` is imported redundantly + --> $DIR/use-redundant-issue-71450.rs:26:13 + | +LL | use std::string::String; + | ^^^^^^^^^^^^^^^^^^^ + --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL + | + = note: the item `String` is already defined here + | +note: the lint level is defined here + --> $DIR/use-redundant-issue-71450.rs:3:9 + | +LL | #![warn(redundant_imports)] + | ^^^^^^^^^^^^^^^^^ + +warning: 1 warning emitted + diff --git a/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2015.rs b/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2015.rs index 62f50c8a0df90..6abe3602abee7 100644 --- a/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2015.rs +++ b/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2015.rs @@ -1,16 +1,12 @@ //@ check-pass -#![warn(unused_imports)] +#![warn(redundant_imports)] -use std::option::Option::Some; -//FIXME(unused_imports): ~^ WARNING the item `Some` is imported redundantly -use std::option::Option::None; -//FIXME(unused_imports): ~ WARNING the item `None` is imported redundantly +use std::option::Option::Some;//~ WARNING the item `Some` is imported redundantly +use std::option::Option::None; //~ WARNING the item `None` is imported redundantly -use std::result::Result::Ok; -//FIXME(unused_imports): ~^ WARNING the item `Ok` is imported redundantly -use std::result::Result::Err; -//FIXME(unused_imports): ~^ WARNING the item `Err` is imported redundantly +use std::result::Result::Ok;//~ WARNING the item `Ok` is imported redundantly +use std::result::Result::Err;//~ WARNING the item `Err` is imported redundantly use std::convert::{TryFrom, TryInto}; fn main() { diff --git a/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2015.stderr b/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2015.stderr new file mode 100644 index 0000000000000..2b0e16a87dc06 --- /dev/null +++ b/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2015.stderr @@ -0,0 +1,44 @@ +warning: the item `Some` is imported redundantly + --> $DIR/use-redundant-prelude-rust-2015.rs:5:5 + | +LL | use std::option::Option::Some; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL + | + = note: the item `Some` is already defined here + | +note: the lint level is defined here + --> $DIR/use-redundant-prelude-rust-2015.rs:2:9 + | +LL | #![warn(redundant_imports)] + | ^^^^^^^^^^^^^^^^^ + +warning: the item `None` is imported redundantly + --> $DIR/use-redundant-prelude-rust-2015.rs:6:5 + | +LL | use std::option::Option::None; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL + | + = note: the item `None` is already defined here + +warning: the item `Ok` is imported redundantly + --> $DIR/use-redundant-prelude-rust-2015.rs:8:5 + | +LL | use std::result::Result::Ok; + | ^^^^^^^^^^^^^^^^^^^^^^^ + --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL + | + = note: the item `Ok` is already defined here + +warning: the item `Err` is imported redundantly + --> $DIR/use-redundant-prelude-rust-2015.rs:9:5 + | +LL | use std::result::Result::Err; + | ^^^^^^^^^^^^^^^^^^^^^^^^ + --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL + | + = note: the item `Err` is already defined here + +warning: 4 warnings emitted + diff --git a/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2021.rs b/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2021.rs index 1baa1ac1b8cd3..236ee032b677b 100644 --- a/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2021.rs +++ b/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2021.rs @@ -1,11 +1,9 @@ //@ check-pass //@ edition:2021 -#![warn(unused_imports)] +#![warn(redundant_imports)] -use std::convert::TryFrom; -//FIXME(unused_imports): ~^ WARNING the item `TryFrom` is imported redundantly -use std::convert::TryInto; -//FIXME(unused_imports): ~^ WARNING the item `TryInto` is imported redundantly +use std::convert::TryFrom;//~ WARNING the item `TryFrom` is imported redundantly +use std::convert::TryInto;//~ WARNING the item `TryInto` is imported redundantly fn main() { let _e: Result = 8u8.try_into(); diff --git a/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2021.stderr b/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2021.stderr new file mode 100644 index 0000000000000..526771c597aa7 --- /dev/null +++ b/tests/ui/lint/use-redundant/use-redundant-prelude-rust-2021.stderr @@ -0,0 +1,26 @@ +warning: the item `TryFrom` is imported redundantly + --> $DIR/use-redundant-prelude-rust-2021.rs:5:5 + | +LL | use std::convert::TryFrom; + | ^^^^^^^^^^^^^^^^^^^^^ + --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL + | + = note: the item `TryFrom` is already defined here + | +note: the lint level is defined here + --> $DIR/use-redundant-prelude-rust-2021.rs:3:9 + | +LL | #![warn(redundant_imports)] + | ^^^^^^^^^^^^^^^^^ + +warning: the item `TryInto` is imported redundantly + --> $DIR/use-redundant-prelude-rust-2021.rs:6:5 + | +LL | use std::convert::TryInto; + | ^^^^^^^^^^^^^^^^^^^^^ + --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL + | + = note: the item `TryInto` is already defined here + +warning: 2 warnings emitted + diff --git a/tests/ui/lint/use-redundant/use-redundant.rs b/tests/ui/lint/use-redundant/use-redundant.rs index 9e4902af34b7d..0efed378f988b 100644 --- a/tests/ui/lint/use-redundant/use-redundant.rs +++ b/tests/ui/lint/use-redundant/use-redundant.rs @@ -1,5 +1,5 @@ //@ check-pass -#![warn(unused_imports)] +#![warn(unused_imports, redundant_imports)] use crate::foo::Bar; @@ -18,7 +18,7 @@ use m1::*; //~ WARNING unused import use m2::*; //~ WARNING unused import fn main() { - use crate::foo::Bar; //FIXME(unused_imports): ~ WARNING imported redundantly + use crate::foo::Bar; //~ WARNING imported redundantly let _a: Bar = 3; baz(); diff --git a/tests/ui/lint/use-redundant/use-redundant.stderr b/tests/ui/lint/use-redundant/use-redundant.stderr index 224e841123748..76846a1dca98d 100644 --- a/tests/ui/lint/use-redundant/use-redundant.stderr +++ b/tests/ui/lint/use-redundant/use-redundant.stderr @@ -7,7 +7,7 @@ LL | use m1::*; note: the lint level is defined here --> $DIR/use-redundant.rs:2:9 | -LL | #![warn(unused_imports)] +LL | #![warn(unused_imports, redundant_imports)] | ^^^^^^^^^^^^^^ warning: unused import: `m2::*` @@ -16,5 +16,20 @@ warning: unused import: `m2::*` LL | use m2::*; | ^^^^^ -warning: 2 warnings emitted +warning: the item `Bar` is imported redundantly + --> $DIR/use-redundant.rs:21:9 + | +LL | use crate::foo::Bar; + | --------------- the item `Bar` is already imported here +... +LL | use crate::foo::Bar; + | ^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/use-redundant.rs:2:25 + | +LL | #![warn(unused_imports, redundant_imports)] + | ^^^^^^^^^^^^^^^^^ + +warning: 3 warnings emitted diff --git a/tests/ui/macros/expr_2024_underscore_expr.edi2021.stderr b/tests/ui/macros/expr_2024_underscore_expr.edi2021.stderr new file mode 100644 index 0000000000000..335b3f613434b --- /dev/null +++ b/tests/ui/macros/expr_2024_underscore_expr.edi2021.stderr @@ -0,0 +1,32 @@ +error: no rules expected the token `_` + --> $DIR/expr_2024_underscore_expr.rs:22:12 + | +LL | macro_rules! m2021 { + | ------------------ when calling this macro +... +LL | m2021!(_); + | ^ no rules expected this token in macro call + | +note: while trying to match meta-variable `$e:expr_2021` + --> $DIR/expr_2024_underscore_expr.rs:10:6 + | +LL | ($e:expr_2021) => { + | ^^^^^^^^^^^^ + +error: no rules expected the token `_` + --> $DIR/expr_2024_underscore_expr.rs:23:12 + | +LL | macro_rules! m2024 { + | ------------------ when calling this macro +... +LL | m2024!(_); + | ^ no rules expected this token in macro call + | +note: while trying to match meta-variable `$e:expr` + --> $DIR/expr_2024_underscore_expr.rs:16:6 + | +LL | ($e:expr) => { + | ^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/tests/ui/macros/expr_2024_underscore_expr.edi2024.stderr b/tests/ui/macros/expr_2024_underscore_expr.edi2024.stderr new file mode 100644 index 0000000000000..9e49f66a89ae8 --- /dev/null +++ b/tests/ui/macros/expr_2024_underscore_expr.edi2024.stderr @@ -0,0 +1,17 @@ +error: no rules expected the token `_` + --> $DIR/expr_2024_underscore_expr.rs:22:12 + | +LL | macro_rules! m2021 { + | ------------------ when calling this macro +... +LL | m2021!(_); + | ^ no rules expected this token in macro call + | +note: while trying to match meta-variable `$e:expr_2021` + --> $DIR/expr_2024_underscore_expr.rs:10:6 + | +LL | ($e:expr_2021) => { + | ^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/macros/expr_2024_underscore_expr.rs b/tests/ui/macros/expr_2024_underscore_expr.rs new file mode 100644 index 0000000000000..b2129bf154f7e --- /dev/null +++ b/tests/ui/macros/expr_2024_underscore_expr.rs @@ -0,0 +1,24 @@ +//@ revisions: edi2021 edi2024 +//@[edi2024]compile-flags: --edition=2024 -Z unstable-options +//@[edi2021]compile-flags: --edition=2021 +// This test ensures that the `_` tok is considered an +// expression on edition 2024. +#![feature(expr_fragment_specifier_2024)] +#![allow(incomplete_features)] + +macro_rules! m2021 { + ($e:expr_2021) => { + $e = 1; + }; +} + +macro_rules! m2024 { + ($e:expr) => { + $e = 1; + }; +} + +fn main() { + m2021!(_); //~ ERROR: no rules expected the token `_` + m2024!(_); //[edi2021]~ ERROR: no rules expected the token `_` +} diff --git a/tests/ui/moves/move-fn-self-receiver.stderr b/tests/ui/moves/move-fn-self-receiver.stderr index f2c6008d27eac..de19a99d388ca 100644 --- a/tests/ui/moves/move-fn-self-receiver.stderr +++ b/tests/ui/moves/move-fn-self-receiver.stderr @@ -101,15 +101,6 @@ LL | mut_foo; | ^^^^^^^ move out of `mut_foo` occurs here LL | ret; | --- borrow later used here - | -note: if `Foo` implemented `Clone`, you could clone the value - --> $DIR/move-fn-self-receiver.rs:5:1 - | -LL | struct Foo; - | ^^^^^^^^^^ consider implementing `Clone` for this type -... -LL | let ret = mut_foo.use_mut_self(); - | ------- you could clone this value error[E0382]: use of moved value: `rc_foo` --> $DIR/move-fn-self-receiver.rs:55:5 diff --git a/tests/ui/nll/closure-access-spans.stderr b/tests/ui/nll/closure-access-spans.stderr index f789e5e9f9571..a8024a8c20b9e 100644 --- a/tests/ui/nll/closure-access-spans.stderr +++ b/tests/ui/nll/closure-access-spans.stderr @@ -60,9 +60,8 @@ LL | r.use_ref(); | help: consider cloning the value if the performance cost is acceptable | -LL - let r = &x; -LL + let r = x.clone(); - | +LL | let r = &x.clone(); + | ++++++++ error[E0382]: borrow of moved value: `x` --> $DIR/closure-access-spans.rs:35:5 @@ -109,11 +108,6 @@ LL | || *x = String::new(); | ^^ -- borrow occurs due to use in closure | | | value borrowed here after move - | -help: consider cloning the value if the performance cost is acceptable - | -LL | let r = x.clone(); - | ++++++++ error[E0382]: use of moved value: `x` --> $DIR/closure-access-spans.rs:50:5 @@ -126,11 +120,6 @@ LL | || x; | ^^ - use occurs due to use in closure | | | value used here after move - | -help: consider cloning the value if the performance cost is acceptable - | -LL | let r = x.clone(); - | ++++++++ error: aborting due to 9 previous errors diff --git a/tests/ui/nll/issue-27282-move-match-input-into-guard.stderr b/tests/ui/nll/issue-27282-move-match-input-into-guard.stderr index 39ec45b20eae6..ae7978004576b 100644 --- a/tests/ui/nll/issue-27282-move-match-input-into-guard.stderr +++ b/tests/ui/nll/issue-27282-move-match-input-into-guard.stderr @@ -10,11 +10,6 @@ LL | _ if { (|| { let bar = b; *bar = false; })(); | -- - variable moved due to use in closure | | | value moved into closure here - | -help: consider cloning the value if the performance cost is acceptable - | -LL | _ if { (|| { let bar = b.clone(); *bar = false; })(); - | ++++++++ error[E0382]: use of moved value: `b` --> $DIR/issue-27282-move-match-input-into-guard.rs:24:5 @@ -28,11 +23,6 @@ LL | (|| { let bar = b; *bar = false; })(); | -- - variable moved due to use in closure | | | value moved into closure here - | -help: consider cloning the value if the performance cost is acceptable - | -LL | (|| { let bar = b.clone(); *bar = false; })(); - | ++++++++ error: aborting due to 2 previous errors diff --git a/tests/ui/nll/issue-27282-move-ref-mut-into-guard.fixed b/tests/ui/nll/issue-27282-move-ref-mut-into-guard.fixed deleted file mode 100644 index 7692be7ccc801..0000000000000 --- a/tests/ui/nll/issue-27282-move-ref-mut-into-guard.fixed +++ /dev/null @@ -1,23 +0,0 @@ -// Issue 27282: Example 1: This sidesteps the AST checks disallowing -// mutable borrows in match guards by hiding the mutable borrow in a -// guard behind a move (of the ref mut pattern id) within a closure. -//@ run-rustfix -#![feature(if_let_guard)] - -fn main() { - match Some(&4) { - None => {}, - ref mut foo - if { (|| { let mut bar = foo.clone(); bar.take() })(); false } => {}, - //~^ ERROR cannot move out of `foo` in pattern guard [E0507] - Some(s) => std::process::exit(*s), - } - - match Some(&4) { - None => {}, - ref mut foo - if let Some(()) = { (|| { let mut bar = foo.clone(); bar.take() })(); None } => {}, - //~^ ERROR cannot move out of `foo` in pattern guard [E0507] - Some(s) => std::process::exit(*s), - } -} diff --git a/tests/ui/nll/issue-27282-move-ref-mut-into-guard.rs b/tests/ui/nll/issue-27282-move-ref-mut-into-guard.rs index f3d0a184e03c5..c3b19886a5078 100644 --- a/tests/ui/nll/issue-27282-move-ref-mut-into-guard.rs +++ b/tests/ui/nll/issue-27282-move-ref-mut-into-guard.rs @@ -1,7 +1,7 @@ // Issue 27282: Example 1: This sidesteps the AST checks disallowing // mutable borrows in match guards by hiding the mutable borrow in a // guard behind a move (of the ref mut pattern id) within a closure. -//@ run-rustfix + #![feature(if_let_guard)] fn main() { diff --git a/tests/ui/nll/issue-27282-move-ref-mut-into-guard.stderr b/tests/ui/nll/issue-27282-move-ref-mut-into-guard.stderr index 7781e77894b89..e790fda4d7ca7 100644 --- a/tests/ui/nll/issue-27282-move-ref-mut-into-guard.stderr +++ b/tests/ui/nll/issue-27282-move-ref-mut-into-guard.stderr @@ -7,10 +7,6 @@ LL | if { (|| { let mut bar = foo; bar.take() })(); false } => {}, | `foo` is moved here | = note: variables bound in patterns cannot be moved from until after the end of the pattern guard -help: consider cloning the value if the performance cost is acceptable - | -LL | if { (|| { let mut bar = foo.clone(); bar.take() })(); false } => {}, - | ++++++++ error[E0507]: cannot move out of `foo` in pattern guard --> $DIR/issue-27282-move-ref-mut-into-guard.rs:19:34 @@ -21,10 +17,6 @@ LL | if let Some(()) = { (|| { let mut bar = foo; bar.take() })(); N | `foo` is moved here | = note: variables bound in patterns cannot be moved from until after the end of the pattern guard -help: consider cloning the value if the performance cost is acceptable - | -LL | if let Some(()) = { (|| { let mut bar = foo.clone(); bar.take() })(); None } => {}, - | ++++++++ error: aborting due to 2 previous errors diff --git a/tests/ui/nll/issue-27282-mutation-in-guard.stderr b/tests/ui/nll/issue-27282-mutation-in-guard.stderr index f73e4aaa489aa..0b5d723172c76 100644 --- a/tests/ui/nll/issue-27282-mutation-in-guard.stderr +++ b/tests/ui/nll/issue-27282-mutation-in-guard.stderr @@ -7,10 +7,6 @@ LL | (|| { let bar = foo; bar.take() })(); | `foo` is moved here | = note: variables bound in patterns cannot be moved from until after the end of the pattern guard -help: consider cloning the value if the performance cost is acceptable - | -LL | (|| { let bar = foo.clone(); bar.take() })(); - | ++++++++ error[E0507]: cannot move out of `foo` in pattern guard --> $DIR/issue-27282-mutation-in-guard.rs:20:18 @@ -21,10 +17,6 @@ LL | (|| { let bar = foo; bar.take() })(); | `foo` is moved here | = note: variables bound in patterns cannot be moved from until after the end of the pattern guard -help: consider cloning the value if the performance cost is acceptable - | -LL | (|| { let bar = foo.clone(); bar.take() })(); - | ++++++++ error: aborting due to 2 previous errors diff --git a/tests/ui/nll/issue-52059-report-when-borrow-and-drop-conflict.stderr b/tests/ui/nll/issue-52059-report-when-borrow-and-drop-conflict.stderr index f4e7869bf0056..7f9cbc3c30a92 100644 --- a/tests/ui/nll/issue-52059-report-when-borrow-and-drop-conflict.stderr +++ b/tests/ui/nll/issue-52059-report-when-borrow-and-drop-conflict.stderr @@ -41,10 +41,6 @@ help: consider borrowing here | LL | let p = &s.url; p | + -help: consider cloning the value if the performance cost is acceptable - | -LL | let p = s.url.clone(); p - | ++++++++ error: aborting due to 4 previous errors diff --git a/tests/ui/nll/match-guards-always-borrow.fixed b/tests/ui/nll/match-guards-always-borrow.fixed deleted file mode 100644 index 56e743bf196a6..0000000000000 --- a/tests/ui/nll/match-guards-always-borrow.fixed +++ /dev/null @@ -1,66 +0,0 @@ -#![feature(if_let_guard)] -#![allow(unused_mut)] -//@ run-rustfix - -// Here is arielb1's basic example from rust-lang/rust#27282 -// that AST borrowck is flummoxed by: - -fn should_reject_destructive_mutate_in_guard() { - match Some(&4) { - None => {}, - ref mut foo if { - (|| { let mut bar = foo.clone(); bar.take() })(); - //~^ ERROR cannot move out of `foo` in pattern guard [E0507] - false } => { }, - Some(s) => std::process::exit(*s), - } - - match Some(&4) { - None => {}, - ref mut foo if let Some(()) = { - (|| { let mut bar = foo.clone(); bar.take() })(); - //~^ ERROR cannot move out of `foo` in pattern guard [E0507] - None } => { }, - Some(s) => std::process::exit(*s), - } -} - -// Here below is a case that needs to keep working: we only use the -// binding via immutable-borrow in the guard, and we mutate in the arm -// body. -fn allow_mutate_in_arm_body() { - match Some(&4) { - None => {}, - ref mut foo if foo.is_some() => { foo.take(); () } - Some(s) => std::process::exit(*s), - } - - match Some(&4) { - None => {}, - ref mut foo if let Some(_) = foo => { foo.take(); () } - Some(s) => std::process::exit(*s), - } -} - -// Here below is a case that needs to keep working: we only use the -// binding via immutable-borrow in the guard, and we move into the arm -// body. -fn allow_move_into_arm_body() { - match Some(&4) { - None => {}, - mut foo if foo.is_some() => { foo.unwrap(); () } - Some(s) => std::process::exit(*s), - } - - match Some(&4) { - None => {}, - mut foo if let Some(_) = foo => { foo.unwrap(); () } - Some(s) => std::process::exit(*s), - } -} - -fn main() { - should_reject_destructive_mutate_in_guard(); - allow_mutate_in_arm_body(); - allow_move_into_arm_body(); -} diff --git a/tests/ui/nll/match-guards-always-borrow.rs b/tests/ui/nll/match-guards-always-borrow.rs index 927d55c42a6e3..5271e3cfc6655 100644 --- a/tests/ui/nll/match-guards-always-borrow.rs +++ b/tests/ui/nll/match-guards-always-borrow.rs @@ -1,6 +1,5 @@ #![feature(if_let_guard)] #![allow(unused_mut)] -//@ run-rustfix // Here is arielb1's basic example from rust-lang/rust#27282 // that AST borrowck is flummoxed by: diff --git a/tests/ui/nll/match-guards-always-borrow.stderr b/tests/ui/nll/match-guards-always-borrow.stderr index bb0c5bd4c9761..71977bd84721b 100644 --- a/tests/ui/nll/match-guards-always-borrow.stderr +++ b/tests/ui/nll/match-guards-always-borrow.stderr @@ -1,5 +1,5 @@ error[E0507]: cannot move out of `foo` in pattern guard - --> $DIR/match-guards-always-borrow.rs:12:14 + --> $DIR/match-guards-always-borrow.rs:11:14 | LL | (|| { let mut bar = foo; bar.take() })(); | ^^ --- move occurs because `foo` has type `&mut Option<&i32>`, which does not implement the `Copy` trait @@ -7,13 +7,9 @@ LL | (|| { let mut bar = foo; bar.take() })(); | `foo` is moved here | = note: variables bound in patterns cannot be moved from until after the end of the pattern guard -help: consider cloning the value if the performance cost is acceptable - | -LL | (|| { let mut bar = foo.clone(); bar.take() })(); - | ++++++++ error[E0507]: cannot move out of `foo` in pattern guard - --> $DIR/match-guards-always-borrow.rs:21:14 + --> $DIR/match-guards-always-borrow.rs:20:14 | LL | (|| { let mut bar = foo; bar.take() })(); | ^^ --- move occurs because `foo` has type `&mut Option<&i32>`, which does not implement the `Copy` trait @@ -21,10 +17,6 @@ LL | (|| { let mut bar = foo; bar.take() })(); | `foo` is moved here | = note: variables bound in patterns cannot be moved from until after the end of the pattern guard -help: consider cloning the value if the performance cost is acceptable - | -LL | (|| { let mut bar = foo.clone(); bar.take() })(); - | ++++++++ error: aborting due to 2 previous errors diff --git a/tests/ui/nll/polonius/polonius-smoke-test.stderr b/tests/ui/nll/polonius/polonius-smoke-test.stderr index 534813b2d9f5a..a8a8267290def 100644 --- a/tests/ui/nll/polonius/polonius-smoke-test.stderr +++ b/tests/ui/nll/polonius/polonius-smoke-test.stderr @@ -27,6 +27,12 @@ LL | let z = x; | ^ move out of `x` occurs here LL | y | - returning this value requires that `*x` is borrowed for `'1` + | +help: consider cloning the value if the performance cost is acceptable + | +LL - let y = &mut *x; +LL + let y = &mut x.clone(); + | error[E0505]: cannot move out of `s` because it is borrowed --> $DIR/polonius-smoke-test.rs:42:5 @@ -40,6 +46,12 @@ LL | s; | ^ move out of `s` occurs here LL | tmp; | --- borrow later used here + | +help: consider cloning the value if the performance cost is acceptable + | +LL - let r = &mut *s; +LL + let r = &mut s.clone(); + | error: aborting due to 4 previous errors diff --git a/tests/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-and-ref.stderr b/tests/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-and-ref.stderr index e925fe78f3393..9359244c6ebc1 100644 --- a/tests/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-and-ref.stderr +++ b/tests/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-and-ref.stderr @@ -333,14 +333,6 @@ LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { drop(b); false | ^ move occurs because `b` has type `&mut U`, which does not implement the `Copy` trait | = note: variables bound in patterns cannot be moved from until after the end of the pattern guard -note: if `U` implemented `Clone`, you could clone the value - --> $DIR/borrowck-pat-ref-mut-and-ref.rs:17:5 - | -LL | struct U; - | ^^^^^^^^ consider implementing `Clone` for this type -... -LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { drop(b); false } => {} - | - you could clone this value error[E0507]: cannot move out of `b` in pattern guard --> $DIR/borrowck-pat-ref-mut-and-ref.rs:103:66 @@ -349,14 +341,6 @@ LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { drop(b); false | ^ move occurs because `b` has type `&mut U`, which does not implement the `Copy` trait | = note: variables bound in patterns cannot be moved from until after the end of the pattern guard -note: if `U` implemented `Clone`, you could clone the value - --> $DIR/borrowck-pat-ref-mut-and-ref.rs:17:5 - | -LL | struct U; - | ^^^^^^^^ consider implementing `Clone` for this type -... -LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { drop(b); false } => {} - | - you could clone this value = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0507]: cannot move out of `a` in pattern guard diff --git a/tests/ui/span/send-is-not-static-std-sync.stderr b/tests/ui/span/send-is-not-static-std-sync.stderr index 50b8ffe0114b0..6bc3ed8d24ff0 100644 --- a/tests/ui/span/send-is-not-static-std-sync.stderr +++ b/tests/ui/span/send-is-not-static-std-sync.stderr @@ -15,7 +15,7 @@ LL | *lock.lock().unwrap() = &z; help: consider cloning the value if the performance cost is acceptable | LL - *lock.lock().unwrap() = &*y; -LL + *lock.lock().unwrap() = y.clone(); +LL + *lock.lock().unwrap() = &y.clone(); | error[E0597]: `z` does not live long enough @@ -48,7 +48,7 @@ LL | *lock.write().unwrap() = &z; help: consider cloning the value if the performance cost is acceptable | LL - *lock.write().unwrap() = &*y; -LL + *lock.write().unwrap() = y.clone(); +LL + *lock.write().unwrap() = &y.clone(); | error[E0597]: `z` does not live long enough @@ -81,7 +81,7 @@ LL | tx.send(&z).unwrap(); help: consider cloning the value if the performance cost is acceptable | LL - tx.send(&*y); -LL + tx.send(y.clone()); +LL + tx.send(&y.clone()); | error[E0597]: `z` does not live long enough diff --git a/tests/ui/stable-mir-print/basic_function.stdout b/tests/ui/stable-mir-print/basic_function.stdout index 3926c1048f54a..76288c2aa49f2 100644 --- a/tests/ui/stable-mir-print/basic_function.stdout +++ b/tests/ui/stable-mir-print/basic_function.stdout @@ -44,14 +44,14 @@ fn demux(_1: u8) -> u8 { let mut _0: u8; debug input => _1; bb0: { - switchInt(_1) -> [0: bb2, 1: bb3, 2: bb4, otherwise: bb1]; + switchInt(_1) -> [0: bb4, 1: bb3, 2: bb2, otherwise: bb1]; } bb1: { _0 = 0_u8; goto -> bb5; } bb2: { - _0 = 10_u8; + _0 = 8_u8; goto -> bb5; } bb3: { @@ -59,7 +59,7 @@ fn demux(_1: u8) -> u8 { goto -> bb5; } bb4: { - _0 = 8_u8; + _0 = 10_u8; goto -> bb5; } bb5: { diff --git a/tests/ui/suggestions/borrow-for-loop-head.stderr b/tests/ui/suggestions/borrow-for-loop-head.stderr index a8de9986c312d..55fcb44168c49 100644 --- a/tests/ui/suggestions/borrow-for-loop-head.stderr +++ b/tests/ui/suggestions/borrow-for-loop-head.stderr @@ -10,9 +10,8 @@ LL | for j in a { | help: consider cloning the value if the performance cost is acceptable | -LL - for i in &a { -LL + for i in a.clone() { - | +LL | for i in &a.clone() { + | ++++++++ error[E0382]: use of moved value: `a` --> $DIR/borrow-for-loop-head.rs:4:18 diff --git a/tests/ui/try-block/try-block-bad-lifetime.stderr b/tests/ui/try-block/try-block-bad-lifetime.stderr index 6f69329535711..28941cb0a9e40 100644 --- a/tests/ui/try-block/try-block-bad-lifetime.stderr +++ b/tests/ui/try-block/try-block-bad-lifetime.stderr @@ -34,11 +34,6 @@ LL | Err(k) ?; ... LL | ::std::mem::drop(k); | ^ value used here after move - | -help: consider cloning the value if the performance cost is acceptable - | -LL | Err(k.clone()) ?; - | ++++++++ error[E0506]: cannot assign to `i` because it is borrowed --> $DIR/try-block-bad-lifetime.rs:32:9 diff --git a/tests/ui/unop/unop-move-semantics.stderr b/tests/ui/unop/unop-move-semantics.stderr index bc9b3ea990384..0ae918d434a0f 100644 --- a/tests/ui/unop/unop-move-semantics.stderr +++ b/tests/ui/unop/unop-move-semantics.stderr @@ -40,7 +40,7 @@ help: if `T` implemented `Clone`, you could clone the value LL | fn move_borrowed>(x: T, mut y: T) { | ^ consider constraining this type parameter with `Clone` LL | let m = &x; - | -- you could clone this value + | - you could clone this value error[E0505]: cannot move out of `y` because it is borrowed --> $DIR/unop-move-semantics.rs:17:6 @@ -63,7 +63,7 @@ LL | fn move_borrowed>(x: T, mut y: T) { | ^ consider constraining this type parameter with `Clone` LL | let m = &x; LL | let n = &mut y; - | ------ you could clone this value + | - you could clone this value error[E0507]: cannot move out of `*m` which is behind a mutable reference --> $DIR/unop-move-semantics.rs:24:6 diff --git a/tests/ui/variance/variance-issue-20533.stderr b/tests/ui/variance/variance-issue-20533.stderr index 0a810b7222e7c..21d8de6ae8815 100644 --- a/tests/ui/variance/variance-issue-20533.stderr +++ b/tests/ui/variance/variance-issue-20533.stderr @@ -17,7 +17,7 @@ LL | struct AffineU32(u32); | ^^^^^^^^^^^^^^^^ consider implementing `Clone` for this type ... LL | let x = foo(&a); - | -- you could clone this value + | - you could clone this value error[E0505]: cannot move out of `a` because it is borrowed --> $DIR/variance-issue-20533.rs:41:14 @@ -38,7 +38,7 @@ LL | struct AffineU32(u32); | ^^^^^^^^^^^^^^^^ consider implementing `Clone` for this type ... LL | let x = bar(&a); - | -- you could clone this value + | - you could clone this value error[E0505]: cannot move out of `a` because it is borrowed --> $DIR/variance-issue-20533.rs:47:14 @@ -59,7 +59,7 @@ LL | struct AffineU32(u32); | ^^^^^^^^^^^^^^^^ consider implementing `Clone` for this type ... LL | let x = baz(&a); - | -- you could clone this value + | - you could clone this value error[E0505]: cannot move out of `a` because it is borrowed --> $DIR/variance-issue-20533.rs:53:14 @@ -80,7 +80,7 @@ LL | struct AffineU32(u32); | ^^^^^^^^^^^^^^^^ consider implementing `Clone` for this type ... LL | let x = bat(&a); - | -- you could clone this value + | - you could clone this value error[E0505]: cannot move out of `a` because it is borrowed --> $DIR/variance-issue-20533.rs:59:14 @@ -96,9 +96,8 @@ LL | drop(x); | help: consider cloning the value if the performance cost is acceptable | -LL - let x = foo(&a); -LL + let x = foo(a.clone()); - | +LL | let x = foo(&a.clone()); + | ++++++++ error: aborting due to 5 previous errors