Skip to content

Commit 4a1fda8

Browse files
committed
Auto merge of #27565 - TimNN:dead-visit-type-in-path, r=nrc
Fixes #23808, passes `make check-stage1` `run-pass` and `run-fail` locally.
2 parents 258f303 + 2d4e07e commit 4a1fda8

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

Diff for: src/librustc/middle/dead.rs

+10
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
7373
}
7474

7575
fn lookup_and_handle_definition(&mut self, id: &ast::NodeId) {
76+
use middle::ty::TypeVariants::{TyEnum, TyStruct};
77+
78+
// If `bar` is a trait item, make sure to mark Foo as alive in `Foo::bar`
79+
self.tcx.tables.borrow().item_substs.get(id)
80+
.and_then(|substs| substs.substs.self_ty())
81+
.map(|ty| match ty.sty {
82+
TyEnum(tyid, _) | TyStruct(tyid, _) => self.check_def_id(tyid.did),
83+
_ => (),
84+
});
85+
7686
self.tcx.def_map.borrow().get(id).map(|def| {
7787
match def.full_def() {
7888
def::DefConst(_) | def::DefAssociatedConst(..) => {

Diff for: src/test/run-pass/issue-23808.rs

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(associated_consts)]
12+
#![deny(dead_code)]
13+
14+
// use different types / traits to test all combinations
15+
16+
trait Const {
17+
const C: ();
18+
}
19+
20+
trait StaticFn {
21+
fn sfn();
22+
}
23+
24+
struct ConstStruct;
25+
struct StaticFnStruct;
26+
27+
enum ConstEnum {}
28+
enum StaticFnEnum {}
29+
30+
struct AliasedConstStruct;
31+
struct AliasedStaticFnStruct;
32+
33+
enum AliasedConstEnum {}
34+
enum AliasedStaticFnEnum {}
35+
36+
type AliasConstStruct = AliasedConstStruct;
37+
type AliasStaticFnStruct = AliasedStaticFnStruct;
38+
type AliasConstEnum = AliasedConstEnum;
39+
type AliasStaticFnEnum = AliasedStaticFnEnum;
40+
41+
macro_rules! impl_Const {($($T:ident),*) => {$(
42+
impl Const for $T {
43+
const C: () = ();
44+
}
45+
)*}}
46+
47+
macro_rules! impl_StaticFn {($($T:ident),*) => {$(
48+
impl StaticFn for $T {
49+
fn sfn() {}
50+
}
51+
)*}}
52+
53+
impl_Const!(ConstStruct, ConstEnum, AliasedConstStruct, AliasedConstEnum);
54+
impl_StaticFn!(StaticFnStruct, StaticFnEnum, AliasedStaticFnStruct, AliasedStaticFnEnum);
55+
56+
fn main() {
57+
let _ = ConstStruct::C;
58+
let _ = ConstEnum::C;
59+
60+
StaticFnStruct::sfn();
61+
StaticFnEnum::sfn();
62+
63+
let _ = AliasConstStruct::C;
64+
let _ = AliasConstEnum::C;
65+
66+
AliasStaticFnStruct::sfn();
67+
AliasStaticFnEnum::sfn();
68+
}

0 commit comments

Comments
 (0)