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.
don't assume trait ambiguity happens in
Self
- Loading branch information
Showing
4 changed files
with
113 additions
and
34 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
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`. |