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

must_use lint: add with overflow #104352

Closed
jruderman opened this issue Nov 13, 2022 · 1 comment · Fixed by #104359
Closed

must_use lint: add with overflow #104352

jruderman opened this issue Nov 13, 2022 · 1 comment · Fixed by #104359
Assignees
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

@jruderman
Copy link
Contributor

jruderman commented Nov 13, 2022

Found with a modified fuzz-rustc

Code

fn main() {
    [0; usize::MAX];
}

Error output

When trying to build using a compiler that has overflow checks enabled:

thread 'rustc' panicked at 'attempt to add with overflow', compiler/rustc_lint/src/unused.rs:284

Backtrace
stack backtrace:
   0:        0x10c7e6811 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h555cbf84463534a2
   1:        0x10c8693a8 - core::fmt::write::h05afe7e253eb9347
   2:        0x10c7dedd8 - std::io::Write::write_fmt::ha26c40e390be1298
   3:        0x10c7e6602 - std::sys_common::backtrace::print::h117821677ef17b9e
   4:        0x10c7c8e75 - std::panicking::default_hook::{{closure}}::h674c8e012ebfd956
   5:        0x10c7c8c57 - std::panicking::default_hook::h28919ad06af0fc69
   6:        0x11de4bcc8 - rustc_driver[c1492cbdcce6be28]::DEFAULT_HOOK::{closure#0}::{closure#0}
   7:        0x10c7c9536 - std::panicking::rust_panic_with_hook::he4c3c24b75675b6b
   8:        0x10c7e4f52 - std::panicking::begin_panic_handler::{{closure}}::h03104d95ce06f62e
   9:        0x10c7e4ec8 - std::sys_common::backtrace::__rust_end_short_backtrace::h05e95a6bb7546abd
  10:        0x10c7c8f48 - _rust_begin_unwind
  11:        0x10c88d0d3 - core::panicking::panic_fmt::haaf3786c9d08448a
  12:        0x10c88d1a7 - core::panicking::panic::h9614480f1ff40688
  13:        0x1225b417d - <rustc_lint[c6b80aa7771506d]::unused::UnusedResults as rustc_lint[c6b80aa7771506d]::passes::LateLintPass>::check_stmt::check_must_use_ty
  14:        0x1225b2bab - <rustc_lint[c6b80aa7771506d]::unused::UnusedResults as rustc_lint[c6b80aa7771506d]::passes::LateLintPass>::check_stmt
  15:        0x1225a4326 - <rustc_lint[c6b80aa7771506d]::late::LateContextAndPass<rustc_lint[c6b80aa7771506d]::BuiltinCombinedModuleLateLintPass> as rustc_hir[423579e8abe3ddb5]::intravisit::Visitor>::visit_stmt
  16:        0x122538b2c - rustc_hir[423579e8abe3ddb5]::intravisit::walk_expr::<rustc_lint[c6b80aa7771506d]::late::LateContextAndPass<rustc_lint[c6b80aa7771506d]::BuiltinCombinedModuleLateLintPass>>
  17:        0x1225a3ad0 - <rustc_lint[c6b80aa7771506d]::late::LateContextAndPass<rustc_lint[c6b80aa7771506d]::BuiltinCombinedModuleLateLintPass> as rustc_hir[423579e8abe3ddb5]::intravisit::Visitor>::visit_expr
  18:        0x1225a2bca - <rustc_lint[c6b80aa7771506d]::late::LateContextAndPass<rustc_lint[c6b80aa7771506d]::BuiltinCombinedModuleLateLintPass> as rustc_hir[423579e8abe3ddb5]::intravisit::Visitor>::visit_nested_body
  19:        0x1225a4745 - <rustc_lint[c6b80aa7771506d]::late::LateContextAndPass<rustc_lint[c6b80aa7771506d]::BuiltinCombinedModuleLateLintPass> as rustc_hir[423579e8abe3ddb5]::intravisit::Visitor>::visit_fn
  20:        0x12253a402 - rustc_hir[423579e8abe3ddb5]::intravisit::walk_item::<rustc_lint[c6b80aa7771506d]::late::LateContextAndPass<rustc_lint[c6b80aa7771506d]::BuiltinCombinedModuleLateLintPass>>
  21:        0x1225a155f - <rustc_lint[c6b80aa7771506d]::late::LateContextAndPass<rustc_lint[c6b80aa7771506d]::BuiltinCombinedModuleLateLintPass> as rustc_hir[423579e8abe3ddb5]::intravisit::Visitor>::visit_nested_item
  22:        0x12253738c - rustc_hir[423579e8abe3ddb5]::intravisit::walk_mod::<rustc_lint[c6b80aa7771506d]::late::LateContextAndPass<rustc_lint[c6b80aa7771506d]::BuiltinCombinedModuleLateLintPass>>
  23:        0x1225a6285 - rustc_lint[c6b80aa7771506d]::late::late_lint_mod::<rustc_lint[c6b80aa7771506d]::BuiltinCombinedModuleLateLintPass>
  24:        0x122516310 - rustc_lint[c6b80aa7771506d]::lint_mod
  25:        0x121968a1c - rustc_query_system[90a25adb6ac2fb9e]::query::plumbing::try_execute_query::<rustc_query_impl[8e1328d96bec24c1]::plumbing::QueryCtxt, rustc_query_system[90a25adb6ac2fb9e]::query::caches::DefaultCache<rustc_span[8c774867ea78c94f]::def_id::LocalDefId, ()>>
  26:        0x121a89b03 - rustc_query_system[90a25adb6ac2fb9e]::query::plumbing::get_query::<rustc_query_impl[8e1328d96bec24c1]::queries::lint_mod, rustc_query_impl[8e1328d96bec24c1]::plumbing::QueryCtxt>
  27:        0x121b27e7f - <rustc_query_impl[8e1328d96bec24c1]::Queries as rustc_middle[9daaf7003dd7fae5]::ty::query::QueryEngine>::lint_mod
  28:        0x11dfad04d - <core[d75b6abbf9be9949]::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures[14290c48d64940a]::sync::par_for_each_in<&[rustc_hir[423579e8abe3ddb5]::hir_id::OwnerId], <rustc_middle[9daaf7003dd7fae5]::hir::map::Map>::par_for_each_module<rustc_lint[c6b80aa7771506d]::late::check_crate<rustc_lint[c6b80aa7771506d]::BuiltinCombinedLateLintPass, rustc_interface[d27c24a0cff43249]::passes::analysis::{closure#5}::{closure#1}::{closure#2}::{closure#0}::{closure#0}>::{closure#1}::{closure#0}::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}> as core[d75b6abbf9be9949]::ops::function::FnOnce<()>>::call_once
  29:        0x11df624f9 - std[edb4f308383f81f7]::panicking::try::<(), core[d75b6abbf9be9949]::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures[14290c48d64940a]::sync::par_for_each_in<&[rustc_hir[423579e8abe3ddb5]::hir_id::OwnerId], <rustc_middle[9daaf7003dd7fae5]::hir::map::Map>::par_for_each_module<rustc_lint[c6b80aa7771506d]::late::check_crate<rustc_lint[c6b80aa7771506d]::BuiltinCombinedLateLintPass, rustc_interface[d27c24a0cff43249]::passes::analysis::{closure#5}::{closure#1}::{closure#2}::{closure#0}::{closure#0}>::{closure#1}::{closure#0}::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}>>
  30:        0x11def9953 - rustc_data_structures[14290c48d64940a]::sync::par_for_each_in::<&[rustc_hir[423579e8abe3ddb5]::hir_id::OwnerId], <rustc_middle[9daaf7003dd7fae5]::hir::map::Map>::par_for_each_module<rustc_lint[c6b80aa7771506d]::late::check_crate<rustc_lint[c6b80aa7771506d]::BuiltinCombinedLateLintPass, rustc_interface[d27c24a0cff43249]::passes::analysis::{closure#5}::{closure#1}::{closure#2}::{closure#0}::{closure#0}>::{closure#1}::{closure#0}::{closure#0}>::{closure#0}>
  31:        0x11defdb7f - <rustc_session[7b13359bdf8db9ac]::session::Session>::time::<(), rustc_lint[c6b80aa7771506d]::late::check_crate<rustc_lint[c6b80aa7771506d]::BuiltinCombinedLateLintPass, rustc_interface[d27c24a0cff43249]::passes::analysis::{closure#5}::{closure#1}::{closure#2}::{closure#0}::{closure#0}>::{closure#1}::{closure#0}>
  32:        0x11defdc3f - <rustc_session[7b13359bdf8db9ac]::session::Session>::time::<(), rustc_interface[d27c24a0cff43249]::passes::analysis::{closure#5}::{closure#1}::{closure#2}::{closure#0}>
  33:        0x11df62608 - std[edb4f308383f81f7]::panicking::try::<(), core[d75b6abbf9be9949]::panic::unwind_safe::AssertUnwindSafe<rustc_interface[d27c24a0cff43249]::passes::analysis::{closure#5}::{closure#1}::{closure#2}>>
  34:        0x11dfadcec - <core[d75b6abbf9be9949]::panic::unwind_safe::AssertUnwindSafe<rustc_interface[d27c24a0cff43249]::passes::analysis::{closure#5}::{closure#1}> as core[d75b6abbf9be9949]::ops::function::FnOnce<()>>::call_once
  35:        0x11df62729 - std[edb4f308383f81f7]::panicking::try::<(), core[d75b6abbf9be9949]::panic::unwind_safe::AssertUnwindSafe<rustc_interface[d27c24a0cff43249]::passes::analysis::{closure#5}::{closure#1}>>
  36:        0x11deff179 - <rustc_session[7b13359bdf8db9ac]::session::Session>::time::<(), rustc_interface[d27c24a0cff43249]::passes::analysis::{closure#5}>
  37:        0x11df5d50c - rustc_interface[d27c24a0cff43249]::passes::analysis
  38:        0x1219a8950 - rustc_query_system[90a25adb6ac2fb9e]::query::plumbing::try_execute_query::<rustc_query_impl[8e1328d96bec24c1]::plumbing::QueryCtxt, rustc_query_system[90a25adb6ac2fb9e]::query::caches::DefaultCache<(), core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>>>
  39:        0x121a89609 - rustc_query_system[90a25adb6ac2fb9e]::query::plumbing::get_query::<rustc_query_impl[8e1328d96bec24c1]::queries::analysis, rustc_query_impl[8e1328d96bec24c1]::plumbing::QueryCtxt>
  40:        0x121b09f07 - <rustc_query_impl[8e1328d96bec24c1]::Queries as rustc_middle[9daaf7003dd7fae5]::ty::query::QueryEngine>::analysis
  41:        0x11de79388 - <rustc_interface[d27c24a0cff43249]::passes::QueryContext>::enter::<rustc_driver[c1492cbdcce6be28]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>>
  42:        0x11de6fcd8 - <rustc_interface[d27c24a0cff43249]::interface::Compiler>::enter::<rustc_driver[c1492cbdcce6be28]::run_compiler::{closure#1}::{closure#2}, core[d75b6abbf9be9949]::result::Result<core[d75b6abbf9be9949]::option::Option<rustc_interface[d27c24a0cff43249]::queries::Linker>, rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>>
  43:        0x11de5f19b - rustc_span[8c774867ea78c94f]::with_source_map::<core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>, rustc_interface[d27c24a0cff43249]::interface::run_compiler<core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>, rustc_driver[c1492cbdcce6be28]::run_compiler::{closure#1}>::{closure#0}::{closure#1}>
  44:        0x11de850ea - <scoped_tls[eb29bcc2d94b2b7f]::ScopedKey<rustc_span[8c774867ea78c94f]::SessionGlobals>>::set::<rustc_interface[d27c24a0cff43249]::interface::run_compiler<core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>, rustc_driver[c1492cbdcce6be28]::run_compiler::{closure#1}>::{closure#0}, core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>>
  45:        0x11de449d0 - std[edb4f308383f81f7]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[d27c24a0cff43249]::util::run_in_thread_pool_with_globals<rustc_interface[d27c24a0cff43249]::interface::run_compiler<core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>, rustc_driver[c1492cbdcce6be28]::run_compiler::{closure#1}>::{closure#0}, core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>>
  46:        0x11de5bffd - std[edb4f308383f81f7]::panicking::try::<core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>, core[d75b6abbf9be9949]::panic::unwind_safe::AssertUnwindSafe<<std[edb4f308383f81f7]::thread::Builder>::spawn_unchecked_<rustc_interface[d27c24a0cff43249]::util::run_in_thread_pool_with_globals<rustc_interface[d27c24a0cff43249]::interface::run_compiler<core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>, rustc_driver[c1492cbdcce6be28]::run_compiler::{closure#1}>::{closure#0}, core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>>::{closure#1}::{closure#0}>>
  47:        0x11de4df10 - <<std[edb4f308383f81f7]::thread::Builder>::spawn_unchecked_<rustc_interface[d27c24a0cff43249]::util::run_in_thread_pool_with_globals<rustc_interface[d27c24a0cff43249]::interface::run_compiler<core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>, rustc_driver[c1492cbdcce6be28]::run_compiler::{closure#1}>::{closure#0}, core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d75b6abbf9be9949]::result::Result<(), rustc_errors[3a3071537b5ec853]::ErrorGuaranteed>>::{closure#1} as core[d75b6abbf9be9949]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  48:        0x10c7c1dab - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7f65ec775065aafc
  49:        0x10c7c399f - std::sys::unix::thread::Thread::new::thread_start::h4513acaf2edb2674
  50:     0x7ff80d84d4e1 - __pthread_start

Version

Built stage1 from aa05f99 with overflow checks enabled

config.toml
# Includes one of the default files in src/bootstrap/defaults
profile = "compiler"
changelog-seen = 2

[llvm]
download-ci-llvm = true     # Download a pre-built LLVM?
assertions = true           # LLVM assertions on?

[rust]
incremental = true          # Build rustc with incremental compilation?
debug-assertions = true
overflow-checks = true
@jruderman jruderman 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 Nov 13, 2022
@Noratrieb
Copy link
Member

@rustbot claim

Manishearth added a commit to Manishearth/rust that referenced this issue Nov 22, 2022
Refactor must_use lint into two parts

Before, the lint did the checking for `must_use` and pretty printing the types in a special format in one pass, causing quite complex and untranslatable code.
Now the collection and printing is split in two. That should also make it easier to translate or extract the type pretty printing in the future.

Also fixes an integer overflow in the array length pluralization
calculation.

fixes rust-lang#104352
Manishearth added a commit to Manishearth/rust that referenced this issue Nov 22, 2022
Refactor must_use lint into two parts

Before, the lint did the checking for `must_use` and pretty printing the types in a special format in one pass, causing quite complex and untranslatable code.
Now the collection and printing is split in two. That should also make it easier to translate or extract the type pretty printing in the future.

Also fixes an integer overflow in the array length pluralization
calculation.

fixes rust-lang#104352
Manishearth added a commit to Manishearth/rust that referenced this issue Nov 23, 2022
Refactor must_use lint into two parts

Before, the lint did the checking for `must_use` and pretty printing the types in a special format in one pass, causing quite complex and untranslatable code.
Now the collection and printing is split in two. That should also make it easier to translate or extract the type pretty printing in the future.

Also fixes an integer overflow in the array length pluralization
calculation.

fixes rust-lang#104352
@bors bors closed this as completed in a673364 Nov 23, 2022
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

Successfully merging a pull request may close this issue.

2 participants