Skip to content

Commit 8217251

Browse files
committed
Auto merge of #152875 - cuviper:beta-next, r=cuviper
[beta] backports - Consider captures to be used by closures that unwind #152103 - Fix feature gating for new `try bikeshed` expressions #152519 - reject inline const patterns pre-expansion #152548 - layout_of unexpected rigid alias delayed bug #152575 - resolve: Disable an assert that no longer holds #152711 r? cuviper
2 parents 172dc09 + 675afc4 commit 8217251

19 files changed

Lines changed: 210 additions & 61 deletions

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,15 +335,11 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
335335
fn visit_expr(&mut self, e: &'a ast::Expr) {
336336
match e.kind {
337337
ast::ExprKind::TryBlock(_, None) => {
338+
// `try { ... }` is old and is only gated post-expansion here.
338339
gate!(&self, try_blocks, e.span, "`try` expression is experimental");
339340
}
340341
ast::ExprKind::TryBlock(_, Some(_)) => {
341-
gate!(
342-
&self,
343-
try_blocks_heterogeneous,
344-
e.span,
345-
"`try bikeshed` expression is experimental"
346-
);
342+
// `try_blocks_heterogeneous` is new, and gated pre-expansion instead.
347343
}
348344
ast::ExprKind::Lit(token::Lit {
349345
kind: token::LitKind::Float | token::LitKind::Integer,
@@ -505,6 +501,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
505501
half_open_range_patterns_in_slices,
506502
"half-open range patterns in slices are unstable"
507503
);
504+
gate_all!(try_blocks_heterogeneous, "`try bikeshed` expression is experimental");
508505
gate_all!(yeet_expr, "`do yeet` expression is experimental");
509506
gate_all!(const_closures, "const closures are experimental");
510507
gate_all!(builtin_syntax, "`builtin #` syntax is unstable");

compiler/rustc_mir_transform/src/liveness.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,7 @@ impl<'tcx> Visitor<'tcx> for TransferFunction<'_, 'tcx> {
12861286
TerminatorKind::Return
12871287
| TerminatorKind::Yield { .. }
12881288
| TerminatorKind::Goto { target: START_BLOCK } // Inserted for the `FnMut` case.
1289+
| TerminatorKind::Call { target: None, .. } // unwinding could be caught
12891290
if self.capture_kind != CaptureKind::None =>
12901291
{
12911292
// All indirect captures have an effect on the environment, so we mark them as live.

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1521,7 +1521,7 @@ impl<'a> Parser<'a> {
15211521
},
15221522
)
15231523
} else if this.check_inline_const(0) {
1524-
this.parse_const_block(lo)
1524+
this.parse_const_block(lo, false)
15251525
} else if this.may_recover() && this.is_do_catch_block() {
15261526
this.recover_do_catch()
15271527
} else if this.is_try_block() {

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ impl<'a> Parser<'a> {
13151315
}
13161316

13171317
/// Parses inline const expressions.
1318-
fn parse_const_block(&mut self, span: Span) -> PResult<'a, Box<Expr>> {
1318+
fn parse_const_block(&mut self, span: Span, pat: bool) -> PResult<'a, Box<Expr>> {
13191319
self.expect_keyword(exp!(Const))?;
13201320
let (attrs, blk) = self.parse_inner_attrs_and_block(None)?;
13211321
let anon_const = AnonConst {
@@ -1324,7 +1324,18 @@ impl<'a> Parser<'a> {
13241324
mgca_disambiguation: MgcaDisambiguation::AnonConst,
13251325
};
13261326
let blk_span = anon_const.value.span;
1327-
let kind = ExprKind::ConstBlock(anon_const);
1327+
let kind = if pat {
1328+
let guar = self
1329+
.dcx()
1330+
.struct_span_err(blk_span, "const blocks cannot be used as patterns")
1331+
.with_help(
1332+
"use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead",
1333+
)
1334+
.emit();
1335+
ExprKind::Err(guar)
1336+
} else {
1337+
ExprKind::ConstBlock(anon_const)
1338+
};
13281339
Ok(self.mk_expr_with_attrs(span.to(blk_span), kind, attrs))
13291340
}
13301341

compiler/rustc_parse/src/parser/pat.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -785,10 +785,8 @@ impl<'a> Parser<'a> {
785785
} else if self.eat_keyword(exp!(Box)) {
786786
self.parse_pat_box()?
787787
} else if self.check_inline_const(0) {
788-
// Parse `const pat`.
789-
// NOTE: This will always error later during AST lowering because
790-
// inline const cannot be used as patterns.
791-
let const_expr = self.parse_const_block(lo.to(self.token.span))?;
788+
// Parse `const pat`
789+
let const_expr = self.parse_const_block(lo.to(self.token.span), true)?;
792790

793791
if let Some(re) = self.parse_range_end() {
794792
self.parse_pat_range_begin_with(const_expr, re)?
@@ -1283,7 +1281,7 @@ impl<'a> Parser<'a> {
12831281
.then_some(self.prev_token.span);
12841282

12851283
let bound = if self.check_inline_const(0) {
1286-
self.parse_const_block(self.token.span)
1284+
self.parse_const_block(self.token.span, true)
12871285
} else if self.check_path() {
12881286
let lo = self.token.span;
12891287
let (qself, path) = if self.eat_lt() {

compiler/rustc_resolve/src/imports.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
366366
// - A glob decl is overwritten by its clone after setting ambiguity in it.
367367
// FIXME: avoid this by removing `warn_ambiguity`, or by triggering glob re-fetch
368368
// with the same decl in some way.
369+
// - A glob decl is overwritten by a glob decl with larger visibility.
370+
// FIXME: avoid this by updating this visibility in place.
369371
// - A glob decl is overwritten by a glob decl re-fetching an
370372
// overwritten decl from other module (the recursive case).
371373
// Here we are detecting all such re-fetches and overwrite old decls
@@ -379,7 +381,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
379381
// FIXME: reenable the asserts when `warn_ambiguity` is removed (#149195).
380382
// assert_ne!(old_deep_decl, deep_decl);
381383
// assert!(old_deep_decl.is_glob_import());
382-
assert!(!deep_decl.is_glob_import());
384+
// FIXME: reenable the assert when visibility is updated in place.
385+
// assert!(!deep_decl.is_glob_import());
383386
if old_glob_decl.ambiguity.get().is_some() && glob_decl.ambiguity.get().is_none() {
384387
// Do not lose glob ambiguities when re-fetching the glob.
385388
glob_decl.ambiguity.set_unchecked(old_glob_decl.ambiguity.get());

compiler/rustc_ty_utils/src/layout.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,9 @@ fn layout_of_uncached<'tcx>(
777777
let err = if ty.has_param() || !cx.typing_env.param_env.caller_bounds().is_empty() {
778778
LayoutError::TooGeneric(ty)
779779
} else {
780-
unreachable!("invalid rigid alias in layout_of after normalization: {ty:?}");
780+
LayoutError::ReferencesError(cx.tcx().dcx().delayed_bug(format!(
781+
"unexpected rigid alias in layout_of after normalization: {ty:?}"
782+
)))
781783
};
782784
return Err(error(cx, err));
783785
}

tests/ui/feature-gates/feature-gate-try_blocks_heterogeneous.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,11 @@ pub fn main() {
66
x
77
};
88
assert_eq!(try_result, Some(5));
9+
10+
// The heterogenous form is new, so is gated even under a `cfg(false)`.
11+
// See <https://github.com/rust-lang/rust/issues/152501>
12+
13+
#[cfg(false)]
14+
try bikeshed () {}
15+
//~^ error `try bikeshed` expression is experimental
916
}

tests/ui/feature-gates/feature-gate-try_blocks_heterogeneous.stderr

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ LL | | };
1212
= help: add `#![feature(try_blocks_heterogeneous)]` to the crate attributes to enable
1313
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1414

15-
error: aborting due to 1 previous error
15+
error[E0658]: `try bikeshed` expression is experimental
16+
--> $DIR/feature-gate-try_blocks_heterogeneous.rs:14:5
17+
|
18+
LL | try bikeshed () {}
19+
| ^^^^^^^^^^^^^^^^^^
20+
|
21+
= note: see issue #149488 <https://github.com/rust-lang/rust/issues/149488> for more information
22+
= help: add `#![feature(try_blocks_heterogeneous)]` to the crate attributes to enable
23+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
24+
25+
error: aborting due to 2 previous errors
1626

1727
For more information about this error, try `rustc --explain E0658`.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Regression test for issue #152606.
2+
3+
//@ check-pass
4+
5+
mod outer {
6+
mod inner {
7+
use super::*; // should go before the ambiguous glob imports
8+
}
9+
10+
use crate::*;
11+
pub use crate::*;
12+
}
13+
14+
fn main() {}

0 commit comments

Comments
 (0)