Skip to content

Commit ae6b75e

Browse files
BoxyUwUlcnr
authored andcommitted
new stuff
1 parent 90e6c79 commit ae6b75e

32 files changed

Lines changed: 1020 additions & 722 deletions

File tree

compiler/rustc_borrowck/src/constraints/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ impl<'tcx> fmt::Debug for OutlivesConstraint<'tcx> {
9696
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
9797
write!(
9898
formatter,
99-
"({:?}: {:?}) due to {:?} ({:?}) ({:?})",
100-
self.sup, self.sub, self.locations, self.variance_info, self.category,
99+
"({:?}: {:?}) due to {:?} ({:?}) ({:?}) (span: {:?})",
100+
self.sup, self.sub, self.locations, self.variance_info, self.category, self.span,
101101
)
102102
}
103103
}

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ impl<'tcx> ConstraintDescription for ConstraintCategory<'tcx> {
5757
ConstraintCategory::OpaqueType => "opaque type ",
5858
ConstraintCategory::ClosureUpvar(_) => "closure capture ",
5959
ConstraintCategory::Usage => "this usage ",
60-
ConstraintCategory::Predicate(_)
60+
ConstraintCategory::SolverRegionConstraint(_)
61+
| ConstraintCategory::Predicate(_)
6162
| ConstraintCategory::Boring
6263
| ConstraintCategory::BoringNoLocation
6364
| ConstraintCategory::Internal
@@ -473,6 +474,14 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
473474
let errci = ErrorConstraintInfo { fr, outlived_fr, category, span: cause.span };
474475

475476
let mut diag = match (category, fr_is_local, outlived_fr_is_local) {
477+
(ConstraintCategory::SolverRegionConstraint(span), _, _) => {
478+
let mut d = self.dcx().struct_span_err(
479+
span,
480+
"unsatisfied lifetime constraint from -Zassumptions-on-binders :3",
481+
);
482+
d.note("meoow :c");
483+
d
484+
}
476485
(ConstraintCategory::Return(kind), true, false) if self.is_closure_fn_mut(fr) => {
477486
self.report_fnmut_error(&errci, kind)
478487
}

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
17981798
// the `'region: 'static` constraints introduced by placeholder outlives.
17991799
ConstraintCategory::Internal => 7,
18001800
ConstraintCategory::OutlivesUnnameablePlaceholder(_) => 8,
1801+
ConstraintCategory::SolverRegionConstraint(_) => 9,
18011802
};
18021803

18031804
debug!("constraint {constraint:?} category: {category:?}, interest: {interest:?}");

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ pub(crate) fn type_check<'tcx>(
187187
&mut converter,
188188
typeck.known_type_outlives_obligations,
189189
universal_region_relations.outlives.clone(),
190+
infcx.tcx.def_span(infcx.root_def_id),
190191
);
191192

192193
// In case type check encountered an error region, we suppress unhelpful extra

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ where
197197

198198
lint_redundant_lifetimes(tcx, body_def_id, &outlives_env);
199199

200-
let errors = infcx.resolve_regions_with_outlives_env(&outlives_env);
200+
let errors = infcx.resolve_regions_with_outlives_env(&outlives_env, tcx.def_span(body_def_id));
201201
if errors.is_empty() {
202202
return Ok(());
203203
}
@@ -211,7 +211,8 @@ where
211211
// the implied bounds hack if this contains `bevy_ecs`'s `ParamSet` type.
212212
false,
213213
);
214-
let errors_compat = infcx_compat.resolve_regions_with_outlives_env(&outlives_env);
214+
let errors_compat =
215+
infcx_compat.resolve_regions_with_outlives_env(&outlives_env, tcx.def_span(body_def_id));
215216
if errors_compat.is_empty() {
216217
// FIXME: Once we fix bevy, this would be the place to insert a warning
217218
// to upgrade bevy.

compiler/rustc_infer/src/infer/at.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ impl<'tcx> InferCtxt<'tcx> {
8181
reported_signature_mismatch: self.reported_signature_mismatch.clone(),
8282
tainted_by_errors: self.tainted_by_errors.clone(),
8383
universe: self.universe.clone(),
84-
universe_assumptions_for_next_solver: self.universe_assumptions_for_next_solver.clone(),
84+
placeholder_assumptions_for_next_solver: self
85+
.placeholder_assumptions_for_next_solver
86+
.clone(),
8587
next_trait_solver: self.next_trait_solver,
8688
obligation_inspector: self.obligation_inspector.clone(),
8789
}
@@ -107,7 +109,9 @@ impl<'tcx> InferCtxt<'tcx> {
107109
reported_signature_mismatch: self.reported_signature_mismatch.clone(),
108110
tainted_by_errors: self.tainted_by_errors.clone(),
109111
universe: self.universe.clone(),
110-
universe_assumptions_for_next_solver: self.universe_assumptions_for_next_solver.clone(),
112+
placeholder_assumptions_for_next_solver: self
113+
.placeholder_assumptions_for_next_solver
114+
.clone(),
111115
next_trait_solver: self.next_trait_solver,
112116
obligation_inspector: self.obligation_inspector.clone(),
113117
};

compiler/rustc_infer/src/infer/context.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> {
3030
self.typing_mode_raw()
3131
}
3232

33-
fn higher_ranked_assumptions_v2(&self) -> bool {
34-
self.tcx.sess.opts.unstable_opts.higher_ranked_assumptions_v2
33+
fn assumptions_on_binders(&self) -> bool {
34+
self.tcx.sess.opts.unstable_opts.assumptions_on_binders
3535
}
3636

3737
fn universe(&self) -> ty::UniverseIndex {
@@ -42,27 +42,40 @@ impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> {
4242
self.create_next_universe()
4343
}
4444

45-
fn insert_universe_assumptions(
45+
fn insert_placeholder_assumptions(
4646
&self,
4747
u: ty::UniverseIndex,
4848
assumptions: Option<rustc_type_ir::region_constraint::Assumptions<TyCtxt<'tcx>>>,
4949
) {
50-
self.universe_assumptions_for_next_solver.borrow_mut().insert(u, assumptions);
50+
self.placeholder_assumptions_for_next_solver.borrow_mut().insert(u, assumptions);
5151
}
5252

53-
fn get_universe_assumptions(
53+
fn get_placeholder_assumptions(
5454
&self,
5555
u: ty::UniverseIndex,
5656
) -> Option<rustc_type_ir::region_constraint::Assumptions<TyCtxt<'tcx>>> {
57-
self.universe_assumptions_for_next_solver.borrow().get(&u).unwrap().as_ref().cloned()
57+
self.placeholder_assumptions_for_next_solver.borrow().get(&u).unwrap().as_ref().cloned()
5858
}
5959

60-
fn get_solve_region_constraint(
60+
fn get_solver_region_constraint(
6161
&self,
6262
) -> rustc_type_ir::region_constraint::RegionConstraint<TyCtxt<'tcx>> {
6363
self.inner.borrow().solver_region_constraint_storage.get_constraint()
6464
}
6565

66+
fn overwrite_solver_region_constraint(
67+
&self,
68+
constraint: rustc_type_ir::region_constraint::RegionConstraint<TyCtxt<'tcx>>,
69+
) {
70+
let mut inner = self.inner.borrow_mut();
71+
use rustc_data_structures::undo_log::UndoLogs;
72+
73+
use crate::infer::UndoLog;
74+
let old_constraint = inner.solver_region_constraint_storage.get_constraint();
75+
inner.undo_log.push(UndoLog::OverwriteSolverRegionConstraint { old_constraint });
76+
inner.solver_region_constraint_storage.overwrite_solver_region_constraint(constraint);
77+
}
78+
6679
fn universe_of_ty(&self, vid: ty::TyVid) -> Option<ty::UniverseIndex> {
6780
match self.try_resolve_ty_var(vid) {
6881
Err(universe) => Some(universe),

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,10 @@ pub struct InferCtxt<'tcx> {
322322
/// List of assumed wellformed types which we can derive implied
323323
/// bounds on a `for<...>` from. Only used unstabley and by the
324324
/// new solver.
325-
universe_assumptions_for_next_solver: RefCell<
325+
//
326+
// FIXME(-Zassumptions-on-binders): This and `universe` should probably be
327+
// in `InferCtxtInner` so they can participate in rollbacks and whatnot
328+
placeholder_assumptions_for_next_solver: RefCell<
326329
FxIndexMap<
327330
ty::UniverseIndex,
328331
Option<rustc_type_ir::region_constraint::Assumptions<TyCtxt<'tcx>>>,
@@ -440,6 +443,10 @@ pub enum SubregionOrigin<'tcx> {
440443
},
441444

442445
AscribeUserTypeProvePredicate(Span),
446+
447+
// FIXME(-Zassumptions-on-binders): this is a temporary hack until we support
448+
// proper diagnostics for solver region constraints.
449+
SolverRegionConstraint(Span),
443450
}
444451

445452
// `SubregionOrigin` is used a lot. Make sure it doesn't unintentionally get bigger.
@@ -451,6 +458,7 @@ impl<'tcx> SubregionOrigin<'tcx> {
451458
match self {
452459
Self::Subtype(type_trace) => type_trace.cause.to_constraint_category(),
453460
Self::AscribeUserTypeProvePredicate(span) => ConstraintCategory::Predicate(*span),
461+
Self::SolverRegionConstraint(span) => ConstraintCategory::SolverRegionConstraint(*span),
454462
_ => ConstraintCategory::BoringNoLocation,
455463
}
456464
}
@@ -650,7 +658,7 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
650658
reported_signature_mismatch: Default::default(),
651659
tainted_by_errors: Cell::new(None),
652660
universe: Cell::new(ty::UniverseIndex::ROOT),
653-
universe_assumptions_for_next_solver: RefCell::new(Default::default()),
661+
placeholder_assumptions_for_next_solver: RefCell::new(Default::default()),
654662
next_trait_solver,
655663
obligation_inspector: Cell::new(None),
656664
}
@@ -1705,6 +1713,7 @@ impl<'tcx> SubregionOrigin<'tcx> {
17051713
SubregionOrigin::CompareImplItemObligation { span, .. } => span,
17061714
SubregionOrigin::AscribeUserTypeProvePredicate(span) => span,
17071715
SubregionOrigin::CheckAssociatedTypeBounds { ref parent, .. } => parent.span(),
1716+
SubregionOrigin::SolverRegionConstraint(a) => a,
17081717
}
17091718
}
17101719

@@ -1836,4 +1845,13 @@ impl<'tcx> SolverRegionConstraintStorage<'tcx> {
18361845
_ => unreachable!(),
18371846
}
18381847
}
1848+
1849+
#[instrument(level = "debug", skip(self))]
1850+
fn overwrite_solver_region_constraint(&mut self, constraint: SolverRegionConstraint<'tcx>) {
1851+
if !constraint.is_and() {
1852+
self.0 = SolverRegionConstraint::And(vec![constraint].into_boxed_slice())
1853+
} else {
1854+
self.0 = constraint;
1855+
}
1856+
}
18391857
}

compiler/rustc_infer/src/infer/outlives/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::iter;
55
use rustc_data_structures::undo_log::UndoLogs;
66
use rustc_middle::traits::query::{NoSolution, OutlivesBound};
77
use rustc_middle::ty;
8+
use rustc_span::Span;
89
use tracing::instrument;
910

1011
use self::env::OutlivesEnvironment;
@@ -49,8 +50,9 @@ impl<'tcx> InferCtxt<'tcx> {
4950
ty::PolyTypeOutlivesPredicate<'tcx>,
5051
SubregionOrigin<'tcx>,
5152
) -> Result<ty::PolyTypeOutlivesPredicate<'tcx>, NoSolution>,
53+
span: Span,
5254
) -> Vec<RegionResolutionError<'tcx>> {
53-
match self.process_registered_region_obligations(outlives_env, deeply_normalize_ty) {
55+
match self.process_registered_region_obligations(outlives_env, deeply_normalize_ty, span) {
5456
Ok(()) => {}
5557
Err((clause, origin)) => {
5658
return vec![RegionResolutionError::CannotNormalize(clause, origin)];

compiler/rustc_infer/src/infer/outlives/obligations.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ use rustc_middle::ty::{
6969
self, GenericArgKind, GenericArgsRef, PolyTypeOutlivesPredicate, Region, RegionVid, Ty, TyCtxt,
7070
TypeFoldable as _, TypeVisitableExt,
7171
};
72-
use rustc_span::DUMMY_SP;
72+
use rustc_span::Span;
7373
use smallvec::smallvec;
7474
use tracing::{debug, instrument};
7575

@@ -147,7 +147,7 @@ impl<'tcx> InferCtxt<'tcx> {
147147
sub_region: Region<'tcx>,
148148
cause: &ObligationCause<'tcx>,
149149
) {
150-
assert!(!self.tcx.sess.opts.unstable_opts.higher_ranked_assumptions_v2);
150+
assert!(!self.tcx.sess.opts.unstable_opts.assumptions_on_binders);
151151

152152
// `is_global` means the type has no params, infer, placeholder, or non-`'static`
153153
// free regions. If the type has none of these things, then we can skip registering
@@ -206,12 +206,13 @@ impl<'tcx> InferCtxt<'tcx> {
206206
pub fn destructure_solver_region_constraints_for_regionck(
207207
&self,
208208
outlives_env: &OutlivesEnvironment<'tcx>,
209+
span: Span,
209210
) {
210211
let assumptions = rustc_type_ir::region_constraint::Assumptions::new(
211212
outlives_env.known_type_outlives().into_iter().cloned().collect(),
212213
outlives_env.free_region_map().relation.clone(),
213214
);
214-
self.destructure_solve_region_constraints(assumptions, self);
215+
self.destructure_solver_region_constraints(assumptions, self, span);
215216
}
216217

217218
pub fn destructure_solver_region_constraints_for_borrowck(
@@ -220,38 +221,38 @@ impl<'tcx> InferCtxt<'tcx> {
220221
conversion: impl TypeOutlivesDelegate<'tcx>,
221222
known_type_outlives: &[PolyTypeOutlivesPredicate<'tcx>],
222223
region_outlives: TransitiveRelation<RegionVid>,
224+
span: Span,
223225
) {
224226
let assumptions = rustc_type_ir::region_constraint::Assumptions::new(
225227
known_type_outlives.into_iter().cloned().collect(),
226228
region_outlives.maybe_map(|r| Some(Region::new_var(self.tcx, r))).unwrap(),
227229
);
228-
self.destructure_solve_region_constraints(assumptions, conversion);
230+
self.destructure_solver_region_constraints(assumptions, conversion, span);
229231
}
230232

231233
#[instrument(level = "debug", skip(self, conversion))]
232-
pub fn destructure_solve_region_constraints(
234+
pub fn destructure_solver_region_constraints(
233235
&self,
234236
assumptions: rustc_type_ir::region_constraint::Assumptions<TyCtxt<'tcx>>,
235237
mut conversion: impl TypeOutlivesDelegate<'tcx>,
238+
span: Span,
236239
) {
237-
if !self.tcx.sess.opts.unstable_opts.higher_ranked_assumptions_v2 {
240+
if !self.tcx.sess.opts.unstable_opts.assumptions_on_binders {
238241
return;
239242
}
240243

241244
assert!(self.next_trait_solver());
242245

243-
// FIXME(-Zhigher-ranked-assumptions-v2): Implement diagnostics
244-
let origin = SubregionOrigin::Reborrow(DUMMY_SP);
246+
let origin = SubregionOrigin::SolverRegionConstraint(span);
245247
let category = origin.to_constraint_category();
246248

247249
let constraint = self.inner.borrow().solver_region_constraint_storage.get_constraint();
248250
debug!(?constraint);
249251
let constraint =
250-
rustc_type_ir::region_constraint::destructure_type_outlives_constraints_in_universe(
252+
rustc_type_ir::region_constraint::destructure_type_outlives_constraints_in_root(
251253
self,
252254
constraint,
253-
None,
254-
&Some(assumptions),
255+
&assumptions,
255256
);
256257
debug!(?constraint);
257258
let constraint = rustc_type_ir::region_constraint::evaluate_solver_constraint(&constraint);
@@ -274,9 +275,9 @@ impl<'tcx> InferCtxt<'tcx> {
274275
category,
275276
);
276277
}
277-
// FIXME(-Zhigher-ranked-assumptions-v2): actually implement OR as an OR
278+
// FIXME(-Zassumptions-on-binders): actually implement OR as an OR
278279
And(nested) | Or(nested) => constraints.extend(nested),
279-
AliasTyOutlivesFromEnv(..) => unreachable!(),
280+
AliasTyOutlivesViaEnv(..) => unreachable!(),
280281
PlaceholderTyOutlives(..) => unreachable!(),
281282
}
282283
}
@@ -300,10 +301,11 @@ impl<'tcx> InferCtxt<'tcx> {
300301
SubregionOrigin<'tcx>,
301302
)
302303
-> Result<PolyTypeOutlivesPredicate<'tcx>, NoSolution>,
304+
span: Span,
303305
) -> Result<(), (PolyTypeOutlivesPredicate<'tcx>, SubregionOrigin<'tcx>)> {
304306
assert!(!self.in_snapshot(), "cannot process registered region obligations in a snapshot");
305307

306-
self.destructure_solver_region_constraints_for_regionck(outlives_env);
308+
self.destructure_solver_region_constraints_for_regionck(outlives_env, span);
307309

308310
// Must loop since the process of normalizing may itself register region obligations.
309311
for iteration in 0.. {

0 commit comments

Comments
 (0)