Skip to content

virtual function elimination: llvm error: Do not know how to promote this operator #124093

Open

Description

auto-reduced (treereduce-rust):

pub mod kitty {
    use std::fmt;

    pub struct cat {
        meows: usize,
        pub how_hungry: isize,
        pub name: String,
    }

    impl fmt::Display for cat {
        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
            write!(f, "{}", self.name)
        }
    }
}
original code

original:

pub mod kitty {
    use std::fmt;

    pub struct cat {
      meows : usize,
      pub how_hungry : isize,
      pub name : String,
    }

    impl fmt::Display for cat {
        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
            write!(f, "{}", self.name)
        }
    }

    impl cat {
        fn meow(&mut self) {
            println!("Meow");
            self.meows += 1;
            if self.meows % 5 == 0 {
                self.how_hungry += 1;
            }
        }

    }

    impl cat {
        pub fn speak(&mut self) { self.meow(); }

        pub fn eat(&mut self) -> bool {
            if self.how_hungry > 0 {
                println!("OM NOM NOM");
                self.how_hungry -= 2;
                return true;
            }
            else {
                println!("Not hungry!");
                return false;
            }
        }
    }

    pub fn cat(in_x : usize, in_y : isize, in_name: String) -> cat {
        cat {
            meows: in_x,
            how_hungry: in_y,
            name: in_name
        }
    }
}

Version information

rustc 1.79.0-nightly (00ed4edb4 2024-04-17)
binary: rustc
commit-hash: 00ed4edb44ccc76d8cc992ef9f9f4634ea6d0e82
commit-date: 2024-04-17
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.3

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zvirtual-function-elimination=true -Clto=true --crate-type=lib

Program output

warning: type `cat` should have an upper camel case name
 --> /tmp/icemaker_global_tempdir.8xGPA271RB07/rustc_testrunner_tmpdir_reporting.GzzcQXIiIZoj/mvce.rs:4:16
  |
4 |     pub struct cat {
  |                ^^^ help: convert the identifier to upper camel case (notice the capitalization): `Cat`
  |
  = note: `#[warn(non_camel_case_types)]` on by default

warning: field `meows` is never read
 --> /tmp/icemaker_global_tempdir.8xGPA271RB07/rustc_testrunner_tmpdir_reporting.GzzcQXIiIZoj/mvce.rs:5:9
  |
4 |     pub struct cat {
  |                --- field in this struct
5 |         meows: usize,
  |         ^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

rustc-LLVM ERROR: Do not know how to promote this operator!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.Category: This is a bug.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions