Skip to content

Commit affcc4e

Browse files
authored
Merge pull request #1114 from dtolnay/failstring
Allow trycatch to call Fail using std::string
2 parents 031723f + 6f257d8 commit affcc4e

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

gen/src/builtin.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ pub(super) fn write(out: &mut OutFile) {
255255
}
256256

257257
if builtin.trycatch {
258+
include.string = true;
258259
out.next_section();
259260
writeln!(out, "class Fail final {{");
260261
writeln!(out, " ::rust::repr::PtrLen &throw$;");
@@ -264,6 +265,7 @@ pub(super) fn write(out: &mut OutFile) {
264265
" Fail(::rust::repr::PtrLen &throw$) : throw$(throw$) {{}}"
265266
);
266267
writeln!(out, " void operator()(const char *) noexcept;");
268+
writeln!(out, " void operator()(const std::string &) noexcept;");
267269
writeln!(out, "}};");
268270
}
269271

src/cxx.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,11 +537,16 @@ class Fail final {
537537
public:
538538
Fail(repr::PtrLen &throw$) : throw$(throw$) {}
539539
void operator()(const char *) noexcept;
540+
void operator()(const std::string &) noexcept;
540541
};
541542

542543
void Fail::operator()(const char *catch$) noexcept {
543544
throw$ = cxxbridge1$exception(catch$, std::strlen(catch$));
544545
}
546+
547+
void Fail::operator()(const std::string &catch$) noexcept {
548+
throw$ = cxxbridge1$exception(catch$.data(), catch$.length());
549+
}
545550
} // namespace detail
546551

547552
} // namespace cxxbridge1

0 commit comments

Comments
 (0)