Skip to content

Detect more cfgd out items in resolution errors #129183

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

Merged
merged 5 commits into from
Aug 2, 2025

Conversation

estebank
Copy link
Contributor

Use a visitor to collect all items (including those nested) that were stripped behind a cfg condition.

error[E0425]: cannot find function `f` in this scope
  --> $DIR/nested-cfg-attrs.rs:4:13
   |
LL | fn main() { f() }
   |             ^ not found in this scope
   |
note: found an item that was configured out
  --> $DIR/nested-cfg-attrs.rs:2:4
   |
LL | fn f() {}
   |    ^
note: the item is gated here
  --> $DIR/nested-cfg-attrs.rs:1:35
   |
LL | #[cfg_attr(all(), cfg_attr(all(), cfg(FALSE)))]
   |                                   ^^^^^^^^^^

@rustbot
Copy link
Collaborator

rustbot commented Aug 17, 2024

r? @cjgillot

rustbot has assigned @cjgillot.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Aug 17, 2024
@petrochenkov petrochenkov self-assigned this Aug 17, 2024
@@ -1,7 +1,7 @@
pub mod inner {
#[cfg(FALSE)]
#[cfg(FALSE)] //~ NOTE the item is gated here
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is correct? no one ever references this item.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is because uwu under inner::gone now gets included for inner (because gone is cfgd out) when trying to access inner::uwu. I believe this is the right thing to do. If the user had written inner::gone::uwu, the output is:

error[E0433]: failed to resolve: could not find `gone` in `inner`
  --> tests/ui/cfg/diagnostics-reexport.rs:38:12
   |
38 |     inner::gone::uwu(); //~ ERROR cannot find function
   |            ^^^^ could not find `gone` in `inner`
   |
note: found an item that was configured out
  --> tests/ui/cfg/diagnostics-reexport.rs:3:9
   |
3  |     mod gone {
   |         ^^^^
note: the item is gated here
  --> tests/ui/cfg/diagnostics-reexport.rs:2:5
   |
2  |     #[cfg(FALSE)] //~ NOTE the item is gated here
   |     ^^^^^^^^^^^^^

but if it is inner::gon::uwu then the output is

error[E0433]: failed to resolve: could not find `gon` in `inner`
  --> tests/ui/cfg/diagnostics-reexport.rs:38:12
   |
38 |     inner::gon::uwu(); //~ ERROR cannot find function
   |            ^^^ could not find `gon` in `inner`

We might actually want to still search for cfgd out items both with levenshtein distance (but the signal there is much weaker) and by looking at the very last path segment (to find the cfgd out uwu).

Copy link
Contributor

Choose a reason for hiding this comment

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

I tend to agree with @Noratrieb: the user wrote inner::uwu, which refers to the use super::uwu below, which already failed to resolve without suggesting gone. Either both suggest gone::uwu, or none of them.

@petrochenkov
Copy link
Contributor

We are doing more work on a good path here.
@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 20, 2024
@petrochenkov petrochenkov removed their assignment Aug 20, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 20, 2024
Detect more `cfg`d out items in resolution errors

Use a visitor to collect *all* items (including those nested) that were stripped behind a `cfg` condition.

```
error[E0425]: cannot find function `f` in this scope
  --> $DIR/nested-cfg-attrs.rs:4:13
   |
LL | fn main() { f() }
   |             ^ not found in this scope
   |
note: found an item that was configured out
  --> $DIR/nested-cfg-attrs.rs:2:4
   |
LL | fn f() {}
   |    ^
note: the item is gated here
  --> $DIR/nested-cfg-attrs.rs:1:35
   |
LL | #[cfg_attr(all(), cfg_attr(all(), cfg(FALSE)))]
   |                                   ^^^^^^^^^^
```
@bors
Copy link
Collaborator

bors commented Aug 20, 2024

⌛ Trying commit 95c2b46 with merge 623e6c7...

@bors
Copy link
Collaborator

bors commented Aug 20, 2024

☀️ Try build successful - checks-actions
Build commit: 623e6c7 (623e6c7b5c223cff0a4b75919463e800e0563a50)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (623e6c7): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.2% [0.2%, 0.2%] 1
Regressions ❌
(secondary)
1.9% [1.9%, 1.9%] 1
Improvements ✅
(primary)
-0.2% [-0.3%, -0.2%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.1% [-0.3%, 0.2%] 3

Max RSS (memory usage)

Results (primary 2.6%, secondary 1.5%)

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)
2.6% [1.8%, 3.3%] 3
Regressions ❌
(secondary)
3.1% [1.7%, 4.3%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.8% [-4.8%, -4.8%] 1
All ❌✅ (primary) 2.6% [1.8%, 3.3%] 3

Cycles

Results (secondary -2.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)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.9% [-3.1%, -2.6%] 6
All ❌✅ (primary) - - 0

Binary size

Results (primary 0.1%)

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.1% [0.0%, 0.4%] 83
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [0.0%, 0.4%] 83

Bootstrap: 749.153s -> 748.829s (-0.04%)
Artifact size: 338.89 MiB -> 338.83 MiB (-0.02%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Aug 20, 2024
@estebank
Copy link
Contributor Author

It might make sense to limit the visitor to two levels of nesting at most, as a way to attempt to reduce the impact on crates that have large modules cfgd out. I suspect that we might not have any test case of a large crate in that configuration, and that's why we're not seeing more effects from this change.

@estebank
Copy link
Contributor Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 28, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 28, 2024
Detect more `cfg`d out items in resolution errors

Use a visitor to collect *all* items (including those nested) that were stripped behind a `cfg` condition.

```
error[E0425]: cannot find function `f` in this scope
  --> $DIR/nested-cfg-attrs.rs:4:13
   |
LL | fn main() { f() }
   |             ^ not found in this scope
   |
note: found an item that was configured out
  --> $DIR/nested-cfg-attrs.rs:2:4
   |
LL | fn f() {}
   |    ^
note: the item is gated here
  --> $DIR/nested-cfg-attrs.rs:1:35
   |
LL | #[cfg_attr(all(), cfg_attr(all(), cfg(FALSE)))]
   |                                   ^^^^^^^^^^
```
@bors
Copy link
Collaborator

bors commented Aug 28, 2024

⌛ Trying commit 0e22c73 with merge 811a696...

@bors
Copy link
Collaborator

bors commented Aug 29, 2024

☀️ Try build successful - checks-actions
Build commit: 811a696 (811a69609bf7d38bbab02fa8f4d3b4cb98802f24)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (811a696): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.2% [0.2%, 0.3%] 4
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.3%] 1
All ❌✅ (primary) 0.2% [0.2%, 0.3%] 4

Max RSS (memory usage)

Results (primary 1.6%, secondary 2.3%)

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)
1.6% [0.6%, 2.6%] 4
Regressions ❌
(secondary)
2.3% [2.1%, 2.7%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.6% [0.6%, 2.6%] 4

Cycles

Results (secondary -2.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)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.9% [-3.4%, -2.6%] 14
All ❌✅ (primary) - - 0

Binary size

Results (primary 0.1%)

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.1% [0.0%, 0.5%] 83
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [0.0%, 0.5%] 83

Bootstrap: 753.9s -> 754.227s (0.04%)
Artifact size: 338.87 MiB -> 339.03 MiB (0.05%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 29, 2024
@Dylan-DPC Dylan-DPC 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 Feb 16, 2025
@bors

This comment was marked as resolved.

@apiraino
Copy link
Contributor

apiraino commented Apr 8, 2025

@Noratrieb @Urgau given you left some comments, do you have capacity to help reviewing here? I am going to reroll the review assignment but feel free to take it 🙂 thanks

r? compiler

@rustbot rustbot assigned davidtwco and unassigned cjgillot Apr 8, 2025
@davidtwco
Copy link
Member

With previous reviews, this looks good to me, r=me after rebase.

@davidtwco davidtwco 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 Apr 17, 2025
Use a visitor to collect *all* items (including those nested) that were stripped behind a `cfg` condition.

```
error[E0425]: cannot find function `f` in this scope
  --> $DIR/nested-cfg-attrs.rs:4:13
   |
LL | fn main() { f() }
   |             ^ not found in this scope
   |
note: found an item that was configured out
  --> $DIR/nested-cfg-attrs.rs:2:4
   |
LL | fn f() {}
   |    ^
note: the item is gated here
  --> $DIR/nested-cfg-attrs.rs:1:35
   |
LL | #[cfg_attr(all(), cfg_attr(all(), cfg(FALSE)))]
   |                                   ^^^^^^^^^^
```
```
error[E0433]: failed to resolve: could not find `doesnt_exist` in `inner`
  --> $DIR/diagnostics-cross-crate.rs:18:23
   |
LL |     cfged_out::inner::doesnt_exist::hello();
   |                       ^^^^^^^^^^^^ could not find `doesnt_exist` in `inner`
   |
note: found an item that was configured out
  --> $DIR/auxiliary/cfged_out.rs:6:13
   |
LL |     #[cfg(false)]
   |           ----- the item is gated here
LL |     pub mod doesnt_exist {
   |             ^^^^^^^^^^^^
```
@estebank
Copy link
Contributor Author

estebank commented Aug 2, 2025

@bors r=davidtwco

@bors
Copy link
Collaborator

bors commented Aug 2, 2025

📌 Commit 4b24c4b has been approved by davidtwco

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 2, 2025
@bors
Copy link
Collaborator

bors commented Aug 2, 2025

⌛ Testing commit 4b24c4b with merge 889701d...

@bors
Copy link
Collaborator

bors commented Aug 2, 2025

☀️ Test successful - checks-actions
Approved by: davidtwco
Pushing 889701d to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 2, 2025
@bors bors merged commit 889701d into rust-lang:master Aug 2, 2025
11 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Aug 2, 2025
Copy link
Contributor

github-actions bot commented Aug 2, 2025

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing c23f07d (parent) -> 889701d (this PR)

Test differences

Show 12 test diffs

12 doctest diffs were found. These are ignored, as they are noisy.

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 889701db1ff614160314734fe4138c2f820a95bb --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. x86_64-apple-2: 5441.6s -> 3689.5s (-32.2%)
  2. dist-aarch64-apple: 5605.8s -> 7278.2s (29.8%)
  3. x86_64-apple-1: 9579.5s -> 7060.2s (-26.3%)
  4. pr-check-1: 1774.1s -> 1483.2s (-16.4%)
  5. aarch64-gnu-llvm-19-1: 3905.4s -> 3305.3s (-15.4%)
  6. x86_64-rust-for-linux: 2971.1s -> 2579.4s (-13.2%)
  7. pr-check-2: 2749.8s -> 2389.9s (-13.1%)
  8. dist-apple-various: 4167.4s -> 4582.7s (10.0%)
  9. x86_64-gnu-llvm-19-2: 6253.5s -> 5631.0s (-10.0%)
  10. aarch64-gnu-llvm-19-2: 2393.7s -> 2162.4s (-9.7%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (889701d): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
1.3% [1.3%, 1.3%] 1
Regressions ❌
(secondary)
1.3% [1.3%, 1.3%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.3% [1.3%, 1.3%] 1

Max RSS (memory usage)

Results (primary 6.9%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
6.9% [6.9%, 6.9%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 6.9% [6.9%, 6.9%] 1

Cycles

Results (secondary -3.5%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.1% [2.1%, 2.1%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-9.1% [-9.1%, -9.1%] 1
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 468.795s -> 467.526s (-0.27%)
Artifact size: 376.84 MiB -> 376.82 MiB (-0.01%)

@rustbot rustbot removed the perf-regression Performance regression. label Aug 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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.

Diagnostic doesn't mention cfg'ed out items if the unresolved path is simple (i.e., a single identifier)