Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate feature and since values inside #[stable(…)] #116773

Merged
merged 5 commits into from Oct 24, 2023

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Oct 15, 2023

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:

// src/lib.rs

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

#[unstable(feature = "kebab-case", issue = "none")]
pub struct Struct;
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:

// 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;
// src/main.rs

#![feature(kebab_case)]

use repro::Struct;

fn main() {}
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:

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

@rustbot
Copy link
Collaborator

rustbot commented Oct 15, 2023

r? @davidtwco

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 15, 2023
library/std/src/process.rs Outdated Show resolved Hide resolved
@dtolnay dtolnay removed the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Oct 15, 2023
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Oct 15, 2023

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@@ -8,7 +8,7 @@
#![feature(no_core, lang_items, intrinsics, staged_api, rustc_attrs)]
#![no_core]
#![crate_type = "lib"]
#![stable(feature = "", since = "")]
#![stable(feature = "intrinsics_for_test", since = "")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also want to validate the since?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good call. Would you want it in this PR or separately?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this PR is fine, just stack on another commit or two

@compiler-errors
Copy link
Member

r? compiler-errors

@rustbot rustbot assigned compiler-errors and unassigned davidtwco Oct 16, 2023
@dtolnay dtolnay changed the title Validate feature name identifier inside #[stable(feature = "...")] Validate feature and since values inside #[stable(…)] Oct 16, 2023
|
LL | #[rustc_const_unstable(feature = "d", issue = "none")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: invalid stability version found
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This older error comes from:

self.tcx.sess.emit_err(errors::InvalidStability { span, item_sp });

It only kicked in if there was also a deprecated attribute on the same item.

I might follow up with a separate PR to store a more structured representation for the since value than what's currently present in StabilityLevel::Stable. We can eliminate the reparsing done by rustc_passes and make that error unreachable.

Stable {
/// Rust release which stabilized this feature.
since: Symbol,

It would also be good if since could store an ExprKind::Err-like variant, because currently if since is invalid, rustc goes forward pretending the whole stable attribute does not exist, giving the bogus extra error "function has missing stability attribute".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#[deprecated(note = "a")] //~ ERROR missing 'since' [E0542]
fn f2() { }

#[stable(feature = "a", since = "b")]
#[stable(feature = "a", since = "4.4.4")]
#[deprecated(since = "a")] //~ ERROR missing 'note' [E0543]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(In a separate PR) here's another thing to check.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -48,33 +50,28 @@ pub(crate) enum UnsupportedLiteralReason {
DeprecatedKvPair,
}

fn handle_errors(sess: &ParseSess, span: Span, error: AttrError) {
fn handle_errors(sess: &ParseSess, span: Span, error: AttrError) -> ErrorGuaranteed {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we get rid of this function, and emit the errors directly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good call. #117064

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 23, 2023
Eliminate rustc_attrs::builtin::handle_errors in favor of emitting errors directly

Suggested in rust-lang#116773 (review).

This `handle_errors` function is originally from rust-lang#34531, in which it was useful because it allowed error messages and error codes (`E0542`) for multiple occurrences of the same error to be centralized in one place. For example rather than repeating this diagnostic in 2 places:

```rust
span_err!(diagnostic, attr.span, E0542, "missing 'since'");
```

one could repeat this instead:

```rust
handle_errors(diagnostic, attr.span, AttrError::MissingSince);
```

ensuring that all "missing 'since'" errors always remained consistent in message and error code.

Over time as error messages and error codes got factored to fluent diagnostics (rust-lang#100836), this rationale no longer applies. The new code has the same benefit while being less verbose (+73, -128).

```rust
sess.emit_err(session_diagnostics::MissingSince { span: attr.span });
```

r? `@cjgillot`
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Oct 23, 2023
Rollup merge of rust-lang#117064 - dtolnay:handleerrors, r=cjgillot

Eliminate rustc_attrs::builtin::handle_errors in favor of emitting errors directly

Suggested in rust-lang#116773 (review).

This `handle_errors` function is originally from rust-lang#34531, in which it was useful because it allowed error messages and error codes (`E0542`) for multiple occurrences of the same error to be centralized in one place. For example rather than repeating this diagnostic in 2 places:

```rust
span_err!(diagnostic, attr.span, E0542, "missing 'since'");
```

one could repeat this instead:

```rust
handle_errors(diagnostic, attr.span, AttrError::MissingSince);
```

ensuring that all "missing 'since'" errors always remained consistent in message and error code.

Over time as error messages and error codes got factored to fluent diagnostics (rust-lang#100836), this rationale no longer applies. The new code has the same benefit while being less verbose (+73, -128).

```rust
sess.emit_err(session_diagnostics::MissingSince { span: attr.span });
```

r? `@cjgillot`
@bors
Copy link
Contributor

bors commented Oct 23, 2023

☔ The latest upstream changes (presumably #117087) made this pull request unmergeable. Please resolve the merge conflicts.

@dtolnay
Copy link
Member Author

dtolnay commented Oct 23, 2023

@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Oct 23, 2023

📌 Commit 6a02e20 has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 23, 2023
@bors
Copy link
Contributor

bors commented Oct 24, 2023

⌛ Testing commit 6a02e20 with merge 07a4b7e...

@bors
Copy link
Contributor

bors commented Oct 24, 2023

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing 07a4b7e to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Oct 24, 2023
@bors bors merged commit 07a4b7e into rust-lang:master Oct 24, 2023
12 checks passed
@rustbot rustbot added this to the 1.75.0 milestone Oct 24, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (07a4b7e): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
4.8% [2.0%, 7.6%] 2
Improvements ✅
(primary)
-3.2% [-3.2%, -3.2%] 1
Improvements ✅
(secondary)
-1.0% [-1.0%, -1.0%] 1
All ❌✅ (primary) -3.2% [-3.2%, -3.2%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: missing data
Artifact size: 304.29 MiB -> 304.38 MiB (0.03%)

@dtolnay dtolnay deleted the validatestable branch October 24, 2023 22:50
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 26, 2023
Store #[stable] attribute's `since` value in structured form

Followup to rust-lang#116773 (review).

Prior to this PR, if you wrote an improper `since` version in a `stable` attribute, such as `#[stable(feature = "foo", since = "wat.0")]`, rustc would emit a diagnostic saying **_'since' must be a Rust version number, such as "1.31.0"_** and then throw out the whole `stable` attribute as if it weren't there. This strategy had 2 problems, both fixed in this PR:

1. If there was also a `#[deprecated]` attribute on the same item, rustc would want to enforce that the stabilization version is older than the deprecation version. This involved reparsing the `stable` attribute's `since` version, with a diagnostic **_invalid stability version found_** if it failed to parse. Of course this diagnostic was unreachable because an invalid `since` version would have already caused the `stable` attribute to be thrown out. This PR deletes that unreachable diagnostic.

2. By throwing out the `stable` attribute when `since` is invalid, you'd end up with a second diagnostic saying **_function has missing stability attribute_** even though your function is not missing a stability attribute. This PR preserves the `stable` attribute even when `since` cannot be parsed, avoiding the misleading second diagnostic.

Followups I plan to try next:

- Do the same for the `since` value of `#[deprecated]`.

- See whether it makes sense to also preserve `stable` and/or `unstable` attributes when they contain an invalid `feature`. What redundant/misleading diagnostics can this eliminate? What problems arise from not having a usable feature name for some API, in the situation that we're already failing compilation, so not concerned about anything that happens in downstream code?
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Oct 28, 2023
Store #[stable] attribute's `since` value in structured form

Followup to rust-lang/rust#116773 (review).

Prior to this PR, if you wrote an improper `since` version in a `stable` attribute, such as `#[stable(feature = "foo", since = "wat.0")]`, rustc would emit a diagnostic saying **_'since' must be a Rust version number, such as "1.31.0"_** and then throw out the whole `stable` attribute as if it weren't there. This strategy had 2 problems, both fixed in this PR:

1. If there was also a `#[deprecated]` attribute on the same item, rustc would want to enforce that the stabilization version is older than the deprecation version. This involved reparsing the `stable` attribute's `since` version, with a diagnostic **_invalid stability version found_** if it failed to parse. Of course this diagnostic was unreachable because an invalid `since` version would have already caused the `stable` attribute to be thrown out. This PR deletes that unreachable diagnostic.

2. By throwing out the `stable` attribute when `since` is invalid, you'd end up with a second diagnostic saying **_function has missing stability attribute_** even though your function is not missing a stability attribute. This PR preserves the `stable` attribute even when `since` cannot be parsed, avoiding the misleading second diagnostic.

Followups I plan to try next:

- Do the same for the `since` value of `#[deprecated]`.

- See whether it makes sense to also preserve `stable` and/or `unstable` attributes when they contain an invalid `feature`. What redundant/misleading diagnostics can this eliminate? What problems arise from not having a usable feature name for some API, in the situation that we're already failing compilation, so not concerned about anything that happens in downstream code?
bors-ferrocene bot added a commit to ferrocene/ferrocene that referenced this pull request Oct 31, 2023
74: Automated pull from upstream `master` r=tshepang a=github-actions[bot]


This PR pulls the following changes from the upstream repository:

* rust-lang/rust#117363
* rust-lang/rust#116405
* rust-lang/rust#117415
  * rust-lang/rust#117414
  * rust-lang/rust#117411
  * rust-lang/rust#117403
  * rust-lang/rust#117398
  * rust-lang/rust#117396
  * rust-lang/rust#117389
  * rust-lang/rust#116862
* rust-lang/rust#117405
  * rust-lang/rust#117395
  * rust-lang/rust#117390
  * rust-lang/rust#117383
  * rust-lang/rust#117376
  * rust-lang/rust#117370
  * rust-lang/rust#117357
  * rust-lang/rust#117356
  * rust-lang/rust#117317
  * rust-lang/rust#117132
  * rust-lang/rust#117068
  * rust-lang/rust#112463
* rust-lang/rust#117267
* rust-lang/rust#116939
* rust-lang/rust#117387
  * rust-lang/rust#117385
  * rust-lang/rust#117382
  * rust-lang/rust#117371
  * rust-lang/rust#117365
  * rust-lang/rust#117350
  * rust-lang/rust#117205
  * rust-lang/rust#117177
  * rust-lang/rust#117147
* rust-lang/rust#116485
* rust-lang/rust#117328
* rust-lang/rust#117332
* rust-lang/rust#117089
* rust-lang/rust#116733
* rust-lang/rust#116889
* rust-lang/rust#116270
* rust-lang/rust#117354
  * rust-lang/rust#117337
  * rust-lang/rust#117312
  * rust-lang/rust#117082
  * rust-lang/rust#117043
  * rust-lang/rust#115968
* rust-lang/rust#117336
  * rust-lang/rust#117325
  * rust-lang/rust#117322
  * rust-lang/rust#117259
  * rust-lang/rust#117170
* rust-lang/rust#117335
  * rust-lang/rust#117319
  * rust-lang/rust#117316
  * rust-lang/rust#117311
  * rust-lang/rust#117162
  * rust-lang/rust#115773
* rust-lang/rust#116447
* rust-lang/rust#117149
* rust-lang/rust#116240
* rust-lang/rust#117123
* rust-lang/rust#81746
* rust-lang/rust#117038
* rust-lang/rust#116609
* rust-lang/rust#117309
  * rust-lang/rust#117277
  * rust-lang/rust#117268
  * rust-lang/rust#117256
  * rust-lang/rust#117025
  * rust-lang/rust#116945
  * rust-lang/rust#116816
  * rust-lang/rust#116739
  * rust-lang/rust#116534
* rust-lang/rust#117253
* rust-lang/rust#117302
* rust-lang/rust#117197
* rust-lang/rust#116471
* rust-lang/rust#117294
  * rust-lang/rust#117287
  * rust-lang/rust#117281
  * rust-lang/rust#117270
  * rust-lang/rust#117247
  * rust-lang/rust#117246
  * rust-lang/rust#117212
  * rust-lang/rust#116834
* rust-lang/rust#103208
* rust-lang/rust#117166
* rust-lang/rust#116751
* rust-lang/rust#116858
* rust-lang/rust#117272
  * rust-lang/rust#117266
  * rust-lang/rust#117262
  * rust-lang/rust#117241
  * rust-lang/rust#117240
  * rust-lang/rust#116868
  * rust-lang/rust#114998
* rust-lang/rust#116205
* rust-lang/rust#117260
* rust-lang/rust#116035
* rust-lang/rust#113183
* rust-lang/rust#117249
  * rust-lang/rust#117243
  * rust-lang/rust#117188
  * rust-lang/rust#117114
  * rust-lang/rust#117106
  * rust-lang/rust#117032
  * rust-lang/rust#116968
* rust-lang/rust#116581
* rust-lang/rust#117228
  * rust-lang/rust#117221
  * rust-lang/rust#117214
  * rust-lang/rust#117207
  * rust-lang/rust#117202
  * rust-lang/rust#117194
  * rust-lang/rust#117143
  * rust-lang/rust#117095
  * rust-lang/rust#116905
* rust-lang/rust#117171
* rust-lang/rust#113262
* rust-lang/rust#112875
* rust-lang/rust#116983
* rust-lang/rust#117148
* rust-lang/rust#117115
* rust-lang/rust#116818
* rust-lang/rust#115872
* rust-lang/rust#117193
  * rust-lang/rust#117175
  * rust-lang/rust#117009
  * rust-lang/rust#117008
  * rust-lang/rust#116931
  * rust-lang/rust#116553
  * rust-lang/rust#116401
* rust-lang/rust#117180
  * rust-lang/rust#117173
  * rust-lang/rust#117163
  * rust-lang/rust#117159
  * rust-lang/rust#117154
  * rust-lang/rust#117152
  * rust-lang/rust#117141
  * rust-lang/rust#117111
* rust-lang/rust#117172
  * rust-lang/rust#117168
  * rust-lang/rust#117160
  * rust-lang/rust#117158
  * rust-lang/rust#117150
  * rust-lang/rust#117136
  * rust-lang/rust#117133
  * rust-lang/rust#116801
* rust-lang/rust#117165
* rust-lang/rust#117113
* rust-lang/rust#117102
* rust-lang/rust#117076
* rust-lang/rust#116236
* rust-lang/rust#116993
* rust-lang/rust#117139
* rust-lang/rust#116482
* rust-lang/rust#115796
* rust-lang/rust#117135
  * rust-lang/rust#117127
  * rust-lang/rust#117010
  * rust-lang/rust#116943
  * rust-lang/rust#116841
  * rust-lang/rust#116792
  * rust-lang/rust#116714
  * rust-lang/rust#116396
  * rust-lang/rust#116094
* rust-lang/rust#117126
  * rust-lang/rust#117105
  * rust-lang/rust#117093
  * rust-lang/rust#117092
  * rust-lang/rust#117091
  * rust-lang/rust#117081
* rust-lang/rust#116773
* rust-lang/rust#117124
* rust-lang/rust#116461
* rust-lang/rust#116435
* rust-lang/rust#116319
* rust-lang/rust#116238
* rust-lang/rust#116998
* rust-lang/rust#116300
* rust-lang/rust#117103
  * rust-lang/rust#117086
  * rust-lang/rust#117074
  * rust-lang/rust#117070
  * rust-lang/rust#117046
  * rust-lang/rust#116859
  * rust-lang/rust#107159
* rust-lang/rust#116033
* rust-lang/rust#107009
* rust-lang/rust#117087
  * rust-lang/rust#117073
  * rust-lang/rust#117064
  * rust-lang/rust#117040
  * rust-lang/rust#116978
  * rust-lang/rust#116960
* rust-lang/rust#116837
* rust-lang/rust#116835
* rust-lang/rust#116849
* rust-lang/rust#117071
  * rust-lang/rust#117069
  * rust-lang/rust#117051
  * rust-lang/rust#117049
  * rust-lang/rust#117044
  * rust-lang/rust#117042
  * rust-lang/rust#105666
* rust-lang/rust#116606
* rust-lang/rust#117066
* rust-lang/rust#115324
* rust-lang/rust#117062
* rust-lang/rust#117000
* rust-lang/rust#117007
* rust-lang/rust#117018
* rust-lang/rust#116256
* rust-lang/rust#117041
  * rust-lang/rust#117037
  * rust-lang/rust#117034
  * rust-lang/rust#116989
  * rust-lang/rust#116985
* rust-lang/rust#116950
* rust-lang/rust#116956
* rust-lang/rust#116932
* rust-lang/rust#117031
* rust-lang/rust#117030
  * rust-lang/rust#117028
  * rust-lang/rust#117026
  * rust-lang/rust#116992
  * rust-lang/rust#116981
  * rust-lang/rust#116955
  * rust-lang/rust#116928
  * rust-lang/rust#116312
* rust-lang/rust#116368
* rust-lang/rust#116922
* rust-lang/rust#117021
* rust-lang/rust#117020
  * rust-lang/rust#117019
  * rust-lang/rust#116975
  * rust-lang/rust#106601
* rust-lang/rust#116734
* rust-lang/rust#117013
  * rust-lang/rust#116995
  * rust-lang/rust#116990
  * rust-lang/rust#116974
  * rust-lang/rust#116964
  * rust-lang/rust#116961
  * rust-lang/rust#116917
  * rust-lang/rust#116911
  * rust-lang/rust#114521
* rust-lang/rust#117011
* rust-lang/rust#116958
* rust-lang/rust#116951
* rust-lang/rust#116966
* rust-lang/rust#116965
* rust-lang/rust#116962
* rust-lang/rust#116946
* rust-lang/rust#116899
* rust-lang/rust#116785
* rust-lang/rust#116838
* rust-lang/rust#116875
* rust-lang/rust#116874
* rust-lang/rust#115214
* rust-lang/rust#116810
* rust-lang/rust#116940
  * rust-lang/rust#116921
  * rust-lang/rust#116906
  * rust-lang/rust#116896
  * rust-lang/rust#116650
* rust-lang/rust#116132
* rust-lang/rust#116037
* rust-lang/rust#116923
  * rust-lang/rust#116912
  * rust-lang/rust#116908
  * rust-lang/rust#116883
  * rust-lang/rust#116829
  * rust-lang/rust#116795
  * rust-lang/rust#116761
  * rust-lang/rust#116663
* rust-lang/rust#114534
* rust-lang/rust#116402
* rust-lang/rust#116493
* rust-lang/rust#116046
* rust-lang/rust#116887
* rust-lang/rust#116885
  * rust-lang/rust#116879
  * rust-lang/rust#116870
  * rust-lang/rust#116865
  * rust-lang/rust#116856
  * rust-lang/rust#116812
* rust-lang/rust#116815
* rust-lang/rust#116814
* rust-lang/rust#116713
* rust-lang/rust#116830



Co-authored-by: Matthias Krüger <matthias.krueger@famsik.de>
Co-authored-by: antoyo <antoyo@users.noreply.github.com>
Co-authored-by: Antoni Boucher <bouanto@zoho.com>
Co-authored-by: bors <bors@rust-lang.org>
Co-authored-by: Esteban Küber <esteban@kuber.com.ar>
Co-authored-by: Kjetil Kjeka <kjetilkjeka@gmail.com>
Co-authored-by: clubby789 <jamie@hill-daniel.co.uk>
Co-authored-by: okaneco <47607823+okaneco@users.noreply.github.com>
Co-authored-by: David Tolnay <dtolnay@gmail.com>
Co-authored-by: Nadrieril <nadrieril+git@gmail.com>
Co-authored-by: Celina G. Val <celinval@amazon.com>
Co-authored-by: Ralf Jung <post@ralfj.de>
Co-authored-by: Zalathar <Zalathar@users.noreply.github.com>
Co-authored-by: Havard Eidnes <he@NetBSD.org>
Co-authored-by: Jacob Pratt <jacob@jhpratt.dev>
Co-authored-by: Kjetil Kjeka <kjetil@muybridge.com>
bors-ferrocene bot added a commit to ferrocene/ferrocene that referenced this pull request Oct 31, 2023
74: Automated pull from upstream `master` r=tshepang a=github-actions[bot]


This PR pulls the following changes from the upstream repository:

* rust-lang/rust#117363
* rust-lang/rust#116405
* rust-lang/rust#117415
  * rust-lang/rust#117414
  * rust-lang/rust#117411
  * rust-lang/rust#117403
  * rust-lang/rust#117398
  * rust-lang/rust#117396
  * rust-lang/rust#117389
  * rust-lang/rust#116862
* rust-lang/rust#117405
  * rust-lang/rust#117395
  * rust-lang/rust#117390
  * rust-lang/rust#117383
  * rust-lang/rust#117376
  * rust-lang/rust#117370
  * rust-lang/rust#117357
  * rust-lang/rust#117356
  * rust-lang/rust#117317
  * rust-lang/rust#117132
  * rust-lang/rust#117068
  * rust-lang/rust#112463
* rust-lang/rust#117267
* rust-lang/rust#116939
* rust-lang/rust#117387
  * rust-lang/rust#117385
  * rust-lang/rust#117382
  * rust-lang/rust#117371
  * rust-lang/rust#117365
  * rust-lang/rust#117350
  * rust-lang/rust#117205
  * rust-lang/rust#117177
  * rust-lang/rust#117147
* rust-lang/rust#116485
* rust-lang/rust#117328
* rust-lang/rust#117332
* rust-lang/rust#117089
* rust-lang/rust#116733
* rust-lang/rust#116889
* rust-lang/rust#116270
* rust-lang/rust#117354
  * rust-lang/rust#117337
  * rust-lang/rust#117312
  * rust-lang/rust#117082
  * rust-lang/rust#117043
  * rust-lang/rust#115968
* rust-lang/rust#117336
  * rust-lang/rust#117325
  * rust-lang/rust#117322
  * rust-lang/rust#117259
  * rust-lang/rust#117170
* rust-lang/rust#117335
  * rust-lang/rust#117319
  * rust-lang/rust#117316
  * rust-lang/rust#117311
  * rust-lang/rust#117162
  * rust-lang/rust#115773
* rust-lang/rust#116447
* rust-lang/rust#117149
* rust-lang/rust#116240
* rust-lang/rust#117123
* rust-lang/rust#81746
* rust-lang/rust#117038
* rust-lang/rust#116609
* rust-lang/rust#117309
  * rust-lang/rust#117277
  * rust-lang/rust#117268
  * rust-lang/rust#117256
  * rust-lang/rust#117025
  * rust-lang/rust#116945
  * rust-lang/rust#116816
  * rust-lang/rust#116739
  * rust-lang/rust#116534
* rust-lang/rust#117253
* rust-lang/rust#117302
* rust-lang/rust#117197
* rust-lang/rust#116471
* rust-lang/rust#117294
  * rust-lang/rust#117287
  * rust-lang/rust#117281
  * rust-lang/rust#117270
  * rust-lang/rust#117247
  * rust-lang/rust#117246
  * rust-lang/rust#117212
  * rust-lang/rust#116834
* rust-lang/rust#103208
* rust-lang/rust#117166
* rust-lang/rust#116751
* rust-lang/rust#116858
* rust-lang/rust#117272
  * rust-lang/rust#117266
  * rust-lang/rust#117262
  * rust-lang/rust#117241
  * rust-lang/rust#117240
  * rust-lang/rust#116868
  * rust-lang/rust#114998
* rust-lang/rust#116205
* rust-lang/rust#117260
* rust-lang/rust#116035
* rust-lang/rust#113183
* rust-lang/rust#117249
  * rust-lang/rust#117243
  * rust-lang/rust#117188
  * rust-lang/rust#117114
  * rust-lang/rust#117106
  * rust-lang/rust#117032
  * rust-lang/rust#116968
* rust-lang/rust#116581
* rust-lang/rust#117228
  * rust-lang/rust#117221
  * rust-lang/rust#117214
  * rust-lang/rust#117207
  * rust-lang/rust#117202
  * rust-lang/rust#117194
  * rust-lang/rust#117143
  * rust-lang/rust#117095
  * rust-lang/rust#116905
* rust-lang/rust#117171
* rust-lang/rust#113262
* rust-lang/rust#112875
* rust-lang/rust#116983
* rust-lang/rust#117148
* rust-lang/rust#117115
* rust-lang/rust#116818
* rust-lang/rust#115872
* rust-lang/rust#117193
  * rust-lang/rust#117175
  * rust-lang/rust#117009
  * rust-lang/rust#117008
  * rust-lang/rust#116931
  * rust-lang/rust#116553
  * rust-lang/rust#116401
* rust-lang/rust#117180
  * rust-lang/rust#117173
  * rust-lang/rust#117163
  * rust-lang/rust#117159
  * rust-lang/rust#117154
  * rust-lang/rust#117152
  * rust-lang/rust#117141
  * rust-lang/rust#117111
* rust-lang/rust#117172
  * rust-lang/rust#117168
  * rust-lang/rust#117160
  * rust-lang/rust#117158
  * rust-lang/rust#117150
  * rust-lang/rust#117136
  * rust-lang/rust#117133
  * rust-lang/rust#116801
* rust-lang/rust#117165
* rust-lang/rust#117113
* rust-lang/rust#117102
* rust-lang/rust#117076
* rust-lang/rust#116236
* rust-lang/rust#116993
* rust-lang/rust#117139
* rust-lang/rust#116482
* rust-lang/rust#115796
* rust-lang/rust#117135
  * rust-lang/rust#117127
  * rust-lang/rust#117010
  * rust-lang/rust#116943
  * rust-lang/rust#116841
  * rust-lang/rust#116792
  * rust-lang/rust#116714
  * rust-lang/rust#116396
  * rust-lang/rust#116094
* rust-lang/rust#117126
  * rust-lang/rust#117105
  * rust-lang/rust#117093
  * rust-lang/rust#117092
  * rust-lang/rust#117091
  * rust-lang/rust#117081
* rust-lang/rust#116773
* rust-lang/rust#117124
* rust-lang/rust#116461
* rust-lang/rust#116435
* rust-lang/rust#116319
* rust-lang/rust#116238
* rust-lang/rust#116998
* rust-lang/rust#116300
* rust-lang/rust#117103
  * rust-lang/rust#117086
  * rust-lang/rust#117074
  * rust-lang/rust#117070
  * rust-lang/rust#117046
  * rust-lang/rust#116859
  * rust-lang/rust#107159
* rust-lang/rust#116033
* rust-lang/rust#107009
* rust-lang/rust#117087
  * rust-lang/rust#117073
  * rust-lang/rust#117064
  * rust-lang/rust#117040
  * rust-lang/rust#116978
  * rust-lang/rust#116960
* rust-lang/rust#116837
* rust-lang/rust#116835
* rust-lang/rust#116849
* rust-lang/rust#117071
  * rust-lang/rust#117069
  * rust-lang/rust#117051
  * rust-lang/rust#117049
  * rust-lang/rust#117044
  * rust-lang/rust#117042
  * rust-lang/rust#105666
* rust-lang/rust#116606
* rust-lang/rust#117066
* rust-lang/rust#115324
* rust-lang/rust#117062
* rust-lang/rust#117000
* rust-lang/rust#117007
* rust-lang/rust#117018
* rust-lang/rust#116256
* rust-lang/rust#117041
  * rust-lang/rust#117037
  * rust-lang/rust#117034
  * rust-lang/rust#116989
  * rust-lang/rust#116985
* rust-lang/rust#116950
* rust-lang/rust#116956
* rust-lang/rust#116932
* rust-lang/rust#117031
* rust-lang/rust#117030
  * rust-lang/rust#117028
  * rust-lang/rust#117026
  * rust-lang/rust#116992
  * rust-lang/rust#116981
  * rust-lang/rust#116955
  * rust-lang/rust#116928
  * rust-lang/rust#116312
* rust-lang/rust#116368
* rust-lang/rust#116922
* rust-lang/rust#117021
* rust-lang/rust#117020
  * rust-lang/rust#117019
  * rust-lang/rust#116975
  * rust-lang/rust#106601
* rust-lang/rust#116734
* rust-lang/rust#117013
  * rust-lang/rust#116995
  * rust-lang/rust#116990
  * rust-lang/rust#116974
  * rust-lang/rust#116964
  * rust-lang/rust#116961
  * rust-lang/rust#116917
  * rust-lang/rust#116911
  * rust-lang/rust#114521
* rust-lang/rust#117011
* rust-lang/rust#116958
* rust-lang/rust#116951
* rust-lang/rust#116966
* rust-lang/rust#116965
* rust-lang/rust#116962
* rust-lang/rust#116946
* rust-lang/rust#116899
* rust-lang/rust#116785
* rust-lang/rust#116838
* rust-lang/rust#116875
* rust-lang/rust#116874
* rust-lang/rust#115214
* rust-lang/rust#116810
* rust-lang/rust#116940
  * rust-lang/rust#116921
  * rust-lang/rust#116906
  * rust-lang/rust#116896
  * rust-lang/rust#116650
* rust-lang/rust#116132
* rust-lang/rust#116037
* rust-lang/rust#116923
  * rust-lang/rust#116912
  * rust-lang/rust#116908
  * rust-lang/rust#116883
  * rust-lang/rust#116829
  * rust-lang/rust#116795
  * rust-lang/rust#116761
  * rust-lang/rust#116663
* rust-lang/rust#114534
* rust-lang/rust#116402
* rust-lang/rust#116493
* rust-lang/rust#116046
* rust-lang/rust#116887
* rust-lang/rust#116885
  * rust-lang/rust#116879
  * rust-lang/rust#116870
  * rust-lang/rust#116865
  * rust-lang/rust#116856
  * rust-lang/rust#116812
* rust-lang/rust#116815
* rust-lang/rust#116814
* rust-lang/rust#116713
* rust-lang/rust#116830



Co-authored-by: antoyo <antoyo@users.noreply.github.com>
Co-authored-by: Antoni Boucher <bouanto@zoho.com>
Co-authored-by: bors <bors@rust-lang.org>
Co-authored-by: Esteban Küber <esteban@kuber.com.ar>
Co-authored-by: Kjetil Kjeka <kjetilkjeka@gmail.com>
Co-authored-by: clubby789 <jamie@hill-daniel.co.uk>
Co-authored-by: okaneco <47607823+okaneco@users.noreply.github.com>
Co-authored-by: David Tolnay <dtolnay@gmail.com>
Co-authored-by: Nadrieril <nadrieril+git@gmail.com>
Co-authored-by: Celina G. Val <celinval@amazon.com>
Co-authored-by: Ralf Jung <post@ralfj.de>
Co-authored-by: Zalathar <Zalathar@users.noreply.github.com>
Co-authored-by: Havard Eidnes <he@NetBSD.org>
Co-authored-by: Jacob Pratt <jacob@jhpratt.dev>
Co-authored-by: Kjetil Kjeka <kjetil@muybridge.com>
Co-authored-by: Matthias Krüger <matthias.krueger@famsik.de>
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Nov 2, 2023
Store #[stable] attribute's `since` value in structured form

Followup to rust-lang/rust#116773 (review).

Prior to this PR, if you wrote an improper `since` version in a `stable` attribute, such as `#[stable(feature = "foo", since = "wat.0")]`, rustc would emit a diagnostic saying **_'since' must be a Rust version number, such as "1.31.0"_** and then throw out the whole `stable` attribute as if it weren't there. This strategy had 2 problems, both fixed in this PR:

1. If there was also a `#[deprecated]` attribute on the same item, rustc would want to enforce that the stabilization version is older than the deprecation version. This involved reparsing the `stable` attribute's `since` version, with a diagnostic **_invalid stability version found_** if it failed to parse. Of course this diagnostic was unreachable because an invalid `since` version would have already caused the `stable` attribute to be thrown out. This PR deletes that unreachable diagnostic.

2. By throwing out the `stable` attribute when `since` is invalid, you'd end up with a second diagnostic saying **_function has missing stability attribute_** even though your function is not missing a stability attribute. This PR preserves the `stable` attribute even when `since` cannot be parsed, avoiding the misleading second diagnostic.

Followups I plan to try next:

- Do the same for the `since` value of `#[deprecated]`.

- See whether it makes sense to also preserve `stable` and/or `unstable` attributes when they contain an invalid `feature`. What redundant/misleading diagnostics can this eliminate? What problems arise from not having a usable feature name for some API, in the situation that we're already failing compilation, so not concerned about anything that happens in downstream code?
flip1995 pushed a commit to flip1995/rust that referenced this pull request Nov 2, 2023
…rrors

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
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants