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

Try to suggest dereferences on trait selection failed #72456

Merged
merged 3 commits into from
Jun 21, 2020

Conversation

ldm0
Copy link
Contributor

@ldm0 ldm0 commented May 22, 2020

Fixes #39029 Fixes #62530
This PR consists of two parts:

  1. Decouple Autoderef with FnCtxt and move Autoderef to librustc_trait_selection.
  2. Try to suggest dereferences when trait selection failed.

The first is needed because:

  1. For suggesting dereferences, the struct Autoderef should be used. But before this PR, it is placed in librustc_typeck, which depends on librustc_trait_selection. But trait selection error emitting happens in librustc_trait_selection, if we want to use Autoderef in it, dependency loop is inevitable. So I moved the Autoderef to librustc_trait_selection.
  2. Before this PR, FnCtxt is coupled to Autoderef, and FnCtxt only exists in librustc_typeck. So decoupling is needed.

After this PR, we can get suggestion like this:

error[E0277]: the trait bound `&Baz: Happy` is not satisfied
  --> $DIR/trait-suggest-deferences-multiple.rs:34:9
   |
LL | fn foo<T>(_: T) where T: Happy {}
   |                          ----- required by this bound in `foo`
...
LL |     foo(&baz);
   |         ^^^^
   |         |
   |         the trait `Happy` is not implemented for `&Baz`
   |         help: consider adding dereference here: `&***baz`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.

r? @estebank

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 22, 2020
@bors
Copy link
Contributor

bors commented May 23, 2020

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

@ldm0 ldm0 marked this pull request as draft May 23, 2020 10:32
@ldm0 ldm0 force-pushed the dereftrait branch 2 times, most recently from 8d3898b to e66f84e Compare May 23, 2020 10:40
@ldm0 ldm0 marked this pull request as ready for review May 23, 2020 11:13
@bors
Copy link
Contributor

bors commented May 30, 2020

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

@ldm0 ldm0 marked this pull request as draft May 30, 2020 16:55
@ldm0 ldm0 force-pushed the dereftrait branch 2 times, most recently from c3fb825 to 3fc1c11 Compare May 30, 2020 18:50
@ldm0 ldm0 marked this pull request as ready for review May 30, 2020 18:51
@ldm0 ldm0 marked this pull request as draft May 30, 2020 19:00
@rust-highfive
Copy link
Collaborator

The job mingw-check of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
##[section]Starting: Linux mingw-check
##[section]Starting: Initialize job
Agent name: 'Azure Pipelines 66'
Agent machine name: 'fv-az578'
Current agent version: '2.169.1'
##[group]Operating System
16.04.6
LTS
LTS
##[endgroup]
##[group]Virtual Environment
Environment: ubuntu-16.04
Version: 20200517.1
Included Software: https://github.com/actions/virtual-environments/blob/ubuntu16/20200517.1/images/linux/Ubuntu1604-README.md
##[endgroup]
Agent running as: 'vsts'
Prepare build directory.
Set build variables.
Download all required tasks.
Download all required tasks.
Downloading task: Bash (3.163.2)
Checking job knob settings.
   Knob: AgentToolsDirectory = /opt/hostedtoolcache Source: ${AGENT_TOOLSDIRECTORY} 
   Knob: AgentPerflog = /home/vsts/perflog Source: ${VSTS_AGENT_PERFLOG} 
Start tracking orphan processes.
##[section]Finishing: Initialize job
##[section]Starting: Configure Job Name
==============================================================================
---
========================== Starting Command Output ===========================
[command]/bin/bash --noprofile --norc /home/vsts/work/_temp/614e9701-794d-4908-a6d8-e4b927ed7acc.sh

##[section]Finishing: Disable git automatic line ending conversion
##[section]Starting: Checkout rust-lang/rust@refs/pull/72456/merge to s
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
---
##[command]git remote add origin https://github.com/rust-lang/rust
##[command]git config gc.auto 0
##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
##[command]git config --get-all http.proxy
##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/72456/merge:refs/remotes/pull/72456/merge
---
 ---> 3adb0605cc65
Step 6/7 : ENV RUN_CHECK_WITH_PARALLEL_QUERIES 1
 ---> Using cache
 ---> 28dbc326cb7f
Step 7/7 : ENV SCRIPT python3 ../x.py test src/tools/expand-yaml-anchors &&            python3 ../x.py check --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu &&            python3 ../x.py build --stage 0 src/tools/build-manifest &&            python3 ../x.py test --stage 0 src/tools/compiletest &&            python3 ../x.py test src/tools/tidy &&            python3 ../x.py doc --stage 0 src/libstd &&            /scripts/validate-toolstate.sh
 ---> 537a01811900
Successfully built 537a01811900
Successfully tagged rust-ci:latest
Built container sha256:537a018119009dc218456238dec90b5530050db1e2a1e166550c218003f6159d
---
extracting /checkout/obj/build/cache/2020-04-22/rustfmt-nightly-x86_64-unknown-linux-gnu.tar.xz
error: failed to resolve patches for `https://github.com/rust-lang/crates.io-index`

Caused by:
  patch for `rustfmt-nightly` in `https://github.com/rust-lang/crates.io-index` did not resolve to any crates. If this is unexpected, you may wish to consult: https://github.com/rust-lang/cargo/issues/4678
Build completed unsuccessfully in 0:00:20
== clock drift check ==
  local time: Sat May 30 19:02:45 UTC 2020
  network time: Sat, 30 May 2020 19:02:45 GMT
  network time: Sat, 30 May 2020 19:02:45 GMT
== end clock drift check ==

##[error]Bash exited with code '1'.
##[section]Finishing: Run build
##[section]Starting: Checkout rust-lang/rust@refs/pull/72456/merge to s
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
Author       : Microsoft
Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
==============================================================================
Cleaning any cached credential from repository: rust-lang/rust (GitHub)
##[section]Finishing: Checkout rust-lang/rust@refs/pull/72456/merge to s
Cleaning up task key
Start cleaning up orphan processes.
Terminate orphan process: pid (3682) (python)
##[section]Finishing: Finalize Job

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @rust-lang/infra. (Feature Requests)

@ldm0 ldm0 force-pushed the dereftrait branch 2 times, most recently from 79a33b0 to 0c0b32d Compare May 30, 2020 19:25
@ldm0 ldm0 marked this pull request as ready for review May 30, 2020 19:30
@Elinvynia Elinvynia added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 10, 2020
@bors
Copy link
Contributor

bors commented Jun 19, 2020

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

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.

Apologies for the delay on reviewing this. I have a couple of nitpicks. Could you address them as you rebase? Other than that, I'm happy with the changes!

@ldm0
Copy link
Contributor Author

ldm0 commented Jun 20, 2020

Rebase done, nitpicks applied.

@estebank
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jun 20, 2020

📌 Commit f1e0710 has been approved by estebank

@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 Jun 20, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 20, 2020
…arth

Rollup of 9 pull requests

Successful merges:

 - rust-lang#72456 (Try to suggest dereferences on trait selection failed)
 - rust-lang#72788 (Projection bound validation)
 - rust-lang#72790 (core/time: Add Duration methods for zero)
 - rust-lang#73227 (Allow multiple `asm!` options groups and report an error on duplicate options)
 - rust-lang#73287 (lint: normalize projections using opaque types)
 - rust-lang#73291 (Pre-compute `LocalDefId` <-> `HirId` mappings and remove `NodeId` <-> `HirId` conversion APIs)
 - rust-lang#73378 (Remove use of specialization from librustc_arena)
 - rust-lang#73411 (Update bootstrap to rustc 1.45.0-beta.2 (1dc0f6d 2020-06-15))
 - rust-lang#73443 (ci: allow gating GHA on everything but macOS)

Failed merges:

r? @ghost
@bors bors merged commit a1404a9 into rust-lang:master Jun 21, 2020
@ldm0 ldm0 deleted the dereftrait branch June 21, 2020 03:32
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.

Account for coercions in trait resolution? Suggest dereference operations when a deref coercion won't work
5 participants