Skip to content

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

+70-19
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

+1-13
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

+3
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

-2
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

+9
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

-1
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

+2-2
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

+1-1
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

-1
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

-1
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,

compiler/rustc_target/src/abi/call/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::abi::{self, Abi, Align, FieldsShape, Size};
22
use crate::abi::{HasDataLayout, TyAbiInterface, TyAndLayout};
3-
use crate::spec::{self, HasTargetSpec, HasWasmCAbiOpt};
3+
use crate::spec::{self, HasTargetSpec, HasWasmCAbiOpt, WasmCAbi};
44
use rustc_macros::HashStable_Generic;
55
use rustc_span::Symbol;
66
use std::fmt;
@@ -854,7 +854,8 @@ impl<'a, Ty> FnAbi<'a, Ty> {
854854
return Ok(());
855855
}
856856

857-
match &cx.target_spec().arch[..] {
857+
let spec = cx.target_spec();
858+
match &spec.arch[..] {
858859
"x86" => {
859860
let flavor = if let spec::abi::Abi::Fastcall { .. }
860861
| spec::abi::Abi::Vectorcall { .. } = abi
@@ -901,9 +902,7 @@ impl<'a, Ty> FnAbi<'a, Ty> {
901902
"sparc" => sparc::compute_abi_info(cx, self),
902903
"sparc64" => sparc64::compute_abi_info(cx, self),
903904
"nvptx64" => {
904-
if cx.target_spec().adjust_abi(cx, abi, self.c_variadic)
905-
== spec::abi::Abi::PtxKernel
906-
{
905+
if cx.target_spec().adjust_abi(abi, self.c_variadic) == spec::abi::Abi::PtxKernel {
907906
nvptx64::compute_ptx_kernel_abi_info(cx, self)
908907
} else {
909908
nvptx64::compute_abi_info(self)
@@ -912,13 +911,14 @@ impl<'a, Ty> FnAbi<'a, Ty> {
912911
"hexagon" => hexagon::compute_abi_info(self),
913912
"xtensa" => xtensa::compute_abi_info(cx, self),
914913
"riscv32" | "riscv64" => riscv::compute_abi_info(cx, self),
915-
"wasm32" | "wasm64" => {
916-
if cx.target_spec().adjust_abi(cx, abi, self.c_variadic) == spec::abi::Abi::Wasm {
914+
"wasm32" => {
915+
if spec.os == "unknown" && cx.wasm_c_abi_opt() == WasmCAbi::Legacy {
917916
wasm::compute_wasm_abi_info(self)
918917
} else {
919918
wasm::compute_c_abi_info(cx, self)
920919
}
921920
}
921+
"wasm64" => wasm::compute_c_abi_info(cx, self),
922922
"bpf" => bpf::compute_abi_info(self),
923923
arch => {
924924
return Err(AdjustForForeignAbiError::Unsupported {

compiler/rustc_target/src/spec/abi/mod.rs

+11-15
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ pub enum Abi {
4848
AvrInterrupt,
4949
AvrNonBlockingInterrupt,
5050
CCmseNonSecureCall,
51-
Wasm,
5251
System {
5352
unwind: bool,
5453
},
@@ -123,7 +122,6 @@ const AbiDatas: &[AbiData] = &[
123122
AbiData { abi: Abi::AvrInterrupt, name: "avr-interrupt" },
124123
AbiData { abi: Abi::AvrNonBlockingInterrupt, name: "avr-non-blocking-interrupt" },
125124
AbiData { abi: Abi::CCmseNonSecureCall, name: "C-cmse-nonsecure-call" },
126-
AbiData { abi: Abi::Wasm, name: "wasm" },
127125
AbiData { abi: Abi::System { unwind: false }, name: "system" },
128126
AbiData { abi: Abi::System { unwind: true }, name: "system-unwind" },
129127
AbiData { abi: Abi::RustIntrinsic, name: "rust-intrinsic" },
@@ -149,6 +147,9 @@ pub fn lookup(name: &str) -> Result<Abi, AbiUnsupported> {
149147
"riscv-interrupt-u" => AbiUnsupported::Reason {
150148
explain: "user-mode interrupt handlers have been removed from LLVM pending standardization, see: https://reviews.llvm.org/D149314",
151149
},
150+
"wasm" => AbiUnsupported::Reason {
151+
explain: "non-standard wasm ABI is no longer supported",
152+
},
152153

153154
_ => AbiUnsupported::Unrecognized,
154155

@@ -241,10 +242,6 @@ pub fn is_stable(name: &str) -> Result<(), AbiDisabled> {
241242
feature: sym::abi_c_cmse_nonsecure_call,
242243
explain: "C-cmse-nonsecure-call ABI is experimental and subject to change",
243244
}),
244-
"wasm" => Err(AbiDisabled::Unstable {
245-
feature: sym::wasm_abi,
246-
explain: "wasm ABI is experimental and subject to change",
247-
}),
248245
_ => Err(AbiDisabled::Unrecognized),
249246
}
250247
}
@@ -287,16 +284,15 @@ impl Abi {
287284
AvrInterrupt => 23,
288285
AvrNonBlockingInterrupt => 24,
289286
CCmseNonSecureCall => 25,
290-
Wasm => 26,
291287
// Cross-platform ABIs
292-
System { unwind: false } => 27,
293-
System { unwind: true } => 28,
294-
RustIntrinsic => 29,
295-
RustCall => 30,
296-
Unadjusted => 31,
297-
RustCold => 32,
298-
RiscvInterruptM => 33,
299-
RiscvInterruptS => 34,
288+
System { unwind: false } => 26,
289+
System { unwind: true } => 27,
290+
RustIntrinsic => 28,
291+
RustCall => 29,
292+
Unadjusted => 30,
293+
RustCold => 31,
294+
RiscvInterruptM => 32,
295+
RiscvInterruptS => 33,
300296
};
301297
debug_assert!(
302298
AbiDatas

compiler/rustc_target/src/spec/mod.rs

+1-16
Original file line numberDiff line numberDiff line change
@@ -2608,22 +2608,8 @@ impl DerefMut for Target {
26082608

26092609
impl Target {
26102610
/// Given a function ABI, turn it into the correct ABI for this target.
2611-
pub fn adjust_abi<C>(&self, cx: &C, abi: Abi, c_variadic: bool) -> Abi
2612-
where
2613-
C: HasWasmCAbiOpt,
2614-
{
2611+
pub fn adjust_abi(&self, abi: Abi, c_variadic: bool) -> Abi {
26152612
match abi {
2616-
Abi::C { .. } => {
2617-
if self.arch == "wasm32"
2618-
&& self.os == "unknown"
2619-
&& cx.wasm_c_abi_opt() == WasmCAbi::Legacy
2620-
{
2621-
Abi::Wasm
2622-
} else {
2623-
abi
2624-
}
2625-
}
2626-
26272613
// On Windows, `extern "system"` behaves like msvc's `__stdcall`.
26282614
// `__stdcall` only applies on x86 and on non-variadic functions:
26292615
// https://learn.microsoft.com/en-us/cpp/cpp/stdcall?view=msvc-170
@@ -2676,7 +2662,6 @@ impl Target {
26762662
Msp430Interrupt => self.arch == "msp430",
26772663
RiscvInterruptM | RiscvInterruptS => ["riscv32", "riscv64"].contains(&&self.arch[..]),
26782664
AvrInterrupt | AvrNonBlockingInterrupt => self.arch == "avr",
2679-
Wasm => ["wasm32", "wasm64"].contains(&&self.arch[..]),
26802665
Thiscall { .. } => self.arch == "x86",
26812666
// On windows these fall-back to platform native calling convention (C) when the
26822667
// architecture is not supported.

0 commit comments

Comments
 (0)