Skip to content

Commit 604d521

Browse files
committed
Auto merge of rust-lang#104743 - JohnTitor:rollup-9z9u7yd, r=JohnTitor
Rollup of 7 pull requests Successful merges: - rust-lang#101368 (Forbid inlining `thread_local!`'s `__getit` function on Windows) - rust-lang#102293 (Add powerpc64-ibm-aix as Tier-3 target) - rust-lang#104717 (Add failing test for projections used as const generic) - rust-lang#104720 (rustdoc: remove no-op CSS `.popover::before / a.test-arrow { display: inline-block }`) - rust-lang#104722 (Speed up mpsc_stress test) - rust-lang#104724 (Fix `ClosureKind::to_def_id`) - rust-lang#104728 (Use `tcx.require_lang_item` instead of unwrapping lang items) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents ff8c8df + 3ec1ca0 commit 604d521

File tree

22 files changed

+218
-54
lines changed

22 files changed

+218
-54
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_errors::{
77
};
88
use rustc_hir as hir;
99
use rustc_hir::intravisit::{walk_block, walk_expr, Visitor};
10-
use rustc_hir::{AsyncGeneratorKind, GeneratorKind};
10+
use rustc_hir::{AsyncGeneratorKind, GeneratorKind, LangItem};
1111
use rustc_infer::infer::TyCtxtInferExt;
1212
use rustc_infer::traits::ObligationCause;
1313
use rustc_middle::mir::tcx::PlaceTy;
@@ -601,7 +601,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
601601
else { return; };
602602
// Try to find predicates on *generic params* that would allow copying `ty`
603603
let infcx = tcx.infer_ctxt().build();
604-
let copy_did = infcx.tcx.lang_items().copy_trait().unwrap();
604+
let copy_did = infcx.tcx.require_lang_item(LangItem::Copy, Some(span));
605605
let cause = ObligationCause::new(
606606
span,
607607
self.mir_hir_id(),

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Concrete error types for all operations which may be invalid in a certain const context.
22
33
use hir::def_id::LocalDefId;
4-
use hir::ConstContext;
4+
use hir::{ConstContext, LangItem};
55
use rustc_errors::{
66
error_code, struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed,
77
};
@@ -304,7 +304,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
304304
err.span_note(deref_target, "deref defined here");
305305
}
306306

307-
diag_trait(&mut err, self_ty, tcx.lang_items().deref_trait().unwrap());
307+
diag_trait(&mut err, self_ty, tcx.require_lang_item(LangItem::Deref, Some(span)));
308308
err
309309
}
310310
_ if tcx.opt_parent(callee) == tcx.get_diagnostic_item(sym::ArgumentV1Methods) => {

compiler/rustc_const_eval/src/util/call_kind.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! context.
44
55
use rustc_hir::def_id::DefId;
6-
use rustc_hir::lang_items;
6+
use rustc_hir::{lang_items, LangItem};
77
use rustc_middle::ty::subst::SubstsRef;
88
use rustc_middle::ty::{self, AssocItemContainer, DefIdTree, Instance, ParamEnv, Ty, TyCtxt};
99
use rustc_span::symbol::Ident;
@@ -26,7 +26,7 @@ impl CallDesugaringKind {
2626
match self {
2727
Self::ForLoopIntoIter => tcx.get_diagnostic_item(sym::IntoIterator).unwrap(),
2828
Self::QuestionBranch | Self::TryBlockFromOutput => {
29-
tcx.lang_items().try_trait().unwrap()
29+
tcx.require_lang_item(LangItem::Try, None)
3030
}
3131
Self::QuestionFromResidual => tcx.get_diagnostic_item(sym::FromResidual).unwrap(),
3232
}

compiler/rustc_hir_analysis/src/coherence/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
114114
traits::ObligationCause::dummy_with_span(field_ty_span),
115115
param_env,
116116
ty,
117-
tcx.lang_items().copy_trait().unwrap(),
117+
tcx.require_lang_item(LangItem::Copy, Some(span)),
118118
) {
119119
let error_predicate = error.obligation.predicate;
120120
// Only note if it's not the root obligation, otherwise it's trivial and

compiler/rustc_hir_typeck/src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11181118
let lhs_deref_ty_is_sized = self
11191119
.infcx
11201120
.type_implements_trait(
1121-
self.tcx.lang_items().sized_trait().unwrap(),
1121+
self.tcx.require_lang_item(LangItem::Sized, None),
11221122
[lhs_deref_ty],
11231123
self.param_env,
11241124
)

compiler/rustc_middle/src/ty/closure.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::{mir, ty};
55

66
use std::fmt::Write;
77

8+
use hir::LangItem;
89
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
910
use rustc_hir as hir;
1011
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -130,11 +131,14 @@ impl<'tcx> ClosureKind {
130131
}
131132

132133
pub fn to_def_id(&self, tcx: TyCtxt<'_>) -> DefId {
133-
match self {
134-
ClosureKind::Fn => tcx.lang_items().fn_once_trait().unwrap(),
135-
ClosureKind::FnMut => tcx.lang_items().fn_mut_trait().unwrap(),
136-
ClosureKind::FnOnce => tcx.lang_items().fn_trait().unwrap(),
137-
}
134+
tcx.require_lang_item(
135+
match self {
136+
ClosureKind::Fn => LangItem::Fn,
137+
ClosureKind::FnMut => LangItem::FnMut,
138+
ClosureKind::FnOnce => LangItem::FnOnce,
139+
},
140+
None,
141+
)
138142
}
139143
}
140144

compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2293,7 +2293,7 @@ impl<'tcx> TyCtxt<'tcx> {
22932293
/// Given a `ty`, return whether it's an `impl Future<...>`.
22942294
pub fn ty_is_opaque_future(self, ty: Ty<'_>) -> bool {
22952295
let ty::Opaque(def_id, _) = ty.kind() else { return false };
2296-
let future_trait = self.lang_items().future_trait().unwrap();
2296+
let future_trait = self.require_lang_item(LangItem::Future, None);
22972297

22982298
self.explicit_item_bounds(def_id).iter().any(|(predicate, _)| {
22992299
let ty::PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder() else {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use rustc_hir as hir;
1111
use rustc_hir::def::{self, CtorKind, DefKind, Namespace};
1212
use rustc_hir::def_id::{DefId, DefIdSet, CRATE_DEF_ID, LOCAL_CRATE};
1313
use rustc_hir::definitions::{DefPathData, DefPathDataName, DisambiguatedDefPathData};
14+
use rustc_hir::LangItem;
1415
use rustc_session::config::TrimmedDefPaths;
1516
use rustc_session::cstore::{ExternCrate, ExternCrateSource};
1617
use rustc_session::Limit;
@@ -889,7 +890,7 @@ pub trait PrettyPrinter<'tcx>:
889890
// Group the return ty with its def id, if we had one.
890891
entry
891892
.return_ty
892-
.map(|ty| (tcx.lang_items().fn_once_output().unwrap(), ty)),
893+
.map(|ty| (tcx.require_lang_item(LangItem::FnOnce, None), ty)),
893894
);
894895
}
895896
if let Some(trait_ref) = entry.fn_mut_trait_ref {

compiler/rustc_middle/src/ty/sty.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_data_structures::captures::Captures;
1717
use rustc_data_structures::intern::Interned;
1818
use rustc_hir as hir;
1919
use rustc_hir::def_id::DefId;
20+
use rustc_hir::LangItem;
2021
use rustc_index::vec::Idx;
2122
use rustc_macros::HashStable;
2223
use rustc_span::symbol::{kw, sym, Symbol};
@@ -2108,7 +2109,7 @@ impl<'tcx> Ty<'tcx> {
21082109

21092110
ty::Str | ty::Slice(_) => (tcx.types.usize, false),
21102111
ty::Dynamic(..) => {
2111-
let dyn_metadata = tcx.lang_items().dyn_metadata().unwrap();
2112+
let dyn_metadata = tcx.require_lang_item(LangItem::DynMetadata, None);
21122113
(tcx.bound_type_of(dyn_metadata).subst(tcx, &[tail.into()]), false)
21132114
},
21142115

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use crate::abi::Endian;
2+
use crate::spec::{crt_objects, cvs, Cc, CodeModel, LinkOutputKind, LinkerFlavor, TargetOptions};
3+
4+
pub fn opts() -> TargetOptions {
5+
TargetOptions {
6+
abi: "vec-extabi".into(),
7+
code_model: Some(CodeModel::Small),
8+
cpu: "pwr7".into(),
9+
os: "aix".into(),
10+
vendor: "ibm".into(),
11+
dynamic_linking: true,
12+
endian: Endian::Big,
13+
executables: true,
14+
archive_format: "aix_big".into(),
15+
families: cvs!["unix"],
16+
has_rpath: false,
17+
has_thread_local: true,
18+
crt_static_respected: true,
19+
linker_flavor: LinkerFlavor::Unix(Cc::No),
20+
linker: Some("ld".into()),
21+
eh_frame_header: false,
22+
is_like_aix: true,
23+
default_dwarf_version: 3,
24+
function_sections: true,
25+
pre_link_objects: crt_objects::new(&[
26+
(LinkOutputKind::DynamicNoPicExe, &["/usr/lib/crt0_64.o", "/usr/lib/crti_64.o"]),
27+
(LinkOutputKind::DynamicPicExe, &["/usr/lib/crt0_64.o", "/usr/lib/crti_64.o"]),
28+
]),
29+
dll_suffix: ".a".into(),
30+
..Default::default()
31+
}
32+
}

compiler/rustc_target/src/spec/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ use rustc_macros::HashStable_Generic;
5858
pub mod abi;
5959
pub mod crt_objects;
6060

61+
mod aix_base;
6162
mod android_base;
6263
mod apple_base;
6364
mod avr_gnu_base;
@@ -1027,6 +1028,7 @@ supported_targets! {
10271028
("powerpc-unknown-linux-gnu", powerpc_unknown_linux_gnu),
10281029
("powerpc-unknown-linux-gnuspe", powerpc_unknown_linux_gnuspe),
10291030
("powerpc-unknown-linux-musl", powerpc_unknown_linux_musl),
1031+
("powerpc64-ibm-aix", powerpc64_ibm_aix),
10301032
("powerpc64-unknown-linux-gnu", powerpc64_unknown_linux_gnu),
10311033
("powerpc64-unknown-linux-musl", powerpc64_unknown_linux_musl),
10321034
("powerpc64le-unknown-linux-gnu", powerpc64le_unknown_linux_gnu),
@@ -1454,6 +1456,9 @@ pub struct TargetOptions {
14541456
pub families: StaticCow<[StaticCow<str>]>,
14551457
/// Whether the target toolchain's ABI supports returning small structs as an integer.
14561458
pub abi_return_struct_as_int: bool,
1459+
/// Whether the target toolchain is like AIX's. Linker options on AIX are special and it uses
1460+
/// XCOFF as binary format. Defaults to false.
1461+
pub is_like_aix: bool,
14571462
/// Whether the target toolchain is like macOS's. Only useful for compiling against iOS/macOS,
14581463
/// in particular running dsymutil and some other stuff like `-dead_strip`. Defaults to false.
14591464
/// Also indiates whether to use Apple-specific ABI changes, such as extending function
@@ -1817,6 +1822,7 @@ impl Default for TargetOptions {
18171822
staticlib_suffix: ".a".into(),
18181823
families: cvs![],
18191824
abi_return_struct_as_int: false,
1825+
is_like_aix: false,
18201826
is_like_osx: false,
18211827
is_like_solaris: false,
18221828
is_like_windows: false,
@@ -2488,6 +2494,7 @@ impl Target {
24882494
key!(staticlib_suffix);
24892495
key!(families, TargetFamilies);
24902496
key!(abi_return_struct_as_int, bool);
2497+
key!(is_like_aix, bool);
24912498
key!(is_like_osx, bool);
24922499
key!(is_like_solaris, bool);
24932500
key!(is_like_windows, bool);
@@ -2741,6 +2748,7 @@ impl ToJson for Target {
27412748
target_option_val!(staticlib_suffix);
27422749
target_option_val!(families, "target-family");
27432750
target_option_val!(abi_return_struct_as_int);
2751+
target_option_val!(is_like_aix);
27442752
target_option_val!(is_like_osx);
27452753
target_option_val!(is_like_solaris);
27462754
target_option_val!(is_like_windows);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use crate::spec::{Cc, LinkerFlavor, Target};
2+
3+
pub fn target() -> Target {
4+
let mut base = super::aix_base::opts();
5+
base.max_atomic_width = Some(64);
6+
base.add_pre_link_args(
7+
LinkerFlavor::Unix(Cc::No),
8+
&[
9+
"-b64".into(),
10+
"-bpT:0x100000000".into(),
11+
"-bpD:0x110000000".into(),
12+
"-bcdtors:all:0:s".into(),
13+
],
14+
);
15+
16+
Target {
17+
llvm_target: "powerpc64-ibm-aix".into(),
18+
pointer_width: 64,
19+
data_layout: "E-m:a-i64:64-n32:64-S128-v256:256:256-v512:512:512".into(),
20+
arch: "powerpc64".into(),
21+
options: base,
22+
}
23+
}

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2625,7 +2625,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
26252625
}
26262626
};
26272627

2628-
let from_generator = tcx.lang_items().from_generator_fn().unwrap();
2628+
let from_generator = tcx.require_lang_item(LangItem::FromGenerator, None);
26292629

26302630
// Don't print the tuple of capture types
26312631
'print: {

library/std/src/thread/local.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ macro_rules! thread_local {
181181
macro_rules! __thread_local_inner {
182182
// used to generate the `LocalKey` value for const-initialized thread locals
183183
(@key $t:ty, const $init:expr) => {{
184-
#[cfg_attr(not(windows), inline)] // see comments below
184+
#[cfg_attr(not(all(windows, target_thread_local)), inline)] // see comments below
185+
#[cfg_attr(all(windows, target_thread_local), inline(never))]
185186
#[deny(unsafe_op_in_unsafe_fn)]
186187
unsafe fn __getit(
187188
_init: $crate::option::Option<&mut $crate::option::Option<$t>>,
@@ -294,12 +295,17 @@ macro_rules! __thread_local_inner {
294295
fn __init() -> $t { $init }
295296

296297
// When reading this function you might ask "why is this inlined
297-
// everywhere other than Windows?", and that's a very reasonable
298-
// question to ask. The short story is that it segfaults rustc if
299-
// this function is inlined. The longer story is that Windows looks
300-
// to not support `extern` references to thread locals across DLL
301-
// boundaries. This appears to at least not be supported in the ABI
302-
// that LLVM implements.
298+
// everywhere other than Windows?", and "why must it not be inlined
299+
// on Windows?" and these are very reasonable questions to ask.
300+
//
301+
// The short story is that Windows doesn't support referencing
302+
// `#[thread_local]` across DLL boundaries. The slightly longer
303+
// story is that each module (dll or exe) has its own separate set
304+
// of static thread locals, so if you try and reference a
305+
// `#[thread_local]` that comes from `crate1.dll` from within one of
306+
// `crate2.dll`'s functions, then it might give you a completely
307+
// different thread local than what you asked for (or it might just
308+
// crash).
303309
//
304310
// Because of this we never inline on Windows, but we do inline on
305311
// other platforms (where external references to thread locals
@@ -314,8 +320,9 @@ macro_rules! __thread_local_inner {
314320
// Cargo question kinda). This means that, unfortunately, Windows
315321
// gets the pessimistic path for now where it's never inlined.
316322
//
317-
// The issue of "should enable on Windows sometimes" is #84933
318-
#[cfg_attr(not(windows), inline)]
323+
// The issue of "should improve things on Windows" is #84933
324+
#[cfg_attr(not(all(windows, target_thread_local)), inline)]
325+
#[cfg_attr(all(windows, target_thread_local), inline(never))]
319326
unsafe fn __getit(
320327
init: $crate::option::Option<&mut $crate::option::Option<$t>>,
321328
) -> $crate::option::Option<&'static $t> {

src/doc/rustc/src/platform-support.md

+1
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ target | std | host | notes
283283
`powerpc64-wrs-vxworks` | ? | |
284284
`powerpc64le-unknown-linux-musl` | ? | |
285285
[`powerpc64-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | OpenBSD/powerpc64
286+
`powerpc64-ibm-aix` | ? | | 64-bit AIX (7.2 and newer)
286287
`riscv32gc-unknown-linux-gnu` | | | RISC-V Linux (kernel 5.4, glibc 2.33)
287288
`riscv32gc-unknown-linux-musl` | | | RISC-V Linux (kernel 5.4, musl + RISCV32 support patches)
288289
`riscv32im-unknown-none-elf` | * | | Bare RISC-V (RV32IM ISA)

src/librustdoc/html/static/css/rustdoc.css

-2
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,6 @@ so that we can apply CSS-filters to change the arrow color in themes */
932932
right: var(--popover-arrow-offset);
933933
border: solid var(--border-color);
934934
border-width: 1px 1px 0 0;
935-
display: inline-block;
936935
padding: 4px;
937936
transform: rotate(-45deg);
938937
top: -5px;
@@ -1200,7 +1199,6 @@ pre.rust .doccomment {
12001199
}
12011200

12021201
a.test-arrow {
1203-
display: inline-block;
12041202
visibility: hidden;
12051203
position: absolute;
12061204
padding: 5px 10px 5px 10px;

src/test/ui/check-cfg/well-known-values.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | #[cfg(target_os = "linuz")]
66
| |
77
| help: did you mean: `"linux"`
88
|
9-
= note: expected values for `target_os` are: android, cuda, dragonfly, emscripten, espidf, freebsd, fuchsia, haiku, hermit, horizon, illumos, ios, l4re, linux, macos, netbsd, none, nto, openbsd, psp, redox, solaris, solid_asp3, tvos, uefi, unknown, vxworks, wasi, watchos, windows, xous
9+
= note: expected values for `target_os` are: aix, android, cuda, dragonfly, emscripten, espidf, freebsd, fuchsia, haiku, hermit, horizon, illumos, ios, l4re, linux, macos, netbsd, none, nto, openbsd, psp, redox, solaris, solid_asp3, tvos, uefi, unknown, vxworks, wasi, watchos, windows, xous
1010
= note: `#[warn(unexpected_cfgs)]` on by default
1111

1212
warning: unexpected `cfg` condition value
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// This is currently not possible to use projections as const generics.
2+
// More information about this available here:
3+
// https://github.com/rust-lang/rust/pull/104443#discussion_r1029375633
4+
5+
pub trait Identity {
6+
type Identity;
7+
}
8+
9+
impl<T> Identity for T {
10+
type Identity = Self;
11+
}
12+
13+
pub fn foo<const X: <i32 as Identity>::Identity>() {
14+
//~^ ERROR
15+
assert!(X == 12);
16+
}
17+
18+
fn main() {
19+
foo::<12>();
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: `<i32 as Identity>::Identity` is forbidden as the type of a const generic parameter
2+
--> $DIR/projection-as-arg-const.rs:13:21
3+
|
4+
LL | pub fn foo<const X: <i32 as Identity>::Identity>() {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: the only supported types are integers, `bool` and `char`
8+
= help: more complex types are supported with `#![feature(adt_const_params)]`
9+
10+
error: aborting due to previous error
11+

src/test/ui/mismatched_types/overloaded-calls-bad.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,23 @@ impl FnOnce<(isize,)> for S {
2020
}
2121
}
2222

23+
struct F;
24+
25+
impl FnOnce<(i32,)> for F {
26+
type Output = ();
27+
28+
extern "rust-call" fn call_once(self, args: (i32,)) -> Self::Output {}
29+
}
30+
2331
fn main() {
24-
let mut s = S {
25-
x: 3,
26-
y: 3,
27-
};
28-
let ans = s("what"); //~ ERROR mismatched types
32+
let mut s = S { x: 3, y: 3 };
33+
let ans = s("what");
34+
//~^ ERROR mismatched types
2935
let ans = s();
3036
//~^ ERROR this function takes 1 argument but 0 arguments were supplied
3137
let ans = s("burma", "shave");
3238
//~^ ERROR this function takes 1 argument but 2 arguments were supplied
39+
40+
F("");
41+
//~^ ERROR mismatched types
3342
}

0 commit comments

Comments
 (0)