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 a34faab

Browse files
committed
Auto merge of #118553 - jackh726:lint-implied-bounds, r=lcnr
error on incorrect implied bounds in wfcheck except for Bevy dependents Rebase of #109763 Additionally, special cases Bevy `ParamSet` types to not trigger the lint. This is tracked in #119956. Fixes #109628
2 parents c485ee7 + a9e30e6 commit a34faab

File tree

26 files changed

+411
-175
lines changed

26 files changed

+411
-175
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(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 & 3 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(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(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,7 +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 = infcx.implied_bounds_tys(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);
20742074
let outlives_env = OutlivesEnvironment::with_bounds(param_env, implied_bounds);
20752075
ocx.resolve_regions_and_report_errors(impl_ty_def_id, &outlives_env)
20762076
}

‎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(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: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_infer::infer::outlives::obligations::TypeOutlives;
1515
use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
1616
use rustc_middle::mir::ConstraintCategory;
1717
use rustc_middle::query::Providers;
18+
use rustc_middle::ty::print::with_no_trimmed_paths;
1819
use rustc_middle::ty::trait_def::TraitSpecializationKind;
1920
use rustc_middle::ty::{
2021
self, AdtKind, GenericParamDefKind, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable,
@@ -112,8 +113,6 @@ where
112113

113114
let assumed_wf_types = wfcx.ocx.assumed_wf_types_and_report_errors(param_env, body_def_id)?;
114115

115-
let implied_bounds = infcx.implied_bounds_tys(param_env, body_def_id, assumed_wf_types);
116-
117116
let errors = wfcx.select_all_or_error();
118117
if !errors.is_empty() {
119118
let err = infcx.err_ctxt().report_fulfillment_errors(errors);
@@ -128,10 +127,65 @@ where
128127
}
129128
}
130129

130+
debug!(?assumed_wf_types);
131+
132+
let infcx_compat = infcx.fork();
133+
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);
131137
let outlives_env = OutlivesEnvironment::with_bounds(param_env, implied_bounds);
132138

133-
wfcx.ocx.resolve_regions_and_report_errors(body_def_id, &outlives_env)?;
134-
infcx.tainted_by_errors().error_reported()
139+
let errors = infcx.resolve_regions(&outlives_env);
140+
if errors.is_empty() {
141+
return Ok(());
142+
}
143+
144+
let is_bevy = 'is_bevy: {
145+
// We don't want to emit this for dependents of Bevy, for now.
146+
// See #119956
147+
let is_bevy_paramset = |def: ty::AdtDef<'_>| {
148+
let adt_did = with_no_trimmed_paths!(infcx.tcx.def_path_str(def.0.did));
149+
adt_did.contains("ParamSet")
150+
};
151+
for ty in assumed_wf_types.iter() {
152+
match ty.kind() {
153+
ty::Adt(def, _) => {
154+
if is_bevy_paramset(*def) {
155+
break 'is_bevy true;
156+
}
157+
}
158+
ty::Ref(_, ty, _) => match ty.kind() {
159+
ty::Adt(def, _) => {
160+
if is_bevy_paramset(*def) {
161+
break 'is_bevy true;
162+
}
163+
}
164+
_ => {}
165+
},
166+
_ => {}
167+
}
168+
}
169+
false
170+
};
171+
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 {
177+
let implied_bounds =
178+
infcx_compat.implied_bounds_tys_compat(param_env, body_def_id, &assumed_wf_types, true);
179+
let outlives_env = OutlivesEnvironment::with_bounds(param_env, implied_bounds);
180+
let errors_compat = infcx_compat.resolve_regions(&outlives_env);
181+
if errors_compat.is_empty() {
182+
Ok(())
183+
} else {
184+
Err(infcx_compat.err_ctxt().report_region_errors(body_def_id, &errors_compat))
185+
}
186+
} else {
187+
Err(infcx.err_ctxt().report_region_errors(body_def_id, &errors))
188+
}
135189
}
136190

137191
fn check_well_formed(tcx: TyCtxt<'_>, def_id: hir::OwnerId) -> Result<(), ErrorGuaranteed> {
@@ -723,7 +777,7 @@ fn resolve_regions_with_wf_tys<'tcx>(
723777
let infcx = tcx.infer_ctxt().build();
724778
let outlives_environment = OutlivesEnvironment::with_bounds(
725779
param_env,
726-
infcx.implied_bounds_tys(param_env, id, wf_tys.clone()),
780+
infcx.implied_bounds_tys(param_env, id, wf_tys),
727781
);
728782
let region_bound_pairs = outlives_environment.region_bound_pairs();
729783

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

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

205-
let implied_bounds = infcx.implied_bounds_tys(param_env, impl1_def_id, assumed_wf_types);
205+
let implied_bounds = infcx.implied_bounds_tys(param_env, impl1_def_id, &assumed_wf_types);
206206
let outlives_env = OutlivesEnvironment::with_bounds(param_env, implied_bounds);
207207
let _ = ocx.resolve_regions_and_report_errors(impl1_def_id, &outlives_env);
208208
let Ok(impl2_args) = infcx.fully_resolve(impl2_args) else {

‎compiler/rustc_middle/src/query/erase.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ impl<T> EraseType for Result<&'_ T, traits::query::NoSolution> {
7474
type Result = [u8; size_of::<Result<&'static (), traits::query::NoSolution>>()];
7575
}
7676

77+
impl<T> EraseType for Result<&'_ [T], traits::query::NoSolution> {
78+
type Result = [u8; size_of::<Result<&'static [()], traits::query::NoSolution>>()];
79+
}
80+
7781
impl<T> EraseType for Result<&'_ T, rustc_errors::ErrorGuaranteed> {
7882
type Result = [u8; size_of::<Result<&'static (), rustc_errors::ErrorGuaranteed>>()];
7983
}

‎compiler/rustc_middle/src/query/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1949,7 +1949,7 @@ rustc_queries! {
19491949
desc { "normalizing `{}`", goal.value }
19501950
}
19511951

1952-
query implied_outlives_bounds(
1952+
query implied_outlives_bounds_compat(
19531953
goal: CanonicalTyGoal<'tcx>
19541954
) -> Result<
19551955
&'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
@@ -1958,6 +1958,15 @@ rustc_queries! {
19581958
desc { "computing implied outlives bounds for `{}`", goal.value.value }
19591959
}
19601960

1961+
query implied_outlives_bounds(
1962+
goal: CanonicalTyGoal<'tcx>
1963+
) -> Result<
1964+
&'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
1965+
NoSolution,
1966+
> {
1967+
desc { "computing implied outlives bounds v2 for `{}`", goal.value.value }
1968+
}
1969+
19611970
/// Do not call this query directly:
19621971
/// invoke `DropckOutlives::new(dropped_ty)).fully_perform(typeck.infcx)` instead.
19631972
query dropck_outlives(

‎compiler/rustc_middle/src/traits/query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ pub struct NormalizationResult<'tcx> {
191191
/// case they are called implied bounds). They are fed to the
192192
/// `OutlivesEnv` which in turn is supplied to the region checker and
193193
/// other parts of the inference system.
194-
#[derive(Clone, Debug, TypeFoldable, TypeVisitable, HashStable)]
194+
#[derive(Copy,Clone, Debug, TypeFoldable, TypeVisitable, HashStable)]
195195
pub enum OutlivesBound<'tcx> {
196196
RegionSubRegion(ty::Region<'tcx>, ty::Region<'tcx>),
197197
RegionSubParam(ty::Region<'tcx>, ty::ParamTy),

‎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
@@ -194,7 +194,7 @@ pub fn all_fields_implement_trait<'tcx>(
194194
infcx.implied_bounds_tys(
195195
param_env,
196196
parent_cause.body_id,
197-
FxIndexSet::from_iter([self_type]),
197+
&FxIndexSet::from_iter([self_type]),
198198
),
199199
);
200200
let errors = infcx.resolve_regions(&outlives_env);

0 commit comments

Comments
(0)

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