You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: standard/attributes.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1258,6 +1258,10 @@ It is an error to use `[UnscopedRef]` on
1258
1258
1259
1259
See §scoped-modifier for more information.
1260
1260
1261
+
### §ScopedRefAttribute The ScopedRef attribute
1262
+
1263
+
The name `System.Runtime.CompilerServices.ScopedRefAttribute` is reserved for compiler use. The compiler emits this attribute on a parameter when the parameter's `scoped` annotation differs from its default state, in order to encode the `scoped` modifier (§scoped-modifier) in metadata. This attribute is not permitted in source.
1264
+
1261
1265
### 23.5.8 The EnumeratorCancellation attribute
1262
1266
1263
1267
Specifies the parameter representing the `CancellationToken` for an asynchronous iterator ([§15.15](classes.md#1515-synchronous-and-asynchronous-iterators)). The argument for this parameter shall be combined with the argument passed to `IAsyncEnumerable<T>.GetAsyncEnumerator(CancellationToken)`. This combined token shall be polled by `IAsyncEnumerator<T>.MoveNextAsync()` ([§15.15.5.2](classes.md#151552-advance-the-enumerator)). The tokens shall be combined into a single token as if by `CancellationToken.CreateLinkedTokenSource` and its `Token` property. The combined token will be canceled if either of the two source tokens are canceled. The combined token is seen as the argument to the asynchronous iterator method ([§15.15](classes.md#1515-synchronous-and-asynchronous-iterators)) in the body of that method.
Copy file name to clipboardExpand all lines: standard/classes.md
+9-1Lines changed: 9 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1715,6 +1715,8 @@ The value of a field is obtained in an expression using a *simple_name* ([§12.8
1715
1715
1716
1716
A field declaration that declares multiple fields is equivalent to multiple declarations of single fields with the same attributes, modifiers, and type.
1717
1717
1718
+
> *Note*: Inside a `ref struct`, a field may also be declared as a reference variable; see §Ref-Fields. *end note*
Aparameterdeclaredwitha `ref` modifierisa ***referenceparameter***. Fordefinite-assignmentrules, see [§9.2.6](variables.md#926-reference-parameters).
@@ -2437,14 +2441,18 @@ A parameter declared with a `ref` modifier is a ***reference parameter***. For d
2437
2441
>
2438
2442
> *end example*
2439
2443
2440
-
For a `struct` type, within an instance method, instance accessor ([§12.2.1](expressions.md#1221-general)), orinstanceconstructorwithaconstructorinitializer, the `this` keywordbehavesexactlyasareferenceparameterofthestructtype ([§12.8.14](expressions.md#12814-this-access)).
2444
+
For a `struct` type, within an instance method, instance accessor ([§12.2.1](expressions.md#1221-general)), orinstanceconstructorwithaconstructorinitializer, the `this` keywordbehavesexactlyasareferenceparameterofthestructtype ([§12.8.14](expressions.md#12814-this-access)). The `this` parameter of a struct instance method is implicitly `scoped ref` (§scoped-modifier).
2445
+
2446
+
A reference parameter may carry the `scoped` modifier (§scoped-modifier) or the `[UnscopedRef]` attribute (§UnscopedRefAttribute).
2441
2447
2442
2448
##### 15.6.2.3.4 Output parameters
2443
2449
2444
2450
A parameter declared with an `out` modifier is an ***output parameter***. For definite-assignment rules, see [§9.2.7](variables.md#927-output-parameters).
2445
2451
2446
2452
A method declared as an optional partial method ([§15.6.9.2](classes.md#15692-optional-partial-methods)) shall not have output parameters.
2447
2453
2454
+
An output parameter is implicitly `scoped` (§scoped-modifier); the `[UnscopedRef]` attribute (§UnscopedRefAttribute) maybeappliedtowidenitsref-safe-context.
>// Without `scoped`, the safe-context of `s` would be caller-context
1512
+
>// because the right-hand side has safe-context of caller-context.
1513
+
>// The `scoped` modifier forces the safe-context to function-member,
1514
+
>// so `s` cannot be returned.
1515
+
>scopedSpan<int>s=default;
1516
+
>returns; // Error: s has safe-context of function-member
1517
+
> }
1518
+
> }
1519
+
> ```
1520
+
>
1521
+
>*endexample*
1522
+
1523
+
>*Example*:Thefollowingillustrateshow `scopedref` onaparameterpreventstheparameterfrombeingcapturedbyaconstructed `ref struct` value that the method returns:
The `scoped` modifier (§scoped-modifier) and `[UnscopedRef]` attribute (§UnscopedRefAttribute) on parameters affect overriding, interface implementation, and `delegate` conversion. The signature for an override, interface implementation, or `delegate` conversion may:
0 commit comments