Skip to content

Disallow setting some built-in cfg via the command-line#126158

Merged
bors merged 2 commits intorust-lang:masterfrom
Urgau:disallow-cfgs
Aug 7, 2024
Merged

Disallow setting some built-in cfg via the command-line#126158
bors merged 2 commits intorust-lang:masterfrom
Urgau:disallow-cfgs

Conversation

@Urgau
Copy link
Member

@Urgau Urgau commented Jun 8, 2024

This PR disallow users from setting some built-in cfg via set the command-line in order to prevent incoherent state, eg. windows cfg active but target is Linux based.

This implements MCP rust-lang/compiler-team#610, with the caveat that we disallow cfgs no matter if they make sense or not, since I don't think it's useful to allow users to set a cfg that will be set anyway. It also complicates the implementation.


The explicit_builtin_cfgs_in_flags lint detects builtin cfgs set via the --cfg flag.

(deny-by-default)

Example

rustc --cfg unix
fn main() {}

This will produce:

error: unexpected `--cfg unix` flag
  |
  = note: config `unix` is only supposed to be controlled by `--target`
  = note: manually setting a built-in cfg can and does create incoherent behaviours
  = note: `#[deny(explicit_builtin_cfgs_in_flags)]` on by default

Explanation

Setting builtin cfgs can and does produce incoherent behaviour, it's better to the use the appropriate rustc flag that controls the config. For example setting the windows cfg but on Linux based target.


r? @petrochenkov
cc @jyn514

try-job: aarch64-apple
try-job: test-various
try-job: armhf-gnu
try-job: x86_64-msvc
try-job: x86_64-mingw
try-job: i686-msvc
try-job: i686-mingw
try-job: x86_64-gnu-llvm-17
try-job: dist-various-1

@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. labels Jun 8, 2024
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 11, 2024
@Urgau Urgau force-pushed the disallow-cfgs branch 3 times, most recently from 4b6c448 to 4ebdd5c Compare June 22, 2024 13:21
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@Urgau Urgau force-pushed the disallow-cfgs branch 2 times, most recently from e63e8f7 to 30480ad Compare June 22, 2024 14:19
@Urgau
Copy link
Member Author

Urgau commented Jun 22, 2024

I've changed the error from a hard-error to a deny-by-default lint as asked and included all the possible cfgs that wouldn't break the world (and added some links for the one that we can't lint on them).

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 22, 2024
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 24, 2024
@Urgau
Copy link
Member Author

Urgau commented Jun 24, 2024

Addressed or replied to all the review comments.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 24, 2024
@petrochenkov
Copy link
Contributor

Ok, let's try landing this.
@bors r+

@bors
Copy link
Collaborator

bors commented Jun 25, 2024

📌 Commit 971cb13 has been approved by petrochenkov

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 Jun 25, 2024
@rust-log-analyzer

This comment was marked as outdated.

@bors

This comment was marked as outdated.

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 7, 2024
@Urgau
Copy link
Member Author

Urgau commented Aug 7, 2024

Another case of a revisions: containing windows/unix as revision name.
Fixed those and re-did a grep on tests/.

But just to be sure, and to not waste more CI-merge time. Let's do a big try build across many different targets.
@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 7, 2024
Disallow setting some built-in cfg via set the command-line

This PR disallow users from setting some built-in cfg via set the command-line in order to prevent incoherent state, eg. `windows` cfg active but target is Linux based.

This implements MCP rust-lang/compiler-team#610, with the caveat that we disallow cfgs no matter if they make sense or not, since I don't think it's useful to allow users to set a cfg that will be set anyway. It also complicates the implementation.

------

The `explicit_builtin_cfgs_in_flags` lint detects builtin cfgs set via the `--cfg` flag.

*(deny-by-default)*

### Example

```text
rustc --cfg unix
```

```rust,ignore (needs command line option)
fn main() {}
```

This will produce:

```text
error: unexpected `--cfg unix` flag
  |
  = note: config `unix` is only supposed to be controlled by `--target`
  = note: manually setting a built-in cfg can and does create incoherent behaviours
  = note: `#[deny(explicit_builtin_cfgs_in_flags)]` on by default
```

### Explanation

Setting builtin cfgs can and does produce incoherent behaviour, it's better to the use the appropriate `rustc` flag that controls the config. For example setting the `windows` cfg but on Linux based target.

-----

r? `@petrochenkov`
cc `@jyn514`

try-job: aarch64-apple
try-job: test-various
try-job: armhf-gnu
try-job: x86_64-msvc
try-job: x86_64-mingw
try-job: i686-msvc
try-job: i686-mingw
try-job: x86_64-gnu-llvm-17
try-job: dist-various-1
@bors
Copy link
Collaborator

bors commented Aug 7, 2024

⌛ Trying commit c0c57b3 with merge ac7969d...

@petrochenkov
Copy link
Contributor

r=me after CI is green.
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 7, 2024
@lcnr
Copy link
Contributor

lcnr commented Aug 7, 2024

@bors r=petrochenkov

@bors
Copy link
Collaborator

bors commented Aug 7, 2024

📌 Commit c0c57b3 has been approved by petrochenkov

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 7, 2024
@Urgau
Copy link
Member Author

Urgau commented Aug 7, 2024

Wait, try isn't finishing yet, and bors doesn't like r+ and try at the same time.
@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 7, 2024
@bors
Copy link
Collaborator

bors commented Aug 7, 2024

☀️ Try build successful - checks-actions
Build commit: ac7969d (ac7969db6cc18caaabd206a34b8c5034a329765d)

@Urgau
Copy link
Member Author

Urgau commented Aug 7, 2024

@bors r=petrochenkov

@bors
Copy link
Collaborator

bors commented Aug 7, 2024

📌 Commit c0c57b3 has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 7, 2024
@bors
Copy link
Collaborator

bors commented Aug 7, 2024

⌛ Testing commit c0c57b3 with merge ce20e15...

@bors
Copy link
Collaborator

bors commented Aug 7, 2024

☀️ Test successful - checks-actions
Approved by: petrochenkov
Pushing ce20e15 to master...

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (ce20e15): 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 (primary -2.6%, secondary -1.9%)

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)
3.3% [3.3%, 3.3%] 1
Improvements ✅
(primary)
-2.6% [-2.6%, -2.6%] 1
Improvements ✅
(secondary)
-3.6% [-3.7%, -3.5%] 3
All ❌✅ (primary) -2.6% [-2.6%, -2.6%] 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: 760.558s -> 760.891s (0.04%)
Artifact size: 336.96 MiB -> 336.96 MiB (0.00%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. merged-by-bors This PR was explicitly merged by bors. relnotes Marks issues that should be documented in the release notes of the next release. 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.