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]: rustdoc: unexpected const parent in type_of(): TraitRef .. #107093

Closed
1 of 4 tasks
matthiaskrgr opened this issue Jan 19, 2023 · 3 comments
Closed
1 of 4 tasks

[ICE]: rustdoc: unexpected const parent in type_of(): TraitRef .. #107093

matthiaskrgr opened this issue Jan 19, 2023 · 3 comments
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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

Code

use std::ops::Generator;

fn gen() -> impl Generator<{}> {}

Affected release channels

  • Previous Stable
  • Current Stable
  • Current Beta
  • Current Nightly

Rust Version

rustc 1.68.0-nightly (333ee6c46 2023-01-18)
binary: rustc
commit-hash: 333ee6c466972185973d5097f8b5fb0f9fb13fa5
commit-date: 2023-01-18
host: x86_64-unknown-linux-gnu
release: 1.68.0-nightly
LLVM version: 15.0.6

Current error output

No response

Backtrace

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

error: internal compiler error: unexpected const parent in type_of(): TraitRef(TraitRef { path: Path { span: a.rs:3:18: 3:31 (#0), res: Def(Trait, DefId(2:2969 ~ core[830d]::ops::generator::Generator)), segments: [PathSegment { ident: Generator#0, hir_id: HirId(DefId(0:6 ~ a[6282]::gen::{opaque#0}).4), res: Def(Trait, DefId(2:2969 ~ core[830d]::ops::generator::Generator)), args: Some(GenericArgs { args: [Const(ConstArg { value: AnonConst { hir_id: HirId(DefId(0:6 ~ a[6282]::gen::{opaque#0}).1), def_id: DefId(0:5 ~ a[6282]::gen::{constant#0}), body: BodyId { hir_id: HirId(DefId(0:6 ~ a[6282]::gen::{opaque#0}).2) } }, span: a.rs:3:28: 3:30 (#0) })], bindings: [], parenthesized: false, span_ext: a.rs:3:27: 3:31 (#0) }), infer_args: false }] }, hir_ref_id: HirId(DefId(0:6 ~ a[6282]::gen::{opaque#0}).5) })
  |
  = note: delayed at    0: <rustc_errors::HandlerInner>::emit_diagnostic
             1: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, &str>
             2: <rustc_middle::ty::context::TyCtxt>::ty_error_with_message::<rustc_span::span_encoding::Span>
             3: rustc_hir_analysis::collect::type_of::type_of
             4: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::type_of, rustc_query_impl::plumbing::QueryCtxt, rustc_middle::dep_graph::dep_node::DepKind>
             5: rustdoc::clean::clean_const
             6: <core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_hir::hir::GenericArg>, rustdoc::clean::clean_generic_args::{closure#1}> as core::iter::traits::iterator::Iterator>::fold::<(), core::iter::traits::iterator::Iterator::for_each::call<rustdoc::clean::types::GenericArg, <alloc::vec::Vec<rustdoc::clean::types::GenericArg>>::extend_trusted<core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_hir::hir::GenericArg>, rustdoc::clean::clean_generic_args::{closure#1}>>::{closure#0}>::{closure#0}>
             7: <alloc::vec::Vec<rustdoc::clean::types::GenericArg> as alloc::vec::spec_from_iter::SpecFromIter<rustdoc::clean::types::GenericArg, core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_hir::hir::GenericArg>, rustdoc::clean::clean_generic_args::{closure#1}>>>::from_iter
             8: rustdoc::clean::clean_generic_args
             9: <thin_vec::ThinVec<rustdoc::clean::types::PathSegment> as core::iter::traits::collect::FromIterator<rustdoc::clean::types::PathSegment>>::from_iter::<core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_hir::hir::PathSegment>, rustdoc::clean::clean_path::{closure#0}>>
            10: rustdoc::clean::clean_poly_trait_ref
            11: rustdoc::clean::clean_generic_bound
            12: <alloc::vec::Vec<rustdoc::clean::types::GenericBound> as alloc::vec::spec_from_iter::SpecFromIter<rustdoc::clean::types::GenericBound, core::iter::adapters::filter_map::FilterMap<core::slice::iter::Iter<rustc_hir::hir::GenericBound>, rustdoc::clean::clean_trait_item::{closure#0}::{closure#1}>>>::from_iter
            13: rustdoc::clean::clean_ty
            14: rustdoc::clean::utils::enter_impl_trait::<rustdoc::clean::clean_function::{closure#0}, (rustdoc::clean::types::Generics, rustdoc::clean::types::FnDecl)>
            15: rustdoc::clean::clean_fn_or_proc_macro
            16: <rustdoc::core::DocContext>::with_param_env::<alloc::vec::Vec<rustdoc::clean::types::Item>, rustdoc::clean::clean_maybe_renamed_item::{closure#1}>
            17: <&mut rustdoc::clean::clean_doc_module::{closure#2} as core::ops::function::FnOnce<(&(&rustc_hir::hir::Item, core::option::Option<rustc_span::symbol::Symbol>, core::option::Option<rustc_hir::hir_id::HirId>),)>>::call_once
            18: <alloc::vec::Vec<rustdoc::clean::types::Item> as alloc::vec::spec_extend::SpecExtend<rustdoc::clean::types::Item, core::iter::adapters::flatten::FlatMap<core::slice::iter::Iter<(&rustc_hir::hir::Item, core::option::Option<rustc_span::symbol::Symbol>, core::option::Option<rustc_hir::hir_id::HirId>)>, alloc::vec::Vec<rustdoc::clean::types::Item>, rustdoc::clean::clean_doc_module::{closure#2}>>>::spec_extend
            19: rustdoc::clean::clean_doc_module
            20: rustdoc::clean::utils::krate
            21: <rustc_session::session::Session>::time::<rustdoc::clean::types::Crate, rustdoc::core::run_global_ctxt::{closure#4}>
            22: rustdoc::core::run_global_ctxt
            23: <rustc_session::session::Session>::time::<(rustdoc::clean::types::Crate, rustdoc::config::RenderOptions, rustdoc::formats::cache::Cache), rustdoc::main_args::{closure#1}::{closure#0}::{closure#1}::{closure#0}>
            24: <rustc_interface::passes::QueryContext>::enter::<rustdoc::main_args::{closure#1}::{closure#0}::{closure#1}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
            25: <rustc_interface::interface::Compiler>::enter::<rustdoc::main_args::{closure#1}::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
            26: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustdoc::main_args::{closure#1}>::{closure#0}::{closure#0}>
            27: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustdoc::main_args::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
            28: 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_errors::ErrorGuaranteed>, rustdoc::main_args::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
            29: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustdoc::main_args::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
            30: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/333ee6c466972185973d5097f8b5fb0f9fb13fa5/library/alloc/src/boxed.rs:1988:9
            31: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/333ee6c466972185973d5097f8b5fb0f9fb13fa5/library/alloc/src/boxed.rs:1988:9
            32: std::sys::unix::thread::Thread::new::thread_start
                       at /rustc/333ee6c466972185973d5097f8b5fb0f9fb13fa5/library/std/src/sys/unix/thread.rs:108:17
            33: <unknown>
            34: <unknown>


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.68.0-nightly (333ee6c46 2023-01-18) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack
thread panicked while panicking. aborting.
[2]    2838854 IOT instruction (core dumped)  rustdoc a.rs

Anything else?

No response

@matthiaskrgr matthiaskrgr added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. 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. C-bug Category: This is a bug. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue labels Jan 19, 2023
@compiler-errors
Copy link
Member

Hm, this has to do with the fact that we don't check well-formedness during rustdoc, even though we really should at least be checking that the code in question has the right substs and stuff...

@megakorre
Copy link
Contributor

So does rustdoc proceed with anything that can be parsed into HIR? cargo check rejects this with can't put a constant there.
What should the code do here in that case?.

  • Make a dummy type and proceed with dock gen anyway.
  • Actually run the type checking before generating docs.
  • error without ICE and just print some general error message.
  • Could also run the type check conditionality if something failed to type I guess and print the message from that.

bors added a commit to rust-lang-ci/rust that referenced this issue Mar 30, 2023
…eck_before_clean, r=GuillaumeGomez

rustdoc: run more HIR validation to mirror rustc

# Explanation

While investigating these issues: rust-lang#107093, rust-lang#106079
I thought it maybe would be useful to test running `rustdoc` on all rust files under `tests/ui` grepping for files that causes any ICEs.
And these are the files I found would cause ICEs.
```
// These are handled by this fix.
tests/ui/late-bound-lifetimes/mismatched_arg_count.rs
tests/ui/associated-consts/issue-102335-const.rs
tests/ui/const-generics/generic_const_exprs/issue-102768.rs
tests/ui/const-generics/const-arg-type-arg-misordered.rs
tests/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.rs
tests/ui/typeck/issue-88643.rs
tests/ui/typeck/issue-75889.rs
tests/ui/typeck/issue-83621-placeholder-static-in-extern.rs
// These are not they will still produce a ICE after this change
tests/ui/limits/issue-56762.rs
tests/ui/union/projection-as-union-type-error-2.rs
tests/ui/union/projection-as-union-type-error.rs
```

I reduces the issues handled by this PR down to the tests added in the PR. That includes the linked issues.
But the 3 files that are not handled I will leave for a future PR.

This PR adds the `type_collecting` step from `hir_analysis::check_crate` to the rustdoc typechecks.
It had the following comment on it.
```
// this ensures that later parts of type checking can assume that items
// have valid types and not error
```
Adding the check report the same errors as rustc does for these input.
And not ICE when the lint checker walks the HIR or when in the `rustdoc::clean` pass.

This PR updates the expected errors of some existing rustdoc-ui tests (some now report less errors).
These new reported errors does mirror the errors reported by rustc.

# Performance
It does more checking so it will probably regress. We should run ``@bors` try `@rust-timer` queue` and see.

# Discussion

Maybe instead of calling a subset of the checks in `hir_analysis::check_crate` and having comments that say they should be kept in sync. We could instead call `check_crate` directly and pass in some flag. Maybe `check_toplevel_signatures_only` or something like that. That flag would have to skip most of the checks in that function tough.
@fmease
Copy link
Member

fmease commented Apr 30, 2023

This issue was fixed in #108576 but never closed. It now errors with:

error[E0747]: constant provided when a type was expected
 --> ice-107093.rs:3:28
  |
3 | fn gen() -> impl Generator<{}> {}
  |                            ^^

error: aborting due to previous error

I don't think that we need a regression test for this. The linked PR has added enough already.

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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants