Skip to content

ICE: "no errors encountered even though delay_span_bug issued" in recursive impl #110623

Description

@WardBrian

Some code I wrote for the 2022 advent of code fails to compile under the newly released 1.69. It compiled previously under 1.67 and 1.68.

Code

use std::{collections::BTreeMap, num::ParseIntError, str::FromStr};

enum FileSystem {
    File(usize),
    Directory(BTreeMap<String, FileSystem>),
}

impl FromStr for FileSystem {
    type Err = ParseIntError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        if s.starts_with("dir") {
            Ok(Self::new_dir())
        } else {
            Ok(Self::File(s.split_whitespace().next().unwrap().parse()?))
        }
    }
}

impl FileSystem {
    fn new_dir() -> FileSystem {
        FileSystem::Directory(BTreeMap::new())
    }

    fn insert(&mut self, name: String, other: FileSystem) -> Option<FileSystem> {
        match self {
            FileSystem::File(_) => panic!("can only insert into directory!"),
            FileSystem::Directory(tree) => tree.insert(name, other),
        }
    }

    // Recursively build a tree from commands. This uses (abuses?)
    // the fact that `cd /` only appears at the start and that
    // subsequent `cd`s can only move ONE level to use the recursion
    // stack as the filesystem stack
    fn build<'a>(
        &mut self,
        mut commands: impl Iterator<Item = &'a str> + 'a,
    ) -> Option<impl Iterator<Item = &'a str> + 'a> {
        let cmd = commands.next()?;
        let mut elements = cmd.lines();
        match elements.next().map(str::trim) {
            Some("cd /") | None => self.build(commands),
            Some("cd ..") => {
                // return to higher scope
                Some(commands)
            }
            Some("ls") => {
                for item in elements {
                    let name = item.split_whitespace().last().unwrap();
                    let prior = self.insert(name.to_string(), item.parse().unwrap());
                    debug_assert!(prior.is_none());
                }
                // continue on
                self.build(commands)
            }
            Some(other_cd) => {
                let name = other_cd
                    .trim()
                    .strip_prefix("cd ")
                    .expect("expected a cd command");
                let mut directory = FileSystem::new_dir();
                let further_commands = directory.build(commands);
                self.insert(name.to_string(), directory);
                self.build(further_commands?) // THIS LINE FAILS TO COMPILE
            }
        }
    }
}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.69.0 (84c898d65 2023-04-16)
binary: rustc
commit-hash: 84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc
commit-date: 2023-04-16
host: x86_64-unknown-linux-gnu
release: 1.69.0
LLVM version: 15.0.7

I also tried with nightly:

rustc 1.71.0-nightly (39c6804b9 2023-04-19)
binary: rustc
commit-hash: 39c6804b92aa202369e402525cee329556bc1db0
commit-date: 2023-04-19
host: x86_64-unknown-linux-gnu
release: 1.71.0-nightly
LLVM version: 16.0.2

Error output

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

error: internal compiler error: opaque type with non-universal region substs
  --> 7/src/main.rs:65:17
   |
65 |                 self.build(further_commands?)
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at    0: <rustc_errors::HandlerInner>::emit_diagnostic
              1: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, &str>
              2: <rustc_borrowck::region_infer::RegionInferenceContext>::infer_opaque_types::{closure#0}::{closure#2}
              3: rustc_middle::ty::util::fold_list::<rustc_middle::ty::fold::RegionFolder, rustc_middle::ty::subst::GenericArg, <&rustc_middle::ty::list::List<rustc_middle::ty::subst::GenericArg> as rustc_type_ir::fold::TypeFoldable<rustc_middle::ty::context::TyCtxt>>::try_fold_with<rustc_middle::ty::fold::RegionFolder>::{closure#0}>
              4: <rustc_borrowck::region_infer::RegionInferenceContext>::infer_opaque_types
              5: rustc_borrowck::nll::compute_regions
              6: rustc_borrowck::do_mir_borrowck
              7: rustc_borrowck::mir_borrowck
              8: <rustc_borrowck::provide::{closure#0} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId)>>::call_once
              9: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::mir_borrowck, rustc_query_impl::plumbing::QueryCtxt>
             10: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_borrowck
             11: rustc_hir_analysis::collect::type_of::type_of
             12: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::type_of, rustc_query_impl::plumbing::QueryCtxt>
             13: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::type_of
             14: rustc_hir_analysis::check::check::check_mod_item_types
             15: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::check_mod_item_types, rustc_query_impl::plumbing::QueryCtxt>
             16: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::check_mod_item_types
             17: <rustc_middle::hir::map::Map>::for_each_module::<rustc_hir_analysis::check_crate::{closure#6}::{closure#0}>
             18: rustc_hir_analysis::check_crate
             19: rustc_interface::passes::analysis
             20: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
             21: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
             22: <rustc_middle::ty::context::GlobalCtxt>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#4}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
             23: rustc_span::with_source_map::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
             24: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
             25: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
             26: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                        at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/alloc/src/boxed.rs:1987:9
             27: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                        at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/alloc/src/boxed.rs:1987:9
             28: std::sys::unix::thread::Thread::new::thread_start
                        at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys/unix/thread.rs:108:17
             29: start_thread
                        at ./nptl/./nptl/pthread_create.c:442:8
             30: clone3
                        at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
           

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.69.0 (84c898d65 2023-04-16) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
warning: `seven` (bin "seven") generated 2 warnings
error: could not compile `seven`; 2 warnings emitted
Backtrace

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

error: internal compiler error: opaque type with non-universal region substs
  --> 7/src/main.rs:65:17
   |
65 |                 self.build(further_commands?)
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at    0: <rustc_errors::HandlerInner>::emit_diagnostic
              1: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, &str>
              2: <rustc_borrowck::region_infer::RegionInferenceContext>::infer_opaque_types::{closure#0}::{closure#2}
              3: rustc_middle::ty::util::fold_list::<rustc_middle::ty::fold::RegionFolder, rustc_middle::ty::subst::GenericArg, <&rustc_middle::ty::list::List<rustc_middle::ty::subst::GenericArg> as rustc_type_ir::fold::TypeFoldable<rustc_middle::ty::context::TyCtxt>>::try_fold_with<rustc_middle::ty::fold::RegionFolder>::{closure#0}>
              4: <rustc_borrowck::region_infer::RegionInferenceContext>::infer_opaque_types
              5: rustc_borrowck::nll::compute_regions
              6: rustc_borrowck::do_mir_borrowck
              7: rustc_borrowck::mir_borrowck
              8: <rustc_borrowck::provide::{closure#0} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId)>>::call_once
              9: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::mir_borrowck, rustc_query_impl::plumbing::QueryCtxt>
             10: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_borrowck
             11: rustc_hir_analysis::collect::type_of::type_of
             12: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::type_of, rustc_query_impl::plumbing::QueryCtxt>
             13: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::type_of
             14: rustc_hir_analysis::check::check::check_mod_item_types
             15: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::check_mod_item_types, rustc_query_impl::plumbing::QueryCtxt>
             16: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::check_mod_item_types
             17: <rustc_middle::hir::map::Map>::for_each_module::<rustc_hir_analysis::check_crate::{closure#6}::{closure#0}>
             18: rustc_hir_analysis::check_crate
             19: rustc_interface::passes::analysis
             20: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
             21: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
             22: <rustc_middle::ty::context::GlobalCtxt>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#4}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
             23: rustc_span::with_source_map::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
             24: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
             25: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
             26: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                        at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/alloc/src/boxed.rs:1987:9
             27: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                        at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/alloc/src/boxed.rs:1987:9
             28: std::sys::unix::thread::Thread::new::thread_start
                        at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys/unix/thread.rs:108:17
             29: start_thread
                        at ./nptl/./nptl/pthread_create.c:442:8
             30: clone3
                        at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
           

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.69.0 (84c898d65 2023-04-16) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
warning: `seven` (bin "seven") generated 2 warnings
error: could not compile `seven`; 2 warnings emitted

Activity

  1. 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 Apr 20, 2023
  2. added
    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.
    on Apr 20, 2023
  3. matthiaskrgr commented on Apr 20, 2023

    @matthiaskrgr
    Member

    reduced

    struct FileSystem;
    
    impl FileSystem {
        fn build<'a>(
            &mut self,
            commands: impl Iterator<Item = &'a str> + 'a,
        ) -> Option<impl Iterator<Item = &'a str> + 'a> {
            let further_commands = self.build(commands);
            self.build(further_commands?)
        }
    }
    
    fn main() {}
  4. matthiaskrgr commented on Apr 20, 2023

    @matthiaskrgr
    Member

    searched toolchains nightly-2022-03-30 through nightly-2023-04-20
    Regression in nightly-2022-03-31

    fetching (via local git) commits from 9c06e1b to c5cf08d
    opening existing repository at "rust.git"
    Found origin remote under name origin
    refreshing repository at "rust.git"
    looking up first commit
    looking up second commit
    checking that commits are by bors and thus have ci artifacts...
    finding bors merge commits
    found 8 bors merge commits in the specified range
    commit[0] 2022-03-29: Auto merge of #95448 - Dylan-DPC:rollup-wpj5yto, r=Dylan-DPC
    commit[1] 2022-03-30: Auto merge of #95455 - RalfJung:miri, r=RalfJung
    commit[2] 2022-03-30: Auto merge of #94081 - oli-obk:lazy_tait_take_two, r=nikomatsakis
    commit[3] 2022-03-30: Auto merge of #95466 - Dylan-DPC:rollup-g7ddr8y, r=Dylan-DPC
    commit[4] 2022-03-30: Auto merge of #95241 - Gankra:cleaned-provenance, r=workingjubilee
    commit[5] 2022-03-30: Auto merge of #94963 - lcnr:inherent-impls-std, r=oli-obk,m-ou-se
    commit[6] 2022-03-30: Auto merge of #95458 - calebcartwright:sync-rustfmt-subtree, r=calebcartwright
    commit[7] 2022-03-30: Auto merge of #95425 - nnethercote:yet-more-parse_tt-improvements, r=petrochenkov
    ERROR: no CI builds available between 9c06e1b and c5cf08d within last 167 days

    ouff, a bit more than a year 😆

    #94081 by @oli-obk looks a bit suspicious imo 🙃

  5. zirconium-n commented on Apr 21, 2023

    @zirconium-n
    Contributor

    reduced

    trait S {}
    
    fn foo<'a>(x: impl S + 'a) -> impl S + 'a {
        foo(foo(x))
    }
    
  6. zirconium-n commented on Apr 21, 2023

    @zirconium-n
    Contributor

    I will try fix this.

    @rustbot claim

  7. removed their assignment
    on Sep 18, 2023
  8. added 3 commits that reference this issue on Oct 19, 2023
    c679690
    e287a7d
    66abdf7
  9. added a commit that references this issue on Mar 28, 2024
    551abd6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.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.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions