Skip to content

Commit 6499c5e

Browse files
committed
Auto merge of rust-lang#93893 - oli-obk:sad_revert, r=oli-obk
Revert lazy TAIT PR Revert rust-lang#92306 (sorry `@Aaron1011,` will include your changes in the fix PR) Revert rust-lang#93783 Revert rust-lang#92007 fixes rust-lang#93788 fixes rust-lang#93794 fixes rust-lang#93821 fixes rust-lang#93831 fixes rust-lang#93841
2 parents 78450d2 + d54195d commit 6499c5e

File tree

370 files changed

+2482
-3621
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

370 files changed

+2482
-3621
lines changed

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

+21-87
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@ use rustc_errors::DiagnosticBuilder;
22
use rustc_infer::infer::canonical::Canonical;
33
use rustc_infer::infer::error_reporting::nice_region_error::NiceRegionError;
44
use rustc_infer::infer::region_constraints::Constraint;
5-
use rustc_infer::infer::region_constraints::RegionConstraintData;
6-
use rustc_infer::infer::RegionVariableOrigin;
75
use rustc_infer::infer::{InferCtxt, RegionResolutionError, SubregionOrigin, TyCtxtInferExt as _};
86
use rustc_infer::traits::{Normalized, ObligationCause, TraitEngine, TraitEngineExt};
97
use rustc_middle::ty::error::TypeError;
10-
use rustc_middle::ty::RegionVid;
11-
use rustc_middle::ty::UniverseIndex;
128
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
139
use rustc_span::Span;
1410
use rustc_trait_selection::traits::query::type_op;
@@ -82,15 +78,6 @@ crate trait ToUniverseInfo<'tcx> {
8278
fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx>;
8379
}
8480

85-
impl<'tcx> ToUniverseInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> {
86-
fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
87-
UniverseInfo(UniverseInfoInner::TypeOp(Rc::new(crate::type_check::InstantiateOpaqueType {
88-
base_universe: Some(base_universe),
89-
..self
90-
})))
91-
}
92-
}
93-
9481
impl<'tcx> ToUniverseInfo<'tcx>
9582
for Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::prove_predicate::ProvePredicate<'tcx>>>
9683
{
@@ -131,12 +118,6 @@ impl<'tcx, F, G> ToUniverseInfo<'tcx> for Canonical<'tcx, type_op::custom::Custo
131118
}
132119
}
133120

134-
impl<'tcx> ToUniverseInfo<'tcx> for ! {
135-
fn to_universe_info(self, _base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
136-
self
137-
}
138-
}
139-
140121
#[allow(unused_lifetimes)]
141122
trait TypeOpInfo<'tcx> {
142123
/// Returns an error to be reported if rerunning the type op fails to
@@ -147,7 +128,7 @@ trait TypeOpInfo<'tcx> {
147128

148129
fn nice_error(
149130
&self,
150-
mbcx: &mut MirBorrowckCtxt<'_, 'tcx>,
131+
tcx: TyCtxt<'tcx>,
151132
cause: ObligationCause<'tcx>,
152133
placeholder_region: ty::Region<'tcx>,
153134
error_region: Option<ty::Region<'tcx>>,
@@ -194,7 +175,7 @@ trait TypeOpInfo<'tcx> {
194175
debug!(?placeholder_region);
195176

196177
let span = cause.span;
197-
let nice_error = self.nice_error(mbcx, cause, placeholder_region, error_region);
178+
let nice_error = self.nice_error(tcx, cause, placeholder_region, error_region);
198179

199180
if let Some(nice_error) = nice_error {
200181
nice_error.buffer(&mut mbcx.errors_buffer);
@@ -223,16 +204,16 @@ impl<'tcx> TypeOpInfo<'tcx> for PredicateQuery<'tcx> {
223204

224205
fn nice_error(
225206
&self,
226-
mbcx: &mut MirBorrowckCtxt<'_, 'tcx>,
207+
tcx: TyCtxt<'tcx>,
227208
cause: ObligationCause<'tcx>,
228209
placeholder_region: ty::Region<'tcx>,
229210
error_region: Option<ty::Region<'tcx>>,
230211
) -> Option<DiagnosticBuilder<'tcx>> {
231-
mbcx.infcx.tcx.infer_ctxt().enter_with_canonical(
212+
tcx.infer_ctxt().enter_with_canonical(
232213
cause.span,
233214
&self.canonical_query,
234215
|ref infcx, key, _| {
235-
let mut fulfill_cx = <dyn TraitEngine<'_>>::new(infcx.tcx);
216+
let mut fulfill_cx = <dyn TraitEngine<'_>>::new(tcx);
236217
type_op_prove_predicate_with_cause(infcx, &mut *fulfill_cx, key, cause);
237218
try_extract_error_from_fulfill_cx(
238219
fulfill_cx,
@@ -266,16 +247,16 @@ where
266247

267248
fn nice_error(
268249
&self,
269-
mbcx: &mut MirBorrowckCtxt<'_, 'tcx>,
250+
tcx: TyCtxt<'tcx>,
270251
cause: ObligationCause<'tcx>,
271252
placeholder_region: ty::Region<'tcx>,
272253
error_region: Option<ty::Region<'tcx>>,
273254
) -> Option<DiagnosticBuilder<'tcx>> {
274-
mbcx.infcx.tcx.infer_ctxt().enter_with_canonical(
255+
tcx.infer_ctxt().enter_with_canonical(
275256
cause.span,
276257
&self.canonical_query,
277258
|ref infcx, key, _| {
278-
let mut fulfill_cx = <dyn TraitEngine<'_>>::new(infcx.tcx);
259+
let mut fulfill_cx = <dyn TraitEngine<'_>>::new(tcx);
279260

280261
let mut selcx = SelectionContext::new(infcx);
281262

@@ -323,16 +304,16 @@ impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
323304

324305
fn nice_error(
325306
&self,
326-
mbcx: &mut MirBorrowckCtxt<'_, 'tcx>,
307+
tcx: TyCtxt<'tcx>,
327308
cause: ObligationCause<'tcx>,
328309
placeholder_region: ty::Region<'tcx>,
329310
error_region: Option<ty::Region<'tcx>>,
330311
) -> Option<DiagnosticBuilder<'tcx>> {
331-
mbcx.infcx.tcx.infer_ctxt().enter_with_canonical(
312+
tcx.infer_ctxt().enter_with_canonical(
332313
cause.span,
333314
&self.canonical_query,
334315
|ref infcx, key, _| {
335-
let mut fulfill_cx = <dyn TraitEngine<'_>>::new(infcx.tcx);
316+
let mut fulfill_cx = <dyn TraitEngine<'_>>::new(tcx);
336317
type_op_ascribe_user_type_with_span(infcx, &mut *fulfill_cx, key, Some(cause.span))
337318
.ok()?;
338319
try_extract_error_from_fulfill_cx(
@@ -346,90 +327,43 @@ impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
346327
}
347328
}
348329

349-
impl<'tcx> TypeOpInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> {
350-
fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
351-
// FIXME: This error message isn't great, but it doesn't show up in the existing UI tests,
352-
// and is only the fallback when the nice error fails. Consider improving this some more.
353-
tcx.sess.struct_span_err(span, "higher-ranked lifetime error for opaque type!")
354-
}
355-
356-
fn base_universe(&self) -> ty::UniverseIndex {
357-
self.base_universe.unwrap()
358-
}
359-
360-
fn nice_error(
361-
&self,
362-
mbcx: &mut MirBorrowckCtxt<'_, 'tcx>,
363-
_cause: ObligationCause<'tcx>,
364-
placeholder_region: ty::Region<'tcx>,
365-
error_region: Option<ty::Region<'tcx>>,
366-
) -> Option<DiagnosticBuilder<'tcx>> {
367-
try_extract_error_from_region_constraints(
368-
mbcx.infcx,
369-
placeholder_region,
370-
error_region,
371-
self.region_constraints.as_ref().unwrap(),
372-
// We're using the original `InferCtxt` that we
373-
// started MIR borrowchecking with, so the region
374-
// constraints have already been taken. Use the data from
375-
// our `mbcx` instead.
376-
|vid| mbcx.regioncx.var_infos[vid].origin,
377-
|vid| mbcx.regioncx.var_infos[vid].universe,
378-
)
379-
}
380-
}
381-
382330
#[instrument(skip(fulfill_cx, infcx), level = "debug")]
383331
fn try_extract_error_from_fulfill_cx<'tcx>(
384332
mut fulfill_cx: Box<dyn TraitEngine<'tcx> + 'tcx>,
385333
infcx: &InferCtxt<'_, 'tcx>,
386334
placeholder_region: ty::Region<'tcx>,
387335
error_region: Option<ty::Region<'tcx>>,
388336
) -> Option<DiagnosticBuilder<'tcx>> {
337+
let tcx = infcx.tcx;
338+
389339
// We generally shouldn't have errors here because the query was
390340
// already run, but there's no point using `delay_span_bug`
391341
// when we're going to emit an error here anyway.
392342
let _errors = fulfill_cx.select_all_or_error(infcx);
393-
let region_constraints = infcx.with_region_constraints(|r| r.clone());
394-
try_extract_error_from_region_constraints(
395-
infcx,
396-
placeholder_region,
397-
error_region,
398-
&region_constraints,
399-
|vid| infcx.region_var_origin(vid),
400-
|vid| infcx.universe_of_region(infcx.tcx.mk_region(ty::ReVar(vid))),
401-
)
402-
}
403343

404-
fn try_extract_error_from_region_constraints<'tcx>(
405-
infcx: &InferCtxt<'_, 'tcx>,
406-
placeholder_region: ty::Region<'tcx>,
407-
error_region: Option<ty::Region<'tcx>>,
408-
region_constraints: &RegionConstraintData<'tcx>,
409-
mut region_var_origin: impl FnMut(RegionVid) -> RegionVariableOrigin,
410-
mut universe_of_region: impl FnMut(RegionVid) -> UniverseIndex,
411-
) -> Option<DiagnosticBuilder<'tcx>> {
412-
let (sub_region, cause) =
344+
let (sub_region, cause) = infcx.with_region_constraints(|region_constraints| {
345+
debug!("{:#?}", region_constraints);
413346
region_constraints.constraints.iter().find_map(|(constraint, cause)| {
414347
match *constraint {
415348
Constraint::RegSubReg(sub, sup) if sup == placeholder_region && sup != sub => {
416349
Some((sub, cause.clone()))
417350
}
418351
// FIXME: Should this check the universe of the var?
419352
Constraint::VarSubReg(vid, sup) if sup == placeholder_region => {
420-
Some((infcx.tcx.mk_region(ty::ReVar(vid)), cause.clone()))
353+
Some((tcx.mk_region(ty::ReVar(vid)), cause.clone()))
421354
}
422355
_ => None,
423356
}
424-
})?;
357+
})
358+
})?;
425359

426360
debug!(?sub_region, "cause = {:#?}", cause);
427361
let nice_error = match (error_region, sub_region) {
428362
(Some(error_region), &ty::ReVar(vid)) => NiceRegionError::new(
429363
infcx,
430364
RegionResolutionError::SubSupConflict(
431365
vid,
432-
region_var_origin(vid),
366+
infcx.region_var_origin(vid),
433367
cause.clone(),
434368
error_region,
435369
cause.clone(),
@@ -446,8 +380,8 @@ fn try_extract_error_from_region_constraints<'tcx>(
446380
infcx,
447381
RegionResolutionError::UpperBoundUniverseConflict(
448382
vid,
449-
region_var_origin(vid),
450-
universe_of_region(vid),
383+
infcx.region_var_origin(vid),
384+
infcx.universe_of_region(sub_region),
451385
cause.clone(),
452386
placeholder_region,
453387
),

compiler/rustc_borrowck/src/lib.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#![feature(crate_visibility_modifier)]
66
#![feature(let_else)]
77
#![feature(min_specialization)]
8-
#![feature(never_type)]
98
#![feature(stmt_expr_attributes)]
109
#![feature(trusted_step)]
1110
#![feature(try_blocks)]
@@ -125,9 +124,8 @@ fn mir_borrowck<'tcx>(
125124
) -> &'tcx BorrowCheckResult<'tcx> {
126125
let (input_body, promoted) = tcx.mir_promoted(def);
127126
debug!("run query mir_borrowck: {}", tcx.def_path_str(def.did.to_def_id()));
128-
let hir_owner = tcx.hir().local_def_id_to_hir_id(def.did).owner;
129127

130-
let opt_closure_req = tcx.infer_ctxt().with_opaque_type_inference(hir_owner).enter(|infcx| {
128+
let opt_closure_req = tcx.infer_ctxt().with_opaque_type_inference(def.did).enter(|infcx| {
131129
let input_body: &Body<'_> = &input_body.borrow();
132130
let promoted: &IndexVec<_, _> = &promoted.borrow();
133131
do_mir_borrowck(&infcx, input_body, promoted, false).0
@@ -142,7 +140,7 @@ fn mir_borrowck<'tcx>(
142140
/// If `return_body_with_facts` is true, then return the body with non-erased
143141
/// region ids on which the borrow checking was performed together with Polonius
144142
/// facts.
145-
#[instrument(skip(infcx, input_body, input_promoted), fields(id=?input_body.source.with_opt_param().as_local().unwrap()), level = "debug")]
143+
#[instrument(skip(infcx, input_body, input_promoted), level = "debug")]
146144
fn do_mir_borrowck<'a, 'tcx>(
147145
infcx: &InferCtxt<'a, 'tcx>,
148146
input_body: &Body<'tcx>,

compiler/rustc_borrowck/src/region_infer/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ mod reverse_sccs;
4444
pub mod values;
4545

4646
pub struct RegionInferenceContext<'tcx> {
47-
pub var_infos: VarInfos,
4847
/// Contains the definition for every region variable. Region
4948
/// variables are identified by their index (`RegionVid`). The
5049
/// definition contains information about where the region came
@@ -267,7 +266,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
267266
) -> Self {
268267
// Create a RegionDefinition for each inference variable.
269268
let definitions: IndexVec<_, _> = var_infos
270-
.iter()
269+
.into_iter()
271270
.map(|info| RegionDefinition::new(info.universe, info.origin))
272271
.collect();
273272

@@ -292,7 +291,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
292291
Rc::new(member_constraints_in.into_mapped(|r| constraint_sccs.scc(r)));
293292

294293
let mut result = Self {
295-
var_infos,
296294
definitions,
297295
liveness_constraints,
298296
constraints,

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+20-38
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use rustc_data_structures::fx::FxHashMap;
22
use rustc_data_structures::vec_map::VecMap;
33
use rustc_hir::OpaqueTyOrigin;
4+
use rustc_infer::infer::opaque_types::OpaqueTypeDecl;
45
use rustc_infer::infer::InferCtxt;
56
use rustc_middle::ty::subst::GenericArgKind;
67
use rustc_middle::ty::{self, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable};
@@ -53,44 +54,27 @@ impl<'tcx> RegionInferenceContext<'tcx> {
5354
pub(crate) fn infer_opaque_types(
5455
&self,
5556
infcx: &InferCtxt<'_, 'tcx>,
56-
opaque_ty_decls: VecMap<OpaqueTypeKey<'tcx>, (Ty<'tcx>, Span, OpaqueTyOrigin)>,
57+
opaque_ty_decls: VecMap<OpaqueTypeKey<'tcx>, OpaqueTypeDecl<'tcx>>,
5758
span: Span,
5859
) -> VecMap<OpaqueTypeKey<'tcx>, Ty<'tcx>> {
5960
opaque_ty_decls
6061
.into_iter()
61-
.map(|(opaque_type_key, (concrete_type, decl_span, origin))| {
62+
.filter_map(|(opaque_type_key, decl)| {
6263
let substs = opaque_type_key.substs;
63-
// FIXME: why are the spans in decl_span often DUMMY_SP?
64-
let span = decl_span.substitute_dummy(span);
64+
let concrete_type = decl.concrete_ty;
6565
debug!(?concrete_type, ?substs);
6666

6767
let mut subst_regions = vec![self.universal_regions.fr_static];
6868
let universal_substs = infcx.tcx.fold_regions(substs, &mut false, |region, _| {
69-
if let ty::RePlaceholder(..) = region {
70-
// Higher kinded regions don't need remapping, they don't refer to anything outside of this the substs.
71-
return region;
72-
}
73-
let vid = self.to_region_vid(region);
74-
trace!(?vid);
75-
let scc = self.constraint_sccs.scc(vid);
76-
trace!(?scc);
77-
match self.scc_values.universal_regions_outlived_by(scc).find_map(|lb| {
78-
self.eval_equal(vid, lb).then_some(self.definitions[lb].external_name?)
79-
}) {
80-
Some(region) => {
81-
let vid = self.universal_regions.to_region_vid(region);
82-
subst_regions.push(vid);
83-
region
84-
}
85-
None => {
86-
subst_regions.push(vid);
87-
infcx.tcx.sess.delay_span_bug(
88-
span,
89-
"opaque type with non-universal region substs",
90-
);
91-
infcx.tcx.lifetimes.re_static
92-
}
93-
}
69+
let vid = self.universal_regions.to_region_vid(region);
70+
subst_regions.push(vid);
71+
self.definitions[vid].external_name.unwrap_or_else(|| {
72+
infcx
73+
.tcx
74+
.sess
75+
.delay_span_bug(span, "opaque type with non-universal region substs");
76+
infcx.tcx.lifetimes.re_static
77+
})
9478
});
9579

9680
subst_regions.sort();
@@ -116,14 +100,12 @@ impl<'tcx> RegionInferenceContext<'tcx> {
116100
span,
117101
);
118102

119-
(
103+
check_opaque_type_parameter_valid(
104+
infcx.tcx,
120105
opaque_type_key,
121-
if check_opaque_type_parameter_valid(infcx.tcx, opaque_type_key, origin, span) {
122-
remapped_type
123-
} else {
124-
infcx.tcx.ty_error()
125-
},
106+
OpaqueTypeDecl { concrete_ty: remapped_type, ..decl },
126107
)
108+
.then_some((opaque_type_key, remapped_type))
127109
})
128110
.collect()
129111
}
@@ -167,10 +149,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
167149
fn check_opaque_type_parameter_valid(
168150
tcx: TyCtxt<'_>,
169151
opaque_type_key: OpaqueTypeKey<'_>,
170-
origin: OpaqueTyOrigin,
171-
span: Span,
152+
decl: OpaqueTypeDecl<'_>,
172153
) -> bool {
173-
match origin {
154+
match decl.origin {
174155
// No need to check return position impl trait (RPIT)
175156
// because for type and const parameters they are correct
176157
// by construction: we convert
@@ -196,6 +177,7 @@ fn check_opaque_type_parameter_valid(
196177
// Check these
197178
OpaqueTyOrigin::TyAlias => {}
198179
}
180+
let span = decl.definition_span;
199181
let opaque_generics = tcx.generics_of(opaque_type_key.def_id);
200182
let mut seen_params: FxHashMap<_, Vec<_>> = FxHashMap::default();
201183
for (i, arg) in opaque_type_key.substs.iter().enumerate() {

0 commit comments

Comments
 (0)