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

Error With Default Associated Type Pointer #32350

Closed
KodrAus opened this issue Mar 19, 2016 · 1 comment · Fixed by #61812
Closed

Error With Default Associated Type Pointer #32350

KodrAus opened this issue Mar 19, 2016 · 1 comment · Fixed by #61812
Assignees
Labels
A-associated-items Area: Associated items (types, constants & functions) C-bug Category: This is a bug. F-associated_type_defaults `#![feature(associated_type_defaults)]` requires-nightly This issue requires a nightly compiler in some way. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@KodrAus
Copy link
Contributor

KodrAus commented Mar 19, 2016

The following used to work in nightly, but doesn't anymore (I'm not sure when it changed):

#![feature(associated_type_defaults)]

pub trait Emitter<'a> {
    type Ctxt: 'a;
    type CtxtBrw: 'a = &'a Self::Ctxt;

    fn get_cx(&'a self) -> Self::CtxtBrw;
}

struct MyCtxt;

struct MyEmitter {
    ctxt: MyCtxt
}

impl <'a> Emitter<'a> for MyEmitter {
    type Ctxt = MyCtxt;

    fn get_cx(&'a self) -> &'a MyCtxt {
        &self.ctxt
    }
}

fn main() {

}

The above returns the following error:

<anon>:19:5: 21:6 error: method `get_cx` has an incompatible type for trait:
 expected associated type,
    found &-ptr [E0053]
<anon>:19     fn get_cx(&'a self) -> &'a MyCtxt {
<anon>:20         &self.ctxt
<anon>:21     }
<anon>:19:5: 21:6 help: see the detailed explanation for E0053
error: aborting due to previous error
playpen: application terminated with error code 101

If I manually implement CtxtBrw then it does compile:

impl <'a> Emitter<'a> for MyEmitter {
    type Ctxt = MyCtxt;
    type CtxtBrw = &'a Self::Ctxt;

    fn get_cx(&'a self) -> &'a MyCtxt {
        &self.ctxt
    }
}

Is this expected behaviour? And if so, what's the rationale so I know if I'm trying to do something I shouldn't :)

@steveklabnik steveklabnik added T-lang Relevant to the language team, which will review and decide on the PR/issue. and removed A-lang labels Mar 24, 2017
@Mark-Simulacrum Mark-Simulacrum added I-needs-decision Issue: In need of a decision. C-bug Category: This is a bug. labels Jul 24, 2017
@jonas-schievink jonas-schievink added the F-associated_type_defaults `#![feature(associated_type_defaults)]` label Aug 29, 2019
@jonas-schievink jonas-schievink self-assigned this Aug 29, 2019
@jonas-schievink jonas-schievink added A-associated-items Area: Associated items (types, constants & functions) requires-nightly This issue requires a nightly compiler in some way. labels Aug 29, 2019
@jonas-schievink jonas-schievink removed the I-needs-decision Issue: In need of a decision. label Aug 29, 2019
@jonas-schievink
Copy link
Contributor

This is now specified in RFC 2532 (#29661) and will be fixed by #61812

@bors bors closed this as completed in 3a0d106 Feb 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) C-bug Category: This is a bug. F-associated_type_defaults `#![feature(associated_type_defaults)]` requires-nightly This issue requires a nightly compiler in some way. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants