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

Commit e390237

Browse files
committed
Auto merge of rust-lang#127614 - matthiaskrgr:rollup-8geziwi, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#124599 (Suggest borrowing on fn argument that is `impl AsRef`) - rust-lang#127572 (Don't mark `DEBUG_EVENT` struct as `repr(packed)`) - rust-lang#127588 (core: Limit remaining f16 doctests to x86_64 linux) - rust-lang#127591 (Make sure that labels are defined after the primary span in diagnostics) - rust-lang#127598 (Allows `#[diagnostic::do_not_recommend]` to supress trait impls in suggestions as well) - rust-lang#127599 (Rename `lazy_cell_consume` to `lazy_cell_into_inner`) - rust-lang#127601 (check is_ident before parse_ident) - rust-lang#127605 (Remove extern "wasm" ABI) r? `@ghost` `@rustbot` modify labels: rollup
2 parents bcf1f6d + fa3ce50 commit e390237

File tree

45 files changed

+447
-409
lines changed

Some content is hidden

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

45 files changed

+447
-409
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 70 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -445,31 +445,81 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
445445
} else {
446446
(None, &[][..], 0)
447447
};
448+
let mut can_suggest_clone = true;
448449
if let Some(def_id) = def_id
449450
&& let node = self.infcx.tcx.hir_node_by_def_id(def_id)
450451
&& let Some(fn_sig) = node.fn_sig()
451452
&& let Some(ident) = node.ident()
452453
&& let Some(pos) = args.iter().position(|arg| arg.hir_id == expr.hir_id)
453454
&& let Some(arg) = fn_sig.decl.inputs.get(pos + offset)
454455
{
455-
let mut span: MultiSpan = arg.span.into();
456-
span.push_span_label(
457-
arg.span,
458-
"this parameter takes ownership of the value".to_string(),
459-
);
460-
let descr = match node.fn_kind() {
461-
Some(hir::intravisit::FnKind::ItemFn(..)) | None => "function",
462-
Some(hir::intravisit::FnKind::Method(..)) => "method",
463-
Some(hir::intravisit::FnKind::Closure) => "closure",
464-
};
465-
span.push_span_label(ident.span, format!("in this {descr}"));
466-
err.span_note(
467-
span,
468-
format!(
469-
"consider changing this parameter type in {descr} `{ident}` to borrow \
470-
instead if owning the value isn't necessary",
471-
),
472-
);
456+
let mut is_mut = false;
457+
if let hir::TyKind::Path(hir::QPath::Resolved(None, path)) = arg.kind
458+
&& let Res::Def(DefKind::TyParam, param_def_id) = path.res
459+
&& self
460+
.infcx
461+
.tcx
462+
.predicates_of(def_id)
463+
.instantiate_identity(self.infcx.tcx)
464+
.predicates
465+
.into_iter()
466+
.any(|pred| {
467+
if let ty::ClauseKind::Trait(predicate) = pred.kind().skip_binder()
468+
&& [
469+
self.infcx.tcx.get_diagnostic_item(sym::AsRef),
470+
self.infcx.tcx.get_diagnostic_item(sym::AsMut),
471+
self.infcx.tcx.get_diagnostic_item(sym::Borrow),
472+
self.infcx.tcx.get_diagnostic_item(sym::BorrowMut),
473+
]
474+
.contains(&Some(predicate.def_id()))
475+
&& let ty::Param(param) = predicate.self_ty().kind()
476+
&& let generics = self.infcx.tcx.generics_of(def_id)
477+
&& let param = generics.type_param(*param, self.infcx.tcx)
478+
&& param.def_id == param_def_id
479+
{
480+
if [
481+
self.infcx.tcx.get_diagnostic_item(sym::AsMut),
482+
self.infcx.tcx.get_diagnostic_item(sym::BorrowMut),
483+
]
484+
.contains(&Some(predicate.def_id()))
485+
{
486+
is_mut = true;
487+
}
488+
true
489+
} else {
490+
false
491+
}
492+
})
493+
{
494+
// The type of the argument corresponding to the expression that got moved
495+
// is a type parameter `T`, which is has a `T: AsRef` obligation.
496+
err.span_suggestion_verbose(
497+
expr.span.shrink_to_lo(),
498+
"borrow the value to avoid moving it",
499+
format!("&{}", if is_mut { "mut " } else { "" }),
500+
Applicability::MachineApplicable,
501+
);
502+
can_suggest_clone = is_mut;
503+
} else {
504+
let mut span: MultiSpan = arg.span.into();
505+
span.push_span_label(
506+
arg.span,
507+
"this parameter takes ownership of the value".to_string(),
508+
);
509+
let descr = match node.fn_kind() {
510+
Some(hir::intravisit::FnKind::ItemFn(..)) | None => "function",
511+
Some(hir::intravisit::FnKind::Method(..)) => "method",
512+
Some(hir::intravisit::FnKind::Closure) => "closure",
513+
};
514+
span.push_span_label(ident.span, format!("in this {descr}"));
515+
err.span_note(
516+
span,
517+
format!(
518+
"consider changing this parameter type in {descr} `{ident}` to \
519+
borrow instead if owning the value isn't necessary",
520+
),
521+
);
522+
}
473523
}
474524
let place = &self.move_data.move_paths[mpi].place;
475525
let ty = place.ty(self.body, self.infcx.tcx).ty;
@@ -487,9 +537,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
487537
ClosureKind::Coroutine(CoroutineKind::Desugared(_, CoroutineSource::Block)),
488538
..
489539
} = move_spans
540+
&& can_suggest_clone
490541
{
491542
self.suggest_cloning(err, ty, expr, None, Some(move_spans));
492-
} else if self.suggest_hoisting_call_outside_loop(err, expr) {
543+
} else if self.suggest_hoisting_call_outside_loop(err, expr) && can_suggest_clone {
493544
// The place where the type moves would be misleading to suggest clone.
494545
// #121466
495546
self.suggest_cloning(err, ty, expr, None, Some(move_spans));

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, PatchableFuncti
66
use rustc_middle::ty::{self, TyCtxt};
77
use rustc_session::config::{FunctionReturn, OptLevel};
88
use rustc_span::symbol::sym;
9-
use rustc_target::spec::abi::Abi;
109
use rustc_target::spec::{FramePointer, SanitizerSet, StackProbeType, StackProtector};
1110
use smallvec::SmallVec;
1211

@@ -482,7 +481,7 @@ pub fn from_fn_attrs<'ll, 'tcx>(
482481
return;
483482
}
484483

485-
let mut function_features = function_features
484+
let function_features = function_features
486485
.iter()
487486
.flat_map(|feat| {
488487
llvm_util::to_llvm_features(cx.tcx.sess, feat).into_iter().map(|f| format!("+{f}"))
@@ -504,17 +503,6 @@ pub fn from_fn_attrs<'ll, 'tcx>(
504503
let name = name.as_str();
505504
to_add.push(llvm::CreateAttrStringValue(cx.llcx, "wasm-import-name", name));
506505
}
507-
508-
// The `"wasm"` abi on wasm targets automatically enables the
509-
// `+multivalue` feature because the purpose of the wasm abi is to match
510-
// the WebAssembly specification, which has this feature. This won't be
511-
// needed when LLVM enables this `multivalue` feature by default.
512-
if !cx.tcx.is_closure_like(instance.def_id()) {
513-
let abi = cx.tcx.fn_sig(instance.def_id()).skip_binder().abi();
514-
if abi == Abi::Wasm {
515-
function_features.push("+multivalue".to_string());
516-
}
517-
}
518506
}
519507

520508
let global_features = cx.tcx.global_backend_features(()).iter().map(|s| s.as_str());

compiler/rustc_feature/src/removed.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ declare_features! (
215215
/// Permits specifying whether a function should permit unwinding or abort on unwind.
216216
(removed, unwind_attributes, "1.56.0", Some(58760), Some("use the C-unwind ABI instead")),
217217
(removed, visible_private_types, "1.0.0", None, None),
218+
/// Allows `extern "wasm" fn`
219+
(removed, wasm_abi, "CURRENT_RUSTC_VERSION", Some(83788),
220+
Some("non-standard wasm ABI is no longer supported")),
218221
// !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!!
219222
// Features are listed in alphabetical order. Tidy will fail if you don't keep it this way.
220223
// !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!!

compiler/rustc_feature/src/unstable.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,6 @@ declare_features! (
640640
(unstable, unsized_tuple_coercion, "1.20.0", Some(42877)),
641641
/// Allows using the `#[used(linker)]` (or `#[used(compiler)]`) attribute.
642642
(unstable, used_with_arg, "1.60.0", Some(93798)),
643-
/// Allows `extern "wasm" fn`
644-
(unstable, wasm_abi, "1.53.0", Some(83788)),
645643
/// Allows `do yeet` expressions
646644
(unstable, yeet_expr, "1.62.0", Some(96373)),
647645
// !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!!

compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ impl DiagnosticDeriveVariantBuilder {
269269
let field_binding = &binding_info.binding;
270270

271271
let inner_ty = FieldInnerTy::from_type(&field.ty);
272+
let mut seen_label = false;
272273

273274
field
274275
.attrs
@@ -280,6 +281,14 @@ impl DiagnosticDeriveVariantBuilder {
280281
}
281282

282283
let name = attr.path().segments.last().unwrap().ident.to_string();
284+
285+
if name == "primary_span" && seen_label {
286+
span_err(attr.span().unwrap(), format!("`#[primary_span]` must be placed before labels, since it overwrites the span of the diagnostic")).emit();
287+
}
288+
if name == "label" {
289+
seen_label = true;
290+
}
291+
283292
let needs_clone =
284293
name == "primary_span" && matches!(inner_ty, FieldInnerTy::Vec(_));
285294
let (binding, needs_destructure) = if needs_clone {

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,6 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: SpecAbi) ->
12121212
| RiscvInterruptM
12131213
| RiscvInterruptS
12141214
| CCmseNonSecureCall
1215-
| Wasm
12161215
| Unadjusted => false,
12171216
Rust | RustCall | RustCold | RustIntrinsic => {
12181217
tcx.sess.panic_strategy() == PanicStrategy::Unwind

compiler/rustc_parse/src/parser/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,8 @@ impl<'a> Parser<'a> {
387387
let span = if is_pub { self.prev_token.span.to(ident_span) } else { ident_span };
388388
let insert_span = ident_span.shrink_to_lo();
389389

390-
let ident = if (!is_const
391-
|| self.look_ahead(1, |t| *t == token::OpenDelim(Delimiter::Parenthesis)))
390+
let ident = if self.token.is_ident()
391+
&& (!is_const || self.look_ahead(1, |t| *t == token::OpenDelim(Delimiter::Parenthesis)))
392392
&& self.look_ahead(1, |t| {
393393
[
394394
token::Lt,

compiler/rustc_resolve/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,8 +1089,8 @@ pub(crate) struct ToolWasAlreadyRegistered {
10891089
#[derive(Diagnostic)]
10901090
#[diag(resolve_tool_only_accepts_identifiers)]
10911091
pub(crate) struct ToolOnlyAcceptsIdentifiers {
1092-
#[label]
10931092
#[primary_span]
1093+
#[label]
10941094
pub(crate) span: Span,
10951095
pub(crate) tool: Symbol,
10961096
}

compiler/rustc_smir/src/rustc_internal/internal.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,6 @@ impl RustcInternal for Abi {
466466
Abi::AvrInterrupt => rustc_target::spec::abi::Abi::AvrInterrupt,
467467
Abi::AvrNonBlockingInterrupt => rustc_target::spec::abi::Abi::AvrNonBlockingInterrupt,
468468
Abi::CCmseNonSecureCall => rustc_target::spec::abi::Abi::CCmseNonSecureCall,
469-
Abi::Wasm => rustc_target::spec::abi::Abi::Wasm,
470469
Abi::System { unwind } => rustc_target::spec::abi::Abi::System { unwind },
471470
Abi::RustIntrinsic => rustc_target::spec::abi::Abi::RustIntrinsic,
472471
Abi::RustCall => rustc_target::spec::abi::Abi::RustCall,

compiler/rustc_smir/src/rustc_smir/convert/ty.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,6 @@ impl<'tcx> Stable<'tcx> for rustc_target::spec::abi::Abi {
909909
abi::Abi::AvrInterrupt => Abi::AvrInterrupt,
910910
abi::Abi::AvrNonBlockingInterrupt => Abi::AvrNonBlockingInterrupt,
911911
abi::Abi::CCmseNonSecureCall => Abi::CCmseNonSecureCall,
912-
abi::Abi::Wasm => Abi::Wasm,
913912
abi::Abi::System { unwind } => Abi::System { unwind },
914913
abi::Abi::RustIntrinsic => Abi::RustIntrinsic,
915914
abi::Abi::RustCall => Abi::RustCall,

0 commit comments

Comments
 (0)