Skip to content
Permalink
Browse files

Specify tuple element in lint message

  • Loading branch information...
varkor committed May 28, 2019
1 parent 77eaa48 commit d65e7d26c4acc8748a6b579852b1bd51bfe729af
Showing with 16 additions and 13 deletions.
  1. +6 −3 src/librustc_lint/unused.rs
  2. +6 −6 src/test/ui/lint/must_use-tuple.rs
  3. +4 −4 src/test/ui/lint/must_use-tuple.stderr
@@ -48,7 +48,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
}

let ty = cx.tables.expr_ty(&expr);
let type_permits_lack_of_use = check_must_use_ty(cx, ty, &expr, s.span);
let type_permits_lack_of_use = check_must_use_ty(cx, ty, &expr, s.span, "");

let mut fn_warned = false;
let mut op_warned = false;
@@ -133,6 +133,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
ty: Ty<'tcx>,
expr: &hir::Expr,
span: Span,
descr_post_path: &str,
) -> bool {
if ty.is_unit() || cx.tcx.is_ty_uninhabited_from(
cx.tcx.hir().get_module_parent_by_hir_id(expr.hir_id), ty)
@@ -141,7 +142,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
}

match ty.sty {
ty::Adt(def, _) => check_must_use_def(cx, def.did, span, "", ""),
ty::Adt(def, _) => check_must_use_def(cx, def.did, span, "", descr_post_path),
ty::Opaque(def, _) => {
let mut has_emitted = false;
for (predicate, _) in &cx.tcx.predicates_of(def).predicates {
@@ -178,7 +179,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
vec![]
};
for (i, ty) in tys.iter().map(|k| k.expect_ty()).enumerate() {
if check_must_use_ty(cx, ty, expr, *spans.get(i).unwrap_or(&span)) {
let descr_post_path = &format!(" in tuple element {}", i);
let span = *spans.get(i).unwrap_or(&span);
if check_must_use_ty(cx, ty, expr, span, descr_post_path) {
has_emitted = true;
}
}
@@ -1,15 +1,15 @@
#![deny(unused_must_use)]

fn foo() -> Result<(), ()> {
Ok::<(), ()>(())
fn foo() -> (Result<(), ()>, ()) {
(Ok::<(), ()>(()), ())
}

fn main() {
(Ok::<(), ()>(()),); //~ ERROR unused `std::result::Result` that must be used
(Ok::<(), ()>(()),); //~ ERROR unused `std::result::Result`

(Ok::<(), ()>(()), 0, Ok::<(), ()>(()), 5);
//~^ ERROR unused `std::result::Result` that must be used
//~^^ ERROR unused `std::result::Result` that must be used
//~^ ERROR unused `std::result::Result`
//~^^ ERROR unused `std::result::Result`

foo(); //~ ERROR unused `std::result::Result` that must be used
foo(); //~ ERROR unused `std::result::Result`
}
@@ -1,4 +1,4 @@
error: unused `std::result::Result` that must be used
error: unused `std::result::Result` in tuple element 0 that must be used
--> $DIR/must_use-tuple.rs:8:6
|
LL | (Ok::<(), ()>(()),);
@@ -11,23 +11,23 @@ LL | #![deny(unused_must_use)]
| ^^^^^^^^^^^^^^^
= note: this `Result` may be an `Err` variant, which should be handled

error: unused `std::result::Result` that must be used
error: unused `std::result::Result` in tuple element 0 that must be used
--> $DIR/must_use-tuple.rs:10:6
|
LL | (Ok::<(), ()>(()), 0, Ok::<(), ()>(()), 5);
| ^^^^^^^^^^^^^^^^
|
= note: this `Result` may be an `Err` variant, which should be handled

error: unused `std::result::Result` that must be used
error: unused `std::result::Result` in tuple element 2 that must be used
--> $DIR/must_use-tuple.rs:10:27
|
LL | (Ok::<(), ()>(()), 0, Ok::<(), ()>(()), 5);
| ^^^^^^^^^^^^^^^^
|
= note: this `Result` may be an `Err` variant, which should be handled

error: unused `std::result::Result` that must be used
error: unused `std::result::Result` in tuple element 0 that must be used
--> $DIR/must_use-tuple.rs:14:5
|
LL | foo();

0 comments on commit d65e7d2

Please sign in to comment.
You can’t perform that action at this time.