Skip to content

Commit d2b3dd7

Browse files
committed
Auto merge of rust-lang#139689 - jhpratt:rollup-wlkdyjg, r=jhpratt
Rollup of 7 pull requests Successful merges: - rust-lang#137835 (Use `BinOp::Cmp` for `iNN::signum`) - rust-lang#139584 (Avoid a reverse map that is only used in diagnostics paths) - rust-lang#139638 (Cleanup the `InstSimplify` MIR transformation) - rust-lang#139653 (Handle a negated literal in `eat_token_lit`.) - rust-lang#139662 (Tweak `DefPathData`) - rust-lang#139664 (Reuse address-space computation from global alloc) - rust-lang#139687 (Add spastorino to users_on_vacation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ed3a4aa + c8992c9 commit d2b3dd7

File tree

36 files changed

+242
-223
lines changed

36 files changed

+242
-223
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -4397,7 +4397,6 @@ dependencies = [
43974397
"rustc_feature",
43984398
"rustc_fluent_macro",
43994399
"rustc_hir",
4400-
"rustc_index",
44014400
"rustc_macros",
44024401
"rustc_metadata",
44034402
"rustc_middle",

compiler/rustc_codegen_llvm/src/common.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::borrow::Borrow;
44

55
use libc::{c_char, c_uint};
66
use rustc_abi as abi;
7+
use rustc_abi::HasDataLayout;
78
use rustc_abi::Primitive::Pointer;
8-
use rustc_abi::{AddressSpace, HasDataLayout};
99
use rustc_ast::Mutability;
1010
use rustc_codegen_ssa::common::TypeKind;
1111
use rustc_codegen_ssa::traits::*;
@@ -269,7 +269,8 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
269269
}
270270
Scalar::Ptr(ptr, _size) => {
271271
let (prov, offset) = ptr.into_parts();
272-
let (base_addr, base_addr_space) = match self.tcx.global_alloc(prov.alloc_id()) {
272+
let global_alloc = self.tcx.global_alloc(prov.alloc_id());
273+
let base_addr = match global_alloc {
273274
GlobalAlloc::Memory(alloc) => {
274275
// For ZSTs directly codegen an aligned pointer.
275276
// This avoids generating a zero-sized constant value and actually needing a
@@ -301,12 +302,10 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
301302
format!("alloc_{hash:032x}").as_bytes(),
302303
);
303304
}
304-
(value, AddressSpace::DATA)
305+
value
305306
}
306307
}
307-
GlobalAlloc::Function { instance, .. } => {
308-
(self.get_fn_addr(instance), self.data_layout().instruction_address_space)
309-
}
308+
GlobalAlloc::Function { instance, .. } => self.get_fn_addr(instance),
310309
GlobalAlloc::VTable(ty, dyn_ty) => {
311310
let alloc = self
312311
.tcx
@@ -319,14 +318,15 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
319318
.unwrap_memory();
320319
let init = const_alloc_to_llvm(self, alloc, /*static*/ false);
321320
let value = self.static_addr_of_impl(init, alloc.inner().align, None);
322-
(value, AddressSpace::DATA)
321+
value
323322
}
324323
GlobalAlloc::Static(def_id) => {
325324
assert!(self.tcx.is_static(def_id));
326325
assert!(!self.tcx.is_thread_local_static(def_id));
327-
(self.get_static(def_id), AddressSpace::DATA)
326+
self.get_static(def_id)
328327
}
329328
};
329+
let base_addr_space = global_alloc.address_space(self);
330330
let llval = unsafe {
331331
llvm::LLVMConstInBoundsGEP2(
332332
self.type_i8(),

compiler/rustc_data_structures/src/unord.rs

+10
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ impl<T, I: Iterator<Item = T>> UnordItems<T, I> {
109109
pub fn collect<C: From<UnordItems<T, I>>>(self) -> C {
110110
self.into()
111111
}
112+
113+
/// If the iterator has only one element, returns it, otherwise returns `None`.
114+
#[track_caller]
115+
pub fn get_only(mut self) -> Option<T> {
116+
let item = self.0.next();
117+
if self.0.next().is_some() {
118+
return None;
119+
}
120+
item
121+
}
112122
}
113123

114124
impl<T> UnordItems<T, std::iter::Empty<T>> {

compiler/rustc_hir/src/def.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,16 @@ impl DefKind {
267267
| DefKind::ForeignTy
268268
| DefKind::TraitAlias
269269
| DefKind::TyParam
270-
| DefKind::ExternCrate => DefPathData::TypeNs(Some(name.unwrap())),
271-
272-
// An associated type names will be missing for an RPITIT. It will
273-
// later be given a name with `synthetic` in it, if necessary.
274-
DefKind::AssocTy => DefPathData::TypeNs(name),
270+
| DefKind::ExternCrate => DefPathData::TypeNs(name.unwrap()),
271+
272+
// An associated type name will be missing for an RPITIT.
273+
DefKind::AssocTy => {
274+
if let Some(name) = name {
275+
DefPathData::TypeNs(name)
276+
} else {
277+
DefPathData::AnonAssocTy
278+
}
279+
}
275280

276281
// It's not exactly an anon const, but wrt DefPathData, there
277282
// is no difference.

compiler/rustc_hir/src/definitions.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,8 @@ pub enum DefPathData {
271271
Use,
272272
/// A global asm item.
273273
GlobalAsm,
274-
/// Something in the type namespace. Will be empty for RPITIT associated
275-
/// types, which are given a synthetic name later, if necessary.
276-
TypeNs(Option<Symbol>),
274+
/// Something in the type namespace.
275+
TypeNs(Symbol),
277276
/// Something in the value namespace.
278277
ValueNs(Symbol),
279278
/// Something in the macro namespace.
@@ -291,6 +290,8 @@ pub enum DefPathData {
291290
/// An existential `impl Trait` type node.
292291
/// Argument position `impl Trait` have a `TypeNs` with their pretty-printed name.
293292
OpaqueTy,
293+
/// An anonymous associated type from an RPITIT.
294+
AnonAssocTy,
294295
/// A synthetic body for a coroutine's by-move body.
295296
SyntheticCoroutineBody,
296297
}
@@ -413,9 +414,7 @@ impl DefPathData {
413414
pub fn get_opt_name(&self) -> Option<Symbol> {
414415
use self::DefPathData::*;
415416
match *self {
416-
TypeNs(name) => name,
417-
418-
ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),
417+
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),
419418

420419
Impl
421420
| ForeignMod
@@ -426,21 +425,17 @@ impl DefPathData {
426425
| Ctor
427426
| AnonConst
428427
| OpaqueTy
428+
| AnonAssocTy
429429
| SyntheticCoroutineBody => None,
430430
}
431431
}
432432

433433
pub fn name(&self) -> DefPathDataName {
434434
use self::DefPathData::*;
435435
match *self {
436-
TypeNs(name) => {
437-
if let Some(name) = name {
438-
DefPathDataName::Named(name)
439-
} else {
440-
DefPathDataName::Anon { namespace: sym::synthetic }
441-
}
436+
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => {
437+
DefPathDataName::Named(name)
442438
}
443-
ValueNs(name) | MacroNs(name) | LifetimeNs(name) => DefPathDataName::Named(name),
444439
// Note that this does not show up in user print-outs.
445440
CrateRoot => DefPathDataName::Anon { namespace: kw::Crate },
446441
Impl => DefPathDataName::Anon { namespace: kw::Impl },
@@ -451,6 +446,7 @@ impl DefPathData {
451446
Ctor => DefPathDataName::Anon { namespace: sym::constructor },
452447
AnonConst => DefPathDataName::Anon { namespace: sym::constant },
453448
OpaqueTy => DefPathDataName::Anon { namespace: sym::opaque },
449+
AnonAssocTy => DefPathDataName::Anon { namespace: sym::anon_assoc },
454450
SyntheticCoroutineBody => DefPathDataName::Anon { namespace: sym::synthetic },
455451
}
456452
}

compiler/rustc_middle/src/ty/print/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
620620
// the children of the visible parent (as was done when computing
621621
// `visible_parent_map`), looking for the specific child we currently have and then
622622
// have access to the re-exported name.
623-
DefPathData::TypeNs(Some(ref mut name)) if Some(visible_parent) != actual_parent => {
623+
DefPathData::TypeNs(ref mut name) if Some(visible_parent) != actual_parent => {
624624
// Item might be re-exported several times, but filter for the one
625625
// that's public and whose identifier isn't `_`.
626626
let reexport = self
@@ -641,7 +641,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
641641
}
642642
// Re-exported `extern crate` (#43189).
643643
DefPathData::CrateRoot => {
644-
data = DefPathData::TypeNs(Some(self.tcx().crate_name(def_id.krate)));
644+
data = DefPathData::TypeNs(self.tcx().crate_name(def_id.krate));
645645
}
646646
_ => {}
647647
}

compiler/rustc_middle/src/ty/significant_drop_order.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn true_significant_drop_ty<'tcx>(
2626
name_rev.push(tcx.crate_name(did.krate));
2727
}
2828
rustc_hir::definitions::DefPathData::TypeNs(symbol) => {
29-
name_rev.push(symbol.unwrap());
29+
name_rev.push(symbol);
3030
}
3131
_ => return None,
3232
}

0 commit comments

Comments
 (0)