Skip to content

Commit a104fd6

Browse files
committed
Tweak extern Rust Result spans to work with nightly-2021-08-12
1 parent 5369efd commit a104fd6

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

macro/src/expand.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,9 +1127,11 @@ fn expand_rust_function_shim_super(
11271127
Some(ret) => quote!(#ret),
11281128
None => quote!(()),
11291129
};
1130-
let impl_trait = quote_spanned!(result.span=> impl);
1131-
let display = quote_spanned!(rangle.span=> ::std::fmt::Display);
1132-
quote!(-> ::std::result::Result<#ok, #impl_trait #display>)
1130+
// Set spans that result in the `Result<...>` written by the user being
1131+
// highlighted as the cause if their error type has no Display impl.
1132+
let result_begin = quote_spanned!(result.span=> ::std::result::Result<#ok, impl);
1133+
let result_end = quote_spanned!(rangle.span=> ::std::fmt::Display>);
1134+
quote!(-> #result_begin #result_end)
11331135
} else {
11341136
expand_return_type(&sig.ret)
11351137
};

tests/ui/result_no_display.stderr

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
error[E0277]: `NonError` doesn't implement `std::fmt::Display`
2-
--> $DIR/result_no_display.rs:1:1
2+
--> $DIR/result_no_display.rs:4:19
33
|
4-
1 | #[cxx::bridge]
5-
| ^^^^^^^^^^^^^^ `NonError` cannot be formatted with the default formatter
4+
4 | fn f() -> Result<()>;
5+
| ^^^^^^^^^^ `NonError` cannot be formatted with the default formatter
66
|
77
= help: the trait `std::fmt::Display` is not implemented for `NonError`
88
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
9-
= note: this error originates in the attribute macro `cxx::bridge` (in Nightly builds, run with -Z macro-backtrace for more info)

0 commit comments

Comments
 (0)