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

Normalize source when loading external foreign source into SourceMap #71048

Merged
merged 1 commit into from
Apr 12, 2020

Conversation

arlosi
Copy link
Contributor

@arlosi arlosi commented Apr 12, 2020

The compiler normalizes source when reading files initially (removes BOMs, etc), but not when loading external sources.

This leads to the external source matching according to the src_hash, but differing internally because it was not normalized.

Fixes #70874.

@rust-highfive
Copy link
Collaborator

r? @eddyb

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 12, 2020
Comment on lines 1188 to 1191
let src = get_src().map(|mut src| {
normalize_src(&mut src, BytePos::from_usize(0));
src
});
Copy link
Member

Choose a reason for hiding this comment

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

Can you move this inside if self.src_hash.matches(&src) {? IIRC src_hash is computed pre-normalization, so we should also check it here in the same way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, it's pretty subtle. We really do need a test for this.

Copy link
Member

Choose a reason for hiding this comment

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

There are some tests that print snippets from other crates, I think you might be able to do a search like rg auxiliary/ src/test/**.stderr to find some examples.

You can then combine that with an unnormalized file, maybe we have some normalization tests?

Copy link
Member

Choose a reason for hiding this comment

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

That is, I think we can use an error message to print a snippet and trigger this through rustc instead of rustdoc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, just saw your suggestion about how to do the test. I added one as a SourceMap test. Let me know if you'd prefer a integration-style test like you suggested, or if this is sufficient.

Copy link
Member

Choose a reason for hiding this comment

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

run-make tests are a PITA, and your test is pretty clear, so no worries.

@eddyb
Copy link
Member

eddyb commented Apr 12, 2020

cc @GuillaumeGomez It might be good to add a test, but I'm not sure it's possible right now.
Maybe a run-make test?

The compiler normalizes source when reading files initially (removes BOMs, etc), but not when loading external sources.

Fixes rust-lang#70874 by normalizing when loading external sources too. Adds a test to verify normalization.
@eddyb
Copy link
Member

eddyb commented Apr 12, 2020

@bors r+ Thanks!

@bors
Copy link
Contributor

bors commented Apr 12, 2020

📌 Commit f41aa16 has been approved by eddyb

@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 Apr 12, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 12, 2020
Rollup of 6 pull requests

Successful merges:

 - rust-lang#71029 (Partial work on building with Cargo)
 - rust-lang#71034 (Clean up E0515 explanation)
 - rust-lang#71041 (Update links of `rustc guide`)
 - rust-lang#71048 (Normalize source when loading external foreign source into SourceMap)
 - rust-lang#71053 (Add some basic docs to `sym` and `kw` modules)
 - rust-lang#71057 (Clean up E0516 explanation)

Failed merges:

r? @ghost
@bors bors merged commit 9c34740 into rust-lang:master Apr 12, 2020
@arlosi arlosi deleted the normalize_ext_src branch April 13, 2020 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cargo +nightly doc panics for crates depending on gfx-backend-empty
4 participants