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

rustc: where clauses are sometimes silently ignored #18906

Closed
aturon opened this issue Nov 12, 2014 · 5 comments
Closed

rustc: where clauses are sometimes silently ignored #18906

aturon opened this issue Nov 12, 2014 · 5 comments
Milestone

Comments

@aturon
Copy link
Member

aturon commented Nov 12, 2014

I'm reasonably sure the problem below is related to multidispatch and its interaction with type inference. It works fine for a standalone function, but not in an impl context:

pub trait Borrow<Sized? Borrowed> {
    fn borrow(&self) -> &Borrowed;
}

impl<T: Sized> Borrow<T> for T {
    fn borrow(&self) -> &T { self }
}

trait Foo {
    fn foo(&self, other: &Self);
}

// This works fine
fn bar<K, Q>(k: &K, q: &Q) where K: Borrow<Q>, Q: Foo {
    q.foo(k.borrow())
}

struct MyTree<K>;
impl<K> MyTree<K> {
    // This fails
    fn bar<Q>(k: &K, q: &Q) where K: Borrow<Q>, Q: Foo {
        q.foo(k.borrow())
    }
}

The error is:

borrow-test.rs:22:15: 22:25 error: mismatched types: expected `&Q`, found `&K` (expected type parameter, found a different type parameter)
borrow-test.rs:22         q.foo(k.borrow())
                                ^~~~~~~~~~

cc @nikomatsakis

@nikomatsakis
Copy link
Contributor

I expect the problem is the (incomplete) implementation of where clauses. Something like K:Borrow<Q> isn't really expected to work sadly.

@aturon
Copy link
Member Author

aturon commented Nov 12, 2014

@nikomatsakis points out that this is more likely a problem with where clauses, namely that method-level where clauses are not implemented and are silently being dropped here.

@nikomatsakis nikomatsakis changed the title rustc: multidispatch inference goes wrong in impl context rustc: where clauses are sometimes silently ignored Nov 20, 2014
@huonw
Copy link
Member

huonw commented Nov 20, 2014

cc #17086

@pnkfelix
Copy link
Member

P-backcompat-lang, 1.0.

@pnkfelix pnkfelix added this to the 1.0 milestone Nov 20, 2014
jroesch added a commit to jroesch/rust that referenced this issue Dec 24, 2014
jroesch added a commit to jroesch/rust that referenced this issue Dec 26, 2014
alexcrichton added a commit to alexcrichton/rust that referenced this issue Dec 30, 2014
Closes issue rust-lang#18906. This is what we talked about last night/early this morning. r? @nikomatsakis.
@nikomatsakis
Copy link
Contributor

Seems this is fixed and even has a test.

lnicola pushed a commit to lnicola/rust that referenced this issue Jan 20, 2025
feat: Re-implement rust string highlighting via tool attribute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants