diff options
| author | Zack M. Davis <code@zackmdavis.net> | 2018-03-10 14:26:33 -0800 |
|---|---|---|
| committer | Zack M. Davis <code@zackmdavis.net> | 2018-04-28 20:32:49 -0700 |
| commit | c659faba8d8a7e21eeddbf446c9101bb945e9f0c (patch) | |
| tree | 2098b56611e6f0314e9e820cedde61025416ed0d /src | |
| parent | f4c1f0ce93137049bd6c25d3289bf12bfc00426d (diff) | |
| download | rust-c659faba8d8a7e21eeddbf446c9101bb945e9f0c.tar.gz rust-c659faba8d8a7e21eeddbf446c9101bb945e9f0c.zip | |
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).
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_lint/unused.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index 5ec8305de78..c32e9cdce0e 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use rustc::hir::def::Def; use rustc::hir::def_id::DefId; use rustc::ty; use rustc::ty::adjustment; @@ -77,7 +78,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults { hir::ExprCall(ref callee, _) => { match callee.node { hir::ExprPath(ref qpath) => { - Some(cx.tables.qpath_def(qpath, callee.hir_id)) + let def = cx.tables.qpath_def(qpath, callee.hir_id); + if let Def::Fn(_) = def { + Some(def) + } else { // `Def::Local` if it was a closure, for which we + None // do not currently support must-use linting + } }, _ => None } |
