|
8 | 8 | // option. This file may not be copied, modified, or distributed
|
9 | 9 | // except according to those terms.
|
10 | 10 |
|
| 11 | +use rustc::hir::def_id::DefId; |
11 | 12 | use rustc::ty;
|
12 | 13 | use rustc::ty::adjustment;
|
13 | 14 | use util::nodemap::FxHashMap;
|
@@ -144,20 +145,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
|
144 | 145 | ty::TyTuple(ref tys, _) if tys.is_empty() => return,
|
145 | 146 | ty::TyNever => return,
|
146 | 147 | ty::TyBool => return,
|
147 |
| - ty::TyAdt(def, _) => { |
148 |
| - let attrs = cx.tcx.get_attrs(def.did); |
149 |
| - check_must_use(cx, &attrs, s.span) |
150 |
| - } |
| 148 | + ty::TyAdt(def, _) => check_must_use(cx, def.did, s.span), |
151 | 149 | _ => false,
|
152 | 150 | };
|
153 | 151 | if !warned {
|
154 | 152 | cx.span_lint(UNUSED_RESULTS, s.span, "unused result");
|
155 | 153 | }
|
156 | 154 |
|
157 |
| - fn check_must_use(cx: &LateContext, attrs: &[ast::Attribute], sp: Span) -> bool { |
158 |
| - for attr in attrs { |
| 155 | + fn check_must_use(cx: &LateContext, def_id: DefId, sp: Span) -> bool { |
| 156 | + for attr in cx.tcx.get_attrs(def_id).iter() { |
159 | 157 | if attr.check_name("must_use") {
|
160 |
| - let mut msg = "unused result which must be used".to_string(); |
| 158 | + let mut msg = format!("unused `{}` which must be used", |
| 159 | + cx.tcx.item_path_str(def_id)); |
161 | 160 | // check for #[must_use="..."]
|
162 | 161 | if let Some(s) = attr.value_str() {
|
163 | 162 | msg.push_str(": ");
|
|
0 commit comments