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

Fix stray notes when the source code is not available #87088

Merged
merged 1 commit into from
Sep 11, 2021

Conversation

FabianWolff
Copy link
Contributor

Fixes #87060. To reproduce it with a local build of rustc, you have to copy the compiler (e.g. build/x86_64-unknown-linux-gnu/stage1/) somewhere and then rename the compiler source directory (maybe there is a smarter way as well). Then, rustc won't find the standard library sources and report stray notes such as

note: deref defined here

with no location for "here". Another example I've found is this:

use std::ops::Add;

fn foo<T: Add<Output=()>>(x: T) {
    x + x;
}

fn main() {}
error[E0382]: use of moved value: `x`
  --> binop.rs:4:9
   |
3  | fn foo<T: Add<Output=()>>(x: T) {
   |                           - move occurs because `x` has type `T`, which does not implement the `Copy` trait
4  |     x + x;
   |     ----^
   |     |   |
   |     |   value used here after move
   |     `x` moved due to usage in operator
   |
note: calling this operator moves the left-hand side
help: consider further restricting this bound
   |
3  | fn foo<T: Add<Output=()> + Copy>(x: T) {
   |                          ^^^^^^

error: aborting due to previous error

where, again, the note is supposed to point somewhere but doesn't. I have fixed this by checking whether the corresponding source code is actually available before emitting the note.

@rust-highfive
Copy link
Collaborator

r? @estebank

(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 Jul 12, 2021
@JohnCSimon JohnCSimon 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 Jul 31, 2021
@JohnCSimon JohnCSimon 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 Aug 15, 2021
@inquisitivecrystal inquisitivecrystal added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Aug 24, 2021
@bors
Copy link
Contributor

bors commented Sep 9, 2021

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

@jackh726
Copy link
Member

jackh726 commented Sep 9, 2021

Any way to write a test for this?

Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

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

r=me after rebase

Comment on lines 195 to 203
// Check whether the source is accessible
if self
.infcx
.tcx
.sess
.source_map()
.span_to_snippet(self_arg.span)
.is_ok()
{
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice if we could add something akin to span_note_with_alternative so that we could provide a fallback span.

@jackh726
Copy link
Member

jackh726 commented Sep 9, 2021

@bors r=estebank

@bors
Copy link
Contributor

bors commented Sep 9, 2021

📌 Commit 57fcb2e has been approved by estebank

@bors
Copy link
Contributor

bors commented Sep 9, 2021

🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened.

@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 9, 2021
@estebank
Copy link
Contributor

Any way to write a test for this?

It would likely require a Makefile test that uses extern crates and mucks around with its path after building.

bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 11, 2021
…arth

Rollup of 15 pull requests

Successful merges:

 - rust-lang#85200 (Ignore derived Clone and Debug implementations during dead code analysis)
 - rust-lang#86165 (Add proc_macro::Span::{before, after}.)
 - rust-lang#87088 (Fix stray notes when the source code is not available)
 - rust-lang#87441 (Emit suggestion when passing byte literal to format macro)
 - rust-lang#88546 (Emit proper errors when on missing closure braces)
 - rust-lang#88578 (fix(rustc): suggest `items` be borrowed in `for i in items[x..]`)
 - rust-lang#88632 (Fix issues with Markdown summary options)
 - rust-lang#88639 (rustdoc: Fix ICE with `doc(hidden)` on tuple variant fields)
 - rust-lang#88667 (Tweak `write_fmt` doc.)
 - rust-lang#88720 (Rustdoc coverage fields count)
 - rust-lang#88732 (RustWrapper: avoid deleted unclear attribute methods)
 - rust-lang#88742 (Fix table in docblocks)
 - rust-lang#88776 (Workaround blink/chromium grid layout limitation of 1000 rows)
 - rust-lang#88807 (Fix typo in docs for iterators)
 - rust-lang#88812 (Fix typo `option` -> `options`.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit e422612 into rust-lang:master Sep 11, 2021
@rustbot rustbot added this to the 1.57.0 milestone Sep 11, 2021
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 28, 2021
Hide `<...> defined here` note if the source is not available

Fixes rust-lang#89159. Similar to rust-lang#87088.

r? `@estebank`
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 28, 2021
Hide `<...> defined here` note if the source is not available

Fixes rust-lang#89159. Similar to rust-lang#87088.

r? ``@estebank``
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 1, 2021
…l, r=cjgillot

Improve error message for `E0659` if the source is not available

Fixes rust-lang#91028. The fix is similar to those in rust-lang#89233 and rust-lang#87088. With this change, instead of the dangling
```
note: `Option` could also refer to the enum defined here
```
I get
```
note: `Option` could also refer to an enum from prelude
```
If the standard library source code _is_ available, the output does not change.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 1, 2021
…l, r=cjgillot

Improve error message for `E0659` if the source is not available

Fixes rust-lang#91028. The fix is similar to those in rust-lang#89233 and rust-lang#87088. With this change, instead of the dangling
```
note: `Option` could also refer to the enum defined here
```
I get
```
note: `Option` could also refer to an enum from prelude
```
If the standard library source code _is_ available, the output does not change.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 1, 2021
…l, r=cjgillot

Improve error message for `E0659` if the source is not available

Fixes rust-lang#91028. The fix is similar to those in rust-lang#89233 and rust-lang#87088. With this change, instead of the dangling
```
note: `Option` could also refer to the enum defined here
```
I get
```
note: `Option` could also refer to an enum from prelude
```
If the standard library source code _is_ available, the output does not change.
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. 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.

"note: deref defined here", but it doesn't actually show anything
8 participants