Skip to content

supertrait methods should be callable on object types #4100

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
brson opened this issue Dec 3, 2012 · 13 comments
Closed

supertrait methods should be callable on object types #4100

brson opened this issue Dec 3, 2012 · 13 comments
Labels
A-trait-system Area: Trait system

Comments

@brson
Copy link
Contributor

brson commented Dec 3, 2012

Bound type parameters can call supertrait methods, objects should be able to as well.

trait A { fn f() }
trait B: A { }

fn foo(b: &B) {
    b.f()
}
@nikomatsakis
Copy link
Contributor

Bumping to 0.6

@catamorphism
Copy link
Contributor

Reproduced as of eed2ca6

@ghost ghost assigned catamorphism Feb 21, 2013
@catamorphism
Copy link
Contributor

Not critical for 0.6, de-milestoning

@Sodel-the-Vociferous
Copy link
Contributor

catamorphism, are you actively working on this one, or do you mind if I take a crack at it?

@catamorphism
Copy link
Contributor

@Sodel-the-Vociferous I'm not actively working on it, so please do! Ask on IRC if you have any questions :-)

@Sodel-the-Vociferous
Copy link
Contributor

Problems found so far:

  • LookupContext::push_inherent_impl_candidates_for_type() wasn't checking supertraits; seems to be fixed on my branch.
  • LookupContext::push_inherent_items_from_trait() wasn't checking supertraits, either. This is taking a bit longer because of the next problem.
  • ty::lookup_item_type() crashes the compiler when I give it a supertrait's def_id, and says there's no matching type in the tcache. I'm going to do a bit more testing to see what else does and does not aggravate this problem.

Also, by analogy to the method_origins "method_self" and "method_super", I'm going to split "method_trait" into "method_trait" and "method_trait_super". We might as well be explicit when we're trying to use trait inheritance with dynamic dispatch.

@Sodel-the-Vociferous
Copy link
Contributor

Objects need some refactoring first. Waiting on #5762.

@catamorphism
Copy link
Contributor

Nominating for milestone 5, production-ready

@graydon
Copy link
Contributor

graydon commented Jul 18, 2013

accepted for feature-complete milestone

@huonw
Copy link
Member

huonw commented Jul 28, 2013

@msullivan has been doing work in this area recently, maybe he has some light to shed?

@ghost ghost assigned msullivan Aug 13, 2013
@msullivan
Copy link
Contributor

Yeah, I'll take this.

@vi
Copy link
Contributor

vi commented Apr 10, 2015

It works, but casting b as &A not. It can be worked around:

struct ProxyObject<'q> (&'q B);

impl<'q> A for ProxyObject<'q> {
   fn f(&self) {let &ProxyObject(x) = self;  x.f();}
}

// &ProxyObject(b) as &A

Maybe the compiler can do something like this automatically?

@nikomatsakis
Copy link
Contributor

@vi indeed, adding more general upcasts is definitely something we'd like to do soon-ish. It's a touch tricky when you dig into the details.

bors pushed a commit to rust-lang-ci/rust that referenced this issue May 15, 2021
RalfJung added a commit to RalfJung/rust that referenced this issue Dec 21, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-trait-system Area: Trait system
Projects
None yet
Development

No branches or pull requests

8 participants