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

Methods that return unsized types can be (uselessly) codegened #26376

Closed
arielb1 opened this issue Jun 17, 2015 · 4 comments · Fixed by #71541
Closed

Methods that return unsized types can be (uselessly) codegened #26376

arielb1 opened this issue Jun 17, 2015 · 4 comments · Fixed by #71541
Labels
A-codegen Area: Code generation A-typesystem Area: The type system C-enhancement Category: An issue proposing an enhancement or a PR with one. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@arielb1
Copy link
Contributor

arielb1 commented Jun 17, 2015

trait Foo {
    fn foo(&self) -> [u8];
}

fn foo(f: Option<&Foo>) {
    if let Some(f) = f {
        let _ = f.foo();
    }
}

fn main() { foo(None) }

This does generate code that calls foo in the vtable, but is not particularly useful.

cc @nikomatsakis

@steveklabnik steveklabnik added the A-typesystem Area: The type system label Jun 23, 2015
@brson brson added A-codegen Area: Code generation P-low Low priority labels Jan 12, 2017
@brson
Copy link
Contributor

brson commented Jan 12, 2017

Still a problem?

@nikomatsakis
Copy link
Contributor

It's still true, but I'm not especially worried about it.

@Mark-Simulacrum Mark-Simulacrum added C-enhancement Category: An issue proposing an enhancement or a PR with one. I-compiletime Issue: Problems and improvements with respect to compile times. labels Jul 22, 2017
@durka
Copy link
Contributor

durka commented Aug 29, 2018

Isn't it a bug that you can declare such a trait at all? There's no way to implement it, right?

@jonas-schievink jonas-schievink added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jan 31, 2020
@jonas-schievink
Copy link
Contributor

This code is now rejected with:

error[E0161]: cannot move a value of type [u8]: the size of [u8] cannot be statically determined
 --> src/main.rs:7:17
  |
7 |         let _ = f.foo();
  |                 ^^^^^^^

error: aborting due to previous error

@jonas-schievink jonas-schievink added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. and removed I-compiletime Issue: Problems and improvements with respect to compile times. labels Jan 31, 2020
wesleywiser added a commit to wesleywiser/rust that referenced this issue Apr 25, 2020
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 26, 2020
Rollup of 5 pull requests

Successful merges:

 - rust-lang#70043 (Add all remaining `DefKind`s.)
 - rust-lang#71140 ([breaking change] Disallow statics initializing themselves)
 - rust-lang#71392 (Don't hold the predecessor cache lock longer than necessary)
 - rust-lang#71541 (Add regression test for rust-lang#26376)
 - rust-lang#71554 (Replace thread_local with generator resume arguments in box_region.)

Failed merges:

r? @ghost
@bors bors closed this as completed in fde4727 Apr 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation A-typesystem Area: The type system C-enhancement Category: An issue proposing an enhancement or a PR with one. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants