Skip to content

Commit 3344a15

Browse files
authored
Unrolled build for #150943
Rollup merge of #150943 - port_must_not_suspend, r=jdonszelmann,JonathanBrouwer Port `#[must_not_suspend]` to attribute parser Tracking issue: #131229 r? @JonathanBrouwer
2 parents b2a322b + 418cff3 commit 3344a15

File tree

15 files changed

+77
-61
lines changed

15 files changed

+77
-61
lines changed

‎compiler/rustc_attr_parsing/src/attributes/mod.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub(crate) mod link_attrs;
4747
pub(crate) mod lint_helpers;
4848
pub(crate) mod loop_match;
4949
pub(crate) mod macro_attrs;
50+
pub(crate) mod must_not_suspend;
5051
pub(crate) mod must_use;
5152
pub(crate) mod no_implicit_prelude;
5253
pub(crate) mod no_link;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use super::prelude::*;
2+
3+
pub(crate) struct MustNotSuspendParser;
4+
5+
impl<S: Stage> SingleAttributeParser<S> for MustNotSuspendParser {
6+
const PATH: &[rustc_span::Symbol] = &[sym::must_not_suspend];
7+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
8+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
9+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
10+
Allow(Target::Struct),
11+
Allow(Target::Enum),
12+
Allow(Target::Union),
13+
Allow(Target::Trait),
14+
]);
15+
const TEMPLATE: AttributeTemplate = template!(Word, List: &["count"]);
16+
17+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
18+
let reason = match args {
19+
ArgParser::NameValue(reason) => match reason.value_as_str() {
20+
Some(val) => Some(val),
21+
None => {
22+
cx.expected_nv_or_no_args(reason.value_span);
23+
return None;
24+
}
25+
},
26+
ArgParser::NoArgs => None,
27+
ArgParser::List(list) => {
28+
cx.expected_nv_or_no_args(list.span);
29+
return None;
30+
}
31+
};
32+
33+
Some(AttributeKind::MustNotSupend { reason })
34+
}
35+
}

‎compiler/rustc_attr_parsing/src/context.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ use crate::attributes::macro_attrs::{
5151
AllowInternalUnsafeParser, CollapseDebugInfoParser, MacroEscapeParser, MacroExportParser,
5252
MacroUseParser,
5353
};
54+
use crate::attributes::must_not_suspend::MustNotSuspendParser;
5455
use crate::attributes::must_use::MustUseParser;
5556
use crate::attributes::no_implicit_prelude::NoImplicitPreludeParser;
5657
use crate::attributes::no_link::NoLinkParser;
@@ -89,7 +90,6 @@ use crate::session_diagnostics::{
8990
AttributeParseError, AttributeParseErrorReason, ParsedDescription,
9091
};
9192
use crate::target_checking::AllowedTargets;
92-
9393
type GroupType<S> = LazyLock<GroupTypeInner<S>>;
9494

9595
pub(super) struct GroupTypeInner<S: Stage> {
@@ -208,6 +208,7 @@ attribute_parsers!(
208208
Single<LinkageParser>,
209209
Single<MacroExportParser>,
210210
Single<MoveSizeLimitParser>,
211+
Single<MustNotSuspendParser>,
211212
Single<MustUseParser>,
212213
Single<ObjcClassParser>,
213214
Single<ObjcSelectorParser>,

‎compiler/rustc_hir/src/attrs/data_structures.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,9 @@ pub enum AttributeKind {
824824
/// Represents `#[move_size_limit]`
825825
MoveSizeLimit { attr_span: Span, limit_span: Span, limit: Limit },
826826

827+
/// Represents `#[must_not_suspend]`
828+
MustNotSupend { reason: Option<Symbol> },
829+
827830
/// Represents `#[must_use]`.
828831
MustUse {
829832
span: Span,

‎compiler/rustc_hir/src/attrs/encode_cross_crate.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ impl AttributeKind {
7171
Marker(..) => No,
7272
MayDangle(..) => No,
7373
MoveSizeLimit { .. } => No,
74+
MustNotSupend { .. } => Yes,
7475
MustUse { .. } => Yes,
7576
Naked(..) => No,
7677
NoCore(..) => No,

‎compiler/rustc_mir_transform/src/coroutine.rs‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ use itertools::izip;
6464
use rustc_abi::{FieldIdx, VariantIdx};
6565
use rustc_data_structures::fx::FxHashSet;
6666
use rustc_errors::pluralize;
67-
use rustc_hir as hir;
67+
use rustc_hir::attrs::AttributeKind;
6868
use rustc_hir::lang_items::LangItem;
69-
use rustc_hir::{CoroutineDesugaring, CoroutineKind};
69+
use rustc_hir::{self as hir, CoroutineDesugaring, CoroutineKind, find_attr};
7070
use rustc_index::bit_set::{BitMatrix, DenseBitSet, GrowableBitSet};
7171
use rustc_index::{Idx, IndexVec, indexvec};
7272
use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor};
@@ -85,7 +85,6 @@ use rustc_mir_dataflow::{
8585
};
8686
use rustc_span::def_id::{DefId, LocalDefId};
8787
use rustc_span::source_map::dummy_spanned;
88-
use rustc_span::symbol::sym;
8988
use rustc_span::{DUMMY_SP, Span};
9089
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
9190
use rustc_trait_selection::infer::TyCtxtInferExt as _;
@@ -1989,11 +1988,11 @@ fn check_must_not_suspend_def(
19891988
hir_id: hir::HirId,
19901989
data: SuspendCheckData<'_>,
19911990
) -> bool {
1992-
if let Some(attr) = tcx.get_attr(def_id, sym::must_not_suspend) {
1993-
let reason = attr.value_str().map(|s| errors::MustNotSuspendReason {
1994-
span: data.source_span,
1995-
reason: s.as_str().to_string(),
1996-
});
1991+
if let Some(reason_str) =
1992+
find_attr!(tcx.get_all_attrs(def_id), AttributeKind::MustNotSupend {reason} => reason)
1993+
{
1994+
let reason =
1995+
reason_str.map(|s| errors::MustNotSuspendReason { span: data.source_span, reason: s });
19971996
tcx.emit_node_span_lint(
19981997
rustc_session::lint::builtin::MUST_NOT_SUSPEND,
19991998
hir_id,

‎compiler/rustc_mir_transform/src/errors.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ impl<'a> LintDiagnostic<'a, ()> for MustNotSupend<'_, '_> {
323323
pub(crate) struct MustNotSuspendReason {
324324
#[primary_span]
325325
pub span: Span,
326-
pub reason: String,
326+
pub reason: Symbol,
327327
}
328328

329329
#[derive(Diagnostic)]

‎compiler/rustc_passes/messages.ftl‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,6 @@ passes_must_implement_not_function_note = all `#[rustc_must_implement_one_of]` a
376376
377377
passes_must_implement_not_function_span_note = required by this annotation
378378
379-
passes_must_not_suspend =
380-
`must_not_suspend` attribute should be applied to a struct, enum, union, or trait
381-
.label = is not a struct, enum, union, or trait
382-
383379
passes_no_main_function =
384380
`main` function not found in crate `{$crate_name}`
385381
.here_is_main = here is a function named `main`

‎compiler/rustc_passes/src/check_attr.rs‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
308308
| AttributeKind::ThreadLocal
309309
| AttributeKind::CfiEncoding { .. }
310310
| AttributeKind::RustcHasIncoherentInherentImpls
311+
| AttributeKind::MustNotSupend { .. }
311312
) => { /* do nothing */ }
312313
Attribute::Unparsed(attr_item) => {
313314
style = Some(attr_item.style);
@@ -325,7 +326,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
325326
| [sym::rustc_dirty, ..]
326327
| [sym::rustc_if_this_changed, ..]
327328
| [sym::rustc_then_this_would_need, ..] => self.check_rustc_dirty_clean(attr),
328-
[sym::must_not_suspend, ..] => self.check_must_not_suspend(attr, span, target),
329329
[sym::autodiff_forward, ..] | [sym::autodiff_reverse, ..] => {
330330
self.check_autodiff(hir_id, attr, span, target)
331331
}
@@ -1197,16 +1197,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
11971197
}
11981198
}
11991199

1200-
/// Checks if `#[must_not_suspend]` is applied to a struct, enum, union, or trait.
1201-
fn check_must_not_suspend(&self, attr: &Attribute, span: Span, target: Target) {
1202-
match target {
1203-
Target::Struct | Target::Enum | Target::Union | Target::Trait => {}
1204-
_ => {
1205-
self.dcx().emit_err(errors::MustNotSuspend { attr_span: attr.span(), span });
1206-
}
1207-
}
1208-
}
1209-
12101200
/// Checks if `#[may_dangle]` is applied to a lifetime or type generic parameter in `Drop` impl.
12111201
fn check_may_dangle(&self, hir_id: HirId, attr_span: Span) {
12121202
if let hir::Node::GenericParam(param) = self.tcx.hir_node(hir_id)

‎compiler/rustc_passes/src/errors.rs‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,6 @@ pub(crate) struct BothFfiConstAndPure {
194194
pub attr_span: Span,
195195
}
196196

197-
#[derive(Diagnostic)]
198-
#[diag(passes_must_not_suspend)]
199-
pub(crate) struct MustNotSuspend {
200-
#[primary_span]
201-
pub attr_span: Span,
202-
#[label]
203-
pub span: Span,
204-
}
205-
206197
#[derive(LintDiagnostic)]
207198
#[diag(passes_link)]
208199
#[warning]

0 commit comments

Comments
 (0)