From 672beb4138011446ee55360e71a857197ae18d97 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 8 Feb 2016 11:28:18 +0100 Subject: [PATCH] prevent panic in enum glob import lint if a crate's elements are glob imported fixes #639 --- src/enum_glob_use.rs | 10 ++++++---- tests/compile-test.rs | 1 + tests/run-pass/enum-glob-import-crate.rs | 7 +++++++ 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 tests/run-pass/enum-glob-import-crate.rs diff --git a/src/enum_glob_use.rs b/src/enum_glob_use.rs index d6df307fec2..c6561461e04 100644 --- a/src/enum_glob_use.rs +++ b/src/enum_glob_use.rs @@ -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"); + } } } } diff --git a/tests/compile-test.rs b/tests/compile-test.rs index 92d2671eaa7..822d9339ba3 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -21,5 +21,6 @@ fn run_mode(mode: &'static str) { #[test] fn compile_test() { + run_mode("run-pass"); run_mode("compile-fail"); } diff --git a/tests/run-pass/enum-glob-import-crate.rs b/tests/run-pass/enum-glob-import-crate.rs new file mode 100644 index 00000000000..5b54698605a --- /dev/null +++ b/tests/run-pass/enum-glob-import-crate.rs @@ -0,0 +1,7 @@ +#![feature(plugin)] +#![plugin(clippy)] +#![deny(clippy)] + +use std::*; + +fn main() { }