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: attempt to subtract with overflow, compiler/rustc_errors/src/lib.rs:348:47 #89280

Closed
jyn514 opened this issue Sep 26, 2021 · 4 comments · Fixed by #89912
Closed

ICE: attempt to subtract with overflow, compiler/rustc_errors/src/lib.rs:348:47 #89280

jyn514 opened this issue Sep 26, 2021 · 4 comments · Fixed by #89912
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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

@jyn514
Copy link
Member

jyn514 commented Sep 26, 2021

Code

Rebase bdb5a5ffe17 over ac8dd1b, then run x test src/tools/clippy. I think this is the write_literal_2 test.

cc @rust-lang/clippy, but I think this is an issue with rustc_errors, not clippy itself.

Meta

rustc --version --verbose:

note: Clippy version: clippy 0.1.57 (ac8dd1b2f24 2021-09-26)

Error output

thread 'rustc' panicked at 'attempt to subtract with overflow', compiler/rustc_errors/src/lib.rs:348:47
Backtrace

thread 'rustc' panicked at 'attempt to subtract with overflow', compiler/rustc_errors/src/lib.rs:348:47
stack backtrace:
   0: rust_begin_unwind
             at /home/joshua/rustc3/library/std/src/panicking.rs:517:5
   1: core::panicking::panic_fmt
             at /home/joshua/rustc3/library/core/src/panicking.rs:100:14
   2: core::panicking::panic
             at /home/joshua/rustc3/library/core/src/panicking.rs:50:5
   3: rustc_errors::CodeSuggestion::splice_lines::{{closure}}
             at /home/joshua/rustc3/compiler/rustc_errors/src/lib.rs:348:47
   4: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
             at /home/joshua/rustc3/library/core/src/ops/function.rs:269:13
   5: core::iter::traits::iterator::Iterator::find_map::check::{{closure}}
             at /home/joshua/rustc3/library/core/src/iter/traits/iterator.rs:2397:32
   6: core::iter::adapters::cloned::clone_try_fold::{{closure}}
             at /home/joshua/rustc3/library/core/src/iter/adapters/cloned.rs:28:21
   7: core::iter::adapters::filter::filter_try_fold::{{closure}}
             at /home/joshua/rustc3/library/core/src/iter/adapters/filter.rs:44:44
   8: core::iter::traits::iterator::Iterator::try_fold
             at /home/joshua/rustc3/library/core/src/iter/traits/iterator.rs:1983:21
   9: <core::iter::adapters::filter::Filter<I,P> as core::iter::traits::iterator::Iterator>::try_fold
             at /home/joshua/rustc3/library/core/src/iter/adapters/filter.rs:93:9
  10: <core::iter::adapters::cloned::Cloned<I> as core::iter::traits::iterator::Iterator>::try_fold
             at /home/joshua/rustc3/library/core/src/iter/adapters/cloned.rs:53:9
  11: core::iter::traits::iterator::Iterator::find_map
             at /home/joshua/rustc3/library/core/src/iter/traits/iterator.rs:2403:9
  12: <core::iter::adapters::filter_map::FilterMap<I,F> as core::iter::traits::iterator::Iterator>::next
             at /home/joshua/rustc3/library/core/src/iter/adapters/filter_map.rs:61:9
  13: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter
             at /home/joshua/rustc3/library/alloc/src/vec/spec_from_iter_nested.rs:23:32
  14: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
             at /home/joshua/rustc3/library/alloc/src/vec/spec_from_iter.rs:33:9
  15: <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter
             at /home/joshua/rustc3/library/alloc/src/vec/mod.rs:2487:9
  16: core::iter::traits::iterator::Iterator::collect
             at /home/joshua/rustc3/library/core/src/iter/traits/iterator.rs:1733:9
  17: rustc_errors::CodeSuggestion::splice_lines
             at /home/joshua/rustc3/compiler/rustc_errors/src/lib.rs:241:9
  18: rustc_errors::emitter::EmitterWriter::emit_suggestion_default
             at /home/joshua/rustc3/compiler/rustc_errors/src/emitter.rs:1572:27
  19: rustc_errors::emitter::EmitterWriter::emit_messages_default
             at /home/joshua/rustc3/compiler/rustc_errors/src/emitter.rs:1856:29
  20: <rustc_errors::emitter::EmitterWriter as rustc_errors::emitter::Emitter>::emit_diagnostic
             at /home/joshua/rustc3/compiler/rustc_errors/src/emitter.rs:511:9
  21: rustc_errors::json::Diagnostic::from_errors_diagnostic
             at /home/joshua/rustc3/compiler/rustc_errors/src/json.rs:374:9
  22: <rustc_errors::json::JsonEmitter as rustc_errors::emitter::Emitter>::emit_diagnostic
             at /home/joshua/rustc3/compiler/rustc_errors/src/json.rs:112:20
  23: rustc_errors::HandlerInner::emit_diagnostic
             at /home/joshua/rustc3/compiler/rustc_errors/src/lib.rs:988:13
  24: rustc_errors::Handler::emit_diagnostic
             at /home/joshua/rustc3/compiler/rustc_errors/src/lib.rs:909:9
  25: rustc_errors::diagnostic_builder::DiagnosticBuilder::emit
             at /home/joshua/rustc3/compiler/rustc_errors/src/diagnostic_builder.rs:103:9
  26: clippy_utils::diagnostics::span_lint_and_then::{{closure}}
             at ./clippy_utils/src/diagnostics.rs:154:9
  27: core::ops::function::FnOnce::call_once{{vtable.shim}}
             at /home/joshua/rustc3/library/core/src/ops/function.rs:227:5
  28: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /home/joshua/rustc3/library/alloc/src/boxed.rs:1638:9
  29: rustc_middle::lint::struct_lint_level::struct_lint_level_impl
             at /home/joshua/rustc3/compiler/rustc_middle/src/lint.rs:384:9
  30: rustc_middle::lint::struct_lint_level
             at /home/joshua/rustc3/compiler/rustc_middle/src/lint.rs:386:5
  31: rustc_lint::levels::LintLevelsBuilder::struct_lint
             at /home/joshua/rustc3/compiler/rustc_lint/src/levels.rs:552:9
  32: <rustc_lint::context::EarlyContext as rustc_lint::context::LintContext>::lookup
             at /home/joshua/rustc3/compiler/rustc_lint/src/context.rs:866:9
  33: rustc_lint::context::LintContext::struct_span_lint
             at /home/joshua/rustc3/compiler/rustc_lint/src/context.rs:795:9
  34: clippy_utils::diagnostics::span_lint_and_then
             at ./clippy_utils/src/diagnostics.rs:150:5
  35: clippy_lints::write::Write::check_tts
             at ./clippy_lints/src/write.rs:586:17
  36: <clippy_lints::write::Write as rustc_lint::passes::EarlyLintPass>::check_mac
             at ./clippy_lints/src/write.rs:321:44
  37: <rustc_lint::early::EarlyLintPassObjects as rustc_lint::passes::EarlyLintPass>::check_mac
             at /home/joshua/rustc3/compiler/rustc_lint/src/early.rs:312:17
  38: <rustc_lint::early::EarlyContextAndPass<T> as rustc_ast::visit::Visitor>::visit_mac_call
             at /home/joshua/rustc3/compiler/rustc_lint/src/early.rs:292:9
  39: rustc_ast::visit::walk_stmt
             at /home/joshua/rustc3/compiler/rustc_ast/src/visit.rs:697:13
  40: rustc_ast::visit::walk_block
             at /home/joshua/rustc3/compiler/rustc_ast/src/visit.rs:686:5
  41: <rustc_lint::early::EarlyContextAndPass<T> as rustc_ast::visit::Visitor>::visit_block
             at /home/joshua/rustc3/compiler/rustc_lint/src/early.rs:208:9
  42: rustc_ast::visit::walk_fn
             at /home/joshua/rustc3/compiler/rustc_ast/src/visit.rs:637:13
  43: <rustc_lint::early::EarlyContextAndPass<T> as rustc_ast::visit::Visitor>::visit_fn
             at /home/joshua/rustc3/compiler/rustc_lint/src/early.rs:152:9
  44: rustc_ast::visit::walk_item
             at /home/joshua/rustc3/compiler/rustc_ast/src/visit.rs:291:13
  45: <rustc_lint::early::EarlyContextAndPass<T> as rustc_ast::visit::Visitor>::visit_item::{{closure}}
             at /home/joshua/rustc3/compiler/rustc_lint/src/early.rs:90:13
  46: rustc_lint::early::EarlyContextAndPass<T>::with_lint_attrs
             at /home/joshua/rustc3/compiler/rustc_lint/src/early.rs:63:9
  47: <rustc_lint::early::EarlyContextAndPass<T> as rustc_ast::visit::Visitor>::visit_item
             at /home/joshua/rustc3/compiler/rustc_lint/src/early.rs:88:9
  48: rustc_ast::visit::walk_crate
             at /home/joshua/rustc3/compiler/rustc_ast/src/visit.rs:235:5
  49: rustc_lint::early::early_lint_crate::{{closure}}
             at /home/joshua/rustc3/compiler/rustc_lint/src/early.rs:347:9
  50: rustc_lint::early::EarlyContextAndPass<T>::with_lint_attrs
             at /home/joshua/rustc3/compiler/rustc_lint/src/early.rs:63:9
  51: rustc_lint::early::early_lint_crate
             at /home/joshua/rustc3/compiler/rustc_lint/src/early.rs:342:5
  52: rustc_lint::early::check_ast_crate
             at /home/joshua/rustc3/compiler/rustc_lint/src/early.rs:372:24
  53: rustc_interface::passes::pre_expansion_lint::{{closure}}
             at /home/joshua/rustc3/compiler/rustc_interface/src/passes.rs:246:9
  54: rustc_data_structures::profiling::TimingGuard::run
             at /home/joshua/rustc3/compiler/rustc_data_structures/src/profiling.rs:590:9
  55: rustc_interface::passes::pre_expansion_lint
             at /home/joshua/rustc3/compiler/rustc_interface/src/passes.rs:245:5
  56: rustc_interface::passes::configure_and_expand
             at /home/joshua/rustc3/compiler/rustc_interface/src/passes.rs:269:5
  57: rustc_interface::queries::Queries::expansion::{{closure}}::{{closure}}
             at /home/joshua/rustc3/compiler/rustc_interface/src/queries.rs:184:17
  58: rustc_interface::passes::boxed_resolver::BoxedResolver::access
             at /home/joshua/rustc3/compiler/rustc_interface/src/passes.rs:142:13
  59: rustc_interface::queries::Queries::expansion::{{closure}}
             at /home/joshua/rustc3/compiler/rustc_interface/src/queries.rs:183:25
  60: rustc_interface::queries::Query<T>::compute
             at /home/joshua/rustc3/compiler/rustc_interface/src/queries.rs:38:28
  61: rustc_interface::queries::Queries::expansion
             at /home/joshua/rustc3/compiler/rustc_interface/src/queries.rs:172:9
  62: rustc_driver::run_compiler::{{closure}}::{{closure}}
             at /home/joshua/rustc3/compiler/rustc_driver/src/lib.rs:364:13
  63: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
             at /home/joshua/rustc3/compiler/rustc_interface/src/queries.rs:390:19
  64: rustc_driver::run_compiler::{{closure}}
             at /home/joshua/rustc3/compiler/rustc_driver/src/lib.rs:312:22
  65: rustc_interface::interface::create_compiler_and_run::{{closure}}
             at /home/joshua/rustc3/compiler/rustc_interface/src/interface.rs:209:13
  66: rustc_span::with_source_map
             at /home/joshua/rustc3/compiler/rustc_span/src/lib.rs:976:5
  67: rustc_interface::interface::create_compiler_and_run
             at /home/joshua/rustc3/compiler/rustc_interface/src/interface.rs:203:5
  68: rustc_interface::interface::run_compiler::{{closure}}
             at /home/joshua/rustc3/compiler/rustc_interface/src/interface.rs:225:12
  69: rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals::{{closure}}::{{closure}}
             at /home/joshua/rustc3/compiler/rustc_interface/src/util.rs:145:13
  70: scoped_tls::ScopedKey<T>::set
             at /home/joshua/.local/lib/cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137:9
  71: rustc_span::create_session_globals_then
             at /home/joshua/rustc3/compiler/rustc_span/src/lib.rs:109:5
  72: rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals::{{closure}}
             at /home/joshua/rustc3/compiler/rustc_interface/src/util.rs:143:9
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy/issues/new

note: Clippy version: clippy 0.1.57 (ac8dd1b2f24 2021-09-26)

query stack during panic:
end of query stack
{"message":"aborting due to 5 previous errors","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to 5 previous errors\n\n"}

------------------------------------------

thread 'compile_test' panicked at 'Some tests failed', /home/joshua/.local/lib/cargo/registry/src/github.com-1ecc6299db9ec823/compiletest_rs-0.7.0/src/lib.rs:105:22
stack backtrace:
   0: std::panicking::begin_panic
             at /home/joshua/rustc3/library/std/src/panicking.rs:543:12
   1: compiletest_rs::run_tests
             at /home/joshua/.local/lib/cargo/registry/src/github.com-1ecc6299db9ec823/compiletest_rs-0.7.0/src/lib.rs:105:22
   2: core::ops::function::FnOnce::call_once
   3: core::ops::function::FnOnce::call_once
             at /home/joshua/rustc3/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.


failures:
    compile_test

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 8.95s

@jyn514 jyn514 added A-diagnostics Area: Messages for errors, warnings, and lints 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. A-clippy Area: Clippy labels Sep 26, 2021
@flip1995
Copy link
Member

This is from a diagnostic constructed in a pre-expansion pass. Maybe this has something to do with the ICE

@camsteffen
Copy link
Contributor

camsteffen commented Sep 27, 2021

I'm able to reproduce this by running rustc +stage1 test.rs with the following contents:

trait X {
    fn test(x: u32, (
    )) {}
}

fn main() {}

And it needs debug = true.

@jyn514 jyn514 removed the A-clippy Area: Clippy label Sep 27, 2021
@estebank
Copy link
Contributor

I thought this had been solved by a recent @oli-obk PR :(

@oli-obk
Copy link
Contributor

oli-obk commented Sep 29, 2021

No, I just avoided a malformed span that was hitting the same ICE

The ICE itself will occur for any multi line span where the end is to the left of the start: #89046 (comment)

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 15, 2021
…ultiple-lines, r=oli-obk

emitter: current substitution can be multi-line

Fixes rust-lang#89280.

In `splice_lines`, there is some arithmetic to compute the required alignment such that future substitutions in a suggestion are aligned correctly. However, this assumed that the current substitution's span was only on a single line. In circumstances where this was not true, it could result in a arithmetic overflow when the substitution's end column was less than the substitution's start column.

r? `@oli-obk`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 15, 2021
…ultiple-lines, r=oli-obk

emitter: current substitution can be multi-line

Fixes rust-lang#89280.

In `splice_lines`, there is some arithmetic to compute the required alignment such that future substitutions in a suggestion are aligned correctly. However, this assumed that the current substitution's span was only on a single line. In circumstances where this was not true, it could result in a arithmetic overflow when the substitution's end column was less than the substitution's start column.

r? ``@oli-obk``
jackh726 added a commit to jackh726/rust that referenced this issue Oct 16, 2021
…ultiple-lines, r=oli-obk

emitter: current substitution can be multi-line

Fixes rust-lang#89280.

In `splice_lines`, there is some arithmetic to compute the required alignment such that future substitutions in a suggestion are aligned correctly. However, this assumed that the current substitution's span was only on a single line. In circumstances where this was not true, it could result in a arithmetic overflow when the substitution's end column was less than the substitution's start column.

r? ```@oli-obk```
@bors bors closed this as completed in 27a7ced Oct 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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

Successfully merging a pull request may close this issue.

5 participants