Skip to content

Commit a5e568b

Browse files
committed
Auto merge of #4551 - mikerite:fix-ice-reporting, r=llogiq
Fix ice reporting changelog: none
2 parents 535bc1d + 16ce071 commit a5e568b

13 files changed

+90
-63
lines changed

clippy_lints/src/drop_forget_ref.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{is_copy, match_def_path, paths, span_note_and_lint};
1+
use crate::utils::{is_copy, match_def_path, paths, qpath_res, span_note_and_lint};
22
use if_chain::if_chain;
33
use rustc::hir::*;
44
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@@ -114,7 +114,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropForgetRef {
114114
if let ExprKind::Call(ref path, ref args) = expr.node;
115115
if let ExprKind::Path(ref qpath) = path.node;
116116
if args.len() == 1;
117-
if let Some(def_id) = cx.tables.qpath_res(qpath, path.hir_id).opt_def_id();
117+
if let Some(def_id) = qpath_res(cx, qpath, path.hir_id).opt_def_id();
118118
then {
119119
let lint;
120120
let msg;

clippy_lints/src/functions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::convert::TryFrom;
22

3-
use crate::utils::{iter_input_pats, snippet, snippet_opt, span_lint, type_is_unsafe_function};
3+
use crate::utils::{iter_input_pats, qpath_res, snippet, snippet_opt, span_lint, type_is_unsafe_function};
44
use matches::matches;
55
use rustc::hir;
66
use rustc::hir::def::Res;
@@ -318,7 +318,7 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> {
318318
impl<'a, 'tcx> DerefVisitor<'a, 'tcx> {
319319
fn check_arg(&self, ptr: &hir::Expr) {
320320
if let hir::ExprKind::Path(ref qpath) = ptr.node {
321-
if let Res::Local(id) = self.cx.tables.qpath_res(qpath, ptr.hir_id) {
321+
if let Res::Local(id) = qpath_res(self.cx, qpath, ptr.hir_id) {
322322
if self.ptrs.contains(&id) {
323323
span_lint(
324324
self.cx,

clippy_lints/src/let_if_seq.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{higher, snippet, span_lint_and_then};
1+
use crate::utils::{higher, qpath_res, snippet, span_lint_and_then};
22
use if_chain::if_chain;
33
use rustc::hir;
44
use rustc::hir::def::Res;
@@ -145,7 +145,7 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UsedVisitor<'a, 'tcx> {
145145
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
146146
if_chain! {
147147
if let hir::ExprKind::Path(ref qpath) = expr.node;
148-
if let Res::Local(local_id) = self.cx.tables.qpath_res(qpath, expr.hir_id);
148+
if let Res::Local(local_id) = qpath_res(self.cx, qpath, expr.hir_id);
149149
if self.id == local_id;
150150
then {
151151
self.used = true;
@@ -170,7 +170,7 @@ fn check_assign<'a, 'tcx>(
170170
if let hir::StmtKind::Semi(ref expr) = expr.node;
171171
if let hir::ExprKind::Assign(ref var, ref value) = expr.node;
172172
if let hir::ExprKind::Path(ref qpath) = var.node;
173-
if let Res::Local(local_id) = cx.tables.qpath_res(qpath, var.hir_id);
173+
if let Res::Local(local_id) = qpath_res(cx, qpath, var.hir_id);
174174
if decl == local_id;
175175
then {
176176
let mut v = UsedVisitor {

clippy_lints/src/loops.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc::{declare_lint_pass, declare_tool_lint};
1111
// use rustc::middle::region::CodeExtent;
1212
use crate::consts::{constant, Constant};
1313
use crate::utils::usage::mutated_variables;
14-
use crate::utils::{is_type_diagnostic_item, sext, sugg};
14+
use crate::utils::{is_type_diagnostic_item, qpath_res, sext, sugg};
1515
use rustc::middle::expr_use_visitor::*;
1616
use rustc::middle::mem_categorization::cmt_;
1717
use rustc::middle::mem_categorization::Categorization;
@@ -754,7 +754,7 @@ fn same_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: HirId) -> bo
754754
if let ExprKind::Path(ref qpath) = expr.node;
755755
if let QPath::Resolved(None, ref path) = *qpath;
756756
if path.segments.len() == 1;
757-
if let Res::Local(local_id) = cx.tables.qpath_res(qpath, expr.hir_id);
757+
if let Res::Local(local_id) = qpath_res(cx, qpath, expr.hir_id);
758758
// our variable!
759759
if local_id == var;
760760
then {
@@ -1618,7 +1618,7 @@ fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr) -> Option<HirId>
16181618
if let ExprKind::Path(ref qpath) = bound.node;
16191619
if let QPath::Resolved(None, _) = *qpath;
16201620
then {
1621-
let res = cx.tables.qpath_res(qpath, bound.hir_id);
1621+
let res = qpath_res(cx, qpath, bound.hir_id);
16221622
if let Res::Local(node_id) = res {
16231623
let node_str = cx.tcx.hir().get(node_id);
16241624
if_chain! {
@@ -1762,7 +1762,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
17621762
if self.prefer_mutable {
17631763
self.indexed_mut.insert(seqvar.segments[0].ident.name);
17641764
}
1765-
let res = self.cx.tables.qpath_res(seqpath, seqexpr.hir_id);
1765+
let res = qpath_res(self.cx, seqpath, seqexpr.hir_id);
17661766
match res {
17671767
Res::Local(hir_id) => {
17681768
let parent_id = self.cx.tcx.hir().get_parent_item(expr.hir_id);
@@ -1824,7 +1824,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
18241824
if let QPath::Resolved(None, ref path) = *qpath;
18251825
if path.segments.len() == 1;
18261826
then {
1827-
if let Res::Local(local_id) = self.cx.tables.qpath_res(qpath, expr.hir_id) {
1827+
if let Res::Local(local_id) = qpath_res(self.cx, qpath, expr.hir_id) {
18281828
if local_id == self.var {
18291829
self.nonindex = true;
18301830
} else {
@@ -2163,7 +2163,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
21632163

21642164
fn var_def_id(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<HirId> {
21652165
if let ExprKind::Path(ref qpath) = expr.node {
2166-
let path_res = cx.tables.qpath_res(qpath, expr.hir_id);
2166+
let path_res = qpath_res(cx, qpath, expr.hir_id);
21672167
if let Res::Local(node_id) = path_res {
21682168
return Some(node_id);
21692169
}
@@ -2355,7 +2355,7 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> {
23552355
if_chain! {
23562356
if let ExprKind::Path(ref qpath) = ex.node;
23572357
if let QPath::Resolved(None, _) = *qpath;
2358-
let res = self.cx.tables.qpath_res(qpath, ex.hir_id);
2358+
let res = qpath_res(self.cx, qpath, ex.hir_id);
23592359
then {
23602360
match res {
23612361
Res::Local(node_id) => {

clippy_lints/src/mem_forget.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{match_def_path, paths, span_lint};
1+
use crate::utils::{match_def_path, paths, qpath_res, span_lint};
22
use rustc::hir::{Expr, ExprKind};
33
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
44
use rustc::{declare_lint_pass, declare_tool_lint};
@@ -29,7 +29,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemForget {
2929
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
3030
if let ExprKind::Call(ref path_expr, ref args) = e.node {
3131
if let ExprKind::Path(ref qpath) = path_expr.node {
32-
if let Some(def_id) = cx.tables.qpath_res(qpath, path_expr.hir_id).opt_def_id() {
32+
if let Some(def_id) = qpath_res(cx, qpath, path_expr.hir_id).opt_def_id() {
3333
if match_def_path(cx, def_id, &paths::MEM_FORGET) {
3434
let forgot_ty = cx.tables.expr_ty(&args[0]);
3535

clippy_lints/src/no_effect.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{has_drop, snippet_opt, span_lint, span_lint_and_sugg};
1+
use crate::utils::{has_drop, qpath_res, snippet_opt, span_lint, span_lint_and_sugg};
22
use rustc::hir::def::{DefKind, Res};
33
use rustc::hir::{BinOpKind, BlockCheckMode, Expr, ExprKind, Stmt, StmtKind, UnsafeSource};
44
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@@ -67,7 +67,7 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
6767
},
6868
ExprKind::Call(ref callee, ref args) => {
6969
if let ExprKind::Path(ref qpath) = callee.node {
70-
let res = cx.tables.qpath_res(qpath, callee.hir_id);
70+
let res = qpath_res(cx, qpath, callee.hir_id);
7171
match res {
7272
Res::Def(DefKind::Struct, ..) | Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(..), _) => {
7373
!has_drop(cx, cx.tables.expr_ty(expr)) && args.iter().all(|arg| has_no_effect(cx, arg))
@@ -145,7 +145,7 @@ fn reduce_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr) -> Option<Vec
145145
},
146146
ExprKind::Call(ref callee, ref args) => {
147147
if let ExprKind::Path(ref qpath) = callee.node {
148-
let res = cx.tables.qpath_res(qpath, callee.hir_id);
148+
let res = qpath_res(cx, qpath, callee.hir_id);
149149
match res {
150150
Res::Def(DefKind::Struct, ..) | Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(..), _)
151151
if !has_drop(cx, cx.tables.expr_ty(expr)) =>

clippy_lints/src/non_copy_const.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_errors::Applicability;
1414
use rustc_typeck::hir_ty_to_ty;
1515
use syntax_pos::{InnerSpan, Span, DUMMY_SP};
1616

17-
use crate::utils::{in_constant, is_copy, span_lint_and_then};
17+
use crate::utils::{in_constant, is_copy, qpath_res, span_lint_and_then};
1818

1919
declare_clippy_lint! {
2020
/// **What it does:** Checks for declaration of `const` items which is interior
@@ -195,7 +195,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst {
195195
}
196196

197197
// Make sure it is a const item.
198-
match cx.tables.qpath_res(qpath, expr.hir_id) {
198+
match qpath_res(cx, qpath, expr.hir_id) {
199199
Res::Def(DefKind::Const, _) | Res::Def(DefKind::AssocConst, _) => {},
200200
_ => return,
201201
};

clippy_lints/src/types.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::consts::{constant, Constant};
2424
use crate::utils::paths;
2525
use crate::utils::{
2626
clip, comparisons, differing_macro_contexts, higher, in_constant, int_bits, last_path_segment, match_def_path,
27-
match_path, multispan_sugg, same_tys, sext, snippet, snippet_opt, snippet_with_applicability,
27+
match_path, multispan_sugg, qpath_res, same_tys, sext, snippet, snippet_opt, snippet_with_applicability,
2828
snippet_with_macro_callsite, span_help_and_lint, span_lint, span_lint_and_sugg, span_lint_and_then, unsext,
2929
};
3030

@@ -218,7 +218,7 @@ fn match_type_parameter(cx: &LateContext<'_, '_>, qpath: &QPath, path: &[&str])
218218
_ => None,
219219
});
220220
if let TyKind::Path(ref qpath) = ty.node;
221-
if let Some(did) = cx.tables.qpath_res(qpath, ty.hir_id).opt_def_id();
221+
if let Some(did) = qpath_res(cx, qpath, ty.hir_id).opt_def_id();
222222
if match_def_path(cx, did, path);
223223
then {
224224
return true;
@@ -240,7 +240,7 @@ fn check_ty(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool) {
240240
match hir_ty.node {
241241
TyKind::Path(ref qpath) if !is_local => {
242242
let hir_id = hir_ty.hir_id;
243-
let res = cx.tables.qpath_res(qpath, hir_id);
243+
let res = qpath_res(cx, qpath, hir_id);
244244
if let Some(def_id) = res.opt_def_id() {
245245
if Some(def_id) == cx.tcx.lang_items().owned_box() {
246246
if match_type_parameter(cx, qpath, &paths::VEC) {
@@ -263,7 +263,7 @@ fn check_ty(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool) {
263263
});
264264
// ty is now _ at this point
265265
if let TyKind::Path(ref ty_qpath) = ty.node;
266-
let res = cx.tables.qpath_res(ty_qpath, ty.hir_id);
266+
let res = qpath_res(cx, ty_qpath, ty.hir_id);
267267
if let Some(def_id) = res.opt_def_id();
268268
if Some(def_id) == cx.tcx.lang_items().owned_box();
269269
// At this point, we know ty is Box<T>, now get T
@@ -369,7 +369,7 @@ fn check_ty_rptr(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool, lt:
369369
match mut_ty.ty.node {
370370
TyKind::Path(ref qpath) => {
371371
let hir_id = mut_ty.ty.hir_id;
372-
let def = cx.tables.qpath_res(qpath, hir_id);
372+
let def = qpath_res(cx, qpath, hir_id);
373373
if_chain! {
374374
if let Some(def_id) = def.opt_def_id();
375375
if Some(def_id) == cx.tcx.lang_items().owned_box();

clippy_lints/src/utils/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,19 @@ pub fn path_to_res(cx: &LateContext<'_, '_>, path: &[&str]) -> Option<(def::Res)
273273
}
274274
}
275275

276+
pub fn qpath_res(cx: &LateContext<'_, '_>, qpath: &hir::QPath, id: hir::HirId) -> Res {
277+
match qpath {
278+
hir::QPath::Resolved(_, path) => path.res,
279+
hir::QPath::TypeRelative(..) => {
280+
if cx.tcx.has_typeck_tables(id.owner_def_id()) {
281+
cx.tcx.typeck_tables_of(id.owner_def_id()).qpath_res(qpath, id)
282+
} else {
283+
Res::Err
284+
}
285+
},
286+
}
287+
}
288+
276289
/// Convenience function to get the `DefId` of a trait by path.
277290
/// It could be a trait or trait alias.
278291
pub fn get_trait_def_id(cx: &LateContext<'_, '_>, path: &[&str]) -> Option<DefId> {

src/driver.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,9 @@ You can use tool lints to allow or deny lints from your code, eg.:
247247

248248
pub fn main() {
249249
rustc_driver::init_rustc_env_logger();
250+
rustc_driver::install_ice_hook();
250251
exit(
251-
rustc_driver::report_ices_to_stderr_if_any(move || {
252+
rustc_driver::catch_fatal_errors(move || {
252253
use std::env;
253254

254255
if std::env::args().any(|a| a == "--version" || a == "-V") {

tests/ui/ice-4545.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
fn repro() {
2+
trait Foo {
3+
type Bar;
4+
}
5+
6+
#[allow(dead_code)]
7+
struct Baz<T: Foo> {
8+
field: T::Bar,
9+
}
10+
}
11+
12+
fn main() {
13+
repro();
14+
}

tests/ui/non_copy_const.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(const_string_new, const_vec_new)]
21
#![allow(clippy::ref_in_deref, dead_code)]
32

43
use std::borrow::Cow;

0 commit comments

Comments
 (0)