Skip to content

Commit 2271376

Browse files
committed
must_not_suspend impl
1 parent 5d2a410 commit 2271376

File tree

19 files changed

+587
-5
lines changed

19 files changed

+587
-5
lines changed

compiler/rustc_feature/src/active.rs

+4
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,10 @@ declare_features! (
679679
/// Allows `let...else` statements.
680680
(active, let_else, "1.56.0", Some(87335), None),
681681

682+
/// Allows `#[must_not_suspend]`.
683+
(active, must_not_suspend, "1.56.0", Some(83310), None),
684+
685+
682686
// -------------------------------------------------------------------------
683687
// feature-group-end: actual feature gates
684688
// -------------------------------------------------------------------------

compiler/rustc_feature/src/builtin_attrs.rs

+4
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
202202
ungated!(forbid, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)),
203203
ungated!(deny, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)),
204204
ungated!(must_use, Normal, template!(Word, NameValueStr: "reason")),
205+
gated!(
206+
must_not_suspend, Normal, template!(Word, NameValueStr: "reason"), must_not_suspend,
207+
experimental!(must_not_suspend)
208+
),
205209
// FIXME(#14407)
206210
ungated!(
207211
deprecated, Normal,

compiler/rustc_lint/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
298298
UNUSED_LABELS,
299299
UNUSED_PARENS,
300300
UNUSED_BRACES,
301+
MUST_NOT_SUSPEND,
301302
REDUNDANT_SEMICOLONS
302303
);
303304

compiler/rustc_lint_defs/src/builtin.rs

+8
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,13 @@ declare_lint! {
314314
"imports that are never used"
315315
}
316316

317+
declare_lint! {
318+
/// [the reference]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute
319+
pub MUST_NOT_SUSPEND,
320+
Warn,
321+
"Use of a `#[must_not_suspend]` value across a yield point",
322+
}
323+
317324
declare_lint! {
318325
/// The `unused_extern_crates` lint guards against `extern crate` items
319326
/// that are never used.
@@ -2993,6 +3000,7 @@ declare_lint_pass! {
29933000
CENUM_IMPL_DROP_CAST,
29943001
CONST_EVALUATABLE_UNCHECKED,
29953002
INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
3003+
MUST_NOT_SUSPEND,
29963004
UNINHABITED_STATIC,
29973005
FUNCTION_ITEM_REFERENCES,
29983006
USELESS_DEPRECATED,

compiler/rustc_passes/src/check_attr.rs

+16
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ impl CheckAttrVisitor<'tcx> {
104104
sym::default_method_body_is_const => {
105105
self.check_default_method_body_is_const(attr, span, target)
106106
}
107+
sym::must_not_suspend => self.check_must_not_suspend(&attr, span, target),
107108
sym::rustc_const_unstable
108109
| sym::rustc_const_stable
109110
| sym::unstable
@@ -1014,6 +1015,21 @@ impl CheckAttrVisitor<'tcx> {
10141015
is_valid
10151016
}
10161017

1018+
/// Checks if `#[must_not_suspend]` is applied to a function. Returns `true` if valid.
1019+
fn check_must_not_suspend(&self, attr: &Attribute, span: &Span, target: Target) -> bool {
1020+
match target {
1021+
Target::Fn | Target::Method(..) | Target::ForeignFn | Target::Closure => {
1022+
self.tcx
1023+
.sess
1024+
.struct_span_err(attr.span, "`must_not_suspend` attribute should be applied to a struct, enum, `impl Trait`, or `dyn Trait`")
1025+
.span_label(*span, "is a function")
1026+
.emit();
1027+
false
1028+
}
1029+
_ => true,
1030+
}
1031+
}
1032+
10171033
/// Checks if `#[cold]` is applied to a non-function. Returns `true` if valid.
10181034
fn check_cold(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
10191035
match target {

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,7 @@ symbols! {
836836
mul,
837837
mul_assign,
838838
mul_with_overflow,
839+
must_not_suspend,
839840
must_use,
840841
mut_ptr,
841842
mut_slice_ptr,

0 commit comments

Comments
 (0)