1
Fork 0

simplify the suggestion notes

This commit is contained in:
Ding Xiang Fei 2024-09-13 02:43:49 +08:00
parent 89682a5313
commit b4b2b356d9
No known key found for this signature in database
GPG key ID: 3CD748647EEF6359
7 changed files with 205 additions and 385 deletions

View file

@ -337,9 +337,7 @@ lint_identifier_uncommon_codepoints = identifier contains {$codepoints_len ->
lint_if_let_rescope = `if let` assigns a shorter lifetime since Edition 2024 lint_if_let_rescope = `if let` assigns a shorter lifetime since Edition 2024
.label = this value has a significant drop implementation which may observe a major change in drop order and requires your discretion .label = this value has a significant drop implementation which may observe a major change in drop order and requires your discretion
.help = the value is now dropped here in Edition 2024 .help = the value is now dropped here in Edition 2024
.suggestion = a `match` with a single arm can preserve the drop order up to Edition 2021
lint_if_let_rescope_suggestion = a `match` with a single arm can preserve the drop order up to Edition 2021
.suggestion = rewrite this `if let` into `match`
lint_ignored_unless_crate_specified = {$level}({$name}) is ignored unless specified at crate level lint_ignored_unless_crate_specified = {$level}({$name}) is ignored unless specified at crate level

View file

@ -7,7 +7,7 @@ use rustc_errors::{
Applicability, Diag, EmissionGuarantee, SubdiagMessageOp, Subdiagnostic, SuggestionStyle, Applicability, Diag, EmissionGuarantee, SubdiagMessageOp, Subdiagnostic, SuggestionStyle,
}; };
use rustc_hir::{self as hir, HirIdSet}; use rustc_hir::{self as hir, HirIdSet};
use rustc_macros::{LintDiagnostic, Subdiagnostic}; use rustc_macros::LintDiagnostic;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_session::lint::{FutureIncompatibilityReason, Level}; use rustc_session::lint::{FutureIncompatibilityReason, Level};
use rustc_session::{declare_lint, impl_lint_pass}; use rustc_session::{declare_lint, impl_lint_pass};
@ -124,45 +124,38 @@ impl IfLetRescope {
let source_map = tcx.sess.source_map(); let source_map = tcx.sess.source_map();
let expr_end = expr.span.shrink_to_hi(); let expr_end = expr.span.shrink_to_hi();
let mut add_bracket_to_match_head = match_head_needs_bracket(tcx, expr); let mut add_bracket_to_match_head = match_head_needs_bracket(tcx, expr);
let mut significant_droppers = vec![];
let mut lifetime_ends = vec![];
let mut closing_brackets = 0; let mut closing_brackets = 0;
let mut alt_heads = vec![]; let mut alt_heads = vec![];
let mut match_heads = vec![]; let mut match_heads = vec![];
let mut consequent_heads = vec![]; let mut consequent_heads = vec![];
let mut first_if_to_rewrite = None; let mut first_if_to_lint = None;
let mut first_if_to_rewrite = false;
let mut empty_alt = false; let mut empty_alt = false;
while let hir::ExprKind::If(cond, conseq, alt) = expr.kind { while let hir::ExprKind::If(cond, conseq, alt) = expr.kind {
self.skip.insert(expr.hir_id); self.skip.insert(expr.hir_id);
let hir::ExprKind::Let(&hir::LetExpr { // We are interested in `let` fragment of the condition.
// Otherwise, we probe into the `else` fragment.
if let hir::ExprKind::Let(&hir::LetExpr {
span, span,
pat, pat,
init, init,
ty: ty_ascription, ty: ty_ascription,
recovered: Recovered::No, recovered: Recovered::No,
}) = cond.kind }) = cond.kind
else { {
if let Some(alt) = alt {
add_bracket_to_match_head = matches!(alt.kind, hir::ExprKind::If(..));
expr = alt;
continue;
} else {
// finalize and emit span
break;
}
};
let if_let_pat = expr.span.shrink_to_lo().between(init.span); let if_let_pat = expr.span.shrink_to_lo().between(init.span);
// the consequent fragment is always a block // The consequent fragment is always a block.
let before_conseq = conseq.span.shrink_to_lo(); let before_conseq = conseq.span.shrink_to_lo();
let lifetime_end = source_map.end_point(conseq.span); let lifetime_end = source_map.end_point(conseq.span);
if let ControlFlow::Break(significant_dropper) = if let ControlFlow::Break(significant_dropper) =
(FindSignificantDropper { cx }).visit_expr(init) (FindSignificantDropper { cx }).visit_expr(init)
{ {
tcx.emit_node_span_lint( first_if_to_lint = first_if_to_lint.or_else(|| Some((span, expr.hir_id)));
IF_LET_RESCOPE, significant_droppers.push(significant_dropper);
expr.hir_id, lifetime_ends.push(lifetime_end);
span,
IfLetRescopeLint { significant_dropper, lifetime_end },
);
if ty_ascription.is_some() if ty_ascription.is_some()
|| !expr.span.can_be_used_for_suggestions() || !expr.span.can_be_used_for_suggestions()
|| !pat.span.can_be_used_for_suggestions() || !pat.span.can_be_used_for_suggestions()
@ -173,46 +166,58 @@ impl IfLetRescope {
// we will also bail. // we will also bail.
// FIXME(#101728): change this when type ascription syntax is stabilized again // FIXME(#101728): change this when type ascription syntax is stabilized again
} else if let Ok(pat) = source_map.span_to_snippet(pat.span) { } else if let Ok(pat) = source_map.span_to_snippet(pat.span) {
let emit_suggestion = || { let emit_suggestion = |alt_span| {
first_if_to_rewrite = first_if_to_rewrite = true;
first_if_to_rewrite.or_else(|| Some((expr.span, expr.hir_id)));
if add_bracket_to_match_head { if add_bracket_to_match_head {
closing_brackets += 2; closing_brackets += 2;
match_heads.push(SingleArmMatchBegin::WithOpenBracket(if_let_pat)); match_heads.push(SingleArmMatchBegin::WithOpenBracket(if_let_pat));
} else { } else {
// It has to be a block // Sometimes, wrapping `match` into a block is undesirable,
// because the scrutinee temporary lifetime is shortened and
// the proposed fix will not work.
closing_brackets += 1; closing_brackets += 1;
match_heads.push(SingleArmMatchBegin::WithoutOpenBracket(if_let_pat)); match_heads
.push(SingleArmMatchBegin::WithoutOpenBracket(if_let_pat));
} }
consequent_heads.push(ConsequentRewrite { span: before_conseq, pat }); consequent_heads.push(ConsequentRewrite { span: before_conseq, pat });
if let Some(alt_span) = alt_span {
alt_heads.push(AltHead(alt_span));
}
}; };
if let Some(alt) = alt { if let Some(alt) = alt {
let alt_head = conseq.span.between(alt.span); let alt_head = conseq.span.between(alt.span);
if alt_head.can_be_used_for_suggestions() { if alt_head.can_be_used_for_suggestions() {
// lint // We lint only when the `else` span is user code, too.
emit_suggestion(); emit_suggestion(Some(alt_head));
alt_heads.push(AltHead(alt_head));
} }
} else { } else {
emit_suggestion(); // This is the end of the `if .. else ..` cascade.
// We can stop here.
emit_suggestion(None);
empty_alt = true; empty_alt = true;
break; break;
} }
} }
} }
}
// At this point, any `if let` fragment in the cascade is definitely preceeded by `else`,
// so a opening bracket is mandatory before each `match`.
add_bracket_to_match_head = true;
if let Some(alt) = alt { if let Some(alt) = alt {
add_bracket_to_match_head = matches!(alt.kind, hir::ExprKind::If(..));
expr = alt; expr = alt;
} else { } else {
break; break;
} }
} }
if let Some((span, hir_id)) = first_if_to_rewrite { if let Some((span, hir_id)) = first_if_to_lint {
tcx.emit_node_span_lint( tcx.emit_node_span_lint(
IF_LET_RESCOPE, IF_LET_RESCOPE,
hir_id, hir_id,
span, span,
IfLetRescopeRewrite { IfLetRescopeLint {
significant_droppers,
lifetime_ends,
rewrite: first_if_to_rewrite.then_some(IfLetRescopeRewrite {
match_heads, match_heads,
consequent_heads, consequent_heads,
closing_brackets: ClosingBrackets { closing_brackets: ClosingBrackets {
@ -221,6 +226,7 @@ impl IfLetRescope {
empty_alt, empty_alt,
}, },
alt_heads, alt_heads,
}),
}, },
); );
} }
@ -254,32 +260,68 @@ impl<'tcx> LateLintPass<'tcx> for IfLetRescope {
#[diag(lint_if_let_rescope)] #[diag(lint_if_let_rescope)]
struct IfLetRescopeLint { struct IfLetRescopeLint {
#[label] #[label]
significant_dropper: Span, significant_droppers: Vec<Span>,
#[help] #[help]
lifetime_end: Span, lifetime_ends: Vec<Span>,
#[subdiagnostic]
rewrite: Option<IfLetRescopeRewrite>,
} }
#[derive(LintDiagnostic)] // #[derive(Subdiagnostic)]
#[diag(lint_if_let_rescope_suggestion)]
struct IfLetRescopeRewrite { struct IfLetRescopeRewrite {
#[subdiagnostic]
match_heads: Vec<SingleArmMatchBegin>, match_heads: Vec<SingleArmMatchBegin>,
#[subdiagnostic]
consequent_heads: Vec<ConsequentRewrite>, consequent_heads: Vec<ConsequentRewrite>,
#[subdiagnostic]
closing_brackets: ClosingBrackets, closing_brackets: ClosingBrackets,
#[subdiagnostic]
alt_heads: Vec<AltHead>, alt_heads: Vec<AltHead>,
} }
#[derive(Subdiagnostic)] impl Subdiagnostic for IfLetRescopeRewrite {
#[multipart_suggestion(lint_suggestion, applicability = "machine-applicable")] fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
struct AltHead(#[suggestion_part(code = " _ => ")] Span); self,
diag: &mut Diag<'_, G>,
f: &F,
) {
let mut suggestions = vec![];
for match_head in self.match_heads {
match match_head {
SingleArmMatchBegin::WithOpenBracket(span) => {
suggestions.push((span, "{ match ".into()))
}
SingleArmMatchBegin::WithoutOpenBracket(span) => {
suggestions.push((span, "match ".into()))
}
}
}
for ConsequentRewrite { span, pat } in self.consequent_heads {
suggestions.push((span, format!("{{ {pat} => ")));
}
for AltHead(span) in self.alt_heads {
suggestions.push((span, " _ => ".into()));
}
let closing_brackets = self.closing_brackets;
suggestions.push((
closing_brackets.span,
closing_brackets
.empty_alt
.then_some(" _ => {}".chars())
.into_iter()
.flatten()
.chain(repeat('}').take(closing_brackets.count))
.collect(),
));
let msg = f(diag, crate::fluent_generated::lint_suggestion.into());
diag.multipart_suggestion_with_style(
msg,
suggestions,
Applicability::MachineApplicable,
SuggestionStyle::ShowCode,
);
}
}
struct AltHead(Span);
#[derive(Subdiagnostic)]
#[multipart_suggestion(lint_suggestion, applicability = "machine-applicable")]
struct ConsequentRewrite { struct ConsequentRewrite {
#[suggestion_part(code = "{{ {pat} => ")]
span: Span, span: Span,
pat: String, pat: String,
} }
@ -289,36 +331,9 @@ struct ClosingBrackets {
count: usize, count: usize,
empty_alt: bool, empty_alt: bool,
} }
impl Subdiagnostic for ClosingBrackets {
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self,
diag: &mut Diag<'_, G>,
f: &F,
) {
let code: String = self
.empty_alt
.then_some(" _ => {}".chars())
.into_iter()
.flatten()
.chain(repeat('}').take(self.count))
.collect();
let msg = f(diag, crate::fluent_generated::lint_suggestion.into());
diag.multipart_suggestion_with_style(
msg,
vec![(self.span, code)],
Applicability::MachineApplicable,
SuggestionStyle::ShowCode,
);
}
}
#[derive(Subdiagnostic)]
enum SingleArmMatchBegin { enum SingleArmMatchBegin {
#[multipart_suggestion(lint_suggestion, applicability = "machine-applicable")] WithOpenBracket(Span),
WithOpenBracket(#[suggestion_part(code = "{{ match ")] Span), WithoutOpenBracket(Span),
#[multipart_suggestion(lint_suggestion, applicability = "machine-applicable")]
WithoutOpenBracket(#[suggestion_part(code = "match ")] Span),
} }
struct FindSignificantDropper<'tcx, 'a> { struct FindSignificantDropper<'tcx, 'a> {

View file

@ -26,9 +26,9 @@ impl Droppy {
fn main() { fn main() {
if let Some(_value) = Droppy.get() { if let Some(_value) = Droppy.get() {
//[with_feature_gate]~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024 //[with_feature_gate]~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
//[with_feature_gate]~| ERROR: a `match` with a single arm can preserve the drop order up to Edition 2021 //[with_feature_gate]~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
//[with_feature_gate]~| WARN: this changes meaning in Rust 2024
//[with_feature_gate]~| WARN: this changes meaning in Rust 2024 //[with_feature_gate]~| WARN: this changes meaning in Rust 2024
} else { } else {
//[with_feature_gate]~^ HELP: the value is now dropped here in Edition 2024
} }
} }

View file

@ -9,7 +9,7 @@ LL | if let Some(_value) = Droppy.get() {
= warning: this changes meaning in Rust 2024 = warning: this changes meaning in Rust 2024
= note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085> = note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085>
help: the value is now dropped here in Edition 2024 help: the value is now dropped here in Edition 2024
--> $DIR/lint-if-let-rescope-gated.rs:32:5 --> $DIR/lint-if-let-rescope-gated.rs:31:5
| |
LL | } else { LL | } else {
| ^ | ^
@ -18,37 +18,16 @@ note: the lint level is defined here
| |
LL | #![deny(if_let_rescope)] LL | #![deny(if_let_rescope)]
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^
help: a `match` with a single arm can preserve the drop order up to Edition 2021
|
LL ~ match Droppy.get() { Some(_value) => {
LL |
LL |
LL |
LL ~ } _ => {
LL |
LL ~ }}
|
error: a `match` with a single arm can preserve the drop order up to Edition 2021 error: aborting due to 1 previous error
--> $DIR/lint-if-let-rescope-gated.rs:27:5
|
LL | / if let Some(_value) = Droppy.get() {
LL | |
LL | |
LL | |
LL | |
LL | | } else {
LL | | }
| |_____^
|
= warning: this changes meaning in Rust 2024
= note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085>
help: rewrite this `if let` into `match`
|
LL | match Droppy.get() {
| ~~~~~
help: rewrite this `if let` into `match`
|
LL | if let Some(_value) = Droppy.get() { Some(_value) => {
| +++++++++++++++++
help: rewrite this `if let` into `match`
|
LL | }}
| +
help: rewrite this `if let` into `match`
|
LL | } _ => {
| ~~~~
error: aborting due to 2 previous errors

View file

@ -27,73 +27,45 @@ fn main() {
match droppy().get() { Some(_value) => { match droppy().get() { Some(_value) => {
//~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024 //~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
//~| WARN: this changes meaning in Rust 2024 //~| WARN: this changes meaning in Rust 2024
//~| WARN: this changes meaning in Rust 2024 //~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
//~| ERROR a `match` with a single arm can preserve the drop order up to Edition 2021
//~| HELP: rewrite this `if let` into `match`
//~| HELP: rewrite this `if let` into `match`
// do something // do something
} _ => { } _ => {
//~^ HELP: the value is now dropped here in Edition 2024 //~^ HELP: the value is now dropped here in Edition 2024
//~| HELP: rewrite this `if let` into `match`
// do something else // do something else
}} }}
//~^ HELP: rewrite this `if let` into `match`
match droppy().get() { Some(_value) => { match droppy().get() { Some(_value) => {
//~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024 //~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
//~| WARN: this changes meaning in Rust 2024 //~| WARN: this changes meaning in Rust 2024
//~| WARN: this changes meaning in Rust 2024 //~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
//~| ERROR a `match` with a single arm can preserve the drop order up to Edition 2021
//~| HELP: rewrite this `if let` into `match`
//~| HELP: rewrite this `if let` into `match`
// do something // do something
} _ => { match droppy().get() { Some(_value) => { } _ => { match droppy().get() { Some(_value) => {
//~^ HELP: the value is now dropped here in Edition 2024 //~^ HELP: the value is now dropped here in Edition 2024
//~| ERROR: `if let` assigns a shorter lifetime since Edition 2024
//~| WARN: this changes meaning in Rust 2024
//~| HELP: rewrite this `if let` into `match`
//~| HELP: rewrite this `if let` into `match`
//~| HELP: rewrite this `if let` into `match`
// do something else // do something else
} _ => {}}}} } _ => {}}}}
//~^ HELP: rewrite this `if let` into `match` //~^ HELP: the value is now dropped here in Edition 2024
//~| HELP: the value is now dropped here in Edition 2024
if droppy().get().is_some() { if droppy().get().is_some() {
// Should not lint // Should not lint
} else { match droppy().get() { Some(_value) => { } else { match droppy().get() { Some(_value) => {
//~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024 //~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
//~| ERROR a `match` with a single arm can preserve the drop order up to Edition 2021
//~| WARN: this changes meaning in Rust 2024 //~| WARN: this changes meaning in Rust 2024
//~| WARN: this changes meaning in Rust 2024 //~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
//~| HELP: rewrite this `if let` into `match`
//~| HELP: rewrite this `if let` into `match`
} _ => if droppy().get().is_none() { } _ => if droppy().get().is_none() {
//~^ HELP: the value is now dropped here in Edition 2024 //~^ HELP: the value is now dropped here in Edition 2024
//~| HELP: rewrite this `if let` into `match`
}}} }}}
//~^ HELP: rewrite this `if let` into `match`
if let Some(1) = { match Droppy.get() { Some(_value) => { Some(1) } _ => { None }} } { if let Some(1) = { match Droppy.get() { Some(_value) => { Some(1) } _ => { None }} } {
//~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024 //~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
//~| ERROR a `match` with a single arm can preserve the drop order up to Edition 2021
//~| WARN: this changes meaning in Rust 2024 //~| WARN: this changes meaning in Rust 2024
//~| WARN: this changes meaning in Rust 2024
//~| HELP: rewrite this `if let` into `match`
//~| HELP: rewrite this `if let` into `match`
//~| HELP: rewrite this `if let` into `match`
//~| HELP: rewrite this `if let` into `match`
//~| HELP: the value is now dropped here in Edition 2024 //~| HELP: the value is now dropped here in Edition 2024
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
} }
if let () = { match Droppy.get() { Some(_value) => {} _ => {}} } { if let () = { match Droppy.get() { Some(_value) => {} _ => {}} } {
//~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024 //~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
//~| ERROR a `match` with a single arm can preserve the drop order up to Edition 2021
//~| WARN: this changes meaning in Rust 2024 //~| WARN: this changes meaning in Rust 2024
//~| WARN: this changes meaning in Rust 2024
//~| HELP: rewrite this `if let` into `match`
//~| HELP: rewrite this `if let` into `match`
//~| HELP: rewrite this `if let` into `match`
//~| HELP: the value is now dropped here in Edition 2024 //~| HELP: the value is now dropped here in Edition 2024
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
} }
} }

View file

@ -27,73 +27,45 @@ fn main() {
if let Some(_value) = droppy().get() { if let Some(_value) = droppy().get() {
//~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024 //~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
//~| WARN: this changes meaning in Rust 2024 //~| WARN: this changes meaning in Rust 2024
//~| WARN: this changes meaning in Rust 2024 //~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
//~| ERROR a `match` with a single arm can preserve the drop order up to Edition 2021
//~| HELP: rewrite this `if let` into `match`
//~| HELP: rewrite this `if let` into `match`
// do something // do something
} else { } else {
//~^ HELP: the value is now dropped here in Edition 2024 //~^ HELP: the value is now dropped here in Edition 2024
//~| HELP: rewrite this `if let` into `match`
// do something else // do something else
} }
//~^ HELP: rewrite this `if let` into `match`
if let Some(_value) = droppy().get() { if let Some(_value) = droppy().get() {
//~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024 //~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
//~| WARN: this changes meaning in Rust 2024 //~| WARN: this changes meaning in Rust 2024
//~| WARN: this changes meaning in Rust 2024 //~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
//~| ERROR a `match` with a single arm can preserve the drop order up to Edition 2021
//~| HELP: rewrite this `if let` into `match`
//~| HELP: rewrite this `if let` into `match`
// do something // do something
} else if let Some(_value) = droppy().get() { } else if let Some(_value) = droppy().get() {
//~^ HELP: the value is now dropped here in Edition 2024 //~^ HELP: the value is now dropped here in Edition 2024
//~| ERROR: `if let` assigns a shorter lifetime since Edition 2024
//~| WARN: this changes meaning in Rust 2024
//~| HELP: rewrite this `if let` into `match`
//~| HELP: rewrite this `if let` into `match`
//~| HELP: rewrite this `if let` into `match`
// do something else // do something else
} }
//~^ HELP: rewrite this `if let` into `match` //~^ HELP: the value is now dropped here in Edition 2024
//~| HELP: the value is now dropped here in Edition 2024
if droppy().get().is_some() { if droppy().get().is_some() {
// Should not lint // Should not lint
} else if let Some(_value) = droppy().get() { } else if let Some(_value) = droppy().get() {
//~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024 //~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
//~| ERROR a `match` with a single arm can preserve the drop order up to Edition 2021
//~| WARN: this changes meaning in Rust 2024 //~| WARN: this changes meaning in Rust 2024
//~| WARN: this changes meaning in Rust 2024 //~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
//~| HELP: rewrite this `if let` into `match`
//~| HELP: rewrite this `if let` into `match`
} else if droppy().get().is_none() { } else if droppy().get().is_none() {
//~^ HELP: the value is now dropped here in Edition 2024 //~^ HELP: the value is now dropped here in Edition 2024
//~| HELP: rewrite this `if let` into `match`
} }
//~^ HELP: rewrite this `if let` into `match`
if let Some(1) = { if let Some(_value) = Droppy.get() { Some(1) } else { None } } { if let Some(1) = { if let Some(_value) = Droppy.get() { Some(1) } else { None } } {
//~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024 //~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
//~| ERROR a `match` with a single arm can preserve the drop order up to Edition 2021
//~| WARN: this changes meaning in Rust 2024 //~| WARN: this changes meaning in Rust 2024
//~| WARN: this changes meaning in Rust 2024
//~| HELP: rewrite this `if let` into `match`
//~| HELP: rewrite this `if let` into `match`
//~| HELP: rewrite this `if let` into `match`
//~| HELP: rewrite this `if let` into `match`
//~| HELP: the value is now dropped here in Edition 2024 //~| HELP: the value is now dropped here in Edition 2024
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
} }
if let () = { if let Some(_value) = Droppy.get() {} } { if let () = { if let Some(_value) = Droppy.get() {} } {
//~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024 //~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
//~| ERROR a `match` with a single arm can preserve the drop order up to Edition 2021
//~| WARN: this changes meaning in Rust 2024 //~| WARN: this changes meaning in Rust 2024
//~| WARN: this changes meaning in Rust 2024
//~| HELP: rewrite this `if let` into `match`
//~| HELP: rewrite this `if let` into `match`
//~| HELP: rewrite this `if let` into `match`
//~| HELP: the value is now dropped here in Edition 2024 //~| HELP: the value is now dropped here in Edition 2024
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
} }
} }

View file

@ -9,7 +9,7 @@ LL | if let Some(_value) = droppy().get() {
= warning: this changes meaning in Rust 2024 = warning: this changes meaning in Rust 2024
= note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085> = note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085>
help: the value is now dropped here in Edition 2024 help: the value is now dropped here in Edition 2024
--> $DIR/lint-if-let-rescope.rs:35:5 --> $DIR/lint-if-let-rescope.rs:32:5
| |
LL | } else { LL | } else {
| ^ | ^
@ -18,53 +18,52 @@ note: the lint level is defined here
| |
LL | #![deny(if_let_rescope)] LL | #![deny(if_let_rescope)]
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^
help: a `match` with a single arm can preserve the drop order up to Edition 2021
error: a `match` with a single arm can preserve the drop order up to Edition 2021
--> $DIR/lint-if-let-rescope.rs:27:5
| |
LL | / if let Some(_value) = droppy().get() { LL ~ match droppy().get() { Some(_value) => {
LL | | LL |
LL | | ...
LL | | LL | // do something
... | LL ~ } _ => {
LL | | // do something else LL |
LL | | } LL | // do something else
| |_____^ LL ~ }}
| |
= warning: this changes meaning in Rust 2024
= note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085>
help: rewrite this `if let` into `match`
|
LL | match droppy().get() {
| ~~~~~
help: rewrite this `if let` into `match`
|
LL | if let Some(_value) = droppy().get() { Some(_value) => {
| +++++++++++++++++
help: rewrite this `if let` into `match`
|
LL | }}
| +
help: rewrite this `if let` into `match`
|
LL | } _ => {
| ~~~~
error: `if let` assigns a shorter lifetime since Edition 2024 error: `if let` assigns a shorter lifetime since Edition 2024
--> $DIR/lint-if-let-rescope.rs:42:8 --> $DIR/lint-if-let-rescope.rs:37:8
| |
LL | if let Some(_value) = droppy().get() { LL | if let Some(_value) = droppy().get() {
| ^^^^^^^^^^^^^^^^^^^--------^^^^^^ | ^^^^^^^^^^^^^^^^^^^--------^^^^^^
| | | |
| this value has a significant drop implementation which may observe a major change in drop order and requires your discretion | this value has a significant drop implementation which may observe a major change in drop order and requires your discretion
...
LL | } else if let Some(_value) = droppy().get() {
| -------- this value has a significant drop implementation which may observe a major change in drop order and requires your discretion
| |
= warning: this changes meaning in Rust 2024 = warning: this changes meaning in Rust 2024
= note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085> = note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085>
help: the value is now dropped here in Edition 2024 help: the value is now dropped here in Edition 2024
--> $DIR/lint-if-let-rescope.rs:50:5 --> $DIR/lint-if-let-rescope.rs:42:5
| |
LL | } else if let Some(_value) = droppy().get() { LL | } else if let Some(_value) = droppy().get() {
| ^ | ^
help: the value is now dropped here in Edition 2024
--> $DIR/lint-if-let-rescope.rs:45:5
|
LL | }
| ^
help: a `match` with a single arm can preserve the drop order up to Edition 2021
|
LL ~ match droppy().get() { Some(_value) => {
LL |
...
LL | // do something
LL ~ } _ => { match droppy().get() { Some(_value) => {
LL |
LL | // do something else
LL ~ } _ => {}}}}
|
error: `if let` assigns a shorter lifetime since Edition 2024 error: `if let` assigns a shorter lifetime since Edition 2024
--> $DIR/lint-if-let-rescope.rs:50:15 --> $DIR/lint-if-let-rescope.rs:50:15
@ -77,100 +76,23 @@ LL | } else if let Some(_value) = droppy().get() {
= warning: this changes meaning in Rust 2024 = warning: this changes meaning in Rust 2024
= note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085> = note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085>
help: the value is now dropped here in Edition 2024 help: the value is now dropped here in Edition 2024
--> $DIR/lint-if-let-rescope.rs:58:5 --> $DIR/lint-if-let-rescope.rs:54:5
|
LL | }
| ^
error: a `match` with a single arm can preserve the drop order up to Edition 2021
--> $DIR/lint-if-let-rescope.rs:42:5
|
LL | / if let Some(_value) = droppy().get() {
LL | |
LL | |
LL | |
... |
LL | | // do something else
LL | | }
| |_____^
|
= warning: this changes meaning in Rust 2024
= note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085>
help: rewrite this `if let` into `match`
|
LL | match droppy().get() {
| ~~~~~
help: rewrite this `if let` into `match`
|
LL | } else { match droppy().get() {
| ~~~~~~~
help: rewrite this `if let` into `match`
|
LL | if let Some(_value) = droppy().get() { Some(_value) => {
| +++++++++++++++++
help: rewrite this `if let` into `match`
|
LL | } else if let Some(_value) = droppy().get() { Some(_value) => {
| +++++++++++++++++
help: rewrite this `if let` into `match`
|
LL | } _ => {}}}}
| ++++++++++
help: rewrite this `if let` into `match`
|
LL | } _ => if let Some(_value) = droppy().get() {
| ~~~~
error: `if let` assigns a shorter lifetime since Edition 2024
--> $DIR/lint-if-let-rescope.rs:64:15
|
LL | } else if let Some(_value) = droppy().get() {
| ^^^^^^^^^^^^^^^^^^^--------^^^^^^
| |
| this value has a significant drop implementation which may observe a major change in drop order and requires your discretion
|
= warning: this changes meaning in Rust 2024
= note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085>
help: the value is now dropped here in Edition 2024
--> $DIR/lint-if-let-rescope.rs:71:5
| |
LL | } else if droppy().get().is_none() { LL | } else if droppy().get().is_none() {
| ^ | ^
help: a `match` with a single arm can preserve the drop order up to Edition 2021
error: a `match` with a single arm can preserve the drop order up to Edition 2021
--> $DIR/lint-if-let-rescope.rs:64:12
| |
LL | } else if let Some(_value) = droppy().get() { LL ~ } else { match droppy().get() { Some(_value) => {
| ____________^ LL |
LL | | LL |
LL | | LL |
LL | | LL ~ } _ => if droppy().get().is_none() {
... | LL |
LL | | LL ~ }}}
LL | | }
| |_____^
| |
= warning: this changes meaning in Rust 2024
= note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085>
help: rewrite this `if let` into `match`
|
LL | } else { match droppy().get() {
| ~~~~~~~
help: rewrite this `if let` into `match`
|
LL | } else if let Some(_value) = droppy().get() { Some(_value) => {
| +++++++++++++++++
help: rewrite this `if let` into `match`
|
LL | }}}
| ++
help: rewrite this `if let` into `match`
|
LL | } _ => if droppy().get().is_none() {
| ~~~~
error: `if let` assigns a shorter lifetime since Edition 2024 error: `if let` assigns a shorter lifetime since Edition 2024
--> $DIR/lint-if-let-rescope.rs:77:27 --> $DIR/lint-if-let-rescope.rs:58:27
| |
LL | if let Some(1) = { if let Some(_value) = Droppy.get() { Some(1) } else { None } } { LL | if let Some(1) = { if let Some(_value) = Droppy.get() { Some(1) } else { None } } {
| ^^^^^^^^^^^^^^^^^^^------^^^^^^ | ^^^^^^^^^^^^^^^^^^^------^^^^^^
@ -180,38 +102,17 @@ LL | if let Some(1) = { if let Some(_value) = Droppy.get() { Some(1) } else
= warning: this changes meaning in Rust 2024 = warning: this changes meaning in Rust 2024
= note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085> = note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085>
help: the value is now dropped here in Edition 2024 help: the value is now dropped here in Edition 2024
--> $DIR/lint-if-let-rescope.rs:77:69 --> $DIR/lint-if-let-rescope.rs:58:69
| |
LL | if let Some(1) = { if let Some(_value) = Droppy.get() { Some(1) } else { None } } { LL | if let Some(1) = { if let Some(_value) = Droppy.get() { Some(1) } else { None } } {
| ^ | ^
help: a `match` with a single arm can preserve the drop order up to Edition 2021
error: a `match` with a single arm can preserve the drop order up to Edition 2021
--> $DIR/lint-if-let-rescope.rs:77:24
| |
LL | if let Some(1) = { if let Some(_value) = Droppy.get() { Some(1) } else { None } } { LL | if let Some(1) = { match Droppy.get() { Some(_value) => { Some(1) } _ => { None }} } {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ~~~~~ +++++++++++++++++ ~~~~ +
|
= warning: this changes meaning in Rust 2024
= note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085>
help: rewrite this `if let` into `match`
|
LL | if let Some(1) = { match Droppy.get() { Some(1) } else { None } } {
| ~~~~~
help: rewrite this `if let` into `match`
|
LL | if let Some(1) = { if let Some(_value) = Droppy.get() { Some(_value) => { Some(1) } else { None } } {
| +++++++++++++++++
help: rewrite this `if let` into `match`
|
LL | if let Some(1) = { if let Some(_value) = Droppy.get() { Some(1) } else { None }} } {
| +
help: rewrite this `if let` into `match`
|
LL | if let Some(1) = { if let Some(_value) = Droppy.get() { Some(1) } _ => { None } } {
| ~~~~
error: `if let` assigns a shorter lifetime since Edition 2024 error: `if let` assigns a shorter lifetime since Edition 2024
--> $DIR/lint-if-let-rescope.rs:89:22 --> $DIR/lint-if-let-rescope.rs:65:22
| |
LL | if let () = { if let Some(_value) = Droppy.get() {} } { LL | if let () = { if let Some(_value) = Droppy.get() {} } {
| ^^^^^^^^^^^^^^^^^^^------^^^^^^ | ^^^^^^^^^^^^^^^^^^^------^^^^^^
@ -221,31 +122,14 @@ LL | if let () = { if let Some(_value) = Droppy.get() {} } {
= warning: this changes meaning in Rust 2024 = warning: this changes meaning in Rust 2024
= note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085> = note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085>
help: the value is now dropped here in Edition 2024 help: the value is now dropped here in Edition 2024
--> $DIR/lint-if-let-rescope.rs:89:55 --> $DIR/lint-if-let-rescope.rs:65:55
| |
LL | if let () = { if let Some(_value) = Droppy.get() {} } { LL | if let () = { if let Some(_value) = Droppy.get() {} } {
| ^ | ^
help: a `match` with a single arm can preserve the drop order up to Edition 2021
|
LL | if let () = { match Droppy.get() { Some(_value) => {} _ => {}} } {
| ~~~~~ +++++++++++++++++ ++++++++
error: a `match` with a single arm can preserve the drop order up to Edition 2021 error: aborting due to 5 previous errors
--> $DIR/lint-if-let-rescope.rs:89:19
|
LL | if let () = { if let Some(_value) = Droppy.get() {} } {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this changes meaning in Rust 2024
= note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085>
help: rewrite this `if let` into `match`
|
LL | if let () = { match Droppy.get() {} } {
| ~~~~~
help: rewrite this `if let` into `match`
|
LL | if let () = { if let Some(_value) = Droppy.get() { Some(_value) => {} } {
| +++++++++++++++++
help: rewrite this `if let` into `match`
|
LL | if let () = { if let Some(_value) = Droppy.get() {} _ => {}} } {
| ++++++++
error: aborting due to 11 previous errors