Skip to content

Commit ecd4547

Browse files
committed
Auto merge of #124111 - matthiaskrgr:rollup-cmmkryf, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #124041 (Fix copy path button) - #124047 (Match ergonomics 2024: miscellaneous code cleanups) - #124064 (Move confusing comment about otherwise blocks in `lower_match_tree`) - #124090 (llvm: update riscv target feature to match LLVM 19) - #124100 (fix: make `str::from_raw_parts_mut` `mut`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents b1248bc + 5543da9 commit ecd4547

89 files changed

Lines changed: 293 additions & 322 deletions

File tree

Some content is hidden

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

‎compiler/rustc_ast/src/ast.rs‎

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ impl Pat {
568568
// In a type expression `_` is an inference variable.
569569
PatKind::Wild => TyKind::Infer,
570570
// An IDENT pattern with no binding mode would be valid as path to a type. E.g. `u32`.
571-
PatKind::Ident(BindingAnnotation::NONE, ident,None) => {
571+
PatKind::Ident(BindingMode::NONE, ident,None) => {
572572
TyKind::Path(None,Path::from_ident(*ident))
573573
}
574574
PatKind::Path(qself, path) => TyKind::Path(qself.clone(), path.clone()),
@@ -675,7 +675,7 @@ impl Pat {
675675
pubfndescr(&self) -> Option<String>{
676676
match&self.kind{
677677
PatKind::Wild => Some("_".to_string()),
678-
PatKind::Ident(BindingAnnotation::NONE, ident,None) => Some(format!("{ident}")),
678+
PatKind::Ident(BindingMode::NONE, ident,None) => Some(format!("{ident}")),
679679
PatKind::Ref(pat, mutbl) => pat.descr().map(|d| format!("&{}{d}", mutbl.prefix_str())),
680680
_ => None,
681681
}
@@ -707,14 +707,25 @@ pub enum ByRef {
707707
No,
708708
}
709709

710-
/// Explicit binding annotations given in the HIR for a binding. Note
711-
/// that this is not the final binding *mode* that we infer after type
712-
/// inference.
710+
implByRef{
711+
pubfncap_ref_mutability(mutself,mutbl:Mutability) -> Self{
712+
ifletByRef::Yes(old_mutbl) = &mutself{
713+
*old_mutbl = cmp::min(*old_mutbl, mutbl);
714+
}
715+
self
716+
}
717+
}
718+
719+
/// The mode of a binding (`mut`, `ref mut`, etc).
720+
/// Used for both the explicit binding annotations given in the HIR for a binding
721+
/// and the final binding mode that we infer after type inference/match ergonomics.
722+
/// `.0` is the by-reference mode (`ref`, `ref mut`, or by value),
723+
/// `.1` is the mutability of the binding.
713724
#[derive(Clone,Copy,Debug,Eq,PartialEq)]
714725
#[derive(Encodable,Decodable,HashStable_Generic)]
715-
pubstructBindingAnnotation(pubByRef,pubMutability);
726+
pubstructBindingMode(pubByRef,pubMutability);
716727

717-
implBindingAnnotation{
728+
implBindingMode{
718729
pubconstNONE:Self = Self(ByRef::No,Mutability::Not);
719730
pubconstREF:Self = Self(ByRef::Yes(Mutability::Not),Mutability::Not);
720731
pubconstMUT:Self = Self(ByRef::No,Mutability::Mut);
@@ -732,13 +743,6 @@ impl BindingAnnotation {
732743
Self::MUT_REF_MUT => "mut ref mut ",
733744
}
734745
}
735-
736-
pubfncap_ref_mutability(mutself,mutbl:Mutability) -> Self{
737-
ifletByRef::Yes(old_mutbl) = &mutself.0{
738-
*old_mutbl = cmp::min(*old_mutbl, mutbl);
739-
}
740-
self
741-
}
742746
}
743747

744748
#[derive(Clone,Encodable,Decodable,Debug)]
@@ -769,7 +773,7 @@ pub enum PatKind {
769773
/// or a unit struct/variant pattern, or a const pattern (in the last two cases the third
770774
/// field must be `None`). Disambiguation cannot be done with parser alone, so it happens
771775
/// during name resolution.
772-
Ident(BindingAnnotation,Ident,Option<P<Pat>>),
776+
Ident(BindingMode,Ident,Option<P<Pat>>),
773777

774778
/// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`).
775779
Struct(Option<P<QSelf>>,Path,ThinVec<PatField>,PatFieldsRest),
@@ -2382,7 +2386,7 @@ pub type ExplicitSelf = Spanned<SelfKind>;
23822386
implParam{
23832387
/// Attempts to cast parameter to `ExplicitSelf`.
23842388
pubfnto_self(&self) -> Option<ExplicitSelf>{
2385-
ifletPatKind::Ident(BindingAnnotation(ByRef::No, mutbl), ident, _) = self.pat.kind{
2389+
ifletPatKind::Ident(BindingMode(ByRef::No, mutbl), ident, _) = self.pat.kind{
23862390
if ident.name == kw::SelfLower{
23872391
returnmatchself.ty.kind{
23882392
TyKind::ImplicitSelf => Some(respan(self.pat.span,SelfKind::Value(mutbl))),
@@ -2434,7 +2438,7 @@ impl Param {
24342438
attrs,
24352439
pat:P(Pat{
24362440
id:DUMMY_NODE_ID,
2437-
kind:PatKind::Ident(BindingAnnotation(ByRef::No, mutbl), eself_ident,None),
2441+
kind:PatKind::Ident(BindingMode(ByRef::No, mutbl), eself_ident,None),
24382442
span,
24392443
tokens:None,
24402444
}),

‎compiler/rustc_ast_lowering/src/delegation.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
178178
let pat_id = self.lower_node_id(pat_node_id);
179179
let pat = self.arena.alloc(hir::Pat{
180180
hir_id: pat_id,
181-
kind: hir::PatKind::Binding(hir::BindingAnnotation::NONE, pat_id,Ident::empty(),None),
181+
kind: hir::PatKind::Binding(hir::BindingMode::NONE, pat_id,Ident::empty(),None),
182182
span: ty.span,
183183
default_binding_modes:false,
184184
});

‎compiler/rustc_ast_lowering/src/expr.rs‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
643643
let(pat, task_context_hid) = self.pat_ident_binding_mode(
644644
span,
645645
Ident::with_dummy_span(sym::_task_context),
646-
hir::BindingAnnotation::MUT,
646+
hir::BindingMode::MUT,
647647
);
648648
let param = hir::Param{
649649
hir_id:self.next_id(),
@@ -805,11 +805,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
805805
// debuggers and debugger extensions expect it to be called `__awaitee`. They use
806806
// this name to identify what is being awaited by a suspended async functions.
807807
let awaitee_ident = Ident::with_dummy_span(sym::__awaitee);
808-
let(awaitee_pat, awaitee_pat_hid) = self.pat_ident_binding_mode(
809-
gen_future_span,
810-
awaitee_ident,
811-
hir::BindingAnnotation::MUT,
812-
);
808+
let(awaitee_pat, awaitee_pat_hid) =
809+
self.pat_ident_binding_mode(gen_future_span, awaitee_ident, hir::BindingMode::MUT);
813810

814811
let task_context_ident = Ident::with_dummy_span(sym::_task_context);
815812

@@ -1648,7 +1645,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
16481645
// `mut iter`
16491646
let iter = Ident::with_dummy_span(sym::iter);
16501647
let(iter_pat, iter_pat_nid) =
1651-
self.pat_ident_binding_mode(head_span, iter, hir::BindingAnnotation::MUT);
1648+
self.pat_ident_binding_mode(head_span, iter, hir::BindingMode::MUT);
16521649

16531650
let match_expr = {
16541651
let iter = self.expr_ident(head_span, iter, iter_pat_nid);

‎compiler/rustc_ast_lowering/src/item.rs‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,9 +1179,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
11791179
// Check if this is a binding pattern, if so, we can optimize and avoid adding a
11801180
// `let <pat> = __argN;` statement. In this case, we do not rename the parameter.
11811181
let(ident, is_simple_parameter) = match parameter.pat.kind{
1182-
hir::PatKind::Binding(hir::BindingAnnotation(ByRef::No, _), _, ident, _) => {
1183-
(ident,true)
1184-
}
1182+
hir::PatKind::Binding(hir::BindingMode(ByRef::No, _), _, ident, _) => (ident,true),
11851183
// For `ref mut` or wildcard arguments, we can't reuse the binding, but
11861184
// we can keep the same name for the parameter.
11871185
// This lets rustdoc render it correctly in documentation.
@@ -1244,7 +1242,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
12441242
// because the user may have specified a `ref mut` binding in the next
12451243
// statement.
12461244
let(move_pat, move_id) =
1247-
self.pat_ident_binding_mode(desugared_span, ident, hir::BindingAnnotation::MUT);
1245+
self.pat_ident_binding_mode(desugared_span, ident, hir::BindingMode::MUT);
12481246
let move_expr = self.expr_ident(desugared_span, ident, new_parameter_id);
12491247
let move_stmt = self.stmt_let_pat(
12501248
None,

‎compiler/rustc_ast_lowering/src/lib.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,7 +1895,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18951895
implicit_self: decl.inputs.get(0).map_or(hir::ImplicitSelfKind::None, |arg| {
18961896
let is_mutable_pat = matches!(
18971897
arg.pat.kind,
1898-
PatKind::Ident(hir::BindingAnnotation(_,Mutability::Mut), ..)
1898+
PatKind::Ident(hir::BindingMode(_,Mutability::Mut), ..)
18991899
);
19001900

19011901
match&arg.ty.kind{
@@ -2478,18 +2478,18 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24782478
}
24792479

24802480
fnpat_ident(&mutself,span:Span,ident:Ident) -> (&'hir hir::Pat<'hir>,HirId){
2481-
self.pat_ident_binding_mode(span, ident, hir::BindingAnnotation::NONE)
2481+
self.pat_ident_binding_mode(span, ident, hir::BindingMode::NONE)
24822482
}
24832483

24842484
fnpat_ident_mut(&mutself,span:Span,ident:Ident) -> (hir::Pat<'hir>,HirId){
2485-
self.pat_ident_binding_mode_mut(span, ident, hir::BindingAnnotation::NONE)
2485+
self.pat_ident_binding_mode_mut(span, ident, hir::BindingMode::NONE)
24862486
}
24872487

24882488
fnpat_ident_binding_mode(
24892489
&mutself,
24902490
span:Span,
24912491
ident:Ident,
2492-
bm: hir::BindingAnnotation,
2492+
bm: hir::BindingMode,
24932493
) -> (&'hir hir::Pat<'hir>,HirId){
24942494
let(pat, hir_id) = self.pat_ident_binding_mode_mut(span, ident, bm);
24952495
(self.arena.alloc(pat), hir_id)
@@ -2499,7 +2499,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24992499
&mutself,
25002500
span:Span,
25012501
ident:Ident,
2502-
bm: hir::BindingAnnotation,
2502+
bm: hir::BindingMode,
25032503
) -> (hir::Pat<'hir>,HirId){
25042504
let hir_id = self.next_id();
25052505

‎compiler/rustc_ast_lowering/src/pat.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
243243
fnlower_pat_ident(
244244
&mutself,
245245
p:&Pat,
246-
annotation:BindingAnnotation,
246+
annotation:BindingMode,
247247
ident:Ident,
248248
lower_sub:implFnOnce(&mutSelf) -> Option<&'hir hir::Pat<'hir>>,
249249
) -> hir::PatKind<'hir>{

‎compiler/rustc_ast_passes/src/ast_validation.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ impl<'a> AstValidator<'a> {
276276
fncheck_decl_no_pat(decl:&FnDecl,mutreport_err:implFnMut(Span,Option<Ident>,bool)){
277277
forParam{ pat, .. }in&decl.inputs{
278278
match pat.kind{
279-
PatKind::Ident(BindingAnnotation::NONE, _,None) | PatKind::Wild => {}
280-
PatKind::Ident(BindingAnnotation::MUT, ident,None) => {
279+
PatKind::Ident(BindingMode::NONE, _,None) | PatKind::Wild => {}
280+
PatKind::Ident(BindingMode::MUT, ident,None) => {
281281
report_err(pat.span,Some(ident),true)
282282
}
283283
_ => report_err(pat.span,None,false),

‎compiler/rustc_ast_pretty/src/pprust/state.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_ast::util::classify;
1717
use rustc_ast::util::comments::{Comment,CommentStyle};
1818
use rustc_ast::util::parser;
1919
use rustc_ast::{selfas ast,AttrArgs,AttrArgsEq,BlockCheckMode,PatKind};
20-
use rustc_ast::{attr,BindingAnnotation,ByRef,DelimArgs,RangeEnd,RangeSyntax,Term};
20+
use rustc_ast::{attr,BindingMode,ByRef,DelimArgs,RangeEnd,RangeSyntax,Term};
2121
use rustc_ast::{GenericArg,GenericBound,SelfKind};
2222
use rustc_ast::{InlineAsmOperand,InlineAsmRegOrRegClass};
2323
use rustc_ast::{InlineAsmOptions,InlineAsmTemplatePiece};
@@ -1558,7 +1558,7 @@ impl<'a> State<'a> {
15581558
match&pat.kind{
15591559
PatKind::Wild => self.word("_"),
15601560
PatKind::Never => self.word("!"),
1561-
PatKind::Ident(BindingAnnotation(by_ref, mutbl), ident, sub) => {
1561+
PatKind::Ident(BindingMode(by_ref, mutbl), ident, sub) => {
15621562
if mutbl.is_mut(){
15631563
self.word_nbsp("mut");
15641564
}
@@ -1654,7 +1654,7 @@ impl<'a> State<'a> {
16541654
if mutbl.is_mut(){
16551655
self.word("mut ");
16561656
}
1657-
ifletPatKind::Ident(ast::BindingAnnotation::MUT, ..) = inner.kind{
1657+
ifletPatKind::Ident(ast::BindingMode::MUT, ..) = inner.kind{
16581658
self.popen();
16591659
self.print_pat(inner);
16601660
self.pclose();

‎compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
377377
if p.span == self.expr_span{
378378
self.pat = Some(p);
379379
}
380-
iflet hir::PatKind::Binding(hir::BindingAnnotation::NONE, _, i, sub) = p.kind{
380+
iflet hir::PatKind::Binding(hir::BindingMode::NONE, _, i, sub) = p.kind{
381381
if i.span == self.expr_span || p.span == self.expr_span{
382382
self.pat = Some(p);
383383
}

‎compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use core::ops::ControlFlow;
55
use hir::{ExprKind,Param};
66
use rustc_errors::{Applicability,Diag};
77
use rustc_hir::intravisit::Visitor;
8-
use rustc_hir::{selfas hir,BindingAnnotation,ByRef,Node};
8+
use rustc_hir::{selfas hir,BindingMode,ByRef,Node};
99
use rustc_infer::traits;
1010
use rustc_middle::mir::{Mutability,Place,PlaceRef,ProjectionElem};
1111
use rustc_middle::ty::{self,InstanceDef,ToPredicate,Ty,TyCtxt};
@@ -303,7 +303,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
303303
{
304304
match*decl.local_info(){
305305
LocalInfo::User(BindingForm::Var(mir::VarBindingForm{
306-
binding_mode:BindingAnnotation(ByRef::No,Mutability::Not),
306+
binding_mode:BindingMode(ByRef::No,Mutability::Not),
307307
opt_ty_info:Some(sp),
308308
opt_match_place: _,
309309
pat_span: _,
@@ -398,7 +398,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
398398
let upvar_hir_id = captured_place.get_root_variable();
399399

400400
ifletNode::Pat(pat) = self.infcx.tcx.hir_node(upvar_hir_id)
401-
&& let hir::PatKind::Binding(hir::BindingAnnotation::NONE, _, upvar_ident, _) =
401+
&& let hir::PatKind::Binding(hir::BindingMode::NONE, _, upvar_ident, _) =
402402
pat.kind
403403
{
404404
if upvar_ident.name == kw::SelfLower{
@@ -729,7 +729,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
729729
debug!("local_decl: {:?}", local_decl);
730730
let pat_span = match*local_decl.local_info(){
731731
LocalInfo::User(BindingForm::Var(mir::VarBindingForm{
732-
binding_mode:BindingAnnotation(ByRef::No,Mutability::Not),
732+
binding_mode:BindingMode(ByRef::No,Mutability::Not),
733733
opt_ty_info: _,
734734
opt_match_place: _,
735735
pat_span,
@@ -1086,7 +1086,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
10861086
}
10871087

10881088
LocalInfo::User(mir::BindingForm::Var(mir::VarBindingForm{
1089-
binding_mode:BindingAnnotation(ByRef::No, _),
1089+
binding_mode:BindingMode(ByRef::No, _),
10901090
opt_ty_info,
10911091
..
10921092
})) => {
@@ -1154,7 +1154,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
11541154
}
11551155

11561156
LocalInfo::User(mir::BindingForm::Var(mir::VarBindingForm{
1157-
binding_mode:BindingAnnotation(ByRef::Yes(_), _),
1157+
binding_mode:BindingMode(ByRef::Yes(_), _),
11581158
..
11591159
})) => {
11601160
let pattern_span:Span = local_decl.source_info.span;
@@ -1356,7 +1356,7 @@ pub fn mut_borrow_of_mutable_ref(local_decl: &LocalDecl<'_>, local_name: Option<
13561356
match*local_decl.local_info(){
13571357
// Check if mutably borrowing a mutable reference.
13581358
LocalInfo::User(mir::BindingForm::Var(mir::VarBindingForm{
1359-
binding_mode:BindingAnnotation(ByRef::No,Mutability::Not),
1359+
binding_mode:BindingMode(ByRef::No,Mutability::Not),
13601360
..
13611361
})) => matches!(local_decl.ty.kind(), ty::Ref(_, _, hir::Mutability::Mut)),
13621362
LocalInfo::User(mir::BindingForm::ImplicitSelf(kind)) => {

0 commit comments

Comments
 (0)