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

Point at type parameter in plain path expr #101425

Merged
merged 1 commit into from
Sep 6, 2022

Conversation

compiler-errors
Copy link
Member

Slightly better error message for a kinda unique use case.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 4, 2022
@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @spastorino (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 4, 2022
@spastorino
Copy link
Member

@compiler-errors looks good but, what was happening before this PR?

@compiler-errors
Copy link
Member Author

compiler-errors commented Sep 5, 2022

If you test the UI test on nightly:

fn foo<T: std::fmt::Display>() {}

fn main() {
    let x = foo::<()>;
    //~^ ERROR `()` doesn't implement `std::fmt::Display`
}

Then you see:

error[[E0277]](https://doc.rust-lang.org/nightly/error-index.html#E0277): `()` doesn't implement `std::fmt::Display`
 --> src/main.rs:4:13
  |
4 |     let x = foo::<()>;
  |             ^^^^^^^^^ `()` cannot be formatted with the default formatter
  |
  = help: the trait `std::fmt::Display` is not implemented for `()`
  = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
note: required by a bound in `foo`
 --> src/main.rs:1:11
  |
1 | fn foo<T: std::fmt::Display>() {}
  |           ^^^^^^^^^^^^^^^^^ required by this bound in `foo`

Notably, that error message on line 4 becomes (after this PR):

LL |     let x = foo::<()>;
   |                   ^^ `()` cannot be formatted with the default formatter

Notice the tighter span.

This was because we were only triggering point_at_path_if_possible if the ExprKind::Path had a parent of ExprKind::Call, even though that's only really necessary to point at args. We can point to the path regardless.

@spastorino
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Sep 5, 2022

📌 Commit 3b3c706 has been approved by spastorino

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 5, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 5, 2022
… r=spastorino

Point at type parameter in plain path expr

Slightly better error message for a kinda unique use case.
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Sep 5, 2022
… r=spastorino

Point at type parameter in plain path expr

Slightly better error message for a kinda unique use case.
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 6, 2022
Rollup of 7 pull requests

Successful merges:

 - rust-lang#99291 (Add let else drop order tests)
 - rust-lang#101402 (Add a Machine hook for inline assembly)
 - rust-lang#101404 (Fix cleanup for uninitialized stdout)
 - rust-lang#101418 (Revert "Mention rust-analyzer maintainers when `proc_macro` bridge is changed")
 - rust-lang#101425 (Point at type parameter in plain path expr)
 - rust-lang#101426 (Don't duplicate file descriptors into stdio fds)
 - rust-lang#101447 (Remove generics_def_id_map from the resolver.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit c3faa22 into rust-lang:master Sep 6, 2022
@rustbot rustbot added this to the 1.65.0 milestone Sep 6, 2022
@compiler-errors compiler-errors deleted the point-at-ty-param branch November 2, 2022 02:59
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.

5 participants