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

Type inference analysis confused by use in scope #3997

Closed
CAD97 opened this issue Apr 16, 2020 · 5 comments
Closed

Type inference analysis confused by use in scope #3997

CAD97 opened this issue Apr 16, 2020 · 5 comments

Comments

@CAD97
Copy link
Contributor

CAD97 commented Apr 16, 2020

(Sorry for the not-super-minimized rerpo, I ran into this while following the gfx-hal intro.)

Cargo.toml

[package]
name = "gfx-hal-tutorials"
version = "0.0.0"
edition = "2018"
publish = false

[dependencies]
winit = "0.22.0"

main.rs (use at root scope)

use winit::dpi::{LogicalSize, PhysicalSize};
const WINDOW_SIZE: [u32; 2] = [512, 512];

fn main() {
    let event_loop = winit::event_loop::EventLoop::new();

    let (logical_window_size, physical_window_size) = {
        let dpi = event_loop.primary_monitor().scale_factor();
        let logical: LogicalSize<u32> = WINDOW_SIZE.into();
        let physical: PhysicalSize<u32> = logical.to_physical(dpi);

        (logical, physical)
    };
}

image

main.rs (scoped use)

const WINDOW_SIZE: [u32; 2] = [512, 512];

fn main() {
    use winit::dpi::{LogicalSize, PhysicalSize};
    let event_loop = winit::event_loop::EventLoop::new();

    let (logical_window_size, physical_window_size) = {
        let dpi = event_loop.primary_monitor().scale_factor();
        let logical: LogicalSize<u32> = WINDOW_SIZE.into();
        let physical: PhysicalSize<u32> = logical.to_physical(dpi);

        (logical, physical)
    };
}

image

This second form infers the wrong type for logical_window_size, and no type for physical_window_size.

@edwin0cheng
Copy link
Member

edwin0cheng commented Apr 17, 2020

Local imports is still not being supported yet. (#1165)

@CAD97
Copy link
Contributor Author

CAD97 commented Apr 17, 2020

An interesting side-effect is r-a pulling what appears to be a completely random type that satisfies [u32; 2] as Into<$0> (maybe?) for logical_window_size here.

@flodiebold
Copy link
Member

I think that may be related to a bug where Chalk nondeterministically returns a definite result when it shouldn't. Does it still happen in latest RA?

@lnicola
Copy link
Member

lnicola commented Apr 17, 2020

image

They show up as unknown for me.

@flodiebold
Copy link
Member

Let's close this since we have #1165 for local imports and the weird inference is fixed.

@CAD97 CAD97 closed this as completed May 1, 2020
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

No branches or pull requests

4 participants