Skip to content

Commit e26ff2f

Browse files
committed
Auto merge of rust-lang#135260 - matthiaskrgr:rollup-8irqs72, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#134228 (Exhaustively handle expressions in patterns) - rust-lang#135194 (triagebot: mark tidy changes with a more specific `A-tidy` label) - rust-lang#135222 (Ensure that we don't try to access fields on a non-struct pattern type) - rust-lang#135250 (A couple simple borrowck cleanups) - rust-lang#135252 (Fix release notes link) - rust-lang#135253 (Revert rust-lang#131365) Failed merges: - rust-lang#135195 (Make `lit_to_mir_constant` and `lit_to_const` infallible) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a580b5c + 6a093f7 commit e26ff2f

File tree

82 files changed

+759
-506
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+759
-506
lines changed

Diff for: RELEASES.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Libraries
3737
- [Move `<float>::copysign`, `<float>::abs`, `<float>::signum` to `core`](https://github.com/rust-lang/rust/pull/131304)
3838
- [Add `LowerExp` and `UpperExp` implementations to `NonZero`](https://github.com/rust-lang/rust/pull/131377)
3939
- [Implement `FromStr` for `CString` and `TryFrom<CString>` for `String`](https://github.com/rust-lang/rust/pull/130608)
40-
- [`std::os::darwin` has been made public](https://github.com/rust-lang/rust/pull/130635)
40+
- [`std::os::darwin` has been made public](https://github.com/rust-lang/rust/pull/123723)
4141

4242
<a id="1.84.0-Stabilized-APIs"></a>
4343

Diff for: compiler/rustc_ast/src/ast.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ impl Pat {
623623
PatKind::Wild
624624
| PatKind::Rest
625625
| PatKind::Never
626-
| PatKind::Lit(_)
626+
| PatKind::Expr(_)
627627
| PatKind::Range(..)
628628
| PatKind::Ident(..)
629629
| PatKind::Path(..)
@@ -801,8 +801,8 @@ pub enum PatKind {
801801
/// A reference pattern (e.g., `&mut (a, b)`).
802802
Ref(P<Pat>, Mutability),
803803

804-
/// A literal.
805-
Lit(P<Expr>),
804+
/// A literal, const block or path.
805+
Expr(P<Expr>),
806806

807807
/// A range pattern (e.g., `1...2`, `1..2`, `1..`, `..2`, `1..=2`, `..=2`).
808808
Range(Option<P<Expr>>, Option<P<Expr>>, Spanned<RangeEnd>),

Diff for: compiler/rustc_ast/src/mut_visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ pub fn walk_pat<T: MutVisitor>(vis: &mut T, pat: &mut P<Pat>) {
15121512
vis.visit_ident(ident);
15131513
visit_opt(sub, |sub| vis.visit_pat(sub));
15141514
}
1515-
PatKind::Lit(e) => vis.visit_expr(e),
1515+
PatKind::Expr(e) => vis.visit_expr(e),
15161516
PatKind::TupleStruct(qself, path, elems) => {
15171517
vis.visit_qself(qself);
15181518
vis.visit_path(path);

Diff for: compiler/rustc_ast/src/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) -> V::Res
680680
try_visit!(visitor.visit_ident(ident));
681681
visit_opt!(visitor, visit_pat, optional_subpattern);
682682
}
683-
PatKind::Lit(expression) => try_visit!(visitor.visit_expr(expression)),
683+
PatKind::Expr(expression) => try_visit!(visitor.visit_expr(expression)),
684684
PatKind::Range(lower_bound, upper_bound, _end) => {
685685
visit_opt!(visitor, visit_expr, lower_bound);
686686
visit_opt!(visitor, visit_expr, upper_bound);

Diff for: compiler/rustc_ast_lowering/src/expr.rs

+28-23
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
102102

103103
let kind = match &e.kind {
104104
ExprKind::Array(exprs) => hir::ExprKind::Array(self.lower_exprs(exprs)),
105-
ExprKind::ConstBlock(c) => {
106-
let c = self.with_new_scopes(c.value.span, |this| {
107-
let def_id = this.local_def_id(c.id);
108-
hir::ConstBlock {
109-
def_id,
110-
hir_id: this.lower_node_id(c.id),
111-
body: this.lower_const_body(c.value.span, Some(&c.value)),
112-
}
113-
});
114-
hir::ExprKind::ConstBlock(c)
115-
}
105+
ExprKind::ConstBlock(c) => hir::ExprKind::ConstBlock(self.lower_const_block(c)),
116106
ExprKind::Repeat(expr, count) => {
117107
let expr = self.lower_expr(expr);
118108
let count = self.lower_array_length_to_const_arg(count);
@@ -153,18 +143,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
153143
let ohs = self.lower_expr(ohs);
154144
hir::ExprKind::Unary(op, ohs)
155145
}
156-
ExprKind::Lit(token_lit) => {
157-
let lit_kind = match LitKind::from_token_lit(*token_lit) {
158-
Ok(lit_kind) => lit_kind,
159-
Err(err) => {
160-
let guar =
161-
report_lit_error(&self.tcx.sess.psess, err, *token_lit, e.span);
162-
LitKind::Err(guar)
163-
}
164-
};
165-
let lit = self.arena.alloc(respan(self.lower_span(e.span), lit_kind));
166-
hir::ExprKind::Lit(lit)
167-
}
146+
ExprKind::Lit(token_lit) => hir::ExprKind::Lit(self.lower_lit(token_lit, e.span)),
168147
ExprKind::IncludedBytes(bytes) => {
169148
let lit = self.arena.alloc(respan(
170149
self.lower_span(e.span),
@@ -403,6 +382,32 @@ impl<'hir> LoweringContext<'_, 'hir> {
403382
})
404383
}
405384

385+
pub(crate) fn lower_const_block(&mut self, c: &AnonConst) -> hir::ConstBlock {
386+
self.with_new_scopes(c.value.span, |this| {
387+
let def_id = this.local_def_id(c.id);
388+
hir::ConstBlock {
389+
def_id,
390+
hir_id: this.lower_node_id(c.id),
391+
body: this.lower_const_body(c.value.span, Some(&c.value)),
392+
}
393+
})
394+
}
395+
396+
pub(crate) fn lower_lit(
397+
&mut self,
398+
token_lit: &token::Lit,
399+
span: Span,
400+
) -> &'hir Spanned<LitKind> {
401+
let lit_kind = match LitKind::from_token_lit(*token_lit) {
402+
Ok(lit_kind) => lit_kind,
403+
Err(err) => {
404+
let guar = report_lit_error(&self.tcx.sess.psess, err, *token_lit, span);
405+
LitKind::Err(guar)
406+
}
407+
};
408+
self.arena.alloc(respan(self.lower_span(span), lit_kind))
409+
}
410+
406411
fn lower_unop(&mut self, u: UnOp) -> hir::UnOp {
407412
match u {
408413
UnOp::Deref => hir::UnOp::Deref,

Diff for: compiler/rustc_ast_lowering/src/index.rs

+8
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,14 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
209209
});
210210
}
211211

212+
fn visit_pat_expr(&mut self, expr: &'hir PatExpr<'hir>) {
213+
self.insert(expr.span, expr.hir_id, Node::PatExpr(expr));
214+
215+
self.with_parent(expr.hir_id, |this| {
216+
intravisit::walk_pat_expr(this, expr);
217+
});
218+
}
219+
212220
fn visit_pat_field(&mut self, field: &'hir PatField<'hir>) {
213221
self.insert(field.span, field.hir_id, Node::PatField(field));
214222
self.with_parent(field.hir_id, |this| {

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#![doc(rust_logo)]
3636
#![feature(assert_matches)]
3737
#![feature(box_patterns)]
38+
#![feature(if_let_guard)]
3839
#![feature(let_chains)]
3940
#![feature(rustdoc_internals)]
4041
#![warn(unreachable_pub)]

Diff for: compiler/rustc_ast_lowering/src/pat.rs

+48-15
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
use std::sync::Arc;
2+
13
use rustc_ast::ptr::P;
24
use rustc_ast::*;
35
use rustc_data_structures::stack::ensure_sufficient_stack;
46
use rustc_hir as hir;
57
use rustc_hir::def::Res;
6-
use rustc_span::source_map::Spanned;
8+
use rustc_middle::span_bug;
9+
use rustc_span::source_map::{Spanned, respan};
710
use rustc_span::{Ident, Span};
811

912
use super::errors::{
@@ -35,8 +38,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
3538
lower_sub,
3639
);
3740
}
38-
PatKind::Lit(e) => {
39-
break hir::PatKind::Lit(self.lower_expr_within_pat(e, false));
41+
PatKind::Expr(e) => {
42+
break hir::PatKind::Expr(self.lower_expr_within_pat(e, false));
4043
}
4144
PatKind::TupleStruct(qself, path, pats) => {
4245
let qpath = self.lower_qpath(
@@ -367,24 +370,54 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
367370
// }
368371
// m!(S);
369372
// ```
370-
fn lower_expr_within_pat(&mut self, expr: &Expr, allow_paths: bool) -> &'hir hir::Expr<'hir> {
371-
match &expr.kind {
372-
ExprKind::Lit(..)
373-
| ExprKind::ConstBlock(..)
374-
| ExprKind::IncludedBytes(..)
375-
| ExprKind::Err(_)
376-
| ExprKind::Dummy => {}
377-
ExprKind::Path(..) if allow_paths => {}
378-
ExprKind::Unary(UnOp::Neg, inner) if matches!(inner.kind, ExprKind::Lit(_)) => {}
373+
fn lower_expr_within_pat(
374+
&mut self,
375+
expr: &Expr,
376+
allow_paths: bool,
377+
) -> &'hir hir::PatExpr<'hir> {
378+
let err = |guar| hir::PatExprKind::Lit {
379+
lit: self.arena.alloc(respan(self.lower_span(expr.span), LitKind::Err(guar))),
380+
negated: false,
381+
};
382+
let kind = match &expr.kind {
383+
ExprKind::Lit(lit) => {
384+
hir::PatExprKind::Lit { lit: self.lower_lit(lit, expr.span), negated: false }
385+
}
386+
ExprKind::ConstBlock(c) => hir::PatExprKind::ConstBlock(self.lower_const_block(c)),
387+
ExprKind::IncludedBytes(bytes) => hir::PatExprKind::Lit {
388+
lit: self.arena.alloc(respan(
389+
self.lower_span(expr.span),
390+
LitKind::ByteStr(Arc::clone(bytes), StrStyle::Cooked),
391+
)),
392+
negated: false,
393+
},
394+
ExprKind::Err(guar) => err(*guar),
395+
ExprKind::Dummy => span_bug!(expr.span, "lowered ExprKind::Dummy"),
396+
ExprKind::Path(qself, path) if allow_paths => hir::PatExprKind::Path(self.lower_qpath(
397+
expr.id,
398+
qself,
399+
path,
400+
ParamMode::Optional,
401+
AllowReturnTypeNotation::No,
402+
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
403+
None,
404+
)),
405+
ExprKind::Unary(UnOp::Neg, inner) if let ExprKind::Lit(lit) = &inner.kind => {
406+
hir::PatExprKind::Lit { lit: self.lower_lit(lit, expr.span), negated: true }
407+
}
379408
_ => {
380409
let pattern_from_macro = expr.is_approximately_pattern();
381410
let guar = self.dcx().emit_err(ArbitraryExpressionInPattern {
382411
span: expr.span,
383412
pattern_from_macro_note: pattern_from_macro,
384413
});
385-
return self.arena.alloc(self.expr_err(expr.span, guar));
414+
err(guar)
386415
}
387-
}
388-
self.lower_expr(expr)
416+
};
417+
self.arena.alloc(hir::PatExpr {
418+
hir_id: self.lower_node_id(expr.id),
419+
span: expr.span,
420+
kind,
421+
})
389422
}
390423
}

Diff for: compiler/rustc_ast_pretty/src/pprust/state.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1701,7 +1701,7 @@ impl<'a> State<'a> {
17011701
self.print_pat(inner);
17021702
}
17031703
}
1704-
PatKind::Lit(e) => self.print_expr(e, FixupContext::default()),
1704+
PatKind::Expr(e) => self.print_expr(e, FixupContext::default()),
17051705
PatKind::Range(begin, end, Spanned { node: end_kind, .. }) => {
17061706
if let Some(e) = begin {
17071707
self.print_expr(e, FixupContext::default());

Diff for: compiler/rustc_borrowck/src/consumers.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ pub use super::dataflow::{BorrowIndex, Borrows, calculate_borrows_out_of_scope_a
1111
pub use super::place_ext::PlaceExt;
1212
pub use super::places_conflict::{PlaceConflictBias, places_conflict};
1313
pub use super::polonius::legacy::{
14-
AllFacts as PoloniusInput, LocationTable, PoloniusOutput, PoloniusRegionVid, RichLocation,
15-
RustcFacts,
14+
PoloniusFacts as PoloniusInput, PoloniusLocationTable, PoloniusOutput, PoloniusRegionVid,
15+
RichLocation, RustcFacts,
1616
};
1717
pub use super::region_infer::RegionInferenceContext;
1818

@@ -33,7 +33,7 @@ pub enum ConsumerOptions {
3333
/// without significant slowdowns.
3434
///
3535
/// Implies [`RegionInferenceContext`](ConsumerOptions::RegionInferenceContext),
36-
/// and additionally retrieve the [`LocationTable`] and [`PoloniusInput`] that
36+
/// and additionally retrieve the [`PoloniusLocationTable`] and [`PoloniusInput`] that
3737
/// would be given to Polonius. Critically, this does not run Polonius, which
3838
/// one may want to avoid due to performance issues on large bodies.
3939
PoloniusInputFacts,
@@ -71,7 +71,7 @@ pub struct BodyWithBorrowckFacts<'tcx> {
7171
/// The table that maps Polonius points to locations in the table.
7272
/// Populated when using [`ConsumerOptions::PoloniusInputFacts`]
7373
/// or [`ConsumerOptions::PoloniusOutputFacts`].
74-
pub location_table: Option<LocationTable>,
74+
pub location_table: Option<PoloniusLocationTable>,
7575
/// Polonius input facts.
7676
/// Populated when using [`ConsumerOptions::PoloniusInputFacts`]
7777
/// or [`ConsumerOptions::PoloniusOutputFacts`].

Diff for: compiler/rustc_borrowck/src/lib.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ use crate::diagnostics::{
6060
use crate::path_utils::*;
6161
use crate::place_ext::PlaceExt;
6262
use crate::places_conflict::{PlaceConflictBias, places_conflict};
63-
use crate::polonius::legacy::{LocationTable, PoloniusOutput};
63+
use crate::polonius::legacy::{PoloniusLocationTable, PoloniusOutput};
6464
use crate::prefixes::PrefixSet;
6565
use crate::region_infer::RegionInferenceContext;
6666
use crate::renumber::RegionCtxt;
@@ -179,7 +179,7 @@ fn do_mir_borrowck<'tcx>(
179179
infcx.register_predefined_opaques_for_next_solver(def);
180180
}
181181

182-
let location_table = LocationTable::new(body);
182+
let location_table = PoloniusLocationTable::new(body);
183183

184184
let move_data = MoveData::gather_moves(body, tcx, |_| true);
185185
let promoted_move_data = promoted
@@ -250,7 +250,8 @@ fn do_mir_borrowck<'tcx>(
250250
infcx: &infcx,
251251
body: promoted_body,
252252
move_data: &move_data,
253-
location_table: &location_table, // no need to create a real one for the promoted, it is not used
253+
// no need to create a real location table for the promoted, it is not used
254+
location_table: &location_table,
254255
movable_coroutine,
255256
fn_self_span_reported: Default::default(),
256257
locals_are_invalidated_at_exit,
@@ -516,7 +517,7 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
516517

517518
/// Map from MIR `Location` to `LocationIndex`; created
518519
/// when MIR borrowck begins.
519-
location_table: &'a LocationTable,
520+
location_table: &'a PoloniusLocationTable,
520521

521522
movable_coroutine: bool,
522523
/// This keeps track of whether local variables are free-ed when the function

0 commit comments

Comments
 (0)