Skip to content

Commit 320b94d

Browse files
committed
Auto merge of #4794 - rust-lang:no-must-use-impls, r=flip1995
no more must-use-candidate impls This should help with #4779. changelog: don't trigger [`must_use_candidate`] on trait impls
2 parents 180f870 + 5f0f673 commit 320b94d

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

clippy_lints/src/functions.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::utils::{
22
attrs::is_proc_macro, iter_input_pats, match_def_path, qpath_res, return_ty, snippet, snippet_opt,
3-
span_help_and_lint, span_lint, span_lint_and_then, type_is_unsafe_function,
3+
span_help_and_lint, span_lint, span_lint_and_then, trait_ref_of_method, type_is_unsafe_function,
44
};
55
use matches::matches;
66
use rustc::hir::{self, def::Res, def_id::DefId, intravisit};
@@ -254,7 +254,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
254254
if let Some(attr) = attr {
255255
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
256256
check_needless_must_use(cx, &sig.decl, item.hir_id, item.span, fn_header_span, attr);
257-
} else if cx.access_levels.is_exported(item.hir_id) && !is_proc_macro(&item.attrs) {
257+
} else if cx.access_levels.is_exported(item.hir_id)
258+
&& !is_proc_macro(&item.attrs)
259+
&& trait_ref_of_method(cx, item.hir_id).is_none()
260+
{
258261
check_must_use_candidate(
259262
cx,
260263
&sig.decl,

tests/ui/must_use_candidates.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub trait MyPureTrait {
2828
}
2929

3030
impl MyPureTrait for MyPure {
31-
#[must_use] fn trait_impl_pure(&self, i: u32) -> u32 {
31+
fn trait_impl_pure(&self, i: u32) -> u32 {
3232
i
3333
}
3434
}

tests/ui/must_use_candidates.stderr

+1-7
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ error: this method could have a `#[must_use]` attribute
1212
LL | pub fn inherent_pure(&self) -> u8 {
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn inherent_pure(&self) -> u8`
1414

15-
error: this method could have a `#[must_use]` attribute
16-
--> $DIR/must_use_candidates.rs:31:5
17-
|
18-
LL | fn trait_impl_pure(&self, i: u32) -> u32 {
19-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] fn trait_impl_pure(&self, i: u32) -> u32`
20-
2115
error: this function could have a `#[must_use]` attribute
2216
--> $DIR/must_use_candidates.rs:48:1
2317
|
@@ -36,5 +30,5 @@ error: this function could have a `#[must_use]` attribute
3630
LL | pub fn arcd(_x: Arc<u32>) -> bool {
3731
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn arcd(_x: Arc<u32>) -> bool`
3832

39-
error: aborting due to 6 previous errors
33+
error: aborting due to 5 previous errors
4034

0 commit comments

Comments
 (0)