Skip to content

Commit be29189

Browse files
committed
Auto merge of rust-lang#129407 - tgross35:rollup-q5vnsge, r=tgross35
Rollup of 7 pull requests Successful merges: - rust-lang#126985 (Implement `-Z embed-source` (DWARFv5 source code embedding extension)) - rust-lang#128349 (Enable `f16` on x86 and x86-64) - rust-lang#128876 (Ship MinGW-w64 runtime DLLs along with `rust-lld.exe` for `-pc-windows-gnu` targets) - rust-lang#129190 (Add f16 and f128 to tests/ui/consts/const-float-bits-conv.rs) - rust-lang#129257 (Allow rust staticlib to work with MSVC's /WHOLEARCHIVE) - rust-lang#129386 (Use a LocalDefId in ResolvedArg.) - rust-lang#129400 (Update `compiler_builtins` to `0.1.120`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0f6e1ae + 56b3880 commit be29189

File tree

34 files changed

+377
-97
lines changed

34 files changed

+377
-97
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ dependencies = [
195195

196196
[[package]]
197197
name = "ar_archive_writer"
198-
version = "0.4.0"
198+
version = "0.4.2"
199199
source = "registry+https://github.com/rust-lang/crates.io-index"
200-
checksum = "de11a9d32db3327f981143bdf699ade4d637c6887b13b97e6e91a9154666963c"
200+
checksum = "01667f6f40216b9a0b2945e05fed5f1ad0ab6470e69cb9378001e37b1c0668e4"
201201
dependencies = [
202202
"object 0.36.3",
203203
]

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+9
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,9 @@ pub fn file_metadata<'ll>(cx: &CodegenCx<'ll, '_>, source_file: &SourceFile) ->
629629
};
630630
let hash_value = hex_encode(source_file.src_hash.hash_bytes());
631631

632+
let source =
633+
cx.sess().opts.unstable_opts.embed_source.then_some(()).and(source_file.src.as_ref());
634+
632635
unsafe {
633636
llvm::LLVMRustDIBuilderCreateFile(
634637
DIB(cx),
@@ -639,6 +642,8 @@ pub fn file_metadata<'ll>(cx: &CodegenCx<'ll, '_>, source_file: &SourceFile) ->
639642
hash_kind,
640643
hash_value.as_ptr().cast(),
641644
hash_value.len(),
645+
source.map_or(ptr::null(), |x| x.as_ptr().cast()),
646+
source.map_or(0, |x| x.len()),
642647
)
643648
}
644649
}
@@ -659,6 +664,8 @@ pub fn unknown_file_metadata<'ll>(cx: &CodegenCx<'ll, '_>) -> &'ll DIFile {
659664
llvm::ChecksumKind::None,
660665
hash_value.as_ptr().cast(),
661666
hash_value.len(),
667+
ptr::null(),
668+
0,
662669
)
663670
})
664671
}
@@ -943,6 +950,8 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
943950
llvm::ChecksumKind::None,
944951
ptr::null(),
945952
0,
953+
ptr::null(),
954+
0,
946955
);
947956

948957
let unit_metadata = llvm::LLVMRustDIBuilderCreateCompileUnit(

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1860,6 +1860,8 @@ extern "C" {
18601860
CSKind: ChecksumKind,
18611861
Checksum: *const c_char,
18621862
ChecksumLen: size_t,
1863+
Source: *const c_char,
1864+
SourceLen: size_t,
18631865
) -> &'a DIFile;
18641866

18651867
pub fn LLVMRustDIBuilderCreateSubroutineType<'a>(

compiler/rustc_codegen_ssa/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
ar_archive_writer = "0.4.0"
8+
ar_archive_writer = "0.4.2"
99
arrayvec = { version = "0.7", default-features = false }
1010
bitflags = "2.4.1"
1111
cc = "1.0.90"

compiler/rustc_codegen_ssa/src/back/archive.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@ pub trait ArchiveBuilderBuilder {
108108
&exports,
109109
machine,
110110
!sess.target.is_like_msvc,
111-
/*comdat=*/ false,
111+
// Enable compatibility with MSVC's `/WHOLEARCHIVE` flag.
112+
// Without this flag a duplicate symbol error would be emitted
113+
// when linking a rust staticlib using `/WHOLEARCHIVE`.
114+
// See #129020
115+
true,
112116
) {
113117
sess.dcx()
114118
.emit_fatal(ErrorCreatingImportLibrary { lib_name, error: error.to_string() });

compiler/rustc_hir_analysis/src/check/check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ fn check_opaque_precise_captures<'tcx>(tcx: TyCtxt<'tcx>, opaque_def_id: LocalDe
529529

530530
match tcx.named_bound_var(hir_id) {
531531
Some(ResolvedArg::EarlyBound(def_id)) => {
532-
expected_captures.insert(def_id);
532+
expected_captures.insert(def_id.to_def_id());
533533

534534
// Make sure we allow capturing these lifetimes through `Self` and
535535
// `T::Assoc` projection syntax, too. These will occur when we only
@@ -538,7 +538,7 @@ fn check_opaque_precise_captures<'tcx>(tcx: TyCtxt<'tcx>, opaque_def_id: LocalDe
538538
// feature -- see <https://github.com/rust-lang/rust/pull/115659>.
539539
if let DefKind::LifetimeParam = tcx.def_kind(def_id)
540540
&& let Some(def_id) = tcx
541-
.map_opaque_lifetime_to_parent_lifetime(def_id.expect_local())
541+
.map_opaque_lifetime_to_parent_lifetime(def_id)
542542
.opt_param_def_id(tcx, tcx.parent(opaque_def_id.to_def_id()))
543543
{
544544
shadowed_captures.insert(def_id);

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+13-14
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use rustc_ast::visit::walk_list;
1313
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
1414
use rustc_hir as hir;
1515
use rustc_hir::def::{DefKind, Res};
16-
use rustc_hir::def_id::LocalDefId;
1716
use rustc_hir::intravisit::{self, Visitor};
1817
use rustc_hir::{GenericArg, GenericParam, GenericParamKind, HirId, HirIdMap, LifetimeName, Node};
1918
use rustc_macros::extension;
@@ -22,7 +21,7 @@ use rustc_middle::middle::resolve_bound_vars::*;
2221
use rustc_middle::query::Providers;
2322
use rustc_middle::ty::{self, TyCtxt, TypeSuperVisitable, TypeVisitor};
2423
use rustc_middle::{bug, span_bug};
25-
use rustc_span::def_id::DefId;
24+
use rustc_span::def_id::{DefId, LocalDefId};
2625
use rustc_span::symbol::{sym, Ident};
2726
use rustc_span::Span;
2827

@@ -32,7 +31,7 @@ use crate::errors;
3231
impl ResolvedArg {
3332
fn early(param: &GenericParam<'_>) -> (LocalDefId, ResolvedArg) {
3433
debug!("ResolvedArg::early: def_id={:?}", param.def_id);
35-
(param.def_id, ResolvedArg::EarlyBound(param.def_id.to_def_id()))
34+
(param.def_id, ResolvedArg::EarlyBound(param.def_id))
3635
}
3736

3837
fn late(idx: u32, param: &GenericParam<'_>) -> (LocalDefId, ResolvedArg) {
@@ -41,10 +40,10 @@ impl ResolvedArg {
4140
"ResolvedArg::late: idx={:?}, param={:?} depth={:?} def_id={:?}",
4241
idx, param, depth, param.def_id,
4342
);
44-
(param.def_id, ResolvedArg::LateBound(depth, idx, param.def_id.to_def_id()))
43+
(param.def_id, ResolvedArg::LateBound(depth, idx, param.def_id))
4544
}
4645

47-
fn id(&self) -> Option<DefId> {
46+
fn id(&self) -> Option<LocalDefId> {
4847
match *self {
4948
ResolvedArg::StaticLifetime | ResolvedArg::Error(_) => None,
5049

@@ -288,13 +287,14 @@ fn late_arg_as_bound_arg<'tcx>(
288287
) -> ty::BoundVariableKind {
289288
match arg {
290289
ResolvedArg::LateBound(_, _, def_id) => {
291-
let name = tcx.hir().name(tcx.local_def_id_to_hir_id(def_id.expect_local()));
290+
let def_id = def_id.to_def_id();
291+
let name = tcx.item_name(def_id);
292292
match param.kind {
293293
GenericParamKind::Lifetime { .. } => {
294-
ty::BoundVariableKind::Region(ty::BrNamed(*def_id, name))
294+
ty::BoundVariableKind::Region(ty::BrNamed(def_id, name))
295295
}
296296
GenericParamKind::Type { .. } => {
297-
ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(*def_id, name))
297+
ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(def_id, name))
298298
}
299299
GenericParamKind::Const { .. } => ty::BoundVariableKind::Const,
300300
}
@@ -717,7 +717,6 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
717717
// In the future, this should be fixed and this error should be removed.
718718
let def = self.map.defs.get(&lifetime.hir_id).copied();
719719
let Some(ResolvedArg::LateBound(_, _, lifetime_def_id)) = def else { continue };
720-
let Some(lifetime_def_id) = lifetime_def_id.as_local() else { continue };
721720
let lifetime_hir_id = self.tcx.local_def_id_to_hir_id(lifetime_def_id);
722721

723722
let bad_place = match self.tcx.hir_node(self.tcx.parent_hir_id(lifetime_hir_id))
@@ -1150,7 +1149,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
11501149
.param_def_id_to_index(self.tcx, region_def_id.to_def_id())
11511150
.is_some()
11521151
{
1153-
break Some(ResolvedArg::EarlyBound(region_def_id.to_def_id()));
1152+
break Some(ResolvedArg::EarlyBound(region_def_id));
11541153
}
11551154
break None;
11561155
}
@@ -1259,7 +1258,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
12591258
kind => span_bug!(
12601259
use_span,
12611260
"did not expect to resolve lifetime to {}",
1262-
kind.descr(param_def_id)
1261+
kind.descr(param_def_id.to_def_id())
12631262
),
12641263
};
12651264
def = ResolvedArg::Error(guar);
@@ -1277,10 +1276,10 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
12771276
kind: hir::ImplItemKind::Fn(..),
12781277
..
12791278
}) => {
1280-
def = ResolvedArg::Free(owner_id.to_def_id(), def.id().unwrap());
1279+
def = ResolvedArg::Free(owner_id.def_id, def.id().unwrap());
12811280
}
12821281
Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(closure), .. }) => {
1283-
def = ResolvedArg::Free(closure.def_id.to_def_id(), def.id().unwrap());
1282+
def = ResolvedArg::Free(closure.def_id, def.id().unwrap());
12841283
}
12851284
_ => {}
12861285
}
@@ -1351,7 +1350,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
13511350
.param_def_id_to_index(self.tcx, param_def_id.to_def_id())
13521351
.is_some()
13531352
{
1354-
break Some(ResolvedArg::EarlyBound(param_def_id.to_def_id()));
1353+
break Some(ResolvedArg::EarlyBound(param_def_id));
13551354
}
13561355
break None;
13571356
}

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+16-13
Original file line numberDiff line numberDiff line change
@@ -296,25 +296,29 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
296296
Some(rbv::ResolvedArg::StaticLifetime) => tcx.lifetimes.re_static,
297297

298298
Some(rbv::ResolvedArg::LateBound(debruijn, index, def_id)) => {
299-
let name = lifetime_name(def_id.expect_local());
299+
let name = lifetime_name(def_id);
300300
let br = ty::BoundRegion {
301301
var: ty::BoundVar::from_u32(index),
302-
kind: ty::BrNamed(def_id, name),
302+
kind: ty::BrNamed(def_id.to_def_id(), name),
303303
};
304304
ty::Region::new_bound(tcx, debruijn, br)
305305
}
306306

307307
Some(rbv::ResolvedArg::EarlyBound(def_id)) => {
308-
let name = tcx.hir().ty_param_name(def_id.expect_local());
309-
let item_def_id = tcx.hir().ty_param_owner(def_id.expect_local());
308+
let name = tcx.hir().ty_param_name(def_id);
309+
let item_def_id = tcx.hir().ty_param_owner(def_id);
310310
let generics = tcx.generics_of(item_def_id);
311-
let index = generics.param_def_id_to_index[&def_id];
311+
let index = generics.param_def_id_to_index[&def_id.to_def_id()];
312312
ty::Region::new_early_param(tcx, ty::EarlyParamRegion { index, name })
313313
}
314314

315315
Some(rbv::ResolvedArg::Free(scope, id)) => {
316-
let name = lifetime_name(id.expect_local());
317-
ty::Region::new_late_param(tcx, scope, ty::BrNamed(id, name))
316+
let name = lifetime_name(id);
317+
ty::Region::new_late_param(
318+
tcx,
319+
scope.to_def_id(),
320+
ty::BrNamed(id.to_def_id(), name),
321+
)
318322

319323
// (*) -- not late-bound, won't change
320324
}
@@ -1953,15 +1957,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
19531957
let tcx = self.tcx();
19541958
match tcx.named_bound_var(hir_id) {
19551959
Some(rbv::ResolvedArg::LateBound(debruijn, index, def_id)) => {
1956-
let name = tcx.item_name(def_id);
1960+
let name = tcx.item_name(def_id.to_def_id());
19571961
let br = ty::BoundTy {
19581962
var: ty::BoundVar::from_u32(index),
1959-
kind: ty::BoundTyKind::Param(def_id, name),
1963+
kind: ty::BoundTyKind::Param(def_id.to_def_id(), name),
19601964
};
19611965
Ty::new_bound(tcx, debruijn, br)
19621966
}
19631967
Some(rbv::ResolvedArg::EarlyBound(def_id)) => {
1964-
let def_id = def_id.expect_local();
19651968
let item_def_id = tcx.hir().ty_param_owner(def_id);
19661969
let generics = tcx.generics_of(item_def_id);
19671970
let index = generics.param_def_id_to_index[&def_id.to_def_id()];
@@ -1982,10 +1985,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
19821985
Some(rbv::ResolvedArg::EarlyBound(def_id)) => {
19831986
// Find the name and index of the const parameter by indexing the generics of
19841987
// the parent item and construct a `ParamConst`.
1985-
let item_def_id = tcx.parent(def_id);
1988+
let item_def_id = tcx.local_parent(def_id);
19861989
let generics = tcx.generics_of(item_def_id);
1987-
let index = generics.param_def_id_to_index[&def_id];
1988-
let name = tcx.item_name(def_id);
1990+
let index = generics.param_def_id_to_index[&def_id.to_def_id()];
1991+
let name = tcx.item_name(def_id.to_def_id());
19891992
ty::Const::new_param(tcx, ty::ParamConst::new(index, name))
19901993
}
19911994
Some(rbv::ResolvedArg::LateBound(debruijn, index, _)) => {

compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,7 @@ fn test_unstable_options_tracking_hash() {
774774
tracked!(direct_access_external_data, Some(true));
775775
tracked!(dual_proc_macros, true);
776776
tracked!(dwarf_version, Some(5));
777+
tracked!(embed_source, true);
777778
tracked!(emit_thin_lto, false);
778779
tracked!(export_executable_symbols, true);
779780
tracked!(fewer_names, Some(true));

compiler/rustc_lint/src/builtin.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1925,16 +1925,16 @@ impl ExplicitOutlivesRequirements {
19251925
fn lifetimes_outliving_lifetime<'tcx>(
19261926
tcx: TyCtxt<'tcx>,
19271927
inferred_outlives: impl Iterator<Item = &'tcx (ty::Clause<'tcx>, Span)>,
1928-
item: DefId,
1929-
lifetime: DefId,
1928+
item: LocalDefId,
1929+
lifetime: LocalDefId,
19301930
) -> Vec<ty::Region<'tcx>> {
19311931
let item_generics = tcx.generics_of(item);
19321932

19331933
inferred_outlives
19341934
.filter_map(|(clause, _)| match clause.kind().skip_binder() {
19351935
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => match *a {
19361936
ty::ReEarlyParam(ebr)
1937-
if item_generics.region_param(ebr, tcx).def_id == lifetime =>
1937+
if item_generics.region_param(ebr, tcx).def_id == lifetime.to_def_id() =>
19381938
{
19391939
Some(b)
19401940
}
@@ -1982,7 +1982,7 @@ impl ExplicitOutlivesRequirements {
19821982
let is_inferred = match tcx.named_bound_var(lifetime.hir_id) {
19831983
Some(ResolvedArg::EarlyBound(def_id)) => inferred_outlives
19841984
.iter()
1985-
.any(|r| matches!(**r, ty::ReEarlyParam(ebr) if { item_generics.region_param(ebr, tcx).def_id == def_id })),
1985+
.any(|r| matches!(**r, ty::ReEarlyParam(ebr) if { item_generics.region_param(ebr, tcx).def_id == def_id.to_def_id() })),
19861986
_ => false,
19871987
};
19881988

@@ -2097,7 +2097,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
20972097
inferred_outlives
20982098
.iter()
20992099
.filter(|(_, span)| !predicate.span.contains(*span)),
2100-
item.owner_id.to_def_id(),
2100+
item.owner_id.def_id,
21012101
region_def_id,
21022102
),
21032103
&predicate.bounds,

compiler/rustc_lint/src/impl_trait_overcaptures.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -300,16 +300,17 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for VisitOpaqueTypes<'tcx> {
300300
Some(
301301
ResolvedArg::EarlyBound(def_id) | ResolvedArg::LateBound(_, _, def_id),
302302
) => {
303-
if self.tcx.def_kind(self.tcx.parent(def_id)) == DefKind::OpaqueTy {
303+
if self.tcx.def_kind(self.tcx.local_parent(def_id)) == DefKind::OpaqueTy
304+
{
304305
let def_id = self
305306
.tcx
306-
.map_opaque_lifetime_to_parent_lifetime(def_id.expect_local())
307+
.map_opaque_lifetime_to_parent_lifetime(def_id)
307308
.opt_param_def_id(self.tcx, self.parent_def_id.to_def_id())
308309
.expect("variable should have been duplicated from parent");
309310

310311
explicitly_captured.insert(def_id);
311312
} else {
312-
explicitly_captured.insert(def_id);
313+
explicitly_captured.insert(def_id.to_def_id());
313314
}
314315
}
315316
_ => {

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -913,14 +913,19 @@ extern "C" LLVMMetadataRef
913913
LLVMRustDIBuilderCreateFile(LLVMRustDIBuilderRef Builder, const char *Filename,
914914
size_t FilenameLen, const char *Directory,
915915
size_t DirectoryLen, LLVMRustChecksumKind CSKind,
916-
const char *Checksum, size_t ChecksumLen) {
916+
const char *Checksum, size_t ChecksumLen,
917+
const char *Source, size_t SourceLen) {
917918

918919
std::optional<DIFile::ChecksumKind> llvmCSKind = fromRust(CSKind);
919920
std::optional<DIFile::ChecksumInfo<StringRef>> CSInfo{};
920921
if (llvmCSKind)
921922
CSInfo.emplace(*llvmCSKind, StringRef{Checksum, ChecksumLen});
923+
std::optional<StringRef> oSource{};
924+
if (Source)
925+
oSource = StringRef(Source, SourceLen);
922926
return wrap(Builder->createFile(StringRef(Filename, FilenameLen),
923-
StringRef(Directory, DirectoryLen), CSInfo));
927+
StringRef(Directory, DirectoryLen), CSInfo,
928+
oSource));
924929
}
925930

926931
extern "C" LLVMMetadataRef

compiler/rustc_middle/src/middle/resolve_bound_vars.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use rustc_data_structures::fx::FxIndexMap;
44
use rustc_errors::ErrorGuaranteed;
5-
use rustc_hir::def_id::DefId;
5+
use rustc_hir::def_id::{DefId, LocalDefId};
66
use rustc_hir::{ItemLocalId, OwnerId};
77
use rustc_macros::{Decodable, Encodable, HashStable, TyDecodable, TyEncodable};
88

@@ -11,9 +11,9 @@ use crate::ty;
1111
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, HashStable)]
1212
pub enum ResolvedArg {
1313
StaticLifetime,
14-
EarlyBound(/* decl */ DefId),
15-
LateBound(ty::DebruijnIndex, /* late-bound index */ u32, /* decl */ DefId),
16-
Free(DefId, /* lifetime decl */ DefId),
14+
EarlyBound(/* decl */ LocalDefId),
15+
LateBound(ty::DebruijnIndex, /* late-bound index */ u32, /* decl */ LocalDefId),
16+
Free(LocalDefId, /* lifetime decl */ LocalDefId),
1717
Error(ErrorGuaranteed),
1818
}
1919

0 commit comments

Comments
 (0)