Skip to content

Commit a435b49

Browse files
committed
Auto merge of #86690 - JohnTitor:rollup-4ukk4yw, r=JohnTitor
Rollup of 6 pull requests Successful merges: - #86206 (Fix type checking of return expressions outside of function bodies) - #86358 (fix pretty print for `loop`) - #86568 (Don't dist miri or rust-analyzer on stable or beta.) - #86683 (:arrow_up: rust-analyzer) - #86687 (Allow anyone to set `perf-regression` label) - #86688 (Add a regression test for issue-65384) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 17ea490 + c5055b7 commit a435b49

File tree

19 files changed

+268
-36
lines changed

19 files changed

+268
-36
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1954,7 +1954,6 @@ impl<'a> State<'a> {
19541954
self.word_space(":");
19551955
}
19561956
self.head("loop");
1957-
self.s.space();
19581957
self.print_block_with_attrs(blk, attrs);
19591958
}
19601959
ast::ExprKind::Match(ref expr, ref arms) => {

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1539,7 +1539,6 @@ impl<'a> State<'a> {
15391539
self.word_space(":");
15401540
}
15411541
self.head("loop");
1542-
self.s.space();
15431542
self.print_block(&blk);
15441543
}
15451544
hir::ExprKind::Match(ref expr, arms, _) => {

compiler/rustc_typeck/src/check/expr.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,39 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
675675
expr: &'tcx hir::Expr<'tcx>,
676676
) -> Ty<'tcx> {
677677
if self.ret_coercion.is_none() {
678-
self.tcx.sess.emit_err(ReturnStmtOutsideOfFnBody { span: expr.span });
678+
let mut err = ReturnStmtOutsideOfFnBody {
679+
span: expr.span,
680+
encl_body_span: None,
681+
encl_fn_span: None,
682+
};
683+
684+
let encl_item_id = self.tcx.hir().get_parent_item(expr.hir_id);
685+
let encl_item = self.tcx.hir().expect_item(encl_item_id);
686+
687+
if let hir::ItemKind::Fn(..) = encl_item.kind {
688+
// We are inside a function body, so reporting "return statement
689+
// outside of function body" needs an explanation.
690+
691+
let encl_body_owner_id = self.tcx.hir().enclosing_body_owner(expr.hir_id);
692+
693+
// If this didn't hold, we would not have to report an error in
694+
// the first place.
695+
assert_ne!(encl_item_id, encl_body_owner_id);
696+
697+
let encl_body_id = self.tcx.hir().body_owned_by(encl_body_owner_id);
698+
let encl_body = self.tcx.hir().body(encl_body_id);
699+
700+
err.encl_body_span = Some(encl_body.value.span);
701+
err.encl_fn_span = Some(encl_item.span);
702+
}
703+
704+
self.tcx.sess.emit_err(err);
705+
706+
if let Some(e) = expr_opt {
707+
// We still have to type-check `e` (issue #86188), but calling
708+
// `check_return_expr` only works inside fn bodies.
709+
self.check_expr(e);
710+
}
679711
} else if let Some(e) = expr_opt {
680712
if self.ret_coercion_span.get().is_none() {
681713
self.ret_coercion_span.set(Some(e.span));

compiler/rustc_typeck/src/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ pub struct TypeofReservedKeywordUsed {
147147
pub struct ReturnStmtOutsideOfFnBody {
148148
#[message = "return statement outside of function body"]
149149
pub span: Span,
150+
#[label = "the return is part of this body..."]
151+
pub encl_body_span: Option<Span>,
152+
#[label = "...not the enclosing function body"]
153+
pub encl_fn_span: Option<Span>,
150154
}
151155

152156
#[derive(SessionDiagnostic)]

src/bootstrap/dist.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,12 @@ impl Step for RustAnalyzer {
10721072
}
10731073

10741074
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1075+
// This prevents rust-analyzer from being built for "dist" or "install"
1076+
// on the stable/beta channels. It is a nightly-only tool and should
1077+
// not be included.
1078+
if !builder.build.unstable_features() {
1079+
return None;
1080+
}
10751081
let compiler = self.compiler;
10761082
let target = self.target;
10771083
assert!(builder.config.extended);
@@ -1171,6 +1177,12 @@ impl Step for Miri {
11711177
}
11721178

11731179
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1180+
// This prevents miri from being built for "dist" or "install"
1181+
// on the stable/beta channels. It is a nightly-only tool and should
1182+
// not be included.
1183+
if !builder.build.unstable_features() {
1184+
return None;
1185+
}
11741186
let compiler = self.compiler;
11751187
let target = self.target;
11761188
assert!(builder.config.extended);

src/test/pretty/ast-stmt-expr-attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn syntax() {
3939
#![attr]
4040
};
4141
let _ =
42-
#[attr] loop {
42+
#[attr] loop {
4343
#![attr]
4444
};
4545
let _ =

src/test/pretty/hir-pretty-loop.pp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#[prelude_import]
2+
use ::std::prelude::rust_2015::*;
3+
#[macro_use]
4+
extern crate std;
5+
// pretty-compare-only
6+
// pretty-mode:hir
7+
// pp-exact:hir-pretty-loop.pp
8+
9+
pub fn foo() { loop { break ; } }

src/test/pretty/hir-pretty-loop.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// pretty-compare-only
2+
// pretty-mode:hir
3+
// pp-exact:hir-pretty-loop.pp
4+
5+
pub fn foo(){
6+
loop{
7+
break;
8+
}
9+
}

src/test/pretty/stmt_expr_attributes.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,8 @@ fn _11() {
166166
#[rustc_dummy] for _ in 0..0 {
167167
#![rustc_dummy]
168168
};
169-
// FIXME: pp bug, two spaces after the loop
170169
let _ =
171-
#[rustc_dummy] loop {
170+
#[rustc_dummy] loop {
172171
#![rustc_dummy]
173172
};
174173
let _ =

src/test/ui/issues/issue-51714.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
fn main() {
2+
//~^ NOTE: not the enclosing function body
3+
//~| NOTE: not the enclosing function body
4+
//~| NOTE: not the enclosing function body
5+
//~| NOTE: not the enclosing function body
26
|_: [_; return || {}] | {};
3-
//~^ ERROR return statement outside of function body
7+
//~^ ERROR: return statement outside of function body [E0572]
8+
//~| NOTE: the return is part of this body...
49

510
[(); return || {}];
6-
//~^ ERROR return statement outside of function body
11+
//~^ ERROR: return statement outside of function body [E0572]
12+
//~| NOTE: the return is part of this body...
713

814
[(); return |ice| {}];
9-
//~^ ERROR return statement outside of function body
15+
//~^ ERROR: return statement outside of function body [E0572]
16+
//~| NOTE: the return is part of this body...
1017

1118
[(); return while let Some(n) = Some(0) {}];
12-
//~^ ERROR return statement outside of function body
19+
//~^ ERROR: return statement outside of function body [E0572]
20+
//~| NOTE: the return is part of this body...
1321
}

0 commit comments

Comments
 (0)