Skip to content

Commit b8e1d7e

Browse files
committed
Auto merge of rust-lang#3706 - rust-lang:rustup-2024-06-24, r=oli-obk
Automatic Rustup
2 parents aded2be + c660016 commit b8e1d7e

File tree

433 files changed

+10901
-5557
lines changed

Some content is hidden

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

433 files changed

+10901
-5557
lines changed

Cargo.lock

Lines changed: 58 additions & 128 deletions
Large diffs are not rendered by default.

compiler/rustc_ast/src/token.rs

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
pub use BinOpToken::*;
22
pub use LitKind::*;
33
pub use Nonterminal::*;
4+
pub use NtExprKind::*;
5+
pub use NtPatKind::*;
46
pub use TokenKind::*;
57

68
use crate::ast;
@@ -871,6 +873,27 @@ impl PartialEq<TokenKind> for Token {
871873
}
872874
}
873875

876+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Encodable, Decodable)]
877+
pub enum NtPatKind {
878+
// Matches or-patterns. Was written using `pat` in edition 2021 or later.
879+
PatWithOr,
880+
// Doesn't match or-patterns.
881+
// - `inferred`: was written using `pat` in edition 2015 or 2018.
882+
// - `!inferred`: was written using `pat_param`.
883+
PatParam { inferred: bool },
884+
}
885+
886+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Encodable, Decodable)]
887+
pub enum NtExprKind {
888+
// Matches expressions using the post-edition 2024. Was written using
889+
// `expr` in edition 2024 or later.
890+
Expr,
891+
// Matches expressions using the pre-edition 2024 rules.
892+
// - `inferred`: was written using `expr` in edition 2021 or earlier.
893+
// - `!inferred`: was written using `expr_2021`.
894+
Expr2021 { inferred: bool },
895+
}
896+
874897
#[derive(Clone, Encodable, Decodable)]
875898
/// For interpolation during macro expansion.
876899
pub enum Nonterminal {
@@ -892,19 +915,8 @@ pub enum NonterminalKind {
892915
Item,
893916
Block,
894917
Stmt,
895-
PatParam {
896-
/// Keep track of whether the user used `:pat_param` or `:pat` and we inferred it from the
897-
/// edition of the span. This is used for diagnostics.
898-
inferred: bool,
899-
},
900-
PatWithOr,
901-
Expr,
902-
/// Matches an expression using the rules from edition 2021 and earlier.
903-
Expr2021 {
904-
/// Keep track of whether the user used `:expr` or `:expr_2021` and we inferred it from the
905-
/// edition of the span. This is used for diagnostics AND feature gating.
906-
inferred: bool,
907-
},
918+
Pat(NtPatKind),
919+
Expr(NtExprKind),
908920
Ty,
909921
Ident,
910922
Lifetime,
@@ -926,20 +938,22 @@ impl NonterminalKind {
926938
sym::item => NonterminalKind::Item,
927939
sym::block => NonterminalKind::Block,
928940
sym::stmt => NonterminalKind::Stmt,
929-
sym::pat => match edition() {
930-
Edition::Edition2015 | Edition::Edition2018 => {
931-
NonterminalKind::PatParam { inferred: true }
941+
sym::pat => {
942+
if edition().at_least_rust_2021() {
943+
NonterminalKind::Pat(PatWithOr)
944+
} else {
945+
NonterminalKind::Pat(PatParam { inferred: true })
932946
}
933-
Edition::Edition2021 | Edition::Edition2024 => NonterminalKind::PatWithOr,
934-
},
935-
sym::pat_param => NonterminalKind::PatParam { inferred: false },
936-
sym::expr => match edition() {
937-
Edition::Edition2015 | Edition::Edition2018 | Edition::Edition2021 => {
938-
NonterminalKind::Expr2021 { inferred: true }
947+
}
948+
sym::pat_param => NonterminalKind::Pat(PatParam { inferred: false }),
949+
sym::expr => {
950+
if edition().at_least_rust_2024() {
951+
NonterminalKind::Expr(Expr)
952+
} else {
953+
NonterminalKind::Expr(Expr2021 { inferred: true })
939954
}
940-
Edition::Edition2024 => NonterminalKind::Expr,
941-
},
942-
sym::expr_2021 => NonterminalKind::Expr2021 { inferred: false },
955+
}
956+
sym::expr_2021 => NonterminalKind::Expr(Expr2021 { inferred: false }),
943957
sym::ty => NonterminalKind::Ty,
944958
sym::ident => NonterminalKind::Ident,
945959
sym::lifetime => NonterminalKind::Lifetime,
@@ -951,15 +965,16 @@ impl NonterminalKind {
951965
_ => return None,
952966
})
953967
}
968+
954969
fn symbol(self) -> Symbol {
955970
match self {
956971
NonterminalKind::Item => sym::item,
957972
NonterminalKind::Block => sym::block,
958973
NonterminalKind::Stmt => sym::stmt,
959-
NonterminalKind::PatParam { inferred: false } => sym::pat_param,
960-
NonterminalKind::PatParam { inferred: true } | NonterminalKind::PatWithOr => sym::pat,
961-
NonterminalKind::Expr | NonterminalKind::Expr2021 { inferred: true } => sym::expr,
962-
NonterminalKind::Expr2021 { inferred: false } => sym::expr_2021,
974+
NonterminalKind::Pat(PatParam { inferred: true } | PatWithOr) => sym::pat,
975+
NonterminalKind::Pat(PatParam { inferred: false }) => sym::pat_param,
976+
NonterminalKind::Expr(Expr2021 { inferred: true } | Expr) => sym::expr,
977+
NonterminalKind::Expr(Expr2021 { inferred: false }) => sym::expr_2021,
963978
NonterminalKind::Ty => sym::ty,
964979
NonterminalKind::Ident => sym::ident,
965980
NonterminalKind::Lifetime => sym::lifetime,

compiler/rustc_ast_passes/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ ast_passes_auto_super_lifetime = auto traits cannot have super traits or lifetim
2828
.label = {ast_passes_auto_super_lifetime}
2929
.suggestion = remove the super traits or lifetime bounds
3030
31-
ast_passes_bad_c_variadic = only foreign or `unsafe extern "C"` functions may be C-variadic
31+
ast_passes_bad_c_variadic = only foreign, `unsafe extern "C"`, or `unsafe extern "C-unwind"` functions may have a C-variadic arg
3232
3333
ast_passes_bare_fn_invalid_safety = function pointers cannot be declared with `safe` safety qualifier
3434
.suggestion = remove safe from this item

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ impl<'a> AstValidator<'a> {
637637
(Some(FnCtxt::Foreign), _) => return,
638638
(Some(FnCtxt::Free), Some(header)) => match header.ext {
639639
Extern::Explicit(StrLit { symbol_unescaped: sym::C, .. }, _)
640+
| Extern::Explicit(StrLit { symbol_unescaped: sym::C_dash_unwind, .. }, _)
640641
| Extern::Implicit(_)
641642
if matches!(header.safety, Safety::Unsafe(_)) =>
642643
{
@@ -898,7 +899,7 @@ fn validate_generic_param_order(dcx: DiagCtxtHandle<'_>, generics: &[GenericPara
898899

899900
impl<'a> Visitor<'a> for AstValidator<'a> {
900901
fn visit_attribute(&mut self, attr: &Attribute) {
901-
validate_attr::check_attr(&self.session.psess, attr);
902+
validate_attr::check_attr(&self.features, &self.session.psess, attr);
902903
}
903904

904905
fn visit_ty(&mut self, ty: &'a Ty) {

compiler/rustc_borrowck/src/borrow_set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'tcx> BorrowSet<'tcx> {
126126
) -> Self {
127127
let mut visitor = GatherBorrows {
128128
tcx,
129-
body: body,
129+
body,
130130
location_map: Default::default(),
131131
activation_map: Default::default(),
132132
local_map: Default::default(),

compiler/rustc_borrowck/src/borrowck_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
213213
via(msg_old),
214214
);
215215

216-
if msg_new == "" {
216+
if msg_new.is_empty() {
217217
// If `msg_new` is empty, then this isn't a borrow of a union field.
218218
err.span_label(span, format!("{kind_new} borrow occurs here"));
219219
err.span_label(old_span, format!("{kind_old} borrow occurs here"));

compiler/rustc_borrowck/src/dataflow.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ impl<'mir, 'tcx> ResultsVisitable<'tcx> for BorrowckResults<'mir, 'tcx> {
4343
}
4444

4545
fn reset_to_block_entry(&self, state: &mut Self::FlowState, block: BasicBlock) {
46-
state.borrows.clone_from(&self.borrows.entry_set_for_block(block));
47-
state.uninits.clone_from(&self.uninits.entry_set_for_block(block));
48-
state.ever_inits.clone_from(&self.ever_inits.entry_set_for_block(block));
46+
state.borrows.clone_from(self.borrows.entry_set_for_block(block));
47+
state.uninits.clone_from(self.uninits.entry_set_for_block(block));
48+
state.ever_inits.clone_from(self.ever_inits.entry_set_for_block(block));
4949
}
5050

5151
fn reconstruct_before_statement_effect(

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
895895
for alias_ty in alias_tys {
896896
if alias_ty.span.desugaring_kind().is_some() {
897897
// Skip `async` desugaring `impl Future`.
898-
()
899898
}
900899
if let TyKind::TraitObject(_, lt, _) = alias_ty.kind {
901900
if lt.ident.name == kw::Empty {

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
519519
}
520520

521521
// Otherwise, let's descend into the referent types.
522-
search_stack.push((*referent_ty, &referent_hir_ty.ty));
522+
search_stack.push((*referent_ty, referent_hir_ty.ty));
523523
}
524524

525525
// Match up something like `Foo<'1>`
@@ -558,7 +558,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
558558
}
559559

560560
(ty::RawPtr(mut_ty, _), hir::TyKind::Ptr(mut_hir_ty)) => {
561-
search_stack.push((*mut_ty, &mut_hir_ty.ty));
561+
search_stack.push((*mut_ty, mut_hir_ty.ty));
562562
}
563563

564564
_ => {
@@ -652,7 +652,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
652652
let upvar_index = self.regioncx.get_upvar_index_for_region(self.infcx.tcx, fr)?;
653653
let (upvar_name, upvar_span) = self.regioncx.get_upvar_name_and_span_for_region(
654654
self.infcx.tcx,
655-
&self.upvars,
655+
self.upvars,
656656
upvar_index,
657657
);
658658
let region_name = self.synthesize_region_name();
@@ -717,7 +717,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
717717
.output;
718718
span = output.span();
719719
if let hir::FnRetTy::Return(ret) = output {
720-
hir_ty = Some(self.get_future_inner_return_ty(*ret));
720+
hir_ty = Some(self.get_future_inner_return_ty(ret));
721721
}
722722
" of async function"
723723
}
@@ -958,7 +958,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
958958
{
959959
let (upvar_name, upvar_span) = self.regioncx.get_upvar_name_and_span_for_region(
960960
self.infcx.tcx,
961-
&self.upvars,
961+
self.upvars,
962962
upvar_index,
963963
);
964964
let region_name = self.synthesize_region_name();

compiler/rustc_borrowck/src/nll.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
114114
move_data,
115115
elements,
116116
upvars,
117-
polonius_input,
118117
);
119118

120119
// Create the region inference context, taking ownership of the

compiler/rustc_borrowck/src/polonius/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ pub(crate) fn emit_facts<'tcx>(
4343
emit_universal_region_facts(
4444
all_facts,
4545
borrow_set,
46-
&universal_regions,
47-
&universal_region_relations,
46+
universal_regions,
47+
universal_region_relations,
4848
);
4949
emit_cfg_and_loan_kills_facts(all_facts, tcx, location_table, body, borrow_set);
5050
emit_loan_invalidations_facts(all_facts, tcx, location_table, body, borrow_set);

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ fn sccs_info<'tcx>(infcx: &BorrowckInferCtxt<'tcx>, sccs: &ConstraintSccs) {
344344

345345
for (reg_var_idx, scc_idx) in sccs.scc_indices().iter().enumerate() {
346346
let reg_var = ty::RegionVid::from_usize(reg_var_idx);
347-
let origin = var_to_origin.get(&reg_var).unwrap_or_else(|| &RegionCtxt::Unknown);
347+
let origin = var_to_origin.get(&reg_var).unwrap_or(&RegionCtxt::Unknown);
348348
components[scc_idx.as_usize()].insert((reg_var, *origin));
349349
}
350350

@@ -2216,7 +2216,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
22162216
// #114907 where this happens via liveness and dropck outlives results.
22172217
// Therefore, we return a default value in case that happens, which should at worst emit a
22182218
// suboptimal error, instead of the ICE.
2219-
self.universe_causes.get(&universe).cloned().unwrap_or_else(|| UniverseInfo::other())
2219+
self.universe_causes.get(&universe).cloned().unwrap_or_else(UniverseInfo::other)
22202220
}
22212221

22222222
/// Tries to find the terminator of the loop in which the region 'r' resides.

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,7 @@ fn check_opaque_type_parameter_valid<'tcx>(
418418
let opaque_param = opaque_generics.param_at(i, tcx);
419419
let kind = opaque_param.kind.descr();
420420

421-
if let Err(guar) = opaque_env.param_is_error(i) {
422-
return Err(guar);
423-
}
421+
opaque_env.param_is_error(i)?;
424422

425423
return Err(tcx.dcx().emit_err(NonGenericOpaqueTypeParam {
426424
ty: arg,

compiler/rustc_borrowck/src/type_check/liveness/mod.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ use rustc_mir_dataflow::ResultsCursor;
1212
use std::rc::Rc;
1313

1414
use crate::{
15-
constraints::OutlivesConstraintSet,
16-
facts::{AllFacts, AllFactsExt},
17-
region_infer::values::LivenessValues,
15+
constraints::OutlivesConstraintSet, region_infer::values::LivenessValues,
1816
universal_regions::UniversalRegions,
1917
};
2018

@@ -38,7 +36,6 @@ pub(super) fn generate<'mir, 'tcx>(
3836
elements: &Rc<DenseLocationMap>,
3937
flow_inits: &mut ResultsCursor<'mir, 'tcx, MaybeInitializedPlaces<'mir, 'tcx>>,
4038
move_data: &MoveData<'tcx>,
41-
use_polonius: bool,
4239
) {
4340
debug!("liveness::generate");
4441

@@ -49,11 +46,8 @@ pub(super) fn generate<'mir, 'tcx>(
4946
);
5047
let (relevant_live_locals, boring_locals) =
5148
compute_relevant_live_locals(typeck.tcx(), &free_regions, body);
52-
let facts_enabled = use_polonius || AllFacts::enabled(typeck.tcx());
5349

54-
if facts_enabled {
55-
polonius::populate_access_facts(typeck, body, move_data);
56-
};
50+
polonius::populate_access_facts(typeck, body, move_data);
5751

5852
trace::trace(
5953
typeck,

compiler/rustc_borrowck/src/type_check/liveness/polonius.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ pub(super) fn populate_access_facts<'a, 'tcx>(
8787
body: &Body<'tcx>,
8888
move_data: &MoveData<'tcx>,
8989
) {
90-
debug!("populate_access_facts()");
91-
let location_table = typeck.borrowck_context.location_table;
92-
9390
if let Some(facts) = typeck.borrowck_context.all_facts.as_mut() {
91+
debug!("populate_access_facts()");
92+
let location_table = typeck.borrowck_context.location_table;
93+
9494
let mut extractor = UseFactsExtractor {
9595
var_defined_at: &mut facts.var_defined_at,
9696
var_used_at: &mut facts.var_used_at,

compiler/rustc_borrowck/src/type_check/liveness/trace.rs

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -217,35 +217,52 @@ impl<'me, 'typeck, 'flow, 'tcx> LivenessResults<'me, 'typeck, 'flow, 'tcx> {
217217
/// Add facts for all locals with free regions, since regions may outlive
218218
/// the function body only at certain nodes in the CFG.
219219
fn add_extra_drop_facts(&mut self, relevant_live_locals: &[Local]) -> Option<()> {
220-
let drop_used = self
221-
.cx
222-
.typeck
223-
.borrowck_context
224-
.all_facts
225-
.as_ref()
226-
.map(|facts| facts.var_dropped_at.clone())?;
220+
// This collect is more necessary than immediately apparent
221+
// because these facts go into `add_drop_live_facts_for()`,
222+
// which also writes to `all_facts`, and so this is genuinely
223+
// a simulatneous overlapping mutable borrow.
224+
// FIXME for future hackers: investigate whether this is
225+
// actually necessary; these facts come from Polonius
226+
// and probably maybe plausibly does not need to go back in.
227+
// It may be necessary to just pick out the parts of
228+
// `add_drop_live_facts_for()` that make sense.
229+
let facts_to_add: Vec<_> = {
230+
let drop_used = &self.cx.typeck.borrowck_context.all_facts.as_ref()?.var_dropped_at;
231+
232+
let relevant_live_locals: FxIndexSet<_> =
233+
relevant_live_locals.iter().copied().collect();
234+
235+
drop_used
236+
.iter()
237+
.filter_map(|(local, location_index)| {
238+
let local_ty = self.cx.body.local_decls[*local].ty;
239+
if relevant_live_locals.contains(local) || !local_ty.has_free_regions() {
240+
return None;
241+
}
227242

228-
let relevant_live_locals: FxIndexSet<_> = relevant_live_locals.iter().copied().collect();
229-
230-
let locations = IntervalSet::new(self.cx.elements.num_points());
231-
232-
for (local, location_index) in drop_used {
233-
if !relevant_live_locals.contains(&local) {
234-
let local_ty = self.cx.body.local_decls[local].ty;
235-
if local_ty.has_free_regions() {
236243
let location = match self
237244
.cx
238245
.typeck
239246
.borrowck_context
240247
.location_table
241-
.to_location(location_index)
248+
.to_location(*location_index)
242249
{
243250
RichLocation::Start(l) => l,
244251
RichLocation::Mid(l) => l,
245252
};
246-
self.cx.add_drop_live_facts_for(local, local_ty, &[location], &locations);
247-
}
248-
}
253+
254+
Some((*local, local_ty, location))
255+
})
256+
.collect()
257+
};
258+
259+
// FIXME: these locations seem to have a special meaning (e.g. everywhere, at the end, ...), but I don't know which one. Please help me rename it to something descriptive!
260+
// Also, if this IntervalSet is used in many places, it maybe should have a newtype'd
261+
// name with a description of what it means for future mortals passing by.
262+
let locations = IntervalSet::new(self.cx.elements.num_points());
263+
264+
for (local, local_ty, location) in facts_to_add {
265+
self.cx.add_drop_live_facts_for(local, local_ty, &[location], &locations);
249266
}
250267
Some(())
251268
}

0 commit comments

Comments
 (0)