From 04eec37dc2cababaecffd423e330d3c19d3c6169 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Sun, 13 Aug 2023 09:02:31 +0000 Subject: [PATCH 1/6] Enable effects for libcore --- compiler/rustc_hir_typeck/src/expr.rs | 8 +- .../rustc_hir_typeck/src/fn_ctxt/checks.rs | 19 ++-- compiler/rustc_monomorphize/src/collector.rs | 6 ++ library/core/src/lib.rs | 1 + library/core/src/marker.rs | 2 +- library/core/src/ops/drop.rs | 2 +- library/core/src/ops/function.rs | 6 +- .../ui/consts/const-block-const-bound.stderr | 9 +- tests/ui/consts/fn_trait_refs.stderr | 86 ++++++++++++++++++- .../ui/consts/unstable-const-fn-in-libcore.rs | 8 +- .../unstable-const-fn-in-libcore.stderr | 34 +------- .../impl-trait/normalize-tait-in-const.stderr | 25 ++---- .../const-closure-parse-not-item.rs | 3 +- .../const-closure-parse-not-item.stderr | 8 ++ .../const-closure-trait-method-fail.stderr | 15 +--- .../const-closure-trait-method.stderr | 15 +--- .../const-closures.stderr | 49 ++++------- .../const-drop-bound.stderr | 23 +++-- .../const-drop-fail-2.stderr | 9 +- .../const-drop-fail.precise.stderr | 7 +- .../const-drop-fail.stock.stderr | 9 +- .../const-drop.precise.stderr | 19 +--- .../const-drop.stock.stderr | 19 +--- .../const-impl-trait.stderr | 38 +++++++- .../effects/infer-fallback.rs | 11 +++ .../issue-92111.stderr | 9 +- 26 files changed, 258 insertions(+), 182 deletions(-) create mode 100644 tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-parse-not-item.stderr create mode 100644 tests/ui/rfcs/rfc-2632-const-trait-impl/effects/infer-fallback.rs diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 70d1dad8a6f46..4ad14ce3059f3 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -525,8 +525,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { _ => self.instantiate_value_path(segs, opt_ty, res, expr.span, expr.hir_id).0, }; - if let ty::FnDef(did, ..) = *ty.kind() { + if let ty::FnDef(did, callee_args) = *ty.kind() { let fn_sig = ty.fn_sig(tcx); + + // HACK: whenever we get a FnDef in a non-const context, enforce effects to get the + // default `host = true` to avoid inference errors later. + if tcx.hir().body_const_context(self.body_id).is_none() { + self.enforce_context_effects(expr.hir_id, qpath.span(), did, callee_args); + } if tcx.fn_sig(did).skip_binder().abi() == RustIntrinsic && tcx.item_name(did) == sym::transmute { diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 4def78673841c..37ea94d821e7a 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -273,11 +273,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // // This check is here because there is currently no way to express a trait bound for `FnDef` types only. if is_const_eval_select && (1..=2).contains(&idx) { - if let ty::FnDef(def_id, _) = checked_ty.kind() { - if idx == 1 && !self.tcx.is_const_fn_raw(*def_id) { - self.tcx - .sess - .emit_err(errors::ConstSelectMustBeConst { span: provided_arg.span }); + if let ty::FnDef(def_id, args) = *checked_ty.kind() { + if idx == 1 { + if !self.tcx.is_const_fn_raw(def_id) { + self.tcx.sess.emit_err(errors::ConstSelectMustBeConst { + span: provided_arg.span, + }); + } else { + self.enforce_context_effects( + provided_arg.hir_id, + provided_arg.span, + def_id, + args, + ) + } } } else { self.tcx.sess.emit_err(errors::ConstSelectMustBeFn { diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 67e821dcf5a37..118b3862887c7 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -815,6 +815,12 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { mir::AssertKind::BoundsCheck { .. } => LangItem::PanicBoundsCheck, _ => LangItem::Panic, }; + let def_id = tcx.require_lang_item(lang_item, Some(source)); + let instance = if has_host_effect { + Instance::new(def_id, tcx.mk_args(&[tcx.consts.true_.into()])) + } else { + Instance::mono(tcx, def_id) + }; push_mono_lang_item(self, lang_item); } mir::TerminatorKind::UnwindTerminate(reason) => { diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index b5458e667ed5f..8b04bafcda54a 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -195,6 +195,7 @@ // // Language features: // tidy-alphabetical-start +#![cfg_attr(not(bootstrap), feature(effects))] #![feature(abi_unadjusted)] #![feature(adt_const_params)] #![feature(allow_internal_unsafe)] diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 5ec751e5168bf..d25a5821911f3 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -960,7 +960,7 @@ marker_impls! { #[lang = "destruct"] #[rustc_on_unimplemented(message = "can't drop `{Self}`", append_const_msg)] #[rustc_deny_explicit_impl(implement_via_object = false)] -#[const_trait] +// FIXME(effects) #[const_trait] pub trait Destruct {} /// A marker for tuple types. diff --git a/library/core/src/ops/drop.rs b/library/core/src/ops/drop.rs index 21c23dabfc2c7..34dfa9e4c51fc 100644 --- a/library/core/src/ops/drop.rs +++ b/library/core/src/ops/drop.rs @@ -202,7 +202,7 @@ /// [nomicon]: ../../nomicon/phantom-data.html#an-exception-the-special-case-of-the-standard-library-and-its-unstable-may_dangle #[lang = "drop"] #[stable(feature = "rust1", since = "1.0.0")] -#[const_trait] +// FIXME(effects) #[const_trait] pub trait Drop { /// Executes the destructor for this type. /// diff --git a/library/core/src/ops/function.rs b/library/core/src/ops/function.rs index 67c8245f0bfe0..20f0bba4c13b6 100644 --- a/library/core/src/ops/function.rs +++ b/library/core/src/ops/function.rs @@ -72,7 +72,7 @@ use crate::marker::Tuple; )] #[fundamental] // so that regex can rely that `&str: !FnMut` #[must_use = "closures are lazy and do nothing unless called"] -#[const_trait] +// FIXME(effects) #[const_trait] pub trait Fn: FnMut { /// Performs the call operation. #[unstable(feature = "fn_traits", issue = "29625")] @@ -159,7 +159,7 @@ pub trait Fn: FnMut { )] #[fundamental] // so that regex can rely that `&str: !FnMut` #[must_use = "closures are lazy and do nothing unless called"] -#[const_trait] +// FIXME(effects) #[const_trait] pub trait FnMut: FnOnce { /// Performs the call operation. #[unstable(feature = "fn_traits", issue = "29625")] @@ -238,7 +238,7 @@ pub trait FnMut: FnOnce { )] #[fundamental] // so that regex can rely that `&str: !FnMut` #[must_use = "closures are lazy and do nothing unless called"] -#[const_trait] +// FIXME(effects) #[const_trait] pub trait FnOnce { /// The returned type after the call operator is used. #[lang = "fn_once_output"] diff --git a/tests/ui/consts/const-block-const-bound.stderr b/tests/ui/consts/const-block-const-bound.stderr index b402f0ea91548..6a001cca44d70 100644 --- a/tests/ui/consts/const-block-const-bound.stderr +++ b/tests/ui/consts/const-block-const-bound.stderr @@ -1,11 +1,8 @@ -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/const-block-const-bound.rs:8:32 +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/const-block-const-bound.rs:8:22 | LL | const fn f(x: T) {} - | ^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions + | ^^^^^^^^ error: aborting due to previous error -For more information about this error, try `rustc --explain E0493`. diff --git a/tests/ui/consts/fn_trait_refs.stderr b/tests/ui/consts/fn_trait_refs.stderr index bfebf66701bd9..b8d5fb7440177 100644 --- a/tests/ui/consts/fn_trait_refs.stderr +++ b/tests/ui/consts/fn_trait_refs.stderr @@ -10,6 +10,90 @@ error[E0635]: unknown feature `const_cmp` LL | #![feature(const_cmp)] | ^^^^^^^^^ -error: aborting due to 2 previous errors +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/fn_trait_refs.rs:15:15 + | +LL | T: ~const Fn<()> + ~const Destruct, + | ^^^^^^ + +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/fn_trait_refs.rs:15:31 + | +LL | T: ~const Fn<()> + ~const Destruct, + | ^^^^^^^^ + +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/fn_trait_refs.rs:15:15 + | +LL | T: ~const Fn<()> + ~const Destruct, + | ^^^^^^ + +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/fn_trait_refs.rs:22:15 + | +LL | T: ~const FnMut<()> + ~const Destruct, + | ^^^^^^^^^ + +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/fn_trait_refs.rs:22:34 + | +LL | T: ~const FnMut<()> + ~const Destruct, + | ^^^^^^^^ + +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/fn_trait_refs.rs:22:15 + | +LL | T: ~const FnMut<()> + ~const Destruct, + | ^^^^^^^^^ + +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/fn_trait_refs.rs:29:15 + | +LL | T: ~const FnOnce<()>, + | ^^^^^^^^^^ + +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/fn_trait_refs.rs:29:15 + | +LL | T: ~const FnOnce<()>, + | ^^^^^^^^^^ + +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/fn_trait_refs.rs:36:15 + | +LL | T: ~const Fn<()> + ~const Destruct, + | ^^^^^^ + +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/fn_trait_refs.rs:36:31 + | +LL | T: ~const Fn<()> + ~const Destruct, + | ^^^^^^^^ + +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/fn_trait_refs.rs:36:15 + | +LL | T: ~const Fn<()> + ~const Destruct, + | ^^^^^^ + +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/fn_trait_refs.rs:50:15 + | +LL | T: ~const FnMut<()> + ~const Destruct, + | ^^^^^^^^^ + +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/fn_trait_refs.rs:50:34 + | +LL | T: ~const FnMut<()> + ~const Destruct, + | ^^^^^^^^ + +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/fn_trait_refs.rs:50:15 + | +LL | T: ~const FnMut<()> + ~const Destruct, + | ^^^^^^^^^ + +error: aborting due to 16 previous errors For more information about this error, try `rustc --explain E0635`. diff --git a/tests/ui/consts/unstable-const-fn-in-libcore.rs b/tests/ui/consts/unstable-const-fn-in-libcore.rs index 61e28117ed455..b62a74039f6dd 100644 --- a/tests/ui/consts/unstable-const-fn-in-libcore.rs +++ b/tests/ui/consts/unstable-const-fn-in-libcore.rs @@ -1,3 +1,5 @@ +// known-bug: #110395 +// FIXME check-pass // This is a non-regression test for const-qualification of unstable items in libcore // as explained in issue #67053. // const-qualification could miss some `const fn`s if they were unstable and the feature @@ -15,12 +17,12 @@ impl Opt { #[rustc_const_unstable(feature = "foo", issue = "none")] #[stable(feature = "rust1", since = "1.0.0")] const fn unwrap_or_else T>(self, f: F) -> T { - //~^ ERROR destructor of - //~| ERROR destructor of + //FIXME ~^ ERROR destructor of + //FIXME ~| ERROR destructor of match self { Opt::Some(t) => t, Opt::None => f(), - //~^ ERROR cannot call + //FIXME ~^ ERROR cannot call } } } diff --git a/tests/ui/consts/unstable-const-fn-in-libcore.stderr b/tests/ui/consts/unstable-const-fn-in-libcore.stderr index 95d7b7e853766..b75f99a720f6e 100644 --- a/tests/ui/consts/unstable-const-fn-in-libcore.stderr +++ b/tests/ui/consts/unstable-const-fn-in-libcore.stderr @@ -1,34 +1,8 @@ -error[E0015]: cannot call non-const closure in constant functions - --> $DIR/unstable-const-fn-in-libcore.rs:22:26 - | -LL | Opt::None => f(), - | ^^^ - | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants -help: consider further restricting this bound - | -LL | const fn unwrap_or_else T + ~const std::ops::FnOnce<()>>(self, f: F) -> T { - | +++++++++++++++++++++++++++++ - -error[E0493]: destructor of `F` cannot be evaluated at compile-time - --> $DIR/unstable-const-fn-in-libcore.rs:17:60 - | -LL | const fn unwrap_or_else T>(self, f: F) -> T { - | ^ the destructor for this type cannot be evaluated in constant functions -... -LL | } - | - value is dropped here - -error[E0493]: destructor of `Opt` cannot be evaluated at compile-time - --> $DIR/unstable-const-fn-in-libcore.rs:17:54 +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/unstable-const-fn-in-libcore.rs:19:39 | LL | const fn unwrap_or_else T>(self, f: F) -> T { - | ^^^^ the destructor for this type cannot be evaluated in constant functions -... -LL | } - | - value is dropped here + | ^^^^^^^^^^^^^ -error: aborting due to 3 previous errors +error: aborting due to previous error -Some errors have detailed explanations: E0015, E0493. -For more information about an error, try `rustc --explain E0015`. diff --git a/tests/ui/impl-trait/normalize-tait-in-const.stderr b/tests/ui/impl-trait/normalize-tait-in-const.stderr index 5fbba9a85caf3..156c67d6ae00f 100644 --- a/tests/ui/impl-trait/normalize-tait-in-const.stderr +++ b/tests/ui/impl-trait/normalize-tait-in-const.stderr @@ -1,25 +1,14 @@ -error[E0015]: cannot call non-const closure in constant functions - --> $DIR/normalize-tait-in-const.rs:26:5 +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/normalize-tait-in-const.rs:25:42 | -LL | fun(filter_positive()); - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants -help: consider further restricting this bound - | -LL | const fn with_positive Fn(&'a Alias<'a>) + ~const Destruct + ~const std::ops::Fn<(&Alias<'_>,)>>(fun: F) { - | ++++++++++++++++++++++++++++++++++++ +LL | const fn with_positive Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { + | ^^^^^^^^^^^^^^^^^ -error[E0493]: destructor of `F` cannot be evaluated at compile-time - --> $DIR/normalize-tait-in-const.rs:25:79 +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/normalize-tait-in-const.rs:25:69 | LL | const fn with_positive Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { - | ^^^ the destructor for this type cannot be evaluated in constant functions -LL | fun(filter_positive()); -LL | } - | - value is dropped here + | ^^^^^^^^ error: aborting due to 2 previous errors -Some errors have detailed explanations: E0015, E0493. -For more information about an error, try `rustc --explain E0015`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-parse-not-item.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-parse-not-item.rs index 2c99d8bf1c677..15f062edf0ede 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-parse-not-item.rs +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-parse-not-item.rs @@ -1,4 +1,5 @@ -// check-pass +// known-bug: #110395 +// FIXME check-pass #![feature(const_trait_impl, const_closures)] #![allow(incomplete_features)] diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-parse-not-item.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-parse-not-item.stderr new file mode 100644 index 0000000000000..f25390a9070e1 --- /dev/null +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-parse-not-item.stderr @@ -0,0 +1,8 @@ +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/const-closure-parse-not-item.rs:7:32 + | +LL | const fn test() -> impl ~const Fn() { + | ^^^^ + +error: aborting due to previous error + diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-trait-method-fail.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-trait-method-fail.stderr index 96ffca6519ab4..4c45b0e56c601 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-trait-method-fail.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-trait-method-fail.stderr @@ -1,15 +1,8 @@ -error[E0015]: cannot call non-const closure in constant functions - --> $DIR/const-closure-trait-method-fail.rs:15:5 +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/const-closure-trait-method-fail.rs:14:39 | -LL | x(()) - | ^^^^^ - | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants -help: consider further restricting this bound - | -LL | const fn need_const_closure i32 + ~const std::ops::FnOnce<((),)>>(x: T) -> i32 { - | ++++++++++++++++++++++++++++++++ +LL | const fn need_const_closure i32>(x: T) -> i32 { + | ^^^^^^^^^^^^^^^^^ error: aborting due to previous error -For more information about this error, try `rustc --explain E0015`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-trait-method.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-trait-method.stderr index fd0c29118145f..a8ef244ea3092 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-trait-method.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closure-trait-method.stderr @@ -1,15 +1,8 @@ -error[E0015]: cannot call non-const closure in constant functions - --> $DIR/const-closure-trait-method.rs:15:5 +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/const-closure-trait-method.rs:14:39 | -LL | x(()) - | ^^^^^ - | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants -help: consider further restricting this bound - | -LL | const fn need_const_closure i32 + ~const std::ops::FnOnce<((),)>>(x: T) -> i32 { - | ++++++++++++++++++++++++++++++++ +LL | const fn need_const_closure i32>(x: T) -> i32 { + | ^^^^^^^^^^^^^^^^^ error: aborting due to previous error -For more information about this error, try `rustc --explain E0015`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closures.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closures.stderr index abf2a2dc511d1..6d61b23e4b7c3 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closures.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closures.stderr @@ -1,39 +1,26 @@ -error[E0015]: cannot call non-const closure in constant functions - --> $DIR/const-closures.rs:12:5 +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/const-closures.rs:8:19 | -LL | f() * 7 - | ^^^ - | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants -help: consider further restricting this bound - | -LL | F: ~const FnOnce() -> u8 + ~const std::ops::Fn<()>, - | +++++++++++++++++++++++++ +LL | F: ~const FnOnce() -> u8, + | ^^^^^^^^^^^^^^ -error[E0015]: cannot call non-const closure in constant functions - --> $DIR/const-closures.rs:24:5 - | -LL | f() + f() - | ^^^ +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/const-closures.rs:9:19 | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants -help: consider further restricting this bound - | -LL | const fn answer u8 + ~const std::ops::Fn<()>>(f: &F) -> u8 { - | +++++++++++++++++++++++++ +LL | F: ~const FnMut() -> u8, + | ^^^^^^^^^^^^^ -error[E0015]: cannot call non-const closure in constant functions - --> $DIR/const-closures.rs:24:11 - | -LL | f() + f() - | ^^^ +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/const-closures.rs:10:19 | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants -help: consider further restricting this bound +LL | F: ~const Fn() -> u8, + | ^^^^^^^^^^ + +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/const-closures.rs:23:27 | -LL | const fn answer u8 + ~const std::ops::Fn<()>>(f: &F) -> u8 { - | +++++++++++++++++++++++++ +LL | const fn answer u8>(f: &F) -> u8 { + | ^^^^^^^^^^ -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors -For more information about this error, try `rustc --explain E0015`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-bound.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-bound.stderr index f5147dc74b873..0142e343bb74b 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-bound.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-bound.stderr @@ -1,9 +1,20 @@ -error[E0493]: destructor of `E` cannot be evaluated at compile-time - --> $DIR/const-drop-bound.rs:12:13 +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/const-drop-bound.rs:9:68 | -LL | Err(_e) => None, - | ^^ the destructor for this type cannot be evaluated in constant functions +LL | const fn foo(res: Result) -> Option where E: ~const Destruct { + | ^^^^^^^^ -error: aborting due to previous error +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/const-drop-bound.rs:20:15 + | +LL | T: ~const Destruct, + | ^^^^^^^^ + +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/const-drop-bound.rs:21:15 + | +LL | E: ~const Destruct, + | ^^^^^^^^ + +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0493`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail-2.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail-2.stderr index 100d1df87d697..8e715169f18da 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail-2.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail-2.stderr @@ -1,11 +1,8 @@ -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/const-drop-fail-2.rs:21:36 +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/const-drop-fail-2.rs:21:26 | LL | const fn check(_: T) {} - | ^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions + | ^^^^^^^^ error: aborting due to previous error -For more information about this error, try `rustc --explain E0493`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr index dfa5ea8c4afa9..ba73c782c8d45 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr @@ -1,9 +1,8 @@ -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/const-drop-fail.rs:24:36 +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/const-drop-fail.rs:24:26 | LL | const fn check(_: T) {} - | ^ the destructor for this type cannot be evaluated in constant functions + | ^^^^^^^^ error: aborting due to previous error -For more information about this error, try `rustc --explain E0493`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail.stock.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail.stock.stderr index 8af38b792e668..ba73c782c8d45 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail.stock.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail.stock.stderr @@ -1,11 +1,8 @@ -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/const-drop-fail.rs:24:36 +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/const-drop-fail.rs:24:26 | LL | const fn check(_: T) {} - | ^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions + | ^^^^^^^^ error: aborting due to previous error -For more information about this error, try `rustc --explain E0493`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.precise.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.precise.stderr index 23e368870258e..5c2e6c5bd7db3 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.precise.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.precise.stderr @@ -1,19 +1,8 @@ -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/const-drop.rs:19:32 +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/const-drop.rs:19:22 | LL | const fn a(_: T) {} - | ^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions + | ^^^^^^^^ -error[E0493]: destructor of `S<'_>` cannot be evaluated at compile-time - --> $DIR/const-drop.rs:24:13 - | -LL | let _ = S(&mut c); - | ^^^^^^^^^- value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions - -error: aborting due to 2 previous errors +error: aborting due to previous error -For more information about this error, try `rustc --explain E0493`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.stock.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.stock.stderr index 23e368870258e..5c2e6c5bd7db3 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.stock.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.stock.stderr @@ -1,19 +1,8 @@ -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/const-drop.rs:19:32 +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/const-drop.rs:19:22 | LL | const fn a(_: T) {} - | ^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions + | ^^^^^^^^ -error[E0493]: destructor of `S<'_>` cannot be evaluated at compile-time - --> $DIR/const-drop.rs:24:13 - | -LL | let _ = S(&mut c); - | ^^^^^^^^^- value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions - -error: aborting due to 2 previous errors +error: aborting due to previous error -For more information about this error, try `rustc --explain E0493`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.stderr index f9078e227910d..ebd4e2160895d 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.stderr @@ -16,24 +16,60 @@ error: ~const can only be applied to `#[const_trait]` traits LL | const fn wrap(x: impl ~const PartialEq + ~const Destruct) | ^^^^^^^^^ +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/const-impl-trait.rs:16:49 + | +LL | const fn wrap(x: impl ~const PartialEq + ~const Destruct) + | ^^^^^^^^ + error: ~const can only be applied to `#[const_trait]` traits --> $DIR/const-impl-trait.rs:17:20 | LL | -> impl ~const PartialEq + ~const Destruct | ^^^^^^^^^ +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/const-impl-trait.rs:17:39 + | +LL | -> impl ~const PartialEq + ~const Destruct + | ^^^^^^^^ + error: ~const can only be applied to `#[const_trait]` traits --> $DIR/const-impl-trait.rs:24:29 | LL | fn huh() -> impl ~const PartialEq + ~const Destruct + Copy; | ^^^^^^^^^ +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/const-impl-trait.rs:24:48 + | +LL | fn huh() -> impl ~const PartialEq + ~const Destruct + Copy; + | ^^^^^^^^ + error: ~const can only be applied to `#[const_trait]` traits --> $DIR/const-impl-trait.rs:28:29 | LL | fn huh() -> impl ~const PartialEq + ~const Destruct + Copy { | ^^^^^^^^^ -error: aborting due to 6 previous errors +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/const-impl-trait.rs:28:48 + | +LL | fn huh() -> impl ~const PartialEq + ~const Destruct + Copy { + | ^^^^^^^^ + +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/const-impl-trait.rs:49:41 + | +LL | const fn apit(_: impl ~const T + ~const Destruct) {} + | ^^^^^^^^ + +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/const-impl-trait.rs:53:73 + | +LL | const fn apit_assoc_bound(_: impl IntoIterator + ~const Destruct) {} + | ^^^^^^^^ + +error: aborting due to 12 previous errors For more information about this error, try `rustc --explain E0635`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/infer-fallback.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/infer-fallback.rs new file mode 100644 index 0000000000000..2f474d978d3b3 --- /dev/null +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/infer-fallback.rs @@ -0,0 +1,11 @@ +// check-pass +#![feature(const_trait_impl, effects)] + +const fn a() {} + +fn foo(a: F) {} + +fn main() { + let _ = a; + foo(a); +} diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-92111.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-92111.stderr index b27f94f99ed74..90d3aee5202a3 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-92111.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-92111.stderr @@ -1,11 +1,8 @@ -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/issue-92111.rs:20:32 +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/issue-92111.rs:20:22 | LL | const fn a(t: T) {} - | ^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions + | ^^^^^^^^ error: aborting due to previous error -For more information about this error, try `rustc --explain E0493`. From 7b1b17574bf1466ddd7e6657b6122244dc5a73ce Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Tue, 12 Sep 2023 01:07:04 +0000 Subject: [PATCH 2/6] fix bugs with effects fallback --- compiler/rustc_monomorphize/src/collector.rs | 6 ------ compiler/rustc_passes/src/lang_items.rs | 12 ++++++++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 118b3862887c7..67e821dcf5a37 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -815,12 +815,6 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { mir::AssertKind::BoundsCheck { .. } => LangItem::PanicBoundsCheck, _ => LangItem::Panic, }; - let def_id = tcx.require_lang_item(lang_item, Some(source)); - let instance = if has_host_effect { - Instance::new(def_id, tcx.mk_args(&[tcx.consts.true_.into()])) - } else { - Instance::mono(tcx, def_id) - }; push_mono_lang_item(self, lang_item); } mir::TerminatorKind::UnwindTerminate(reason) => { diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs index 476394f30ccfd..7e83724391836 100644 --- a/compiler/rustc_passes/src/lang_items.rs +++ b/compiler/rustc_passes/src/lang_items.rs @@ -20,7 +20,8 @@ use rustc_hir::lang_items::{extract, GenericRequirement}; use rustc_hir::{LangItem, LanguageItems, Target}; use rustc_middle::ty::TyCtxt; use rustc_session::cstore::ExternCrate; -use rustc_span::{symbol::kw::Empty, Span}; +use rustc_span::symbol::kw::Empty; +use rustc_span::{sym, Span}; use rustc_middle::query::Providers; @@ -157,7 +158,14 @@ impl<'tcx> LanguageItemCollector<'tcx> { self.tcx.hir().get_by_def_id(item_def_id) { let (actual_num, generics_span) = match kind.generics() { - Some(generics) => (generics.params.len(), generics.span), + Some(generics) => ( + generics + .params + .iter() + .filter(|p| !self.tcx.has_attr(p.def_id, sym::rustc_host)) + .count(), + generics.span, + ), None => (0, *item_span), }; From a3b5f1ad85828e15ceceedb8fdb950072e7d9776 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Wed, 20 Sep 2023 01:34:37 +0000 Subject: [PATCH 3/6] ignore host effect params in rustdoc --- src/librustdoc/clean/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 190b1b038b68a..c401146188528 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -793,6 +793,7 @@ fn clean_ty_generics<'tcx>( } Some(clean_generic_param_def(param, cx)) } + ty::GenericParamDefKind::Const { is_host_effect: true, .. } => None, ty::GenericParamDefKind::Const { .. } => Some(clean_generic_param_def(param, cx)), }) .collect::>(); From 7446012c1e6bcf9669684399337ede66072b41a3 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Wed, 20 Sep 2023 01:57:06 +0000 Subject: [PATCH 4/6] fix rustdoc tests --- library/core/src/marker.rs | 2 +- tests/rustdoc/rfc-2632-const-trait-impl.rs | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index d25a5821911f3..5ec751e5168bf 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -960,7 +960,7 @@ marker_impls! { #[lang = "destruct"] #[rustc_on_unimplemented(message = "can't drop `{Self}`", append_const_msg)] #[rustc_deny_explicit_impl(implement_via_object = false)] -// FIXME(effects) #[const_trait] +#[const_trait] pub trait Destruct {} /// A marker for tuple types. diff --git a/tests/rustdoc/rfc-2632-const-trait-impl.rs b/tests/rustdoc/rfc-2632-const-trait-impl.rs index 5d742dc391a53..7f56b2ffeb8ad 100644 --- a/tests/rustdoc/rfc-2632-const-trait-impl.rs +++ b/tests/rustdoc/rfc-2632-const-trait-impl.rs @@ -5,6 +5,8 @@ // To future blessers: make sure that `const_trait_impl` is // stabilized when changing `@!has` to `@has`, and please do // not remove this test. +// +// FIXME(effects) add `const_trait` to `Fn` so we use `~const` #![feature(const_trait_impl)] #![crate_name = "foo"] @@ -22,9 +24,9 @@ pub trait Tr { // @has - '//section[@id="method.a"]/h4[@class="code-header"]/a[@class="trait"]' 'Fn' // @!has - '//section[@id="method.a"]/h4[@class="code-header"]/span[@class="where"]' '~const' // @has - '//section[@id="method.a"]/h4[@class="code-header"]/span[@class="where fmt-newline"]' ': Fn' - fn a() + fn a() where - Option: ~const Fn() + ~const Destruct, + Option: /* ~const */ Fn() + ~const Destruct, { } } @@ -34,13 +36,13 @@ pub trait Tr { // @has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header"]/a[@class="trait"]' 'Fn' // @!has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header"]/span[@class="where"]' '~const' // @has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header"]/span[@class="where fmt-newline"]' ': Fn' -impl const Tr for T +impl const Tr for T where - Option: ~const Fn() + ~const Destruct, + Option: /* ~const */ Fn() + ~const Destruct, { - fn a() + fn a() where - Option: ~const Fn() + ~const Destruct, + Option: /* ~const */ Fn() + ~const Destruct, { } } @@ -49,9 +51,9 @@ where // @has - '//pre[@class="rust item-decl"]/code/a[@class="trait"]' 'Fn' // @!has - '//pre[@class="rust item-decl"]/code/span[@class="where fmt-newline"]' '~const' // @has - '//pre[@class="rust item-decl"]/code/span[@class="where fmt-newline"]' ': Fn' -pub const fn foo() +pub const fn foo() where - Option: ~const Fn() + ~const Destruct, + Option: /* ~const */ Fn() + ~const Destruct, { F::a() } @@ -61,9 +63,9 @@ impl S { // @has - '//section[@id="method.foo"]/h4[@class="code-header"]/a[@class="trait"]' 'Fn' // @!has - '//section[@id="method.foo"]/h4[@class="code-header"]/span[@class="where"]' '~const' // @has - '//section[@id="method.foo"]/h4[@class="code-header"]/span[@class="where fmt-newline"]' ': Fn' - pub const fn foo() + pub const fn foo() where - B: ~const Fn() + ~const Destruct, + B: /* ~const */ Fn() + ~const Destruct, { B::a() } From 2063ebc3eac2587612fea57c2e48e7b6a78f9736 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Wed, 20 Sep 2023 02:25:49 +0000 Subject: [PATCH 5/6] bless the known-bug tests --- .../ui/consts/const-block-const-bound.stderr | 9 +++-- tests/ui/consts/fn_trait_refs.stderr | 26 +------------ .../impl-trait/normalize-tait-in-const.stderr | 8 +--- .../const-drop-bound.stderr | 23 +++-------- .../const-drop-fail-2.stderr | 9 +++-- .../const-drop-fail.precise.stderr | 7 ++-- .../const-drop-fail.stock.stderr | 9 +++-- .../const-drop.precise.stderr | 19 ++++++++-- .../const-drop.stock.stderr | 19 ++++++++-- .../const-impl-trait.stderr | 38 +------------------ .../issue-92111.stderr | 9 +++-- 11 files changed, 67 insertions(+), 109 deletions(-) diff --git a/tests/ui/consts/const-block-const-bound.stderr b/tests/ui/consts/const-block-const-bound.stderr index 6a001cca44d70..b402f0ea91548 100644 --- a/tests/ui/consts/const-block-const-bound.stderr +++ b/tests/ui/consts/const-block-const-bound.stderr @@ -1,8 +1,11 @@ -error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/const-block-const-bound.rs:8:22 +error[E0493]: destructor of `T` cannot be evaluated at compile-time + --> $DIR/const-block-const-bound.rs:8:32 | LL | const fn f(x: T) {} - | ^^^^^^^^ + | ^ - value is dropped here + | | + | the destructor for this type cannot be evaluated in constant functions error: aborting due to previous error +For more information about this error, try `rustc --explain E0493`. diff --git a/tests/ui/consts/fn_trait_refs.stderr b/tests/ui/consts/fn_trait_refs.stderr index b8d5fb7440177..658a0b7b2a084 100644 --- a/tests/ui/consts/fn_trait_refs.stderr +++ b/tests/ui/consts/fn_trait_refs.stderr @@ -16,12 +16,6 @@ error: ~const can only be applied to `#[const_trait]` traits LL | T: ~const Fn<()> + ~const Destruct, | ^^^^^^ -error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/fn_trait_refs.rs:15:31 - | -LL | T: ~const Fn<()> + ~const Destruct, - | ^^^^^^^^ - error: ~const can only be applied to `#[const_trait]` traits --> $DIR/fn_trait_refs.rs:15:15 | @@ -34,12 +28,6 @@ error: ~const can only be applied to `#[const_trait]` traits LL | T: ~const FnMut<()> + ~const Destruct, | ^^^^^^^^^ -error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/fn_trait_refs.rs:22:34 - | -LL | T: ~const FnMut<()> + ~const Destruct, - | ^^^^^^^^ - error: ~const can only be applied to `#[const_trait]` traits --> $DIR/fn_trait_refs.rs:22:15 | @@ -64,12 +52,6 @@ error: ~const can only be applied to `#[const_trait]` traits LL | T: ~const Fn<()> + ~const Destruct, | ^^^^^^ -error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/fn_trait_refs.rs:36:31 - | -LL | T: ~const Fn<()> + ~const Destruct, - | ^^^^^^^^ - error: ~const can only be applied to `#[const_trait]` traits --> $DIR/fn_trait_refs.rs:36:15 | @@ -82,18 +64,12 @@ error: ~const can only be applied to `#[const_trait]` traits LL | T: ~const FnMut<()> + ~const Destruct, | ^^^^^^^^^ -error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/fn_trait_refs.rs:50:34 - | -LL | T: ~const FnMut<()> + ~const Destruct, - | ^^^^^^^^ - error: ~const can only be applied to `#[const_trait]` traits --> $DIR/fn_trait_refs.rs:50:15 | LL | T: ~const FnMut<()> + ~const Destruct, | ^^^^^^^^^ -error: aborting due to 16 previous errors +error: aborting due to 12 previous errors For more information about this error, try `rustc --explain E0635`. diff --git a/tests/ui/impl-trait/normalize-tait-in-const.stderr b/tests/ui/impl-trait/normalize-tait-in-const.stderr index 156c67d6ae00f..ada8fd7fa50ee 100644 --- a/tests/ui/impl-trait/normalize-tait-in-const.stderr +++ b/tests/ui/impl-trait/normalize-tait-in-const.stderr @@ -4,11 +4,5 @@ error: ~const can only be applied to `#[const_trait]` traits LL | const fn with_positive Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { | ^^^^^^^^^^^^^^^^^ -error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/normalize-tait-in-const.rs:25:69 - | -LL | const fn with_positive Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { - | ^^^^^^^^ - -error: aborting due to 2 previous errors +error: aborting due to previous error diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-bound.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-bound.stderr index 0142e343bb74b..f5147dc74b873 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-bound.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-bound.stderr @@ -1,20 +1,9 @@ -error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-bound.rs:9:68 +error[E0493]: destructor of `E` cannot be evaluated at compile-time + --> $DIR/const-drop-bound.rs:12:13 | -LL | const fn foo(res: Result) -> Option where E: ~const Destruct { - | ^^^^^^^^ +LL | Err(_e) => None, + | ^^ the destructor for this type cannot be evaluated in constant functions -error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-bound.rs:20:15 - | -LL | T: ~const Destruct, - | ^^^^^^^^ - -error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-bound.rs:21:15 - | -LL | E: ~const Destruct, - | ^^^^^^^^ - -error: aborting due to 3 previous errors +error: aborting due to previous error +For more information about this error, try `rustc --explain E0493`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail-2.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail-2.stderr index 8e715169f18da..100d1df87d697 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail-2.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail-2.stderr @@ -1,8 +1,11 @@ -error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-fail-2.rs:21:26 +error[E0493]: destructor of `T` cannot be evaluated at compile-time + --> $DIR/const-drop-fail-2.rs:21:36 | LL | const fn check(_: T) {} - | ^^^^^^^^ + | ^ - value is dropped here + | | + | the destructor for this type cannot be evaluated in constant functions error: aborting due to previous error +For more information about this error, try `rustc --explain E0493`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr index ba73c782c8d45..dfa5ea8c4afa9 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr @@ -1,8 +1,9 @@ -error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-fail.rs:24:26 +error[E0493]: destructor of `T` cannot be evaluated at compile-time + --> $DIR/const-drop-fail.rs:24:36 | LL | const fn check(_: T) {} - | ^^^^^^^^ + | ^ the destructor for this type cannot be evaluated in constant functions error: aborting due to previous error +For more information about this error, try `rustc --explain E0493`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail.stock.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail.stock.stderr index ba73c782c8d45..8af38b792e668 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail.stock.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail.stock.stderr @@ -1,8 +1,11 @@ -error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/const-drop-fail.rs:24:26 +error[E0493]: destructor of `T` cannot be evaluated at compile-time + --> $DIR/const-drop-fail.rs:24:36 | LL | const fn check(_: T) {} - | ^^^^^^^^ + | ^ - value is dropped here + | | + | the destructor for this type cannot be evaluated in constant functions error: aborting due to previous error +For more information about this error, try `rustc --explain E0493`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.precise.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.precise.stderr index 5c2e6c5bd7db3..23e368870258e 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.precise.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.precise.stderr @@ -1,8 +1,19 @@ -error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/const-drop.rs:19:22 +error[E0493]: destructor of `T` cannot be evaluated at compile-time + --> $DIR/const-drop.rs:19:32 | LL | const fn a(_: T) {} - | ^^^^^^^^ + | ^ - value is dropped here + | | + | the destructor for this type cannot be evaluated in constant functions -error: aborting due to previous error +error[E0493]: destructor of `S<'_>` cannot be evaluated at compile-time + --> $DIR/const-drop.rs:24:13 + | +LL | let _ = S(&mut c); + | ^^^^^^^^^- value is dropped here + | | + | the destructor for this type cannot be evaluated in constant functions + +error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0493`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.stock.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.stock.stderr index 5c2e6c5bd7db3..23e368870258e 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.stock.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.stock.stderr @@ -1,8 +1,19 @@ -error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/const-drop.rs:19:22 +error[E0493]: destructor of `T` cannot be evaluated at compile-time + --> $DIR/const-drop.rs:19:32 | LL | const fn a(_: T) {} - | ^^^^^^^^ + | ^ - value is dropped here + | | + | the destructor for this type cannot be evaluated in constant functions -error: aborting due to previous error +error[E0493]: destructor of `S<'_>` cannot be evaluated at compile-time + --> $DIR/const-drop.rs:24:13 + | +LL | let _ = S(&mut c); + | ^^^^^^^^^- value is dropped here + | | + | the destructor for this type cannot be evaluated in constant functions + +error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0493`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.stderr index ebd4e2160895d..f9078e227910d 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.stderr @@ -16,60 +16,24 @@ error: ~const can only be applied to `#[const_trait]` traits LL | const fn wrap(x: impl ~const PartialEq + ~const Destruct) | ^^^^^^^^^ -error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/const-impl-trait.rs:16:49 - | -LL | const fn wrap(x: impl ~const PartialEq + ~const Destruct) - | ^^^^^^^^ - error: ~const can only be applied to `#[const_trait]` traits --> $DIR/const-impl-trait.rs:17:20 | LL | -> impl ~const PartialEq + ~const Destruct | ^^^^^^^^^ -error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/const-impl-trait.rs:17:39 - | -LL | -> impl ~const PartialEq + ~const Destruct - | ^^^^^^^^ - error: ~const can only be applied to `#[const_trait]` traits --> $DIR/const-impl-trait.rs:24:29 | LL | fn huh() -> impl ~const PartialEq + ~const Destruct + Copy; | ^^^^^^^^^ -error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/const-impl-trait.rs:24:48 - | -LL | fn huh() -> impl ~const PartialEq + ~const Destruct + Copy; - | ^^^^^^^^ - error: ~const can only be applied to `#[const_trait]` traits --> $DIR/const-impl-trait.rs:28:29 | LL | fn huh() -> impl ~const PartialEq + ~const Destruct + Copy { | ^^^^^^^^^ -error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/const-impl-trait.rs:28:48 - | -LL | fn huh() -> impl ~const PartialEq + ~const Destruct + Copy { - | ^^^^^^^^ - -error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/const-impl-trait.rs:49:41 - | -LL | const fn apit(_: impl ~const T + ~const Destruct) {} - | ^^^^^^^^ - -error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/const-impl-trait.rs:53:73 - | -LL | const fn apit_assoc_bound(_: impl IntoIterator + ~const Destruct) {} - | ^^^^^^^^ - -error: aborting due to 12 previous errors +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0635`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-92111.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-92111.stderr index 90d3aee5202a3..b27f94f99ed74 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-92111.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-92111.stderr @@ -1,8 +1,11 @@ -error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/issue-92111.rs:20:22 +error[E0493]: destructor of `T` cannot be evaluated at compile-time + --> $DIR/issue-92111.rs:20:32 | LL | const fn a(t: T) {} - | ^^^^^^^^ + | ^ - value is dropped here + | | + | the destructor for this type cannot be evaluated in constant functions error: aborting due to previous error +For more information about this error, try `rustc --explain E0493`. From ab168b6ef3b276d06fdf0aac236b9881841815ed Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Fri, 22 Sep 2023 00:05:45 +0000 Subject: [PATCH 6/6] fix clippy errors (ignore effects in certainty) --- src/tools/clippy/clippy_utils/src/ty/type_certainty/mod.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/tools/clippy/clippy_utils/src/ty/type_certainty/mod.rs b/src/tools/clippy/clippy_utils/src/ty/type_certainty/mod.rs index dc7756533acb0..4b06b12fb94d0 100644 --- a/src/tools/clippy/clippy_utils/src/ty/type_certainty/mod.rs +++ b/src/tools/clippy/clippy_utils/src/ty/type_certainty/mod.rs @@ -207,7 +207,8 @@ fn path_segment_certainty( // Checking `res_generics_def_id(..)` before calling `generics_of` avoids an ICE. if cx.tcx.res_generics_def_id(path_segment.res).is_some() { let generics = cx.tcx.generics_of(def_id); - let lhs = if (parent_certainty.is_certain() || generics.parent_count == 0) && generics.params.is_empty() + let count = generics.params.len() - generics.host_effect_index.is_some() as usize; + let lhs = if (parent_certainty.is_certain() || generics.parent_count == 0) && count == 0 { Certainty::Certain(None) } else { @@ -299,7 +300,7 @@ fn type_is_inferrable_from_arguments(cx: &LateContext<'_>, expr: &Expr<'_>) -> b // Check that all type parameters appear in the functions input types. (0..(generics.parent_count + generics.params.len()) as u32).all(|index| { - fn_sig + Some(index as usize) == generics.host_effect_index || fn_sig .inputs() .iter() .any(|input_ty| contains_param(*input_ty.skip_binder(), index))