diff --git a/README.md b/README.md index 21ed55020c1..fd9a0bf2c9e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ # Rust RFCs +[Rust RFCs]: #rust-rfcs + +(jump forward to: [Table of Contents], [Active RFC List]) Many changes, including bug fixes and documentation improvements can be implemented and reviewed via the normal GitHub pull request workflow. @@ -12,7 +15,54 @@ consistent and controlled path for new features to enter the language and standard libraries, so that all stakeholders can be confident about the direction the language is evolving in. +## Active RFC List +[Active RFC List]: #active-rfc-list + +* [0002-rfc-process.md](text/0002-rfc-process.md) +* [0008-new-intrinsics.md](text/0008-new-intrinsics.md) +* [0016-more-attributes.md](text/0016-more-attributes.md) +* [0019-opt-in-builtin-traits.md](text/0019-opt-in-builtin-traits.md) +* [0048-traits.md](text/0048-traits.md) +* [0066-better-temporary-lifetimes.md](text/0066-better-temporary-lifetimes.md) +* [0090-lexical-syntax-simplification.md](text/0090-lexical-syntax-simplification.md) +* [0107-pattern-guards-with-bind-by-move.md](text/0107-pattern-guards-with-bind-by-move.md) +* [0114-closures.md](text/0114-closures.md) +* [0131-target-specification.md](text/0131-target-specification.md) +* [0132-ufcs.md](text/0132-ufcs.md) +* [0135-where.md](text/0135-where.md) +* [0141-lifetime-elision.md](text/0141-lifetime-elision.md) +* [0151-capture-by-value.md](text/0151-capture-by-value.md) +* [0195-associated-items.md](text/0195-associated-items.md) +* [0198-slice-notation.md](text/0198-slice-notation.md) +* [0199-ownership-variants.md](text/0199-ownership-variants.md) +* [0201-error-chaining.md](text/0201-error-chaining.md) +* [0212-restore-int-fallback.md](text/0212-restore-int-fallback.md) +* [0214-while-let.md](text/0214-while-let.md) +* [0216-collection-views.md](text/0216-collection-views.md) +* [0221-panic.md](text/0221-panic.md) +* [0230-remove-runtime.md](text/0230-remove-runtime.md) +* [0231-upvar-capture-inference.md](text/0231-upvar-capture-inference.md) +* [0240-unsafe-api-location.md](text/0240-unsafe-api-location.md) +* [0246-const-vs-static.md](text/0246-const-vs-static.md) +* [0341-remove-virtual-structs.md](text/0341-remove-virtual-structs.md) +* [0342-keywords.md](text/0342-keywords.md) + +## Table of Contents +[Table of Contents]: #table-of-contents +* [Opening](#rust-rfcs) +* [Active RFC List] +* [Table of Contents] +* [When you need to follow this process] +* [What the process is] +* [The role of the shepherd] +* [The RFC life-cycle] +* [Implementing an RFC] +* [Reviewing RFC's] +* [RFC Postponement] +* [Help this is all too informal!] + ## When you need to follow this process +[When you need to follow this process]: #when-you-need-to-follow-this-process You need to follow this process if you intend to make "substantial" changes to the Rust distribution. What constitutes a "substantial" @@ -39,7 +89,7 @@ through the RFC process, it may be closed with a polite request to submit an RFC first. ## What the process is - +[What the process is]: #what-the-process-is In short, to get a major feature added to Rust, one must first get the RFC merged into the RFC repo as a markdown file. At that point the RFC is 'active' and may be implemented with the goal of eventual inclusion @@ -62,6 +112,7 @@ merging the pull request and assigning the RFC a number, at which point the RFC is 'active', or reject it by closing the pull request. ## The role of the shepherd +[The role of the shepherd]: the-role-of-the-shepherd During triage, every RFC will either be closed or assigned a shepherd. The role of the shepherd is to move the RFC through the process. This @@ -74,6 +125,7 @@ here is to "front-load" as much of the feedback as possible before the point where we actually reach a decision. ## The RFC life-cycle +[The RFC life-cycle]: #the-rfc-life-cycle Once an RFC becomes active then authors may implement it and submit the feature as a pull request to the Rust repo. An 'active' is not a rubber @@ -100,6 +152,7 @@ that fails after becoming active is 'inactive' and moves to the 'inactive' folder. ## Implementing an RFC +[Implementing an RFC]: #implementing-an-rfc Some accepted RFC's represent vital features that need to be implemented right away. Other accepted RFC's can represent features @@ -118,6 +171,7 @@ RFC, but cannot determine if someone else is already working on it, feel free to ask (e.g. by leaving a comment on the associated issue). ## Reviewing RFC's +[Reviewing RFC's]: #reviewing-rfcs Each week the [core team] will attempt to review some set of open RFC pull requests. The choice of pull requests to review is largely @@ -144,6 +198,7 @@ should act as a "shepherd" for the feature. The shepherd need not its virtues and the community’s desire for it. ## RFC Postponement +[RFC Postponement]: #rfc-postponement Some RFC pull requests are tagged with the 'postponed' label when they are closed (as part of the rejection process). An RFC closed with @@ -161,6 +216,7 @@ response is to close the RFC, not postpone it.) ### Help this is all too informal! +[Help this is all too informal!]: #help-this-is-all-too-informal The process is intended to be as lightweight as reasonable for the present circumstances. As usual, we are trying to let the process be diff --git a/complete/0004-private-fields.md b/text/0001-private-fields.md similarity index 100% rename from complete/0004-private-fields.md rename to text/0001-private-fields.md diff --git a/active/0001-rfc-process.md b/text/0002-rfc-process.md similarity index 85% rename from active/0001-rfc-process.md rename to text/0002-rfc-process.md index 86f7e8bf814..4bd0c1f02a8 100644 --- a/active/0001-rfc-process.md +++ b/text/0002-rfc-process.md @@ -61,7 +61,7 @@ is 'active' and may be implemented with the goal of eventual inclusion into Rust. * Fork the RFC repo https://github.com/rust-lang/rfcs -* Copy `0000-template.md` to `active/0000-my-feature.md` (where +* Copy `0000-template.md` to `text/0000-my-feature.md` (where 'my-feature' is descriptive. don't assign an RFC number yet). * Fill in the RFC * Submit a pull request. The pull request is the time to get review of @@ -71,16 +71,19 @@ are much more likely to make progress than those that don't receive any comments. Eventually, somebody on the [core team] will either accept the RFC by -merging the pull request and assigning the RFC a number, at which point -the RFC is 'active', or reject it by closing the pull request. +merging the pull request, at which point the RFC is 'active', or +reject it by closing the pull request. Whomever merges the RFC should do the following: -* Assign a sequential id. -* Add the file in the active directory. -* Create a corresponding issue on Rust. -* Fill in the remaining metadata in the RFC header, including the original - PR # and Rust issue #. +* Assign an id, using the PR number of the RFC pull request. (If the RFC + has multiple pull requests associated with it, choose one PR number, + preferably the minimal one.) +* Add the file in the `text/` directory. +* Create a corresponding issue on [Rust repo](https://github.com/rust-lang/rust) +* Fill in the remaining metadata in the RFC header, including links for + the original pull request(s) and the newly created Rust issue. +* Add an entry in the [Active RFC List] of the root `README.md`. * Commit everything. Once an RFC becomes active then authors may implement it and submit the @@ -91,9 +94,11 @@ have agreed to the feature and are amenable to merging it. Modifications to active RFC's can be done in followup PR's. An RFC that makes it through the entire process to implementation is considered -'complete' and is moved to the 'complete' folder; an RFC that fails +'complete' and is removed from the [Active RFC List]; an RFC that fails after becoming active is 'inactive' and moves to the 'inactive' folder. +[Active RFC List]: ../README.md#active-rfc-list + # Alternatives Retain the current informal RFC process. The newly proposed RFC process is diff --git a/complete/0002-attribute-usage.md b/text/0003-attribute-usage.md similarity index 100% rename from complete/0002-attribute-usage.md rename to text/0003-attribute-usage.md diff --git a/active/0005-new-intrinsics.md b/text/0008-new-intrinsics.md similarity index 100% rename from active/0005-new-intrinsics.md rename to text/0008-new-intrinsics.md diff --git a/active/0040-more-attributes.md b/text/0016-more-attributes.md similarity index 100% rename from active/0040-more-attributes.md rename to text/0016-more-attributes.md diff --git a/active/0003-opt-in-builtin-traits.md b/text/0019-opt-in-builtin-traits.md similarity index 99% rename from active/0003-opt-in-builtin-traits.md rename to text/0019-opt-in-builtin-traits.md index ae4ab261e93..c29e0356326 100644 --- a/active/0003-opt-in-builtin-traits.md +++ b/text/0019-opt-in-builtin-traits.md @@ -1,6 +1,6 @@ - Start Date: 2014-09-18 -- RFC PR #: #127 -- Rust Issue #: #13231 +- RFC PR #: [rust-lang/rfcs#19](https://github.com/rust-lang/rfcs/pull/19), [rust-lang/rfcs#127](https://github.com/rust-lang/rfcs/pull/127) +- Rust Issue #: [rust-lang/rust#13231](https://github.com/rust-lang/rust/issues/13231) # Summary diff --git a/complete/0006-remove-priv.md b/text/0026-remove-priv.md similarity index 100% rename from complete/0006-remove-priv.md rename to text/0026-remove-priv.md diff --git a/complete/0011-bounded-type-parameters.md b/text/0034-bounded-type-parameters.md similarity index 95% rename from complete/0011-bounded-type-parameters.md rename to text/0034-bounded-type-parameters.md index aaaaf6bdb88..96504d94336 100644 --- a/complete/0011-bounded-type-parameters.md +++ b/text/0034-bounded-type-parameters.md @@ -1,6 +1,6 @@ - Start Date: 2014-04-05 -- RFC PR: -- Rust Issue: +- RFC PR: [rust-lang/rfcs#34](https://github.com/rust-lang/rfcs/pull/34) +- Rust Issue: [rust-lang/rust#15759](https://github.com/rust-lang/rust/issues/15759) # Summary diff --git a/complete/0012-libstd-facade.md b/text/0040-libstd-facade.md similarity index 100% rename from complete/0012-libstd-facade.md rename to text/0040-libstd-facade.md diff --git a/complete/0007-regexps.md b/text/0042-regexps.md similarity index 100% rename from complete/0007-regexps.md rename to text/0042-regexps.md diff --git a/active/0024-traits.md b/text/0048-traits.md similarity index 100% rename from active/0024-traits.md rename to text/0048-traits.md diff --git a/complete/0008-match-arm-attributes.md b/text/0049-match-arm-attributes.md similarity index 100% rename from complete/0008-match-arm-attributes.md rename to text/0049-match-arm-attributes.md diff --git a/complete/0015-assert.md b/text/0050-assert.md similarity index 100% rename from complete/0015-assert.md rename to text/0050-assert.md diff --git a/complete/0014-remove-tilde.md b/text/0059-remove-tilde.md similarity index 100% rename from complete/0014-remove-tilde.md rename to text/0059-remove-tilde.md diff --git a/complete/0019-rename-strbuf.md b/text/0060-rename-strbuf.md similarity index 100% rename from complete/0019-rename-strbuf.md rename to text/0060-rename-strbuf.md diff --git a/complete/0016-module-file-system-hierarchy.md b/text/0063-module-file-system-hierarchy.md similarity index 100% rename from complete/0016-module-file-system-hierarchy.md rename to text/0063-module-file-system-hierarchy.md diff --git a/active/0031-better-temporary-lifetimes.md b/text/0066-better-temporary-lifetimes.md similarity index 100% rename from active/0031-better-temporary-lifetimes.md rename to text/0066-better-temporary-lifetimes.md diff --git a/complete/0032-const-unsafe-pointers.md b/text/0068-const-unsafe-pointers.md similarity index 100% rename from complete/0032-const-unsafe-pointers.md rename to text/0068-const-unsafe-pointers.md diff --git a/complete/0023-ascii-literals.md b/text/0069-ascii-literals.md similarity index 100% rename from complete/0023-ascii-literals.md rename to text/0069-ascii-literals.md diff --git a/complete/0017-const-block-expr.md b/text/0071-const-block-expr.md similarity index 100% rename from complete/0017-const-block-expr.md rename to text/0071-const-block-expr.md diff --git a/complete/0018-undefined-struct-layout.md b/text/0079-undefined-struct-layout.md similarity index 100% rename from complete/0018-undefined-struct-layout.md rename to text/0079-undefined-struct-layout.md diff --git a/complete/0020-pattern-macros.md b/text/0085-pattern-macros.md similarity index 100% rename from complete/0020-pattern-macros.md rename to text/0085-pattern-macros.md diff --git a/complete/0022-plugin-registrar.md b/text/0086-plugin-registrar.md similarity index 100% rename from complete/0022-plugin-registrar.md rename to text/0086-plugin-registrar.md diff --git a/complete/0027-trait-bounds-with-plus.md b/text/0087-trait-bounds-with-plus.md similarity index 100% rename from complete/0027-trait-bounds-with-plus.md rename to text/0087-trait-bounds-with-plus.md diff --git a/complete/0029-loadable-lints.md b/text/0089-loadable-lints.md similarity index 100% rename from complete/0029-loadable-lints.md rename to text/0089-loadable-lints.md diff --git a/active/0021-lexical-syntax-simplification.md b/text/0090-lexical-syntax-simplification.md similarity index 100% rename from active/0021-lexical-syntax-simplification.md rename to text/0090-lexical-syntax-simplification.md diff --git a/complete/0025-struct-grammar.md b/text/0092-struct-grammar.md similarity index 100% rename from complete/0025-struct-grammar.md rename to text/0092-struct-grammar.md diff --git a/complete/0026-remove-format-intl.md b/text/0093-remove-format-intl.md similarity index 100% rename from complete/0026-remove-format-intl.md rename to text/0093-remove-format-intl.md diff --git a/complete/0028-partial-cmp.md b/text/0100-partial-cmp.md similarity index 100% rename from complete/0028-partial-cmp.md rename to text/0100-partial-cmp.md diff --git a/active/0036-pattern-guards-with-bind-by-move.md b/text/0107-pattern-guards-with-bind-by-move.md similarity index 100% rename from active/0036-pattern-guards-with-bind-by-move.md rename to text/0107-pattern-guards-with-bind-by-move.md diff --git a/complete/0035-remove-crate-id.md b/text/0109-remove-crate-id.md similarity index 100% rename from complete/0035-remove-crate-id.md rename to text/0109-remove-crate-id.md diff --git a/complete/0034-index-traits.md b/text/0111-index-traits.md similarity index 100% rename from complete/0034-index-traits.md rename to text/0111-index-traits.md diff --git a/complete/0033-remove-cross-borrowing.md b/text/0112-remove-cross-borrowing.md similarity index 100% rename from complete/0033-remove-cross-borrowing.md rename to text/0112-remove-cross-borrowing.md diff --git a/active/0044-closures.md b/text/0114-closures.md similarity index 100% rename from active/0044-closures.md rename to text/0114-closures.md diff --git a/complete/0030-rm-integer-fallback.md b/text/0115-rm-integer-fallback.md similarity index 100% rename from complete/0030-rm-integer-fallback.md rename to text/0115-rm-integer-fallback.md diff --git a/complete/0050-no-module-shadowing.md b/text/0116-no-module-shadowing.md similarity index 100% rename from complete/0050-no-module-shadowing.md rename to text/0116-no-module-shadowing.md diff --git a/complete/0045-share-to-threadsafe.md b/text/0123-share-to-threadsafe.md similarity index 98% rename from complete/0045-share-to-threadsafe.md rename to text/0123-share-to-threadsafe.md index 5b3422d479c..0d8739d7748 100644 --- a/complete/0045-share-to-threadsafe.md +++ b/text/0123-share-to-threadsafe.md @@ -1,5 +1,5 @@ - Start Date: 2014-06-15 -- RFC PR #: [rust-lang/rfcs#123](https://github.com/rust-lang/rfcs/pull/123j) +- RFC PR #: [rust-lang/rfcs#123](https://github.com/rust-lang/rfcs/pull/123) - Rust Issue #: [rust-lang/rust#16281](https://github.com/rust-lang/rust/issues/16281) # Summary diff --git a/complete/0043-box-not-special.md b/text/0130-box-not-special.md similarity index 100% rename from complete/0043-box-not-special.md rename to text/0130-box-not-special.md diff --git a/active/0042-target-specification.md b/text/0131-target-specification.md similarity index 100% rename from active/0042-target-specification.md rename to text/0131-target-specification.md diff --git a/active/0046-ufcs.md b/text/0132-ufcs.md similarity index 100% rename from active/0046-ufcs.md rename to text/0132-ufcs.md diff --git a/active/0066-where.md b/text/0135-where.md similarity index 100% rename from active/0066-where.md rename to text/0135-where.md diff --git a/complete/0048-no-privates-in-public.md b/text/0136-no-privates-in-public.md similarity index 100% rename from complete/0048-no-privates-in-public.md rename to text/0136-no-privates-in-public.md diff --git a/complete/0037-remove-cross-borrowing-entirely.md b/text/0139-remove-cross-borrowing-entirely.md similarity index 100% rename from complete/0037-remove-cross-borrowing-entirely.md rename to text/0139-remove-cross-borrowing-entirely.md diff --git a/active/0039-lifetime-elision.md b/text/0141-lifetime-elision.md similarity index 100% rename from active/0039-lifetime-elision.md rename to text/0141-lifetime-elision.md diff --git a/active/0038-capture-by-value.md b/text/0151-capture-by-value.md similarity index 100% rename from active/0038-capture-by-value.md rename to text/0151-capture-by-value.md diff --git a/complete/0057-anonymous-impl-only-in-same-module.md b/text/0155-anonymous-impl-only-in-same-module.md similarity index 97% rename from complete/0057-anonymous-impl-only-in-same-module.md rename to text/0155-anonymous-impl-only-in-same-module.md index 065dc8a86af..8bc961ec716 100644 --- a/complete/0057-anonymous-impl-only-in-same-module.md +++ b/text/0155-anonymous-impl-only-in-same-module.md @@ -1,6 +1,6 @@ - Start Date: 2014-07-04 -- RFC PR #: 155 -- Rust Issue #: 17059 +- RFC PR #: [rust-lang/rfcs#155](https://github.com/rust-lang/rfcs/pull/155) +- Rust Issue #: [rust-lang/rust#17059](https://github.com/rust-lang/rust/issues/17059) # Summary diff --git a/complete/0051-if-let.md b/text/0160-if-let.md similarity index 100% rename from complete/0051-if-let.md rename to text/0160-if-let.md diff --git a/complete/0054-feature-gate-slice-pats.md b/text/0164-feature-gate-slice-pats.md similarity index 100% rename from complete/0054-feature-gate-slice-pats.md rename to text/0164-feature-gate-slice-pats.md diff --git a/complete/0041-mod.md b/text/0168-mod.md similarity index 100% rename from complete/0041-mod.md rename to text/0168-mod.md diff --git a/complete/0047-use-path-as-id.md b/text/0169-use-path-as-id.md similarity index 100% rename from complete/0047-use-path-as-id.md rename to text/0169-use-path-as-id.md diff --git a/complete/0053-tuple-accessors.md b/text/0184-tuple-accessors.md similarity index 100% rename from complete/0053-tuple-accessors.md rename to text/0184-tuple-accessors.md diff --git a/complete/0049-bounds-on-object-and-generic-types.md b/text/0192-bounds-on-object-and-generic-types.md similarity index 100% rename from complete/0049-bounds-on-object-and-generic-types.md rename to text/0192-bounds-on-object-and-generic-types.md diff --git a/complete/0065-cfg-syntax.md b/text/0194-cfg-syntax.md similarity index 100% rename from complete/0065-cfg-syntax.md rename to text/0194-cfg-syntax.md diff --git a/active/0059-associated-items.md b/text/0195-associated-items.md similarity index 100% rename from active/0059-associated-items.md rename to text/0195-associated-items.md diff --git a/active/0058-slice-notation.md b/text/0198-slice-notation.md similarity index 100% rename from active/0058-slice-notation.md rename to text/0198-slice-notation.md diff --git a/active/0052-ownership-variants.md b/text/0199-ownership-variants.md similarity index 100% rename from active/0052-ownership-variants.md rename to text/0199-ownership-variants.md diff --git a/active/0070-error-chaining.md b/text/0201-error-chaining.md similarity index 100% rename from active/0070-error-chaining.md rename to text/0201-error-chaining.md diff --git a/complete/0055-subslice-syntax-change.md b/text/0202-subslice-syntax-change.md similarity index 100% rename from complete/0055-subslice-syntax-change.md rename to text/0202-subslice-syntax-change.md diff --git a/active/0056-restore-int-fallback.md b/text/0212-restore-int-fallback.md similarity index 100% rename from active/0056-restore-int-fallback.md rename to text/0212-restore-int-fallback.md diff --git a/active/0068-while-let.md b/text/0214-while-let.md similarity index 100% rename from active/0068-while-let.md rename to text/0214-while-let.md diff --git a/active/0060-collection-views.md b/text/0216-collection-views.md similarity index 100% rename from active/0060-collection-views.md rename to text/0216-collection-views.md diff --git a/active/0064-panic.md b/text/0221-panic.md similarity index 100% rename from active/0064-panic.md rename to text/0221-panic.md diff --git a/active/0062-remove-runtime.md b/text/0230-remove-runtime.md similarity index 100% rename from active/0062-remove-runtime.md rename to text/0230-remove-runtime.md diff --git a/active/0063-upvar-capture-inference.md b/text/0231-upvar-capture-inference.md similarity index 100% rename from active/0063-upvar-capture-inference.md rename to text/0231-upvar-capture-inference.md diff --git a/complete/0061-variants-namespace.md b/text/0234-variants-namespace.md similarity index 100% rename from complete/0061-variants-namespace.md rename to text/0234-variants-namespace.md diff --git a/text/0240-unsafe-api-location.md b/text/0240-unsafe-api-location.md new file mode 100644 index 00000000000..58697bf4616 --- /dev/null +++ b/text/0240-unsafe-api-location.md @@ -0,0 +1,162 @@ +- Start Date: 2014-10-07 +- RFC PR: [rust-lang/rfcs#240](https://github.com/rust-lang/rfcs/pull/240) +- Rust Issue: [rust-lang/rust#17863](https://github.com/rust-lang/rust/issues/17863) + +# Summary + +This is a *conventions RFC* for settling the location of `unsafe` APIs relative +to the types they work with, as well as the use of `raw` submodules. + +The brief summary is: + +* Unsafe APIs should be made into methods or static functions in the same cases + that safe APIs would be. + +* `raw` submodules should be used only to *define* explicit low-level + representations. + +# Motivation + +Many data structures provide unsafe APIs either for avoiding checks or working +directly with their (otherwise private) representation. For example, `string` +provides: + +* An `as_mut_vec` method on `String` that provides a `Vec` view of the + string. This method makes it easy to work with the byte-based representation + of the string, but thereby also allows violation of the utf8 guarantee. + +* A `raw` submodule with a number of free functions, like `from_parts`, that + constructs a `String` instances from a raw-pointer-based representation, a + `from_utf8` variant that does not actually check for utf8 validity, and so + on. The unifying theme is that all of these functions avoid checking some key + invariant. + +The problem is that currently, there is no clear/consistent guideline about +which of these APIs should live as methods/static functions associated with a +type, and which should live in a `raw` submodule. Both forms appear throughout +the standard library. + +# Detailed design + +The proposed convention is: + +* When an unsafe function/method is clearly "about" a certain type (as a way of + constructing, destructuring, or modifying values of that type), it should be a + method or static function on that type. This is the same as the convention for + placement of safe functions/methods. So functions like + `string::raw::from_parts` would become static functions on `String`. + +* `raw` submodules should only be used to *define* low-level + types/representations (and methods/functions on them). Methods for converting + to/from such low-level types should be available directly on the high-level + types. Examples: `core::raw`, `sync::raw`. + +The benefits are: + +* *Ergonomics*. You can gain easy access to unsafe APIs merely by having a value + of the type (or, for static functions, importing the type). + +* *Consistency and simplicity*. The rules for placement of unsafe APIs are the + same as those for safe APIs. + +The perspective here is that marking APIs `unsafe` is enough to deter their use +in ordinary situations; they don't need to be further distinguished by placement +into a separate module. + +There are also some naming conventions to go along with unsafe static functions +and methods: + +* When an unsafe function/method is an unchecked variant of an otherwise safe + API, it should be marked using an `_unchecked` suffix. + + For example, the `String` module should provide both `from_utf8` and + `from_utf8_unchecked` constructors, where the latter does not actually check + the utf8 encoding. The `string::raw::slice_bytes` and + `string::raw::slice_unchecked` functions should be merged into a single + `slice_unchecked` method on strings that checks neither bounds nor utf8 + boundaries. + +* When an unsafe function/method produces or consumes a low-level representation + of a data structure, the API should use `raw` in its name. Specifically, + `from_raw_parts` is the typical name used for constructing a value from e.g. a + pointer-based representation. + +* Otherwise, *consider* using a name that suggests *why* the API is unsafe. In + some cases, like `String::as_mut_vec`, other stronger conventions apply, and the + `unsafe` qualifier on the signature (together with API documentation) is + enough. + +The unsafe methods and static functions for a given type should be placed in +their own `impl` block, at the end of the module defining the type; this will +ensure that they are grouped together in rustdoc. (Thanks @kballard for the +suggestion.) + +# Drawbacks + +One potential drawback of these conventions is that the documentation for a +module will be cluttered with rarely-used `unsafe` APIs, whereas the `raw` +submodule approach neatly groups these APIs. But rustdoc could easily be +changed to either hide or separate out `unsafe` APIs by default, and in the +meantime the `impl` block grouping should help. + +More specifically, the convention of placing unsafe constructors in `raw` makes +them very easy to find. But the usual `from_` convention, together with the +naming conventions suggested above, should make it fairly easy to discover such +constructors even when they're supplied directly as static functions. + +More generally, these conventions give `unsafe` APIs more equal status with safe +APIs. Whether this is a *drawback* depends on your philosophy about the status +of unsafe programming. But on a technical level, the key point is that the APIs +are marked `unsafe`, so users still have to opt-in to using them. *Ed note: from +my perspective, low-level/unsafe programming is important to support, and there +is no reason to penalize its ergonomics given that it's opt-in anyway.* + +# Alternatives + +There are a few alternatives: + +* Rather than providing unsafe APIs directly as methods/static functions, they + could be grouped into a single extension trait. For example, the `String` type + could be accompanied by a `StringRaw` extension trait providing APIs for + working with raw string representations. This would allow a clear grouping of + unsafe APIs, while still providing them as methods/static functions and + allowing them to easily be imported with e.g. `use std::string::StringRaw`. + On the other hand, it still further penalizes the raw APIs (beyond marking + them `unsafe`), and given that rustdoc could easily provide API grouping, it's + unclear exactly what the benefit is. + +* ([Suggested by @kballard](https://github.com/rust-lang/rfcs/pull/240#issuecomment-55635468)): + + > Use `raw` for functions that construct a value of the type without checking + > for one or more invariants. + + The advantage is that it's easy to find such invariant-ignoring functions. The + disadvantage is that their ergonomics is worsened, since they much be + separately imported or referenced through a lengthy path: + + ```rust + // Compare the ergonomics: + string::raw::slice_unchecked(some_string, start, end) + some_string.slice_unchecked(start, end) + ``` + +* Another suggestion by @kballard is to keep the basic structure of `raw` + submodules, but use associated types to improve the ergonomics. Details (and + discussions of pros/cons) are in + [this comment](https://github.com/rust-lang/rfcs/pull/240/files#r17572875). + +* Use `raw` submodules to group together *all* manipulation of low-level + representations. No module in `std` currently does this; existing modules + provide some free functions in `raw`, and some unsafe methods, without a clear + driving principle. The ergonomics of moving *everything* into free functions + in a `raw` submodule are quite poor. + +# Unresolved questions + +The `core::raw` module provides structs with public representations equivalent +to several built-in and library types (boxes, closures, slices, etc.). It's not +clear whether the name of this module, or the location of its contents, should +change as a result of this RFC. The module is a special case, because not all of +the types it deals with even have corresponding modules/type declarations -- so +it probably suffices to leave decisions about it to the API stabilization +process. diff --git a/active/0069-const-vs-static.md b/text/0246-const-vs-static.md similarity index 100% rename from active/0069-const-vs-static.md rename to text/0246-const-vs-static.md diff --git a/complete/0067-remove-refcounting-gc-of-t.md b/text/0256-remove-refcounting-gc-of-t.md similarity index 100% rename from complete/0067-remove-refcounting-gc-of-t.md rename to text/0256-remove-refcounting-gc-of-t.md diff --git a/text/0341-remove-virtual-structs.md b/text/0341-remove-virtual-structs.md new file mode 100644 index 00000000000..ea7c5a0db8f --- /dev/null +++ b/text/0341-remove-virtual-structs.md @@ -0,0 +1,45 @@ +- Start Date: 2014-09-30 +- RFC PR: https://github.com/rust-lang/rfcs/pull/341 +- Rust Issue: https://github.com/rust-lang/rust/issues/17861 + +# Summary + +Removes the "virtual struct" (aka struct inheritance) feature, which +is currently feature gated. + +# Motivation + +Virtual structs were added experimentally prior to the RFC process as +a way of inheriting fields from one struct when defining a new struct. + +The feature was introduced and remains behind a feature gate. + +The motivations for removing this feature altogether are: + +1. The feature is likely to be replaced by a more general mechanism, + as part of the need to address hierarchies such as the DOM, ASTs, + and so on. See + [this post](http://discuss.rust-lang.org/t/summary-of-efficient-inheritance-rfcs/494/43) + for some recent discussion. + +2. The implementation is somewhat buggy and incomplete, and the + feature is not well-documented. + +3. Although it's behind a feature gate, keeping the feature around is + still a maintenance burden. + +# Detailed design + +Remove the implementation and feature gate for virtual structs. + +Retain the `virtual` keyword as reserved for possible future use. + +# Drawbacks + +The language will no longer offer any built-in mechanism for avoiding +repetition of struct fields. Macros offer a reasonable workaround +until a more general mechanism is added. + +# Unresolved questions + +None known. diff --git a/text/0342-keywords.md b/text/0342-keywords.md new file mode 100644 index 00000000000..a550d908248 --- /dev/null +++ b/text/0342-keywords.md @@ -0,0 +1,35 @@ +- Start Date: 2014-10-07 +- RFC PR: https://github.com/rust-lang/rfcs/pull/342 +- Rust Issue: https://github.com/rust-lang/rust/issues/17862 + +# Summary + +Reserve `abstract`, `final`, and `override` as possible keywords. + +# Motivation + +We intend to add some mechanism to Rust to support more efficient inheritance +(see, e.g., RFC PRs #245 and #250, and this +[thread](http://discuss.rust-lang.org/t/summary-of-efficient-inheritance-rfcs/494/43) +on discuss). Although we have not decided how to do this, we do know that we +will. Any implementation is likely to make use of keywords `virtual` (already +used, to remain reserved), `abstract`, `final`, and `override`, so it makes +sense to reserve these now to make the eventual implementation as backwards +compatible as possible. + +# Detailed design + +Make `abstract`, `final`, and `override` reserved keywords. + +# Drawbacks + +Takes a few more words out of the possible vocabulary of Rust programmers. + +# Alternatives + +Don't do this and deal with it when we have an implementation. This would mean +bumping the language version, probably. + +# Unresolved questions + +N/A