Skip to content

Fix #23808: dead_code lint: visit types in paths #27565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
}

fn lookup_and_handle_definition(&mut self, id: &ast::NodeId) {
use middle::ty::TypeVariants::{TyEnum, TyStruct};

// If `bar` is a trait item, make sure to mark Foo as alive in `Foo::bar`
self.tcx.tables.borrow().item_substs.get(id)
.and_then(|substs| substs.substs.self_ty())
.map(|ty| match ty.sty {
TyEnum(tyid, _) | TyStruct(tyid, _) => self.check_def_id(tyid.did),
_ => (),
});

self.tcx.def_map.borrow().get(id).map(|def| {
match def.full_def() {
def::DefConst(_) | def::DefAssociatedConst(..) => {
Expand Down
68 changes: 68 additions & 0 deletions src/test/run-pass/issue-23808.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(associated_consts)]
#![deny(dead_code)]

// use different types / traits to test all combinations

trait Const {
const C: ();
}

trait StaticFn {
fn sfn();
}

struct ConstStruct;
struct StaticFnStruct;

enum ConstEnum {}
enum StaticFnEnum {}

struct AliasedConstStruct;
struct AliasedStaticFnStruct;

enum AliasedConstEnum {}
enum AliasedStaticFnEnum {}

type AliasConstStruct = AliasedConstStruct;
type AliasStaticFnStruct = AliasedStaticFnStruct;
type AliasConstEnum = AliasedConstEnum;
type AliasStaticFnEnum = AliasedStaticFnEnum;

macro_rules! impl_Const {($($T:ident),*) => {$(
impl Const for $T {
const C: () = ();
}
)*}}

macro_rules! impl_StaticFn {($($T:ident),*) => {$(
impl StaticFn for $T {
fn sfn() {}
}
)*}}

impl_Const!(ConstStruct, ConstEnum, AliasedConstStruct, AliasedConstEnum);
impl_StaticFn!(StaticFnStruct, StaticFnEnum, AliasedStaticFnStruct, AliasedStaticFnEnum);

fn main() {
let _ = ConstStruct::C;
let _ = ConstEnum::C;

StaticFnStruct::sfn();
StaticFnEnum::sfn();

let _ = AliasConstStruct::C;
let _ = AliasConstEnum::C;

AliasStaticFnStruct::sfn();
AliasStaticFnEnum::sfn();
}