Skip to content

Commit 68d0b29

Browse files
committed
Auto merge of rust-lang#98255 - Dylan-DPC:rollup-hr129rg, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - rust-lang#98105 (rustdoc: remove tuple link on round braces) - rust-lang#98136 (Rename `impl_constness` to `constness`) - rust-lang#98146 (Remove --memory-init-file flag when linking with Emscripten) - rust-lang#98219 (Skip late bound regions in GATSubstCollector) - rust-lang#98233 (Remove accidental uses of `&A: Allocator`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 67404f7 + 6a2a56d commit 68d0b29

File tree

25 files changed

+98
-73
lines changed

25 files changed

+98
-73
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1120,8 +1120,6 @@ impl<'a> Linker for EmLinker<'a> {
11201120
OptLevel::Size => "-Os",
11211121
OptLevel::SizeMin => "-Oz",
11221122
});
1123-
// Unusable until https://github.com/rust-lang/rust/issues/38454 is resolved
1124-
self.cmd.args(&["--memory-init-file", "0"]);
11251123
}
11261124

11271125
fn pgo_gen(&mut self) {

compiler/rustc_const_eval/src/const_eval/fn_queries.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ pub fn is_unstable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Symbol> {
1717

1818
pub fn is_parent_const_impl_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
1919
let parent_id = tcx.local_parent(def_id);
20-
tcx.def_kind(parent_id) == DefKind::Impl
21-
&& tcx.impl_constness(parent_id) == hir::Constness::Const
20+
tcx.def_kind(parent_id) == DefKind::Impl && tcx.constness(parent_id) == hir::Constness::Const
2221
}
2322

24-
/// Checks whether the function has a `const` modifier or, in case it is an intrinsic, whether
25-
/// said intrinsic has a `rustc_const_{un,}stable` attribute.
26-
fn impl_constness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::Constness {
23+
/// Checks whether an item is considered to be `const`. If it is a constructor, it is const. If
24+
/// it is a trait impl/function, return if it has a `const` modifier. If it is an intrinsic,
25+
/// report whether said intrinsic has a `rustc_const_{un,}stable` attribute. Otherwise, return
26+
/// `Constness::NotConst`.
27+
fn constness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::Constness {
2728
let def_id = def_id.expect_local();
2829
let node = tcx.hir().get_by_def_id(def_id);
2930

@@ -77,5 +78,5 @@ fn is_promotable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
7778
}
7879

7980
pub fn provide(providers: &mut Providers) {
80-
*providers = Providers { impl_constness, is_promotable_const_fn, ..*providers };
81+
*providers = Providers { constness, is_promotable_const_fn, ..*providers };
8182
}

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
753753
callee = did;
754754
}
755755

756-
if let hir::Constness::NotConst = tcx.impl_constness(data.impl_def_id) {
756+
if let hir::Constness::NotConst = tcx.constness(data.impl_def_id) {
757757
self.check_op(ops::FnCallNonConst {
758758
caller,
759759
callee,

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
214214
impl_parent => { table }
215215
impl_polarity => { table_direct }
216216
impl_defaultness => { table_direct }
217-
impl_constness => { table_direct }
217+
constness => { table_direct }
218218
coerce_unsized_info => { table }
219219
mir_const_qualif => { table }
220220
rendered_const => { table }

compiler/rustc_metadata/src/rmeta/encoder.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
10631063
};
10641064

10651065
record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
1066-
self.tables.impl_constness.set(def_id.index, hir::Constness::Const);
1066+
self.tables.constness.set(def_id.index, hir::Constness::Const);
10671067
record_array!(self.tables.children[def_id] <- variant.fields.iter().map(|f| {
10681068
assert!(f.did.is_local());
10691069
f.did.index
@@ -1092,7 +1092,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
10921092
};
10931093

10941094
record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
1095-
self.tables.impl_constness.set(def_id.index, hir::Constness::Const);
1095+
self.tables.constness.set(def_id.index, hir::Constness::Const);
10961096
self.encode_item_type(def_id);
10971097
if variant.ctor_kind == CtorKind::Fn {
10981098
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
@@ -1175,7 +1175,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
11751175
};
11761176

11771177
record!(self.tables.repr_options[def_id] <- adt_def.repr());
1178-
self.tables.impl_constness.set(def_id.index, hir::Constness::Const);
1178+
self.tables.constness.set(def_id.index, hir::Constness::Const);
11791179
record!(self.tables.kind[def_id] <- EntryKind::Struct(self.lazy(data)));
11801180
self.encode_item_type(def_id);
11811181
if variant.ctor_kind == CtorKind::Fn {
@@ -1226,7 +1226,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
12261226
}
12271227
};
12281228
self.tables.asyncness.set(def_id.index, m_sig.header.asyncness);
1229-
self.tables.impl_constness.set(def_id.index, hir::Constness::NotConst);
1229+
self.tables.constness.set(def_id.index, hir::Constness::NotConst);
12301230
record!(self.tables.kind[def_id] <- EntryKind::AssocFn(self.lazy(AssocFnData {
12311231
container,
12321232
has_self: trait_item.fn_has_self_parameter,
@@ -1290,7 +1290,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
12901290
} else {
12911291
hir::Constness::NotConst
12921292
};
1293-
self.tables.impl_constness.set(def_id.index, constness);
1293+
self.tables.constness.set(def_id.index, constness);
12941294
record!(self.tables.kind[def_id] <- EntryKind::AssocFn(self.lazy(AssocFnData {
12951295
container,
12961296
has_self: impl_item.fn_has_self_parameter,
@@ -1413,7 +1413,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14131413
hir::ItemKind::Fn(ref sig, .., body) => {
14141414
self.tables.asyncness.set(def_id.index, sig.header.asyncness);
14151415
record_array!(self.tables.fn_arg_names[def_id] <- self.tcx.hir().body_param_names(body));
1416-
self.tables.impl_constness.set(def_id.index, sig.header.constness);
1416+
self.tables.constness.set(def_id.index, sig.header.constness);
14171417
EntryKind::Fn
14181418
}
14191419
hir::ItemKind::Macro(ref macro_def, _) => {
@@ -1437,7 +1437,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14371437
hir::ItemKind::Struct(ref struct_def, _) => {
14381438
let adt_def = self.tcx.adt_def(def_id);
14391439
record!(self.tables.repr_options[def_id] <- adt_def.repr());
1440-
self.tables.impl_constness.set(def_id.index, hir::Constness::Const);
1440+
self.tables.constness.set(def_id.index, hir::Constness::Const);
14411441

14421442
// Encode def_ids for each field and method
14431443
// for methods, write all the stuff get_trait_method
@@ -1468,7 +1468,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14681468
}
14691469
hir::ItemKind::Impl(hir::Impl { defaultness, constness, .. }) => {
14701470
self.tables.impl_defaultness.set(def_id.index, *defaultness);
1471-
self.tables.impl_constness.set(def_id.index, *constness);
1471+
self.tables.constness.set(def_id.index, *constness);
14721472

14731473
let trait_ref = self.tcx.impl_trait_ref(def_id);
14741474
if let Some(trait_ref) = trait_ref {
@@ -1934,7 +1934,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
19341934
} else {
19351935
hir::Constness::NotConst
19361936
};
1937-
self.tables.impl_constness.set(def_id.index, constness);
1937+
self.tables.constness.set(def_id.index, constness);
19381938
record!(self.tables.kind[def_id] <- EntryKind::ForeignFn);
19391939
}
19401940
hir::ForeignItemKind::Static(..) => {

compiler/rustc_metadata/src/rmeta/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ define_tables! {
364364
thir_abstract_const: Table<DefIndex, LazyValue<&'static [thir::abstract_const::Node<'static>]>>,
365365
impl_parent: Table<DefIndex, RawDefId>,
366366
impl_polarity: Table<DefIndex, ty::ImplPolarity>,
367-
impl_constness: Table<DefIndex, hir::Constness>,
367+
constness: Table<DefIndex, hir::Constness>,
368368
is_intrinsic: Table<DefIndex, ()>,
369369
impl_defaultness: Table<DefIndex, hir::Defaultness>,
370370
// FIXME(eddyb) perhaps compute this on the fly if cheap enough?

compiler/rustc_middle/src/query/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,9 @@ rustc_queries! {
590590
/// not have the feature gate active).
591591
///
592592
/// **Do not call this function manually.** It is only meant to cache the base data for the
593-
/// `is_const_fn` function.
594-
query impl_constness(key: DefId) -> hir::Constness {
595-
desc { |tcx| "checking if item is const fn: `{}`", tcx.def_path_str(key) }
593+
/// `is_const_fn` function. Consider using `is_const_fn` or `is_const_fn_raw` instead.
594+
query constness(key: DefId) -> hir::Constness {
595+
desc { |tcx| "checking if item is const: `{}`", tcx.def_path_str(key) }
596596
cache_on_disk_if { key.is_local() }
597597
separate_provide_extern
598598
}

compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2341,7 +2341,7 @@ impl<'tcx> TyCtxt<'tcx> {
23412341
#[inline]
23422342
pub fn is_const_fn_raw(self, def_id: DefId) -> bool {
23432343
matches!(self.def_kind(def_id), DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..))
2344-
&& self.impl_constness(def_id) == hir::Constness::Const
2344+
&& self.constness(def_id) == hir::Constness::Const
23452345
}
23462346

23472347
#[inline]

compiler/rustc_middle/src/ty/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ impl<'tcx> TyCtxt<'tcx> {
376376
let (did, constness) = self.find_map_relevant_impl(drop_trait, ty, |impl_did| {
377377
if let Some(item_id) = self.associated_item_def_ids(impl_did).first() {
378378
if validate(self, impl_did).is_ok() {
379-
return Some((*item_id, self.impl_constness(impl_did)));
379+
return Some((*item_id, self.constness(impl_did)));
380380
}
381381
}
382382
None

compiler/rustc_target/src/spec/asmjs_unknown_emscripten.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ use super::{wasm32_unknown_emscripten, LinkerFlavor, Target};
22

33
pub fn target() -> Target {
44
let mut target = wasm32_unknown_emscripten::target();
5-
target
6-
.post_link_args
7-
.entry(LinkerFlavor::Em)
8-
.or_default()
9-
.extend(vec!["-s".into(), "WASM=0".into()]);
5+
target.post_link_args.entry(LinkerFlavor::Em).or_default().extend(vec![
6+
"-sWASM=0".into(),
7+
"--memory-init-file".into(),
8+
"0".into(),
9+
]);
1010
target
1111
}

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
970970

971971
if let Some(impl_def_id) = relevant_impl {
972972
// Check that `impl Drop` is actually const, if there is a custom impl
973-
if self.tcx().impl_constness(impl_def_id) == hir::Constness::Const {
973+
if self.tcx().constness(impl_def_id) == hir::Constness::Const {
974974
candidates.vec.push(ConstDestructCandidate(Some(impl_def_id)));
975975
}
976976
} else {

compiler/rustc_trait_selection/src/traits/select/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1119,8 +1119,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11191119
if obligation.is_const() {
11201120
match candidate {
11211121
// const impl
1122-
ImplCandidate(def_id)
1123-
if tcx.impl_constness(def_id) == hir::Constness::Const => {}
1122+
ImplCandidate(def_id) if tcx.constness(def_id) == hir::Constness::Const => {}
11241123
// const param
11251124
ParamCandidate(trait_pred) if trait_pred.is_const_if_const() => {}
11261125
// auto trait impl

compiler/rustc_typeck/src/check/wfcheck.rs

+4-17
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<'tcx>>(
490490
// The bounds we that we would require from `to_check`
491491
let mut bounds = FxHashSet::default();
492492

493-
let (regions, types) = GATSubstCollector::visit(tcx, gat_def_id.to_def_id(), to_check);
493+
let (regions, types) = GATSubstCollector::visit(gat_def_id.to_def_id(), to_check);
494494

495495
// If both regions and types are empty, then this GAT isn't in the
496496
// set of types we are checking, and we shouldn't try to do clause analysis
@@ -664,7 +664,6 @@ fn resolve_regions_with_wf_tys<'tcx>(
664664
/// the two vectors, `regions` and `types` (depending on their kind). For each
665665
/// parameter `Pi` also track the index `i`.
666666
struct GATSubstCollector<'tcx> {
667-
tcx: TyCtxt<'tcx>,
668667
gat: DefId,
669668
// Which region appears and which parameter index its substituted for
670669
regions: FxHashSet<(ty::Region<'tcx>, usize)>,
@@ -674,16 +673,11 @@ struct GATSubstCollector<'tcx> {
674673

675674
impl<'tcx> GATSubstCollector<'tcx> {
676675
fn visit<T: TypeFoldable<'tcx>>(
677-
tcx: TyCtxt<'tcx>,
678676
gat: DefId,
679677
t: T,
680678
) -> (FxHashSet<(ty::Region<'tcx>, usize)>, FxHashSet<(Ty<'tcx>, usize)>) {
681-
let mut visitor = GATSubstCollector {
682-
tcx,
683-
gat,
684-
regions: FxHashSet::default(),
685-
types: FxHashSet::default(),
686-
};
679+
let mut visitor =
680+
GATSubstCollector { gat, regions: FxHashSet::default(), types: FxHashSet::default() };
687681
t.visit_with(&mut visitor);
688682
(visitor.regions, visitor.types)
689683
}
@@ -692,19 +686,12 @@ impl<'tcx> GATSubstCollector<'tcx> {
692686
impl<'tcx> TypeVisitor<'tcx> for GATSubstCollector<'tcx> {
693687
type BreakTy = !;
694688

695-
fn visit_binder<T: TypeFoldable<'tcx>>(
696-
&mut self,
697-
t: &ty::Binder<'tcx, T>,
698-
) -> ControlFlow<Self::BreakTy> {
699-
self.tcx.liberate_late_bound_regions(self.gat, t.clone()).visit_with(self)
700-
}
701-
702689
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
703690
match t.kind() {
704691
ty::Projection(p) if p.item_def_id == self.gat => {
705692
for (idx, subst) in p.substs.iter().enumerate() {
706693
match subst.unpack() {
707-
GenericArgKind::Lifetime(lt) => {
694+
GenericArgKind::Lifetime(lt) if !lt.is_late_bound() => {
708695
self.regions.insert((lt, idx));
709696
}
710697
GenericArgKind::Type(t) => {

library/alloc/src/collections/btree/map.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1644,11 +1644,11 @@ impl<K, V, A: Allocator + Clone> IntoIter<K, V, A> {
16441644
&mut self,
16451645
) -> Option<Handle<NodeRef<marker::Dying, K, V, marker::LeafOrInternal>, marker::KV>> {
16461646
if self.length == 0 {
1647-
self.range.deallocating_end(&self.alloc);
1647+
self.range.deallocating_end(self.alloc.clone());
16481648
None
16491649
} else {
16501650
self.length -= 1;
1651-
Some(unsafe { self.range.deallocating_next_unchecked(&self.alloc) })
1651+
Some(unsafe { self.range.deallocating_next_unchecked(self.alloc.clone()) })
16521652
}
16531653
}
16541654

@@ -1658,11 +1658,11 @@ impl<K, V, A: Allocator + Clone> IntoIter<K, V, A> {
16581658
&mut self,
16591659
) -> Option<Handle<NodeRef<marker::Dying, K, V, marker::LeafOrInternal>, marker::KV>> {
16601660
if self.length == 0 {
1661-
self.range.deallocating_end(&self.alloc);
1661+
self.range.deallocating_end(self.alloc.clone());
16621662
None
16631663
} else {
16641664
self.length -= 1;
1665-
Some(unsafe { self.range.deallocating_next_back_unchecked(&self.alloc) })
1665+
Some(unsafe { self.range.deallocating_next_back_unchecked(self.alloc.clone()) })
16661666
}
16671667
}
16681668
}
@@ -1849,7 +1849,7 @@ where
18491849
type Item = (K, V);
18501850

18511851
fn next(&mut self) -> Option<(K, V)> {
1852-
self.inner.next(&mut self.pred, &self.alloc)
1852+
self.inner.next(&mut self.pred, self.alloc.clone())
18531853
}
18541854

18551855
fn size_hint(&self) -> (usize, Option<usize>) {

library/alloc/src/collections/btree/set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,7 @@ where
13201320
fn next(&mut self) -> Option<T> {
13211321
let pred = &mut self.pred;
13221322
let mut mapped_pred = |k: &T, _v: &mut ()| pred(k);
1323-
self.inner.next(&mut mapped_pred, &self.alloc).map(|(k, _)| k)
1323+
self.inner.next(&mut mapped_pred, self.alloc.clone()).map(|(k, _)| k)
13241324
}
13251325

13261326
fn size_hint(&self) -> (usize, Option<usize>) {

library/std/src/alloc.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl System {
187187
old_size => unsafe {
188188
let new_ptr = self.alloc_impl(new_layout, zeroed)?;
189189
ptr::copy_nonoverlapping(ptr.as_ptr(), new_ptr.as_mut_ptr(), old_size);
190-
Allocator::deallocate(&self, ptr, old_layout);
190+
Allocator::deallocate(self, ptr, old_layout);
191191
Ok(new_ptr)
192192
},
193193
}
@@ -254,7 +254,7 @@ unsafe impl Allocator for System {
254254
match new_layout.size() {
255255
// SAFETY: conditions must be upheld by the caller
256256
0 => unsafe {
257-
Allocator::deallocate(&self, ptr, old_layout);
257+
Allocator::deallocate(self, ptr, old_layout);
258258
Ok(NonNull::slice_from_raw_parts(new_layout.dangling(), 0))
259259
},
260260

@@ -274,9 +274,9 @@ unsafe impl Allocator for System {
274274
// `new_ptr`. Thus, the call to `copy_nonoverlapping` is safe. The safety contract
275275
// for `dealloc` must be upheld by the caller.
276276
new_size => unsafe {
277-
let new_ptr = Allocator::allocate(&self, new_layout)?;
277+
let new_ptr = Allocator::allocate(self, new_layout)?;
278278
ptr::copy_nonoverlapping(ptr.as_ptr(), new_ptr.as_mut_ptr(), new_size);
279-
Allocator::deallocate(&self, ptr, old_layout);
279+
Allocator::deallocate(self, ptr, old_layout);
280280
Ok(new_ptr)
281281
},
282282
}

src/etc/htmldocck.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ def check_snapshot(snapshot_name, actual_tree, normalize_to_text):
417417
snapshot_path = '{}.{}.{}'.format(rust_test_path[:-3], snapshot_name, 'html')
418418
try:
419419
with open(snapshot_path, 'r') as snapshot_file:
420-
expected_str = snapshot_file.read()
420+
expected_str = snapshot_file.read().replace("{{channel}}", channel)
421421
except FileNotFoundError:
422422
if bless:
423423
expected_str = None
@@ -429,8 +429,6 @@ def check_snapshot(snapshot_name, actual_tree, normalize_to_text):
429429
else:
430430
actual_str = flatten(actual_tree)
431431

432-
expected_str = expected_str.replace("{{channel}}", channel)
433-
434432
# Conditions:
435433
# 1. Is --bless
436434
# 2. Are actual and expected tree different

0 commit comments

Comments
 (0)