Skip to content

Default impls are not restricted to same module (or submodule) as the trait #25655

@nham

Description

@nham

In the OIBIT RFC there are two limitations for default impls:

  1. The default impl must appear in the same module as Trait (or a submodule).
  2. Trait must not define any methods.

Limitation (1) does not appear to match the current implementation. The only error I can find pertaining to this rule is E0318, whose message is:

cannot create default implementations for traits outside the crate they're defined in; define a new trait instead

Also, the following example currently compiles:

#![feature(optin_builtin_traits)]

mod foo {
    pub trait Foo { }
}

mod bar {
    impl super::foo::Foo for .. { }
}

fn main() {}

I'm not sure if this is a bug in the implementation, if it's merely unimplemented, or if the RFC should be updated to reflect that you can define a default impl in the same crate, with no restriction on which module it's defined in.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions