From b97e5cc747766fe49b6a554c685543102878c052 Mon Sep 17 00:00:00 2001 From: Ding Xiang Fei Date: Sun, 25 Aug 2024 01:55:41 +0800 Subject: [PATCH 1/2] crater run --- compiler/rustc_lint/src/if_let_rescope.rs | 3 +-- .../ui/drop/if-let-rescope-suggestions.fixed | 26 +++++++++++++++++++ tests/ui/drop/if-let-rescope-suggestions.rs | 25 ++++++++++++++++++ .../ui/drop/if-let-rescope-suggestions.stderr | 26 +++++++++++++++++++ 4 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 tests/ui/drop/if-let-rescope-suggestions.fixed create mode 100644 tests/ui/drop/if-let-rescope-suggestions.rs create mode 100644 tests/ui/drop/if-let-rescope-suggestions.stderr diff --git a/compiler/rustc_lint/src/if_let_rescope.rs b/compiler/rustc_lint/src/if_let_rescope.rs index 5b65541bea6e2..ac9e731b2568b 100644 --- a/compiler/rustc_lint/src/if_let_rescope.rs +++ b/compiler/rustc_lint/src/if_let_rescope.rs @@ -24,7 +24,6 @@ declare_lint! { /// ### Example /// /// ```rust,edition2021 - /// #![feature(if_let_rescope)] /// #![warn(if_let_rescope)] /// #![allow(unused_variables)] /// @@ -239,7 +238,7 @@ impl_lint_pass!( impl<'tcx> LateLintPass<'tcx> for IfLetRescope { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) { - if expr.span.edition().at_least_rust_2024() || !cx.tcx.features().if_let_rescope { + if expr.span.edition().at_least_rust_2024() { return; } if let (Level::Allow, _) = cx.tcx.lint_level_at_node(IF_LET_RESCOPE, expr.hir_id) { diff --git a/tests/ui/drop/if-let-rescope-suggestions.fixed b/tests/ui/drop/if-let-rescope-suggestions.fixed new file mode 100644 index 0000000000000..bf22151d4f2e8 --- /dev/null +++ b/tests/ui/drop/if-let-rescope-suggestions.fixed @@ -0,0 +1,26 @@ +//@ edition:2024 +//@ compile-flags: -Z validate-mir -Zunstable-options +//@ run-rustfix + +#![deny(if_let_rescope)] +#![feature(if_let_rescope)] + +struct Droppy; +impl Drop for Droppy { + fn drop(&mut self) { + println!("dropped"); + } +} +impl Droppy { + fn get_ref(&self) -> Option<&u8> { + None + } +} + +fn do_something(_: &T) {} + +fn main() { + let binding = Droppy; + do_something(match binding.get_ref() { Some(value) => { value } _ => { &0 }}); + //~^ ERROR: temporary value dropped while borrowed +} diff --git a/tests/ui/drop/if-let-rescope-suggestions.rs b/tests/ui/drop/if-let-rescope-suggestions.rs new file mode 100644 index 0000000000000..0e32a1b480baa --- /dev/null +++ b/tests/ui/drop/if-let-rescope-suggestions.rs @@ -0,0 +1,25 @@ +//@ edition:2024 +//@ compile-flags: -Z validate-mir -Zunstable-options +//@ run-rustfix + +#![deny(if_let_rescope)] +#![feature(if_let_rescope)] + +struct Droppy; +impl Drop for Droppy { + fn drop(&mut self) { + println!("dropped"); + } +} +impl Droppy { + fn get_ref(&self) -> Option<&u8> { + None + } +} + +fn do_something(_: &T) {} + +fn main() { + do_something(if let Some(value) = Droppy.get_ref() { value } else { &0 }); + //~^ ERROR: temporary value dropped while borrowed +} diff --git a/tests/ui/drop/if-let-rescope-suggestions.stderr b/tests/ui/drop/if-let-rescope-suggestions.stderr new file mode 100644 index 0000000000000..43ae645097fa4 --- /dev/null +++ b/tests/ui/drop/if-let-rescope-suggestions.stderr @@ -0,0 +1,26 @@ +error[E0716]: temporary value dropped while borrowed + --> $DIR/if-let-rescope-suggestions.rs:23:39 + | +LL | do_something(if let Some(value) = Droppy.get_ref() { value } else { &0 }); + | ^^^^^^ - temporary value is freed at the end of this statement + | | + | creates a temporary value which is freed while still in use + | +note: lifetime for temporaries generated in `if let`s have been shorted in Edition 2024 + --> $DIR/if-let-rescope-suggestions.rs:23:65 + | +LL | do_something(if let Some(value) = Droppy.get_ref() { value } else { &0 }); + | ^ +help: consider using a `let` binding to create a longer lived value + | +LL ~ let binding = Droppy; +LL ~ do_something(if let Some(value) = binding.get_ref() { value } else { &0 }); + | +help: consider rewriting the `if` into `match` which preserves the extended lifetime + | +LL | do_something(match Droppy.get_ref() { Some(value) => { value } _ => { &0 }}); + | ~~~~~ ++++++++++++++++ ~~~~ + + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0716`. From 083cf03ad5640ffa638a8299763cc71d8d5d76dc Mon Sep 17 00:00:00 2001 From: Ding Xiang Fei Date: Sun, 25 Aug 2024 01:57:26 +0800 Subject: [PATCH 2/2] crater run --- .gitmodules | 2 +- compiler/rustc_hir_analysis/src/check/region.rs | 4 ++-- compiler/rustc_mir_build/src/thir/cx/expr.rs | 2 +- src/tools/cargo | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitmodules b/.gitmodules index 2082ec9ef455f..4791003975dd3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,7 +4,7 @@ shallow = true [submodule "src/tools/cargo"] path = src/tools/cargo - url = https://github.com/rust-lang/cargo.git + url = https://github.com/dingxiangfei2009/cargo.git shallow = true [submodule "src/doc/reference"] path = src/doc/reference diff --git a/compiler/rustc_hir_analysis/src/check/region.rs b/compiler/rustc_hir_analysis/src/check/region.rs index 33e58a92e3755..8a7689549a06d 100644 --- a/compiler/rustc_hir_analysis/src/check/region.rs +++ b/compiler/rustc_hir_analysis/src/check/region.rs @@ -472,7 +472,7 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h hir::ExprKind::If(cond, then, Some(otherwise)) => { let expr_cx = visitor.cx; - let data = if expr.span.at_least_rust_2024() && visitor.tcx.features().if_let_rescope { + let data = if expr.span.at_least_rust_2024() { ScopeData::IfThenRescope } else { ScopeData::IfThen @@ -487,7 +487,7 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h hir::ExprKind::If(cond, then, None) => { let expr_cx = visitor.cx; - let data = if expr.span.at_least_rust_2024() && visitor.tcx.features().if_let_rescope { + let data = if expr.span.at_least_rust_2024() { ScopeData::IfThenRescope } else { ScopeData::IfThen diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index aa8ccc8b7ddd6..6a5ca33a88330 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -707,7 +707,7 @@ impl<'tcx> Cx<'tcx> { if_then_scope: region::Scope { id: then.hir_id.local_id, data: { - if expr.span.at_least_rust_2024() && tcx.features().if_let_rescope { + if expr.span.at_least_rust_2024() { region::ScopeData::IfThenRescope } else { region::ScopeData::IfThen diff --git a/src/tools/cargo b/src/tools/cargo index c1fa840a85eca..b12607b978dae 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit c1fa840a85eca53818895901a53fae34247448b2 +Subproject commit b12607b978daeff526951424f8e3f02578a91333