forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#99146 - compiler-errors:issue-61525, r=lcnr
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.
- Loading branch information
Showing
5 changed files
with
77 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
pub trait Example { | ||
fn query<Q>(self, q: Q); | ||
} | ||
|
||
impl Example for i32 { | ||
fn query<Q>(self, _: Q) { | ||
unimplemented!() | ||
} | ||
} | ||
|
||
mod nested { | ||
use super::Example; | ||
fn example() { | ||
1.query::<dyn ToString>("") | ||
//~^ ERROR the size for values of type `dyn ToString` cannot be known at compilation time | ||
//~| ERROR mismatched types | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
error[E0277]: the size for values of type `dyn ToString` cannot be known at compilation time | ||
--> $DIR/issue-61525.rs:14:33 | ||
| | ||
LL | 1.query::<dyn ToString>("") | ||
| ----- ^^ doesn't have a size known at compile-time | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= help: the trait `Sized` is not implemented for `dyn ToString` | ||
note: required by a bound in `Example::query` | ||
--> $DIR/issue-61525.rs:2:14 | ||
| | ||
LL | fn query<Q>(self, q: Q); | ||
| ^ required by this bound in `Example::query` | ||
help: consider relaxing the implicit `Sized` restriction | ||
| | ||
LL | fn query<Q: ?Sized>(self, q: Q); | ||
| ++++++++ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-61525.rs:14:33 | ||
| | ||
LL | 1.query::<dyn ToString>("") | ||
| --------------------- ^^ expected trait object `dyn ToString`, found `&str` | ||
| | | ||
| arguments to this function are incorrect | ||
| | ||
= note: expected trait object `dyn ToString` | ||
found reference `&'static str` | ||
note: associated function defined here | ||
--> $DIR/issue-61525.rs:2:8 | ||
| | ||
LL | fn query<Q>(self, q: Q); | ||
| ^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0277, E0308. | ||
For more information about an error, try `rustc --explain E0277`. |