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

Do not error during method probe on Sized predicates for types that aren't the method receiver #99146

Merged
merged 2 commits into from
Jul 12, 2022

Conversation

compiler-errors
Copy link
Member

Fixes #61525

This is safe even though we're skipping an error because we end up confirming the method, which means we're still checking the Sized predicate in the end. It just means that we don't emit an erroneous message as below:

error: the `query` method cannot be invoked on a trait object
  --> src/lib.rs:14:11
   |
14 |         1.query::<dyn ToString>("")
   |           ^^^^^
   |
   = note: another candidate was found in the following trait, perhaps add a `use` for it:
           `use crate::Example;`

Also fixes erroneously suggesting the same trait over again, as seen in the issue-35976.rs UI test.

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

r? @lcnr

(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 11, 2022
@@ -0,0 +1,39 @@
error[E0277]: the size for values of type `dyn ToString` cannot be known at compilation time
Copy link
Member Author

Choose a reason for hiding this comment

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

This error is actually more verbose than what it used to (erroneously) say before, but it's more consistent with an error you'd get if you, for example, passed any other DST as a generic arg. It also makes the second error, the mismatched types ("" against dyn ToString) not be suppressed any longer, which IMO is better.

@lcnr
Copy link
Contributor

lcnr commented Jul 11, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Jul 11, 2022

📌 Commit 88f2140 has been approved by lcnr

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 Jul 11, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 11, 2022
Do not error during method probe on `Sized` predicates for types that aren't the method receiver

Fixes rust-lang#61525

This is safe even though we're skipping an error because we end up confirming the method, which means we're still checking the `Sized` predicate in the end. It just means that we don't emit an erroneous message as below:

```
error: the `query` method cannot be invoked on a trait object
  --> src/lib.rs:14:11
   |
14 |         1.query::<dyn ToString>("")
   |           ^^^^^
   |
   = note: another candidate was found in the following trait, perhaps add a `use` for it:
           `use crate::Example;`
```

Also fixes erroneously suggesting the same trait over again, as seen in the `issue-35976.rs` UI test.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 11, 2022
Do not error during method probe on `Sized` predicates for types that aren't the method receiver

Fixes rust-lang#61525

This is safe even though we're skipping an error because we end up confirming the method, which means we're still checking the `Sized` predicate in the end. It just means that we don't emit an erroneous message as below:

```
error: the `query` method cannot be invoked on a trait object
  --> src/lib.rs:14:11
   |
14 |         1.query::<dyn ToString>("")
   |           ^^^^^
   |
   = note: another candidate was found in the following trait, perhaps add a `use` for it:
           `use crate::Example;`
```

Also fixes erroneously suggesting the same trait over again, as seen in the `issue-35976.rs` UI test.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 12, 2022
…askrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#97210 (Support `-A`, `-W`, `-D` and `-F` when running `./x.py clippy`)
 - rust-lang#99055 (Fix rustdoc help options)
 - rust-lang#99075 (Fix duplicated type annotation suggestion)
 - rust-lang#99124 (Fix sized check ICE in asm check)
 - rust-lang#99142 (fix(doctest): treat fatal parse errors as incomplete attributes)
 - rust-lang#99145 (Don't rerun the build script for the compiler each time on non-windows platforms)
 - rust-lang#99146 (Do not error during method probe on `Sized` predicates for types that aren't the method receiver)
 - rust-lang#99161 (compiletest: trim edition before passing as flag)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 5e223dc into rust-lang:master Jul 12, 2022
@rustbot rustbot added this to the 1.64.0 milestone Jul 12, 2022
@@ -81,11 +81,25 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
let rcvr_substs = self.fresh_receiver_substs(self_ty, &pick);
let all_substs = self.instantiate_method_substs(&pick, segment, rcvr_substs);

debug!("all_substs={:?}", all_substs);
debug!("rcvr_substs={rcvr_substs:?}, all_substs={all_substs:?}");
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this the same as

debug!(?rcvr_substs, ?all_substs);

?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, you're right. not super familiar with the tracing macros, sorry😅

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.

Error when passing a trait object as a generic type doesn't indicate what is the trait object
6 participants