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: attempted .def_id() on invalid res: Err #137508

Closed
cushionbadak opened this issue Feb 24, 2025 · 2 comments · Fixed by #137631
Closed

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

cushionbadak opened this issue Feb 24, 2025 · 2 comments · Fixed by #137631
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cushionbadak
Copy link

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:?}"))
    }
@cushionbadak cushionbadak 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 Feb 24, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 24, 2025
@moxian
Copy link
Contributor

moxian commented Feb 24, 2025

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

@cyrgani
Copy link
Contributor

cyrgani commented Feb 24, 2025

a bit simpler:

trait Tr {
    type Item;
}

fn main() {
    let _: dyn Tr + ?Foo();
}

@jieyouxu jieyouxu added the S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue label Feb 24, 2025
@TaKO8Ki TaKO8Ki self-assigned this Feb 25, 2025
TaKO8Ki added a commit to TaKO8Ki/rust that referenced this issue Feb 25, 2025
TaKO8Ki added a commit to TaKO8Ki/rust that referenced this issue Feb 25, 2025
rename ui tests
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 26, 2025
fmease added a commit to fmease/rust that referenced this issue Feb 26, 2025
…rrors

Avoid collecting associated types for undefined trait

Fixes rust-lang#137508
Fixes rust-lang#137554
fmease added a commit to fmease/rust that referenced this issue Feb 26, 2025
…rrors

Avoid collecting associated types for undefined trait

Fixes rust-lang#137508
Fixes rust-lang#137554
@bors bors closed this as completed in b7a5497 Feb 26, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 26, 2025
Rollup merge of rust-lang#137631 - TaKO8Ki:issue-137508, r=compiler-errors

Avoid collecting associated types for undefined trait

Fixes rust-lang#137508
Fixes rust-lang#137554
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. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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.

6 participants