Skip to content

Commit 8aab472

Browse files
committed
Auto merge of rust-lang#98486 - matthiaskrgr:rollup-u7m508x, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#96412 (Windows: Iterative `remove_dir_all`) - rust-lang#98126 (Mitigate MMIO stale data vulnerability) - rust-lang#98149 (Set relocation_model to Pic on emscripten target) - rust-lang#98194 (Leak pthread_{mutex,rwlock}_t if it's dropped while locked.) - rust-lang#98298 (Point to type parameter definition when not finding variant, method and associated item) - rust-lang#98311 (Reverse folder hierarchy) - rust-lang#98401 (Add tracking issues to `--extern` option docs.) - rust-lang#98429 (Use correct substs in enum discriminant cast) - rust-lang#98431 (Suggest defining variable as mutable on `&mut _` type mismatch in pats) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 00ce472 + 1f923c2 commit 8aab472

File tree

85 files changed

+766
-371
lines changed

Some content is hidden

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

85 files changed

+766
-371
lines changed

compiler/rustc_infer/src/infer/resolve.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for OpportunisticRegionResolver<'a, 'tcx> {
9292
.borrow_mut()
9393
.unwrap_region_constraints()
9494
.opportunistic_resolve_var(rid);
95-
self.tcx().reuse_or_mk_region(r, ty::ReVar(resolved))
95+
TypeFolder::tcx(self).reuse_or_mk_region(r, ty::ReVar(resolved))
9696
}
9797
_ => r,
9898
}
@@ -179,15 +179,13 @@ struct FullTypeResolver<'a, 'tcx> {
179179
infcx: &'a InferCtxt<'a, 'tcx>,
180180
}
181181

182-
impl<'a, 'tcx> TypeFolder<'tcx> for FullTypeResolver<'a, 'tcx> {
182+
impl<'a, 'tcx> FallibleTypeFolder<'tcx> for FullTypeResolver<'a, 'tcx> {
183183
type Error = FixupError<'tcx>;
184184

185185
fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
186186
self.infcx.tcx
187187
}
188-
}
189188

190-
impl<'a, 'tcx> FallibleTypeFolder<'tcx> for FullTypeResolver<'a, 'tcx> {
191189
fn try_fold_ty(&mut self, t: Ty<'tcx>) -> Result<Ty<'tcx>, Self::Error> {
192190
if !t.needs_infer() {
193191
Ok(t) // micro-optimize -- if there is nothing in this type that this fold affects...

compiler/rustc_middle/src/ty/fold.rs

+34-51
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
8686
/// A convenient alternative to `try_fold_with` for use with infallible
8787
/// folders. Do not override this method, to ensure coherence with
8888
/// `try_fold_with`.
89-
fn fold_with<F: TypeFolder<'tcx, Error = !>>(self, folder: &mut F) -> Self {
89+
fn fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
9090
self.try_fold_with(folder).into_ok()
9191
}
9292

@@ -216,7 +216,7 @@ pub trait TypeSuperFoldable<'tcx>: TypeFoldable<'tcx> {
216216
/// A convenient alternative to `try_super_fold_with` for use with
217217
/// infallible folders. Do not override this method, to ensure coherence
218218
/// with `try_super_fold_with`.
219-
fn super_fold_with<F: TypeFolder<'tcx, Error = !>>(self, folder: &mut F) -> Self {
219+
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
220220
self.try_super_fold_with(folder).into_ok()
221221
}
222222

@@ -229,70 +229,46 @@ pub trait TypeSuperFoldable<'tcx>: TypeFoldable<'tcx> {
229229
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy>;
230230
}
231231

232-
/// This trait is implemented for every folding traversal. There is a fold
233-
/// method defined for every type of interest. Each such method has a default
234-
/// that does an "identity" fold. Implementations of these methods often fall
235-
/// back to a `super_fold_with` method if the primary argument doesn't
236-
/// satisfy a particular condition.
232+
/// This trait is implemented for every infallible folding traversal. There is
233+
/// a fold method defined for every type of interest. Each such method has a
234+
/// default that does an "identity" fold. Implementations of these methods
235+
/// often fall back to a `super_fold_with` method if the primary argument
236+
/// doesn't satisfy a particular condition.
237237
///
238-
/// If this folder is fallible (and therefore its [`Error`][`TypeFolder::Error`]
239-
/// associated type is something other than the default `!`) then
240-
/// [`FallibleTypeFolder`] should be implemented manually. Otherwise,
241-
/// a blanket implementation of [`FallibleTypeFolder`] will defer to
238+
/// A blanket implementation of [`FallibleTypeFolder`] will defer to
242239
/// the infallible methods of this trait to ensure that the two APIs
243240
/// are coherent.
244-
pub trait TypeFolder<'tcx>: Sized {
245-
type Error = !;
246-
241+
pub trait TypeFolder<'tcx>: FallibleTypeFolder<'tcx, Error = !> {
247242
fn tcx<'a>(&'a self) -> TyCtxt<'tcx>;
248243

249244
fn fold_binder<T>(&mut self, t: Binder<'tcx, T>) -> Binder<'tcx, T>
250245
where
251246
T: TypeFoldable<'tcx>,
252-
Self: TypeFolder<'tcx, Error = !>,
253247
{
254248
t.super_fold_with(self)
255249
}
256250

257-
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx>
258-
where
259-
Self: TypeFolder<'tcx, Error = !>,
260-
{
251+
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
261252
t.super_fold_with(self)
262253
}
263254

264-
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx>
265-
where
266-
Self: TypeFolder<'tcx, Error = !>,
267-
{
255+
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
268256
r.super_fold_with(self)
269257
}
270258

271-
fn fold_const(&mut self, c: ty::Const<'tcx>) -> ty::Const<'tcx>
272-
where
273-
Self: TypeFolder<'tcx, Error = !>,
274-
{
259+
fn fold_const(&mut self, c: ty::Const<'tcx>) -> ty::Const<'tcx> {
275260
c.super_fold_with(self)
276261
}
277262

278-
fn fold_unevaluated(&mut self, uv: ty::Unevaluated<'tcx>) -> ty::Unevaluated<'tcx>
279-
where
280-
Self: TypeFolder<'tcx, Error = !>,
281-
{
263+
fn fold_unevaluated(&mut self, uv: ty::Unevaluated<'tcx>) -> ty::Unevaluated<'tcx> {
282264
uv.super_fold_with(self)
283265
}
284266

285-
fn fold_predicate(&mut self, p: ty::Predicate<'tcx>) -> ty::Predicate<'tcx>
286-
where
287-
Self: TypeFolder<'tcx, Error = !>,
288-
{
267+
fn fold_predicate(&mut self, p: ty::Predicate<'tcx>) -> ty::Predicate<'tcx> {
289268
p.super_fold_with(self)
290269
}
291270

292-
fn fold_mir_const(&mut self, c: mir::ConstantKind<'tcx>) -> mir::ConstantKind<'tcx>
293-
where
294-
Self: TypeFolder<'tcx, Error = !>,
295-
{
271+
fn fold_mir_const(&mut self, c: mir::ConstantKind<'tcx>) -> mir::ConstantKind<'tcx> {
296272
bug!("most type folders should not be folding MIR datastructures: {:?}", c)
297273
}
298274
}
@@ -304,7 +280,11 @@ pub trait TypeFolder<'tcx>: Sized {
304280
/// A blanket implementation of this trait (that defers to the relevant
305281
/// method of [`TypeFolder`]) is provided for all infallible folders in
306282
/// order to ensure the two APIs are coherent.
307-
pub trait FallibleTypeFolder<'tcx>: TypeFolder<'tcx> {
283+
pub trait FallibleTypeFolder<'tcx>: Sized {
284+
type Error;
285+
286+
fn tcx<'a>(&'a self) -> TyCtxt<'tcx>;
287+
308288
fn try_fold_binder<T>(&mut self, t: Binder<'tcx, T>) -> Result<Binder<'tcx, T>, Self::Error>
309289
where
310290
T: TypeFoldable<'tcx>,
@@ -350,45 +330,48 @@ pub trait FallibleTypeFolder<'tcx>: TypeFolder<'tcx> {
350330
// delegates to infallible methods to ensure coherence.
351331
impl<'tcx, F> FallibleTypeFolder<'tcx> for F
352332
where
353-
F: TypeFolder<'tcx, Error = !>,
333+
F: TypeFolder<'tcx>,
354334
{
355-
fn try_fold_binder<T>(&mut self, t: Binder<'tcx, T>) -> Result<Binder<'tcx, T>, Self::Error>
335+
type Error = !;
336+
337+
fn tcx<'a>(&'a self) -> TyCtxt<'tcx> {
338+
TypeFolder::tcx(self)
339+
}
340+
341+
fn try_fold_binder<T>(&mut self, t: Binder<'tcx, T>) -> Result<Binder<'tcx, T>, !>
356342
where
357343
T: TypeFoldable<'tcx>,
358344
{
359345
Ok(self.fold_binder(t))
360346
}
361347

362-
fn try_fold_ty(&mut self, t: Ty<'tcx>) -> Result<Ty<'tcx>, Self::Error> {
348+
fn try_fold_ty(&mut self, t: Ty<'tcx>) -> Result<Ty<'tcx>, !> {
363349
Ok(self.fold_ty(t))
364350
}
365351

366-
fn try_fold_region(&mut self, r: ty::Region<'tcx>) -> Result<ty::Region<'tcx>, Self::Error> {
352+
fn try_fold_region(&mut self, r: ty::Region<'tcx>) -> Result<ty::Region<'tcx>, !> {
367353
Ok(self.fold_region(r))
368354
}
369355

370-
fn try_fold_const(&mut self, c: ty::Const<'tcx>) -> Result<ty::Const<'tcx>, Self::Error> {
356+
fn try_fold_const(&mut self, c: ty::Const<'tcx>) -> Result<ty::Const<'tcx>, !> {
371357
Ok(self.fold_const(c))
372358
}
373359

374360
fn try_fold_unevaluated(
375361
&mut self,
376362
c: ty::Unevaluated<'tcx>,
377-
) -> Result<ty::Unevaluated<'tcx>, Self::Error> {
363+
) -> Result<ty::Unevaluated<'tcx>, !> {
378364
Ok(self.fold_unevaluated(c))
379365
}
380366

381-
fn try_fold_predicate(
382-
&mut self,
383-
p: ty::Predicate<'tcx>,
384-
) -> Result<ty::Predicate<'tcx>, Self::Error> {
367+
fn try_fold_predicate(&mut self, p: ty::Predicate<'tcx>) -> Result<ty::Predicate<'tcx>, !> {
385368
Ok(self.fold_predicate(p))
386369
}
387370

388371
fn try_fold_mir_const(
389372
&mut self,
390373
c: mir::ConstantKind<'tcx>,
391-
) -> Result<mir::ConstantKind<'tcx>, Self::Error> {
374+
) -> Result<mir::ConstantKind<'tcx>, !> {
392375
Ok(self.fold_mir_const(c))
393376
}
394377
}

compiler/rustc_middle/src/ty/normalize_erasing_regions.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,13 @@ impl<'tcx> TryNormalizeAfterErasingRegionsFolder<'tcx> {
228228
}
229229
}
230230

231-
impl<'tcx> TypeFolder<'tcx> for TryNormalizeAfterErasingRegionsFolder<'tcx> {
231+
impl<'tcx> FallibleTypeFolder<'tcx> for TryNormalizeAfterErasingRegionsFolder<'tcx> {
232232
type Error = NormalizationError<'tcx>;
233233

234234
fn tcx(&self) -> TyCtxt<'tcx> {
235235
self.tcx
236236
}
237-
}
238237

239-
impl<'tcx> FallibleTypeFolder<'tcx> for TryNormalizeAfterErasingRegionsFolder<'tcx> {
240238
fn try_fold_ty(&mut self, ty: Ty<'tcx>) -> Result<Ty<'tcx>, Self::Error> {
241239
match self.try_normalize_generic_arg_after_erasing_regions(ty.into()) {
242240
Ok(t) => Ok(t.expect_ty()),

compiler/rustc_middle/src/ty/subst.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
705705
return val;
706706
}
707707

708-
let result = ty::fold::shift_vars(self.tcx(), val, self.binders_passed);
708+
let result = ty::fold::shift_vars(TypeFolder::tcx(self), val, self.binders_passed);
709709
debug!("shift_vars: shifted result = {:?}", result);
710710

711711
result

0 commit comments

Comments
 (0)