Skip to content
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
1,462 changes: 725 additions & 737 deletions compiler/rustc_builtin_macros/src/autodiff.rs

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion compiler/rustc_mir_build/src/builder/expr/as_constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,13 @@ fn lit_to_mir_constant<'tcx>(tcx: TyCtxt<'tcx>, lit_input: LitToConstInput<'tcx>
(ast::LitKind::Byte(n), ty::Uint(ty::UintTy::U8)) => {
ConstValue::Scalar(Scalar::from_uint(n, Size::from_bytes(1)))
}
(ast::LitKind::Int(n, _), ty::Uint(_)) if !neg => trunc(n.get()),
// Only reachable through a user `impl Neg` for an unsigned type, which violates the
// orphan rules and has already been reported.
(ast::LitKind::Int(..), ty::Uint(_)) if neg => {
let guar = tcx.dcx().delayed_bug("negated unsigned literal without a prior error");
return Const::Ty(Ty::new_error(tcx, guar), ty::Const::new_error(tcx, guar));
}
(ast::LitKind::Int(n, _), ty::Uint(_)) => trunc(n.get()),
(ast::LitKind::Int(n, _), ty::Int(_)) => {
// Unsigned "negation" has the same bitwise effect as signed negation,
// which gets the result we want without additional casts.
Expand Down
24 changes: 13 additions & 11 deletions compiler/rustc_symbol_mangling/src/v0.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::fmt::Write;
use std::hash::Hasher;
use std::iter;
use std::ops::Range;

Expand All @@ -8,7 +7,6 @@ use rustc_data_structures::base_n::ToBaseN;
use rustc_data_structures::either::Either;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::intern::Interned;
use rustc_data_structures::stable_hash::StableHasher;
use rustc_hashes::Hash64;
use rustc_hir as hir;
use rustc_hir::def::CtorKind;
Expand Down Expand Up @@ -172,15 +170,19 @@ pub fn mangle_internal_symbol<'tcx>(tcx: TyCtxt<'tcx>, item_name: &str) -> Strin
|p| {
p.push("C");
p.push_disambiguator_fixed_len({
let mut hasher = StableHasher::new();
// Incorporate the rustc version to ensure #[rustc_std_internal_symbol] functions
// get a different symbol name depending on the rustc version.
//
// RUSTC_FORCE_RUSTC_VERSION is ignored here as otherwise different we would get an
// abi incompatibility with the standard library.
hasher.write(tcx.sess.cfg_version.as_bytes());

hasher.finish()
let core = tcx
.lang_items()
.sized_trait()
// The Sized trait is guaranteed to exist at this point. If you try to define
// any function or static without defining the Sized trait you will get an error
// during type checking.
.expect("#[rustc_std_internal_symbol] requires the Sized trait to be defined")
.krate;

// Use the same disambiguator as 'core' to ensure #[rustc_std_internal_symbol]
// functions get a different symbol name depending on the rustc version and
// -Cmetadata flags.
tcx.stable_crate_id(core).as_hash()
});
p.push_ident("__rustc");
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ dependencies = [
"clap",
"clap_complete",
"cmake",
"errno",
"expect-test",
"home",
"ignore",
"junction",
"libc",
"object",
"opener",
"rustix",
"semver",
"serde",
"serde_derive",
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ features = [

# src/utils/job.rs
[target.'cfg(all(unix, not(any(target_os = "haiku", target_os = "hermit"))))'.dependencies]
errno = "0.3.14"
rustix = { version = "1.1.4", default-features = false, features = ["std", "process"] }

[dev-dependencies]
expect-test = "1"
Expand Down
37 changes: 6 additions & 31 deletions src/bootstrap/src/utils/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,14 @@ pub(crate) fn setup(_sess: &Session) {}

#[cfg(all(unix, not(any(target_os = "haiku", target_os = "hermit"))))]
mod for_unix {
use std::ffi::c_int;
use std::io;

use libc::id_t;

fn get_priority(which: c_int, who: id_t) -> io::Result<c_int> {
// Genius design: `getpriority` can return -1 on success if the nice value is literally -1.
// Per `getpriority`'s docs, clear `errno` beforehand and check it afterward regardless of
// return value.
errno::set_errno(errno::Errno(0));
// SAFETY: empty safety contract
let nice = unsafe { libc::getpriority(which as _, who) };
let new_errno = errno::errno().0;
if new_errno == 0 { Ok(nice) } else { Err(io::Error::from_raw_os_error(new_errno)) }
}
fn set_priority(which: c_int, who: id_t, prio: c_int) -> io::Result<()> {
// SAFETY: empty safety contract
if unsafe { libc::setpriority(which as _, who, prio) != -1 } {
Ok(())
} else {
Err(io::Error::last_os_error())
}
}
use rustix::process::{getpriority_process, setpriority_process};

pub(crate) fn setup(sess: &super::Session) {
const TARGET_NICE: c_int = 10;
// The processes that spawn the build are all descendants of the
// current thread.
let (which, who) = (libc::PRIO_PROCESS as _, 0);
// Unwrap both of those to alert users to ridiculous Seccomp-BPF setups messing up their
// performance.
if sess.config.low_priority && get_priority(which, who).unwrap() < TARGET_NICE {
set_priority(which, who, TARGET_NICE).unwrap();
const TARGET_NICE: libc::c_int = 10;
// The processes that spawn the build are all descendants of the current thread. Unwrap both
// of those to alert users to ridiculous Seccomp-BPF setups messing up their performance.
if sess.config.low_priority && getpriority_process(None).unwrap() < TARGET_NICE {
setpriority_process(None, TARGET_NICE).unwrap();
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/coherence/orphan-neg-impl-negated-unsigned-literal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Regression test for <https://github.com/rust-lang/rust/issues/165689>.
// An orphan `impl Neg for u8` let `-1: u8` reach MIR building, which ICEd on the negated literal.

impl std::ops::Neg for u8 {
//~^ ERROR only traits defined in the current crate can be implemented for primitive types
type Output = u8;
fn neg(self) -> Self::Output {
-1
}
}

fn main() {}
15 changes: 15 additions & 0 deletions tests/ui/coherence/orphan-neg-impl-negated-unsigned-literal.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0117]: only traits defined in the current crate can be implemented for primitive types
--> $DIR/orphan-neg-impl-negated-unsigned-literal.rs:4:1
|
LL | impl std::ops::Neg for u8 {
| ^^^^^^^^^^^^^^^^^^^^^^^--
| |
| `u8` is not defined in the current crate
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0117`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//@ compile-flags: -Znext-solver=globally

#![feature(type_alias_impl_trait)]
type Tait = impl Iterator<Item = impl Sized>;

#[define_opaque(Tait)]
fn a() {
let _: Tait = IntoIterator::into_iter([0i32; 0i32]); //~ ERROR mismatched types
}

#[define_opaque(Tait)]
fn b() {
let _: Tait = IntoIterator::into_iter([0i32; 42 /* <- */]);
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error[E0308]: mismatched types
--> $DIR/next-solver-non-defining-use-ice-152446.rs:8:50
|
LL | let _: Tait = IntoIterator::into_iter([0i32; 0i32]);
| ^^^^ expected `usize`, found `i32`
|
= note: array length can only be `usize`
help: change the type of the numeric literal from `i32` to `usize`
|
LL - let _: Tait = IntoIterator::into_iter([0i32; 0i32]);
LL + let _: Tait = IntoIterator::into_iter([0i32; 0usize]);
|

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.
Loading