Skip to content

Commit c308726

Browse files
committed
Auto merge of rust-lang#119552 - krtab:dead_code_priv_mod_pub_field, r=cjgillot,saethlin
Replace visibility test with reachability test in dead code detection Fixes rust-lang#119545 Also included is a fix for an error now flagged by the lint
2 parents 0ad5e0d + 7342cc4 commit c308726

File tree

29 files changed

+129
-53
lines changed

29 files changed

+129
-53
lines changed

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,7 +2065,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20652065
from_closure: constraint.from_closure,
20662066
cause: ObligationCause::new(constraint.span, CRATE_DEF_ID, cause_code.clone()),
20672067
variance_info: constraint.variance_info,
2068-
outlives_constraint: *constraint,
20692068
})
20702069
.collect();
20712070
debug!("categorized_path={:#?}", categorized_path);
@@ -2294,5 +2293,4 @@ pub struct BlameConstraint<'tcx> {
22942293
pub from_closure: bool,
22952294
pub cause: ObligationCause<'tcx>,
22962295
pub variance_info: ty::VarianceDiagInfo<'tcx>,
2297-
pub outlives_constraint: OutlivesConstraint<'tcx>,
22982296
}

compiler/rustc_builtin_macros/src/deriving/debug.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
5151

5252
let (ident, vdata, fields) = match substr.fields {
5353
Struct(vdata, fields) => (substr.type_ident, *vdata, fields),
54-
EnumMatching(_, _, v, fields) => (v.ident, &v.data, fields),
54+
EnumMatching(_, v, fields) => (v.ident, &v.data, fields),
5555
AllFieldlessEnum(enum_def) => return show_fieldless_enum(cx, span, enum_def, substr),
5656
EnumTag(..) | StaticStruct(..) | StaticEnum(..) => {
5757
cx.dcx().span_bug(span, "nonsensical .fields in `#[derive(Debug)]`")

compiler/rustc_builtin_macros/src/deriving/encodable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ fn encodable_substructure(
226226
BlockOrExpr::new_expr(expr)
227227
}
228228

229-
EnumMatching(idx, _, variant, fields) => {
229+
EnumMatching(idx, variant, fields) => {
230230
// We're not generating an AST that the borrow checker is expecting,
231231
// so we need to generate a unique local variable to take the
232232
// mutable loan out on, otherwise we get conflicts which don't

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,10 @@ pub enum SubstructureFields<'a> {
310310
/// variants has any fields).
311311
AllFieldlessEnum(&'a ast::EnumDef),
312312

313-
/// Matching variants of the enum: variant index, variant count, ast::Variant,
313+
/// Matching variants of the enum: variant index, ast::Variant,
314314
/// fields: the field name is only non-`None` in the case of a struct
315315
/// variant.
316-
EnumMatching(usize, usize, &'a ast::Variant, Vec<FieldInfo>),
316+
EnumMatching(usize, &'a ast::Variant, Vec<FieldInfo>),
317317

318318
/// The tag of an enum. The first field is a `FieldInfo` for the tags, as
319319
/// if they were fields. The second field is the expression to combine the
@@ -1272,7 +1272,7 @@ impl<'a> MethodDef<'a> {
12721272
trait_,
12731273
type_ident,
12741274
nonselflike_args,
1275-
&EnumMatching(0, 1, &variants[0], Vec::new()),
1275+
&EnumMatching(0, &variants[0], Vec::new()),
12761276
);
12771277
}
12781278
}
@@ -1318,7 +1318,7 @@ impl<'a> MethodDef<'a> {
13181318
// expressions for referencing every field of every
13191319
// Self arg, assuming all are instances of VariantK.
13201320
// Build up code associated with such a case.
1321-
let substructure = EnumMatching(index, variants.len(), variant, fields);
1321+
let substructure = EnumMatching(index, variant, fields);
13221322
let arm_expr = self
13231323
.call_substructure_method(
13241324
cx,
@@ -1346,7 +1346,7 @@ impl<'a> MethodDef<'a> {
13461346
trait_,
13471347
type_ident,
13481348
nonselflike_args,
1349-
&EnumMatching(0, variants.len(), v, Vec::new()),
1349+
&EnumMatching(0, v, Vec::new()),
13501350
)
13511351
.into_expr(cx, span),
13521352
)

compiler/rustc_codegen_gcc/src/context.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ pub struct CodegenCx<'gcc, 'tcx> {
110110
local_gen_sym_counter: Cell<usize>,
111111

112112
eh_personality: Cell<Option<RValue<'gcc>>>,
113+
#[cfg(feature="master")]
113114
pub rust_try_fn: Cell<Option<(Type<'gcc>, Function<'gcc>)>>,
114115

115116
pub pointee_infos: RefCell<FxHashMap<(Ty<'tcx>, Size), Option<PointeeInfo>>>,
@@ -121,6 +122,7 @@ pub struct CodegenCx<'gcc, 'tcx> {
121122
/// FIXME(antoyo): fix the rustc API to avoid having this hack.
122123
pub structs_as_pointer: RefCell<FxHashSet<RValue<'gcc>>>,
123124

125+
#[cfg(feature="master")]
124126
pub cleanup_blocks: RefCell<FxHashSet<Block<'gcc>>>,
125127
}
126128

@@ -325,9 +327,11 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
325327
struct_types: Default::default(),
326328
local_gen_sym_counter: Cell::new(0),
327329
eh_personality: Cell::new(None),
330+
#[cfg(feature="master")]
328331
rust_try_fn: Cell::new(None),
329332
pointee_infos: Default::default(),
330333
structs_as_pointer: Default::default(),
334+
#[cfg(feature="master")]
331335
cleanup_blocks: Default::default(),
332336
};
333337
// TODO(antoyo): instead of doing this, add SsizeT to libgccjit.

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ use rustc_session::config::{CrateType, DebugInfo, PAuthKey, PacRet};
2727
use rustc_session::Session;
2828
use rustc_span::source_map::Spanned;
2929
use rustc_span::Span;
30-
use rustc_target::abi::{
31-
call::FnAbi, HasDataLayout, PointeeInfo, Size, TargetDataLayout, VariantIdx,
32-
};
30+
use rustc_target::abi::{call::FnAbi, HasDataLayout, TargetDataLayout, VariantIdx};
3331
use rustc_target::spec::{HasTargetSpec, RelocModel, Target, TlsModel};
3432
use smallvec::SmallVec;
3533

@@ -83,7 +81,6 @@ pub struct CodegenCx<'ll, 'tcx> {
8381
/// Mapping of scalar types to llvm types.
8482
pub scalar_lltypes: RefCell<FxHashMap<Ty<'tcx>, &'ll Type>>,
8583

86-
pub pointee_infos: RefCell<FxHashMap<(Ty<'tcx>, Size), Option<PointeeInfo>>>,
8784
pub isize_ty: &'ll Type,
8885

8986
pub coverage_cx: Option<coverageinfo::CrateCoverageContext<'ll, 'tcx>>,
@@ -450,7 +447,6 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
450447
compiler_used_statics: RefCell::new(Vec::new()),
451448
type_lowering: Default::default(),
452449
scalar_lltypes: Default::default(),
453-
pointee_infos: Default::default(),
454450
isize_ty,
455451
coverage_cx,
456452
dbg_cx,

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fn propagate_ssa<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
131131
|local, value, location| {
132132
let value = match value {
133133
// We do not know anything of this assigned value.
134-
AssignedValue::Arg | AssignedValue::Terminator(_) => None,
134+
AssignedValue::Arg | AssignedValue::Terminator => None,
135135
// Try to get some insight.
136136
AssignedValue::Rvalue(rvalue) => {
137137
let value = state.simplify_rvalue(rvalue, location);

compiler/rustc_mir_transform/src/ssa.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub struct SsaLocals {
2929
pub enum AssignedValue<'a, 'tcx> {
3030
Arg,
3131
Rvalue(&'a mut Rvalue<'tcx>),
32-
Terminator(&'a mut TerminatorKind<'tcx>),
32+
Terminator,
3333
}
3434

3535
impl SsaLocals {
@@ -149,8 +149,7 @@ impl SsaLocals {
149149
Set1::One(DefLocation::CallReturn { call, .. }) => {
150150
let bb = &mut basic_blocks[call];
151151
let loc = Location { block: call, statement_index: bb.statements.len() };
152-
let term = bb.terminator_mut();
153-
f(local, AssignedValue::Terminator(&mut term.kind), loc)
152+
f(local, AssignedValue::Terminator, loc)
154153
}
155154
_ => {}
156155
}

compiler/rustc_passes/src/dead.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,15 +525,16 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
525525
let tcx = self.tcx;
526526
let unconditionally_treat_fields_as_live = self.repr_unconditionally_treats_fields_as_live;
527527
let has_repr_simd = self.repr_has_repr_simd;
528+
let effective_visibilities = &tcx.effective_visibilities(());
528529
let live_fields = def.fields().iter().filter_map(|f| {
529530
let def_id = f.def_id;
530531
if unconditionally_treat_fields_as_live || (f.is_positional() && has_repr_simd) {
531532
return Some(def_id);
532533
}
533-
if !tcx.visibility(f.hir_id.owner.def_id).is_public() {
534+
if !effective_visibilities.is_reachable(f.hir_id.owner.def_id) {
534535
return None;
535536
}
536-
if tcx.visibility(def_id).is_public() { Some(def_id) } else { None }
537+
if effective_visibilities.is_reachable(def_id) { Some(def_id) } else { None }
537538
});
538539
self.live_symbols.extend(live_fields);
539540

library/alloc/src/collections/btree/navigate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ impl<BorrowType: marker::BorrowType, K, V> NodeRef<BorrowType, K, V, marker::Lea
655655
pub enum Position<BorrowType, K, V> {
656656
Leaf(NodeRef<BorrowType, K, V, marker::Leaf>),
657657
Internal(NodeRef<BorrowType, K, V, marker::Internal>),
658-
InternalKV(Handle<NodeRef<BorrowType, K, V, marker::Internal>, marker::KV>),
658+
InternalKV,
659659
}
660660

661661
impl<'a, K: 'a, V: 'a> NodeRef<marker::Immut<'a>, K, V, marker::LeafOrInternal> {
@@ -677,7 +677,7 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Immut<'a>, K, V, marker::LeafOrInternal>
677677
visit(Position::Leaf(leaf));
678678
match edge.next_kv() {
679679
Ok(kv) => {
680-
visit(Position::InternalKV(kv));
680+
visit(Position::InternalKV);
681681
kv.right_edge()
682682
}
683683
Err(_) => return,
@@ -699,7 +699,7 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Immut<'a>, K, V, marker::LeafOrInternal>
699699
self.visit_nodes_in_order(|pos| match pos {
700700
Position::Leaf(node) => result += node.len(),
701701
Position::Internal(node) => result += node.len(),
702-
Position::InternalKV(_) => (),
702+
Position::InternalKV => (),
703703
});
704704
result
705705
}

0 commit comments

Comments
 (0)