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 #89420

Closed
wants to merge 22 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d3f981b
Move is_const_fn to under TyCtxt
fee1-dead Sep 15, 2021
f8aa73d
Coerce const FnDefs to implement const Fn traits
fee1-dead Sep 15, 2021
d8e9db0
feat(rustc_parse): recover from pre-RFC-2000 const generics syntax
notriddle Sep 16, 2021
db8af3f
Add support for specifying multiple clobber_abi in `asm!`
asquared31415 Sep 28, 2021
42e9dfd
Reapply "Remove optimization_fuel_crate from Session"
bjorn3 Aug 30, 2021
8a7c130
Use less verbose syntax for error annotations
notriddle Sep 28, 2021
befdfb5
Improve error messages for bad type constraints
notriddle Sep 28, 2021
105b60f
feat(rustc_typeck): avoid erroring with "wrong number of generics" if…
notriddle Sep 28, 2021
6490ed3
Improve error message for `printf`-style format strings
FabianWolff Sep 28, 2021
4425fe4
More spans, don't duplicate clobbers
asquared31415 Sep 29, 2021
d90934c
Fix use after drop in self-profile with llvm events
andjo403 Sep 29, 2021
b159d95
Update docs
asquared31415 Sep 30, 2021
09f1542
Implemented -Z randomize-layout
Kixiron Aug 29, 2021
198d907
Add `pie` as another `relocation-model` value
hlopko Sep 10, 2021
11ab736
Rollup merge of #87868 - Kixiron:packing-on-the-pounds, r=eddyb
fee1-dead Oct 1, 2021
d8ffbaf
Rollup merge of #88820 - hlopko:add_pie_relocation_model, r=petrochenkov
fee1-dead Oct 1, 2021
a91818a
Rollup merge of #88963 - fee1-dead:const-iterator, r=oli-obk
fee1-dead Oct 1, 2021
13c8c32
Rollup merge of #89029 - notriddle:notriddle/issue-89013, r=estebank
fee1-dead Oct 1, 2021
1826030
Rollup merge of #89316 - asquared31415:multiple-clobber-abi, r=Amanieu
fee1-dead Oct 1, 2021
742ee9d
Rollup merge of #89322 - tmiasko:rm-optimization-fuel, r=michaelwoeri…
fee1-dead Oct 1, 2021
5a09551
Rollup merge of #89340 - FabianWolff:issue-89173, r=petrochenkov
fee1-dead Oct 1, 2021
01762f6
Rollup merge of #89376 - andjo403:selfProfileUseAfterDropFix, r=Mark-…
fee1-dead Oct 1, 2021
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
Prev Previous commit
Next Next commit
Coerce const FnDefs to implement const Fn traits
fee1-dead committed Sep 15, 2021

Verified

This commit was signed with the committer’s verified signature.
commit f8aa73d3dd951d69903e962054f2614b083c5b9c
3 changes: 1 addition & 2 deletions compiler/rustc_const_eval/src/transform/promote_consts.rs
Original file line number Diff line number Diff line change
@@ -655,8 +655,7 @@ impl<'tcx> Validator<'_, 'tcx> {

let is_const_fn = match *fn_ty.kind() {
ty::FnDef(def_id, _) => {
self.tcx.is_const_fn_raw(def_id)
|| is_lang_panic_fn(self.tcx, def_id)
self.tcx.is_const_fn_raw(def_id) || is_lang_panic_fn(self.tcx, def_id)
}
_ => false,
};
4 changes: 3 additions & 1 deletion compiler/rustc_middle/src/traits/select.rs
Original file line number Diff line number Diff line change
@@ -120,7 +120,9 @@ pub enum SelectionCandidate<'tcx> {

/// Implementation of a `Fn`-family trait by one of the anonymous
/// types generated for a fn pointer type (e.g., `fn(int) -> int`)
FnPointerCandidate,
FnPointerCandidate {
is_const: bool,
},

/// Builtin implementation of `DiscriminantKind`.
DiscriminantKindCandidate,
5 changes: 4 additions & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
@@ -2750,7 +2750,10 @@ impl<'tcx> TyCtxt<'tcx> {
Some(stability) if stability.level.is_unstable() => {
// has a `rustc_const_unstable` attribute, check whether the user enabled the
// corresponding feature gate.
self.features().declared_lib_features.iter().any(|&(sym, _)| sym == stability.feature)
self.features()
.declared_lib_features
.iter()
.any(|&(sym, _)| sym == stability.feature)
}
// functions without const stability are either stable user written
// const fn or the user is using feature gates and we thus don't
Original file line number Diff line number Diff line change
@@ -475,7 +475,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
..
} = self_ty.fn_sig(self.tcx()).skip_binder()
{
candidates.vec.push(FnPointerCandidate);
candidates.vec.push(FnPointerCandidate { is_const: false });
}
}
// Provide an impl for suitable functions, rejecting `#[target_feature]` functions (RFC 2396).
@@ -488,7 +488,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
} = self_ty.fn_sig(self.tcx()).skip_binder()
{
if self.tcx().codegen_fn_attrs(def_id).target_features.is_empty() {
candidates.vec.push(FnPointerCandidate);
candidates
.vec
.push(FnPointerCandidate { is_const: self.tcx().is_const_fn(def_id) });
}
}
}
Original file line number Diff line number Diff line change
@@ -92,7 +92,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
Ok(ImplSource::Generator(vtable_generator))
}

FnPointerCandidate => {
FnPointerCandidate { .. } => {
let data = self.confirm_fn_pointer_candidate(obligation)?;
Ok(ImplSource::FnPointer(data))
}
17 changes: 11 additions & 6 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
@@ -1100,6 +1100,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// generator, this will raise error in other places
// or ignore error with const_async_blocks feature
GeneratorCandidate => {}
// FnDef where the function is const
FnPointerCandidate { is_const: true } => {}
ConstDropCandidate => {}
_ => {
// reject all other types of candidates
@@ -1513,6 +1515,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
}

// Drop otherwise equivalent non-const fn pointer candidates
(FnPointerCandidate { .. }, FnPointerCandidate { is_const: false }) => true,

// Global bounds from the where clause should be ignored
// here (see issue #50825). Otherwise, we have a where
// clause so don't go around looking for impls.
@@ -1523,7 +1528,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ImplCandidate(..)
| ClosureCandidate
| GeneratorCandidate
| FnPointerCandidate
| FnPointerCandidate { .. }
| BuiltinObjectCandidate
| BuiltinUnsizeCandidate
| TraitUpcastingUnsizeCandidate(_)
@@ -1541,7 +1546,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ImplCandidate(_)
| ClosureCandidate
| GeneratorCandidate
| FnPointerCandidate
| FnPointerCandidate { .. }
| BuiltinObjectCandidate
| BuiltinUnsizeCandidate
| TraitUpcastingUnsizeCandidate(_)
@@ -1571,7 +1576,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ImplCandidate(..)
| ClosureCandidate
| GeneratorCandidate
| FnPointerCandidate
| FnPointerCandidate { .. }
| BuiltinObjectCandidate
| BuiltinUnsizeCandidate
| TraitUpcastingUnsizeCandidate(_)
@@ -1583,7 +1588,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ImplCandidate(..)
| ClosureCandidate
| GeneratorCandidate
| FnPointerCandidate
| FnPointerCandidate { .. }
| BuiltinObjectCandidate
| BuiltinUnsizeCandidate
| TraitUpcastingUnsizeCandidate(_)
@@ -1664,7 +1669,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ImplCandidate(_)
| ClosureCandidate
| GeneratorCandidate
| FnPointerCandidate
| FnPointerCandidate { .. }
| BuiltinObjectCandidate
| BuiltinUnsizeCandidate
| TraitUpcastingUnsizeCandidate(_)
@@ -1673,7 +1678,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ImplCandidate(_)
| ClosureCandidate
| GeneratorCandidate
| FnPointerCandidate
| FnPointerCandidate { .. }
| BuiltinObjectCandidate
| BuiltinUnsizeCandidate
| TraitUpcastingUnsizeCandidate(_)
31 changes: 31 additions & 0 deletions src/test/ui/rfc-2632-const-trait-impl/const-closures.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// run-pass

#![feature(const_trait_impl)]
#![feature(const_fn_trait_bound)]

const fn answer_p1<F>(f: &F) -> u8
where
F: ~const FnOnce() -> u8,
F: ~const FnMut() -> u8,
F: ~const Fn() -> u8,
{
f() * 7
}

const fn three() -> u8 {
3
}

const fn answer_p2() -> u8 {
answer_p1(&three)
}

const fn answer<F: ~const Fn() -> u8>(f: &F) -> u8 {
f() + f()
}

const ANSWER: u8 = answer(&answer_p2);

fn main() {
assert_eq!(ANSWER, 42)
}