Skip to content

Removing cold/inline(never) from slice_error_fail causes a cycle error #122659

Closed
@saethlin

Description

@saethlin

Apply this patch:

diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs
index 4943bbc45d0..77ef7b9431d 100644
--- a/library/core/src/str/mod.rs
+++ b/library/core/src/str/mod.rs
@@ -80,8 +80,6 @@
 use iter::SplitInternal;
 use iter::{MatchesInternal, SplitNInternal};
 
-#[inline(never)]
-#[cold]
 #[track_caller]
 #[rustc_allow_const_fn_unstable(const_eval_select)]
 #[cfg(not(feature = "panic_immediate_abort"))]

And you'll get this query cycle error:

error[E0391]: cycle detected when optimizing MIR for `str::traits::<impl at library/core/src/str/traits.rs:330:1: 330:52>::index`
   --> library/core/src/str/traits.rs:363:5
    |
363  |     fn index(self, slice: &str) -> &Self::Output {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
note: ...which requires whether the item should be made inlinable across crates...
   --> library/core/src/str/mod.rs:86:1
    |
86   | const fn slice_error_fail(s: &str, begin: usize, end: usize) -> ! {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires optimizing MIR for `str::slice_error_fail`...
   --> library/core/src/str/mod.rs:86:1
    |
86   | const fn slice_error_fail(s: &str, begin: usize, end: usize) -> ! {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires whether the item should be made inlinable across crates...
   --> library/core/src/str/mod.rs:109:1
    |
109  | fn slice_error_fail_rt(s: &str, begin: usize, end: usize) -> ! {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires optimizing MIR for `str::slice_error_fail_rt`...
   --> library/core/src/str/mod.rs:109:1
    |
109  | fn slice_error_fail_rt(s: &str, begin: usize, end: usize) -> ! {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: ...which again requires optimizing MIR for `str::traits::<impl at library/core/src/str/traits.rs:330:1: 330:52>::index`, completing the cycle
note: cycle used when optimizing MIR for `fmt::<impl at library/core/src/fmt/mod.rs:1238:1: 1238:23>::write_formatted_parts`
   --> library/core/src/fmt/mod.rs:1527:5
    |
1527 |     unsafe fn write_formatted_parts(&mut self, formatted: &numfmt::Formatted<'_>) -> Result {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information

There's a strange call graph here; slice_error_fail_rt which is responsible for emitting string slicing panics uses panicky string slicing. From reading the code, I'm pretty confident that the infinite recursion case is actually impossible, but our query cycle detection doesn't know or care, and is supposed to handle this case.

Metadata

Metadata

Assignees

Labels

A-mir-optArea: MIR optimizationsA-mir-opt-inliningArea: MIR inliningC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions