Stream: t-compiler/help

Topic: codegen_ssa::FunctionCx::monomorphize


Bastian Kauschke (Mar 21 2020 at 18:02, on Zulip):

Hi, I am currently trying to fix https://github.com/rust-lang/rust/issues/70125

I am kind of stuck with FunctionCx::monomophize. https://github.com/rust-lang/rust/blob/7900b2bc135a0e02d945143176cf3a80b6e92aa8/src/librustc_codegen_ssa/mir/mod.rs#L86-L102

The following uses this function and ends up failing there.

const L: usize = 3;

pub trait Print<const N: usize> {
    fn print(&self) -> usize {
        N
       // the subst for  `N` is unevaluatated
    }
}

pub struct Printer {}
impl Print<L> for Printer {}

fn main() {
    let p = Printer {};
    assert_eq!(p.print(), 3);
}

And the following seems to not use FunctionCx::monomorphize at all and compiles, which kind of surprises me

pub trait Print<const N: usize> {
    fn print(&self) -> usize {
        N
    }
}

pub struct Printer {}
impl Print<3> for Printer
fn main() {
    let p = Printer {};
    assert_eq!(p.print(), 3);
}

Can someone help me out with when exactly monomorphize is called?

Bastian Kauschke (Mar 21 2020 at 18:29, on Zulip):

ok, the error is actually not in monomorphize :laughing:

Last update: Sep 27 2020 at 13:15UTC