Merge pull request #640 from oli-obk/fix/639

prevent panic in enum glob import lint if a crate's elements are glob imported
This commit is contained in:
Manish Goregaokar 2016-02-08 16:15:59 +05:30
commit d68dc8e25a
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() { }