Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Incoherent impls are still allowed on opaque types #86411

Closed
matthewjasper opened this issue Jun 17, 2021 · 3 comments · Fixed by #95973
Closed

Incoherent impls are still allowed on opaque types #86411

matthewjasper opened this issue Jun 17, 2021 · 3 comments · Fixed by #95973
Assignees
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness requires-nightly This issue requires a nightly compiler in some way. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@matthewjasper
Copy link
Contributor

matthewjasper commented Jun 17, 2021

I tried this code (modified version of #74298):

#![feature(min_type_alias_impl_trait)]

type X<T> = impl Sized;

fn f<T>() -> X<T> {}

trait Y {
    fn g(&self) {}
}

impl Y for (X<()>,) {}
impl Y for (X<i32>,) {}

fn main() {
    (f::<()>(),).g();
}

I expected to see this happen: incoherent impls error

Instead, this happened: ICE during codegen

Meta

rustc --version --verbose:

rustc 1.54.0-nightly (657bc0188 2021-05-31)
binary: rustc
commit-hash: 657bc01888e6297257655585f9c475a0801db6d2
commit-date: 2021-05-31
host: x86_64-unknown-linux-gnu
release: 1.54.0-nightly
LLVM version: 12.0.1
Backtrace


thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:1021:13
stack backtrace:
   0:     0x7f8294e6af80 - std::backtrace_rs::backtrace::libunwind::trace::h1a39bd9a98540471
                               at /rustc/657bc01888e6297257655585f9c475a0801db6d2/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
   1:     0x7f8294e6af80 - std::backtrace_rs::backtrace::trace_unsynchronized::h21a1eeae7103ab3f
                               at /rustc/657bc01888e6297257655585f9c475a0801db6d2/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f8294e6af80 - std::sys_common::backtrace::_print_fmt::hc9ffbae9ed6a9871
                               at /rustc/657bc01888e6297257655585f9c475a0801db6d2/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7f8294e6af80 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h17510753a34a3f09
                               at /rustc/657bc01888e6297257655585f9c475a0801db6d2/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x7f8294ed89ac - core::fmt::write::h1e5a1f350e43b10f
                               at /rustc/657bc01888e6297257655585f9c475a0801db6d2/library/core/src/fmt/mod.rs:1110:17
   5:     0x7f8294e5c805 - std::io::Write::write_fmt::h06ec27c6d028baf1
                               at /rustc/657bc01888e6297257655585f9c475a0801db6d2/library/std/src/io/mod.rs:1588:15
   6:     0x7f8294e6eddb - std::sys_common::backtrace::_print::h1a02603349b1dc60
                               at /rustc/657bc01888e6297257655585f9c475a0801db6d2/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x7f8294e6eddb - std::sys_common::backtrace::print::h0fc317d31c48cd9b
                               at /rustc/657bc01888e6297257655585f9c475a0801db6d2/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x7f8294e6eddb - std::panicking::default_hook::{{closure}}::ha522601c22d7057b
                               at /rustc/657bc01888e6297257655585f9c475a0801db6d2/library/std/src/panicking.rs:208:50
   9:     0x7f8294e6e8b1 - std::panicking::default_hook::hd50ab173af9a3ce8
                               at /rustc/657bc01888e6297257655585f9c475a0801db6d2/library/std/src/panicking.rs:225:9
  10:     0x7f829563f78d - rustc_driver::report_ice::h0bbc0ae77d597594
  11:     0x7f8294e6f5e6 - std::panicking::rust_panic_with_hook::hb5a01416e02405ad
                               at /rustc/657bc01888e6297257655585f9c475a0801db6d2/library/std/src/panicking.rs:626:17
  12:     0x7f8294e6f0c7 - std::panicking::begin_panic_handler::{{closure}}::hf1dda5d5c0706ee0
                               at /rustc/657bc01888e6297257655585f9c475a0801db6d2/library/std/src/panicking.rs:519:13
  13:     0x7f8294e6b45c - std::sys_common::backtrace::__rust_end_short_backtrace::h56c02e9609085b17
                               at /rustc/657bc01888e6297257655585f9c475a0801db6d2/library/std/src/sys_common/backtrace.rs:141:18
  14:     0x7f8294e6f029 - rust_begin_unwind
                               at /rustc/657bc01888e6297257655585f9c475a0801db6d2/library/std/src/panicking.rs:515:5
  15:     0x7f8294e37eeb - std::panicking::begin_panic_fmt::h5889dddec113b3e8
                               at /rustc/657bc01888e6297257655585f9c475a0801db6d2/library/std/src/panicking.rs:457:5
  16:     0x7f8297ac5969 - rustc_errors::HandlerInner::flush_delayed::h71762d6b78304836
  17:     0x7f8297ac441d - <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop::h4ee3903f55419f69
  18:     0x7f8297140d06 - core::ptr::drop_in_place<rustc_session::parse::ParseSess>::hd706f063b3ef96ed
  19:     0x7f829714334e - <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop::h30ee59f057910eb2
  20:     0x7f82971464dd - core::ptr::drop_in_place<rustc_interface::interface::Compiler>::hf2f304d3f5096f94
  21:     0x7f8297145f50 - rustc_span::with_source_map::h6ee13da35fa72295
  22:     0x7f8297148ac8 - scoped_tls::ScopedKey<T>::set::h9c6565b722913393
  23:     0x7f829716d9db - std::sys_common::backtrace::__rust_begin_short_backtrace::hdcf17779193f6d57
  24:     0x7f82971447b5 - core::ops::function::FnOnce::call_once{{vtable.shim}}::hf48084e1b458d4b2
  25:     0x7f8294e7bad7 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hf00ff0dfc0b9e39f
                               at /rustc/657bc01888e6297257655585f9c475a0801db6d2/library/alloc/src/boxed.rs:1575:9
  26:     0x7f8294e7bad7 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h236979b1b61b3517
                               at /rustc/657bc01888e6297257655585f9c475a0801db6d2/library/alloc/src/boxed.rs:1575:9
  27:     0x7f8294e7bad7 - std::sys::unix::thread::Thread::new::thread_start::h8f357e546e4775fa
                               at /rustc/657bc01888e6297257655585f9c475a0801db6d2/library/std/src/sys/unix/thread.rs:71:17
  28:     0x7f8294dba609 - start_thread
  29:     0x7f8294cce293 - clone
  30:                0x0 - <unknown>

error: internal compiler error: unexpected panic

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.54.0-nightly (657bc0188 2021-05-31) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z verbose -C debuginfo=1 -C linker=/opt/compiler-explorer/gcc-11.1.0/bin/gcc --crate-type bin


@matthewjasper matthewjasper added C-bug Category: This is a bug. A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness requires-nightly This issue requires a nightly compiler in some way. labels Jun 17, 2021
@nikomatsakis
Copy link
Contributor

I think for the time being, we should just forbid opaque types from appearing in impl headers altogether.

Eventually it might be something we could support.

@nikomatsakis
Copy link
Contributor

@rustbot assign @lqd

@lqd
Copy link
Member

lqd commented Jun 29, 2021

Since there's already a simple check, added in #76940, my thoughts were to handle the more complex cases at the same place:

if let ty::Opaque(def_id, _) = *trait_ref.self_ty().kind() {
self.tcx
.sess
.struct_span_err(sp, "cannot implement trait on type alias impl trait")
.span_note(self.tcx.def_span(def_id), "type alias impl trait defined here")
.emit();
}

Is the idea to instead use a TypeFolder or visitor there on the trait ref substs, and emit basically the same error (maybe only when the min-TAIT gate is active) ?

Interestingly enough there are a couple tests setting up conflicting implementations with an opaque type argument:

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness requires-nightly This issue requires a nightly compiler in some way. T-types Relevant to the types team, which will review and decide on the PR/issue.
6 participants