Skip to content

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

Closed

Description

@arielb1
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

Activity

  1. brson commented on Jan 12, 2017

    @brson
    Contributor

    Still a problem?

  2. nikomatsakis commented on Jan 12, 2017

    @nikomatsakis
    Contributor

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

  3. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    I-compiletimeIssue: Problems and improvements with respect to compile times.
    on Jul 22, 2017
  4. durka commented on Aug 29, 2018

    @durka
    Contributor

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

  5. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Jan 31, 2020
  6. jonas-schievink commented on Jan 31, 2020

    @jonas-schievink
    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
    
  7. added
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    and removed
    I-compiletimeIssue: Problems and improvements with respect to compile times.
    on Jan 31, 2020
  8. added a commit that references this issue on Apr 25, 2020
  9. added a commit that references this issue on Apr 26, 2020
  10. added and removed on Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationA-type-systemArea: Type systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions