Skip to content

[ICE]: stricter_of: left and right restriction do not reference the same crate #160873

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

pub mod inner {
    #[derive(Default)]
    pub struct InnerS {
        pub mut(self) x: i32,
        pub mut(in std) i2: i32,
    }
}

original:

#![feature(mut_restriction)]

#[derive(Default)]
pub struct TopLevelS {
    pub mut(crate) x: i32,
    pub y: i32,
}

pub enum TopLevelE {
    Var {
        mut(crate) x: i32,
        y: i32,
    },
    Tup(mut(crate) i32, i32),
}

pub union TopLevelU {
    pub mut(crate) x: i32,
    pub y: i32,
}

pub mod inner {
    #[derive(Default)]
    pub struct InnerS {
        pub mut(self) x: i32,
        pub mut(in ::std) i2: i32,
    }

    pub enum InnerE {
        Var {
            mut(self) x: i32,
            y: i32,
        },
        Tup(mut(self) i32, i32),
    }

    pub union InnerU {
        pub mut(self) x: i32,
        pub y: i32,
    }
}

Version information

rustc 1.99.0-nightly (ea0604237 2026-08-10)
binary: rustc
commit-hash: ea060423749bf6e561c3398f403425c502beb9ba
commit-date: 2026-08-10
host: x86_64-unknown-linux-gnu
release: 1.99.0-nightly
LLVM version: 23.1.0

Possibly related line of code:

(RestrictionKind::Unrestricted, r) | (r, RestrictionKind::Unrestricted) => r,
(
RestrictionKind::Restricted(left_did, _),
RestrictionKind::Restricted(right_did, _),
) => {
if left_did.krate != right_did.krate {
bug!("stricter_of: left and right restriction do not reference the same crate");
}
if tcx.is_descendant_of(left_did, right_did) { self } else { rhs }
}
}
}
}

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error: field mutation can only be restricted to ancestor modules
 --> /tmp/icemaker_global_tempdir.CGLljZwjTbOy/rustc_testrunner_tmpdir_reporting.vePoqhBRFU9l/mvce.rs:5:20
  |
5 |         pub mut(in std) i2: i32,
  |                    ^^^

error[E0658]: `mut` restrictions are experimental
 --> /tmp/icemaker_global_tempdir.CGLljZwjTbOy/rustc_testrunner_tmpdir_reporting.vePoqhBRFU9l/mvce.rs:4:13
  |
4 |         pub mut(self) x: i32,
  |             ^^^^^^^^^
  |
  = note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
  = help: add `#![feature(mut_restriction)]` to the crate attributes to enable
  = note: this compiler was built on 2026-08-10; consider upgrading it if it is out of date

error[E0658]: `mut` restrictions are experimental
 --> /tmp/icemaker_global_tempdir.CGLljZwjTbOy/rustc_testrunner_tmpdir_reporting.vePoqhBRFU9l/mvce.rs:5:13
  |
5 |         pub mut(in std) i2: i32,
  |             ^^^^^^^^^^^
  |
  = note: see issue #105077 <https://github.com/rust-lang/rust/issues/105077> for more information
  = help: add `#![feature(mut_restriction)]` to the crate attributes to enable
  = note: this compiler was built on 2026-08-10; consider upgrading it if it is out of date

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.CGLljZwjTbOy/rustc_testrunner_tmpdir_reporting.vePoqhBRFU9l/mvce.rs:7:2
  |
7 | }
  |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.CGLljZwjTbOy/rustc_testrunner_tmpdir_reporting.vePoqhBRFU9l/mvce.rs`

error: internal compiler error: /rustc-dev/ea060423749bf6e561c3398f403425c502beb9ba/compiler/rustc_middle/src/ty/mod.rs:458:21: stricter_of: left and right restriction do not reference the same crate


thread 'rustc' (4161557) panicked at /rustc-dev/ea060423749bf6e561c3398f403425c502beb9ba/compiler/rustc_middle/src/ty/mod.rs:458:21:
Box<dyn Any>
stack backtrace:
   0:     0x7f83846b1446 - <<std[9c753cd266a8fcaa]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[6d4b1fdd3a6c2a5d]::fmt::Display>::fmt
   1:     0x7f8384e0ebcf - core[6d4b1fdd3a6c2a5d]::fmt::write
   2:     0x7f83846c636c - <std[9c753cd266a8fcaa]::sys::stdio::unix::Stderr as core[6d4b1fdd3a6c2a5d]::io::write::Write>::write_fmt
   3:     0x7f83846844ba - std[9c753cd266a8fcaa]::panicking::default_hook::{closure#0}
   4:     0x7f83846a51d3 - std[9c753cd266a8fcaa]::panicking::default_hook
   5:     0x7f838363336a - std[9c753cd266a8fcaa]::panicking::update_hook::<alloc[ef0849ade25201a2]::boxed::Box<rustc_driver_impl[68770ae6fe528fea]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f83846a5672 - std[9c753cd266a8fcaa]::panicking::panic_with_hook
   7:     0x7f8383660ed4 - std[9c753cd266a8fcaa]::panicking::begin_panic::<rustc_errors[4770f19ac3513e26]::ExplicitBug>::{closure#0}
   8:     0x7f8383659b16 - std[9c753cd266a8fcaa]::sys::backtrace::__rust_end_short_backtrace::<std[9c753cd266a8fcaa]::panicking::begin_panic<rustc_errors[4770f19ac3513e26]::ExplicitBug>::{closure#0}, !>
   9:     0x7f838365995b - std[9c753cd266a8fcaa]::panicking::begin_panic::<rustc_errors[4770f19ac3513e26]::ExplicitBug>
  10:     0x7f838366c841 - <rustc_errors[4770f19ac3513e26]::diagnostic::BugAbort as rustc_errors[4770f19ac3513e26]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7f8383bf5769 - rustc_middle[92a732b8f1464377]::util::bug::opt_span_bug_fmt::<rustc_span[b3f964fbe3485545]::span_encoding::Span>::{closure#0}
  12:     0x7f8383bf5b62 - rustc_middle[92a732b8f1464377]::ty::context::tls::with_opt::<rustc_middle[92a732b8f1464377]::util::bug::opt_span_bug_fmt<rustc_span[b3f964fbe3485545]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  13:     0x7f8383be04f0 - rustc_middle[92a732b8f1464377]::ty::context::tls::with_context_opt::<rustc_middle[92a732b8f1464377]::ty::context::tls::with_opt<rustc_middle[92a732b8f1464377]::util::bug::opt_span_bug_fmt<rustc_span[b3f964fbe3485545]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  14:     0x7f8380baab74 - rustc_middle[92a732b8f1464377]::util::bug::bug_fmt
  15:     0x7f83856cb01e - <rustc_mir_transform[ae9d32225cc4301b]::check_mut_restriction::CheckMutRestriction as rustc_mir_transform[ae9d32225cc4301b]::pass_manager::MirLint>::run_lint
  16:     0x7f8384e25583 - rustc_mir_transform[ae9d32225cc4301b]::mir_built
  17:     0x7f83855f77b5 - rustc_query_impl[57c7831b71573462]::execution::try_execute_query::<rustc_data_structures[a65dd62818d036b8]::vec_cache::VecCache<rustc_span[b3f964fbe3485545]::def_id::LocalDefId, rustc_middle[92a732b8f1464377]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[92a732b8f1464377]::dep_graph::graph::DepNodeIndex>, false>
  18:     0x7f83855f74e7 - rustc_query_impl[57c7831b71573462]::query_impl::mir_built::execute_query_non_incr::__rust_end_short_backtrace
  19:     0x7f8385aaec05 - rustc_mir_build[d72efe58f858893a]::check_unsafety::check_unsafety
  20:     0x7f83855fb09e - rustc_query_impl[57c7831b71573462]::execution::try_execute_query::<rustc_data_structures[a65dd62818d036b8]::vec_cache::VecCache<rustc_span[b3f964fbe3485545]::def_id::LocalDefId, rustc_middle[92a732b8f1464377]::query::erase::ErasedData<[u8; 0usize]>, rustc_middle[92a732b8f1464377]::dep_graph::graph::DepNodeIndex>, false>
  21:     0x7f83855fae15 - rustc_query_impl[57c7831b71573462]::query_impl::check_unsafety::execute_query_non_incr::__rust_end_short_backtrace
  22:     0x7f83855f9d60 - <rustc_middle[92a732b8f1464377]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface[38db8d455abfb687]::passes::run_required_analyses::{closure#2}::{closure#0}>::{closure#0}
  23:     0x7f83855f91fe - rustc_interface[38db8d455abfb687]::passes::analysis
  24:     0x7f8385fd1b4a - rustc_query_impl[57c7831b71573462]::execution::try_execute_query::<rustc_middle[92a732b8f1464377]::query::caches::SingleCache<rustc_middle[92a732b8f1464377]::query::erase::ErasedData<[u8; 0usize]>>, false>
  25:     0x7f8385fd18d3 - rustc_query_impl[57c7831b71573462]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  26:     0x7f8386055f77 - rustc_interface[38db8d455abfb687]::interface::run_compiler::<(), rustc_driver_impl[68770ae6fe528fea]::run_compiler::{closure#0}>::{closure#2}
  27:     0x7f838607e3e4 - std[9c753cd266a8fcaa]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[38db8d455abfb687]::util::run_in_thread_with_globals<rustc_interface[38db8d455abfb687]::util::run_in_thread_pool_with_globals<rustc_interface[38db8d455abfb687]::interface::run_compiler<(), rustc_driver_impl[68770ae6fe528fea]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  28:     0x7f838607e1ad - <std[9c753cd266a8fcaa]::thread::lifecycle::spawn_unchecked<rustc_interface[38db8d455abfb687]::util::run_in_thread_with_globals<rustc_interface[38db8d455abfb687]::util::run_in_thread_pool_with_globals<rustc_interface[38db8d455abfb687]::interface::run_compiler<(), rustc_driver_impl[68770ae6fe528fea]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[6d4b1fdd3a6c2a5d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  29:     0x7f83860e3eba - <std[9c753cd266a8fcaa]::sys::thread::unix::Thread>::new::thread_start
  30:     0x7f837f497739 - <unknown>
  31:     0x7f837f51bedc - <unknown>
  32:                0x0 - <unknown>

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: please make sure that you have updated to the latest nightly

note: rustc 1.99.0-nightly (ea0604237 2026-08-10) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_built] building MIR for `inner::<impl at /tmp/icemaker_global_tempdir.CGLljZwjTbOy/rustc_testrunner_tmpdir_reporting.vePoqhBRFU9l/mvce.rs:2:14: 2:21>::default`
#1 [check_unsafety] unsafety-checking `inner::<impl at /tmp/icemaker_global_tempdir.CGLljZwjTbOy/rustc_testrunner_tmpdir_reporting.vePoqhBRFU9l/mvce.rs:2:14: 2:21>::default`
#2 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 5 previous errors

Some errors have detailed explanations: E0601, E0658.
For more information about an error, try `rustc --explain E0601`.

@rustbot label +F-mut_restriction

Activity

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

Metadata

Metadata

Labels

C-bugCategory: This is a bug.F-mut_restriction`#![feature(mut_restriction)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions