Skip to content

impl dyn for AnyType fails to compile #50405

Closed
@Havvy

Description

@Havvy

Playpen

fn main() {
    let s = Box::new(S);
    let d = s as Box<dyn dyn>;
    d.say();
}

trait dyn {
    fn say(&self) -> &'static str;
}

struct S;

impl dyn for S {
    fn say(&self) -> &'static str { "I'm S!" }
}

Expected: Program outputs "I'm S!" (missed a println) compiles.

Actual:

Compiling playground v0.0.1 (file:///playground)
error: expected `<`, found `S`
  --> src/main.rs:13:14
   |
13 | impl dyn for S {
   |              ^ expected `<` here

error: aborting due to previous error

error: Could not compile `playground`.

Since dyn is a contextual keyword and still allowed as an identifier, I expect to still be able to implement a trait named "dyn" for various structs. And indeed, if I change the trait name to "dyna", it works.

Metadata

Metadata

Assignees

Labels

A-edition-2018Area: The 2018 editionA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-parserArea: The lexing & parsing of Rust source code to an ASTT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-epochWorking group: Epoch (2018) managementregression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions