prevent panic in enum glob import lint if a crate's elements are glob imported

fixes #639
This commit is contained in:
Oliver Schneider 2016-02-08 11:28:18 +01:00
parent 4d5cd7255d
commit 672beb4138
3 changed files with 14 additions and 4 deletions

View file

@ -3,7 +3,7 @@
use rustc::lint::{LateLintPass, LintPass, LateContext, LintArray, LintContext};
use rustc_front::hir::*;
use rustc::front::map::Node::NodeItem;
use rustc::front::map::PathElem::PathName;
use rustc::front::map::definitions::DefPathData;
use rustc::middle::ty::TyEnum;
use utils::span_lint;
use syntax::codemap::Span;
@ -49,9 +49,11 @@ impl EnumGlobUse {
span_lint(cx, ENUM_GLOB_USE, item.span, "don't use glob imports for enum variants");
}
} else {
if let Some(&PathName(_)) = cx.sess().cstore.item_path(def.def_id()).last() {
if let TyEnum(..) = cx.sess().cstore.item_type(&cx.tcx, def.def_id()).ty.sty {
span_lint(cx, ENUM_GLOB_USE, item.span, "don't use glob imports for enum variants");
if let Some(dp) = cx.sess().cstore.def_path(def.def_id()).last() {
if let DefPathData::Type(_) = dp.data {
if let TyEnum(..) = cx.sess().cstore.item_type(&cx.tcx, def.def_id()).ty.sty {
span_lint(cx, ENUM_GLOB_USE, item.span, "don't use glob imports for enum variants");
}
}
}
}

View file

@ -21,5 +21,6 @@ fn run_mode(mode: &'static str) {
#[test]
fn compile_test() {
run_mode("run-pass");
run_mode("compile-fail");
}

View file

@ -0,0 +1,7 @@
#![feature(plugin)]
#![plugin(clippy)]
#![deny(clippy)]
use std::*;
fn main() { }