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

ICE: "resolving bounds outside of type inference": -Zmir-opt-level=3 --emit=mir #96170

Closed
matthiaskrgr opened this issue Apr 18, 2022 · 0 comments · Fixed by #96806
Closed

ICE: "resolving bounds outside of type inference": -Zmir-opt-level=3 --emit=mir #96170

matthiaskrgr opened this issue Apr 18, 2022 · 0 comments · Fixed by #96806
Assignees
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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.

Comments

@matthiaskrgr
Copy link
Member

Code

// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// run-pass

// Check that tautalogically false bounds are accepted, and are used
// in type inference.
#![feature(trivial_bounds)]
#![allow(unused)]

pub trait Foo {
    fn test(&self);
}

fn generic_function<X: Foo>(x: X) {}

enum E where i32: Foo { V }

struct S where i32: Foo;

trait T where i32: Foo {}

union U where i32: Foo { f: i32 }

type Y where i32: Foo = ();

impl Foo for () where i32: Foo {
    fn test(&self) {
        3i32.test();
        Foo::test(&4i32);
        generic_function(5i32);
    }
}

fn f() where i32: Foo {
    let s = S;
    3i32.test();
    Foo::test(&4i32);
    generic_function(5i32);
}

fn g() where &'static str: Foo {
    "Foo".test();
    Foo::test(&"Foo");
    generic_function("Foo");
}

trait A {}

impl A for i32 {}

struct Dst<X: ?Sized> {
    x: X,
}

struct TwoStrs(str, str) where str: Sized;

fn unsized_local() where for<'a> Dst<A + 'a>: Sized {
    let x: Dst<A> = *(Box::new(Dst { x: 1 }) as Box<Dst<A>>);
}

fn return_str() -> str where str: Sized {
    *"Sized".to_string().into_boxed_str()
}

fn use_op(s: String) -> String where String: ::std::ops::Neg<Output=String> {
    -s
}

fn use_for() where i32: Iterator {
    for _ in 2i32 {}
}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.62.0-nightly (878c7833f 2022-04-16)
binary: rustc
commit-hash: 878c7833f6c1ff10e2fd89074e5bd4ef5ff15936
commit-date: 2022-04-16
host: x86_64-unknown-linux-gnu
release: 1.62.0-nightly
LLVM version: 14.0.0

Error output

warning: trait objects without an explicit `dyn` are deprecated
  --> ./2c8b873b8c9462db590283b28bf0778bd62ac0e4.rs:65:38
   |
65 | fn unsized_local() where for<'a> Dst<A + 'a>: Sized {
   |                                      ^^^^^^
   |
   = note: `#[warn(bare_trait_objects)]` on by default
   = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
   = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: use `dyn`
   |
65 - fn unsized_local() where for<'a> Dst<A + 'a>: Sized {
65 + fn unsized_local() where for<'a> Dst<dyn A + 'a>: Sized {
   |

warning: trait objects without an explicit `dyn` are deprecated
  --> ./2c8b873b8c9462db590283b28bf0778bd62ac0e4.rs:66:16
   |
66 |     let x: Dst<A> = *(Box::new(Dst { x: 1 }) as Box<Dst<A>>);
   |                ^
   |
   = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
   = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: use `dyn`
   |
66 -     let x: Dst<A> = *(Box::new(Dst { x: 1 }) as Box<Dst<A>>);
66 +     let x: Dst<dyn A> = *(Box::new(Dst { x: 1 }) as Box<Dst<A>>);
   |

warning: trait objects without an explicit `dyn` are deprecated
  --> ./2c8b873b8c9462db590283b28bf0778bd62ac0e4.rs:66:57
   |
66 |     let x: Dst<A> = *(Box::new(Dst { x: 1 }) as Box<Dst<A>>);
   |                                                         ^
   |
   = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
   = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: use `dyn`
   |
66 -     let x: Dst<A> = *(Box::new(Dst { x: 1 }) as Box<Dst<A>>);
66 +     let x: Dst<A> = *(Box::new(Dst { x: 1 }) as Box<Dst<dyn A>>);
   |

warning: trait bound i32: Foo does not depend on any type or lifetime parameters
  --> ./2c8b873b8c9462db590283b28bf0778bd62ac0e4.rs:24:19
   |
24 | enum E where i32: Foo { V }
   |                   ^^^
   |
   = note: `#[warn(trivial_bounds)]` on by default

warning: trait bound i32: Foo does not depend on any type or lifetime parameters
  --> ./2c8b873b8c9462db590283b28bf0778bd62ac0e4.rs:26:21
   |
26 | struct S where i32: Foo;
   |                     ^^^

warning: trait bound i32: Foo does not depend on any type or lifetime parameters
  --> ./2c8b873b8c9462db590283b28bf0778bd62ac0e4.rs:28:20
   |
28 | trait T where i32: Foo {}
   |                    ^^^

warning: trait bound i32: Foo does not depend on any type or lifetime parameters
  --> ./2c8b873b8c9462db590283b28bf0778bd62ac0e4.rs:30:20
   |
30 | union U where i32: Foo { f: i32 }
   |                    ^^^

warning: where clauses are not enforced in type aliases
  --> ./2c8b873b8c9462db590283b28bf0778bd62ac0e4.rs:32:14
   |
32 | type Y where i32: Foo = ();
   |              ^^^^^^^^
   |
   = note: `#[warn(type_alias_bounds)]` on by default
help: the clause will not be checked when the type alias is used, and should be removed
   |
32 - type Y where i32: Foo = ();
32 + type Y  = ();
   |

warning: trait bound i32: Foo does not depend on any type or lifetime parameters
  --> ./2c8b873b8c9462db590283b28bf0778bd62ac0e4.rs:32:19
   |
32 | type Y where i32: Foo = ();
   |                   ^^^

warning: trait bound i32: Foo does not depend on any type or lifetime parameters
  --> ./2c8b873b8c9462db590283b28bf0778bd62ac0e4.rs:34:28
   |
34 | impl Foo for () where i32: Foo {
   |                            ^^^

warning: trait bound i32: Foo does not depend on any type or lifetime parameters
  --> ./2c8b873b8c9462db590283b28bf0778bd62ac0e4.rs:42:19
   |
42 | fn f() where i32: Foo {
   |                   ^^^

warning: trait bound &'static str: Foo does not depend on any type or lifetime parameters
  --> ./2c8b873b8c9462db590283b28bf0778bd62ac0e4.rs:49:28
   |
49 | fn g() where &'static str: Foo {
   |                            ^^^

warning: trait bound str: Sized does not depend on any type or lifetime parameters
  --> ./2c8b873b8c9462db590283b28bf0778bd62ac0e4.rs:63:37
   |
63 | struct TwoStrs(str, str) where str: Sized;
   |                                     ^^^^^

warning: trait bound for<'a> Dst<(dyn A + 'a)>: Sized does not depend on any type or lifetime parameters
  --> ./2c8b873b8c9462db590283b28bf0778bd62ac0e4.rs:65:47
   |
65 | fn unsized_local() where for<'a> Dst<A + 'a>: Sized {
   |                                               ^^^^^

warning: trait bound str: Sized does not depend on any type or lifetime parameters
  --> ./2c8b873b8c9462db590283b28bf0778bd62ac0e4.rs:69:35
   |
69 | fn return_str() -> str where str: Sized {
   |                                   ^^^^^

warning: trait bound String: Neg does not depend on any type or lifetime parameters
  --> ./2c8b873b8c9462db590283b28bf0778bd62ac0e4.rs:73:46
   |
73 | fn use_op(s: String) -> String where String: ::std::ops::Neg<Output=String> {
   |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: trait bound i32: Iterator does not depend on any type or lifetime parameters
  --> ./2c8b873b8c9462db590283b28bf0778bd62ac0e4.rs:77:25
   |
77 | fn use_for() where i32: Iterator {
   |                         ^^^^^^^^

warning: 17 warnings emitted

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: Encountered error `Unimplemented` selecting `Binder(<i32 as Foo>, [])` during codegen
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/codegen.rs:65:43

error: internal compiler error: Encountered error `Unimplemented` selecting `Binder(<&str as Foo>, [])` during codegen
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/codegen.rs:65:43

error: internal compiler error: Encountered error `Unimplemented` selecting `Binder(<std::string::String as std::ops::Neg>, [])` during codegen
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/codegen.rs:65:43

error: internal compiler error: Encountered errors `[FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<i32 as std::iter::Iterator>, polarity:Positive), []), depth=1),Unimplemented)]` resolving bounds outside of type inference
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/codegen.rs:125:24

error: internal compiler error: Encountered error `Unimplemented` selecting `Binder(<i32 as std::iter::Iterator>, [])` during codegen
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/codegen.rs:65:43

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1383:13
stack backtrace:
Backtrace

warning: 17 warnings emitted

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: Encountered error `Unimplemented` selecting `Binder(<i32 as Foo>, [])` during codegen
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/codegen.rs:65:43

error: internal compiler error: Encountered error `Unimplemented` selecting `Binder(<&str as Foo>, [])` during codegen
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/codegen.rs:65:43

error: internal compiler error: Encountered error `Unimplemented` selecting `Binder(<std::string::String as std::ops::Neg>, [])` during codegen
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/codegen.rs:65:43

error: internal compiler error: Encountered errors `[FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<i32 as std::iter::Iterator>, polarity:Positive), []), depth=1),Unimplemented)]` resolving bounds outside of type inference
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/codegen.rs:125:24

error: internal compiler error: Encountered error `Unimplemented` selecting `Binder(<i32 as std::iter::Iterator>, [])` during codegen
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/codegen.rs:65:43

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1383:13
stack backtrace:
   0:     0x7f1344e9d7fd - std::backtrace_rs::backtrace::libunwind::trace::h533af29c806df9d1
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f1344e9d7fd - std::backtrace_rs::backtrace::trace_unsynchronized::hdb4c2ff88b52ef66
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f1344e9d7fd - std::sys_common::backtrace::_print_fmt::h68495a06222c4efb
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f1344e9d7fd - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h91043f683408357d
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f1344ef8eec - core::fmt::write::hcc15453d8963f001
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/core/src/fmt/mod.rs:1194:17
   5:     0x7f1344e8ef51 - std::io::Write::write_fmt::h5217846c280e1260
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/std/src/io/mod.rs:1655:15
   6:     0x7f1344ea0515 - std::sys_common::backtrace::_print::h88be4bfce1061450
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f1344ea0515 - std::sys_common::backtrace::print::he017a6566e010988
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f1344ea0515 - std::panicking::default_hook::{{closure}}::hb793c4d82607bce7
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/std/src/panicking.rs:295:22
   9:     0x7f1344ea0189 - std::panicking::default_hook::hc3c558385f484fdc
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/std/src/panicking.rs:314:9
  10:     0x7f13456d1421 - rustc_driver[19d608e2c8daf1f4]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f1344ea0ce6 - std::panicking::rust_panic_with_hook::h28c3b2fc9e3a60cd
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/std/src/panicking.rs:702:17
  12:     0x7f134681af31 - std[cd658a55527ed977]::panicking::begin_panic::<rustc_errors[9417c7ccc58903d8]::ExplicitBug>::{closure#0}
  13:     0x7f1346819fe6 - std[cd658a55527ed977]::sys_common::backtrace::__rust_end_short_backtrace::<std[cd658a55527ed977]::panicking::begin_panic<rustc_errors[9417c7ccc58903d8]::ExplicitBug>::{closure#0}, !>
  14:     0x7f1346822fdf - std[cd658a55527ed977]::panicking::begin_panic::<rustc_errors[9417c7ccc58903d8]::ExplicitBug>
  15:     0x7f13468260f6 - std[cd658a55527ed977]::panic::panic_any::<rustc_errors[9417c7ccc58903d8]::ExplicitBug>
  16:     0x7f1347fde317 - <rustc_errors[9417c7ccc58903d8]::HandlerInner as core[9a854ec5d686c1fc]::ops::drop::Drop>::drop
  17:     0x7f13476ecea8 - core[9a854ec5d686c1fc]::ptr::drop_in_place::<rustc_session[52f1952c06c4e035]::parse::ParseSess>
  18:     0x7f13476ef4c3 - <alloc[c0e4610846cb0c5f]::rc::Rc<rustc_session[52f1952c06c4e035]::session::Session> as core[9a854ec5d686c1fc]::ops::drop::Drop>::drop
  19:     0x7f13477197ad - core[9a854ec5d686c1fc]::ptr::drop_in_place::<rustc_interface[c2767953942b9161]::interface::Compiler>
  20:     0x7f13477190a4 - rustc_span[ae9ba53627e4b7a2]::with_source_map::<core[9a854ec5d686c1fc]::result::Result<(), rustc_errors[9417c7ccc58903d8]::ErrorGuaranteed>, rustc_interface[c2767953942b9161]::interface::create_compiler_and_run<core[9a854ec5d686c1fc]::result::Result<(), rustc_errors[9417c7ccc58903d8]::ErrorGuaranteed>, rustc_driver[19d608e2c8daf1f4]::run_compiler::{closure#1}>::{closure#1}>
  21:     0x7f13476f0ee7 - <scoped_tls[673d87c3fad674a0]::ScopedKey<rustc_span[ae9ba53627e4b7a2]::SessionGlobals>>::set::<rustc_interface[c2767953942b9161]::interface::run_compiler<core[9a854ec5d686c1fc]::result::Result<(), rustc_errors[9417c7ccc58903d8]::ErrorGuaranteed>, rustc_driver[19d608e2c8daf1f4]::run_compiler::{closure#1}>::{closure#0}, core[9a854ec5d686c1fc]::result::Result<(), rustc_errors[9417c7ccc58903d8]::ErrorGuaranteed>>
  22:     0x7f13477062ff - std[cd658a55527ed977]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[c2767953942b9161]::util::run_in_thread_pool_with_globals<rustc_interface[c2767953942b9161]::interface::run_compiler<core[9a854ec5d686c1fc]::result::Result<(), rustc_errors[9417c7ccc58903d8]::ErrorGuaranteed>, rustc_driver[19d608e2c8daf1f4]::run_compiler::{closure#1}>::{closure#0}, core[9a854ec5d686c1fc]::result::Result<(), rustc_errors[9417c7ccc58903d8]::ErrorGuaranteed>>::{closure#0}, core[9a854ec5d686c1fc]::result::Result<(), rustc_errors[9417c7ccc58903d8]::ErrorGuaranteed>>
  23:     0x7f1347706439 - <<std[cd658a55527ed977]::thread::Builder>::spawn_unchecked_<rustc_interface[c2767953942b9161]::util::run_in_thread_pool_with_globals<rustc_interface[c2767953942b9161]::interface::run_compiler<core[9a854ec5d686c1fc]::result::Result<(), rustc_errors[9417c7ccc58903d8]::ErrorGuaranteed>, rustc_driver[19d608e2c8daf1f4]::run_compiler::{closure#1}>::{closure#0}, core[9a854ec5d686c1fc]::result::Result<(), rustc_errors[9417c7ccc58903d8]::ErrorGuaranteed>>::{closure#0}, core[9a854ec5d686c1fc]::result::Result<(), rustc_errors[9417c7ccc58903d8]::ErrorGuaranteed>>::{closure#1} as core[9a854ec5d686c1fc]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  24:     0x7f1344eaab93 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha55af26f35189599
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/alloc/src/boxed.rs:1866:9
  25:     0x7f1344eaab93 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h6a841b0f36efd076
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/alloc/src/boxed.rs:1866:9
  26:     0x7f1344eaab93 - std::sys::unix::thread::Thread::new::thread_start::h4d154f7a3783bf9b
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/std/src/sys/unix/thread.rs:108:17
  27:     0x7f1344c835c2 - start_thread
  28:     0x7f1344d08584 - __clone
  29:                0x0 - <unknown>

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.62.0-nightly (878c7833f 2022-04-16) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-opt-level=3

query stack during panic:
end of query stack

@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. labels Apr 18, 2022
@compiler-errors compiler-errors self-assigned this Apr 20, 2022
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Apr 23, 2022
@bors bors closed this as completed in cb9cb4d May 12, 2022
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. glacier ICE tracked in rust-lang/glacier. 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants