You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
str.find/index_of: a start-offset form (find(needle, from)) #2377
From #2358: s.find(block, first + 1) is what a tool script naturally writes to find the next occurrence. #2358 makes the two-argument call a clean diagnostic ("find expects 1 argument(s), found 2"); this issue tracks the enhancement itself.
What needs a ruling/spec words before implementation:
semantics: negative from (clamp to 0? from end?), from > len() (no match/-1?), byte vs char offset (find returns a byte offset today);
whether index_of, contains, starts_with grow the same parameter or only find.
Implementation sketch once ruled: BuiltinSigs row gains the parameter (BuiltinSigs has no default-value spelling yet, so a defaulted parameter needs one, or Sema pads the omitted argument the way Atomic's Ordering is materialized in MirLower); MirIntrinsic.STR_FIND/STR_INDEX_OF carry the offset to with_str_index_of_ref (rt grows a from-variant or the offset is applied to a slice view); ComptimeEval's comptime_str_find and the emit-C path (CcBuiltin.STR_FIND) follow.
Done in #2402 as D129 (delegated): find(needle: &str, from: isize = 0) -> isize is an impl str method in std.string over the index_of intrinsic; from past len() finds nothing, a negative from is out of range (D71), an empty needle is found at from. rfind no longer panics inside a multibyte character.
Activity
#2366: an assignment makes the new value before freeing the old; #2377 …
ehartford commentedon Oct 14, 2026
Done in #2402 as D129 (delegated):
find(needle: &str, from: isize = 0) -> isizeis animpl strmethod in std.string over theindex_ofintrinsic;frompastlen()finds nothing, a negativefromis out of range (D71), an empty needle is found atfrom.rfindno longer panics inside a multibyte character.