rust/library/std/src
bors 07a4b7e2a9 Auto merge of #116773 - dtolnay:validatestable, r=compiler-errors
Validate `feature` and `since` values inside `#[stable(…)]`

Previously the string passed to `#[unstable(feature = "...")]` would be validated as an identifier, but not `#[stable(feature = "...")]`. In the standard library there were `stable` attributes containing the empty string, and kebab-case string, neither of which should be allowed.

Pre-existing validation of `unstable`:

```rust
// src/lib.rs

#![allow(internal_features)]
#![feature(staged_api)]
#![unstable(feature = "kebab-case", issue = "none")]

#[unstable(feature = "kebab-case", issue = "none")]
pub struct Struct;
```

```console
error[E0546]: 'feature' is not an identifier
 --> src/lib.rs:5:1
  |
5 | #![unstable(feature = "kebab-case", issue = "none")]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

For an `unstable` attribute, the need for an identifier is obvious because the downstream code needs to write a `#![feature(...)]` attribute containing that identifier. `#![feature(kebab-case)]` is not valid syntax and `#![feature(kebab_case)]` would not work if that is not the name of the feature.

Having a valid identifier even in `stable` is less essential but still useful because it allows for informative diagnostic about the stabilization of a feature. Compare:

```rust
// src/lib.rs

#![allow(internal_features)]
#![feature(staged_api)]
#![stable(feature = "kebab-case", since = "1.0.0")]

#[stable(feature = "kebab-case", since = "1.0.0")]
pub struct Struct;
```

```rust
// src/main.rs

#![feature(kebab_case)]

use repro::Struct;

fn main() {}
```

```console
error[E0635]: unknown feature `kebab_case`
 --> src/main.rs:3:12
  |
3 | #![feature(kebab_case)]
  |            ^^^^^^^^^^
```

vs the situation if we correctly use `feature = "snake_case"` and `#![feature(snake_case)]`, as enforced by this PR:

```console
warning: the feature `snake_case` has been stable since 1.0.0 and no longer requires an attribute to enable
 --> src/main.rs:3:12
  |
3 | #![feature(snake_case)]
  |            ^^^^^^^^^^
  |
  = note: `#[warn(stable_features)]` on by default
```
2023-10-24 15:06:20 +00:00
..
backtrace Implement UnwindSafe and RefUnwindSafe for Backtrace 2023-07-31 10:38:24 +02:00
collections s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
env Better Debug for Vars and VarsOs 2023-08-07 12:18:27 -04:00
error core/any: remove Provider trait 2023-08-13 13:07:53 -06:00
f32 Add gamma and ln_gamma functions to f32 and f64 2023-07-31 07:41:50 -07:00
f64 Add gamma and ln_gamma functions to f32 and f64 2023-07-31 07:41:50 -07:00
ffi Bump version placeholders 2023-10-03 20:26:36 -04:00
fs Skip test if Unix sockets are unsupported 2023-10-20 18:10:34 +01:00
io Fix invalid stability attribute features in standard library 2023-10-23 13:03:10 -07:00
net Auto merge of #105394 - Patiga:improve-udpsocket-docs, r=workingjubilee 2023-10-03 20:35:38 +00:00
num rustc_expand: Mark inner #![test] attributes as soft-unstable 2020-11-20 19:35:03 +03:00
os changes from feedback 2023-10-20 23:55:14 +01:00
panic review: fix nits and move panic safety tests to the correct place 2020-09-25 23:10:24 +02:00
path std: add tests for Path::with_extension 2023-07-14 13:19:45 -03:00
prelude correct std::prelude comment 2023-04-27 15:56:57 +02:00
process Rollup merge of #114379 - RalfJung:command-removed-env-vars, r=m-ou-se 2023-09-22 12:15:25 +02:00
sync Implement OnceCell/Lock::try_insert() 2023-10-13 14:54:32 +02:00
sys Auto merge of #116461 - ChrisDenton:sleep, r=thomcc 2023-10-24 11:14:15 +00:00
sys_common Auto merge of #116132 - darthunix:connect_poll, r=cuviper 2023-10-19 11:22:28 +00:00
thread std: broaden the allowed behaviour for recursive TLS initialization 2023-09-26 12:54:01 +02:00
time Rollup merge of #103056 - beetrees:timespec-bug-fix, r=thomcc 2023-05-05 18:40:32 +05:30
alloc.rs Correct and expand documentation of handle_alloc_error and set_alloc_error_hook. 2023-08-19 13:27:03 -07:00
ascii.rs Add the basic ascii::Char type 2023-05-03 22:09:33 -07:00
backtrace.rs Implement UnwindSafe and RefUnwindSafe for Backtrace 2023-07-31 10:38:24 +02:00
env.rs add a csky-unknown-linux-gnuabiv2 target 2023-08-14 23:02:36 +08:00
error.rs Expose core::error::request_value in std 2023-08-18 13:06:53 -04:00
f32.rs Rollup merge of #114754 - workingjubilee:gamma-ray-logger, r=thomcc 2023-08-25 09:00:12 +02:00
f64.rs Rollup merge of #114754 - workingjubilee:gamma-ray-logger, r=thomcc 2023-08-25 09:00:12 +02:00
fs.rs Add more diagnostic items for clippy 2023-10-05 18:21:47 -04:00
keyword_docs.rs docs: Add example, reference link for type keyword. 2023-08-21 20:00:43 +07:00
lib.rs rustdoc: remove rust logo from non-Rust crates 2023-10-08 20:17:53 -07:00
macros.rs print macros: add xrefs to format syntax documentation 2023-08-28 11:51:41 +02:00
num.rs Bump version placeholders 2023-10-03 20:26:36 -04:00
panic.rs Shorten lifetime of even more panic temporaries 2023-05-15 03:47:37 -07:00
panicking.rs Rollup merge of #116008 - m-ou-se:boxmeup, r=oli-obk 2023-09-21 00:11:37 +02:00
path.rs fix(std): Rename os_str_bytes to encoded_bytes 2023-09-01 19:33:16 -05:00
process.rs Deduplicate std::process Default impl feature names 2023-10-15 11:42:28 -07:00
rt.rs Automatically enable cross-crate inlining for small functions 2023-10-17 19:53:51 -04:00
time.rs Auto merge of #116238 - tamird:gettimeofday, r=thomcc 2023-10-24 04:15:39 +00:00