Skip to content

Commit 851b33a

Browse files
committed
rust-timer simulated merge of a188791
Original message: Rollup merge of rust-lang#80629 - sexxi-goose:migrations_1, r=nikomatsakis Add lint for 2229 migrations Implements the first for RFC 2229 where we make the decision to migrate a root variable based on if the type of the variable needs Drop and if the root variable would be moved into the closure when the feature isn't enabled. r? `@nikomatsakis`
1 parent 46aae25 commit 851b33a

File tree

10 files changed

+812
-53
lines changed

10 files changed

+812
-53
lines changed

compiler/rustc_lint_defs/src/builtin.rs

+46
Original file line numberDiff line numberDiff line change
@@ -2968,6 +2968,7 @@ declare_lint_pass! {
29682968
UNSUPPORTED_NAKED_FUNCTIONS,
29692969
MISSING_ABI,
29702970
SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
2971+
DISJOINT_CAPTURE_DROP_REORDER,
29712972
]
29722973
}
29732974

@@ -2994,6 +2995,51 @@ declare_lint! {
29942995
"detects doc comments that aren't used by rustdoc"
29952996
}
29962997

2998+
declare_lint! {
2999+
/// The `disjoint_capture_drop_reorder` lint detects variables that aren't completely
3000+
/// captured when the feature `capture_disjoint_fields` is enabled and it affects the Drop
3001+
/// order of at least one path starting at this variable.
3002+
///
3003+
/// ### Example
3004+
///
3005+
/// ```rust,compile_fail
3006+
/// # #![deny(disjoint_capture_drop_reorder)]
3007+
/// # #![allow(unused)]
3008+
/// struct FancyInteger(i32);
3009+
///
3010+
/// impl Drop for FancyInteger {
3011+
/// fn drop(&mut self) {
3012+
/// println!("Just dropped {}", self.0);
3013+
/// }
3014+
/// }
3015+
///
3016+
/// struct Point { x: FancyInteger, y: FancyInteger }
3017+
///
3018+
/// fn main() {
3019+
/// let p = Point { x: FancyInteger(10), y: FancyInteger(20) };
3020+
///
3021+
/// let c = || {
3022+
/// let x = p.x;
3023+
/// };
3024+
///
3025+
/// c();
3026+
///
3027+
/// // ... More code ...
3028+
/// }
3029+
/// ```
3030+
///
3031+
/// {{produces}}
3032+
///
3033+
/// ### Explanation
3034+
///
3035+
/// In the above example `p.y` will be dropped at the end of `f` instead of with `c` if
3036+
/// the feature `capture_disjoint_fields` is enabled.
3037+
pub DISJOINT_CAPTURE_DROP_REORDER,
3038+
Allow,
3039+
"Drop reorder because of `capture_disjoint_fields`"
3040+
3041+
}
3042+
29973043
declare_lint_pass!(UnusedDocComment => [UNUSED_DOC_COMMENTS]);
29983044

29993045
declare_lint! {

0 commit comments

Comments
 (0)