Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit acab765

Browse files
committed
Add -Zno-implied-bounds-compat option and use it
1 parent d96003d commit acab765

File tree

8 files changed

+37
-16
lines changed

8 files changed

+37
-16
lines changed

‎compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ fn check_opaque_meets_bounds<'tcx>(
368368
// Can have different predicates to their defining use
369369
hir::OpaqueTyOrigin::TyAlias { .. } => {
370370
let wf_tys = ocx.assumed_wf_types_and_report_errors(param_env, def_id)?;
371-
let implied_bounds = infcx.implied_bounds_tys_compat(param_env, def_id, &wf_tys);
371+
let implied_bounds = infcx.implied_bounds_tys(param_env, def_id, &wf_tys);
372372
let outlives_env = OutlivesEnvironment::with_bounds(param_env, implied_bounds);
373373
ocx.resolve_regions_and_report_errors(defining_use_anchor, &outlives_env)?;
374374
}

‎compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ fn compare_method_predicate_entailment<'tcx>(
378378
// lifetime parameters.
379379
let outlives_env = OutlivesEnvironment::with_bounds(
380380
param_env,
381-
infcx.implied_bounds_tys_compat(param_env, impl_m_def_id, &wf_tys),
381+
infcx.implied_bounds_tys(param_env, impl_m_def_id, &wf_tys),
382382
);
383383
let errors = infcx.resolve_regions(&outlives_env);
384384
if !errors.is_empty() {
@@ -702,7 +702,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
702702
// lifetime parameters.
703703
let outlives_env = OutlivesEnvironment::with_bounds(
704704
param_env,
705-
infcx.implied_bounds_tys_compat(param_env, impl_m_def_id, &wf_tys),
705+
infcx.implied_bounds_tys(param_env, impl_m_def_id, &wf_tys),
706706
);
707707
ocx.resolve_regions_and_report_errors(impl_m_def_id, &outlives_env)?;
708708

@@ -2070,8 +2070,7 @@ pub(super) fn check_type_bounds<'tcx>(
20702070

20712071
// Finally, resolve all regions. This catches wily misuses of
20722072
// lifetime parameters.
2073-
let implied_bounds =
2074-
infcx.implied_bounds_tys_compat(param_env, impl_ty_def_id, &assumed_wf_types);
2073+
let implied_bounds = infcx.implied_bounds_tys(param_env, impl_ty_def_id, &assumed_wf_types);
20752074
let outlives_env = OutlivesEnvironment::with_bounds(param_env, implied_bounds);
20762075
ocx.resolve_regions_and_report_errors(impl_ty_def_id, &outlives_env)
20772076
}

‎compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
158158
}
159159
let outlives_env = OutlivesEnvironment::with_bounds(
160160
param_env,
161-
infcx.implied_bounds_tys_compat(param_env, impl_m.def_id.expect_local(), &implied_wf_types),
161+
infcx.implied_bounds_tys(param_env, impl_m.def_id.expect_local(), &implied_wf_types),
162162
);
163163
let errors = infcx.resolve_regions(&outlives_env);
164164
if !errors.is_empty() {

‎compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,13 @@ where
127127
}
128128
}
129129

130+
debug!(?assumed_wf_types);
131+
130132
let infcx_compat = infcx.fork();
131133

132-
debug!(?assumed_wf_types);
133-
let implied_bounds = infcx.implied_bounds_tys(param_env, body_def_id, &assumed_wf_types);
134+
// We specifically want to call the non-compat version of `implied_bounds_tys`; we do this always.
135+
let implied_bounds =
136+
infcx.implied_bounds_tys_compat(param_env, body_def_id, &assumed_wf_types, false);
134137
let outlives_env = OutlivesEnvironment::with_bounds(param_env, implied_bounds);
135138

136139
let errors = infcx.resolve_regions(&outlives_env);
@@ -166,9 +169,13 @@ where
166169
false
167170
};
168171

169-
if is_bevy {
172+
// If we have set `no_implied_bounds_compat`, then do not attempt compatibility.
173+
// We could also just always enter if `is_bevy`, and call `implied_bounds_tys`,
174+
// but that does result in slightly more work when this option is set and
175+
// just obscures what we mean here anyways. Let's just be explicit.
176+
if is_bevy && !infcx.tcx.sess.opts.unstable_opts.no_implied_bounds_compat {
170177
let implied_bounds =
171-
infcx_compat.implied_bounds_tys_compat(param_env, body_def_id, &assumed_wf_types);
178+
infcx_compat.implied_bounds_tys_compat(param_env, body_def_id, &assumed_wf_types,true);
172179
let outlives_env = OutlivesEnvironment::with_bounds(param_env, implied_bounds);
173180
let errors_compat = infcx_compat.resolve_regions(&outlives_env);
174181
if errors_compat.is_empty() {
@@ -770,7 +777,7 @@ fn resolve_regions_with_wf_tys<'tcx>(
770777
let infcx = tcx.infer_ctxt().build();
771778
let outlives_environment = OutlivesEnvironment::with_bounds(
772779
param_env,
773-
infcx.implied_bounds_tys_compat(param_env, id, wf_tys),
780+
infcx.implied_bounds_tys(param_env, id, wf_tys),
774781
);
775782
let region_bound_pairs = outlives_environment.region_bound_pairs();
776783

‎compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ fn get_impl_args(
202202
return Err(guar);
203203
}
204204

205-
let implied_bounds =
206-
infcx.implied_bounds_tys_compat(param_env, impl1_def_id, &assumed_wf_types);
205+
let implied_bounds = infcx.implied_bounds_tys(param_env, impl1_def_id, &assumed_wf_types);
207206
let outlives_env = OutlivesEnvironment::with_bounds(param_env, implied_bounds);
208207
let _ = ocx.resolve_regions_and_report_errors(impl1_def_id, &outlives_env);
209208
let Ok(impl2_args) = infcx.fully_resolve(impl2_args) else {

‎compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,6 +1724,8 @@ options! {
17241724
"run all passes except codegen; no output"),
17251725
no_generate_arange_section: bool = (false, parse_no_flag, [TRACKED],
17261726
"omit DWARF address ranges that give faster lookups"),
1727+
no_implied_bounds_compat: bool = (false, parse_bool, [TRACKED],
1728+
"disable the compatibility version of the `implied_bounds_ty` query"),
17271729
no_jump_tables: bool = (false, parse_no_flag, [TRACKED],
17281730
"disable the jump tables and lookup tables that can be generated from a switch case lowering"),
17291731
no_leak_check: bool = (false, parse_no_flag, [UNTRACKED],

‎compiler/rustc_trait_selection/src/traits/misc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ pub fn all_fields_implement_trait<'tcx>(
191191
// Check regions assuming the self type of the impl is WF
192192
let outlives_env = OutlivesEnvironment::with_bounds(
193193
param_env,
194-
infcx.implied_bounds_tys_compat(
194+
infcx.implied_bounds_tys(
195195
param_env,
196196
parent_cause.body_id,
197197
&FxIndexSet::from_iter([self_type]),

‎compiler/rustc_trait_selection/src/traits/outlives_bounds.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ pub use rustc_middle::traits::query::OutlivesBound;
1212
pub type BoundsCompat<'a, 'tcx: 'a> = impl Iterator<Item = OutlivesBound<'tcx>> + 'a;
1313
pub type Bounds<'a, 'tcx: 'a> = impl Iterator<Item = OutlivesBound<'tcx>> + 'a;
1414
pub trait InferCtxtExt<'a, 'tcx> {
15+
/// Do *NOT* call this directly.
1516
fn implied_bounds_tys_compat(
1617
&'a self,
1718
param_env: ty::ParamEnv<'tcx>,
1819
body_id: LocalDefId,
1920
tys: &'a FxIndexSet<Ty<'tcx>>,
21+
compat: bool,
2022
) -> BoundsCompat<'a, 'tcx>;
2123

24+
/// If `-Z no-implied-bounds-compat` is set, calls `implied_bounds_tys_compat`
25+
/// with `compat` set to `true`, otherwise `false`.
2226
fn implied_bounds_tys(
2327
&'a self,
2428
param_env: ty::ParamEnv<'tcx>,
@@ -132,8 +136,10 @@ impl<'a, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'tcx> {
132136
param_env: ParamEnv<'tcx>,
133137
body_id: LocalDefId,
134138
tys: &'a FxIndexSet<Ty<'tcx>>,
139+
compat: bool,
135140
) -> BoundsCompat<'a, 'tcx> {
136-
tys.iter().flat_map(move |ty| implied_outlives_bounds(self, param_env, body_id, *ty, true))
141+
tys.iter()
142+
.flat_map(move |ty| implied_outlives_bounds(self, param_env, body_id, *ty, compat))
137143
}
138144

139145
fn implied_bounds_tys(
@@ -142,6 +148,14 @@ impl<'a, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'tcx> {
142148
body_id: LocalDefId,
143149
tys: &'a FxIndexSet<Ty<'tcx>>,
144150
) -> Bounds<'a, 'tcx> {
145-
tys.iter().flat_map(move |ty| implied_outlives_bounds(self, param_env, body_id, *ty, false))
151+
tys.iter().flat_map(move |ty| {
152+
implied_outlives_bounds(
153+
self,
154+
param_env,
155+
body_id,
156+
*ty,
157+
!self.tcx.sess.opts.unstable_opts.no_implied_bounds_compat,
158+
)
159+
})
146160
}
147161
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /