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

Implement special-cased projection error message for some common traits #98863

Merged
merged 2 commits into from
Aug 8, 2022

Conversation

compiler-errors
Copy link
Member

Not sure what the best phrasing is, but I feel like these are more clear than the plain <Type as Iterator>::Output == Type messages.

If this is actually a good idea, are there any other traits this could benefit?

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 3, 2022
@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 3, 2022
@bors
Copy link
Contributor

bors commented Jul 8, 2022

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

))
} else if Some(trait_def_id) == self.tcx.get_diagnostic_item(sym::Iterator) {
Some(format!(
"expected `{self_ty}` to be an iterator of `{expected_ty}`, but it actually returns items of `{normalized_ty}`"
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm less enthusiastic about the wording "expected foo to be an iterator of i32 but it actually returns items of u32", because it feels we're mixing up concepts here. We could use "yields items of u32" instead, but yield isn't a keyword people will know from Rust (yet).

What about "expected foo to be an iterator over items of type i32 but it is an iterator over items of type u32"?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think "yield" is okay here since it doesn't necessarily imply connection to the yield kw, but I can just use "over".

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think of

expected `foo` to be an iterator that yields `i32` but it yields `u32`

))
} else if Some(trait_def_id) == self.tcx.lang_items().future_trait() {
Some(format!(
"expected `{self_ty}` to be a future that yields `{expected_ty}`, but it actually yields `{normalized_ty}`"
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe the same about using "yields" to talk about the Future::Output? What about "...to be a future that resolves to ty, but it resolves to ty".

Let's also drop the "actually". It doesn't add as much to the messaging, I feel.

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.

The code changes look good, I have some qualms over wording. What do you think?

(Apologies for the review delay)

@compiler-errors
Copy link
Member Author

I can apply these messaging changes, the ones I wrote originally were just kinda there to demonstrate the concept.

@rustbot author

@rustbot rustbot 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 Aug 4, 2022
@compiler-errors
Copy link
Member Author

@rustbot ready

Adjusted the wording, what do you think now? Open to more changes if needed.

@rustbot rustbot 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 8, 2022
@@ -22,19 +22,22 @@ LL | where
LL | F: for<'r> T0<'r, (<Self as Ty<'r>>::V,), O = <B as Ty<'r>>::V>,
| ^^^^^^^^^^^^^^^^^^^^ required by this bound in `T1::m`

error[E0271]: type mismatch resolving `for<'r> <[closure@$DIR/issue-62203-hrtb-ice.rs:42:17: 42:20] as FnOnce<((&'r u8,),)>>::Output == Unit3`
error[E0271]: expected `[closure@$DIR/issue-62203-hrtb-ice.rs:42:16: 42:19]` to be a closure that returns `Unit3`, but it returns `Unit4`
Copy link
Contributor

Choose a reason for hiding this comment

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

Not for this PR: I would love to instead say "expected the closure to return Unit3..." and have a span label pointing at the closure, but we need to improve that in general.

@@ -1,7 +1,7 @@
error[E0271]: type mismatch resolving `<fn() -> impl Sized {hi} as FnOnce<()>>::Output == Box<u8>`
--> $DIR/issue-98608.rs:4:39
error[E0271]: expected `fn() -> impl Sized {hi}` to be a fn item that returns `Box<u8>`, but it returns `impl Sized`
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly here, we could refer to the function by name

expected `hi` to return `Box<u8>`, but it returns `impl Sized`

@estebank
Copy link
Contributor

estebank commented Aug 8, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Aug 8, 2022

📌 Commit 3fdf3cb has been approved by estebank

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 Aug 8, 2022
@bors
Copy link
Contributor

bors commented Aug 8, 2022

⌛ Testing commit 3fdf3cb with merge f03ce30...

@bors
Copy link
Contributor

bors commented Aug 8, 2022

☀️ Test successful - checks-actions
Approved by: estebank
Pushing f03ce30 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 8, 2022
@bors bors merged commit f03ce30 into rust-lang:master Aug 8, 2022
@rustbot rustbot added this to the 1.65.0 milestone Aug 8, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f03ce30): comparison url.

Instruction count

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

Max RSS (memory usage)

Results
  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: mixed results
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
1.6% 1.6% 1
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-3.2% -3.2% 1
All 😿🎉 (primary) N/A N/A 0

Cycles

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

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

Footnotes

  1. the arithmetic mean of the percent change

  2. number of relevant changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

6 participants