Skip to content

Commit

Permalink
Rollup merge of rust-lang#42756 - sanxiyn:name-for-must-use, r=estebank
Browse files Browse the repository at this point in the history
Show type name for unused_must_use lint

Fix rust-lang#42688.
  • Loading branch information
frewsxcv authored Jun 20, 2017
2 parents d3e116a + 05540bf commit f9edbcc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
13 changes: 6 additions & 7 deletions src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use rustc::hir::def_id::DefId;
use rustc::ty;
use rustc::ty::adjustment;
use util::nodemap::FxHashMap;
Expand Down Expand Up @@ -144,20 +145,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
ty::TyTuple(ref tys, _) if tys.is_empty() => return,
ty::TyNever => return,
ty::TyBool => return,
ty::TyAdt(def, _) => {
let attrs = cx.tcx.get_attrs(def.did);
check_must_use(cx, &attrs, s.span)
}
ty::TyAdt(def, _) => check_must_use(cx, def.did, s.span),
_ => false,
};
if !warned {
cx.span_lint(UNUSED_RESULTS, s.span, "unused result");
}

fn check_must_use(cx: &LateContext, attrs: &[ast::Attribute], sp: Span) -> bool {
for attr in attrs {
fn check_must_use(cx: &LateContext, def_id: DefId, sp: Span) -> bool {
for attr in cx.tcx.get_attrs(def_id).iter() {
if attr.check_name("must_use") {
let mut msg = "unused result which must be used".to_string();
let mut msg = format!("unused `{}` which must be used",
cx.tcx.item_path_str(def_id));
// check for #[must_use="..."]
if let Some(s) = attr.value_str() {
msg.push_str(": ");
Expand Down
8 changes: 4 additions & 4 deletions src/test/compile-fail/unused-result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ fn qux() -> MustUseMsg { return foo::<MustUseMsg>(); }
#[allow(unused_results)]
fn test() {
foo::<isize>();
foo::<MustUse>(); //~ ERROR: unused result which must be used
foo::<MustUseMsg>(); //~ ERROR: unused result which must be used: some message
foo::<MustUse>(); //~ ERROR: unused `MustUse` which must be used
foo::<MustUseMsg>(); //~ ERROR: unused `MustUseMsg` which must be used: some message
}

#[allow(unused_results, unused_must_use)]
Expand All @@ -39,8 +39,8 @@ fn test2() {

fn main() {
foo::<isize>(); //~ ERROR: unused result
foo::<MustUse>(); //~ ERROR: unused result which must be used
foo::<MustUseMsg>(); //~ ERROR: unused result which must be used: some message
foo::<MustUse>(); //~ ERROR: unused `MustUse` which must be used
foo::<MustUseMsg>(); //~ ERROR: unused `MustUseMsg` which must be used: some message

let _ = foo::<isize>();
let _ = foo::<MustUse>();
Expand Down

0 comments on commit f9edbcc

Please sign in to comment.