Q: return/break/continue in an inlined function

I'm wondering about something like the following scenario:

#[inline(always)]
fn foo(r: usize) -> String {
    if r < 10 { 
        return String::from("r < 10");
    } 
    String::from("r >= 10");
}

fn main() {
    let s0: String = foo(0);
    let s1: String = foo(15);
}

Imagine that there are multiple levels of inlined functions like foo*, each with their own uses of return/break/continue etc.
Would that simply continue to behave as if all the functions were never inlined?

Intuition tells me that inlined versions should work identically to the non-inlined versions i.e. that all returns, continues, breaks etc just continue to work as the Programmer intended, but I can't really back that up with anything specific, hence this question.

*By multiple levels I mean that there are inlined functions (indirectly) calling other inlined functions.

Yes, inlining doesn't change the semantics in any way, including borrow checking or returning.

1 Like

Nice.
I assume that that also holds for inlined closures?

Yes, same idea.

1 Like