Skip to content

Commit d3accba

Browse files
committed
Auto merge of rust-lang#3428 - rust-lang:rustup-2024-03-30, r=RalfJung
Automatic Rustup
2 parents eae940f + 28521fd commit d3accba

File tree

156 files changed

+1574
-995
lines changed

Some content is hidden

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

156 files changed

+1574
-995
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -702,19 +702,10 @@ pub struct PatField {
702702
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
703703
#[derive(Encodable, Decodable, HashStable_Generic)]
704704
pub enum ByRef {
705-
Yes,
705+
Yes(Mutability),
706706
No,
707707
}
708708

709-
impl From<bool> for ByRef {
710-
fn from(b: bool) -> ByRef {
711-
match b {
712-
false => ByRef::No,
713-
true => ByRef::Yes,
714-
}
715-
}
716-
}
717-
718709
/// Explicit binding annotations given in the HIR for a binding. Note
719710
/// that this is not the final binding *mode* that we infer after type
720711
/// inference.
@@ -724,16 +715,20 @@ pub struct BindingAnnotation(pub ByRef, pub Mutability);
724715

725716
impl BindingAnnotation {
726717
pub const NONE: Self = Self(ByRef::No, Mutability::Not);
727-
pub const REF: Self = Self(ByRef::Yes, Mutability::Not);
718+
pub const REF: Self = Self(ByRef::Yes(Mutability::Not), Mutability::Not);
728719
pub const MUT: Self = Self(ByRef::No, Mutability::Mut);
729-
pub const REF_MUT: Self = Self(ByRef::Yes, Mutability::Mut);
720+
pub const REF_MUT: Self = Self(ByRef::Yes(Mutability::Mut), Mutability::Not);
721+
pub const MUT_REF: Self = Self(ByRef::Yes(Mutability::Not), Mutability::Mut);
722+
pub const MUT_REF_MUT: Self = Self(ByRef::Yes(Mutability::Mut), Mutability::Mut);
730723

731724
pub fn prefix_str(self) -> &'static str {
732725
match self {
733726
Self::NONE => "",
734727
Self::REF => "ref ",
735728
Self::MUT => "mut ",
736729
Self::REF_MUT => "ref mut ",
730+
Self::MUT_REF => "mut ref ",
731+
Self::MUT_REF_MUT => "mut ref mut ",
737732
}
738733
}
739734
}

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,8 +1847,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18471847
// the case where we have a mutable pattern to a reference as that would
18481848
// no longer be an `ImplicitSelf`.
18491849
TyKind::Ref(_, mt) if mt.ty.kind.is_implicit_self() => match mt.mutbl {
1850-
hir::Mutability::Not => hir::ImplicitSelfKind::ImmRef,
1851-
hir::Mutability::Mut => hir::ImplicitSelfKind::MutRef,
1850+
hir::Mutability::Not => hir::ImplicitSelfKind::RefImm,
1851+
hir::Mutability::Mut => hir::ImplicitSelfKind::RefMut,
18521852
},
18531853
_ => hir::ImplicitSelfKind::None,
18541854
}

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
15521552
/// When encountering an equality constraint in a `where` clause, emit an error. If the code seems
15531553
/// like it's setting an associated type, provide an appropriate suggestion.
15541554
fn deny_equality_constraints(
1555-
this: &mut AstValidator<'_>,
1555+
this: &AstValidator<'_>,
15561556
predicate: &WhereEqPredicate,
15571557
generics: &Generics,
15581558
) {

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
565565
gate_all!(unnamed_fields, "unnamed fields are not yet fully implemented");
566566
gate_all!(fn_delegation, "functions delegation is not yet fully implemented");
567567
gate_all!(postfix_match, "postfix match is experimental");
568+
gate_all!(mut_ref, "mutable by-reference bindings are experimental");
568569

569570
if !visitor.features.never_patterns {
570571
if let Some(spans) = spans.get(&sym::never_patterns) {

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,12 +1545,15 @@ impl<'a> State<'a> {
15451545
PatKind::Wild => self.word("_"),
15461546
PatKind::Never => self.word("!"),
15471547
PatKind::Ident(BindingAnnotation(by_ref, mutbl), ident, sub) => {
1548-
if *by_ref == ByRef::Yes {
1549-
self.word_nbsp("ref");
1550-
}
15511548
if mutbl.is_mut() {
15521549
self.word_nbsp("mut");
15531550
}
1551+
if let ByRef::Yes(rmutbl) = by_ref {
1552+
self.word_nbsp("ref");
1553+
if rmutbl.is_mut() {
1554+
self.word_nbsp("mut");
1555+
}
1556+
}
15541557
self.print_ident(*ident);
15551558
if let Some(p) = sub {
15561559
self.space();

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
337337
}
338338

339339
fn suggest_ref_or_clone(
340-
&mut self,
340+
&self,
341341
mpi: MovePathIndex,
342342
move_span: Span,
343343
err: &mut Diag<'tcx>,
@@ -1125,7 +1125,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11251125
}
11261126

11271127
pub(crate) fn report_use_while_mutably_borrowed(
1128-
&mut self,
1128+
&self,
11291129
location: Location,
11301130
(place, _span): (Place<'tcx>, Span),
11311131
borrow: &BorrowData<'tcx>,
@@ -1174,7 +1174,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11741174
}
11751175

11761176
pub(crate) fn report_conflicting_borrow(
1177-
&mut self,
1177+
&self,
11781178
location: Location,
11791179
(place, span): (Place<'tcx>, Span),
11801180
gen_borrow_kind: BorrowKind,
@@ -2463,7 +2463,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
24632463
}
24642464

24652465
fn report_local_value_does_not_live_long_enough(
2466-
&mut self,
2466+
&self,
24672467
location: Location,
24682468
name: &str,
24692469
borrow: &BorrowData<'tcx>,
@@ -2642,7 +2642,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
26422642
}
26432643

26442644
fn report_thread_local_value_does_not_live_long_enough(
2645-
&mut self,
2645+
&self,
26462646
drop_span: Span,
26472647
borrow_span: Span,
26482648
) -> Diag<'tcx> {
@@ -2663,7 +2663,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
26632663

26642664
#[instrument(level = "debug", skip(self))]
26652665
fn report_temporary_value_does_not_live_long_enough(
2666-
&mut self,
2666+
&self,
26672667
location: Location,
26682668
borrow: &BorrowData<'tcx>,
26692669
drop_span: Span,
@@ -2921,7 +2921,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
29212921

29222922
#[instrument(level = "debug", skip(self))]
29232923
fn report_escaping_closure_capture(
2924-
&mut self,
2924+
&self,
29252925
use_span: UseSpans<'tcx>,
29262926
var_span: Span,
29272927
fr_name: &RegionName,
@@ -3031,7 +3031,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
30313031
}
30323032

30333033
fn report_escaping_data(
3034-
&mut self,
3034+
&self,
30353035
borrow_span: Span,
30363036
name: &Option<String>,
30373037
upvar_span: Span,
@@ -3065,7 +3065,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
30653065
}
30663066

30673067
fn get_moved_indexes(
3068-
&mut self,
3068+
&self,
30693069
location: Location,
30703070
mpi: MovePathIndex,
30713071
) -> (Vec<MoveSite>, Vec<Location>) {
@@ -3854,7 +3854,7 @@ enum AnnotatedBorrowFnSignature<'tcx> {
38543854
impl<'tcx> AnnotatedBorrowFnSignature<'tcx> {
38553855
/// Annotate the provided diagnostic with information about borrow from the fn signature that
38563856
/// helps explain.
3857-
pub(crate) fn emit(&self, cx: &mut MirBorrowckCtxt<'_, 'tcx>, diag: &mut Diag<'_>) -> String {
3857+
pub(crate) fn emit(&self, cx: &MirBorrowckCtxt<'_, 'tcx>, diag: &mut Diag<'_>) -> String {
38583858
match self {
38593859
&AnnotatedBorrowFnSignature::Closure { argument_ty, argument_span } => {
38603860
diag.span_label(

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
use core::ops::ControlFlow;
55
use hir::{ExprKind, Param};
66
use rustc_errors::{Applicability, Diag};
7-
use rustc_hir as hir;
87
use rustc_hir::intravisit::Visitor;
9-
use rustc_hir::Node;
8+
use rustc_hir::{self as hir, BindingAnnotation, ByRef, Node};
109
use rustc_infer::traits;
1110
use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem};
1211
use rustc_middle::ty::{self, InstanceDef, ToPredicate, Ty, TyCtxt};
@@ -304,7 +303,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
304303
{
305304
match *decl.local_info() {
306305
LocalInfo::User(BindingForm::Var(mir::VarBindingForm {
307-
binding_mode: ty::BindingMode::BindByValue(Mutability::Not),
306+
binding_mode: BindingAnnotation(ByRef::No, Mutability::Not),
308307
opt_ty_info: Some(sp),
309308
opt_match_place: _,
310309
pat_span: _,
@@ -342,7 +341,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
342341
} else if decl.mutability.is_not() {
343342
if matches!(
344343
decl.local_info(),
345-
LocalInfo::User(BindingForm::ImplicitSelf(hir::ImplicitSelfKind::MutRef))
344+
LocalInfo::User(BindingForm::ImplicitSelf(hir::ImplicitSelfKind::RefMut))
346345
) {
347346
err.note(
348347
"as `Self` may be unsized, this call attempts to take `&mut &mut self`",
@@ -407,7 +406,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
407406
if let Some(fn_decl) = node.fn_decl() {
408407
if !matches!(
409408
fn_decl.implicit_self,
410-
hir::ImplicitSelfKind::ImmRef | hir::ImplicitSelfKind::MutRef
409+
hir::ImplicitSelfKind::RefImm | hir::ImplicitSelfKind::RefMut
411410
) {
412411
err.span_suggestion(
413412
upvar_ident.span,
@@ -717,7 +716,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
717716
debug!("local_decl: {:?}", local_decl);
718717
let pat_span = match *local_decl.local_info() {
719718
LocalInfo::User(BindingForm::Var(mir::VarBindingForm {
720-
binding_mode: ty::BindingMode::BindByValue(Mutability::Not),
719+
binding_mode: BindingAnnotation(ByRef::No, Mutability::Not),
721720
opt_ty_info: _,
722721
opt_match_place: _,
723722
pat_span,
@@ -1070,7 +1069,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
10701069
}
10711070

10721071
LocalInfo::User(mir::BindingForm::Var(mir::VarBindingForm {
1073-
binding_mode: ty::BindingMode::BindByValue(_),
1072+
binding_mode: BindingAnnotation(ByRef::No, _),
10741073
opt_ty_info,
10751074
..
10761075
})) => {
@@ -1138,7 +1137,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
11381137
}
11391138

11401139
LocalInfo::User(mir::BindingForm::Var(mir::VarBindingForm {
1141-
binding_mode: ty::BindingMode::BindByReference(_),
1140+
binding_mode: BindingAnnotation(ByRef::Yes(_), _),
11421141
..
11431142
})) => {
11441143
let pattern_span: Span = local_decl.source_info.span;
@@ -1329,7 +1328,7 @@ pub fn mut_borrow_of_mutable_ref(local_decl: &LocalDecl<'_>, local_name: Option<
13291328
match *local_decl.local_info() {
13301329
// Check if mutably borrowing a mutable reference.
13311330
LocalInfo::User(mir::BindingForm::Var(mir::VarBindingForm {
1332-
binding_mode: ty::BindingMode::BindByValue(Mutability::Not),
1331+
binding_mode: BindingAnnotation(ByRef::No, Mutability::Not),
13331332
..
13341333
})) => matches!(local_decl.ty.kind(), ty::Ref(_, _, hir::Mutability::Mut)),
13351334
LocalInfo::User(mir::BindingForm::ImplicitSelf(kind)) => {
@@ -1338,7 +1337,7 @@ pub fn mut_borrow_of_mutable_ref(local_decl: &LocalDecl<'_>, local_name: Option<
13381337
//
13391338
// Deliberately fall into this case for all implicit self types,
13401339
// so that we don't fall into the next case with them.
1341-
kind == hir::ImplicitSelfKind::MutRef
1340+
kind == hir::ImplicitSelfKind::RefMut
13421341
}
13431342
_ if Some(kw::SelfLower) == local_name => {
13441343
// Otherwise, check if the name is the `self` keyword - in which case

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ pub(super) fn populate_access_facts<'a, 'tcx>(
8787
body: &Body<'tcx>,
8888
location_table: &LocationTable,
8989
move_data: &MoveData<'tcx>,
90+
//FIXME: this is not mutated, but expected to be modified as
91+
// out param, bug?
9092
dropped_at: &mut Vec<(Local, Location)>,
9193
) {
9294
debug!("populate_access_facts()");

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl<'me, 'typeck, 'flow, 'tcx> LivenessResults<'me, 'typeck, 'flow, 'tcx> {
200200
for local in boring_locals {
201201
let local_ty = self.cx.body.local_decls[local].ty;
202202
let drop_data = self.cx.drop_data.entry(local_ty).or_insert_with({
203-
let typeck = &mut self.cx.typeck;
203+
let typeck = &self.cx.typeck;
204204
move || LivenessContext::compute_drop_data(typeck, local_ty)
205205
});
206206

@@ -542,7 +542,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
542542
);
543543

544544
let drop_data = self.drop_data.entry(dropped_ty).or_insert_with({
545-
let typeck = &mut self.typeck;
545+
let typeck = &self.typeck;
546546
move || Self::compute_drop_data(typeck, dropped_ty)
547547
});
548548

@@ -597,10 +597,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
597597
});
598598
}
599599

600-
fn compute_drop_data(
601-
typeck: &mut TypeChecker<'_, 'tcx>,
602-
dropped_ty: Ty<'tcx>,
603-
) -> DropData<'tcx> {
600+
fn compute_drop_data(typeck: &TypeChecker<'_, 'tcx>, dropped_ty: Ty<'tcx>) -> DropData<'tcx> {
604601
debug!("compute_drop_data(dropped_ty={:?})", dropped_ty,);
605602

606603
match typeck

compiler/rustc_builtin_macros/src/asm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub struct AsmArgs {
2929
}
3030

3131
fn parse_args<'a>(
32-
ecx: &mut ExtCtxt<'a>,
32+
ecx: &ExtCtxt<'a>,
3333
sp: Span,
3434
tts: TokenStream,
3535
is_global_asm: bool,
@@ -303,7 +303,7 @@ pub fn parse_asm_args<'a>(
303303
///
304304
/// This function must be called immediately after the option token is parsed.
305305
/// Otherwise, the suggestion will be incorrect.
306-
fn err_duplicate_option(p: &mut Parser<'_>, symbol: Symbol, span: Span) {
306+
fn err_duplicate_option(p: &Parser<'_>, symbol: Symbol, span: Span) {
307307
// Tool-only output
308308
let full_span = if p.token.kind == token::Comma { span.to(p.token.span) } else { span };
309309
p.psess.dcx.emit_err(errors::AsmOptAlreadyprovided { span, symbol, full_span });
@@ -315,7 +315,7 @@ fn err_duplicate_option(p: &mut Parser<'_>, symbol: Symbol, span: Span) {
315315
/// This function must be called immediately after the option token is parsed.
316316
/// Otherwise, the error will not point to the correct spot.
317317
fn try_set_option<'a>(
318-
p: &mut Parser<'a>,
318+
p: &Parser<'a>,
319319
args: &mut AsmArgs,
320320
symbol: Symbol,
321321
option: ast::InlineAsmOptions,

compiler/rustc_builtin_macros/src/assert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn expr_if_not(
111111
cx.expr_if(span, cx.expr(span, ExprKind::Unary(UnOp::Not, cond)), then, els)
112112
}
113113

114-
fn parse_assert<'a>(cx: &mut ExtCtxt<'a>, sp: Span, stream: TokenStream) -> PResult<'a, Assert> {
114+
fn parse_assert<'a>(cx: &ExtCtxt<'a>, sp: Span, stream: TokenStream) -> PResult<'a, Assert> {
115115
let mut parser = cx.new_parser_from_tts(stream);
116116

117117
if parser.token == token::Eof {

compiler/rustc_builtin_macros/src/cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn expand_cfg(
3535
})
3636
}
3737

38-
fn parse_cfg<'a>(cx: &mut ExtCtxt<'a>, span: Span, tts: TokenStream) -> PResult<'a, ast::MetaItem> {
38+
fn parse_cfg<'a>(cx: &ExtCtxt<'a>, span: Span, tts: TokenStream) -> PResult<'a, ast::MetaItem> {
3939
let mut p = cx.new_parser_from_tts(tts);
4040

4141
if p.token == token::Eof {

compiler/rustc_builtin_macros/src/cfg_accessible.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_span::Span;
1010

1111
pub(crate) struct Expander;
1212

13-
fn validate_input<'a>(ecx: &mut ExtCtxt<'_>, mi: &'a ast::MetaItem) -> Option<&'a ast::Path> {
13+
fn validate_input<'a>(ecx: &ExtCtxt<'_>, mi: &'a ast::MetaItem) -> Option<&'a ast::Path> {
1414
use errors::CfgAccessibleInvalid::*;
1515
match mi.meta_item_list() {
1616
None => {}

compiler/rustc_builtin_macros/src/concat_bytes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::errors;
88

99
/// Emits errors for literal expressions that are invalid inside and outside of an array.
1010
fn invalid_type_err(
11-
cx: &mut ExtCtxt<'_>,
11+
cx: &ExtCtxt<'_>,
1212
token_lit: token::Lit,
1313
span: Span,
1414
is_nested: bool,
@@ -65,7 +65,7 @@ fn invalid_type_err(
6565
/// Otherwise, returns `None`, and either pushes the `expr`'s span to `missing_literals` or
6666
/// updates `guar` accordingly.
6767
fn handle_array_element(
68-
cx: &mut ExtCtxt<'_>,
68+
cx: &ExtCtxt<'_>,
6969
guar: &mut Option<ErrorGuaranteed>,
7070
missing_literals: &mut Vec<rustc_span::Span>,
7171
expr: &P<rustc_ast::Expr>,

compiler/rustc_builtin_macros/src/deriving/bounds.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_expand::base::{Annotatable, ExtCtxt};
66
use rustc_span::Span;
77

88
pub fn expand_deriving_copy(
9-
cx: &mut ExtCtxt<'_>,
9+
cx: &ExtCtxt<'_>,
1010
span: Span,
1111
mitem: &MetaItem,
1212
item: &Annotatable,
@@ -29,7 +29,7 @@ pub fn expand_deriving_copy(
2929
}
3030

3131
pub fn expand_deriving_const_param_ty(
32-
cx: &mut ExtCtxt<'_>,
32+
cx: &ExtCtxt<'_>,
3333
span: Span,
3434
mitem: &MetaItem,
3535
item: &Annotatable,

0 commit comments

Comments
 (0)