mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
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 (⬆️ 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
This commit is contained in:
commit
a435b49e86
@ -1954,7 +1954,6 @@ impl<'a> State<'a> {
|
|||||||
self.word_space(":");
|
self.word_space(":");
|
||||||
}
|
}
|
||||||
self.head("loop");
|
self.head("loop");
|
||||||
self.s.space();
|
|
||||||
self.print_block_with_attrs(blk, attrs);
|
self.print_block_with_attrs(blk, attrs);
|
||||||
}
|
}
|
||||||
ast::ExprKind::Match(ref expr, ref arms) => {
|
ast::ExprKind::Match(ref expr, ref arms) => {
|
||||||
|
@ -1539,7 +1539,6 @@ impl<'a> State<'a> {
|
|||||||
self.word_space(":");
|
self.word_space(":");
|
||||||
}
|
}
|
||||||
self.head("loop");
|
self.head("loop");
|
||||||
self.s.space();
|
|
||||||
self.print_block(&blk);
|
self.print_block(&blk);
|
||||||
}
|
}
|
||||||
hir::ExprKind::Match(ref expr, arms, _) => {
|
hir::ExprKind::Match(ref expr, arms, _) => {
|
||||||
|
@ -675,7 +675,39 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
expr: &'tcx hir::Expr<'tcx>,
|
expr: &'tcx hir::Expr<'tcx>,
|
||||||
) -> Ty<'tcx> {
|
) -> Ty<'tcx> {
|
||||||
if self.ret_coercion.is_none() {
|
if self.ret_coercion.is_none() {
|
||||||
self.tcx.sess.emit_err(ReturnStmtOutsideOfFnBody { span: expr.span });
|
let mut err = ReturnStmtOutsideOfFnBody {
|
||||||
|
span: expr.span,
|
||||||
|
encl_body_span: None,
|
||||||
|
encl_fn_span: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let encl_item_id = self.tcx.hir().get_parent_item(expr.hir_id);
|
||||||
|
let encl_item = self.tcx.hir().expect_item(encl_item_id);
|
||||||
|
|
||||||
|
if let hir::ItemKind::Fn(..) = encl_item.kind {
|
||||||
|
// We are inside a function body, so reporting "return statement
|
||||||
|
// outside of function body" needs an explanation.
|
||||||
|
|
||||||
|
let encl_body_owner_id = self.tcx.hir().enclosing_body_owner(expr.hir_id);
|
||||||
|
|
||||||
|
// If this didn't hold, we would not have to report an error in
|
||||||
|
// the first place.
|
||||||
|
assert_ne!(encl_item_id, encl_body_owner_id);
|
||||||
|
|
||||||
|
let encl_body_id = self.tcx.hir().body_owned_by(encl_body_owner_id);
|
||||||
|
let encl_body = self.tcx.hir().body(encl_body_id);
|
||||||
|
|
||||||
|
err.encl_body_span = Some(encl_body.value.span);
|
||||||
|
err.encl_fn_span = Some(encl_item.span);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.tcx.sess.emit_err(err);
|
||||||
|
|
||||||
|
if let Some(e) = expr_opt {
|
||||||
|
// We still have to type-check `e` (issue #86188), but calling
|
||||||
|
// `check_return_expr` only works inside fn bodies.
|
||||||
|
self.check_expr(e);
|
||||||
|
}
|
||||||
} else if let Some(e) = expr_opt {
|
} else if let Some(e) = expr_opt {
|
||||||
if self.ret_coercion_span.get().is_none() {
|
if self.ret_coercion_span.get().is_none() {
|
||||||
self.ret_coercion_span.set(Some(e.span));
|
self.ret_coercion_span.set(Some(e.span));
|
||||||
|
@ -147,6 +147,10 @@ pub struct TypeofReservedKeywordUsed {
|
|||||||
pub struct ReturnStmtOutsideOfFnBody {
|
pub struct ReturnStmtOutsideOfFnBody {
|
||||||
#[message = "return statement outside of function body"]
|
#[message = "return statement outside of function body"]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
|
#[label = "the return is part of this body..."]
|
||||||
|
pub encl_body_span: Option<Span>,
|
||||||
|
#[label = "...not the enclosing function body"]
|
||||||
|
pub encl_fn_span: Option<Span>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(SessionDiagnostic)]
|
#[derive(SessionDiagnostic)]
|
||||||
|
@ -1072,6 +1072,12 @@ impl Step for RustAnalyzer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
|
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
|
||||||
|
// This prevents rust-analyzer from being built for "dist" or "install"
|
||||||
|
// on the stable/beta channels. It is a nightly-only tool and should
|
||||||
|
// not be included.
|
||||||
|
if !builder.build.unstable_features() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
let compiler = self.compiler;
|
let compiler = self.compiler;
|
||||||
let target = self.target;
|
let target = self.target;
|
||||||
assert!(builder.config.extended);
|
assert!(builder.config.extended);
|
||||||
@ -1171,6 +1177,12 @@ impl Step for Miri {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
|
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
|
||||||
|
// This prevents miri from being built for "dist" or "install"
|
||||||
|
// on the stable/beta channels. It is a nightly-only tool and should
|
||||||
|
// not be included.
|
||||||
|
if !builder.build.unstable_features() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
let compiler = self.compiler;
|
let compiler = self.compiler;
|
||||||
let target = self.target;
|
let target = self.target;
|
||||||
assert!(builder.config.extended);
|
assert!(builder.config.extended);
|
||||||
|
@ -39,7 +39,7 @@ fn syntax() {
|
|||||||
#![attr]
|
#![attr]
|
||||||
};
|
};
|
||||||
let _ =
|
let _ =
|
||||||
#[attr] loop {
|
#[attr] loop {
|
||||||
#![attr]
|
#![attr]
|
||||||
};
|
};
|
||||||
let _ =
|
let _ =
|
||||||
|
9
src/test/pretty/hir-pretty-loop.pp
Normal file
9
src/test/pretty/hir-pretty-loop.pp
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#[prelude_import]
|
||||||
|
use ::std::prelude::rust_2015::*;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate std;
|
||||||
|
// pretty-compare-only
|
||||||
|
// pretty-mode:hir
|
||||||
|
// pp-exact:hir-pretty-loop.pp
|
||||||
|
|
||||||
|
pub fn foo() { loop { break ; } }
|
9
src/test/pretty/hir-pretty-loop.rs
Normal file
9
src/test/pretty/hir-pretty-loop.rs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// pretty-compare-only
|
||||||
|
// pretty-mode:hir
|
||||||
|
// pp-exact:hir-pretty-loop.pp
|
||||||
|
|
||||||
|
pub fn foo(){
|
||||||
|
loop{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
@ -166,9 +166,8 @@ fn _11() {
|
|||||||
#[rustc_dummy] for _ in 0..0 {
|
#[rustc_dummy] for _ in 0..0 {
|
||||||
#![rustc_dummy]
|
#![rustc_dummy]
|
||||||
};
|
};
|
||||||
// FIXME: pp bug, two spaces after the loop
|
|
||||||
let _ =
|
let _ =
|
||||||
#[rustc_dummy] loop {
|
#[rustc_dummy] loop {
|
||||||
#![rustc_dummy]
|
#![rustc_dummy]
|
||||||
};
|
};
|
||||||
let _ =
|
let _ =
|
||||||
|
@ -1,13 +1,21 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
|
//~^ NOTE: not the enclosing function body
|
||||||
|
//~| NOTE: not the enclosing function body
|
||||||
|
//~| NOTE: not the enclosing function body
|
||||||
|
//~| NOTE: not the enclosing function body
|
||||||
|_: [_; return || {}] | {};
|
|_: [_; return || {}] | {};
|
||||||
//~^ ERROR return statement outside of function body
|
//~^ ERROR: return statement outside of function body [E0572]
|
||||||
|
//~| NOTE: the return is part of this body...
|
||||||
|
|
||||||
[(); return || {}];
|
[(); return || {}];
|
||||||
//~^ ERROR return statement outside of function body
|
//~^ ERROR: return statement outside of function body [E0572]
|
||||||
|
//~| NOTE: the return is part of this body...
|
||||||
|
|
||||||
[(); return |ice| {}];
|
[(); return |ice| {}];
|
||||||
//~^ ERROR return statement outside of function body
|
//~^ ERROR: return statement outside of function body [E0572]
|
||||||
|
//~| NOTE: the return is part of this body...
|
||||||
|
|
||||||
[(); return while let Some(n) = Some(0) {}];
|
[(); return while let Some(n) = Some(0) {}];
|
||||||
//~^ ERROR return statement outside of function body
|
//~^ ERROR: return statement outside of function body [E0572]
|
||||||
|
//~| NOTE: the return is part of this body...
|
||||||
}
|
}
|
||||||
|
@ -1,26 +1,62 @@
|
|||||||
error[E0572]: return statement outside of function body
|
error[E0572]: return statement outside of function body
|
||||||
--> $DIR/issue-51714.rs:2:14
|
--> $DIR/issue-51714.rs:6:14
|
||||||
|
|
|
|
||||||
LL | |_: [_; return || {}] | {};
|
LL | / fn main() {
|
||||||
| ^^^^^^^^^^^^
|
LL | |
|
||||||
|
LL | |
|
||||||
|
LL | |
|
||||||
|
LL | |
|
||||||
|
LL | | |_: [_; return || {}] | {};
|
||||||
|
| | ^^^^^^^^^^^^ the return is part of this body...
|
||||||
|
... |
|
||||||
|
LL | |
|
||||||
|
LL | | }
|
||||||
|
| |_- ...not the enclosing function body
|
||||||
|
|
||||||
error[E0572]: return statement outside of function body
|
error[E0572]: return statement outside of function body
|
||||||
--> $DIR/issue-51714.rs:5:10
|
--> $DIR/issue-51714.rs:10:10
|
||||||
|
|
|
|
||||||
LL | [(); return || {}];
|
LL | / fn main() {
|
||||||
| ^^^^^^^^^^^^
|
LL | |
|
||||||
|
LL | |
|
||||||
|
LL | |
|
||||||
|
... |
|
||||||
|
LL | | [(); return || {}];
|
||||||
|
| | ^^^^^^^^^^^^ the return is part of this body...
|
||||||
|
... |
|
||||||
|
LL | |
|
||||||
|
LL | | }
|
||||||
|
| |_- ...not the enclosing function body
|
||||||
|
|
||||||
error[E0572]: return statement outside of function body
|
error[E0572]: return statement outside of function body
|
||||||
--> $DIR/issue-51714.rs:8:10
|
--> $DIR/issue-51714.rs:14:10
|
||||||
|
|
|
|
||||||
LL | [(); return |ice| {}];
|
LL | / fn main() {
|
||||||
| ^^^^^^^^^^^^^^^
|
LL | |
|
||||||
|
LL | |
|
||||||
|
LL | |
|
||||||
|
... |
|
||||||
|
LL | | [(); return |ice| {}];
|
||||||
|
| | ^^^^^^^^^^^^^^^ the return is part of this body...
|
||||||
|
... |
|
||||||
|
LL | |
|
||||||
|
LL | | }
|
||||||
|
| |_- ...not the enclosing function body
|
||||||
|
|
||||||
error[E0572]: return statement outside of function body
|
error[E0572]: return statement outside of function body
|
||||||
--> $DIR/issue-51714.rs:11:10
|
--> $DIR/issue-51714.rs:18:10
|
||||||
|
|
|
|
||||||
LL | [(); return while let Some(n) = Some(0) {}];
|
LL | / fn main() {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
LL | |
|
||||||
|
LL | |
|
||||||
|
LL | |
|
||||||
|
... |
|
||||||
|
LL | | [(); return while let Some(n) = Some(0) {}];
|
||||||
|
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the return is part of this body...
|
||||||
|
LL | |
|
||||||
|
LL | |
|
||||||
|
LL | | }
|
||||||
|
| |_- ...not the enclosing function body
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
|
22
src/test/ui/return/issue-86188-return-not-in-fn-body.rs
Normal file
22
src/test/ui/return/issue-86188-return-not-in-fn-body.rs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Due to a compiler bug, if a return occurs outside of a function body
|
||||||
|
// (e.g. in an AnonConst body), the return value expression would not be
|
||||||
|
// type-checked, leading to an ICE. This test checks that the ICE no
|
||||||
|
// longer happens, and that an appropriate error message is issued that
|
||||||
|
// also explains why the return is considered "outside of a function body"
|
||||||
|
// if it seems to be inside one, as in the main function below.
|
||||||
|
|
||||||
|
const C: [(); 42] = {
|
||||||
|
[(); return || {
|
||||||
|
//~^ ERROR: return statement outside of function body [E0572]
|
||||||
|
let tx;
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
//~^ NOTE: ...not the enclosing function body
|
||||||
|
[(); return || {
|
||||||
|
//~^ ERROR: return statement outside of function body [E0572]
|
||||||
|
//~| NOTE: the return is part of this body...
|
||||||
|
let tx;
|
||||||
|
}];
|
||||||
|
}
|
28
src/test/ui/return/issue-86188-return-not-in-fn-body.stderr
Normal file
28
src/test/ui/return/issue-86188-return-not-in-fn-body.stderr
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
error[E0572]: return statement outside of function body
|
||||||
|
--> $DIR/issue-86188-return-not-in-fn-body.rs:9:10
|
||||||
|
|
|
||||||
|
LL | [(); return || {
|
||||||
|
| __________^
|
||||||
|
LL | |
|
||||||
|
LL | | let tx;
|
||||||
|
LL | | }]
|
||||||
|
| |_____^
|
||||||
|
|
||||||
|
error[E0572]: return statement outside of function body
|
||||||
|
--> $DIR/issue-86188-return-not-in-fn-body.rs:17:10
|
||||||
|
|
|
||||||
|
LL | / fn main() {
|
||||||
|
LL | |
|
||||||
|
LL | | [(); return || {
|
||||||
|
| |__________^
|
||||||
|
LL | ||
|
||||||
|
LL | ||
|
||||||
|
LL | || let tx;
|
||||||
|
LL | || }];
|
||||||
|
| ||_____^ the return is part of this body...
|
||||||
|
LL | | }
|
||||||
|
| |_- ...not the enclosing function body
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0572`.
|
@ -1,10 +1,19 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
|
//~^ NOTE: not the enclosing function body
|
||||||
|
//~| NOTE: not the enclosing function body
|
||||||
|
//~| NOTE: not the enclosing function body
|
||||||
[(); return match 0 { n => n }];
|
[(); return match 0 { n => n }];
|
||||||
//~^ ERROR: return statement outside of function body
|
//~^ ERROR: return statement outside of function body [E0572]
|
||||||
|
//~| NOTE: the return is part of this body...
|
||||||
|
|
||||||
[(); return match 0 { 0 => 0 }];
|
[(); return match 0 { 0 => 0 }];
|
||||||
//~^ ERROR: return statement outside of function body
|
//~^ ERROR: return statement outside of function body [E0572]
|
||||||
|
//~| NOTE: the return is part of this body...
|
||||||
|
|
||||||
[(); return match () { 'a' => 0, _ => 0 }];
|
[(); return match () { 'a' => 0, _ => 0 }];
|
||||||
//~^ ERROR: return statement outside of function body
|
//~^ ERROR: return statement outside of function body [E0572]
|
||||||
|
//~| NOTE: the return is part of this body...
|
||||||
|
//~| ERROR: mismatched types [E0308]
|
||||||
|
//~| NOTE: expected `()`, found `char`
|
||||||
|
//~| NOTE: this expression has type `()`
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,56 @@
|
|||||||
error[E0572]: return statement outside of function body
|
|
||||||
--> $DIR/return-match-array-const.rs:2:10
|
|
||||||
|
|
|
||||||
LL | [(); return match 0 { n => n }];
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error[E0572]: return statement outside of function body
|
error[E0572]: return statement outside of function body
|
||||||
--> $DIR/return-match-array-const.rs:5:10
|
--> $DIR/return-match-array-const.rs:5:10
|
||||||
|
|
|
|
||||||
LL | [(); return match 0 { 0 => 0 }];
|
LL | / fn main() {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
LL | |
|
||||||
|
LL | |
|
||||||
|
LL | |
|
||||||
|
LL | | [(); return match 0 { n => n }];
|
||||||
|
| | ^^^^^^^^^^^^^^^^^^^^^^^^^ the return is part of this body...
|
||||||
|
... |
|
||||||
|
LL | |
|
||||||
|
LL | | }
|
||||||
|
| |_- ...not the enclosing function body
|
||||||
|
|
||||||
error[E0572]: return statement outside of function body
|
error[E0572]: return statement outside of function body
|
||||||
--> $DIR/return-match-array-const.rs:8:10
|
--> $DIR/return-match-array-const.rs:9:10
|
||||||
|
|
|
||||||
|
LL | / fn main() {
|
||||||
|
LL | |
|
||||||
|
LL | |
|
||||||
|
LL | |
|
||||||
|
... |
|
||||||
|
LL | | [(); return match 0 { 0 => 0 }];
|
||||||
|
| | ^^^^^^^^^^^^^^^^^^^^^^^^^ the return is part of this body...
|
||||||
|
... |
|
||||||
|
LL | |
|
||||||
|
LL | | }
|
||||||
|
| |_- ...not the enclosing function body
|
||||||
|
|
||||||
|
error[E0572]: return statement outside of function body
|
||||||
|
--> $DIR/return-match-array-const.rs:13:10
|
||||||
|
|
|
||||||
|
LL | / fn main() {
|
||||||
|
LL | |
|
||||||
|
LL | |
|
||||||
|
LL | |
|
||||||
|
... |
|
||||||
|
LL | | [(); return match () { 'a' => 0, _ => 0 }];
|
||||||
|
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the return is part of this body...
|
||||||
|
... |
|
||||||
|
LL | |
|
||||||
|
LL | | }
|
||||||
|
| |_- ...not the enclosing function body
|
||||||
|
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/return-match-array-const.rs:13:28
|
||||||
|
|
|
|
||||||
LL | [(); return match () { 'a' => 0, _ => 0 }];
|
LL | [(); return match () { 'a' => 0, _ => 0 }];
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| -- ^^^ expected `()`, found `char`
|
||||||
|
| |
|
||||||
|
| this expression has type `()`
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0572`.
|
Some errors have detailed explanations: E0308, E0572.
|
||||||
|
For more information about an error, try `rustc --explain E0308`.
|
||||||
|
16
src/test/ui/type-alias-impl-trait/issue-65384.rs
Normal file
16
src/test/ui/type-alias-impl-trait/issue-65384.rs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#![feature(min_type_alias_impl_trait)]
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
trait MyTrait {}
|
||||||
|
|
||||||
|
impl MyTrait for () {}
|
||||||
|
|
||||||
|
type Bar = impl MyTrait;
|
||||||
|
|
||||||
|
impl MyTrait for Bar {}
|
||||||
|
//~^ ERROR: cannot implement trait on type alias impl trait
|
||||||
|
|
||||||
|
fn bazr() -> Bar { }
|
||||||
|
|
||||||
|
fn main() {}
|
14
src/test/ui/type-alias-impl-trait/issue-65384.stderr
Normal file
14
src/test/ui/type-alias-impl-trait/issue-65384.stderr
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
error: cannot implement trait on type alias impl trait
|
||||||
|
--> $DIR/issue-65384.rs:11:1
|
||||||
|
|
|
||||||
|
LL | impl MyTrait for Bar {}
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
note: type alias impl trait defined here
|
||||||
|
--> $DIR/issue-65384.rs:9:12
|
||||||
|
|
|
||||||
|
LL | type Bar = impl MyTrait;
|
||||||
|
| ^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
@ -1 +1 @@
|
|||||||
Subproject commit 13da28cc2bc1b59f7af817eca36927a71edb023c
|
Subproject commit 1fa82adfdca502a13f4dd952f9a50574870f5b7b
|
@ -4,6 +4,7 @@ allow-unauthenticated = [
|
|||||||
"D-*",
|
"D-*",
|
||||||
"requires-nightly",
|
"requires-nightly",
|
||||||
"regression-*",
|
"regression-*",
|
||||||
|
"perf-regression",
|
||||||
# I-* without I-nominated
|
# I-* without I-nominated
|
||||||
"I-*", "!I-nominated",
|
"I-*", "!I-nominated",
|
||||||
"AsyncAwait-OnDeck",
|
"AsyncAwait-OnDeck",
|
||||||
|
Loading…
Reference in New Issue
Block a user