From 058ab53dc58b70d4b0b60374d4f7ddfede4dae65 Mon Sep 17 00:00:00 2001 From: lcnr Date: Fri, 19 Jan 2024 08:19:18 +0100 Subject: [PATCH] use implied bounds compat mode in MIR borrowck --- .../query/type_op/implied_outlives_bounds.rs | 12 ++++++++++-- .../issue-111404-1.rs | 1 - .../issue-111404-1.stderr | 10 +--------- tests/ui/implied-bounds/bevy_world_query.rs | 4 +++- .../normalization-nested.lifetime.stderr | 10 ++++++++++ .../ui/implied-bounds/normalization-nested.rs | 14 ++++++++++---- ...09.stderr => issue-80409.no-compat.stderr} | 0 tests/ui/inference/issue-80409.rs | 19 ++++++++++++------- 8 files changed, 46 insertions(+), 24 deletions(-) create mode 100644 tests/ui/implied-bounds/normalization-nested.lifetime.stderr rename tests/ui/inference/{issue-80409.stderr => issue-80409.no-compat.stderr} (100%) diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/implied_outlives_bounds.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/implied_outlives_bounds.rs index 2fdb63d7deebd..83d23597c0cd8 100644 --- a/compiler/rustc_trait_selection/src/traits/query/type_op/implied_outlives_bounds.rs +++ b/compiler/rustc_trait_selection/src/traits/query/type_op/implied_outlives_bounds.rs @@ -48,14 +48,22 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ImpliedOutlivesBounds<'tcx> { param_env.and(ty) }); - tcx.implied_outlives_bounds(canonicalized) + if tcx.sess.opts.unstable_opts.no_implied_bounds_compat { + tcx.implied_outlives_bounds(canonicalized) + } else { + tcx.implied_outlives_bounds_compat(canonicalized) + } } fn perform_locally_with_next_solver( ocx: &ObligationCtxt<'_, 'tcx>, key: ParamEnvAnd<'tcx, Self>, ) -> Result { - compute_implied_outlives_bounds_inner(ocx, key.param_env, key.value.ty) + if ocx.infcx.tcx.sess.opts.unstable_opts.no_implied_bounds_compat { + compute_implied_outlives_bounds_inner(ocx, key.param_env, key.value.ty) + } else { + compute_implied_outlives_bounds_compat_inner(ocx, key.param_env, key.value.ty) + } } } diff --git a/tests/ui/associated-inherent-types/issue-111404-1.rs b/tests/ui/associated-inherent-types/issue-111404-1.rs index 74f9434b8818a..dd62e59f07d22 100644 --- a/tests/ui/associated-inherent-types/issue-111404-1.rs +++ b/tests/ui/associated-inherent-types/issue-111404-1.rs @@ -10,6 +10,5 @@ impl<'a> Foo { fn bar(_: fn(Foo fn(Foo::Assoc)>::Assoc)) {} //~^ ERROR higher-ranked subtype error //~| ERROR higher-ranked subtype error -//~| ERROR higher-ranked subtype error fn main() {} diff --git a/tests/ui/associated-inherent-types/issue-111404-1.stderr b/tests/ui/associated-inherent-types/issue-111404-1.stderr index 1613161a873f7..cf4d4a5f19b12 100644 --- a/tests/ui/associated-inherent-types/issue-111404-1.stderr +++ b/tests/ui/associated-inherent-types/issue-111404-1.stderr @@ -12,13 +12,5 @@ LL | fn bar(_: fn(Foo fn(Foo::Assoc)>::Assoc)) {} | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: higher-ranked subtype error - --> $DIR/issue-111404-1.rs:10:1 - | -LL | fn bar(_: fn(Foo fn(Foo::Assoc)>::Assoc)) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors diff --git a/tests/ui/implied-bounds/bevy_world_query.rs b/tests/ui/implied-bounds/bevy_world_query.rs index d5de0e9ef2176..2e3d4e6a7c667 100644 --- a/tests/ui/implied-bounds/bevy_world_query.rs +++ b/tests/ui/implied-bounds/bevy_world_query.rs @@ -19,7 +19,9 @@ impl SystemParam for Query { pub struct ParamSet(T) where T::State: Sized; -fn handler<'a>(_: ParamSet>) {} +fn handler<'a>(x: ParamSet>) { + let _: ParamSet<_> = x; +} fn ref_handler<'a>(_: &ParamSet>) {} diff --git a/tests/ui/implied-bounds/normalization-nested.lifetime.stderr b/tests/ui/implied-bounds/normalization-nested.lifetime.stderr new file mode 100644 index 0000000000000..c43cc0999f1d7 --- /dev/null +++ b/tests/ui/implied-bounds/normalization-nested.lifetime.stderr @@ -0,0 +1,10 @@ +error: lifetime may not live long enough + --> $DIR/normalization-nested.rs:40:5 + | +LL | pub fn test_borrowck<'x>(_: Map>, s: &'x str) -> &'static str { + | -- lifetime `'x` defined here +LL | s + | ^ returning this value requires that `'x` must outlive `'static` + +error: aborting due to 1 previous error + diff --git a/tests/ui/implied-bounds/normalization-nested.rs b/tests/ui/implied-bounds/normalization-nested.rs index 3f569aa1acea7..6ceb13e94731f 100644 --- a/tests/ui/implied-bounds/normalization-nested.rs +++ b/tests/ui/implied-bounds/normalization-nested.rs @@ -1,14 +1,19 @@ // Test for normalization of projections that appear in the item bounds // (versus those that appear directly in the input types). // -// revisions: param_ty lifetime -// check-pass +// revisions: param_ty lifetime param_ty_no_compat lifetime_no_compat + +//[param_ty] check-pass +//[param_ty_no_compat] check-pass +//[lifetime_no_compat] check-pass +//[param_ty_no_compat] compile-flags: -Zno-implied-bounds-compat +//[lifetime_no_compat] compile-flags: -Zno-implied-bounds-compat pub trait Iter { type Item; } -#[cfg(param_ty)] +#[cfg(any(param_ty, param_ty_no_compat))] impl Iter for I where I: IntoIterator, @@ -16,7 +21,7 @@ where type Item = X; } -#[cfg(lifetime)] +#[cfg(any(lifetime, lifetime_no_compat))] impl<'x, I> Iter for I where I: IntoIterator, @@ -33,6 +38,7 @@ pub fn test_wfcheck<'x>(_: Map>) {} pub fn test_borrowck<'x>(_: Map>, s: &'x str) -> &'static str { s + //[lifetime]~^ ERROR lifetime may not live long enough } fn main() {} diff --git a/tests/ui/inference/issue-80409.stderr b/tests/ui/inference/issue-80409.no-compat.stderr similarity index 100% rename from tests/ui/inference/issue-80409.stderr rename to tests/ui/inference/issue-80409.no-compat.stderr diff --git a/tests/ui/inference/issue-80409.rs b/tests/ui/inference/issue-80409.rs index d36688978e9f3..49c9978fe1558 100644 --- a/tests/ui/inference/issue-80409.rs +++ b/tests/ui/inference/issue-80409.rs @@ -1,12 +1,17 @@ // This should not pass, because `usize: Fsm` does not hold. However, it currently ICEs. -// check-fail -// known-bug: #80409 -// failure-status: 101 -// normalize-stderr-test "note: .*\n\n" -> "" -// normalize-stderr-test "thread 'rustc' panicked.*\n" -> "" -// normalize-stderr-test "(error: internal compiler error: [^:]+):\d+:\d+: " -> "$1:LL:CC: " -// rustc-env:RUST_BACKTRACE=0 +// ignore-tidy-linelength + +// revisions: compat no-compat +//[compat] check-pass +//[no-compat] compile-flags: -Zno-implied-bounds-compat +//[no-compat] check-fail +//[no-compat] known-bug: #80409 +//[no-compat] failure-status: 101 +//[no-compat] normalize-stderr-test "note: .*\n\n" -> "" +//[no-compat] normalize-stderr-test "thread 'rustc' panicked.*\n" -> "" +//[no-compat] normalize-stderr-test "(error: internal compiler error: [^:]+):\d+:\d+: " -> "$1:LL:CC: " +//[no-compat] rustc-env:RUST_BACKTRACE=0 #![allow(unreachable_code, unused)]