From 5e97fc9aa265cb523a16cbe035c638eb35257cf5 Mon Sep 17 00:00:00 2001 From: woppopo Date: Sun, 23 Jan 2022 23:04:39 +0900 Subject: [PATCH 01/13] Make `NonNull::new` `const` --- library/core/src/ptr/non_null.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index 3a7e99faccf23..3f5d3f62c9604 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -211,8 +211,9 @@ impl NonNull { /// } /// ``` #[stable(feature = "nonnull", since = "1.25.0")] + #[rustc_const_unstable(feature = "const_nonnull_new", issue = "93235")] #[inline] - pub fn new(ptr: *mut T) -> Option { + pub const fn new(ptr: *mut T) -> Option { if !ptr.is_null() { // SAFETY: The pointer is already checked and is not null Some(unsafe { Self::new_unchecked(ptr) }) From 1ab97dbc52b76fa5b4bc01a110f366d81560b81d Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 26 Jan 2022 19:09:44 -0800 Subject: [PATCH 02/13] add note suggesting that predicate is satisfied but is not const --- compiler/rustc_middle/src/ty/mod.rs | 9 ++++++++ .../src/traits/error_reporting/mod.rs | 22 +++++++++++++++++++ .../intrinsics/const-eval-select-bad.stderr | 5 +++++ .../assoc-type.stderr | 5 +++++ .../call-generic-method-nonconst.stderr | 5 +++++ .../const-drop-fail.precise.stderr | 5 +++++ .../const-drop-fail.stock.stderr | 5 +++++ ...-method-body-is-const-body-checking.stderr | 5 +++++ .../trait-where-clause.stderr | 10 +++++++++ 9 files changed, 71 insertions(+) diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 6174c922e2d06..2d8ee549f48dd 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -803,6 +803,10 @@ impl<'tcx> PolyTraitPredicate<'tcx> { p }); } + + pub fn is_const(self) -> bool { + self.skip_binder().constness == BoundConstness::ConstIfConst + } } #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] @@ -1388,6 +1392,10 @@ impl<'tcx> ParamEnv<'tcx> { self.packed.tag().constness } + 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 @@ -1503,6 +1511,7 @@ impl<'tcx> PolyTraitRef<'tcx> { polarity: ty::ImplPolarity::Positive, }) } + #[inline] pub fn without_const(self) -> PolyTraitPredicate<'tcx> { self.with_constness(BoundConstness::NotConst) diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 37cf41a0ec2e2..081f823f851c6 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -439,6 +439,28 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } else { err.span_label(span, explanation); } + + if trait_predicate.is_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); } diff --git a/src/test/ui/intrinsics/const-eval-select-bad.stderr b/src/test/ui/intrinsics/const-eval-select-bad.stderr index 083b00645388e..06a7a2f63cf5a 100644 --- a/src/test/ui/intrinsics/const-eval-select-bad.stderr +++ b/src/test/ui/intrinsics/const-eval-select-bad.stderr @@ -7,6 +7,11 @@ LL | const_eval_select((), || {}, || {}); | required by a bound introduced by this call | = help: the trait `~const FnOnce<()>` is not implemented for `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:32]` +note: the trait `FnOnce<()>` is implemented for `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:32]`, but that implementation is not `const` + --> $DIR/const-eval-select-bad.rs:6:27 + | +LL | const_eval_select((), || {}, || {}); + | ^^^^^ = note: wrap the `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:32]` in a closure with no arguments: `|| { /* code */ }` note: required by a bound in `const_eval_select` --> $SRC_DIR/core/src/intrinsics.rs:LL:COL diff --git a/src/test/ui/rfc-2632-const-trait-impl/assoc-type.stderr b/src/test/ui/rfc-2632-const-trait-impl/assoc-type.stderr index 429b9f3364be1..0788b17a1c032 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/assoc-type.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/assoc-type.stderr @@ -5,6 +5,11 @@ LL | type Bar = NonConstAdd; | ^^^^^^^^^^^ no implementation for `NonConstAdd + NonConstAdd` | = help: the trait `~const Add` is not implemented for `NonConstAdd` +note: the trait `Add` is implemented for `NonConstAdd`, but that implementation is not `const` + --> $DIR/assoc-type.rs:18:16 + | +LL | type Bar = NonConstAdd; + | ^^^^^^^^^^^ note: required by a bound in `Foo::Bar` --> $DIR/assoc-type.rs:14:15 | diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr index 13cffaba91a1d..35b7fe8e401c3 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr @@ -7,6 +7,11 @@ LL | pub const EQ: bool = equals_self(&S); | required by a bound introduced by this call | = help: the trait `~const PartialEq` is not implemented for `S` +note: the trait `PartialEq` is implemented for `S`, but that implementation is not `const` + --> $DIR/call-generic-method-nonconst.rs:19:34 + | +LL | pub const EQ: bool = equals_self(&S); + | ^^ note: required by a bound in `equals_self` --> $DIR/call-generic-method-nonconst.rs:12:25 | diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr index df776908a0365..d280cd2556f06 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr @@ -28,6 +28,11 @@ LL | const _: () = check($exp); LL | ConstImplWithDropGlue(NonTrivialDrop), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `ConstImplWithDropGlue`, the trait `~const Drop` is not implemented for `NonTrivialDrop` | +note: the trait `Drop` is implemented for `NonTrivialDrop`, but that implementation is not `const` + --> $DIR/const-drop-fail.rs:46:5 + | +LL | ConstImplWithDropGlue(NonTrivialDrop), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: required because it appears within the type `ConstImplWithDropGlue` --> $DIR/const-drop-fail.rs:17:8 | diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.stock.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.stock.stderr index df776908a0365..d280cd2556f06 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.stock.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.stock.stderr @@ -28,6 +28,11 @@ LL | const _: () = check($exp); LL | ConstImplWithDropGlue(NonTrivialDrop), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `ConstImplWithDropGlue`, the trait `~const Drop` is not implemented for `NonTrivialDrop` | +note: the trait `Drop` is implemented for `NonTrivialDrop`, but that implementation is not `const` + --> $DIR/const-drop-fail.rs:46:5 + | +LL | ConstImplWithDropGlue(NonTrivialDrop), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: required because it appears within the type `ConstImplWithDropGlue` --> $DIR/const-drop-fail.rs:17:8 | diff --git a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.stderr b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.stderr index 05a74757b94f1..bc807507fd668 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.stderr @@ -4,6 +4,11 @@ error[E0277]: the trait bound `(): ~const Tr` is not satisfied LL | foo::<()>(); | ^^ the trait `~const Tr` is not implemented for `()` | +note: the trait `Tr` is implemented for `()`, but that implementation is not `const` + --> $DIR/default-method-body-is-const-body-checking.rs:12:15 + | +LL | foo::<()>(); + | ^^ note: required by a bound in `foo` --> $DIR/default-method-body-is-const-body-checking.rs:7:28 | diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr index 903cd924ca55b..f9b5d81c63b85 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr @@ -4,6 +4,11 @@ error[E0277]: the trait bound `T: ~const Bar` is not satisfied LL | T::b(); | ^^^^ the trait `~const Bar` is not implemented for `T` | +note: the trait `Bar` is implemented for `T`, but that implementation is not `const` + --> $DIR/trait-where-clause.rs:14:5 + | +LL | T::b(); + | ^^^^ note: required by a bound in `Foo::b` --> $DIR/trait-where-clause.rs:8:24 | @@ -20,6 +25,11 @@ error[E0277]: the trait bound `T: ~const Bar` is not satisfied LL | T::c::(); | ^^^^^^^^^ the trait `~const Bar` is not implemented for `T` | +note: the trait `Bar` is implemented for `T`, but that implementation is not `const` + --> $DIR/trait-where-clause.rs:16:5 + | +LL | T::c::(); + | ^^^^^^^^^ note: required by a bound in `Foo::c` --> $DIR/trait-where-clause.rs:9:13 | From c6de4d55aab6d06f040202cbe39dc5c32809aac2 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 26 Jan 2022 19:24:01 -0800 Subject: [PATCH 03/13] drive-by: use is_const and is_const_if_const --- .../rustc_const_eval/src/const_eval/eval_queries.rs | 5 ++--- compiler/rustc_lint/src/traits.rs | 3 +-- compiler/rustc_middle/src/ty/mod.rs | 11 +++++++++-- .../src/traits/error_reporting/mod.rs | 2 +- .../src/traits/select/candidate_assembly.rs | 2 +- .../src/traits/select/confirmation.rs | 4 +--- .../rustc_trait_selection/src/traits/select/mod.rs | 4 +--- 7 files changed, 16 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs index 3ec9f3ca3b8c2..9dc34260de766 100644 --- a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs +++ b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs @@ -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; @@ -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; @@ -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 diff --git a/compiler/rustc_lint/src/traits.rs b/compiler/rustc_lint/src/traits.rs index dafff640b36ef..4c7f3482776d7 100644 --- a/compiler/rustc_lint/src/traits.rs +++ b/compiler/rustc_lint/src/traits.rs @@ -86,7 +86,6 @@ 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); @@ -94,7 +93,7 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints { 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; } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 2d8ee549f48dd..e7a8e71ce71b0 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -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> { @@ -804,8 +809,9 @@ impl<'tcx> PolyTraitPredicate<'tcx> { }); } - pub fn is_const(self) -> bool { - self.skip_binder().constness == BoundConstness::ConstIfConst + #[inline] + pub fn is_const_if_const(self) -> bool { + self.skip_binder().is_const_if_const() } } @@ -1392,6 +1398,7 @@ impl<'tcx> ParamEnv<'tcx> { self.packed.tag().constness } + #[inline] pub fn is_const(self) -> bool { self.packed.tag().constness == hir::Constness::Const } diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 081f823f851c6..687bd16ba30f4 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -440,7 +440,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { err.span_label(span, explanation); } - if trait_predicate.is_const() && obligation.param_env.is_const() { + 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(), diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 0099fba920042..db86041f6180b 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -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 { diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 2e20ea34e10ef..639884844b25d 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -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(), diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index ae53690548375..47427395b93b3 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -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 From c6f6e3e0e98dad9578df472a33a71d6bdf104666 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 26 Jan 2022 22:43:07 -0800 Subject: [PATCH 04/13] do not register infer var for GAT projection in opaque --- .../rustc_infer/src/infer/opaque_types.rs | 16 ++++++++------- .../generic-associated-types/issue-93340.rs | 20 +++++++++++++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 src/test/ui/generic-associated-types/issue-93340.rs diff --git a/compiler/rustc_infer/src/infer/opaque_types.rs b/compiler/rustc_infer/src/infer/opaque_types.rs index 4851e637d3a62..e7dca94806cb7 100644 --- a/compiler/rustc_infer/src/infer/opaque_types.rs +++ b/compiler/rustc_infer/src/infer/opaque_types.rs @@ -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, diff --git a/src/test/ui/generic-associated-types/issue-93340.rs b/src/test/ui/generic-associated-types/issue-93340.rs new file mode 100644 index 0000000000000..d065bde88c414 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-93340.rs @@ -0,0 +1,20 @@ +// check-pass + +#![feature(generic_associated_types)] + +pub trait Scalar: 'static { + type RefType<'a>: ScalarRef<'a>; +} + +pub trait ScalarRef<'a>: 'a {} + +fn cmp_eq<'a, 'b, A: Scalar, B: Scalar, O: Scalar>(a: A::RefType<'a>, b: B::RefType<'b>) -> O { + todo!() +} + +fn build_expression( +) -> impl Fn(A::RefType<'_>, B::RefType<'_>) -> O { + cmp_eq +} + +fn main() {} From da0d506ace5dc5ec36cd1eafa37a0657fa61442e Mon Sep 17 00:00:00 2001 From: Tomoaki Kawada Date: Fri, 28 Jan 2022 14:53:54 +0900 Subject: [PATCH 05/13] kmc-solid: Implement `FileDesc::duplicate` --- library/std/src/sys/solid/abi/sockets.rs | 3 +++ library/std/src/sys/solid/net.rs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/library/std/src/sys/solid/abi/sockets.rs b/library/std/src/sys/solid/abi/sockets.rs index 7c21d0dd25e03..eb06a6dd927e6 100644 --- a/library/std/src/sys/solid/abi/sockets.rs +++ b/library/std/src/sys/solid/abi/sockets.rs @@ -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; diff --git a/library/std/src/sys/solid/net.rs b/library/std/src/sys/solid/net.rs index 63ba6341c796c..c91ecce4d728b 100644 --- a/library/std/src/sys/solid/net.rs +++ b/library/std/src/sys/solid/net.rs @@ -107,7 +107,7 @@ impl FileDesc { } fn duplicate(&self) -> io::Result { - super::unsupported() + cvt(unsafe { netc::dup(self.fd) }).map(Self::new) } } From cdd0873db690cbcea1e5a011bbfc7fc94c5d5a6e Mon Sep 17 00:00:00 2001 From: woppopo Date: Fri, 28 Jan 2022 18:41:35 +0900 Subject: [PATCH 06/13] Add a test case for using NonNull::new in const context --- library/core/tests/lib.rs | 2 ++ library/core/tests/ptr.rs | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 841c114063dc1..e5ae65f1ab5e0 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -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)] diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs index b9c0d75b702e5..bbfd2d64dda40 100644 --- a/library/core/tests/ptr.rs +++ b/library/core/tests/ptr.rs @@ -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 From 2188c551cdd937f0939ecbb2a7c6bad2d7998c97 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Fri, 28 Jan 2022 09:36:04 +0000 Subject: [PATCH 07/13] Move unstable is_{arch}_feature_detected! macros to std::arch --- library/std/src/lib.rs | 44 ++++++++++++++++------------ library/std/tests/run-time-detect.rs | 6 ++++ 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 489d362be4276..7c8cb5378a2ab 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -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")] @@ -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] @@ -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)] diff --git a/library/std/tests/run-time-detect.rs b/library/std/tests/run-time-detect.rs index 079f00a5753f1..14a9e3acca499 100644 --- a/library/std/tests/run-time-detect.rs +++ b/library/std/tests/run-time-detect.rs @@ -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")); @@ -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")); @@ -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")); @@ -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")); @@ -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 From 9a814b8ba69257d01489c132e54b883de503802e Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Fri, 28 Jan 2022 09:51:09 +0000 Subject: [PATCH 08/13] Update stdarch submodule --- library/stdarch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/stdarch b/library/stdarch index 11c98f6eb9c4b..eaee02ffdf5d8 160000 --- a/library/stdarch +++ b/library/stdarch @@ -1 +1 @@ -Subproject commit 11c98f6eb9c4ba48b2362ad4960343b312d056b8 +Subproject commit eaee02ffdf5d820729ccdf2f95fa08b08c7d24d2 From 9d65342591d344c5358ee1aa2dd22c72748549f9 Mon Sep 17 00:00:00 2001 From: lcnr Date: Fri, 28 Jan 2022 15:02:47 +0100 Subject: [PATCH 09/13] fix nit --- compiler/rustc_middle/src/ty/sty.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 20db25f7899dd..f70fde2a040a1 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -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), } } From f9e0eb3b94776a80de110b1820d15270fadec633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Fri, 28 Jan 2022 16:56:05 +0100 Subject: [PATCH 10/13] remove unused `jemallocator` crate --- Cargo.lock | 11 ----------- compiler/rustc/Cargo.toml | 6 +----- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 738f33d3fa219..b70e82f36568f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3319,7 +3319,6 @@ dependencies = [ "rustc_codegen_ssa", "rustc_driver", "tikv-jemalloc-sys", - "tikv-jemallocator", ] [[package]] @@ -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" diff --git a/compiler/rustc/Cargo.toml b/compiler/rustc/Cargo.toml index 277cf0f51d378..696c003a587ac 100644 --- a/compiler/rustc/Cargo.toml +++ b/compiler/rustc/Cargo.toml @@ -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'] From 5b2747a3b95493344e7d3fb11a0f08a4973d77f2 Mon Sep 17 00:00:00 2001 From: Ben Reeves Date: Sun, 26 Dec 2021 23:30:46 -0600 Subject: [PATCH 11/13] Add test for old ICE The ICE from #84044 no longer occurs. --- src/test/ui/closures/issue-84044-drop-non-mut.rs | 6 ++++++ src/test/ui/closures/issue-84044-drop-non-mut.stderr | 11 +++++++++++ 2 files changed, 17 insertions(+) create mode 100644 src/test/ui/closures/issue-84044-drop-non-mut.rs create mode 100644 src/test/ui/closures/issue-84044-drop-non-mut.stderr diff --git a/src/test/ui/closures/issue-84044-drop-non-mut.rs b/src/test/ui/closures/issue-84044-drop-non-mut.rs new file mode 100644 index 0000000000000..aed7750f1b9df --- /dev/null +++ b/src/test/ui/closures/issue-84044-drop-non-mut.rs @@ -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 +} diff --git a/src/test/ui/closures/issue-84044-drop-non-mut.stderr b/src/test/ui/closures/issue-84044-drop-non-mut.stderr new file mode 100644 index 0000000000000..c0bfad263f178 --- /dev/null +++ b/src/test/ui/closures/issue-84044-drop-non-mut.stderr @@ -0,0 +1,11 @@ +error[E0596]: cannot borrow `f` as mutable, as it is not declared as mutable + --> $DIR/issue-84044-drop-non-mut.rs:5:10 + | +LL | let f = || {}; + | - help: consider changing this to be mutable: `mut f` +LL | drop(&mut f); + | ^^^^^^ cannot borrow as mutable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0596`. From 2819d9051c733e3777b884e9f5f653029e49cce0 Mon Sep 17 00:00:00 2001 From: Ben Reeves Date: Mon, 27 Dec 2021 00:09:19 -0600 Subject: [PATCH 12/13] Add test for old ICE in #91594 --- src/test/ui/traits/issue-91594.rs | 17 +++++++++++++++++ src/test/ui/traits/issue-91594.stderr | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/test/ui/traits/issue-91594.rs create mode 100644 src/test/ui/traits/issue-91594.stderr diff --git a/src/test/ui/traits/issue-91594.rs b/src/test/ui/traits/issue-91594.rs new file mode 100644 index 0000000000000..930f7f0c6ad6b --- /dev/null +++ b/src/test/ui/traits/issue-91594.rs @@ -0,0 +1,17 @@ +// #91594: This used to ICE. + +trait Component { + type Interface; +} +trait HasComponent {} + +struct Foo; + +impl HasComponent<>::Interface> for Foo {} +//~^ ERROR the trait bound `Foo: HasComponent<()>` is not satisfied + +impl> Component for Foo { + type Interface = u8; +} + +fn main() {} diff --git a/src/test/ui/traits/issue-91594.stderr b/src/test/ui/traits/issue-91594.stderr new file mode 100644 index 0000000000000..10298a0c7037a --- /dev/null +++ b/src/test/ui/traits/issue-91594.stderr @@ -0,0 +1,17 @@ +error[E0277]: the trait bound `Foo: HasComponent<()>` is not satisfied + --> $DIR/issue-91594.rs:10:6 + | +LL | impl HasComponent<>::Interface> for Foo {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `HasComponent<()>` is not implemented for `Foo` + | + = help: the following implementations were found: + >::Interface>> +note: required because of the requirements on the impl of `Component` for `Foo` + --> $DIR/issue-91594.rs:13:27 + | +LL | impl> Component for Foo { + | ^^^^^^^^^^^^ ^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. From 3f849a8b1edb11762194ef6f0f153a0e672c9112 Mon Sep 17 00:00:00 2001 From: Ben Reeves Date: Mon, 27 Dec 2021 00:24:19 -0600 Subject: [PATCH 13/13] Add test for old ICE in #89066 --- src/test/ui/save-analysis/issue-89066.rs | 28 ++++++++++++++ src/test/ui/save-analysis/issue-89066.stderr | 39 ++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 src/test/ui/save-analysis/issue-89066.rs create mode 100644 src/test/ui/save-analysis/issue-89066.stderr diff --git a/src/test/ui/save-analysis/issue-89066.rs b/src/test/ui/save-analysis/issue-89066.rs new file mode 100644 index 0000000000000..2873f5237d4a1 --- /dev/null +++ b/src/test/ui/save-analysis/issue-89066.rs @@ -0,0 +1,28 @@ +// compile-flags: -Zsave-analysis + +// Check that this does not ICE. +// Stolen from src/test/ui/const-generics/generic_arg_infer/infer-arg-test.rs + +#![feature(generic_arg_infer)] + +struct All<'a, T, const N: usize> { + v: &'a T, +} + +struct BadInfer<_>; +//~^ ERROR expected identifier +//~| ERROR parameter `_` is never used + +fn all_fn<'a, T, const N: usize>() {} + +fn bad_infer_fn<_>() {} +//~^ ERROR expected identifier + + +fn main() { + let a: All<_, _, _>; + //~^ ERROR this struct takes 2 generic arguments but 3 generic arguments were supplied + all_fn(); + let v: [u8; _]; + let v: [u8; 10] = [0; _]; +} diff --git a/src/test/ui/save-analysis/issue-89066.stderr b/src/test/ui/save-analysis/issue-89066.stderr new file mode 100644 index 0000000000000..a3ff1c02b2a04 --- /dev/null +++ b/src/test/ui/save-analysis/issue-89066.stderr @@ -0,0 +1,39 @@ +error: expected identifier, found reserved identifier `_` + --> $DIR/issue-89066.rs:12:17 + | +LL | struct BadInfer<_>; + | ^ expected identifier, found reserved identifier + +error: expected identifier, found reserved identifier `_` + --> $DIR/issue-89066.rs:18:17 + | +LL | fn bad_infer_fn<_>() {} + | ^ expected identifier, found reserved identifier + +error[E0392]: parameter `_` is never used + --> $DIR/issue-89066.rs:12:17 + | +LL | struct BadInfer<_>; + | ^ unused parameter + | + = help: consider removing `_`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `_` to be a const parameter, use `const _: usize` instead + +error[E0107]: this struct takes 2 generic arguments but 3 generic arguments were supplied + --> $DIR/issue-89066.rs:23:10 + | +LL | let a: All<_, _, _>; + | ^^^ - help: remove this generic argument + | | + | expected 2 generic arguments + | +note: struct defined here, with 2 generic parameters: `T`, `N` + --> $DIR/issue-89066.rs:8:8 + | +LL | struct All<'a, T, const N: usize> { + | ^^^ - - + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0107, E0392. +For more information about an error, try `rustc --explain E0107`.