Skip to content

Bad closure bounds check #3354

@philberty

Description

@philberty

Summary

Closures automatically implement the fn trait so this needs fixed

Reproducer

I tried this code:

#[lang = "sized"]
pub trait Sized {}

#[lang = "fn_once"]
pub trait FnOnce<Args> {
    #[lang = "fn_once_output"]
    type Output;

    extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
}


pub fn test() {
    let add: fn(i32) -> i32 = |x| {
    	x
    };
}

Does the code make use of any (1.49) nightly feature ?

  • Nightly

Godbolt link

https://godbolt.org/z/d4oo8dYoT

Actual behavior

The current behavior is...

<source>:14:5: error: bounds not satisfied for fnptr (i32 ,) -> i32 'FnOnce' is not satisfied [E0277]
   14 |     let add: fn(i32) -> i32 = |x| {
      |     ^~~ 

Expected behavior

I expected to see...

compiles

GCC Version

9de4235

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Todo

Relationships

None yet

Development

No branches or pull requests

Issue actions