question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support impl for type parameter `impl<T> Trait for T`

See original GitHub issue

Currently we don’t look for impls like impl<T> Trait for T, so this test fails

trait Trait {
    fn foo(&self) {}
}    //X
impl<T> Trait for T {}
struct X;
fn main() {
    X.foo();
}   //^

It is pretty easy to implement. Here we indexing the impl by the type. We should check if type is a type parameter of this impl (go to parent psi, find type parameters declaration and check the type name is the same), then if it is a type parameter, save it to index with a specific key that is invalid identifier (like #). Then while finding impls retreive index twice: with actual type name and with our specific key.


You can find more info about how to start contributing to Intellij-Rust in CONTRIBUTING.md, and some info about our architecure in ARCHITECTURE.md. If you have any questions about this issue, you can ask them right here or in our gitter. If you decided to grab this issue, please leave a comment here and put yourself in the worklist.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
Undincommented, Sep 16, 2017

I’ve previously thought about it I want to grab it:)

0reactions
vlad20012commented, Sep 20, 2017

@Undin I don’t see a much difference between impl<T: Foo> for T and impl<T: Foo> for S<T> in terms of trait boud matching. We do not support both =) So it’s another issue. (see RsPreciseTraitMatchingTest)

@farodin91 no-no-no, #1649 is another problem

Read more comments on GitHub >

github_iconTop Results From Across the Web

Impl trait type - The Rust Reference
impl Trait provides ways to specify unnamed but concrete types that implement a specific trait. It can appear in two sorts of places:...
Read more >
the type parameter `T` is not constrained by the impl trait, self ...
As the compiler says, a generic parameter for an impl Trait must be constrained. Simply speaking, in the line impl<T> SendsMessages for ...
Read more >
Advanced Traits - The Rust Programming Language
Using a default type parameter in the Add trait definition makes it easier to implement the trait since you don't have to specify...
Read more >
impl Trait in argument position #44721 - rust-lang/rust - GitHub
Should we permit specifying types if some parameters are implicit and some are explicit? e.g., fn foo<T>(x: impl Iterator<Item = T>>) ?
Read more >
Traits: Defining Shared Behavior - The Rust Programming ...
In situations where we use generic type parameters, we can use trait ... In other words, we aren't allowed to implement external traits...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found