rust-lang / rust-lang/rust

ICE: `Same capture can't be ByUse and ByValue at the same time`

Open
#141,916 1 comment 0 reactions 1 assignee View on GitHub

@spastorino is already working on this.

Since Jun 6, 2025.

C-bug F-ergonomic_clones I-ICE T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
#![allow(incomplete_features)]
#![feature(ergonomic_clones)]

use std::clone::UseCloned;

#[derive(Clone)]
struct Foo;

impl UseCloned for Foo {}

fn do_not_move_test(x: Foo) -> Foo { async {
    let s = x.use;
    x
} }

fn main() {}

A mutant of tests/ui/ergonomic-clones/dotuse/basic.rs

Meta

rustc --version --verbose:

rustc 1.89.0-nightly (99e7c15e8 2025-06-01)
binary: rustc
commit-hash: 99e7c15e81385b38a8186b51edc4577d5d7b5bdd
commit-date: 2025-06-01
host: aarch64-apple-darwin
release: 1.89.0-nightly
LLVM version: 20.1.5
Error output

command: rustc --edition=2024

--edition=2021 also ICEs

error[E0308]: mismatched types
  --> afidt_3.rs:11:38
   |
11 |   fn do_not_move_test(x: Foo) -> Foo { async {
   |  ________________________________---___^
   | |                                |
   | |                                expected `Foo` because of return type
12 | |     let s = x.use;
13 | |     x
14 | | } }
   | |_^ expected `Foo`, found `async` block
   |
   = note:     expected struct `Foo`
           found `async` block `{async block@afidt_3.rs:11:38: 11:43}`

error: internal compiler error: compiler/rustc_hir_typeck/src/upvar.rs:2431:17: Same capture can't be ByUse and ByValue at the same time


thread 'rustc' panicked at compiler/rustc_hir_typeck/src/upvar.rs:2431:17:
Box<dyn Any>
Backtrace

thread 'rustc' panicked at compiler/rustc_hir_typeck/src/upvar.rs:2431:17:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   5: rustc_middle::util::bug::bug_fmt
   6: rustc_hir_typeck::upvar::determine_capture_info
   7: <rustc_hir_typeck::fn_ctxt::FnCtxt>::compute_min_captures
   8: <rustc_hir_typeck::fn_ctxt::FnCtxt>::analyze_closure
   9: <rustc_hir_typeck::upvar::InferBorrowKindVisitor as rustc_hir::intravisit::Visitor>::visit_expr
  10: rustc_hir_typeck::typeck_with_inspect::{closure#0}
  11: rustc_hir_typeck::typeck
      [... omitted 1 frame ...]
  12: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis::check_crate::{closure#1}>::{closure#0}
  13: rustc_hir_analysis::check_crate
  14: rustc_interface::passes::run_required_analyses
  15: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  16: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
  17: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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: please make sure that you have updated to the latest nightly

note: please attach the file at `/Users/jisukbyun/workspace/250203 scratch/rustc-ice-2025-06-02T14_11_03-89049.txt` to your bug report

query stack during panic:
#0 [typeck] type-checking `do_not_move_test`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.

Bisects to

searched nightlies: from nightly-2025-01-01 to nightly-2025-06-01
regressed nightly: nightly-2025-03-08
searched commit range: https://github.com/rust-lang/rust/compare/b74da9613a8cb5ba67a985f71325be0b7b16c0dd...f5a1ef7121ad661b5a21a1d02941c8064d54ee0b
regressed commit: https://github.com/rust-lang/rust/commit/f5a1ef7121ad661b5a21a1d02941c8064d54ee0b

bisected with cargo-bisect-rustc v0.6.9

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --end=2025-06-01 --regress ice --preserve --script rustc -- afidt_3.rs --edition=2024
********************************************************************************
Regression in f5a1ef7121ad661b5a21a1d02941c8064d54ee0b
********************************************************************************

Attempting to search unrolled perf builds
Found commits ["5cf66023", "16414e51", "0b6c069b", "aa349152", "275aad33", "eaf94402"]
installing 5cf660233fcc08fce21f8845d36982b25cb0535c
rust-std-nightly-x86_64-unknown-linux-gnu: 30.69 MB / 30.69 MB [==================================] 100.00 % 12.52 MB/s testing...
RESULT: 5cf660233fcc08fce21f8845d36982b25cb0535c, ===> Script found ICE

Regression in https://github.com/rust-lang-ci/rust/commit/5cf660233fcc08fce21f8845d36982b25cb0535c
The PR introducing the regression in this rollup is #134797: Ergonomic ref counting
Notes

@rustbot label F-ergonomic_clones

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.