diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2025-06-22 17:35:34 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-22 17:35:34 +0200 |
| commit | 2681bb095206433ba6f6d32757281a55809059a2 (patch) | |
| tree | 0d834a10aaab53ece9c7deb9e097dfcfaac9eccb /compiler/rustc_lint | |
| parent | a9a0753e96de8a7b4651d15bed2730725f69ae8b (diff) | |
| parent | b24df424888d9db3a22d6d52f3f516e29d5be21a (diff) | |
| download | rust-2681bb095206433ba6f6d32757281a55809059a2.tar.gz rust-2681bb095206433ba6f6d32757281a55809059a2.zip | |
Rollup merge of #142780 - JonathanBrouwer:must_use_new_attr, r=jdonszelmann
Port `#[must_use]` to new attribute parsing infrastructure Ports `must_use` to the new attribute parsing infrastructure for https://github.com/rust-lang/rust/issues/131229#issuecomment-2971353197 r? `@jdonszelmann`
Diffstat (limited to 'compiler/rustc_lint')
| -rw-r--r-- | compiler/rustc_lint/src/unused.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 1620f425794..a868c887493 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -2,6 +2,7 @@ use std::iter; use rustc_ast::util::{classify, parser}; use rustc_ast::{self as ast, ExprKind, HasAttrs as _, StmtKind}; +use rustc_attr_data_structures::{AttributeKind, find_attr}; use rustc_errors::{MultiSpan, pluralize}; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; @@ -368,10 +369,12 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { } fn is_def_must_use(cx: &LateContext<'_>, def_id: DefId, span: Span) -> Option<MustUsePath> { - if let Some(attr) = cx.tcx.get_attr(def_id, sym::must_use) { + if let Some(reason) = find_attr!( + cx.tcx.get_all_attrs(def_id), + AttributeKind::MustUse { reason, .. } => reason + ) { // check for #[must_use = "..."] - let reason = attr.value_str(); - Some(MustUsePath::Def(span, def_id, reason)) + Some(MustUsePath::Def(span, def_id, *reason)) } else { None } |
