Skip to content

ICE: attempted .def_id() on invalid res: Err #137508

@cushionbadak

Description

@cushionbadak

Code

trait Tr {
    type Item;
}

type A2 = dyn for<'a> Tr + ?foo(b);

fn main() {}
Original Code (Fuzzing)

trait Tr: ?Sized {
    type Item = &usize;
    //~^ ERROR 18:17: 18:18: in the trait associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type

    fn poke(&mut self, item: Self::Item) {
        self += *item;
    }
}
//~^ ERROR `?Trait` is not permitted in supertraits

type A1 = dyn Tr + (?Sized);
//~^ ERROR `?Trait` is not permitted in trait object types
type A2 = dyn for<'adds_bnd> Tr + (?simd_fexp2(a));
//~^ ERROR `?Trait` is not permitted in trait object types

fn main() {}


// /root/workspace/seeds_250219/tests/ui/maybe-bounds.rs

Meta

rustc --version --verbose:

rustc 1.87.0-nightly (f8a913b13 2025-02-23)
binary: rustc
commit-hash: f8a913b1381e90379c7ca63ac2b88b9518936628
commit-date: 2025-02-23
host: x86_64-apple-darwin
release: 1.87.0-nightly
LLVM version: 20.1.0

Error output

error[E0658]: `?Trait` is not permitted in trait object types
 --> 05C5.rs:5:28
  |
5 | type A2 = dyn for<'a> Tr + ?foo(b);
  |                            ^^^^^^^
  |
  = help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
  = note: this compiler was built on 2025-02-23; consider upgrading it if it is out of date

error[E0405]: cannot find trait `foo` in this scope
 --> 05C5.rs:5:29
  |
5 | type A2 = dyn for<'a> Tr + ?foo(b);
  |                             ^^^ not found in this scope

error[E0412]: cannot find type `b` in this scope
 --> 05C5.rs:5:33
  |
5 | type A2 = dyn for<'a> Tr + ?foo(b);
  |                                 ^ not found in this scope


thread 'rustc' panicked at /rustc/f8a913b1381e90379c7ca63ac2b88b9518936628/compiler/rustc_hir/src/def.rs:683:45:
attempted .def_id() on invalid res: Err
Backtrace

thread 'rustc' panicked at /rustc/f8a913b1381e90379c7ca63ac2b88b9518936628/compiler/rustc_hir/src/def.rs:683:45:
attempted .def_id() on invalid res: Err
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: <dyn rustc_hir_analysis::hir_ty_lowering::HirTyLowerer>::check_for_required_assoc_tys
   3: <dyn rustc_hir_analysis::hir_ty_lowering::HirTyLowerer>::lower_trait_object_ty
   4: <dyn rustc_hir_analysis::hir_ty_lowering::HirTyLowerer>::lower_ty
   5: rustc_hir_analysis::collect::type_of::type_of
      [... omitted 1 frame ...]
   6: rustc_hir_analysis::collect::lower_item
   7: <rustc_hir_analysis::collect::CollectItemTypesVisitor as rustc_hir::intravisit::Visitor>::visit_item
   8: rustc_hir_analysis::check::wfcheck::check_item
   9: rustc_hir_analysis::check::wfcheck::check_well_formed
      [... omitted 1 frame ...]
  10: <rustc_middle::hir::ModuleItems>::par_opaques::<rustc_hir_analysis::check::wfcheck::check_mod_type_wf::{closure#4}>::{closure#0}
  11: rustc_hir_analysis::check::wfcheck::check_mod_type_wf
      [... omitted 1 frame ...]
  12: rustc_hir_analysis::check_crate
  13: rustc_interface::passes::run_required_analyses
  14: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  15: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
  16: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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

note: please attach the file at `/Volumes/T7/workspace/250224 scratch/codes/rustc-ice-2025-02-24T05_09_01-67498.txt` to your bug report

query stack during panic:
#0 [type_of] expanding type alias `A2`
#1 [check_well_formed] checking that `A2` is well-formed
#2 [check_mod_type_wf] checking that types are well-formed in top-level module
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors

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

Notes

  • ICE location: compiler/rustc_hir/src/def.rs Line-683
    impl<Id> Res<Id> {
    /// Return the `DefId` of this `Def` if it has an ID, else panic.
    pub fn def_id(&self) -> DefId
    where
    Id: Debug,
    {
    self.opt_def_id().unwrap_or_else(|| panic!("attempted .def_id() on invalid res: {self:?}"))
    }

Activity

added
C-bugCategory: This is a bug.
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.
on Feb 24, 2025
added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Feb 24, 2025
moxian

moxian commented on Feb 24, 2025

@moxian
Contributor

cargo-bisect-rustc points to nightly-2024-07-27 (specifically 7120fda...7c2012d ), so probably #121676 which introduced more_maybe_bounds feature gate.

cyrgani

cyrgani commented on Feb 24, 2025

@cyrgani
Contributor

a bit simpler:

trait Tr {
    type Item;
}

fn main() {
    let _: dyn Tr + ?Foo();
}
added
S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issue
on Feb 24, 2025
self-assigned this
on Feb 25, 2025
added a commit that references this issue on Feb 25, 2025
2c18b10
added 2 commits that reference this issue on Feb 25, 2025
1ac2051
b7a5497
removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Feb 26, 2025
added 2 commits that reference this issue on Feb 26, 2025
1507108
2fc8823
added a commit that references this issue on Feb 26, 2025
a9ca133
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-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

    Participants

    @moxian@cushionbadak@jieyouxu@TaKO8Ki@rustbot

    Issue actions

      ICE: `attempted .def_id() on invalid res: Err` · Issue #137508 · rust-lang/rust