Skip to content

Commit 24cfe98

Browse files
authored
Rollup merge of rust-lang#149147 - chenyukang:yukang-fix-unused_assignments-macro-gen-147648, r=JonathanBrouwer
Fix unused_assignments false positives from macros Fixes rust-lang#147648
2 parents 538c7c9 + f943606 commit 24cfe98

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

compiler/rustc_mir_transform/src/liveness.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ pub(crate) fn check_liveness<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Den
7575
return DenseBitSet::new_empty(0);
7676
}
7777

78+
// Don't run unused pass for items generated by foreign macros
79+
if tcx.def_span(parent).in_external_macro(tcx.sess.source_map()) {
80+
return DenseBitSet::new_empty(0);
81+
}
82+
7883
let mut body = &*tcx.mir_promoted(def_id).0.borrow();
7984
let mut body_mem;
8085

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#[macro_export]
2+
macro_rules! unused_assign {
3+
($x:ident) => {
4+
let mut $x = 1;
5+
$x = 2;
6+
};
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//@ check-pass
2+
//@ aux-build:aux_issue_147648.rs
3+
4+
#![deny(unused_assignments)]
5+
6+
extern crate aux_issue_147648;
7+
8+
fn main() {
9+
aux_issue_147648::unused_assign!(y);
10+
}

0 commit comments

Comments
 (0)