Skip to content

Commit

Permalink
don't let const_fn feature flag affect impl-block-level trait bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Apr 29, 2021
1 parent ada1024 commit 9a85277
Show file tree
Hide file tree
Showing 11 changed files with 9 additions and 21 deletions.
13 changes: 2 additions & 11 deletions compiler/rustc_mir/src/transform/check_consts/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ impl Validator<'mir, 'tcx> {
ty::PredicateKind::Subtype(_) => {
bug!("subtype predicate on function: {:#?}", predicate)
}
ty::PredicateKind::Trait(pred, constness) => {
ty::PredicateKind::Trait(pred, _constness) => {
if Some(pred.def_id()) == tcx.lang_items().sized_trait() {
continue;
}
Expand All @@ -440,16 +440,7 @@ impl Validator<'mir, 'tcx> {
// arguments when determining importance.
let kind = LocalKind::Arg;

if constness == hir::Constness::Const {
self.check_op_spanned(ops::ty::TraitBound(kind), span);
} else if !tcx.features().const_fn
|| self.ccx.is_const_stable_const_fn()
{
// HACK: We shouldn't need the conditional above, but trait
// bounds on containing impl blocks are wrongly being marked as
// "not-const".
self.check_op_spanned(ops::ty::TraitBound(kind), span);
}
self.check_op_spanned(ops::ty::TraitBound(kind), span);
}
// other kinds of bounds are either tautologies
// or cause errors in other passes
Expand Down
3 changes: 2 additions & 1 deletion library/proc_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
#![feature(rustc_allow_const_fn_unstable)]
#![feature(nll)]
#![feature(staged_api)]
#![feature(const_fn)]
#![cfg_attr(bootstrap, feature(const_fn))]
#![cfg_attr(not(bootstrap), feature(const_fn_trait_bound))]
#![feature(const_fn_fn_ptr_basics)]
#![feature(allow_internal_unstable)]
#![feature(decl_macro)]
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/rfc-2632-const-trait-impl/assoc-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#![allow(incomplete_features)]
#![feature(const_trait_impl)]
#![feature(const_fn)]

struct NonConstAdd(i32);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![allow(incomplete_features)]
#![feature(const_trait_impl)]
#![feature(const_fn)]

pub trait Plus {
fn plus(self, rhs: Self) -> Self;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
--> $DIR/call-const-trait-method-fail.rs:26:5
--> $DIR/call-const-trait-method-fail.rs:25:5
|
LL | a.plus(b)
| ^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#![allow(incomplete_features)]
#![feature(const_trait_impl)]
#![feature(const_fn)]

struct Int(i32);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(const_fn)]
#![feature(const_fn_trait_bound)]
#![feature(const_trait_impl)]
#![feature(const_trait_bound_opt_out)]
#![allow(incomplete_features)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// check-pass

#![feature(const_fn)]
#![feature(const_fn_trait_bound)]
#![feature(const_trait_impl)]
#![feature(const_trait_bound_opt_out)]
#![allow(incomplete_features)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// FIXME(jschievink): this is not rejected correctly (only when the non-const impl is actually used)
// ignore-test

#![feature(const_fn)]
#![feature(const_trait_impl)]
#![allow(incomplete_features)]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![cfg_attr(gated, feature(const_trait_bound_opt_out))]
#![allow(incomplete_features)]
#![feature(rustc_attrs)]
#![feature(const_fn)]
#![feature(const_fn_trait_bound)]

trait T {
const CONST: i32;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/rfc-2632-const-trait-impl/hir-const-check.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Regression test for #69615.

#![feature(const_trait_impl, const_fn)]
#![feature(const_trait_impl)]
#![allow(incomplete_features)]

pub trait MyTrait {
Expand Down

0 comments on commit 9a85277

Please sign in to comment.