Skip to content

Can not create static function pointer to generic instantiation #13971

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

Closed
Kimundi opened this issue May 6, 2014 · 1 comment · Fixed by #21447
Closed

Can not create static function pointer to generic instantiation #13971

Kimundi opened this issue May 6, 2014 · 1 comment · Fixed by #21447

Comments

@Kimundi
Copy link
Member

Kimundi commented May 6, 2014

Testcase:

fn foo<T>(a: T) -> T { a }

static BLOCK_FN: fn(usize) -> uint = foo::<usize>;

fn main() {}

Output:

bug_generic_static_function_ptr.rs:3:37: 3:48 error: paths in constants may only refer to items without type parameters
bug_generic_static_function_ptr.rs:3 static BLOCK_FN: fn(usize) -> uint = foo::<usize>;
                                                                         ^~~~~~~~~~~
error: aborting due to previous error

@Kimundi Kimundi changed the title Can not create static function pointer to generic instiation Can not create static function pointer to generic instantiation May 6, 2014
@emberian
Copy link
Member

No longer repros, uncommenting test.

alexcrichton added a commit to alexcrichton/rust that referenced this issue Jan 21, 2015
bors added a commit to rust-lang-ci/rust that referenced this issue Feb 13, 2023
…ypes, r=Veykril

fix: more precise binop inference

While inferring binary operator expressions, Rust puts some extra constraints on the types of the operands for better inference. Relevant part in rustc is [this](https://github.com/rust-lang/rust/blob/159ba8a92c9e2fa4121f106176309521f4af87e9/compiler/rustc_hir_typeck/src/op.rs#L128-L152).

There are two things we currently fail to consider:
- we should enforce them only when both lhs and rhs type are builtin types that are applicable to the binop
- lhs and rhs types may be single reference to applicable builtin types

This PR basically ports [`enforce_builtin_binop_types()`](https://github.com/rust-lang/rust/blob/159ba8a92c9e2fa4121f106176309521f4af87e9/compiler/rustc_hir_typeck/src/op.rs#L159) and [`is_builtin_binop()`](https://github.com/rust-lang/rust/blob/159ba8a92c9e2fa4121f106176309521f4af87e9/compiler/rustc_hir_typeck/src/op.rs#LL927) to our inference context.
bors pushed a commit to rust-lang-ci/rust that referenced this issue Jan 28, 2025
I noticed that this was missing bf482928 while doing the release. No
harm done, as it was updated on the next push to master.

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants