Point at try ?
on errors affecting the err match arm of the desugared code
This commit is contained in:
parent
70f130954d
commit
007b40be01
4 changed files with 21 additions and 13 deletions
|
@ -4685,6 +4685,14 @@ impl<'a> LoweringContext<'a> {
|
|||
Symbol::intern("try_trait")
|
||||
].into()),
|
||||
);
|
||||
let try_span = self.sess.source_map().end_point(e.span);
|
||||
let try_span = self.mark_span_with_reason(
|
||||
CompilerDesugaringKind::QuestionMark,
|
||||
try_span,
|
||||
Some(vec![
|
||||
Symbol::intern("try_trait")
|
||||
].into()),
|
||||
);
|
||||
|
||||
// `Try::into_result(<expr>)`
|
||||
let discr = {
|
||||
|
@ -4729,14 +4737,14 @@ impl<'a> LoweringContext<'a> {
|
|||
// return Try::from_error(From::from(err)),`
|
||||
let err_arm = {
|
||||
let err_ident = self.str_to_ident("err");
|
||||
let (err_local, err_local_nid) = self.pat_ident(e.span, err_ident);
|
||||
let (err_local, err_local_nid) = self.pat_ident(try_span, err_ident);
|
||||
let from_expr = {
|
||||
let path = &["convert", "From", "from"];
|
||||
let from = P(self.expr_std_path(
|
||||
e.span, path, None, ThinVec::new()));
|
||||
let err_expr = self.expr_ident(e.span, err_ident, err_local_nid);
|
||||
try_span, path, None, ThinVec::new()));
|
||||
let err_expr = self.expr_ident(try_span, err_ident, err_local_nid);
|
||||
|
||||
self.expr_call(e.span, from, hir_vec![err_expr])
|
||||
self.expr_call(try_span, from, hir_vec![err_expr])
|
||||
};
|
||||
let from_err_expr =
|
||||
self.wrap_in_try_constructor("from_error", from_expr, unstable_span);
|
||||
|
@ -4745,7 +4753,7 @@ impl<'a> LoweringContext<'a> {
|
|||
let ret_expr = if let Some(catch_node) = catch_scope {
|
||||
let target_id = Ok(self.lower_node_id(catch_node).hir_id);
|
||||
P(self.expr(
|
||||
e.span,
|
||||
try_span,
|
||||
hir::ExprKind::Break(
|
||||
hir::Destination {
|
||||
label: None,
|
||||
|
@ -4756,10 +4764,10 @@ impl<'a> LoweringContext<'a> {
|
|||
thin_attrs,
|
||||
))
|
||||
} else {
|
||||
P(self.expr(e.span, hir::ExprKind::Ret(Some(from_err_expr)), thin_attrs))
|
||||
P(self.expr(try_span, hir::ExprKind::Ret(Some(from_err_expr)), thin_attrs))
|
||||
};
|
||||
|
||||
let err_pat = self.pat_err(e.span, err_local);
|
||||
let err_pat = self.pat_err(try_span, err_local);
|
||||
self.arm(hir_vec![err_pat], ret_expr)
|
||||
};
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
error[E0277]: the trait bound `(): std::convert::From<{integer}>` is not satisfied
|
||||
--> $DIR/issue-32709.rs:4:5
|
||||
--> $DIR/issue-32709.rs:4:11
|
||||
|
|
||||
LL | Err(5)?;
|
||||
| ^^^^^^^ the trait `std::convert::From<{integer}>` is not implemented for `()`
|
||||
| ^ the trait `std::convert::From<{integer}>` is not implemented for `()`
|
||||
|
|
||||
= note: required by `std::convert::From::from`
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
error[E0277]: the trait bound `i32: std::convert::From<&str>` is not satisfied
|
||||
--> $DIR/try-block-bad-type.rs:7:9
|
||||
--> $DIR/try-block-bad-type.rs:7:16
|
||||
|
|
||||
LL | Err("")?;
|
||||
| ^^^^^^^^ the trait `std::convert::From<&str>` is not implemented for `i32`
|
||||
| ^ the trait `std::convert::From<&str>` is not implemented for `i32`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<i32 as std::convert::From<bool>>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
error[E0277]: the trait bound `(): std::convert::From<std::option::NoneError>` is not satisfied
|
||||
--> $DIR/try-on-option.rs:7:5
|
||||
--> $DIR/try-on-option.rs:7:6
|
||||
|
|
||||
LL | x?;
|
||||
| ^^ the trait `std::convert::From<std::option::NoneError>` is not implemented for `()`
|
||||
| ^ the trait `std::convert::From<std::option::NoneError>` is not implemented for `()`
|
||||
|
|
||||
= note: required by `std::convert::From::from`
|
||||
|
||||
|
|
Loading…
Reference in a new issue