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

Avoid blessing cargo deps's source code in ui tests #115869

Merged
merged 2 commits into from
Sep 19, 2023

Conversation

pietroalbini
Copy link
Member

Before this PR, the source code of dependencies was included in UI test error messages whenever possible. Unfortunately, "whenever possible" means in some cases the source code wouldn't be injected, resulting in a test failure.

One such case is when $CARGO_HOME is remapped to something that is not present on disk 1. As the remapped path doesn't exist on disk, the source code wouldn't be showed in tests/ui/issues/issue-21763.rs:

    = note: required for `hashbrown::raw::RawTable<(Rc<()>, Rc<()>)>` to implement `Send`
 note: required because it appears within the type `HashMap<Rc<()>, Rc<()>, RandomState>`
   --> $HASHBROWN_SRC_LOCATION
-   |
-LL | pub struct HashMap<K, V, S = DefaultHashBuilder, A: Allocator + Clone = Global> {
-   |            ^^^^^^^
 note: required because it appears within the type `HashMap<Rc<()>, Rc<()>>`
   --> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL
 note: required by a bound in `foo`

This PR fixes the problem by always hiding dependencies source code in the error messages generated during UI tests. This is implemented with a new internal flag, -Z ignore-directory-in-diagnostics-source-blocks=$path, which compiletest passes during UI tests. Once this is merged, remapping the Cargo home will be supported.

This PR is best reviewed commit-by-commit.

Footnotes

  1. After being puzzled for a bit, I discovered why this never impacted rust-lang/rust: we don't remap $CARGO_HOME 😅. Instead, we set $CARGO_HOME to /cargo in CI, which sort-of-but-not-really achieves the same effect.

@rustbot
Copy link
Collaborator

rustbot commented Sep 15, 2023

r? @compiler-errors

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

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 15, 2023
@rustbot
Copy link
Collaborator

rustbot commented Sep 15, 2023

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Sep 18, 2023

📌 Commit c230637 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 Sep 18, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 19, 2023
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#115869 (Avoid blessing cargo deps's source code in ui tests)
 - rust-lang#115873 (Make `TyKind::Adt`'s `Debug` impl be more pretty)
 - rust-lang#115879 (Migrate diagnostics in `hir_typeck/src/cast.rs`)
 - rust-lang#115930 (coverage: Fix an unstable-sort inconsistency in coverage spans)
 - rust-lang#115931 (Move mobile topbar title creation entirely into JS)
 - rust-lang#115941 (Add myself to .mailmap)
 - rust-lang#115943 (compiletest: Don't swallow some error messages.)
 - rust-lang#115949 (Update browser-ui-test version)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 0eec5e3 into rust-lang:master Sep 19, 2023
11 checks passed
@rustbot rustbot added this to the 1.74.0 milestone Sep 19, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Sep 19, 2023
Rollup merge of rust-lang#115869 - ferrocene:pa-fix-tests-cargo-remap, r=compiler-errors

Avoid blessing cargo deps's source code in ui tests

Before this PR, the source code of dependencies was included in UI test error messages whenever possible. Unfortunately, "whenever possible" means in some cases the source code wouldn't be injected, resulting in a test failure.

One such case is when `$CARGO_HOME` is remapped to something that is not present on disk [^1]. As the remapped path doesn't exist on disk, the source code wouldn't be showed in `tests/ui/issues/issue-21763.rs`:

```diff
    = note: required for `hashbrown::raw::RawTable<(Rc<()>, Rc<()>)>` to implement `Send`
 note: required because it appears within the type `HashMap<Rc<()>, Rc<()>, RandomState>`
   --> $HASHBROWN_SRC_LOCATION
-   |
-LL | pub struct HashMap<K, V, S = DefaultHashBuilder, A: Allocator + Clone = Global> {
-   |            ^^^^^^^
 note: required because it appears within the type `HashMap<Rc<()>, Rc<()>>`
   --> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL
 note: required by a bound in `foo`
```

This PR fixes the problem by always hiding dependencies source code in the error messages generated during UI tests. This is implemented with a new internal flag, `-Z ignore-directory-in-diagnostics-source-blocks=$path`, which compiletest passes during UI tests. Once this is merged, remapping the Cargo home will be supported.

This PR is best reviewed commit-by-commit.

[^1]: After being puzzled for a bit, I discovered why this never impacted `rust-lang/rust`: we don't remap `$CARGO_HOME` :sweat_smile:. Instead, we set `$CARGO_HOME` to `/cargo` in CI, which sort-of-but-not-really achieves the same effect.
@tshepang tshepang deleted the pa-fix-tests-cargo-remap branch September 19, 2023 05:30
@xry111
Copy link
Contributor

xry111 commented Nov 17, 2023

Hmm, I'm still seeing this test failure with 1.74.0. I guess it's because I'm using vendor = true? Should we exclude vendor directory as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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.

5 participants