Skip to content

Commit 8c1d720

Browse files
committed
Auto merge of rust-lang#157064 - JonathanBrouwer:rollup-BDFNumV, r=JonathanBrouwer
Rollup of 7 pull requests Successful merges: - rust-lang#157046 (file locking: clarify that double-locking is underspecified) - rust-lang#156401 (rustdoc: deterministic sorting for `doc_cfg` badges) - rust-lang#156746 (cg_llvm: Use `LLVMDIBuilderCreateEnumeratorOfArbitraryPrecision`) - rust-lang#156889 (Suggest function-local constructors without enclosing function path) - rust-lang#157012 (Fix missing note of escaping `{` for braces including whitespaces) - rust-lang#157056 (Update Xtensa target data layouts to match upstream LLVM) - rust-lang#157062 (Add link to RFMF Sponsors page)
2 parents b5e038d + 5cd06d1 commit 8c1d720

30 files changed

Lines changed: 520 additions & 99 deletions

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
github: rustfoundation
12
custom: ["rust-lang.org/funding"]

compiler/rustc_builtin_macros/src/format.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,7 @@ fn report_invalid_references(
987987
// Collect all the implicit positions:
988988
let mut spans = Vec::new();
989989
let mut num_placeholders = 0;
990+
let mut has_white_space_only_missing_arg = false;
990991
for piece in template {
991992
let mut placeholder = None;
992993
// `{arg:.*}`
@@ -1009,13 +1010,21 @@ fn report_invalid_references(
10091010
}
10101011
// `{}`
10111012
if let FormatArgsPiece::Placeholder(FormatPlaceholder {
1012-
argument: FormatArgPosition { kind: FormatArgPositionKind::Implicit, .. },
1013+
argument: FormatArgPosition { kind: FormatArgPositionKind::Implicit, index, .. },
10131014
span,
10141015
..
10151016
}) = piece
10161017
{
10171018
placeholder = *span;
10181019
num_placeholders += 1;
1020+
// Check whether there's any non-space whitespace in the placeholder. If so, we should emit a note suggesting an escaping `{`.
1021+
if index.is_err()
1022+
&& let Some(span) = span
1023+
&& let Ok(snippet) = ecx.source_map().span_to_snippet(*span)
1024+
&& snippet.chars().any(|c| c.is_whitespace() && c != ' ')
1025+
{
1026+
has_white_space_only_missing_arg = true;
1027+
}
10191028
}
10201029
// For `{:.*}`, we only push one span.
10211030
spans.extend(placeholder);
@@ -1071,6 +1080,9 @@ fn report_invalid_references(
10711080
if has_precision_star {
10721081
e.note("positional arguments are zero-based");
10731082
}
1083+
if has_white_space_only_missing_arg {
1084+
e.note("if you intended to print `{`, you can escape it with `{{`");
1085+
}
10741086
} else {
10751087
let mut indexes: Vec<_> = invalid_refs.iter().map(|&(index, _, _, _)| index).collect();
10761088
// Avoid `invalid reference to positional arguments 7 and 7 (there is 1 argument)`

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use crate::debuginfo::metadata::{
2121
file_metadata_from_def_id, type_di_node, unknown_file_metadata,
2222
};
2323
use crate::debuginfo::utils::{DIB, create_DIArray, get_namespace_for_item};
24-
use crate::llvm;
2524
use crate::llvm::debuginfo::{DIFlags, DIType};
25+
use crate::llvm::{self, ToLlvmBool};
2626

2727
mod cpp_like;
2828
mod native;
@@ -111,16 +111,23 @@ fn build_enumeration_type_di_node<'ll, 'tcx>(
111111
let (size, align) = cx.size_and_align_of(base_type);
112112

113113
let enumerator_di_nodes: SmallVec<Option<&'ll DIType>> = enumerators
114-
.map(|(name, value)| unsafe {
115-
let value = [value as u64, (value >> 64) as u64];
116-
Some(llvm::LLVMRustDIBuilderCreateEnumerator(
117-
DIB(cx),
118-
name.as_c_char_ptr(),
119-
name.len(),
120-
value.as_ptr(),
121-
size.bits() as libc::c_uint,
122-
is_unsigned,
123-
))
114+
.map(|(name, value)| {
115+
let value_words = [value as u64, (value >> 64) as u64];
116+
let size_in_bits = size.bits();
117+
// LLVM computes `NumWords = (SizeInBits + 63) / 64`.
118+
assert!((size_in_bits + 63) / 64 <= value_words.len() as u64);
119+
120+
let enumerator = unsafe {
121+
llvm::LLVMDIBuilderCreateEnumeratorOfArbitraryPrecision(
122+
DIB(cx),
123+
name.as_ptr(),
124+
name.len(),
125+
size_in_bits,
126+
value_words.as_ptr(),
127+
is_unsigned.to_llvm_bool(),
128+
)
129+
};
130+
Some(enumerator)
124131
})
125132
.collect();
126133

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ use libc::{c_char, c_int, c_uchar, c_uint, c_ulonglong, c_void, size_t};
2222

2323
use super::RustString;
2424
use super::debuginfo::{
25-
DIArray, DIBuilder, DIDerivedType, DIDescriptor, DIEnumerator, DIFile, DIFlags, DILocation,
26-
DISPFlags, DIScope, DISubprogram, DITemplateTypeParameter, DIType, DebugEmissionKind,
27-
DebugNameTableKind,
25+
DIArray, DIBuilder, DIDerivedType, DIDescriptor, DIFile, DIFlags, DILocation, DISPFlags,
26+
DIScope, DISubprogram, DITemplateTypeParameter, DIType, DebugEmissionKind, DebugNameTableKind,
2827
};
2928
use crate::llvm::MetadataKindId;
3029
use crate::{TryFromU32, llvm};
@@ -752,7 +751,6 @@ pub(crate) mod debuginfo {
752751
pub(crate) type DICompositeType = DIDerivedType;
753752
pub(crate) type DIVariable = DIDescriptor;
754753
pub(crate) type DIArray = DIDescriptor;
755-
pub(crate) type DIEnumerator = DIDescriptor;
756754
pub(crate) type DITemplateTypeParameter = DIDescriptor;
757755

758756
bitflags! {
@@ -1794,6 +1792,15 @@ unsafe extern "C" {
17941792
Flags: DIFlags, // (default is `DIFlags::DIFlagZero`)
17951793
) -> &'ll Metadata;
17961794

1795+
pub(crate) fn LLVMDIBuilderCreateEnumeratorOfArbitraryPrecision<'ll>(
1796+
Builder: &DIBuilder<'ll>,
1797+
Name: *const c_uchar, // See "PTR_LEN_STR".
1798+
NameLen: size_t,
1799+
SizeInBits: u64,
1800+
Words: *const u64, // LLVM computes `NumWords = (SizeInBits + 63) / 64`.
1801+
IsUnsigned: llvm::Bool,
1802+
) -> &'ll Metadata;
1803+
17971804
pub(crate) fn LLVMDIBuilderCreateUnionType<'ll>(
17981805
Builder: &DIBuilder<'ll>,
17991806
Scope: Option<&'ll Metadata>,
@@ -1989,6 +1996,7 @@ unsafe extern "C" {
19891996
pub(crate) fn LLVMRustDisableSystemDialogsOnCrash();
19901997

19911998
// Operations on all values
1999+
/// FIXME: After dropping LLVM 21, migrate to LLVM-C's `LLVMGlobalAddMetadata`.
19922000
pub(crate) fn LLVMRustGlobalAddMetadata<'a>(
19932001
Val: &'a Value,
19942002
KindID: MetadataKindId,
@@ -2058,6 +2066,7 @@ unsafe extern "C" {
20582066
) -> &Attribute;
20592067

20602068
// Operations on functions
2069+
/// FIXME: After dropping LLVM 21, migrate to LLVM-C's `LLVMGetOrInsertFunction`.
20612070
pub(crate) fn LLVMRustGetOrInsertFunction<'a>(
20622071
M: &'a Module,
20632072
Name: *const c_char,
@@ -2208,6 +2217,9 @@ unsafe extern "C" {
22082217
ValueLen: size_t,
22092218
);
22102219

2220+
/// We can't use LLVM-C's `LLVMDIBuilderCreateCompileUnit` because it hardcodes
2221+
/// `DICompileUnit::DebugNameTableKind::Default`, but we want to be able to
2222+
/// pass other values.
22112223
pub(crate) fn LLVMRustDIBuilderCreateCompileUnit<'a>(
22122224
Builder: &DIBuilder<'a>,
22132225
Lang: c_uint,
@@ -2225,6 +2237,8 @@ unsafe extern "C" {
22252237
DebugNameTableKind: DebugNameTableKind,
22262238
) -> &'a DIDescriptor;
22272239

2240+
/// We can't use LLVM-C's `LLVMDIBuilderCreateFileWithChecksum` because it
2241+
/// _requires_ a checksum, but we sometimes don't provide one.
22282242
pub(crate) fn LLVMRustDIBuilderCreateFile<'a>(
22292243
Builder: &DIBuilder<'a>,
22302244
Filename: *const c_char,
@@ -2238,6 +2252,8 @@ unsafe extern "C" {
22382252
SourceLen: size_t,
22392253
) -> &'a DIFile;
22402254

2255+
/// We can't use LLVM-C's `LLVMDIBuilderCreateFunction` because it only
2256+
/// supports a subset of `DISubprogram::DISPFlags`.
22412257
pub(crate) fn LLVMRustDIBuilderCreateFunction<'a>(
22422258
Builder: &DIBuilder<'a>,
22432259
Scope: &'a DIDescriptor,
@@ -2256,6 +2272,7 @@ unsafe extern "C" {
22562272
Decl: Option<&'a DIDescriptor>,
22572273
) -> &'a DISubprogram;
22582274

2275+
/// As of LLVM 22 there is no corresponding LLVM-C function.
22592276
pub(crate) fn LLVMRustDIBuilderCreateMethod<'a>(
22602277
Builder: &DIBuilder<'a>,
22612278
Scope: &'a DIDescriptor,
@@ -2271,6 +2288,7 @@ unsafe extern "C" {
22712288
TParam: &'a DIArray,
22722289
) -> &'a DISubprogram;
22732290

2291+
/// As of LLVM 22 there is no corresponding LLVM-C function.
22742292
pub(crate) fn LLVMRustDIBuilderCreateVariantMemberType<'a>(
22752293
Builder: &DIBuilder<'a>,
22762294
Scope: &'a DIScope,
@@ -2286,15 +2304,7 @@ unsafe extern "C" {
22862304
Ty: &'a DIType,
22872305
) -> &'a DIType;
22882306

2289-
pub(crate) fn LLVMRustDIBuilderCreateEnumerator<'a>(
2290-
Builder: &DIBuilder<'a>,
2291-
Name: *const c_char,
2292-
NameLen: size_t,
2293-
Value: *const u64,
2294-
SizeInBits: c_uint,
2295-
IsUnsigned: bool,
2296-
) -> &'a DIEnumerator;
2297-
2307+
/// As of LLVM 22 there is no corresponding LLVM-C function.
22982308
pub(crate) fn LLVMRustDIBuilderCreateEnumerationType<'a>(
22992309
Builder: &DIBuilder<'a>,
23002310
Scope: &'a DIScope,
@@ -2309,6 +2319,7 @@ unsafe extern "C" {
23092319
IsScoped: bool,
23102320
) -> &'a DIType;
23112321

2322+
/// As of LLVM 22 there is no corresponding LLVM-C function.
23122323
pub(crate) fn LLVMRustDIBuilderCreateVariantPart<'a>(
23132324
Builder: &DIBuilder<'a>,
23142325
Scope: &'a DIScope,
@@ -2325,6 +2336,7 @@ unsafe extern "C" {
23252336
UniqueIdLen: size_t,
23262337
) -> &'a DIDerivedType;
23272338

2339+
/// As of LLVM 22 there is no corresponding LLVM-C function.
23282340
pub(crate) fn LLVMRustDIBuilderCreateTemplateTypeParameter<'a>(
23292341
Builder: &DIBuilder<'a>,
23302342
Scope: Option<&'a DIScope>,
@@ -2333,13 +2345,17 @@ unsafe extern "C" {
23332345
Ty: &'a DIType,
23342346
) -> &'a DITemplateTypeParameter;
23352347

2348+
/// We can't use LLVM-C's `LLVMReplaceArrays` because it doesn't take a
2349+
/// `Params` argument.
23362350
pub(crate) fn LLVMRustDICompositeTypeReplaceArrays<'a>(
23372351
Builder: &DIBuilder<'a>,
23382352
CompositeType: &'a DIType,
23392353
Elements: Option<&'a DIArray>,
23402354
Params: Option<&'a DIArray>,
23412355
);
23422356

2357+
/// We can't use LLVM-C's `LLVMDIBuilderGetOrCreateSubrange` because it doesn't
2358+
/// call the overload that takes a `Metadata` upper bound.
23432359
pub(crate) fn LLVMRustDIGetOrCreateSubrange<'a>(
23442360
Builder: &DIBuilder<'a>,
23452361
CountNode: Option<&'a Metadata>,
@@ -2348,6 +2364,8 @@ unsafe extern "C" {
23482364
Stride: Option<&'a Metadata>,
23492365
) -> &'a Metadata;
23502366

2367+
/// We can't use LLVM-C's `LLVMDIBuilderCreateVectorType` because it doesn't
2368+
/// take a `BitStride` argument.
23512369
pub(crate) fn LLVMRustDICreateVectorType<'a>(
23522370
Builder: &DIBuilder<'a>,
23532371
Size: u64,
@@ -2357,6 +2375,7 @@ unsafe extern "C" {
23572375
BitStride: Option<&'a Metadata>,
23582376
) -> &'a Metadata;
23592377

2378+
/// As of LLVM 22 there is no corresponding LLVM-C function.
23602379
pub(crate) fn LLVMRustDILocationCloneWithBaseDiscriminator<'a>(
23612380
Location: &'a DILocation,
23622381
BD: c_uint,

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
1818
use rustc_hir_analysis::suggest_impl_trait;
1919
use rustc_middle::middle::stability::EvalResult;
2020
use rustc_middle::span_bug;
21-
use rustc_middle::ty::print::with_no_trimmed_paths;
21+
use rustc_middle::ty::print::{with_no_trimmed_paths, with_types_for_suggestion};
2222
use rustc_middle::ty::{
2323
self, Article, Binder, IsSuggestable, Ty, TyCtxt, TypeVisitableExt, Unnormalized, Upcast,
2424
suggest_constraining_type_params,
@@ -2679,8 +2679,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26792679

26802680
let sole_field_ty = sole_field.ty(self.tcx, args).skip_norm_wip();
26812681
if self.may_coerce(expr_ty, sole_field_ty) {
2682-
let variant_path =
2683-
with_no_trimmed_paths!(self.tcx.def_path_str(variant.def_id));
2682+
let variant_path = with_types_for_suggestion!(with_no_trimmed_paths!(
2683+
self.tcx.def_path_str(variant.def_id)
2684+
));
26842685
// FIXME #56861: DRYer prelude filtering
26852686
if let Some(path) = variant_path.strip_prefix("std::prelude::")
26862687
&& let Some((_, path)) = path.split_once("::")

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,15 +1198,6 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariantMemberType(
11981198
fromRust(Flags), unwrapDI<DIType>(Ty)));
11991199
}
12001200

1201-
extern "C" LLVMMetadataRef
1202-
LLVMRustDIBuilderCreateEnumerator(LLVMDIBuilderRef Builder, const char *Name,
1203-
size_t NameLen, const uint64_t Value[2],
1204-
unsigned SizeInBits, bool IsUnsigned) {
1205-
return wrap(unwrap(Builder)->createEnumerator(
1206-
StringRef(Name, NameLen),
1207-
APSInt(APInt(SizeInBits, ArrayRef<uint64_t>(Value, 2)), IsUnsigned)));
1208-
}
1209-
12101201
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerationType(
12111202
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
12121203
size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,

compiler/rustc_target/src/spec/targets/xtensa_esp32_espidf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub(crate) fn target() -> Target {
77
Target {
88
llvm_target: "xtensa-none-elf".into(),
99
pointer_width: 32,
10-
data_layout: "e-m:e-p:32:32-v1:8:8-i64:64-i128:128-n32".into(),
10+
data_layout: "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-n32".into(),
1111
arch: Arch::Xtensa,
1212
metadata: TargetMetadata { description: None, tier: Some(3), host_tools: None, std: None },
1313

compiler/rustc_target/src/spec/targets/xtensa_esp32_none_elf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub(crate) fn target() -> Target {
55
Target {
66
llvm_target: "xtensa-none-elf".into(),
77
pointer_width: 32,
8-
data_layout: "e-m:e-p:32:32-v1:8:8-i64:64-i128:128-n32".into(),
8+
data_layout: "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-n32".into(),
99
arch: Arch::Xtensa,
1010
metadata: TargetMetadata {
1111
description: Some("Xtensa ESP32".into()),

compiler/rustc_target/src/spec/targets/xtensa_esp32s2_espidf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub(crate) fn target() -> Target {
77
Target {
88
llvm_target: "xtensa-none-elf".into(),
99
pointer_width: 32,
10-
data_layout: "e-m:e-p:32:32-v1:8:8-i64:64-i128:128-n32".into(),
10+
data_layout: "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-n32".into(),
1111
arch: Arch::Xtensa,
1212
metadata: TargetMetadata { description: None, tier: Some(3), host_tools: None, std: None },
1313

compiler/rustc_target/src/spec/targets/xtensa_esp32s2_none_elf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub(crate) fn target() -> Target {
55
Target {
66
llvm_target: "xtensa-none-elf".into(),
77
pointer_width: 32,
8-
data_layout: "e-m:e-p:32:32-v1:8:8-i64:64-i128:128-n32".into(),
8+
data_layout: "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-n32".into(),
99
arch: Arch::Xtensa,
1010
metadata: TargetMetadata {
1111
description: Some("Xtensa ESP32-S2".into()),

0 commit comments

Comments
 (0)