Skip to content

Commit cc19a1b

Browse files
committed
Switch to use --rust-version instead of #[rust_version]
1 parent 5d5923a commit cc19a1b

File tree

1 file changed

+53
-29
lines changed

1 file changed

+53
-29
lines changed

text/0000-language-semver.md

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -255,35 +255,51 @@ should or should not be introduced in this fashion.
255255
We use the term *"opt-in changes"* to refer to changes that would be
256256
breaking changes, but are not because of the opt-in mechanism.
257257

258-
#### Rust version attribute
259-
260-
The specific proposal is an attribute `#![rust_version="X.Y"]` that
261-
can be attached to the crate; the version `X.Y` in this attribute is
262-
called the crate's "declared version". Every build of the Rust
263-
compiler will also have a version number built into it reflecting the
264-
current release.
265-
266-
When a `#[rust_version="X.Y"]` attribute is encountered, the compiler
267-
will endeavor to produce the semantics of Rust "as it was" during
268-
version `X.Y`. RFCs that propose opt-in changes should discuss how the
269-
older behavior can be supported in the compiler, but this is expected
270-
to be straightforward: if supporting older behavior is hard to do, it
271-
may indicate that the opt-in change is too complex and should not be
272-
accepted.
273-
274-
If the crate declares a version `X.Y` that is *newer* than the
275-
compiler itself, the compiler should simply issue a warning and
276-
proceed as if the crate had declared the compiler's version (i.e., the
277-
newer version the compiler knows about).
278-
279-
Note that if the changes introducing by the Rust version `X.Y` affect
280-
parsing, implementing these semantics may require some limited amount
281-
of feedback between the parser and the tokenizer, or else a limited
282-
"pre-parse" to scan the set of crate attributes and extract the
283-
version. For example, if version `X.Y` adds new keywords, the
284-
tokenizer will likely need to be configured appropriately with the
285-
proper set of keywords. For this reason, it may make sense to require
286-
that the `#![rust_version]` attribute appear *first* on the crate.
258+
#### Rust version option
259+
260+
The specific proposal is to introduce a command-line option
261+
`--rust-version=X.Y[.Z]` that instructs the Rust compiler to expect
262+
source code from older versions of Rust. This option could also be
263+
specified in a `Cargo.toml` file in a `rust-version` property. The
264+
version applies to the crate currently being compiled and is called
265+
the crate's "supplied version". Every build of the Rust compiler will
266+
also have a version number built into it reflecting the current
267+
release; if the command-line option is not supplied, the compiler
268+
defaults to this builtin version.
269+
270+
The supplied version is used by the compiler to produce the semantics
271+
of Rust "as it was" during version `X.Y`. RFCs that propose opt-in
272+
changes should discuss how the older behavior can be supported in the
273+
compiler, but this is expected to be straightforward: if supporting
274+
older behavior is hard to do, it may indicate that the opt-in change
275+
is too complex and should not be accepted.
276+
277+
Note that the supplied version may affect the parser configuration
278+
used when parsing the initial crate, since it can affect the keywords
279+
recognized by the tokenizer and perhaps other minor details in the
280+
syntax. However, because the version is supplied on the command line,
281+
this configuration is known before parsing begins.
282+
283+
#### Defaults and extreme cases
284+
285+
If no version is supplied on the `rustc` command line, `rustc` will
286+
default to the maximal version it recognizes. If the user supplies a
287+
version `X.Y` that is *newer* than the compiler itself, the compiler
288+
should simply issue a warning and proceed as if the user had supplied
289+
the compiler's version (i.e., the newest version the compiler knows
290+
about).
291+
292+
Cargo will always invoke `rustc` with a supplied version. If there is
293+
no version in the `Cargo.toml` file, then `1.0.0` is assumed. Whenever
294+
a new project is created with `cargo new`, the new `Cargo.toml` will
295+
include the most recent Rust version number by default.
296+
297+
Note that the defaults for `rustc` and `cargo` differ. `rustc` prefers
298+
the most recent verison of Rust by default, whereas `cargo` prefers
299+
the oldest. The reason is that we expect running `rustc` in a
300+
standalone fashion to be used primarily when experimenting with small
301+
scripts and one-offs, and the user is most likely to want "current
302+
Rust" in that scenario.
287303

288304
#### When opt-in changes are appropriate
289305

@@ -347,6 +363,14 @@ section on *unresolved questions*.
347363

348364
# Alternatives
349365

366+
**Use an attribute rather than command-line option.** Earlier versions
367+
of this RFC used a `#[rust_version]` attribute to specify the Rust
368+
version rather than a command-line parameter. This was changed to use
369+
a command-line parameter because it (a) exposes the version int he
370+
Cargo metadata, (b) is analogous to the approach used by most other
371+
languages, and (c) simplifies the implementation, since the parser
372+
does not need to be reconfigured midparse.
373+
350374
**Rather than supporting opt-in changes, one might consider simply
351375
issuing a new major release for every such change.** Put simply,
352376
though, issuing a new major release just because we want to have a new

0 commit comments

Comments
 (0)