Skip to content

trait permitting extra members #54665

Description

@nikomatsakis

I've been tinkering locally with a crate called salsa. Along the way, I noticed that my impl permits me to add extra members. e.g., I have this trait:

pub trait QueryContext: QueryContextStorageTypes {
    fn salsa_runtime(&self) -> &runtime::Runtime<Self>;
}

But in my cargo example I can use this impl:

impl salsa::QueryContext for QueryContextImpl {
    fn extra(&self) -> u32 {
        0
    }

    fn salsa_runtime(&self) -> &salsa::runtime::Runtime<QueryContextImpl> {
        &self.runtime
    }
}

What the heck is going on here? I couldn't easily reproduce this in a smaller example, so I saved the commit. It did reproduce cleanly after rm -rf target and cargo clean, so I guess it's (probably?) not an incremental bug.

To reproduce:

  • Clone the salsa repo at https://github.com/nikomatsakis/salsa and go to the commit 36e2b9cdcc01228560f9fb7ffdfadf466d21e60d.
  • Run cargo build --example storage_varieties
  • Observe that build does not fail

Marking as T-compiler and P-high. P-high because this could be a very dangerous bug in terms of backwards compat risk! But I'm hoping it's something more bizarre (e.g., not rebuilding when I think it is). I did validate though that adding other weird stuff (e.g., invalid tokens) causes compilation to fail. Assigning to myself to investigate on Monday.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-trait-systemArea: Trait systemP-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions