Skip to content

Commit f2568c8

Browse files
committed
Auto merge of #3050 - RalfJung:rustup, r=RalfJung
Rustup
2 parents d2f5dc9 + fb26c21 commit f2568c8

File tree

251 files changed

+3878
-3081
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

251 files changed

+3878
-3081
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ trait ResolverAstLoweringExt {
153153
fn get_label_res(&self, id: NodeId) -> Option<NodeId>;
154154
fn get_lifetime_res(&self, id: NodeId) -> Option<LifetimeRes>;
155155
fn take_extra_lifetime_params(&mut self, id: NodeId) -> Vec<(Ident, NodeId, LifetimeRes)>;
156+
fn remap_extra_lifetime_params(&mut self, from: NodeId, to: NodeId);
156157
fn decl_macro_kind(&self, def_id: LocalDefId) -> MacroKind;
157158
}
158159

@@ -213,6 +214,11 @@ impl ResolverAstLoweringExt for ResolverAstLowering {
213214
self.extra_lifetime_params_map.remove(&id).unwrap_or_default()
214215
}
215216

217+
fn remap_extra_lifetime_params(&mut self, from: NodeId, to: NodeId) {
218+
let lifetimes = self.extra_lifetime_params_map.remove(&from).unwrap_or_default();
219+
self.extra_lifetime_params_map.insert(to, lifetimes);
220+
}
221+
216222
fn decl_macro_kind(&self, def_id: LocalDefId) -> MacroKind {
217223
self.builtin_macro_kinds.get(&def_id).copied().unwrap_or(MacroKind::Bang)
218224
}
@@ -1089,6 +1095,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10891095
// constructing the HIR for `impl bounds...` and then lowering that.
10901096

10911097
let impl_trait_node_id = self.next_node_id();
1098+
// Shift `impl Trait` lifetime captures from the associated type bound's
1099+
// node id to the opaque node id, so that the opaque can actually use
1100+
// these lifetime bounds.
1101+
self.resolver
1102+
.remap_extra_lifetime_params(constraint.id, impl_trait_node_id);
10921103

10931104
self.with_dyn_type_scope(false, |this| {
10941105
let node_id = this.next_node_id();

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2249,7 +2249,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
22492249
}
22502250

22512251
pub(crate) fn universe_info(&self, universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
2252-
self.universe_causes[&universe].clone()
2252+
// Query canonicalization can create local superuniverses (for example in
2253+
// `InferCtx::query_response_substitution_guess`), but they don't have an associated
2254+
// `UniverseInfo` explaining why they were created.
2255+
// This can cause ICEs if these causes are accessed in diagnostics, for example in issue
2256+
// #114907 where this happens via liveness and dropck outlives results.
2257+
// Therefore, we return a default value in case that happens, which should at worst emit a
2258+
// suboptimal error, instead of the ICE.
2259+
self.universe_causes.get(&universe).cloned().unwrap_or_else(|| UniverseInfo::other())
22532260
}
22542261

22552262
/// Tries to find the terminator of the loop in which the region 'r' resides.

compiler/rustc_borrowck/src/type_check/canonical.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_span::Span;
99
use rustc_trait_selection::traits::query::type_op::{self, TypeOpOutput};
1010
use rustc_trait_selection::traits::ObligationCause;
1111

12-
use crate::diagnostics::{ToUniverseInfo, UniverseInfo};
12+
use crate::diagnostics::ToUniverseInfo;
1313

1414
use super::{Locations, NormalizeLocation, TypeChecker};
1515

@@ -46,13 +46,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
4646
self.push_region_constraints(locations, category, data);
4747
}
4848

49+
// If the query has created new universes and errors are going to be emitted, register the
50+
// cause of these new universes for improved diagnostics.
4951
let universe = self.infcx.universe();
50-
51-
if old_universe != universe {
52-
let universe_info = match error_info {
53-
Some(error_info) => error_info.to_universe_info(old_universe),
54-
None => UniverseInfo::other(),
55-
};
52+
if old_universe != universe && let Some(error_info) = error_info {
53+
let universe_info = error_info.to_universe_info(old_universe);
5654
for u in (old_universe + 1)..=universe {
5755
self.borrowck_context.constraints.universe_causes.insert(u, universe_info.clone());
5856
}
@@ -69,15 +67,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
6967
where
7068
T: TypeFoldable<TyCtxt<'tcx>>,
7169
{
72-
let old_universe = self.infcx.universe();
73-
7470
let (instantiated, _) =
7571
self.infcx.instantiate_canonical_with_fresh_inference_vars(span, canonical);
76-
77-
for u in (old_universe + 1)..=self.infcx.universe() {
78-
self.borrowck_context.constraints.universe_causes.insert(u, UniverseInfo::other());
79-
}
80-
8172
instantiated
8273
}
8374

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,6 @@ pub(crate) fn type_check<'mir, 'tcx>(
163163

164164
debug!(?normalized_inputs_and_output);
165165

166-
for u in ty::UniverseIndex::ROOT..=infcx.universe() {
167-
constraints.universe_causes.insert(u, UniverseInfo::other());
168-
}
169-
170166
let mut borrowck_context = BorrowCheckContext {
171167
universal_regions,
172168
location_table,

compiler/rustc_codegen_llvm/src/back/archive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ impl<'a> LlvmArchiveBuilder<'a> {
367367
match addition {
368368
Addition::File { path, name_in_archive } => {
369369
let path = CString::new(path.to_str().unwrap())?;
370-
let name = CString::new(name_in_archive.clone())?;
370+
let name = CString::new(name_in_archive.as_bytes())?;
371371
members.push(llvm::LLVMRustArchiveMemberNew(
372372
path.as_ptr(),
373373
name.as_ptr(),

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ fn thin_lto(
441441

442442
for (i, (name, buffer)) in modules.into_iter().enumerate() {
443443
info!("local module: {} - {}", i, name);
444-
let cname = CString::new(name.clone()).unwrap();
444+
let cname = CString::new(name.as_bytes()).unwrap();
445445
thin_modules.push(llvm::ThinLTOModule {
446446
identifier: cname.as_ptr(),
447447
data: buffer.data().as_ptr(),

compiler/rustc_const_eval/src/interpret/terminator.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
254254
}
255255

256256
/// Find the wrapped inner type of a transparent wrapper.
257+
/// Must not be called on 1-ZST (as they don't have a uniquely defined "wrapped field").
257258
fn unfold_transparent(&self, layout: TyAndLayout<'tcx>) -> TyAndLayout<'tcx> {
258259
match layout.ty.kind() {
259260
ty::Adt(adt_def, _) if adt_def.repr().transparent() => {
@@ -263,11 +264,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
263264
let field = layout.field(self, idx);
264265
if field.is_1zst() { None } else { Some(field) }
265266
});
266-
let Some(first) = non_1zst_fields.next() else {
267-
// All fields are 1-ZST, so this is basically the same as `()`.
268-
// (We still also compare the `PassMode`, so if this target does something strange with 1-ZST there, we'll know.)
269-
return self.layout_of(self.tcx.types.unit).unwrap();
270-
};
267+
let first = non_1zst_fields.next().expect("`unfold_transparent` called on 1-ZST");
271268
assert!(
272269
non_1zst_fields.next().is_none(),
273270
"more than one non-1-ZST field in a transparent type"
@@ -289,17 +286,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
289286
caller_layout: TyAndLayout<'tcx>,
290287
callee_layout: TyAndLayout<'tcx>,
291288
) -> bool {
292-
fn primitive_abi_compat(a1: abi::Primitive, a2: abi::Primitive) -> bool {
293-
match (a1, a2) {
294-
// For integers, ignore the sign.
295-
(abi::Primitive::Int(int_ty1, _sign1), abi::Primitive::Int(int_ty2, _sign2)) => {
296-
int_ty1 == int_ty2
297-
}
298-
// For everything else we require full equality.
299-
_ => a1 == a2,
300-
}
301-
}
302-
303289
if caller_layout.ty == callee_layout.ty {
304290
// Fast path: equal types are definitely compatible.
305291
return true;
@@ -308,27 +294,40 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
308294
match (caller_layout.abi, callee_layout.abi) {
309295
// If both sides have Scalar/Vector/ScalarPair ABI, we can easily directly compare them.
310296
// Different valid ranges are okay (the validity check will complain if this leads to
311-
// invalid transmutes).
297+
// invalid transmutes). Different signs are *not* okay on some targets (e.g. `extern
298+
// "C"` on `s390x` where small integers are passed zero/sign-extended in large
299+
// registers), so we generally reject them to increase portability.
300+
// NOTE: this is *not* a stable guarantee! It just reflects a property of our current
301+
// ABIs. It's also fragile; the same pair of types might be considered ABI-compatible
302+
// when used directly by-value but not considered compatible as a struct field or array
303+
// element.
312304
(abi::Abi::Scalar(caller), abi::Abi::Scalar(callee)) => {
313-
primitive_abi_compat(caller.primitive(), callee.primitive())
305+
caller.primitive() == callee.primitive()
314306
}
315307
(
316308
abi::Abi::Vector { element: caller_element, count: caller_count },
317309
abi::Abi::Vector { element: callee_element, count: callee_count },
318310
) => {
319-
primitive_abi_compat(caller_element.primitive(), callee_element.primitive())
311+
caller_element.primitive() == callee_element.primitive()
320312
&& caller_count == callee_count
321313
}
322314
(abi::Abi::ScalarPair(caller1, caller2), abi::Abi::ScalarPair(callee1, callee2)) => {
323-
primitive_abi_compat(caller1.primitive(), callee1.primitive())
324-
&& primitive_abi_compat(caller2.primitive(), callee2.primitive())
315+
caller1.primitive() == callee1.primitive()
316+
&& caller2.primitive() == callee2.primitive()
325317
}
326318
(abi::Abi::Aggregate { .. }, abi::Abi::Aggregate { .. }) => {
327-
// Aggregates are compatible only if they newtype-wrap the same type.
319+
// Aggregates are compatible only if they newtype-wrap the same type, or if they are both 1-ZST.
320+
// (The latter part is needed to ensure e.g. that `struct Zst` is compatible with `struct Wrap((), Zst)`.)
328321
// This is conservative, but also means that our check isn't quite so heavily dependent on the `PassMode`,
329322
// which means having ABI-compatibility on one target is much more likely to imply compatibility for other targets.
330-
self.unfold_transparent(caller_layout).ty
331-
== self.unfold_transparent(callee_layout).ty
323+
if caller_layout.is_1zst() || callee_layout.is_1zst() {
324+
// If either is a 1-ZST, both must be.
325+
caller_layout.is_1zst() && callee_layout.is_1zst()
326+
} else {
327+
// Neither is a 1-ZST, so we can check what they are wrapping.
328+
self.unfold_transparent(caller_layout).ty
329+
== self.unfold_transparent(callee_layout).ty
330+
}
332331
}
333332
// What remains is `Abi::Uninhabited` (which can never be passed anyway) and
334333
// mismatching ABIs, that should all be rejected.

compiler/rustc_data_structures/src/sync.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ cfg_if! {
273273
pub use std::cell::RefMut as MappedWriteGuard;
274274
pub use std::cell::RefMut as MappedLockGuard;
275275

276-
pub use std::cell::OnceCell;
276+
pub use std::cell::OnceCell as OnceLock;
277277

278278
use std::cell::RefCell as InnerRwLock;
279279

@@ -327,7 +327,7 @@ cfg_if! {
327327

328328
pub use parking_lot::MappedMutexGuard as MappedLockGuard;
329329

330-
pub use std::sync::OnceLock as OnceCell;
330+
pub use std::sync::OnceLock;
331331

332332
pub use std::sync::atomic::{AtomicBool, AtomicUsize, AtomicU32, AtomicU64};
333333

compiler/rustc_error_codes/src/error_codes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ E0794: include_str!("./error_codes/E0794.md"),
608608
// E0420, // merged into 532
609609
// E0421, // merged into 531
610610
// E0427, // merged into 530
611+
// E0445, // merged into 446 and type privacy lints
611612
// E0456, // plugin `..` is not available for triple `..`
612613
// E0465, // removed: merged with E0464
613614
// E0467, // removed

compiler/rustc_error_codes/src/error_codes/E0445.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
A private trait was used on a public type parameter bound.
1+
#### Note: this error code is no longer emitted by the compiler.
22

3-
Erroneous code examples:
3+
A private trait was used on a public type parameter bound.
44

5-
```compile_fail,E0445
6-
#![deny(private_in_public)]
5+
Previously erroneous code examples:
76

7+
```
88
trait Foo {
99
fn dummy(&self) { }
1010
}

0 commit comments

Comments
 (0)