Skip to content

Commit f010879

Browse files
committed
Auto merge of rust-lang#135161 - matthiaskrgr:rollup-esq741u, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#134742 (Use `PostBorrowckAnalysis` in `check_coroutine_obligations`) - rust-lang#134951 (Suppress host effect predicates if underlying trait doesn't hold) - rust-lang#135097 (bootstrap: Consolidate coverage test suite steps into a single step) - rust-lang#135146 (Don't enable anyhow's `backtrace` feature in opt-dist) - rust-lang#135157 (Move the has_errors check in rustdoc back to after TyCtxt is created) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 243d2ca + 09d0472 commit f010879

File tree

11 files changed

+224
-155
lines changed

11 files changed

+224
-155
lines changed

Cargo.lock

-3
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,6 @@ name = "anyhow"
185185
version = "1.0.95"
186186
source = "registry+https://github.com/rust-lang/crates.io-index"
187187
checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04"
188-
dependencies = [
189-
"backtrace",
190-
]
191188

192189
[[package]]
193190
name = "ar_archive_writer"

compiler/rustc_hir_analysis/src/check/check.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -1845,13 +1845,18 @@ pub(super) fn check_coroutine_obligations(
18451845

18461846
debug!(?typeck_results.coroutine_stalled_predicates);
18471847

1848+
let mode = if tcx.next_trait_solver_globally() {
1849+
TypingMode::post_borrowck_analysis(tcx, def_id)
1850+
} else {
1851+
TypingMode::analysis_in_body(tcx, def_id)
1852+
};
1853+
18481854
let infcx = tcx
18491855
.infer_ctxt()
18501856
// typeck writeback gives us predicates with their regions erased.
18511857
// As borrowck already has checked lifetimes, we do not need to do it again.
18521858
.ignoring_regions()
1853-
// FIXME(#132279): This should eventually use the already defined hidden types.
1854-
.build(TypingMode::analysis_in_body(tcx, def_id));
1859+
.build(mode);
18551860

18561861
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
18571862
for (predicate, cause) in &typeck_results.coroutine_stalled_predicates {
@@ -1864,12 +1869,14 @@ pub(super) fn check_coroutine_obligations(
18641869
return Err(infcx.err_ctxt().report_fulfillment_errors(errors));
18651870
}
18661871

1867-
// Check that any hidden types found when checking these stalled coroutine obligations
1868-
// are valid.
1869-
for (key, ty) in infcx.take_opaque_types() {
1870-
let hidden_type = infcx.resolve_vars_if_possible(ty.hidden_type);
1871-
let key = infcx.resolve_vars_if_possible(key);
1872-
sanity_check_found_hidden_type(tcx, key, hidden_type)?;
1872+
if !tcx.next_trait_solver_globally() {
1873+
// Check that any hidden types found when checking these stalled coroutine obligations
1874+
// are valid.
1875+
for (key, ty) in infcx.take_opaque_types() {
1876+
let hidden_type = infcx.resolve_vars_if_possible(ty.hidden_type);
1877+
let key = infcx.resolve_vars_if_possible(key);
1878+
sanity_check_found_hidden_type(tcx, key, hidden_type)?;
1879+
}
18731880
}
18741881

18751882
Ok(())

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

+38-19
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
114114
//
115115
// We rely on a few heuristics to identify cases where this root
116116
// obligation is more important than the leaf obligation:
117-
let (main_trait_predicate, o) = if let ty::PredicateKind::Clause(
117+
let (main_trait_predicate, main_obligation) = if let ty::PredicateKind::Clause(
118118
ty::ClauseKind::Trait(root_pred)
119119
) = root_obligation.predicate.kind().skip_binder()
120120
&& !leaf_trait_predicate.self_ty().skip_binder().has_escaping_bound_vars()
@@ -199,7 +199,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
199199
notes,
200200
parent_label,
201201
append_const_msg,
202-
} = self.on_unimplemented_note(main_trait_predicate, o, &mut long_ty_file);
202+
} = self.on_unimplemented_note(main_trait_predicate, main_obligation, &mut long_ty_file);
203203

204204
let have_alt_message = message.is_some() || label.is_some();
205205
let is_try_conversion = self.is_try_conversion(span, main_trait_ref.def_id());
@@ -538,23 +538,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
538538
}
539539

540540
ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(predicate)) => {
541-
// FIXME(const_trait_impl): We should recompute the predicate with `~const`
542-
// if it's `const`, and if it holds, explain that this bound only
543-
// *conditionally* holds. If that fails, we should also do selection
544-
// to drill this down to an impl or built-in source, so we can
545-
// point at it and explain that while the trait *is* implemented,
546-
// that implementation is not const.
547-
let err_msg = self.get_standard_error_message(
548-
bound_predicate.rebind(ty::TraitPredicate {
549-
trait_ref: predicate.trait_ref,
550-
polarity: ty::PredicatePolarity::Positive,
551-
}),
552-
None,
553-
Some(predicate.constness),
554-
None,
555-
String::new(),
556-
);
557-
struct_span_code_err!(self.dcx(), span, E0277, "{}", err_msg)
541+
self.report_host_effect_error(bound_predicate.rebind(predicate), obligation.param_env, span)
558542
}
559543

560544
ty::PredicateKind::Subtype(predicate) => {
@@ -763,6 +747,41 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
763747
applied_do_not_recommend
764748
}
765749

750+
fn report_host_effect_error(
751+
&self,
752+
predicate: ty::Binder<'tcx, ty::HostEffectPredicate<'tcx>>,
753+
param_env: ty::ParamEnv<'tcx>,
754+
span: Span,
755+
) -> Diag<'a> {
756+
// FIXME(const_trait_impl): We should recompute the predicate with `~const`
757+
// if it's `const`, and if it holds, explain that this bound only
758+
// *conditionally* holds. If that fails, we should also do selection
759+
// to drill this down to an impl or built-in source, so we can
760+
// point at it and explain that while the trait *is* implemented,
761+
// that implementation is not const.
762+
let trait_ref = predicate.map_bound(|predicate| ty::TraitPredicate {
763+
trait_ref: predicate.trait_ref,
764+
polarity: ty::PredicatePolarity::Positive,
765+
});
766+
let err_msg = self.get_standard_error_message(
767+
trait_ref,
768+
None,
769+
Some(predicate.constness()),
770+
None,
771+
String::new(),
772+
);
773+
let mut diag = struct_span_code_err!(self.dcx(), span, E0277, "{}", err_msg);
774+
if !self.predicate_may_hold(&Obligation::new(
775+
self.tcx,
776+
ObligationCause::dummy(),
777+
param_env,
778+
trait_ref,
779+
)) {
780+
diag.downgrade_to_delayed_bug();
781+
}
782+
diag
783+
}
784+
766785
fn emit_specialized_closure_kind_error(
767786
&self,
768787
obligation: &PredicateObligation<'tcx>,

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

+68-118
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::utils::helpers::{
2727
linker_args, linker_flags, t, target_supports_cranelift_backend, up_to_date,
2828
};
2929
use crate::utils::render_tests::{add_flags_and_try_run_tests, try_run_tests};
30-
use crate::{CLang, DocTests, GitRepo, Mode, envify};
30+
use crate::{CLang, DocTests, GitRepo, Mode, PathSet, envify};
3131

3232
const ADB_TEST_DIR: &str = "/data/local/tmp/work";
3333

@@ -1185,53 +1185,6 @@ macro_rules! test {
11851185
};
11861186
}
11871187

1188-
/// Declares an alias for running the [`Coverage`] tests in only one mode.
1189-
/// Adapted from [`test`].
1190-
macro_rules! coverage_test_alias {
1191-
(
1192-
$( #[$attr:meta] )* // allow docstrings and attributes
1193-
$name:ident {
1194-
alias_and_mode: $alias_and_mode:expr, // &'static str
1195-
default: $default:expr, // bool
1196-
only_hosts: $only_hosts:expr // bool
1197-
$( , )? // optional trailing comma
1198-
}
1199-
) => {
1200-
$( #[$attr] )*
1201-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1202-
pub struct $name {
1203-
pub compiler: Compiler,
1204-
pub target: TargetSelection,
1205-
}
1206-
1207-
impl $name {
1208-
const MODE: &'static str = $alias_and_mode;
1209-
}
1210-
1211-
impl Step for $name {
1212-
type Output = ();
1213-
const DEFAULT: bool = $default;
1214-
const ONLY_HOSTS: bool = $only_hosts;
1215-
1216-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1217-
// Register the mode name as a command-line alias.
1218-
// This allows `x test coverage-map` and `x test coverage-run`.
1219-
run.alias($alias_and_mode)
1220-
}
1221-
1222-
fn make_run(run: RunConfig<'_>) {
1223-
let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
1224-
1225-
run.builder.ensure($name { compiler, target: run.target });
1226-
}
1227-
1228-
fn run(self, builder: &Builder<'_>) {
1229-
Coverage::run_coverage_tests(builder, self.compiler, self.target, Self::MODE);
1230-
}
1231-
}
1232-
};
1233-
}
1234-
12351188
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
12361189
pub struct RunMakeSupport {
12371190
pub compiler: Compiler,
@@ -1473,99 +1426,96 @@ impl Step for RunMake {
14731426

14741427
test!(Assembly { path: "tests/assembly", mode: "assembly", suite: "assembly", default: true });
14751428

1476-
/// Coverage tests are a bit more complicated than other test suites, because
1477-
/// we want to run the same set of test files in multiple different modes,
1478-
/// in a way that's convenient and flexible when invoked manually.
1479-
///
1480-
/// This combined step runs the specified tests (or all of `tests/coverage`)
1481-
/// in both "coverage-map" and "coverage-run" modes.
1482-
///
1483-
/// Used by:
1484-
/// - `x test coverage`
1485-
/// - `x test tests/coverage`
1486-
/// - `x test tests/coverage/trivial.rs` (etc)
1487-
///
1488-
/// (Each individual mode also has its own step that will run the tests in
1489-
/// just that mode.)
1490-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1429+
/// Runs the coverage test suite at `tests/coverage` in some or all of the
1430+
/// coverage test modes.
1431+
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
14911432
pub struct Coverage {
14921433
pub compiler: Compiler,
14931434
pub target: TargetSelection,
1435+
pub mode: &'static str,
14941436
}
14951437

14961438
impl Coverage {
14971439
const PATH: &'static str = "tests/coverage";
14981440
const SUITE: &'static str = "coverage";
1499-
1500-
/// Runs the coverage test suite (or a user-specified subset) in one mode.
1501-
///
1502-
/// This same function is used by the multi-mode step ([`Coverage`]) and by
1503-
/// the single-mode steps ([`CoverageMap`] and [`CoverageRun`]), to help
1504-
/// ensure that they all behave consistently with each other, regardless of
1505-
/// how the coverage tests have been invoked.
1506-
fn run_coverage_tests(
1507-
builder: &Builder<'_>,
1508-
compiler: Compiler,
1509-
target: TargetSelection,
1510-
mode: &'static str,
1511-
) {
1512-
// Like many other test steps, we delegate to a `Compiletest` step to
1513-
// actually run the tests. (See `test_definitions!`.)
1514-
builder.ensure(Compiletest {
1515-
compiler,
1516-
target,
1517-
mode,
1518-
suite: Self::SUITE,
1519-
path: Self::PATH,
1520-
compare_mode: None,
1521-
});
1522-
}
1441+
const ALL_MODES: &[&str] = &["coverage-map", "coverage-run"];
15231442
}
15241443

15251444
impl Step for Coverage {
15261445
type Output = ();
1527-
/// We rely on the individual CoverageMap/CoverageRun steps to run themselves.
1528-
const DEFAULT: bool = false;
1529-
/// When manually invoked, try to run as much as possible.
1446+
const DEFAULT: bool = true;
15301447
/// Compiletest will automatically skip the "coverage-run" tests if necessary.
15311448
const ONLY_HOSTS: bool = false;
15321449

1533-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1534-
// Take responsibility for command-line paths within `tests/coverage`.
1535-
run.suite_path(Self::PATH)
1450+
fn should_run(mut run: ShouldRun<'_>) -> ShouldRun<'_> {
1451+
// Support various invocation styles, including:
1452+
// - `./x test coverage`
1453+
// - `./x test tests/coverage/trivial.rs`
1454+
// - `./x test coverage-map`
1455+
// - `./x test coverage-run -- tests/coverage/trivial.rs`
1456+
run = run.suite_path(Self::PATH);
1457+
for mode in Self::ALL_MODES {
1458+
run = run.alias(mode);
1459+
}
1460+
run
15361461
}
15371462

15381463
fn make_run(run: RunConfig<'_>) {
15391464
let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
1465+
let target = run.target;
1466+
1467+
// List of (coverage) test modes that the coverage test suite will be
1468+
// run in. It's OK for this to contain duplicates, because the call to
1469+
// `Builder::ensure` below will take care of deduplication.
1470+
let mut modes = vec![];
1471+
1472+
// From the pathsets that were selected on the command-line (or by default),
1473+
// determine which modes to run in.
1474+
for path in &run.paths {
1475+
match path {
1476+
PathSet::Set(_) => {
1477+
for mode in Self::ALL_MODES {
1478+
if path.assert_single_path().path == Path::new(mode) {
1479+
modes.push(mode);
1480+
break;
1481+
}
1482+
}
1483+
}
1484+
PathSet::Suite(_) => {
1485+
modes.extend(Self::ALL_MODES);
1486+
break;
1487+
}
1488+
}
1489+
}
1490+
1491+
// Skip any modes that were explicitly skipped/excluded on the command-line.
1492+
// FIXME(Zalathar): Integrate this into central skip handling somehow?
1493+
modes.retain(|mode| !run.builder.config.skip.iter().any(|skip| skip == Path::new(mode)));
1494+
1495+
// FIXME(Zalathar): Make these commands skip all coverage tests, as expected:
1496+
// - `./x test --skip=tests`
1497+
// - `./x test --skip=tests/coverage`
1498+
// - `./x test --skip=coverage`
1499+
// Skip handling currently doesn't have a way to know that skipping the coverage
1500+
// suite should also skip the `coverage-map` and `coverage-run` aliases.
15401501

1541-
run.builder.ensure(Coverage { compiler, target: run.target });
1502+
for mode in modes {
1503+
run.builder.ensure(Coverage { compiler, target, mode });
1504+
}
15421505
}
15431506

15441507
fn run(self, builder: &Builder<'_>) {
1545-
// Run the specified coverage tests (possibly all of them) in both modes.
1546-
Self::run_coverage_tests(builder, self.compiler, self.target, CoverageMap::MODE);
1547-
Self::run_coverage_tests(builder, self.compiler, self.target, CoverageRun::MODE);
1548-
}
1549-
}
1550-
1551-
coverage_test_alias! {
1552-
/// Runs the `tests/coverage` test suite in "coverage-map" mode only.
1553-
/// Used by `x test` and `x test coverage-map`.
1554-
CoverageMap {
1555-
alias_and_mode: "coverage-map",
1556-
default: true,
1557-
only_hosts: false,
1558-
}
1559-
}
1560-
coverage_test_alias! {
1561-
/// Runs the `tests/coverage` test suite in "coverage-run" mode only.
1562-
/// Used by `x test` and `x test coverage-run`.
1563-
CoverageRun {
1564-
alias_and_mode: "coverage-run",
1565-
default: true,
1566-
// Compiletest knows how to automatically skip these tests when cross-compiling,
1567-
// but skipping the whole step here makes it clearer that they haven't run at all.
1568-
only_hosts: true,
1508+
let Self { compiler, target, mode } = self;
1509+
// Like other compiletest suite test steps, delegate to an internal
1510+
// compiletest task to actually run the tests.
1511+
builder.ensure(Compiletest {
1512+
compiler,
1513+
target,
1514+
mode,
1515+
suite: Self::SUITE,
1516+
path: Self::PATH,
1517+
compare_mode: None,
1518+
});
15691519
}
15701520
}
15711521

src/bootstrap/src/core/builder/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -944,8 +944,6 @@ impl<'a> Builder<'a> {
944944
test::Ui,
945945
test::Crashes,
946946
test::Coverage,
947-
test::CoverageMap,
948-
test::CoverageRun,
949947
test::MirOpt,
950948
test::Codegen,
951949
test::CodegenUnits,

0 commit comments

Comments
 (0)