Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #104743

Merged
merged 15 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_errors::{
};
use rustc_hir as hir;
use rustc_hir::intravisit::{walk_block, walk_expr, Visitor};
use rustc_hir::{AsyncGeneratorKind, GeneratorKind};
use rustc_hir::{AsyncGeneratorKind, GeneratorKind, LangItem};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_infer::traits::ObligationCause;
use rustc_middle::mir::tcx::PlaceTy;
Expand Down Expand Up @@ -601,7 +601,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
else { return; };
// Try to find predicates on *generic params* that would allow copying `ty`
let infcx = tcx.infer_ctxt().build();
let copy_did = infcx.tcx.lang_items().copy_trait().unwrap();
let copy_did = infcx.tcx.require_lang_item(LangItem::Copy, Some(span));
let cause = ObligationCause::new(
span,
self.mir_hir_id(),
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_const_eval/src/transform/check_consts/ops.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Concrete error types for all operations which may be invalid in a certain const context.

use hir::def_id::LocalDefId;
use hir::ConstContext;
use hir::{ConstContext, LangItem};
use rustc_errors::{
error_code, struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed,
};
Expand Down Expand Up @@ -304,7 +304,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
err.span_note(deref_target, "deref defined here");
}

diag_trait(&mut err, self_ty, tcx.lang_items().deref_trait().unwrap());
diag_trait(&mut err, self_ty, tcx.require_lang_item(LangItem::Deref, Some(span)));
err
}
_ if tcx.opt_parent(callee) == tcx.get_diagnostic_item(sym::ArgumentV1Methods) => {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_const_eval/src/util/call_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! context.

use rustc_hir::def_id::DefId;
use rustc_hir::lang_items;
use rustc_hir::{lang_items, LangItem};
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::{self, AssocItemContainer, DefIdTree, Instance, ParamEnv, Ty, TyCtxt};
use rustc_span::symbol::Ident;
Expand All @@ -26,7 +26,7 @@ impl CallDesugaringKind {
match self {
Self::ForLoopIntoIter => tcx.get_diagnostic_item(sym::IntoIterator).unwrap(),
Self::QuestionBranch | Self::TryBlockFromOutput => {
tcx.lang_items().try_trait().unwrap()
tcx.require_lang_item(LangItem::Try, None)
}
Self::QuestionFromResidual => tcx.get_diagnostic_item(sym::FromResidual).unwrap(),
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/coherence/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
traits::ObligationCause::dummy_with_span(field_ty_span),
param_env,
ty,
tcx.lang_items().copy_trait().unwrap(),
tcx.require_lang_item(LangItem::Copy, Some(span)),
) {
let error_predicate = error.obligation.predicate;
// Only note if it's not the root obligation, otherwise it's trivial and
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let lhs_deref_ty_is_sized = self
.infcx
.type_implements_trait(
self.tcx.lang_items().sized_trait().unwrap(),
self.tcx.require_lang_item(LangItem::Sized, None),
[lhs_deref_ty],
self.param_env,
)
Expand Down
14 changes: 9 additions & 5 deletions compiler/rustc_middle/src/ty/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{mir, ty};

use std::fmt::Write;

use hir::LangItem;
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId};
Expand Down Expand Up @@ -130,11 +131,14 @@ impl<'tcx> ClosureKind {
}

pub fn to_def_id(&self, tcx: TyCtxt<'_>) -> DefId {
match self {
ClosureKind::Fn => tcx.lang_items().fn_once_trait().unwrap(),
ClosureKind::FnMut => tcx.lang_items().fn_mut_trait().unwrap(),
ClosureKind::FnOnce => tcx.lang_items().fn_trait().unwrap(),
}
tcx.require_lang_item(
match self {
ClosureKind::Fn => LangItem::Fn,
ClosureKind::FnMut => LangItem::FnMut,
ClosureKind::FnOnce => LangItem::FnOnce,
},
None,
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2293,7 +2293,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// Given a `ty`, return whether it's an `impl Future<...>`.
pub fn ty_is_opaque_future(self, ty: Ty<'_>) -> bool {
let ty::Opaque(def_id, _) = ty.kind() else { return false };
let future_trait = self.lang_items().future_trait().unwrap();
let future_trait = self.require_lang_item(LangItem::Future, None);

self.explicit_item_bounds(def_id).iter().any(|(predicate, _)| {
let ty::PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder() else {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use rustc_hir as hir;
use rustc_hir::def::{self, CtorKind, DefKind, Namespace};
use rustc_hir::def_id::{DefId, DefIdSet, CRATE_DEF_ID, LOCAL_CRATE};
use rustc_hir::definitions::{DefPathData, DefPathDataName, DisambiguatedDefPathData};
use rustc_hir::LangItem;
use rustc_session::config::TrimmedDefPaths;
use rustc_session::cstore::{ExternCrate, ExternCrateSource};
use rustc_session::Limit;
Expand Down Expand Up @@ -889,7 +890,7 @@ pub trait PrettyPrinter<'tcx>:
// Group the return ty with its def id, if we had one.
entry
.return_ty
.map(|ty| (tcx.lang_items().fn_once_output().unwrap(), ty)),
.map(|ty| (tcx.require_lang_item(LangItem::FnOnce, None), ty)),
);
}
if let Some(trait_ref) = entry.fn_mut_trait_ref {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use rustc_data_structures::captures::Captures;
use rustc_data_structures::intern::Interned;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::LangItem;
use rustc_index::vec::Idx;
use rustc_macros::HashStable;
use rustc_span::symbol::{kw, sym, Symbol};
Expand Down Expand Up @@ -2108,7 +2109,7 @@ impl<'tcx> Ty<'tcx> {

ty::Str | ty::Slice(_) => (tcx.types.usize, false),
ty::Dynamic(..) => {
let dyn_metadata = tcx.lang_items().dyn_metadata().unwrap();
let dyn_metadata = tcx.require_lang_item(LangItem::DynMetadata, None);
(tcx.bound_type_of(dyn_metadata).subst(tcx, &[tail.into()]), false)
},

Expand Down
32 changes: 32 additions & 0 deletions compiler/rustc_target/src/spec/aix_base.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use crate::abi::Endian;
use crate::spec::{crt_objects, cvs, Cc, CodeModel, LinkOutputKind, LinkerFlavor, TargetOptions};

pub fn opts() -> TargetOptions {
TargetOptions {
abi: "vec-extabi".into(),
code_model: Some(CodeModel::Small),
cpu: "pwr7".into(),
os: "aix".into(),
vendor: "ibm".into(),
dynamic_linking: true,
endian: Endian::Big,
executables: true,
archive_format: "aix_big".into(),
families: cvs!["unix"],
has_rpath: false,
has_thread_local: true,
crt_static_respected: true,
linker_flavor: LinkerFlavor::Unix(Cc::No),
linker: Some("ld".into()),
eh_frame_header: false,
is_like_aix: true,
default_dwarf_version: 3,
function_sections: true,
pre_link_objects: crt_objects::new(&[
(LinkOutputKind::DynamicNoPicExe, &["/usr/lib/crt0_64.o", "/usr/lib/crti_64.o"]),
(LinkOutputKind::DynamicPicExe, &["/usr/lib/crt0_64.o", "/usr/lib/crti_64.o"]),
]),
dll_suffix: ".a".into(),
..Default::default()
}
}
8 changes: 8 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ use rustc_macros::HashStable_Generic;
pub mod abi;
pub mod crt_objects;

mod aix_base;
mod android_base;
mod apple_base;
mod avr_gnu_base;
Expand Down Expand Up @@ -1027,6 +1028,7 @@ supported_targets! {
("powerpc-unknown-linux-gnu", powerpc_unknown_linux_gnu),
("powerpc-unknown-linux-gnuspe", powerpc_unknown_linux_gnuspe),
("powerpc-unknown-linux-musl", powerpc_unknown_linux_musl),
("powerpc64-ibm-aix", powerpc64_ibm_aix),
("powerpc64-unknown-linux-gnu", powerpc64_unknown_linux_gnu),
("powerpc64-unknown-linux-musl", powerpc64_unknown_linux_musl),
("powerpc64le-unknown-linux-gnu", powerpc64le_unknown_linux_gnu),
Expand Down Expand Up @@ -1454,6 +1456,9 @@ pub struct TargetOptions {
pub families: StaticCow<[StaticCow<str>]>,
/// Whether the target toolchain's ABI supports returning small structs as an integer.
pub abi_return_struct_as_int: bool,
/// Whether the target toolchain is like AIX's. Linker options on AIX are special and it uses
/// XCOFF as binary format. Defaults to false.
pub is_like_aix: bool,
/// Whether the target toolchain is like macOS's. Only useful for compiling against iOS/macOS,
/// in particular running dsymutil and some other stuff like `-dead_strip`. Defaults to false.
/// Also indiates whether to use Apple-specific ABI changes, such as extending function
Expand Down Expand Up @@ -1817,6 +1822,7 @@ impl Default for TargetOptions {
staticlib_suffix: ".a".into(),
families: cvs![],
abi_return_struct_as_int: false,
is_like_aix: false,
is_like_osx: false,
is_like_solaris: false,
is_like_windows: false,
Expand Down Expand Up @@ -2488,6 +2494,7 @@ impl Target {
key!(staticlib_suffix);
key!(families, TargetFamilies);
key!(abi_return_struct_as_int, bool);
key!(is_like_aix, bool);
key!(is_like_osx, bool);
key!(is_like_solaris, bool);
key!(is_like_windows, bool);
Expand Down Expand Up @@ -2741,6 +2748,7 @@ impl ToJson for Target {
target_option_val!(staticlib_suffix);
target_option_val!(families, "target-family");
target_option_val!(abi_return_struct_as_int);
target_option_val!(is_like_aix);
target_option_val!(is_like_osx);
target_option_val!(is_like_solaris);
target_option_val!(is_like_windows);
Expand Down
23 changes: 23 additions & 0 deletions compiler/rustc_target/src/spec/powerpc64_ibm_aix.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use crate::spec::{Cc, LinkerFlavor, Target};

pub fn target() -> Target {
let mut base = super::aix_base::opts();
base.max_atomic_width = Some(64);
base.add_pre_link_args(
LinkerFlavor::Unix(Cc::No),
&[
"-b64".into(),
"-bpT:0x100000000".into(),
"-bpD:0x110000000".into(),
"-bcdtors:all:0:s".into(),
],
);

Target {
llvm_target: "powerpc64-ibm-aix".into(),
pointer_width: 64,
data_layout: "E-m:a-i64:64-n32:64-S128-v256:256:256-v512:512:512".into(),
arch: "powerpc64".into(),
options: base,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2625,7 +2625,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
}
};

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

// Don't print the tuple of capture types
'print: {
Expand Down
25 changes: 16 additions & 9 deletions library/std/src/thread/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ macro_rules! thread_local {
macro_rules! __thread_local_inner {
// used to generate the `LocalKey` value for const-initialized thread locals
(@key $t:ty, const $init:expr) => {{
#[cfg_attr(not(windows), inline)] // see comments below
#[cfg_attr(not(all(windows, target_thread_local)), inline)] // see comments below
#[cfg_attr(all(windows, target_thread_local), inline(never))]
#[deny(unsafe_op_in_unsafe_fn)]
unsafe fn __getit(
_init: $crate::option::Option<&mut $crate::option::Option<$t>>,
Expand Down Expand Up @@ -294,12 +295,17 @@ macro_rules! __thread_local_inner {
fn __init() -> $t { $init }

// When reading this function you might ask "why is this inlined
// everywhere other than Windows?", and that's a very reasonable
// question to ask. The short story is that it segfaults rustc if
// this function is inlined. The longer story is that Windows looks
// to not support `extern` references to thread locals across DLL
// boundaries. This appears to at least not be supported in the ABI
// that LLVM implements.
// everywhere other than Windows?", and "why must it not be inlined
// on Windows?" and these are very reasonable questions to ask.
//
// The short story is that Windows doesn't support referencing
// `#[thread_local]` across DLL boundaries. The slightly longer
// story is that each module (dll or exe) has its own separate set
// of static thread locals, so if you try and reference a
// `#[thread_local]` that comes from `crate1.dll` from within one of
// `crate2.dll`'s functions, then it might give you a completely
// different thread local than what you asked for (or it might just
// crash).
//
// Because of this we never inline on Windows, but we do inline on
// other platforms (where external references to thread locals
Expand All @@ -314,8 +320,9 @@ macro_rules! __thread_local_inner {
// Cargo question kinda). This means that, unfortunately, Windows
// gets the pessimistic path for now where it's never inlined.
//
// The issue of "should enable on Windows sometimes" is #84933
#[cfg_attr(not(windows), inline)]
// The issue of "should improve things on Windows" is #84933
#[cfg_attr(not(all(windows, target_thread_local)), inline)]
#[cfg_attr(all(windows, target_thread_local), inline(never))]
unsafe fn __getit(
init: $crate::option::Option<&mut $crate::option::Option<$t>>,
) -> $crate::option::Option<&'static $t> {
Expand Down
1 change: 1 addition & 0 deletions src/doc/rustc/src/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ target | std | host | notes
`powerpc64-wrs-vxworks` | ? | |
`powerpc64le-unknown-linux-musl` | ? | |
[`powerpc64-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | OpenBSD/powerpc64
`powerpc64-ibm-aix` | ? | | 64-bit AIX (7.2 and newer)
`riscv32gc-unknown-linux-gnu` | | | RISC-V Linux (kernel 5.4, glibc 2.33)
`riscv32gc-unknown-linux-musl` | | | RISC-V Linux (kernel 5.4, musl + RISCV32 support patches)
`riscv32im-unknown-none-elf` | * | | Bare RISC-V (RV32IM ISA)
Expand Down
2 changes: 0 additions & 2 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,6 @@ so that we can apply CSS-filters to change the arrow color in themes */
right: var(--popover-arrow-offset);
border: solid var(--border-color);
border-width: 1px 1px 0 0;
display: inline-block;
padding: 4px;
transform: rotate(-45deg);
top: -5px;
Expand Down Expand Up @@ -1200,7 +1199,6 @@ pre.rust .doccomment {
}

a.test-arrow {
display: inline-block;
visibility: hidden;
position: absolute;
padding: 5px 10px 5px 10px;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/check-cfg/well-known-values.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | #[cfg(target_os = "linuz")]
| |
| help: did you mean: `"linux"`
|
= 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
= 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
= note: `#[warn(unexpected_cfgs)]` on by default

warning: unexpected `cfg` condition value
Expand Down
20 changes: 20 additions & 0 deletions src/test/ui/const-generics/projection-as-arg-const.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This is currently not possible to use projections as const generics.
// More information about this available here:
// https://github.com/rust-lang/rust/pull/104443#discussion_r1029375633

pub trait Identity {
type Identity;
}

impl<T> Identity for T {
type Identity = Self;
}

pub fn foo<const X: <i32 as Identity>::Identity>() {
//~^ ERROR
assert!(X == 12);
}

fn main() {
foo::<12>();
}
11 changes: 11 additions & 0 deletions src/test/ui/const-generics/projection-as-arg-const.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: `<i32 as Identity>::Identity` is forbidden as the type of a const generic parameter
--> $DIR/projection-as-arg-const.rs:13:21
|
LL | pub fn foo<const X: <i32 as Identity>::Identity>() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the only supported types are integers, `bool` and `char`
= help: more complex types are supported with `#![feature(adt_const_params)]`

error: aborting due to previous error

19 changes: 14 additions & 5 deletions src/test/ui/mismatched_types/overloaded-calls-bad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,23 @@ impl FnOnce<(isize,)> for S {
}
}

struct F;

impl FnOnce<(i32,)> for F {
type Output = ();

extern "rust-call" fn call_once(self, args: (i32,)) -> Self::Output {}
}

fn main() {
let mut s = S {
x: 3,
y: 3,
};
let ans = s("what"); //~ ERROR mismatched types
let mut s = S { x: 3, y: 3 };
let ans = s("what");
//~^ ERROR mismatched types
let ans = s();
//~^ ERROR this function takes 1 argument but 0 arguments were supplied
let ans = s("burma", "shave");
//~^ ERROR this function takes 1 argument but 2 arguments were supplied

F("");
//~^ ERROR mismatched types
}
Loading