10BC0 Auto merge of #127865 - matthiaskrgr:rollup-8m49dlg, r=matthiaskrgr · rust-lang-ci/rust@e35364a · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e35364a

Browse files
committed
Auto merge of rust-lang#127865 - matthiaskrgr:rollup-8m49dlg, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#125042 (Use ordinal number in argument error) - rust-lang#127229 (rustdoc: click target for sidebar items flush left) - rust-lang#127337 (Move a few intrinsics to Rust abi) - rust-lang#127472 (MIR building: Stop using `unpack!` for `BlockAnd<()>`) - rust-lang#127579 (Solve a error `.clone()` suggestion when moving a mutable reference) - rust-lang#127769 (Don't use implicit features in `Cargo.toml` in `compiler/`) - rust-lang#127844 (Remove invalid further restricting suggestion for type bound) - rust-lang#127855 (Add myself to review rotation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents fcc325f + 2ea21cf commit e35364a

File tree

92 files changed

+717
-387
lines changed
  • matches
  • rustc_next_trait_solver
  • rustc_query_system
  • rustc_transmute
  • rustc_type_ir
  • rustc
  • library/core/src
  • src/librustdoc/html/static/css
  • tests
  • Some content is hidden

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

    92 files changed

    +717
    -387
    lines changed

    compiler/rustc/Cargo.toml

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -27,7 +27,7 @@ features = ['unprefixed_malloc_on_supported_platforms']
    2727

    2828
    [features]
    2929
    # tidy-alphabetical-start
    30-
    jemalloc = ['jemalloc-sys']
    30+
    jemalloc = ['dep:jemalloc-sys']
    3131
    llvm = ['rustc_driver_impl/llvm']
    3232
    max_level_info = ['rustc_driver_impl/max_level_info']
    3333
    rustc_use_parallel_compiler = ['rustc_driver_impl/rustc_use_parallel_compiler']

    compiler/rustc/src/main.rs

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -34,7 +34,7 @@
    3434

    3535
    fn main() {
    3636
    // See the comment at the top of this file for an explanation of this.
    37-
    #[cfg(feature = "jemalloc-sys")]
    37+
    #[cfg(feature = "jemalloc")]
    3838
    {
    3939
    use std::os::raw::{c_int, c_void};
    4040

    compiler/rustc_abi/Cargo.toml

    Lines changed: 4 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -21,10 +21,10 @@ default = ["nightly", "randomize"]
    2121
    # rust-analyzer depends on this crate and we therefore require it to built on a stable toolchain
    2222
    # without depending on rustc_data_structures, rustc_macros and rustc_serialize
    2323
    nightly = [
    24-
    "rustc_data_structures",
    24+
    "dep:rustc_data_structures",
    25+
    "dep:rustc_macros",
    26+
    "dep:rustc_serialize",
    2527
    "rustc_index/nightly",
    26-
    "rustc_macros",
    27-
    "rustc_serialize",
    2828
    ]
    29-
    randomize = ["rand", "rand_xoshiro", "nightly"]
    29+
    randomize = ["dep:rand", "dep:rand_xoshiro", "nightly"]
    3030
    # tidy-alphabetical-end

    compiler/rustc_ast_ir/Cargo.toml

    Lines changed: 4 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -14,8 +14,8 @@ rustc_span = { path = "../rustc_span", optional = true }
    1414
    [features]
    1515
    default = ["nightly"]
    1616
    nightly = [
    17-
    "rustc_serialize",
    18-
    "rustc_data_structures",
    19-
    "rustc_macros",
    20-
    "rustc_span",
    17+
    "dep:rustc_serialize",
    18+
    "dep:rustc_data_structures",
    19+
    "dep:rustc_macros",
    20+
    "dep:rustc_span",
    2121
    ]

    compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

    Lines changed: 60 additions & 16 deletions
    Original file line numberDiff line numberDiff line change
    @@ -205,16 +205,25 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
    205205
    is_loop_move = true;
    206206
    }
    207207

    208+
    let mut has_suggest_reborrow = false;
    208209
    if !seen_spans.contains(&move_span) {
    209210
    if !closure {
    210-
    self.suggest_ref_or_clone(mpi, &mut err, &mut in_pattern, move_spans);
    211+
    self.suggest_ref_or_clone(
    212+
    mpi,
    213+
    &mut err,
    214+
    &mut in_pattern,
    215+
    move_spans,
    216+
    moved_place.as_ref(),
    217+
    &mut has_suggest_reborrow,
    218+
    );
    211219
    }
    212220

    213221
    let msg_opt = CapturedMessageOpt {
    214222
    is_partial_move,
    215223
    is_loop_message,
    216224
    is_move_msg,
    217225
    is_loop_move,
    226+
    has_suggest_reborrow,
    218227
    maybe_reinitialized_locations_is_empty: maybe_reinitialized_locations
    219228
    .is_empty(),
    220229
    };
    @@ -259,17 +268,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
    259268
    if is_loop_move & !in_pattern && !matches!(use_spans, UseSpans::ClosureUse { .. }) {
    260269
    if let ty::Ref(_, _, hir::Mutability::Mut) = ty.kind() {
    261270
    // We have a `&mut` ref, we need to reborrow on each iteration (#62112).
    262-
    err.span_suggestion_verbose(
    263-
    span.shrink_to_lo(),
    264-
    format!(
    265-
    "consider creating a fresh reborrow of {} here",
    266-
    self.describe_place(moved_place)
    267-
    .map(|n| format!("`{n}`"))
    268-
    .unwrap_or_else(|| "the mutable reference".to_string()),
    269-
    ),
    270-
    "&mut *",
    271-
    Applicability::MachineApplicable,
    272-
    );
    271+
    self.suggest_reborrow(&mut err, span, moved_place);
    273272
    }
    274273
    }
    275274

    @@ -346,6 +345,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
    346345
    err: &mut Diag<'infcx>,
    347346
    in_pattern: &mut bool,
    348347
    move_spans: UseSpans<'tcx>,
    348+
    moved_place: PlaceRef<'tcx>,
    349+
    has_suggest_reborrow: &mut bool,
    349350
    ) {
    350351
    let move_span = match move_spans {
    351352
    UseSpans::ClosureUse { capture_kind_span, .. } => capture_kind_span,
    @@ -435,20 +436,44 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
    435436
    let parent = self.infcx.tcx.parent_hir_node(expr.hir_id);
    436437
    let (def_id, args, offset) = if let hir::Node::Expr(parent_expr) = parent
    437438
    && let hir::ExprKind::MethodCall(_, _, args, _) = parent_expr.kind
    438-
    && let Some(def_id) = typeck.type_dependent_def_id(parent_expr.hir_id)
    439439
    {
    440-
    (def_id.as_local(), args, 1)
    440+
    (typeck.type_dependent_def_id(parent_expr.hir_id), args, 1)
    441441
    } else if let hir::Node::Expr(parent_expr) = parent
    442442
    && let hir::ExprKind::Call(call, args) = parent_expr.kind
    443443
    && let ty::FnDef(def_id, _) = typeck.node_type(call.hir_id).kind()
    444444
    {
    445-
    (def_id.as_local(), args, 0)
    445+
    (Some(*def_id), args, 0)
    446446
    } else {
    447447
    (None, &[][..], 0)
    448448
    };
    449+
    450+
    // If the moved value is a mut reference, it is used in a
    451+
    // generic function and it's type is a generic param, it can be
    452+
    // reborrowed to avoid moving.
    453+
    // for example:
    454+
    // struct Y(u32);
    455+
    // x's type is '& mut Y' and it is used in `fn generic<T>(x: T) {}`.
    456+
    if let Some(def_id) = def_id
    457+
    && self.infcx.tcx.def_kind(def_id).is_fn_like()
    458+
    && let Some(pos) = args.iter().position(|arg| arg.hir_id == expr.hir_id)
    459+
    && let ty::Param(_) =
    460+
    self.infcx.tcx.fn_sig(def_id).skip_binder().skip_binder().inputs()
    461+
    [pos + offset]
    462+
    .kind()
    463+
    {
    464+
    let place = &self.move_data.move_paths[mpi].place;
    465+
    let ty = place.ty(self.body, self.infcx.tcx).ty;
    466+
    if let ty::Ref(_, _, hir::Mutability::Mut) = ty.kind() {
    467+
    *has_suggest_reborrow = true;
    468+
    self.suggest_reborrow(err, expr.span, moved_place);
    469+
    return;
    470+
    }
    471+
    }
    472+
    449473
    let mut can_suggest_clone = true;
    450474
    if let Some(def_id) = def_id
    451-
    && let node = self.infcx.tcx.hir_node_by_def_id(def_id)
    475+
    && let Some(local_def_id) = def_id.as_local()
    476+
    && let node = self.infcx.tcx.hir_node_by_def_id(local_def_id)
    452477
    && let Some(fn_sig) = node.fn_sig()
    453478
    && let Some(ident) = node.ident()
    454479
    && let Some(pos) = args.iter().position(|arg| arg.hir_id == expr.hir_id)
    @@ -622,6 +647,25 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
    622647
    }
    623648
    }
    624649

    650+
    pub fn suggest_reborrow(
    651+
    &self,
    652+
    err: &mut Diag<'infcx>,
    653+
    span: Span,
    654+
    moved_place: PlaceRef<'tcx>,
    655+
    ) {
    656+
    err.span_suggestion_verbose(
    657+
    span.shrink_to_lo(),
    658+
    format!(
    659+
    "consider creating a fresh reborrow of {} here",
    660+
    self.describe_place(moved_place)
    661+
    .map(|n| format!("`{n}`"))
    662+
    .unwrap_or_else(|| "the mutable reference".to_string()),
    663+
    ),
    664+
    "&mut *",
    665+
    Applicability::MachineApplicable,
    666+
    );
    667+
    }
    668+
    625669
    fn report_use_of_uninitialized(
    626670
    &self,
    627671
    mpi: MovePathIndex,

    compiler/rustc_borrowck/src/diagnostics/mod.rs

    Lines changed: 12 additions & 13 deletions
    Original file line numberDiff line numberDiff line change
    @@ -768,10 +768,11 @@ struct CapturedMessageOpt {
    768768
    is_loop_message: bool,
    769769
    is_move_msg: bool,
    770770
    is_loop_move: bool,
    771+
    has_suggest_reborrow: bool,
    771772
    maybe_reinitialized_locations_is_empty: bool,
    772773
    }
    773774

    774-
    impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> {
    775+
    impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
    775776
    /// Finds the spans associated to a move or copy of move_place at location.
    776777
    pub(super) fn move_spans(
    777778
    &self,
    @@ -997,7 +998,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> {
    997998
    #[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
    998999
    fn explain_captures(
    9991000
    &mut self,
    1000-
    err: &mut Diag<'_>,
    1001+
    err: &mut Diag<'infcx>,
    10011002
    span: Span,
    10021003
    move_span: Span,
    10031004
    move_spans: UseSpans<'tcx>,
    @@ -1009,6 +1010,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> {
    10091010
    is_loop_message,
    10101011
    is_move_msg,
    10111012
    is_loop_move,
    1013+
    has_suggest_reborrow,
    10121014
    maybe_reinitialized_locations_is_empty,
    10131015
    } = msg_opt;
    10141016
    if let UseSpans::FnSelfUse { var_span, fn_call_span, fn_span, kind } = move_spans {
    @@ -1182,18 +1184,15 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> {
    11821184
    if let ty::Ref(_, _, hir::Mutability::Mut) =
    11831185
    moved_place.ty(self.body, self.infcx.tcx).ty.kind()
    11841186
    {
    1185-
    // If we are in a loop this will be suggested later.
    1186-
    if !is_loop_move {
    1187-
    err.span_suggestion_verbose(
    1187+
    // Suggest `reborrow` in other place for following situations:
    1188+
    // 1. If we are in a loop this will be suggested later.
    1189+
    // 2. If the moved value is a mut reference, it is used in a
    1190+
    // generic function and the corresponding arg's type is generic param.
    1191+
    if !is_loop_move && !has_suggest_reborrow {
    1192+
    self.suggest_reborrow(
    1193+
    err,
    11881194
    move_span.shrink_to_lo(),
    1189-
    format!(
    1190-
    "consider creating a fresh reborrow of {} here",
    1191-
    self.describe_place(moved_place.as_ref())
    1192-
    .map(|n| format!("`{n}`"))
    1193-
    .unwrap_or_else(|| "the mutable reference".to_string()),
    1194-
    ),
    1195-
    "&mut *",
    1196-
    Applicability::MachineApplicable,
    1195+
    moved_place.as_ref(),
    11971196
    );
    11981197
    }
    11991198
    }

    compiler/rustc_borrowck/src/diagnostics/move_errors.rs

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -554,6 +554,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
    554554
    is_loop_message: false,
    555555
    is_move_msg: false,
    556556
    is_loop_move: false,
    557+
    has_suggest_reborrow: false,
    557558
    maybe_reinitialized_locations_is_empty: true,
    558559
    };
    559560
    if let Some(use_spans) = use_spans {

    compiler/rustc_data_structures/Cargo.toml

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -56,5 +56,5 @@ portable-atomic = "1.5.1"
    5656

    5757
    [features]
    5858
    # tidy-alphabetical-start
    59-
    rustc_use_parallel_compiler = ["indexmap/rustc-rayon", "rustc-rayon"]
    59+
    rustc_use_parallel_compiler = ["indexmap/rustc-rayon", "dep:rustc-rayon"]
    6060
    # tidy-alphabetical-end

    compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

    Lines changed: 17 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1105,7 +1105,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
    11051105
    } else {
    11061106
    "".to_string()
    11071107
    };
    1108-
    labels.push((provided_span, format!("unexpected argument{provided_ty_name}")));
    1108+
    let idx = if provided_arg_tys.len() == 1 {
    1109+
    "".to_string()
    1110+
    } else {
    1111+
    format!(" #{}", arg_idx.as_usize() + 1)
    1112+
    };
    1113+
    labels.push((
    1114+
    provided_span,
    1115+
    format!("unexpected argument{idx}{provided_ty_name}"),
    1116+
    ));
    11091117
    let mut span = provided_span;
    11101118
    if span.can_be_used_for_suggestions()
    11111119
    && error_span.can_be_used_for_suggestions()
    @@ -1186,7 +1194,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
    11861194
    } else {
    11871195
    "".to_string()
    11881196
    };
    1189-
    labels.push((span, format!("an argument{rendered} is missing")));
    1197+
    labels.push((
    1198+
    span,
    1199+
    format!(
    1200+
    "argument #{}{rendered} is missing",
    1201+
    expected_idx.as_usize() + 1
    1202+
    ),
    1203+
    ));
    1204+
    11901205
    suggestion_text = match suggestion_text {
    11911206
    SuggestionText::None => SuggestionText::Provide(false),
    11921207
    SuggestionText::Provide(_) => SuggestionText::Provide(true),

    compiler/rustc_index/Cargo.toml

    Lines changed: 5 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -15,5 +15,9 @@ smallvec = "1.8.1"
    1515
    [features]
    1616
    # tidy-alphabetical-start
    1717
    default = ["nightly"]
    18-
    nightly = ["rustc_serialize", "rustc_macros", "rustc_index_macros/nightly"]
    18+
    nightly = [
    19+
    "dep:rustc_serialize",
    20+
    "dep:rustc_macros",
    21+
    "rustc_index_macros/nightly",
    22+
    ]
    1923
    # tidy-alphabetical-end

    0 commit comments

    Comments
     (0)
    0