Skip to content

Commit c659fab

Browse files
committed
in which the fn-must-use codepath is prevented from panicking on closure
The must-use lint needs the DefId of called functions and method receivers in order to look for a `#[must_use]` attribute, but this would ICE (!) if a called function was actually a closure (with a non-unit return value). Instead, let's be specific that we want a `Def::Fn`, rather than blithely assuming that we can get the DefId of a qpath. Supporting must-use closures doesn't seem like a priority, but could conceivably be added in the future if desired (conditional on the statement and expression attributes (#15701) story being amicable).
1 parent f4c1f0c commit c659fab

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/librustc_lint/unused.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use rustc::hir::def::Def;
1112
use rustc::hir::def_id::DefId;
1213
use rustc::ty;
1314
use rustc::ty::adjustment;
@@ -77,7 +78,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
7778
hir::ExprCall(ref callee, _) => {
7879
match callee.node {
7980
hir::ExprPath(ref qpath) => {
80-
Some(cx.tables.qpath_def(qpath, callee.hir_id))
81+
let def = cx.tables.qpath_def(qpath, callee.hir_id);
82+
if let Def::Fn(_) = def {
83+
Some(def)
84+
} else { // `Def::Local` if it was a closure, for which we
85+
None // do not currently support must-use linting
86+
}
8187
},
8288
_ => None
8389
}

0 commit comments

Comments
 (0)