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

broken MIR in DefId(0:15 ~ nocore[d905]::{impl#0}::add) #92157

Closed
kpp opened this issue Dec 21, 2021 · 5 comments · Fixed by #106878
Closed

broken MIR in DefId(0:15 ~ nocore[d905]::{impl#0}::add) #92157

kpp opened this issue Dec 21, 2021 · 5 comments · Fixed by #106878
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kpp
Copy link
Contributor

kpp commented Dec 21, 2021

Code

#![feature(no_core)]
#![feature(lang_items)]

#![no_core]
#[cfg(target_os = "linux")]
#[link(name = "c")]
extern {}

#[lang = "start"]
fn start<T>(_main: fn() -> T, _argc: isize, _argv: *const *const u8) -> isize {
    40+2
}
pub fn main() { }

#[lang = "sized"]
pub trait Sized {}
#[lang = "copy"]
pub trait Copy {}

#[lang = "drop_in_place"]
#[allow(unconditional_recursion)]
pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
    drop_in_place(to_drop)
}

#[lang = "add"]
trait Add<RHS> {
    type Output;
    fn add(self, other: RHS) -> Self::Output;
}

impl Add<isize> for isize {
    type Output = isize;
    fn add(self, other: isize) -> isize {
        self + other
    }
}

Meta

rustc --version --verbose:

rustc 1.59.0-nightly (91a0600a5 2021-12-18) running on x86_64-unknown-linux-gnu

Error output

error: internal compiler error: broken MIR in DefId(0:15 ~ nocore[d905]::{impl#0}::add) (NoSolution): could not prove Binder(TraitPredicate(<isize as Copy>, polarity:Positive), [])
  |
  = note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:319:27

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:1188:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug

note: rustc 1.59.0-nightly (91a0600a5 2021-12-18) running on x86_64-unknown-linux-gnu
Backtrace

stack backtrace:
   0: rust_begin_unwind
             at /rustc/91a0600a5c22b9d159e3c57526af83e71d1120f8/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/91a0600a5c22b9d159e3c57526af83e71d1120f8/library/core/src/panicking.rs:107:14
   2: core::panicking::panic_display::<&str>
   3: <rustc_errors::HandlerInner>::flush_delayed
   4: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
   5: core::ptr::drop_in_place::<rustc_session::parse::ParseSess>
   6: <alloc::rc::Rc<rustc_session::session::Session> as core::ops::drop::Drop>::drop
   7: core::ptr::drop_in_place::<rustc_interface::interface::Compiler>
   8: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
   9: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@kpp kpp added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 21, 2021
@kpp
Copy link
Contributor Author

kpp commented Dec 21, 2021

A "fix" for that code is to add impl Copy for isize {} however I don't want to get an ICE but a nice error.

@bjorn3 bjorn3 added the requires-nightly This issue requires a nightly compiler in some way. label Dec 21, 2021
@bjorn3
Copy link
Member

bjorn3 commented Dec 21, 2021

The error comes from

// To have a `Copy` operand, the type `T` of the
// value must be `Copy`. Note that we prove that `T: Copy`,
// rather than using the `is_copy_modulo_regions`
// test. This is important because
// `is_copy_modulo_regions` ignores the resulting region
// obligations and assumes they pass. This can result in
// bounds from `Copy` impls being unsoundly ignored (e.g.,
// #29149). Note that we decide to use `Copy` before knowing
// whether the bounds fully apply: in effect, the rule is
// that if a value of some type could implement `Copy`, then
// it must.
self.cx.prove_trait_ref(
trait_ref,
location.to_locations(),
ConstraintCategory::CopyBound,
);
I think. If you weren't using #![no_core] hitting this case would be a genuine bug in rustc. Turning it from an ICE into a nice error would require special casing integer types to not ICE here. In general you should expect to see internal compiler errors when you mess up with #![no_core]. In some cases it is feasible to give nice errors but I think this is not such a case.

@kpp
Copy link
Contributor Author

kpp commented Dec 21, 2021

Thanks! You may close if you think there is nothing you can do.

@inquisitivecrystal
Copy link
Contributor

The error comes from

// To have a `Copy` operand, the type `T` of the
// value must be `Copy`. Note that we prove that `T: Copy`,
// rather than using the `is_copy_modulo_regions`
// test. This is important because
// `is_copy_modulo_regions` ignores the resulting region
// obligations and assumes they pass. This can result in
// bounds from `Copy` impls being unsoundly ignored (e.g.,
// #29149). Note that we decide to use `Copy` before knowing
// whether the bounds fully apply: in effect, the rule is
// that if a value of some type could implement `Copy`, then
// it must.
self.cx.prove_trait_ref(
trait_ref,
location.to_locations(),
ConstraintCategory::CopyBound,
);

I think. If you weren't using #![no_core] hitting this case would be a genuine bug in rustc. Turning it from an ICE into a nice error would require special casing integer types to not ICE here. In general you should expect to see internal compiler errors when you mess up with #![no_core]. In some cases it is feasible to give nice errors but I think this is not such a case.

I am by no means familiar with the relevant code, but this would seem more like a basis for making this a P-low than closing it entirely. As in, it would be nice if there was a way to fix this, but we don't know what it is and it's not really a priority.

@JohnTitor
Copy link
Member

Triage: Fixed since nightly-2023-01-04, marking as E-needs-test.

@JohnTitor JohnTitor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Jan 14, 2023
JohnTitor added a commit to JohnTitor/rust that referenced this issue Jan 14, 2023
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 15, 2023
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#106072 (fix: misleading "add dyn keyword before derive macro" suggestion)
 - rust-lang#106859 (Suggestion for type mismatch when we need a u8 but the programmer wrote a char literal)
 - rust-lang#106863 (Remove various double spaces in compiler source comments.)
 - rust-lang#106865 (Add explanation comment for GUI test)
 - rust-lang#106867 (Fix the stability attributes for `std::os::fd`.)
 - rust-lang#106878 (Add regression test for rust-lang#92157)
 - rust-lang#106879 (Add regression test for rust-lang#42114)
 - rust-lang#106880 (doc: fix typo)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in 08ef0ce Jan 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants