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

make Fn* traits const_trait again #116058

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions compiler/rustc_hir_typeck/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
tcx.consts.false_
}
Some(hir::ConstContext::ConstFn) => {
let args = ty::GenericArgs::identity_for_item(tcx, context);
args.host_effect_param().expect("ConstContext::Maybe must have host effect param")
ty::GenericArgs::identity_for_item(tcx, callee_did).const_at(host_effect_index)
}
None => tcx.consts.true_,
};
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_middle/src/ty/generic_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
use rustc_hir::def_id::DefId;
use rustc_macros::HashStable;
use rustc_serialize::{self, Decodable, Encodable};
use rustc_span::sym;
use rustc_type_ir::WithCachedTypeInfo;
use smallvec::SmallVec;

Expand Down Expand Up @@ -452,10 +451,6 @@ impl<'tcx> GenericArgs<'tcx> {
tcx.mk_args_from_iter(self.iter().take(generics.count()))
}

pub fn host_effect_param(&'tcx self) -> Option<ty::Const<'tcx>> {
self.consts().rfind(|x| matches!(x.kind(), ty::ConstKind::Param(p) if p.name == sym::host))
}

pub fn print_as_list(&self) -> String {
let v = self.iter().map(|arg| arg.to_string()).collect::<Vec<_>>();
format!("[{}]", v.join(", "))
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_middle/src/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ impl<'tcx> Instance<'tcx> {
!args.has_escaping_bound_vars(),
"args of instance {def_id:?} not normalized for codegen: {args:?}"
);
if cfg!(debug_assertions) {
super::tls::with(|tcx| {
assert_eq!(tcx.generics_of(def_id).count(), args.len());
});
}
Instance { def: InstanceDef::Item(def_id), args }
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ fn build_call_shim<'tcx>(
// Create substitutions for the `Self` and `Args` generic parameters of the shim body.
let arg_tup = Ty::new_tup(tcx, untuple_args);

(Some([ty.into(), arg_tup.into()]), Some(untuple_args))
(Some([ty.into(), arg_tup.into(), tcx.consts.true_.into()]), Some(untuple_args))
} else {
(None, None)
};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/traits/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ pub fn closure_trait_ref_and_return_type<'tcx>(
TupleArgumentsFlag::No => sig.skip_binder().inputs()[0],
TupleArgumentsFlag::Yes => Ty::new_tup(tcx, sig.skip_binder().inputs()),
};
let trait_ref = ty::TraitRef::new(tcx, fn_trait_def_id, [self_ty, arguments_tuple]);
let trait_ref = ty::TraitRef::new(tcx, fn_trait_def_id, [ty::GenericArg::from(self_ty), arguments_tuple.into(), tcx.consts.true_.into()]);
sig.map_bound(|sig| (trait_ref, sig.output()))
}

Expand Down
10 changes: 5 additions & 5 deletions library/core/src/ops/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ use crate::marker::Tuple;
)]
#[fundamental] // so that regex can rely that `&str: !FnMut`
#[must_use = "closures are lazy and do nothing unless called"]
// FIXME(effects) #[const_trait]
pub trait Fn<Args: Tuple>: FnMut<Args> {
#[const_trait]
pub trait Fn<Args: Tuple>: ~const FnMut<Args> {
/// Performs the call operation.
#[unstable(feature = "fn_traits", issue = "29625")]
extern "rust-call" fn call(&self, args: Args) -> Self::Output;
Expand Down Expand Up @@ -159,8 +159,8 @@ pub trait Fn<Args: Tuple>: FnMut<Args> {
)]
#[fundamental] // so that regex can rely that `&str: !FnMut`
#[must_use = "closures are lazy and do nothing unless called"]
// FIXME(effects) #[const_trait]
pub trait FnMut<Args: Tuple>: FnOnce<Args> {
#[const_trait]
pub trait FnMut<Args: Tuple>: ~const FnOnce<Args> {
/// Performs the call operation.
#[unstable(feature = "fn_traits", issue = "29625")]
extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
Expand Down Expand Up @@ -238,7 +238,7 @@ pub trait FnMut<Args: Tuple>: FnOnce<Args> {
)]
#[fundamental] // so that regex can rely that `&str: !FnMut`
#[must_use = "closures are lazy and do nothing unless called"]
// FIXME(effects) #[const_trait]
#[const_trait]
pub trait FnOnce<Args: Tuple> {
/// The returned type after the call operator is used.
#[lang = "fn_once_output"]
Expand Down
2 changes: 1 addition & 1 deletion tests/rustdoc/rfc-2632-const-trait-impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// not remove this test.
//
// FIXME(effects) add `const_trait` to `Fn` so we use `~const`
#![feature(const_trait_impl)]
#![feature(const_trait_impl, effects)]
#![crate_name = "foo"]

use std::marker::Destruct;
Expand Down