https://gcc.gnu.org/g:d182d582c0f15ec9868b283f93b4ecb2eeae485f
commit r17-3059-gd182d582c0f15ec9868b283f93b4ecb2eeae485f Author: Pierre-Emmanuel Patry <[email protected]> Date: Sun May 24 23:14:18 2026 +0200 gccrs: Return empty file name for inline string source The compiler would crash if the file name was requested from the lexer whilst lexing from a non-file source (mainly string sources). Now return an empty file name instead. gcc/rust/ChangeLog: * lex/rust-lex.h: Return an empty file name when file is missing. Signed-off-by: Pierre-Emmanuel Patry <[email protected]> Diff: --- gcc/rust/lex/rust-lex.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gcc/rust/lex/rust-lex.h b/gcc/rust/lex/rust-lex.h index 8d65a6ddf551..530eafbe5457 100644 --- a/gcc/rust/lex/rust-lex.h +++ b/gcc/rust/lex/rust-lex.h @@ -207,7 +207,13 @@ public: void split_current_token (std::vector<TokenPtr> new_tokens); Linemap *get_line_map () { return line_map; } - std::string get_filename () { return std::string (input.get_filename ()); } + std::string get_filename () + { + if (input.ok ()) + return std::string (input.get_filename ()); + else + return ""; + } private: void start_line (int current_line, int current_column);
