Skip to content

Commit 526c36b

Browse files
committed
Auto merge of #160619 - Kivooeo:enable-next-solver, r=lcnr,jdonszelmann,kobzol
Enable `-Znext-solver` on nightly by default Implementation of rust-lang/compiler-team#1014 cc rust-lang/blog.rust-lang.org#1896 #160895 This enables `-Znext-solver=globally` by default in nightly, but keeps `-Znext-solver=coherence` for most tests.
2 parents 16a623a + 72c9724 commit 526c36b

16 files changed

Lines changed: 131 additions & 31 deletions

File tree

compiler/rustc_ast_passes/src/diagnostics.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ pub(crate) struct ImplFnConst {
3838
pub parent_constness: Span,
3939
}
4040

41+
#[derive(Diagnostic)]
42+
#[diag("`feature(generic_const_exprs)` is not supported with the next-generation trait solver")]
43+
#[note("`-Znext-solver=globally` is currently enabled by default for testing")]
44+
#[note("reverted the setting to `-Znext-solver=coherence` for this crate")]
45+
#[note("the currently stable trait solver will be used for this crate")]
46+
#[note("see issues #160895 <https://github.com/rust-lang/rust/issues/160895> for more information")]
47+
pub(crate) struct NextSolverDisabledForGenericConstExprs {
48+
#[primary_span]
49+
pub span: Span,
50+
}
51+
4152
#[derive(Diagnostic)]
4253
#[diag("functions in {$in_impl ->
4354
[true] trait impls

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_errors::msg;
66
use rustc_feature::Features;
77
use rustc_session::Session;
88
use rustc_session::diagnostics::{feature_err, feature_warn};
9-
use rustc_span::{Span, Spanned, Symbol, sym};
9+
use rustc_span::{Span, Spanned, sym};
1010

1111
use crate::diagnostics;
1212

@@ -436,7 +436,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
436436
maybe_stage_features(sess, features, krate);
437437
check_incompatible_features(sess, features);
438438
check_dependent_features(sess, features);
439-
check_new_solver_banned_features(sess, features);
439+
warn_next_solver_and_gce(sess, features);
440440
check_features_requiring_new_solver(sess, features);
441441

442442
let mut visitor = PostExpansionVisitor { sess, features };
@@ -722,26 +722,21 @@ fn check_dependent_features(sess: &Session, features: &Features) {
722722
}
723723
}
724724

725-
fn check_new_solver_banned_features(sess: &Session, features: &Features) {
725+
fn warn_next_solver_and_gce(sess: &Session, features: &Features) {
726726
if !sess.opts.unstable_opts.next_solver.globally {
727727
return;
728728
}
729729

730-
// Ban GCE with the new solver, because it does not implement GCE correctly.
730+
// Warn people who uses GCE and -Znext-solver=globally
731+
// that their trait solver was downgraded to -Znext-solver=no
731732
if let Some(gce_span) = features
732733
.enabled_lang_features()
733734
.iter()
734735
.find(|feat| feat.gate_name == sym::generic_const_exprs)
735736
.map(|feat| feat.attr_sp)
736737
{
737-
// Abort immediately, otherwise GCE can lower to `ConstKind::Expr`,
738-
// which the new solver intentionally does not support.
739-
#[allow(rustc::symbol_intern_string_literal)]
740-
sess.dcx().emit_fatal(diagnostics::IncompatibleFeatures {
741-
spans: vec![gce_span],
742-
f1: Symbol::intern("-Znext-solver=globally"),
743-
f2: sym::generic_const_exprs,
744-
});
738+
sess.dcx()
739+
.emit_warn(diagnostics::NextSolverDisabledForGenericConstExprs { span: gce_span });
745740
}
746741
}
747742

compiler/rustc_interface/src/tests.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,13 @@ fn test_unstable_options_tracking_hash() {
852852
tracked!(mir_opt_level, Some(4));
853853
tracked!(mir_preserve_ub, true);
854854
tracked!(move_size_limit, Some(4096));
855-
tracked!(next_solver, NextSolverConfig { coherence: true, globally: true });
855+
856+
// tidy-alphabetical-end
857+
// FIXME(#160895): We don't test this when the next-solver is enabled by default.
858+
if option_env!("CFG_DEFAULT_NEXT_SOLVER_GLOBALLY").is_none() {
859+
tracked!(next_solver, NextSolverConfig { coherence: true, globally: true });
860+
}
861+
// tidy-alphabetical-start
856862
tracked!(no_generate_arange_section, true);
857863
tracked!(no_link, true);
858864
tracked!(no_profiler_runtime, true);

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2689,7 +2689,7 @@ impl<'tcx> TyCtxt<'tcx> {
26892689
}
26902690

26912691
pub fn next_trait_solver_globally(self) -> bool {
2692-
self.sess.opts.unstable_opts.next_solver.globally
2692+
self.sess.opts.unstable_opts.next_solver.globally && !self.features().generic_const_exprs()
26932693
}
26942694

26952695
pub fn next_trait_solver_in_coherence(self) -> bool {

compiler/rustc_session/src/config.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ impl ExternEntry {
10191019
}
10201020
}
10211021

1022-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Default)]
1022+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
10231023
pub struct NextSolverConfig {
10241024
/// Whether the new trait solver should be enabled in coherence.
10251025
pub coherence: bool = true,
@@ -1028,6 +1028,18 @@ pub struct NextSolverConfig {
10281028
pub globally: bool = false,
10291029
}
10301030

1031+
// FIXME(#160895): Using -Znext-solver as default on nightly
1032+
// See https://github.com/rust-lang/compiler-team/issues/1014
1033+
impl Default for NextSolverConfig {
1034+
fn default() -> Self {
1035+
if option_env!("CFG_DEFAULT_NEXT_SOLVER_GLOBALLY").is_some() {
1036+
Self { coherence: true, globally: true }
1037+
} else {
1038+
Self { coherence: true, globally: false }
1039+
}
1040+
}
1041+
}
1042+
10311043
#[derive(Clone)]
10321044
pub enum Input {
10331045
/// Load source code from a file.

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1374,8 +1374,9 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS
13741374

13751375
let nightly = builder.config.channel == "nightly" || builder.config.channel == "dev";
13761376
if nightly {
1377-
// We want to enable Polonius Alpha by default on nighty
1377+
// We want to enable Polonius Alpha and Next Trait Solver by default on nighty
13781378
cargo.env("CFG_DEFAULT_POLONIUS_NEXT", "1");
1379+
cargo.env("CFG_DEFAULT_NEXT_SOLVER_GLOBALLY", "1");
13791380
}
13801381

13811382
// These conditionals represent a tension between three forces:

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3288,6 +3288,9 @@ fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) ->
32883288
builder.do_if_verbose(|| println!("doc tests for: {}", markdown.display()));
32893289
let mut cmd = builder.rustdoc_cmd(compiler);
32903290
builder.add_rust_test_threads(&mut cmd);
3291+
// FIXME(#160895): While the new solver is enabled by default on nightly,
3292+
// we don't want to use it in our tests for now.
3293+
cmd.arg("-Znext-solver=coherence");
32913294
// allow for unstable options such as new editions
32923295
cmd.arg("-Z");
32933296
cmd.arg("unstable-options");
@@ -3360,7 +3363,7 @@ impl CommandLineStep for CrateLibrustc {
33603363
///
33613364
/// Returns whether the test succeeded.
33623365
fn run_cargo_test<'a>(
3363-
cargo: builder::Cargo,
3366+
mut cargo: builder::Cargo,
33643367
libtest_args: &[&str],
33653368
crates: &[String],
33663369
description: impl Into<Option<&'a str>>,
@@ -3374,6 +3377,10 @@ fn run_cargo_test<'a>(
33743377
_ => compiler.stage + 1,
33753378
};
33763379

3380+
// FIXME(#160895): While the new solver is enabled by default on nightly,
3381+
// we don't want to use it in our tests for now.
3382+
cargo.rustdocflag("-Znext-solver=coherence");
3383+
33773384
let mut cargo = prepare_cargo_test(cargo, libtest_args, crates, target, builder);
33783385
let _time = helpers::timeit(builder);
33793386

src/tools/clippy/tests/compile-test.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ impl TestContext {
228228
"-Ainternal_features",
229229
"-Zui-testing",
230230
"-Zdeduplicate-diagnostics=no",
231+
// FIXME(#160895): While the new solver is enabled by default on nightly,
232+
// we don't want to use it in our tests for now.
233+
"-Znext-solver=coherence",
231234
"-Dwarnings",
232235
]
233236
.map(OsString::from),
@@ -334,7 +337,9 @@ fn run_ui_cargo(cx: &TestContext) {
334337
config.program.out_dir_flag = CommandBuilder::cargo().out_dir_flag;
335338
config.program.args = vec!["clippy".into(), "--color".into(), "never".into(), "--quiet".into()];
336339
config.program.envs.extend([
337-
("RUSTFLAGS".into(), Some("-Dwarnings".into())),
340+
// FIXME(#160895): While the new solver is enabled by default on nightly,
341+
// we don't want to use it in our tests for now.
342+
("RUSTFLAGS".into(), Some("-Dwarnings -Znext-solver=coherence".into())),
338343
("CARGO_INCREMENTAL".into(), Some("0".into())),
339344
]);
340345
// We need to do this while we still have a rustc in the `program` field.

src/tools/compiletest/src/runtest.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,9 @@ impl<'test> TestCx<'test> {
10401040
.arg(file_to_doc)
10411041
.arg("-A")
10421042
.arg("internal_features")
1043+
// FIXME(#160895): While the new solver is enabled by default on nightly,
1044+
// we don't want to use it in our tests for now.
1045+
.arg("-Znext-solver=coherence")
10431046
.args(&self.props.compile_flags)
10441047
.args(&self.props.doc_flags);
10451048

@@ -1880,6 +1883,10 @@ impl<'test> TestCx<'test> {
18801883
},
18811884
}
18821885

1886+
// FIXME(#160895): While the new solver is enabled by default on nightly,
1887+
// we don't want to use it in our tests for now.
1888+
compiler.args(["-Znext-solver=coherence"]);
1889+
18831890
match self.config.compare_mode {
18841891
Some(CompareMode::Polonius) => {
18851892
compiler.args(&["-Zpolonius=next"]);

src/tools/lint-docs/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,9 @@ impl<'a> LintExtractor<'a> {
473473
cmd.arg(format!("--edition={edition}"));
474474
// Just in case this is an unstable edition.
475475
cmd.arg("-Zunstable-options");
476+
// FIXME(#160895): While the new solver is enabled by default on nightly,
477+
// we don't want to use it in our tests for now.
478+
cmd.arg("-Znext-solver=coherence");
476479
cmd.arg("--error-format=json");
477480
cmd.arg("--target").arg(self.rustc_target);
478481
if let Some(target_linker) = self.rustc_linker {

0 commit comments

Comments
 (0)