8000 Rollup of 4 pull requests by Centril · Pull Request #64951 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Rollup of 4 pull requests #64951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1d704e7
fix typo
ztlpn Sep 16, 2019
3f85ff4
fix spurious unreachable_code lints for try{} block ok-wrapping
ztlpn Sep 18, 2019
c60c0cb
add tests
ztlpn Sep 18, 2019
65251ea
address review comments
ztlpn Sep 18, 2019
58eacaa
fix test after rebase
ztlpn Sep 22, 2019
d2c0d10
[const-prop] Handle MIR Rvalue::Repeat
wesleywiser Sep 14, 2019
f290467
syntax: cleanup method parsing.
Centril Sep 29, 2019
378cc98
syntax: `is_named_argument` -> `is_named_param`.
Centril Sep 29, 2019
4fa9c3b
syntax refactor `parse_fn_params`
Centril Sep 29, 2019
40dc9da
syntax refactor `parse_self_param` (1)
Centril Sep 29, 2019
f688f8a
syntax refactor `parse_self_param` (2)
Centril Sep 29, 2019
ac454e9
syntax refactor `parse_self_param` (3)
Centril Sep 30, 2019
4306d00
syntax refactor `parse_self_param` (4)
Centril Sep 30, 2019
0492302
syntax refactor `parse_self_param` (5)
Centril Sep 30, 2019
347deac
syntax: reorder param parsing to make more sense.
Centril Sep 30, 2019
d9d0e5d
syntax: cleanup `parse_fn_decl`.
Centril Sep 30, 2019
5b80ead
syntax: misc cleanup
Centril Sep 30, 2019
66bf323
syntax: cleanup `parse_visibility`.
Centril Sep 30, 2019
573a8d8
syntax: extract `error_on_invalid_abi`.
Centril Sep 30, 2019
258e86a
syntax: fuse more code paths together.
Centril Sep 30, 2019
bea404f
syntax: stylistic cleanup in item parsing.
Centril Sep 30, 2019
151ce96
syntax: reduce repetition in fn parsing.
Centril Sep 30, 2019
85f2945
[const-prop] Handle MIR Rvalue::Aggregates
wesleywiser Sep 14, 2019
ea78010
[const-prop] Handle MIR Rvalue::Discriminant
wesleywiser Sep 15, 2019
b3234a3
[const-prop] Handle MIR Rvalue::Box
wesleywiser Sep 15, 2019
5804c3b
Cleanup const_prop() some
wesleywiser Sep 15, 2019
7062164
Added interpreter mode to compiler interface, interpreter parsing fun…
alexreg Sep 20, 2019
df298b4
syntax: document some methods.
Centril Oct 1, 2019
30647d1
syntax: put helpers of `parse_self_param` in the method.
Centril Oct 1, 2019
49780d2
syntax: merge things back into `parse_visibility`.
Centril Oct 1, 2019
e046904
syntax: de-closure-ify `check_or_expected`.
Centril Oct 1, 2019
5c5dd80
syntax: reformat passing of `FnHeader` to `parse_item_fn`.
Centril Oct 1, 2019
e463a22
Rollup merge of #64581 - ztlpn:fix-ok-wrapping-unreachable-code, r=Ce…
Centril Oct 1, 2019
031d968
Rollup merge of #64648 - alexreg:rush-parsing, r=Mark-Simulacrum
Centril Oct 1, 2019
8436080
Rollup merge of #64890 - wesleywiser:const_prop_rvalue, r=oli-obk
Centril Oct 1, 2019
c0e0a32
Rollup merge of #64910 - Centril:params-cleanup, r=petrochenkov
Centril Oct 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
address review comments
  • Loading branch information
ztlpn committed Sep 22, 2019
commit 65251ea73ab5d19e70a6ff4b64fb218a03504b6b
28 changes: 13 additions & 15 deletions src/librustc/hir/lowering/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,36 +392,34 @@ impl LoweringContext<'_> {
)
}

/// Desugar `try { <stmts>; <expr> }` into `{ <stmts>; ::std::ops::Try::from_ok(<expr>) }`,
/// `try { <stmts>; }` into `{ <stmts>; ::std::ops::Try::from_ok(()) }`
/// and save the block id to use it as a break target for desugaring of the `?` operator.
fn lower_expr_try_block(&mut self, body: &Block) -> hir::ExprKind {
self.with_catch_scope(body.id, |this| {
let mut block = this.lower_block(body, true).into_inner();

let tail_expr = block.expr.take().map_or_else(
|| {
let unit_span = this.mark_span_with_reason(
DesugaringKind::TryBlock,
this.sess.source_map().end_point(body.span),
None
);
this.expr_unit(unit_span)
},
|x: P<hir::Expr>| x.into_inner(),
);

let from_ok_span = this.mark_span_with_reason(
let try_span = this.mark_span_with_reason(
DesugaringKind::TryBlock,
tail_expr.span,
body.span,
this.allow_try_trait.clone(),
);

// Final expression of the block (if present) or `()` with span at the end of block
let tail_expr = block.expr.take().map_or_else(
|| this.expr_unit(this.sess.source_map().end_point(try_span)),
|x: P<hir::Expr>| x.into_inner(),
);

let ok_wrapped_span = this.mark_span_with_reason(
DesugaringKind::TryBlock,
tail_expr.span,
None
);

// `::std::ops::Try::from_ok($tail_expr)`
block.expr = Some(this.wrap_in_try_constructor(
sym::from_ok, from_ok_span, tail_expr, ok_wrapped_span));
sym::from_ok, try_span, tail_expr, ok_wrapped_span));

hir::ExprKind::Block(P(block), None)
})
Expand Down
40 changes: 20 additions & 20 deletions src/librustc_typeck/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
debug!(">> type-checking: expr={:?} expected={:?}",
expr, expected);

// If when desugaring the try block we ok-wrapped an expression that diverges
// (e.g. `try { return }`) then technically the ok-wrapping expression is unreachable.
// But since it is autogenerated code the resulting warning is confusing for the user
// so we want avoid generating it.
// Ditto for the autogenerated `Try::from_ok(())` at the end of e.g. `try { return; }`.
let (is_try_block_ok_wrapped_expr, is_try_block_generated_expr) = match expr.node {
ExprKind::Call(_, ref args) if expr.span.is_desugaring(DesugaringKind::TryBlock) => {
(true, args.len() == 1 && args[0].span.is_desugaring(DesugaringKind::TryBlock))
}
_ => (false, false),
// True if `expr` is a `Try::from_ok(())` that is a result of desugaring a try block
// without the final expr (e.g. `try { return; }`). We don't want to generate an
// unreachable_code lint for it since warnings for autogenerated code are confusing.
let is_try_block_generated_unit_expr = match expr.node {
ExprKind::Call(_, ref args) if expr.span.is_desugaring(DesugaringKind::TryBlock) =>
args.len() == 1 && args[0].span.is_desugaring(DesugaringKind::TryBlock),

_ => false,
};

// Warn for expressions after diverging siblings.
if !is_try_block_generated_expr {
if !is_try_block_generated_unit_expr {
self.warn_if_unreachable(expr.hir_id, expr.span, "expression");
}

Expand All @@ -174,15 +172,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let ty = self.check_expr_kind(expr, expected, needs);

// Warn for non-block expressions with diverging children.
if !is_try_block_ok_wrapped_expr {
match expr.node {
ExprKind::Block(..) | ExprKind::Loop(..) | ExprKind::Match(..) => {},
ExprKind::Call(ref callee, _) =>
self.warn_if_unreachable(expr.hir_id, callee.span, "call"),
ExprKind::MethodCall(_, ref span, _) =>
self.warn_if_unreachable(expr.hir_id, *span, "call"),
_ => self.warn_if_unreachable(expr.hir_id, expr.span, "expression"),
}
match expr.node {
ExprKind::Block(..) | ExprKind::Loop(..) | ExprKind::Match(..) => {},
// If `expr` is a result of desugaring the try block and is an ok-wrapped
// diverging expression (e.g. it arose from desugaring of `try { return }`),
// we skip issuing a warning because it is autogenerated code.
ExprKind::Call(..) if expr.span.is_desugaring(DesugaringKind::TryBlock) => {},
ExprKind::Call(ref callee, _) =>
self.warn_if_un CAD6 reachable(expr.hir_id, callee.span, "call"),
ExprKind::MethodCall(_, ref span, _) =>
self.warn_if_unreachable(expr.hir_id, *span, "call"),
_ => self.warn_if_unreachable(expr.hir_id, expr.span, "expression"),
}

// Any expression that produces a value of type `!` must have diverged
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/try-block/try-block-bad-type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ LL | let res: Result<i32, i32> = try { };
found type `()`

error[E0277]: the trait bound `(): std::ops::Try` is not satisfied
--> $DIR/try-block-bad-type.rs:17:25
--> $DIR/try-block-bad-type.rs:17:23
|
LL | let res: () = try { };
| ^ the trait `std::ops::Try` is not implemented for `()`
| ^^^ the trait `std::ops::Try` is not implemented for `()`
|
= note: required by `std::ops::Try::from_ok`

error[E0277]: the trait bound `i32: std::ops::Try` is not satisfied
--> $DIR/try-block-bad-type.rs:19:26
--> $DIR/try-block-bad-type.rs:19:24
|
LL | let res: i32 = try { 5 };
| ^ the trait `std::ops::Try` is not implemented for `i32`
| ^^^^^ the trait `std::ops::Try` is not implemented for `i32`
|
= note: required by `std::ops::Try::from_ok`

Expand Down
0