From 68c0ced41604913545cf4108e090e0c5d7272e26 Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 23 May 2019 22:56:31 +0100 Subject: [PATCH] Add test for #[must_use] in tuples --- src/librustc_lint/unused.rs | 4 ++-- src/test/ui/lint/must_use-tuple.rs | 5 +++++ src/test/ui/lint/must_use-tuple.stderr | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/lint/must_use-tuple.rs create mode 100644 src/test/ui/lint/must_use-tuple.stderr diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index a1a61a9b1bf42..2567018134e35 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -1,7 +1,7 @@ use rustc::hir::def::{Res, DefKind}; use rustc::hir::def_id::DefId; use rustc::lint; -use rustc::ty; +use rustc::ty::{self, Ty}; use rustc::ty::adjustment; use rustc_data_structures::fx::FxHashMap; use lint::{LateContext, EarlyContext, LintContext, LintArray}; @@ -137,7 +137,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults { // Returns whether an error has been emitted (and thus another does not need to be later). fn check_must_use_ty( cx: &LateContext<'_, '_>, - ty: ty::Ty<'_>, + ty: Ty<'_>, span: Span, ) -> bool { match ty.sty { diff --git a/src/test/ui/lint/must_use-tuple.rs b/src/test/ui/lint/must_use-tuple.rs new file mode 100644 index 0000000000000..bc972d7ffc391 --- /dev/null +++ b/src/test/ui/lint/must_use-tuple.rs @@ -0,0 +1,5 @@ +#![deny(unused_must_use)] + +fn main() { + (Ok::<(), ()>(()),); //~ ERROR unused `std::result::Result` that must be used +} diff --git a/src/test/ui/lint/must_use-tuple.stderr b/src/test/ui/lint/must_use-tuple.stderr new file mode 100644 index 0000000000000..67d1ec01966f9 --- /dev/null +++ b/src/test/ui/lint/must_use-tuple.stderr @@ -0,0 +1,15 @@ +error: unused `std::result::Result` that must be used + --> $DIR/must_use-tuple.rs:4:5 + | +LL | (Ok::<(), ()>(()),); + | ^^^^^^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/must_use-tuple.rs:1:9 + | +LL | #![deny(unused_must_use)] + | ^^^^^^^^^^^^^^^ + = note: this `Result` may be an `Err` variant, which should be handled + +error: aborting due to previous error +