Skip to content

inline_const blocks type inference #89964

Closed
@scottmcm

Description

@scottmcm

I tried this code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=b628c24337168091d1c20e62ff6e31e8

#![feature(inline_const)]
use std::collections::HashMap;
fn main() {
    let mut h = <HashMap<usize, Vec<i32>>>::new();
    h.entry(123).or_insert(const { Vec::new() });
    dbg!(h);
}

I expected to see this happen: It compiles, the same as the following (without the const{}) does https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=2da5b1d9926024223ba6dff77a647f17

#![feature(inline_const)]
use std::collections::HashMap;
fn main() {
    let mut h = <HashMap<usize, Vec<i32>>>::new();
    h.entry(123).or_insert(Vec::new());
    dbg!(h);
}

Instead, this happened: type inference fails

error[E0282]: type annotations needed
 --> src/main.rs:5:36
  |
5 |     h.entry(123).or_insert(const { Vec::new() });
  |                                    ^^^^^^^^ cannot infer type for type parameter `T`

(Spotted after looking at https://internals.rust-lang.org/t/should-clippy-warn-about-function-calls-outside-closures-if-those-are-const-answered/15452/4?u=scottmcm)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-inline_constInline constants (aka: const blocks, const expressions, anonymous constants)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions