Ban combination of GCE and new solver

This commit is contained in:
Michael Goulet 2024-09-24 10:53:19 -04:00
parent 11e760b7f4
commit ead569a06d
6 changed files with 63 additions and 11 deletions

View File

@ -4,9 +4,9 @@
use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP, BuiltinAttribute, Features, GateIssue}; use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP, BuiltinAttribute, Features, GateIssue};
use rustc_session::Session; use rustc_session::Session;
use rustc_session::parse::{feature_err, feature_err_issue, feature_warn}; use rustc_session::parse::{feature_err, feature_err_issue, feature_warn};
use rustc_span::Span;
use rustc_span::source_map::Spanned; use rustc_span::source_map::Spanned;
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
use rustc_span::{Span, Symbol};
use rustc_target::spec::abi; use rustc_target::spec::abi;
use thin_vec::ThinVec; use thin_vec::ThinVec;
@ -483,6 +483,8 @@ fn visit_assoc_item(&mut self, i: &'a ast::AssocItem, ctxt: AssocCtxt) {
pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) { pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
maybe_stage_features(sess, features, krate); maybe_stage_features(sess, features, krate);
check_incompatible_features(sess, features); check_incompatible_features(sess, features);
check_new_solver_banned_features(sess, features);
let mut visitor = PostExpansionVisitor { sess, features }; let mut visitor = PostExpansionVisitor { sess, features };
let spans = sess.psess.gated_spans.spans.borrow(); let spans = sess.psess.gated_spans.spans.borrow();
@ -662,3 +664,22 @@ fn check_incompatible_features(sess: &Session, features: &Features) {
} }
} }
} }
fn check_new_solver_banned_features(sess: &Session, features: &Features) {
if !sess.opts.unstable_opts.next_solver.is_some_and(|n| n.globally) {
return;
}
// Ban GCE with the new solver, because it does not implement GCE correctly.
if let Some(&(_, gce_span, _)) = features
.declared_lang_features
.iter()
.find(|&&(feat, _, _)| feat == sym::generic_const_exprs)
{
sess.dcx().emit_err(errors::IncompatibleFeatures {
spans: vec![gce_span],
f1: Symbol::intern("-Znext-solver=globally"),
f2: sym::generic_const_exprs,
});
}
}

View File

@ -1,3 +1,11 @@
error: `-Znext-solver=globally` and `generic_const_exprs` are incompatible, using them at the same time is not allowed
--> $DIR/unify-op-with-fn-call.rs:3:12
|
LL | #![feature(generic_const_exprs, adt_const_params, const_trait_impl, effects)]
| ^^^^^^^^^^^^^^^^^^^
|
= help: remove one of these features
error: const `impl` for trait `Add` which is not marked with `#[const_trait]` error: const `impl` for trait `Add` which is not marked with `#[const_trait]`
--> $DIR/unify-op-with-fn-call.rs:10:12 --> $DIR/unify-op-with-fn-call.rs:10:12
| |
@ -67,7 +75,7 @@ error[E0284]: type annotations needed: cannot normalize `foo2<N>::{constant#0}`
LL | bar2::<{ std::ops::Add::add(N, N) }>(); LL | bar2::<{ std::ops::Add::add(N, N) }>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot normalize `foo2<N>::{constant#0}` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot normalize `foo2<N>::{constant#0}`
error: aborting due to 8 previous errors error: aborting due to 9 previous errors
Some errors have detailed explanations: E0284, E0741. Some errors have detailed explanations: E0284, E0741.
For more information about an error, try `rustc --explain E0284`. For more information about an error, try `rustc --explain E0284`.

View File

@ -1,3 +1,11 @@
error: `-Znext-solver=globally` and `generic_const_exprs` are incompatible, using them at the same time is not allowed
--> $DIR/issue-88119.rs:4:39
|
LL | #![feature(const_trait_impl, effects, generic_const_exprs)]
| ^^^^^^^^^^^^^^^^^^^
|
= help: remove one of these features
error[E0284]: type annotations needed: cannot normalize `<&T as ConstName>::{constant#0}` error[E0284]: type annotations needed: cannot normalize `<&T as ConstName>::{constant#0}`
--> $DIR/issue-88119.rs:19:49 --> $DIR/issue-88119.rs:19:49
| |
@ -28,6 +36,6 @@ LL | where
LL | [(); name_len::<T>()]:, LL | [(); name_len::<T>()]:,
| --------------------- unsatisfied trait bound introduced here | --------------------- unsatisfied trait bound introduced here
error: aborting due to 2 previous errors error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0284`. For more information about this error, try `rustc --explain E0284`.

View File

@ -1,3 +1,11 @@
error: `-Znext-solver=globally` and `generic_const_exprs` are incompatible, using them at the same time is not allowed
--> $DIR/const-trait-bounds.rs:4:39
|
LL | #![feature(const_trait_impl, effects, generic_const_exprs)]
| ^^^^^^^^^^^^^^^^^^^
|
= help: remove one of these features
error[E0284]: type annotations needed: cannot normalize `process<T>::{constant#0}` error[E0284]: type annotations needed: cannot normalize `process<T>::{constant#0}`
--> $DIR/const-trait-bounds.rs:12:35 --> $DIR/const-trait-bounds.rs:12:35
| |
@ -16,6 +24,6 @@ error[E0284]: type annotations needed: cannot normalize `process<T>::{constant#1
LL | input LL | input
| ^^^^^ cannot normalize `process<T>::{constant#1}` | ^^^^^ cannot normalize `process<T>::{constant#1}`
error: aborting due to 3 previous errors error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0284`. For more information about this error, try `rustc --explain E0284`.

View File

@ -1,3 +1,4 @@
//@ known-bug: unknown
// Ensure that we print unsatisfied always-const trait bounds as `const Trait` in diagnostics. // Ensure that we print unsatisfied always-const trait bounds as `const Trait` in diagnostics.
//@ compile-flags: -Znext-solver //@ compile-flags: -Znext-solver
@ -19,7 +20,7 @@ fn make() -> u32 { 0 }
fn main() { fn main() {
// FIXME(effects): improve diagnostics on this // FIXME(effects): improve diagnostics on this
require::<Ty>(); //~ ERROR the trait bound `Trait::{synthetic#0}: const Compat` is not satisfied require::<Ty>();
} }
struct Container<const N: u32>; struct Container<const N: u32>;
@ -27,9 +28,7 @@ fn main() {
// FIXME(effects): Somehow emit `the trait bound `T: const Trait` is not satisfied` here instead // FIXME(effects): Somehow emit `the trait bound `T: const Trait` is not satisfied` here instead
// and suggest changing `Trait` to `const Trait`. // and suggest changing `Trait` to `const Trait`.
fn accept0<T: Trait>(_: Container<{ T::make() }>) {} fn accept0<T: Trait>(_: Container<{ T::make() }>) {}
//~^ ERROR mismatched types
// FIXME(effects): Instead of suggesting `+ const Trait`, suggest // FIXME(effects): Instead of suggesting `+ const Trait`, suggest
// changing `~const Trait` to `const Trait`. // changing `~const Trait` to `const Trait`.
const fn accept1<T: ~const Trait>(_: Container<{ T::make() }>) {} const fn accept1<T: ~const Trait>(_: Container<{ T::make() }>) {}
//~^ ERROR mismatched types

View File

@ -1,5 +1,13 @@
error: `-Znext-solver=globally` and `generic_const_exprs` are incompatible, using them at the same time is not allowed
--> $DIR/unsatisfied-const-trait-bound.rs:5:39
|
LL | #![feature(const_trait_impl, effects, generic_const_exprs)]
| ^^^^^^^^^^^^^^^^^^^
|
= help: remove one of these features
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/unsatisfied-const-trait-bound.rs:29:37 --> $DIR/unsatisfied-const-trait-bound.rs:30:37
| |
LL | fn accept0<T: Trait>(_: Container<{ T::make() }>) {} LL | fn accept0<T: Trait>(_: Container<{ T::make() }>) {}
| ^^^^^^^^^ expected `false`, found `true` | ^^^^^^^^^ expected `false`, found `true`
@ -17,18 +25,18 @@ LL | const fn accept1<T: ~const Trait>(_: Container<{ T::make() }>) {}
found constant `host` found constant `host`
error[E0277]: the trait bound `Trait::{synthetic#0}: const Compat` is not satisfied error[E0277]: the trait bound `Trait::{synthetic#0}: const Compat` is not satisfied
--> $DIR/unsatisfied-const-trait-bound.rs:22:15 --> $DIR/unsatisfied-const-trait-bound.rs:23:15
| |
LL | require::<Ty>(); LL | require::<Ty>();
| ^^ the trait `const Compat` is not implemented for `Trait::{synthetic#0}` | ^^ the trait `const Compat` is not implemented for `Trait::{synthetic#0}`
| |
note: required by a bound in `require` note: required by a bound in `require`
--> $DIR/unsatisfied-const-trait-bound.rs:7:15 --> $DIR/unsatisfied-const-trait-bound.rs:8:15
| |
LL | fn require<T: const Trait>() {} LL | fn require<T: const Trait>() {}
| ^^^^^^^^^^^ required by this bound in `require` | ^^^^^^^^^^^ required by this bound in `require`
error: aborting due to 3 previous errors error: aborting due to 4 previous errors
Some errors have detailed explanations: E0277, E0308. Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`. For more information about an error, try `rustc --explain E0277`.