Useful tools:
C++ Insights can show you that fileContents is cast to std::string&& (which is equivalent to std::move(fileContents)) when passed to the constructor of std::optional.
Compiler Explorer can show you that the constructor of std::optional invoked at the return statement is the one accepting rvalue reference of std::string.