Skip to content

Commit 7a52736

Browse files
committed
Auto merge of #147475 - matthiaskrgr:rollup-iyrkv0g, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #144006 (clarify wording of match ergonomics diagnostics (`rust_2024_incompatible_pat` lint and error)) - #147386 (some more `proc_macro` cleanups) - #147412 (Convert impossible cases in macro resolution into assertions) - #147464 (prefer repeat_n() over repeat().take()) - #147469 (Add rustdoc crate name in error) - #147472 (refactor: replace `LLVMRustAtomicLoad/Store` with LLVM built-in functions) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 910617d + 359bfa9 commit 7a52736

35 files changed

+690
-660
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -639,13 +639,9 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
639639
size: Size,
640640
) -> &'ll Value {
641641
unsafe {
642-
let load = llvm::LLVMRustBuildAtomicLoad(
643-
self.llbuilder,
644-
ty,
645-
ptr,
646-
UNNAMED,
647-
AtomicOrdering::from_generic(order),
648-
);
642+
let load = llvm::LLVMBuildLoad2(self.llbuilder, ty, ptr, UNNAMED);
643+
// Set atomic ordering
644+
llvm::LLVMSetOrdering(load, AtomicOrdering::from_generic(order));
649645
// LLVM requires the alignment of atomic loads to be at least the size of the type.
650646
llvm::LLVMSetAlignment(load, size.bytes() as c_uint);
651647
load
@@ -872,12 +868,9 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
872868
debug!("Store {:?} -> {:?}", val, ptr);
873869
assert_eq!(self.cx.type_kind(self.cx.val_ty(ptr)), TypeKind::Pointer);
874870
unsafe {
875-
let store = llvm::LLVMRustBuildAtomicStore(
876-
self.llbuilder,
877-
val,
878-
ptr,
879-
AtomicOrdering::from_generic(order),
880-
);
871+
let store = llvm::LLVMBuildStore(self.llbuilder, val, ptr);
872+
// Set atomic ordering
873+
llvm::LLVMSetOrdering(store, AtomicOrdering::from_generic(order));
881874
// LLVM requires the alignment of atomic stores to be at least the size of the type.
882875
llvm::LLVMSetAlignment(store, size.bytes() as c_uint);
883876
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,7 @@ unsafe extern "C" {
11511151

11521152
// Operations on load/store instructions (only)
11531153
pub(crate) fn LLVMSetVolatile(MemoryAccessInst: &Value, volatile: Bool);
1154+
pub(crate) fn LLVMSetOrdering(MemoryAccessInst: &Value, Ordering: AtomicOrdering);
11541155

11551156
// Operations on phi nodes
11561157
pub(crate) fn LLVMAddIncoming<'a>(
@@ -2090,22 +2091,6 @@ unsafe extern "C" {
20902091
RHS: &'a Value,
20912092
) -> &'a Value;
20922093

2093-
// Atomic Operations
2094-
pub(crate) fn LLVMRustBuildAtomicLoad<'a>(
2095-
B: &Builder<'a>,
2096-
ElementType: &'a Type,
2097-
PointerVal: &'a Value,
2098-
Name: *const c_char,
2099-
Order: AtomicOrdering,
2100-
) -> &'a Value;
2101-
2102-
pub(crate) fn LLVMRustBuildAtomicStore<'a>(
2103-
B: &Builder<'a>,
2104-
Val: &'a Value,
2105-
Ptr: &'a Value,
2106-
Order: AtomicOrdering,
2107-
) -> &'a Value;
2108-
21092094
pub(crate) fn LLVMRustTimeTraceProfilerInitialize();
21102095

21112096
pub(crate) fn LLVMRustTimeTraceProfilerFinishThread();

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
878878
.compute_size_in_bytes(layout.size, count)
879879
.ok_or_else(|| err_ub_custom!(fluent::const_eval_size_overflow, name = name))?;
880880

881-
let bytes = std::iter::repeat(byte).take(len.bytes_usize());
881+
let bytes = std::iter::repeat_n(byte, len.bytes_usize());
882882
self.write_bytes_ptr(dst, bytes)
883883
}
884884

compiler/rustc_hir_typeck/src/pat.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3115,20 +3115,29 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
31153115
// binding mode. This keeps it from making those suggestions, as doing so could panic.
31163116
let info = table.entry(pat_id).or_insert_with(|| ty::Rust2024IncompatiblePatInfo {
31173117
primary_labels: Vec::new(),
3118-
bad_modifiers: false,
3118+
bad_ref_modifiers: false,
3119+
bad_mut_modifiers: false,
31193120
bad_ref_pats: false,
31203121
suggest_eliding_modes: !self.tcx.features().ref_pat_eat_one_layer_2024()
31213122
&& !self.tcx.features().ref_pat_eat_one_layer_2024_structural(),
31223123
});
31233124

31243125
let pat_kind = if let PatKind::Binding(user_bind_annot, _, _, _) = subpat.kind {
3125-
info.bad_modifiers = true;
31263126
// If the user-provided binding modifier doesn't match the default binding mode, we'll
31273127
// need to suggest reference patterns, which can affect other bindings.
31283128
// For simplicity, we opt to suggest making the pattern fully explicit.
31293129
info.suggest_eliding_modes &=
31303130
user_bind_annot == BindingMode(ByRef::Yes(def_br_mutbl), Mutability::Not);
3131-
"binding modifier"
3131+
if user_bind_annot == BindingMode(ByRef::No, Mutability::Mut) {
3132+
info.bad_mut_modifiers = true;
3133+
"`mut` binding modifier"
3134+
} else {
3135+
info.bad_ref_modifiers = true;
3136+
match user_bind_annot.1 {
3137+
Mutability::Not => "explicit `ref` binding modifier",
3138+
Mutability::Mut => "explicit `ref mut` binding modifier",
3139+
}
3140+
}
31323141
} else {
31333142
info.bad_ref_pats = true;
31343143
// For simplicity, we don't try to suggest eliding reference patterns. Thus, we'll
@@ -3147,11 +3156,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
31473156
// so, we may want to inspect the span's source callee or macro backtrace.
31483157
"occurs within macro expansion".to_owned()
31493158
} else {
3150-
let dbm_str = match def_br_mutbl {
3151-
Mutability::Not => "ref",
3152-
Mutability::Mut => "ref mut",
3153-
};
3154-
format!("{pat_kind} not allowed under `{dbm_str}` default binding mode")
3159+
format!("{pat_kind} not allowed when implicitly borrowing")
31553160
};
31563161
info.primary_labels.push((trimmed_span, primary_label));
31573162
}

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,7 @@ declare_lint! {
16011601
"detects patterns whose meaning will change in Rust 2024",
16021602
@future_incompatible = FutureIncompatibleInfo {
16031603
reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
1604-
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>",
1604+
reference: "<https://doc.rust-lang.org/edition-guide/rust-2024/match-ergonomics.html>",
16051605
};
16061606
}
16071607

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,6 @@ using namespace llvm::object;
6060
static_assert(dwarf::DW_OP_LLVM_fragment == 0x1000);
6161
static_assert(dwarf::DW_OP_stack_value == 0x9f);
6262

63-
// LLVMAtomicOrdering is already an enum - don't create another
64-
// one.
65-
static AtomicOrdering fromRust(LLVMAtomicOrdering Ordering) {
66-
switch (Ordering) {
67-
case LLVMAtomicOrderingNotAtomic:
68-
return AtomicOrdering::NotAtomic;
69-
case LLVMAtomicOrderingUnordered:
70-
return AtomicOrdering::Unordered;
71-
case LLVMAtomicOrderingMonotonic:
72-
return AtomicOrdering::Monotonic;
73-
case LLVMAtomicOrderingAcquire:
74-
return AtomicOrdering::Acquire;
75-
case LLVMAtomicOrderingRelease:
76-
return AtomicOrdering::Release;
77-
case LLVMAtomicOrderingAcquireRelease:
78-
return AtomicOrdering::AcquireRelease;
79-
case LLVMAtomicOrderingSequentiallyConsistent:
80-
return AtomicOrdering::SequentiallyConsistent;
81-
}
82-
83-
report_fatal_error("Invalid LLVMAtomicOrdering value!");
84-
}
85-
8663
static LLVM_THREAD_LOCAL char *LastError;
8764

8865
// Custom error handler for fatal LLVM errors.
@@ -623,24 +600,6 @@ extern "C" void LLVMRustSetAllowReassoc(LLVMValueRef V) {
623600
}
624601
}
625602

626-
extern "C" LLVMValueRef
627-
LLVMRustBuildAtomicLoad(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Source,
628-
const char *Name, LLVMAtomicOrdering Order) {
629-
Value *Ptr = unwrap(Source);
630-
LoadInst *LI = unwrap(B)->CreateLoad(unwrap(Ty), Ptr, Name);
631-
LI->setAtomic(fromRust(Order));
632-
return wrap(LI);
633-
}
634-
635-
extern "C" LLVMValueRef LLVMRustBuildAtomicStore(LLVMBuilderRef B,
636-
LLVMValueRef V,
637-
LLVMValueRef Target,
638-
LLVMAtomicOrdering Order) {
639-
StoreInst *SI = unwrap(B)->CreateStore(unwrap(V), unwrap(Target));
640-
SI->setAtomic(fromRust(Order));
641-
return wrap(SI);
642-
}
643-
644603
extern "C" uint64_t LLVMRustGetArrayNumElements(LLVMTypeRef Ty) {
645604
return unwrap(Ty)->getArrayNumElements();
646605
}

compiler/rustc_middle/src/ty/typeck_results.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -858,8 +858,10 @@ impl<'tcx> std::fmt::Display for UserTypeKind<'tcx> {
858858
pub struct Rust2024IncompatiblePatInfo {
859859
/// Labeled spans for `&`s, `&mut`s, and binding modifiers incompatible with Rust 2024.
860860
pub primary_labels: Vec<(Span, String)>,
861-
/// Whether any binding modifiers occur under a non-`move` default binding mode.
862-
pub bad_modifiers: bool,
861+
/// Whether any `mut` binding modifiers occur under a non-`move` default binding mode.
862+
pub bad_mut_modifiers: bool,
863+
/// Whether any `ref`/`ref mut` binding modifiers occur under a non-`move` default binding mode.
864+
pub bad_ref_modifiers: bool,
863865
/// Whether any `&` or `&mut` patterns occur under a non-`move` default binding mode.
864866
pub bad_ref_pats: bool,
865867
/// If `true`, we can give a simpler suggestion solely by eliding explicit binding modifiers.

compiler/rustc_mir_build/messages.ftl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -322,17 +322,6 @@ mir_build_pointer_pattern = function pointers and raw pointers not derived from
322322
323323
mir_build_privately_uninhabited = pattern `{$witness_1}` is currently uninhabited, but this variant contains private fields which may become inhabited in the future
324324
325-
mir_build_rust_2024_incompatible_pat = {$bad_modifiers ->
326-
*[true] binding modifiers{$bad_ref_pats ->
327-
*[true] {" "}and reference patterns
328-
[false] {""}
329-
}
330-
[false] reference patterns
331-
} may only be written when the default binding mode is `move`{$is_hard_error ->
332-
*[true] {""}
333-
[false] {" "}in Rust 2024
334-
}
335-
336325
mir_build_static_in_pattern = statics cannot be referenced in patterns
337326
.label = can't be used in patterns
338327
mir_build_static_in_pattern_def = `static` defined here

compiler/rustc_mir_build/src/errors.rs

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use rustc_data_structures::fx::FxIndexMap;
21
use rustc_errors::codes::*;
32
use rustc_errors::{
43
Applicability, Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level,
5-
MultiSpan, Subdiagnostic, pluralize,
4+
MultiSpan, Subdiagnostic,
65
};
76
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
87
use rustc_middle::ty::{self, Ty};
@@ -1087,69 +1086,6 @@ pub(crate) enum MiscPatternSuggestion {
10871086
},
10881087
}
10891088

1090-
#[derive(LintDiagnostic)]
1091-
#[diag(mir_build_rust_2024_incompatible_pat)]
1092-
pub(crate) struct Rust2024IncompatiblePat {
1093-
#[subdiagnostic]
1094-
pub(crate) sugg: Rust2024IncompatiblePatSugg,
1095-
pub(crate) bad_modifiers: bool,
1096-
pub(crate) bad_ref_pats: bool,
1097-
pub(crate) is_hard_error: bool,
1098-
}
1099-
1100-
pub(crate) struct Rust2024IncompatiblePatSugg {
1101-
/// If true, our suggestion is to elide explicit binding modifiers.
1102-
/// If false, our suggestion is to make the pattern fully explicit.
1103-
pub(crate) suggest_eliding_modes: bool,
1104-
pub(crate) suggestion: Vec<(Span, String)>,
1105-
pub(crate) ref_pattern_count: usize,
1106-
pub(crate) binding_mode_count: usize,
1107-
/// Labels for where incompatibility-causing by-ref default binding modes were introduced.
1108-
pub(crate) default_mode_labels: FxIndexMap<Span, ty::Mutability>,
1109-
}
1110-
1111-
impl Subdiagnostic for Rust2024IncompatiblePatSugg {
1112-
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1113-
// Format and emit explanatory notes about default binding modes. Reversing the spans' order
1114-
// means if we have nested spans, the innermost ones will be visited first.
1115-
for (span, def_br_mutbl) in self.default_mode_labels.into_iter().rev() {
1116-
// Don't point to a macro call site.
1117-
if !span.from_expansion() {
1118-
let note_msg = "matching on a reference type with a non-reference pattern changes the default binding mode";
1119-
let label_msg =
1120-
format!("this matches on type `{}_`", def_br_mutbl.ref_prefix_str());
1121-
let mut label = MultiSpan::from(span);
1122-
label.push_span_label(span, label_msg);
1123-
diag.span_note(label, note_msg);
1124-
}
1125-
}
1126-
1127-
// Format and emit the suggestion.
1128-
let applicability =
1129-
if self.suggestion.iter().all(|(span, _)| span.can_be_used_for_suggestions()) {
1130-
Applicability::MachineApplicable
1131-
} else {
1132-
Applicability::MaybeIncorrect
1133-
};
1134-
let msg = if self.suggest_eliding_modes {
1135-
let plural_modes = pluralize!(self.binding_mode_count);
1136-
format!("remove the unnecessary binding modifier{plural_modes}")
1137-
} else {
1138-
let plural_derefs = pluralize!(self.ref_pattern_count);
1139-
let and_modes = if self.binding_mode_count > 0 {
1140-
format!(" and variable binding mode{}", pluralize!(self.binding_mode_count))
1141-
} else {
1142-
String::new()
1143-
};
1144-
format!("make the implied reference pattern{plural_derefs}{and_modes} explicit")
1145-
};
1146-
// FIXME(dianne): for peace of mind, don't risk emitting a 0-part suggestion (that panics!)
1147-
if !self.suggestion.is_empty() {
1148-
diag.multipart_suggestion_verbose(msg, self.suggestion, applicability);
1149-
}
1150-
}
1151-
}
1152-
11531089
#[derive(Diagnostic)]
11541090
#[diag(mir_build_loop_match_invalid_update)]
11551091
pub(crate) struct LoopMatchInvalidUpdate {

0 commit comments

Comments
 (0)