Skip to content

Commit f2568c8

Browse files
committed
Auto merge of rust-lang#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

+11
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

+8-1
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

+5-14
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

-4
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

+1-1
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

+1-1
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

+23-24
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

+2-2
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

+1
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

+4-4
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
}

compiler/rustc_error_codes/src/error_codes/E0446.md

+25-21
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
A private type was used in a public type signature.
1+
A private type or trait was used in a public associated type signature.
22

33
Erroneous code example:
44

55
```compile_fail,E0446
6-
#![deny(private_in_public)]
7-
struct Bar(u32);
8-
9-
mod foo {
10-
use crate::Bar;
11-
pub fn bar() -> Bar { // error: private type in public interface
12-
Bar(0)
13-
}
6+
struct Bar;
7+
8+
pub trait PubTr {
9+
type Alias;
10+
}
11+
12+
impl PubTr for u8 {
13+
type Alias = Bar; // error private type in public interface
1414
}
1515
1616
fn main() {}
@@ -22,13 +22,14 @@ This is done by using pub(crate) or pub(in crate::my_mod::etc)
2222
Example:
2323

2424
```
25-
struct Bar(u32);
25+
struct Bar;
26+
27+
pub(crate) trait PubTr { // only public to crate root
28+
type Alias;
29+
}
2630
27-
mod foo {
28-
use crate::Bar;
29-
pub(crate) fn bar() -> Bar { // only public to crate root
30-
Bar(0)
31-
}
31+
impl PubTr for u8 {
32+
type Alias = Bar;
3233
}
3334
3435
fn main() {}
@@ -38,12 +39,15 @@ The other way to solve this error is to make the private type public.
3839
Example:
3940

4041
```
41-
pub struct Bar(u32); // we set the Bar type public
42-
mod foo {
43-
use crate::Bar;
44-
pub fn bar() -> Bar { // ok!
45-
Bar(0)
46-
}
42+
43+
pub struct Bar; // we set the Bar trait public
44+
45+
pub trait PubTr {
46+
type Alias;
47+
}
48+
49+
impl PubTr for u8 {
50+
type Alias = Bar;
4751
}
4852
4953
fn main() {}

compiler/rustc_errors/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ use std::num::NonZeroUsize;
5555
use std::panic;
5656
use std::path::{Path, PathBuf};
5757

58+
// Used by external projects such as `rust-gpu`.
59+
// See https://github.com/rust-lang/rust/pull/115393.
5860
pub use termcolor::{Color, ColorSpec, WriteColor};
5961

6062
pub mod annotate_snippet_emitter_writer;

compiler/rustc_feature/src/accepted.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ declare_features! (
5454
/// instead of just the platforms on which it is the C ABI.
5555
(accepted, abi_sysv64, "1.24.0", Some(36167), None),
5656
/// Allows using the `thiscall` ABI.
57-
(accepted, abi_thiscall, "1.19.0", None, None),
57+
(accepted, abi_thiscall, "1.73.0", None, None),
5858
/// Allows using ADX intrinsics from `core::arch::{x86, x86_64}`.
5959
(accepted, adx_target_feature, "1.61.0", Some(44839), None),
6060
/// Allows explicit discriminants on non-unit enum variants.

compiler/rustc_hir/src/hir.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3729,6 +3729,8 @@ impl<'hir> Node<'hir> {
37293729
Node::Lifetime(lt) => Some(lt.ident),
37303730
Node::GenericParam(p) => Some(p.name.ident()),
37313731
Node::TypeBinding(b) => Some(b.ident),
3732+
Node::PatField(f) => Some(f.ident),
3733+
Node::ExprField(f) => Some(f.ident),
37323734
Node::Param(..)
37333735
| Node::AnonConst(..)
37343736
| Node::ConstBlock(..)
@@ -3737,8 +3739,6 @@ impl<'hir> Node<'hir> {
37373739
| Node::Block(..)
37383740
| Node::Ctor(..)
37393741
| Node::Pat(..)
3740-
| Node::PatField(..)
3741-
| Node::ExprField(..)
37423742
| Node::Arm(..)
37433743
| Node::Local(..)
37443744
| Node::Crate(..)

compiler/rustc_hir_analysis/src/astconv/mod.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -910,19 +910,24 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
910910
) -> Ty<'tcx> {
911911
let tcx = self.tcx();
912912
let args = self.ast_path_args_for_ty(span, did, item_segment);
913-
let ty = tcx.at(span).type_of(did);
914913

915-
if let DefKind::TyAlias { lazy } = tcx.def_kind(did)
916-
&& (lazy || ty.skip_binder().has_opaque_types())
917-
{
918-
// Type aliases referring to types that contain opaque types (but aren't just directly
919-
// referencing a single opaque type) as well as those defined in crates that have the
914+
if let DefKind::TyAlias { lazy: true } = tcx.def_kind(did) {
915+
// Type aliases defined in crates that have the
920916
// feature `lazy_type_alias` enabled get encoded as a type alias that normalization will
921917
// then actually instantiate the where bounds of.
922918
let alias_ty = tcx.mk_alias_ty(did, args);
923919
Ty::new_alias(tcx, ty::Weak, alias_ty)
924920
} else {
925-
ty.instantiate(tcx, args)
921+
let ty = tcx.at(span).type_of(did);
922+
if ty.skip_binder().has_opaque_types() {
923+
// Type aliases referring to types that contain opaque types (but aren't just directly
924+
// referencing a single opaque type) get encoded as a type alias that normalization will
925+
// then actually instantiate the where bounds of.
926+
let alias_ty = tcx.mk_alias_ty(did, args);
927+
Ty::new_alias(tcx, ty::Weak, alias_ty)
928+
} else {
929+
ty.instantiate(tcx, args)
930+
}
926931
}
927932
}
928933

0 commit comments

Comments
 (0)