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

'assertion failed' after error #82092

Closed
m-hugo opened this issue Feb 14, 2021 · 4 comments
Closed

'assertion failed' after error #82092

m-hugo opened this issue Feb 14, 2021 · 4 comments
Labels
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.

Comments

@m-hugo
Copy link

m-hugo commented Feb 14, 2021

Code

use std::result::Result;
fn main() -> Ok {Ok}

Meta

rustc --version --verbose:

note: rustc 1.52.0-nightly (3f5aee2d5 2021-02-12) running on x86_64-unknown-linux-gnu

Error output

error[E0573]: expected type, found variant `Ok`
 --> ./out.rs:2:14
  |
2 | fn main() -> Ok {Ok}
  |              ^^ not a type
  |

thread 'rustc' panicked at 'assertion failed: !self.substitutions.is_empty()', compiler/rustc_errors/src/lib.rs:189:9

Backtrace

stack backtrace:
   0: rust_begin_unwind
             at /rustc/3f5aee2d5241139d808f4fdece0026603489afd1/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/3f5aee2d5241139d808f4fdece0026603489afd1/library/core/src/panicking.rs:92:14
   2: core::panicking::panic
             at /rustc/3f5aee2d5241139d808f4fdece0026603489afd1/library/core/src/panicking.rs:50:5
   3: rustc_errors::CodeSuggestion::splice_lines
   4: <rustc_errors::emitter::EmitterWriter as rustc_errors::emitter::Emitter>::emit_diagnostic
   5: rustc_errors::HandlerInner::emit_diagnostic
   6: rustc_errors::diagnostic_builder::DiagnosticBuilder::emit
   7: rustc_resolve::Resolver::report_errors
   8: rustc_session::utils::<impl rustc_session::session::Session>::time
   9: rustc_resolve::Resolver::resolve_crate
  10: rustc_interface::passes::configure_and_expand_inner
  11: rustc_interface::passes::configure_and_expand::{{closure}}
  12: rustc_data_structures::box_region::PinnedGenerator<I,A,R>::new
  13: rustc_interface::queries::Queries::expansion
  14: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  15: rustc_span::with_source_map
  16: scoped_tls::ScopedKey<T>::set

@m-hugo m-hugo 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 14, 2021
@osa1
Copy link
Contributor

osa1 commented Feb 14, 2021

There could be multiple ways of fixing this, but I think it would be good to fix this by fixing this function:

/// Gets the stringified path for an enum from an `ImportSuggestion` for an enum variant.
fn import_candidate_to_enum_paths(suggestion: &ImportSuggestion) -> (String, String) {
let variant_path = &suggestion.path;
let variant_path_string = path_names_to_string(variant_path);
let path_len = suggestion.path.segments.len();
let enum_path = ast::Path {
span: suggestion.path.span,
segments: suggestion.path.segments[0..path_len - 1].to_vec(),
tokens: None,
};
let enum_path_string = path_names_to_string(&enum_path);
(variant_path_string, enum_path_string)
}

Given something like std::prelude::v1::Ok, this function returns std::prelude::v1 as the enum path. Instead it should return std::prelude::v1::Result. More generally, for variant path like x::y::V it will return x::y (a module path, instead of a variant path), which is not how this function is supposed to work.

I don't know if this is easy to fix though. Perhaps there's an easier fix at the call site of this function and we could avoid calling this function altogether.

@tmiasko
Copy link
Contributor

tmiasko commented Feb 14, 2021

cc #82087

@osa1
Copy link
Contributor

osa1 commented Feb 14, 2021

#82087 should fix this issue, without generating a suggestion.

@m-hugo
Copy link
Author

m-hugo commented Feb 14, 2021

i didn't see #78651, closing as duplicate

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

No branches or pull requests

3 participants