Skip to content

Lint against Sized constraints where appropriate #2172

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

Open
UserAB1236872 opened this issue Oct 24, 2017 · 0 comments
Open

Lint against Sized constraints where appropriate #2172

UserAB1236872 opened this issue Oct 24, 2017 · 0 comments
Labels
S-needs-discussion Status: Needs further discussion before merging or work can be started

Comments

@UserAB1236872
Copy link

I've used Rust for a while now, and a long time ago struggled with needing to add : Sized to some types. Apparently quite a while ago, this changed to Sized being default and needing to request unsizedness in certain contexts. I had been struggling thinking

trait Foo {
    type Assoc;
    fn foo(&self, in: &Assoc);
}

struct Bar {}

impl Foo for Bar {
    type Assoc = [AType];
    fn foo(&self, in: &[AType]) { ... }
}

Had simply become impossible (I haven't needed it since pre-1.0 so it could've been true) until I went on the Rust Discord and had it revealed that, in fact, Sized is the default and ?Sized needs to be requested; an un-constraint rather than a constraint.

Unfortunately, I've been operating under this assumption for a while so I have some code with associated types that needs Sized behavior that explicitly calls for type Assoc: Sized or <T: Sized>. It might be worth linting against Sized constraints and noting it's effectively a non-constraint.

One consideration is that : Sized could potentially be seen as documentation (i.e. "hello future coder do not change this to ?Sized please or things will break"), so I don't know if it should be on by default or not.

Related to #1368.

@oli-obk oli-obk added the S-needs-discussion Status: Needs further discussion before merging or work can be started label Oct 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-needs-discussion Status: Needs further discussion before merging or work can be started
Projects
None yet
Development

No branches or pull requests

2 participants