forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 0
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#78111 - SNCPlay42:not-always-self, r=lcnr
Trait predicate ambiguities are not always in `Self` When reporting ambiguities in trait predicates, the compiler incorrectly assumed the ambiguity was always in the type the trait should be implemented on, and never the generic parameters of the trait. This caused silly suggestions for predicates like `<KnownType as Trait<_>>`, such as giving explicit types to completely unrelated variables that happened to be of type `KnownType`. This also reverts rust-lang#73027, which worked around this issue in some cases and does not appear to be necessary any more. fixes rust-lang#77982 fixes rust-lang#78055
- Loading branch information
Showing
8 changed files
with
123 additions
and
62 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
4 changes: 2 additions & 2 deletions
4
src/test/ui/closure-expected-type/expect-two-infer-vars-supply-ty-with-bound-region.stderr
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
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,40 @@ | ||
use std::collections::HashMap; | ||
|
||
fn what() { | ||
let descr = String::new(); | ||
let mut opts = HashMap::<String, ()>::new(); | ||
let opt = String::new(); | ||
|
||
opts.get(opt.as_ref()); //~ ERROR type annotations needed | ||
} | ||
|
||
fn main() { | ||
let ips: Vec<_> = (0..100_000).map(|_| u32::from(0u32.into())).collect(); | ||
//~^ ERROR type annotations needed | ||
} | ||
|
||
trait Foo<'a, T: ?Sized> { | ||
fn foo(&self) -> Box<T> { | ||
todo!() | ||
} | ||
} | ||
|
||
trait Bar<'a, T: ?Sized> { | ||
fn bar(&self) -> Box<T> { | ||
todo!() | ||
} | ||
} | ||
|
||
impl Foo<'static, u32> for () {} | ||
impl<'a> Foo<'a, i16> for () {} | ||
|
||
impl<'a> Bar<'static, u32> for &'a () {} | ||
impl<'a> Bar<'a, i16> for &'a () {} | ||
|
||
fn foo() { | ||
let _ = ().foo(); //~ ERROR type annotations needed | ||
} | ||
|
||
fn bar() { | ||
let _ = (&()).bar(); //~ ERROR type annotations needed | ||
} |
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,44 @@ | ||
error[E0283]: type annotations needed | ||
--> $DIR/issue-77982.rs:8:10 | ||
| | ||
LL | opts.get(opt.as_ref()); | ||
| ^^^ ------------ this method call resolves to `&T` | ||
| | | ||
| cannot infer type for type parameter `Q` declared on the associated function `get` | ||
| | ||
= note: cannot satisfy `String: Borrow<_>` | ||
|
||
error[E0283]: type annotations needed | ||
--> $DIR/issue-77982.rs:12:44 | ||
| | ||
LL | let ips: Vec<_> = (0..100_000).map(|_| u32::from(0u32.into())).collect(); | ||
| ^^^^^^^^^ ----------- this method call resolves to `T` | ||
| | | ||
| cannot infer type for type parameter `T` declared on the trait `From` | ||
| | ||
= note: cannot satisfy `u32: From<_>` | ||
= note: required by `from` | ||
|
||
error[E0283]: type annotations needed for `Box<T>` | ||
--> $DIR/issue-77982.rs:35:16 | ||
| | ||
LL | let _ = ().foo(); | ||
| - ^^^ cannot infer type for type parameter `T` declared on the trait `Foo` | ||
| | | ||
| consider giving this pattern the explicit type `Box<T>`, where the type parameter `T` is specified | ||
| | ||
= note: cannot satisfy `(): Foo<'_, _>` | ||
|
||
error[E0283]: type annotations needed for `Box<T>` | ||
--> $DIR/issue-77982.rs:39:19 | ||
| | ||
LL | let _ = (&()).bar(); | ||
| - ^^^ cannot infer type for type parameter `T` declared on the trait `Bar` | ||
| | | ||
| consider giving this pattern the explicit type `Box<T>`, where the type parameter `T` is specified | ||
| | ||
= note: cannot satisfy `&(): Bar<'_, _>` | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0283`. |