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 8 pull requests #93452

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5e97fc9
Make `NonNull::new` `const`
lilasta Jan 23, 2022
1ab97db
add note suggesting that predicate is satisfied but is not const
compiler-errors Jan 27, 2022
c6de4d5
drive-by: use is_const and is_const_if_const
compiler-errors Jan 27, 2022
c6f6e3e
do not register infer var for GAT projection in opaque
compiler-errors Jan 27, 2022
da0d506
kmc-solid: Implement `FileDesc::duplicate`
kawadakk Jan 28, 2022
cdd0873
Add a test case for using NonNull::new in const context
lilasta Jan 28, 2022
2188c55
Move unstable is_{arch}_feature_detected! macros to std::arch
Amanieu Jan 28, 2022
9a814b8
Update stdarch submodule
Amanieu Jan 28, 2022
9d65342
fix nit
lcnr Jan 28, 2022
f9e0eb3
remove unused `jemallocator` crate
lqd Jan 28, 2022
5b2747a
Add test for old ICE
BGR360 Dec 27, 2021
2819d90
Add test for old ICE in #91594
BGR360 Dec 27, 2021
3f849a8
Add test for old ICE in #89066
BGR360 Dec 27, 2021
2b684a3
Rollup merge of #92312 - BGR360:needs-test, r=Mark-Simulacrum
matthiaskrgr Jan 29, 2022
cb97b8a
Rollup merge of #93236 - woppopo:const_nonnull_new, r=oli-obk
matthiaskrgr Jan 29, 2022
8e9fecf
Rollup merge of #93358 - compiler-errors:is-not-const, r=fee1-dead
matthiaskrgr Jan 29, 2022
7fa7e02
Rollup merge of #93362 - compiler-errors:ice-gat-in-rpit, r=oli-obk
matthiaskrgr Jan 29, 2022
be7249a
Rollup merge of #93410 - solid-rs:feat-kmc-solid-net-dup, r=dtolnay
matthiaskrgr Jan 29, 2022
45f9ac8
Rollup merge of #93414 - Amanieu:std_arch_detect, r=m-ou-se
matthiaskrgr Jan 29, 2022
0aac06f
Rollup merge of #93424 - lcnr:nit, r=spastorino
matthiaskrgr Jan 29, 2022
49cae39
Rollup merge of #93431 - lqd:remove-jemallocator, r=Mark-Simulacrum
matthiaskrgr Jan 29, 2022
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
11 changes: 0 additions & 11 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3319,7 +3319,6 @@ dependencies = [
"rustc_codegen_ssa",
"rustc_driver",
"tikv-jemalloc-sys",
"tikv-jemallocator",
]

[[package]]
Expand Down Expand Up @@ -5164,16 +5163,6 @@ dependencies = [
"libc",
]

[[package]]
name = "tikv-jemallocator"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c14a5a604eb8715bc5785018a37d00739b180bcf609916ddf4393d33d49ccdf"
dependencies = [
"libc",
"tikv-jemalloc-sys",
]

[[package]]
name = "time"
version = "0.1.43"
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ version = '0.4.0'
optional = true
features = ['unprefixed_malloc_on_supported_platforms']

[dependencies.tikv-jemallocator]
version = '0.4.0'
optional = true

[features]
jemalloc = ['tikv-jemalloc-sys', 'tikv-jemallocator']
jemalloc = ['tikv-jemalloc-sys']
llvm = ['rustc_driver/llvm']
max_level_info = ['rustc_driver/max_level_info']
5 changes: 2 additions & 3 deletions compiler/rustc_const_eval/src/const_eval/eval_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::interpret::{
};

use rustc_errors::ErrorReported;
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_middle::mir;
use rustc_middle::mir::interpret::ErrorHandled;
Expand Down Expand Up @@ -216,7 +215,7 @@ pub fn eval_to_const_value_raw_provider<'tcx>(
tcx: TyCtxt<'tcx>,
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
) -> ::rustc_middle::mir::interpret::EvalToConstValueResult<'tcx> {
assert!(key.param_env.constness() == hir::Constness::Const);
assert!(key.param_env.is_const());
// see comment in eval_to_allocation_raw_provider for what we're doing here
if key.param_env.reveal() == Reveal::All {
let mut key = key;
Expand Down Expand Up @@ -251,7 +250,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
tcx: TyCtxt<'tcx>,
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
) -> ::rustc_middle::mir::interpret::EvalToAllocationRawResult<'tcx> {
assert!(key.param_env.constness() == hir::Constness::Const);
assert!(key.param_env.is_const());
// Because the constant is computed twice (once per value of `Reveal`), we are at risk of
// reporting the same error twice here. To resolve this, we check whether we can evaluate the
// constant in the more restrictive `Reveal::UserFacing`, which most likely already was
Expand Down
16 changes: 9 additions & 7 deletions compiler/rustc_infer/src/infer/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,13 +569,15 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
let predicate = predicate.fold_with(&mut BottomUpFolder {
tcx,
ty_op: |ty| match ty.kind() {
ty::Projection(projection_ty) => infcx.infer_projection(
self.param_env,
*projection_ty,
traits::ObligationCause::misc(self.value_span, self.body_id),
0,
&mut self.obligations,
),
ty::Projection(projection_ty) if !projection_ty.has_escaping_bound_vars() => {
infcx.infer_projection(
self.param_env,
*projection_ty,
traits::ObligationCause::misc(self.value_span, self.body_id),
0,
&mut self.obligations,
)
}
_ => ty,
},
lt_op: |lt| lt,
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_lint/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,14 @@ declare_lint_pass!(

impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
use rustc_middle::ty;
use rustc_middle::ty::PredicateKind::*;

let predicates = cx.tcx.explicit_predicates_of(item.def_id);
for &(predicate, span) in predicates.predicates {
let Trait(trait_predicate) = predicate.kind().skip_binder() else {
continue
};
if trait_predicate.constness == ty::BoundConstness::ConstIfConst {
if trait_predicate.is_const_if_const() {
// `~const Drop` definitely have meanings so avoid linting here.
continue;
}
Expand Down
16 changes: 16 additions & 0 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,11 @@ impl<'tcx> TraitPredicate<'tcx> {
pub fn self_ty(self) -> Ty<'tcx> {
self.trait_ref.self_ty()
}

#[inline]
pub fn is_const_if_const(self) -> bool {
self.constness == BoundConstness::ConstIfConst
}
}

impl<'tcx> PolyTraitPredicate<'tcx> {
Expand All @@ -803,6 +808,11 @@ impl<'tcx> PolyTraitPredicate<'tcx> {
p
});
}

#[inline]
pub fn is_const_if_const(self) -> bool {
self.skip_binder().is_const_if_const()
}
}

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]
Expand Down Expand Up @@ -1388,6 +1398,11 @@ impl<'tcx> ParamEnv<'tcx> {
self.packed.tag().constness
}

#[inline]
pub fn is_const(self) -> bool {
self.packed.tag().constness == hir::Constness::Const
}

/// Construct a trait environment with no where-clauses in scope
/// where the values of all `impl Trait` and other hidden types
/// are revealed. This is suitable for monomorphized, post-typeck
Expand Down Expand Up @@ -1503,6 +1518,7 @@ impl<'tcx> PolyTraitRef<'tcx> {
polarity: ty::ImplPolarity::Positive,
})
}

#[inline]
pub fn without_const(self) -> PolyTraitPredicate<'tcx> {
self.with_constness(BoundConstness::NotConst)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1810,7 +1810,7 @@ impl<'tcx> TyS<'tcx> {
pub fn sequence_element_type(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
match self.kind() {
Array(ty, _) | Slice(ty) => ty,
Str => tcx.mk_mach_uint(ty::UintTy::U8),
Str => tcx.types.u8,
_ => bug!("`sequence_element_type` called on non-sequence value: {}", self),
}
}
Expand Down
22 changes: 22 additions & 0 deletions compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,28 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
} else {
err.span_label(span, explanation);
}

if trait_predicate.is_const_if_const() && obligation.param_env.is_const() {
let non_const_predicate = trait_ref.without_const();
let non_const_obligation = Obligation {
cause: obligation.cause.clone(),
param_env: obligation.param_env.without_const(),
predicate: non_const_predicate.to_predicate(tcx),
recursion_depth: obligation.recursion_depth,
};
if self.predicate_may_hold(&non_const_obligation) {
err.span_note(
span,
&format!(
"the trait `{}` is implemented for `{}`, \
but that implementation is not `const`",
non_const_predicate.print_modifiers_and_trait_path(),
trait_ref.skip_binder().self_ty(),
),
);
}
}

if let Some((msg, span)) = type_def {
err.span_label(span, &msg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
} else if lang_items.unsize_trait() == Some(def_id) {
self.assemble_candidates_for_unsizing(obligation, &mut candidates);
} else if lang_items.drop_trait() == Some(def_id)
&& obligation.predicate.skip_binder().constness == ty::BoundConstness::ConstIfConst
&& obligation.predicate.is_const_if_const()
{
self.assemble_const_drop_candidates(obligation, &mut candidates);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// CheckPredicate(&A: Super)
// CheckPredicate(A: ~const Super) // <- still const env, failure
// ```
if obligation.param_env.constness() == Constness::Const
&& obligation.predicate.skip_binder().constness == ty::BoundConstness::NotConst
{
if obligation.param_env.is_const() && !obligation.predicate.is_const_if_const() {
new_obligation = TraitObligation {
cause: obligation.cause.clone(),
param_env: obligation.param_env.without_const(),
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1173,9 +1173,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ImplCandidate(def_id)
if tcx.impl_constness(def_id) == hir::Constness::Const => {}
// const param
ParamCandidate(trait_pred)
if trait_pred.skip_binder().constness
== ty::BoundConstness::ConstIfConst => {}
ParamCandidate(trait_pred) if trait_pred.is_const_if_const() => {}
// auto trait impl
AutoImplCandidate(..) => {}
// generator, this will raise error in other places
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/ptr/non_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,9 @@ impl<T: ?Sized> NonNull<T> {
/// }
/// ```
#[stable(feature = "nonnull", since = "1.25.0")]
#[rustc_const_unstable(feature = "const_nonnull_new", issue = "93235")]
#[inline]
pub fn new(ptr: *mut T) -> Option<Self> {
pub const fn new(ptr: *mut T) -> Option<Self> {
if !ptr.is_null() {
// SAFETY: The pointer is already checked and is not null
Some(unsafe { Self::new_unchecked(ptr) })
Expand Down
2 changes: 2 additions & 0 deletions library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
#![feature(const_maybe_uninit_as_mut_ptr)]
#![feature(const_maybe_uninit_assume_init)]
#![feature(const_maybe_uninit_assume_init_read)]
#![feature(const_nonnull_new)]
#![feature(const_num_from_num)]
#![feature(const_ptr_as_ref)]
#![feature(const_ptr_read)]
#![feature(const_ptr_write)]
#![feature(const_ptr_offset)]
Expand Down
15 changes: 15 additions & 0 deletions library/core/tests/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,21 @@ fn test_unsized_nonnull() {
assert!(ys == zs);
}

#[test]
fn test_const_nonnull_new() {
const {
assert!(NonNull::new(core::ptr::null_mut::<()>()).is_none());

let value = &mut 0u32;
let mut ptr = NonNull::new(value).unwrap();
unsafe { *ptr.as_mut() = 42 };

let reference = unsafe { &*ptr.as_ref() };
assert!(*reference == *value);
assert!(*reference == 42);
};
}

#[test]
#[allow(warnings)]
// Have a symbol for the test below. It doesn’t need to be an actual variadic function, match the
Expand Down
44 changes: 25 additions & 19 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,6 @@ pub use alloc_crate::string;
pub use alloc_crate::vec;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::any;
#[stable(feature = "simd_arch", since = "1.27.0")]
// The `no_inline`-attribute is required to make the documentation of all
// targets available.
// See https://github.com/rust-lang/rust/pull/57808#issuecomment-457390549 for
// more information.
#[doc(no_inline)] // Note (#82861): required for correct documentation
pub use core::arch;
#[stable(feature = "core_array", since = "1.36.0")]
pub use core::array;
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -527,6 +520,31 @@ pub mod task {
pub use alloc::task::*;
}

#[doc = include_str!("../../stdarch/crates/core_arch/src/core_arch_docs.md")]
#[stable(feature = "simd_arch", since = "1.27.0")]
pub mod arch {
#[stable(feature = "simd_arch", since = "1.27.0")]
// The `no_inline`-attribute is required to make the documentation of all
// targets available.
// See https://github.com/rust-lang/rust/pull/57808#issuecomment-457390549 for
// more information.
#[doc(no_inline)] // Note (#82861): required for correct documentation
pub use core::arch::*;

#[stable(feature = "simd_x86", since = "1.27.0")]
pub use std_detect::is_x86_feature_detected;
#[unstable(feature = "stdsimd", issue = "48556")]
pub use std_detect::{
is_aarch64_feature_detected, is_arm_feature_detected, is_mips64_feature_detected,
is_mips_feature_detected, is_powerpc64_feature_detected, is_powerpc_feature_detected,
is_riscv_feature_detected,
};
}

// This was stabilized in the crate root so we have to keep it there.
#[stable(feature = "simd_x86", since = "1.27.0")]
pub use std_detect::is_x86_feature_detected;

// The runtime entry point and a few unstable public functions used by the
// compiler
#[macro_use]
Expand All @@ -545,18 +563,6 @@ mod panicking;
#[allow(dead_code, unused_attributes)]
mod backtrace_rs;

#[stable(feature = "simd_x86", since = "1.27.0")]
pub use std_detect::is_x86_feature_detected;
#[doc(hidden)]
#[unstable(feature = "stdsimd", issue = "48556")]
pub use std_detect::*;
#[unstable(feature = "stdsimd", issue = "48556")]
pub use std_detect::{
is_aarch64_feature_detected, is_arm_feature_detected, is_mips64_feature_detected,
is_mips_feature_detected, is_powerpc64_feature_detected, is_powerpc_feature_detected,
is_riscv_feature_detected,
};

// Re-export macros defined in libcore.
#[stable(feature = "rust1", since = "1.0.0")]
#[allow(deprecated, deprecated_in_future)]
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/sys/solid/abi/sockets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ extern "C" {
#[link_name = "SOLID_NET_Close"]
pub fn close(s: c_int) -> c_int;

#[link_name = "SOLID_NET_Dup"]
pub fn dup(s: c_int) -> c_int;

#[link_name = "SOLID_NET_GetPeerName"]
pub fn getpeername(s: c_int, name: *mut sockaddr, namelen: *mut socklen_t) -> c_int;

Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/solid/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl FileDesc {
}

fn duplicate(&self) -> io::Result<FileDesc> {
super::unsupported()
cvt(unsafe { netc::dup(self.fd) }).map(Self::new)
}
}

Expand Down
6 changes: 6 additions & 0 deletions library/std/tests/run-time-detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#[test]
#[cfg(all(target_arch = "arm", any(target_os = "linux", target_os = "android")))]
fn arm_linux() {
use std::arch::is_arm_feature_detected;
println!("neon: {}", is_arm_feature_detected!("neon"));
println!("pmull: {}", is_arm_feature_detected!("pmull"));
println!("crypto: {}", is_arm_feature_detected!("crypto"));
Expand All @@ -25,6 +26,7 @@ fn arm_linux() {
#[test]
#[cfg(all(target_arch = "aarch64", any(target_os = "linux", target_os = "android")))]
fn aarch64_linux() {
use std::arch::is_aarch64_feature_detected;
println!("neon: {}", is_aarch64_feature_detected!("neon"));
println!("asimd: {}", is_aarch64_feature_detected!("asimd"));
println!("pmull: {}", is_aarch64_feature_detected!("pmull"));
Expand Down Expand Up @@ -71,6 +73,7 @@ fn aarch64_linux() {
#[test]
#[cfg(all(target_arch = "powerpc", target_os = "linux"))]
fn powerpc_linux() {
use std::arch::is_powerpc_feature_detected;
println!("altivec: {}", is_powerpc_feature_detected!("altivec"));
println!("vsx: {}", is_powerpc_feature_detected!("vsx"));
println!("power8: {}", is_powerpc_feature_detected!("power8"));
Expand All @@ -79,6 +82,7 @@ fn powerpc_linux() {
#[test]
#[cfg(all(target_arch = "powerpc64", target_os = "linux"))]
fn powerpc64_linux() {
use std::arch::is_powerpc64_feature_detected;
println!("altivec: {}", is_powerpc64_feature_detected!("altivec"));
println!("vsx: {}", is_powerpc64_feature_detected!("vsx"));
println!("power8: {}", is_powerpc64_feature_detected!("power8"));
Expand All @@ -87,6 +91,8 @@ fn powerpc64_linux() {
#[test]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn x86_all() {
use std::arch::is_x86_feature_detected;

// the below is the set of features we can test at runtime, but don't actually
// use to gate anything and are thus not part of the X86_ALLOWED_FEATURES list

Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/closures/issue-84044-drop-non-mut.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// #84044: This used to ICE.

fn main() {
let f = || {};
drop(&mut f); //~ ERROR cannot borrow `f` as mutable, as it is not declared as mutable
}
Loading