Skip to content

Commit c0c485c

Browse files
committed
rustc: don't thread existential projections through path_generic_args.
1 parent ffa00d4 commit c0c485c

File tree

8 files changed

+251
-156
lines changed

8 files changed

+251
-156
lines changed

src/librustc/infer/error_reporting/mod.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use crate::traits::{ObligationCause, ObligationCauseCode};
5858
use crate::ty::error::TypeError;
5959
use crate::ty::{self, subst::{Subst, SubstsRef}, Region, Ty, TyCtxt, TyKind, TypeFoldable};
6060
use errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
61-
use std::{cmp, fmt, iter};
61+
use std::{cmp, fmt};
6262
use syntax_pos::{Pos, Span};
6363

6464
mod note;
@@ -458,6 +458,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
458458
type Path = Vec<String>;
459459
type Region = !;
460460
type Type = !;
461+
type DynExistential = !;
461462

462463
fn print_region(
463464
self: PrintCx<'_, '_, '_, Self>,
@@ -473,6 +474,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
473474
Err(NonTrivialPath)
474475
}
475476

477+
fn print_dyn_existential<'tcx>(
478+
self: PrintCx<'_, '_, 'tcx, Self>,
479+
_predicates: &'tcx ty::List<ty::ExistentialPredicate<'tcx>>,
480+
) -> Result<Self::DynExistential, Self::Error> {
481+
Err(NonTrivialPath)
482+
}
483+
476484
fn path_crate(
477485
self: PrintCx<'_, '_, '_, Self>,
478486
cnum: CrateNum,
@@ -513,8 +521,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
513521
print_prefix: impl FnOnce(
514522
PrintCx<'_, 'gcx, 'tcx, Self>,
515523
) -> Result<Self::Path, Self::Error>,
516-
_args: impl Iterator<Item = Kind<'tcx>> + Clone,
517-
_projections: impl Iterator<Item = ty::ExistentialProjection<'tcx>>,
524+
_args: &[Kind<'tcx>],
518525
) -> Result<Self::Path, Self::Error> {
519526
print_prefix(self)
520527
}
@@ -526,7 +533,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
526533
if !(did1.is_local() || did2.is_local()) && did1.krate != did2.krate {
527534
let abs_path = |def_id| {
528535
PrintCx::new(self.tcx, AbsolutePathPrinter)
529-
.print_def_path(def_id, None, iter::empty())
536+
.print_def_path(def_id, None)
530537
};
531538

532539
// We compare strings because DefPath can be different

src/librustc/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2409,7 +2409,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
24092409
let f = &mut *fmt;
24102410
PrintCx::with_tls_tcx(FmtPrinter::new(f, Namespace::ValueNS), |cx| {
24112411
let substs = cx.tcx.lift(&substs).expect("could not lift for printing");
2412-
cx.print_def_path(variant_def.did, Some(substs), iter::empty())?;
2412+
cx.print_def_path(variant_def.did, Some(substs))?;
24132413
Ok(())
24142414
})?;
24152415

src/librustc/ty/instance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl<'tcx> fmt::Display for Instance<'tcx> {
178178
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
179179
PrintCx::with_tls_tcx(FmtPrinter::new(&mut *f, Namespace::ValueNS), |cx| {
180180
let substs = cx.tcx.lift(&self.substs).expect("could not lift for printing");
181-
cx.print_def_path(self.def_id(), Some(substs), iter::empty())?;
181+
cx.print_def_path(self.def_id(), Some(substs))?;
182182
Ok(())
183183
})?;
184184

src/librustc/ty/print/mod.rs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::ty::subst::{Kind, Subst, SubstsRef};
55

66
use rustc_data_structures::fx::FxHashSet;
77

8-
use std::iter;
98
use std::ops::{Deref, DerefMut};
109

1110
// `pretty` is a separate module only for organization.
@@ -64,14 +63,14 @@ pub trait Printer: Sized {
6463
type Path;
6564
type Region;
6665
type Type;
66+
type DynExistential;
6767

6868
fn print_def_path(
6969
self: PrintCx<'_, '_, 'tcx, Self>,
7070
def_id: DefId,
7171
substs: Option<SubstsRef<'tcx>>,
72-
projections: impl Iterator<Item = ty::ExistentialProjection<'tcx>>,
7372
) -> Result<Self::Path, Self::Error> {
74-
self.default_print_def_path(def_id, substs, projections)
73+
self.default_print_def_path(def_id, substs)
7574
}
7675
fn print_impl_path(
7776
self: PrintCx<'_, '_, 'tcx, Self>,
@@ -93,6 +92,11 @@ pub trait Printer: Sized {
9392
ty: Ty<'tcx>,
9493
) -> Result<Self::Type, Self::Error>;
9594

95+
fn print_dyn_existential(
96+
self: PrintCx<'_, '_, 'tcx, Self>,
97+
predicates: &'tcx ty::List<ty::ExistentialPredicate<'tcx>>,
98+
) -> Result<Self::DynExistential, Self::Error>;
99+
96100
fn path_crate(
97101
self: PrintCx<'_, '_, '_, Self>,
98102
cnum: CrateNum,
@@ -123,8 +127,7 @@ pub trait Printer: Sized {
123127
print_prefix: impl FnOnce(
124128
PrintCx<'_, 'gcx, 'tcx, Self>,
125129
) -> Result<Self::Path, Self::Error>,
126-
args: impl Iterator<Item = Kind<'tcx>> + Clone,
127-
projections: impl Iterator<Item = ty::ExistentialProjection<'tcx>>,
130+
args: &[Kind<'tcx>],
128131
) -> Result<Self::Path, Self::Error>;
129132
}
130133

@@ -133,7 +136,6 @@ impl<P: Printer> PrintCx<'_, 'gcx, 'tcx, P> {
133136
self,
134137
def_id: DefId,
135138
substs: Option<SubstsRef<'tcx>>,
136-
projections: impl Iterator<Item = ty::ExistentialProjection<'tcx>>,
137139
) -> Result<P::Path, P::Error> {
138140
debug!("default_print_def_path: def_id={:?}, substs={:?}", def_id, substs);
139141
let key = self.tcx.def_key(def_id);
@@ -175,10 +177,10 @@ impl<P: Printer> PrintCx<'_, 'gcx, 'tcx, P> {
175177
let trait_ref = ty::TraitRef::new(parent_def_id, substs);
176178
cx.path_qualified(trait_ref.self_ty(), Some(trait_ref))
177179
} else {
178-
cx.print_def_path(parent_def_id, substs, iter::empty())
180+
cx.print_def_path(parent_def_id, substs)
179181
}
180182
} else {
181-
cx.print_def_path(parent_def_id, None, iter::empty())
183+
cx.print_def_path(parent_def_id, None)
182184
}
183185
};
184186
let print_path = |cx: PrintCx<'_, 'gcx, 'tcx, P>| {
@@ -197,7 +199,7 @@ impl<P: Printer> PrintCx<'_, 'gcx, 'tcx, P> {
197199

198200
if let (Some(generics), Some(substs)) = (generics, substs) {
199201
let args = self.generic_args_to_print(generics, substs);
200-
self.path_generic_args(print_path, args, projections)
202+
self.path_generic_args(print_path, args)
201203
} else {
202204
print_path(self)
203205
}
@@ -209,13 +211,16 @@ impl<P: Printer> PrintCx<'_, 'gcx, 'tcx, P> {
209211
&self,
210212
generics: &'tcx ty::Generics,
211213
substs: SubstsRef<'tcx>,
212-
) -> impl Iterator<Item = Kind<'tcx>> + Clone {
214+
) -> &'tcx [Kind<'tcx>] {
215+
let mut own_params = generics.parent_count..generics.count();
216+
213217
// Don't print args for `Self` parameters (of traits).
214-
let has_own_self = generics.has_self && generics.parent_count == 0;
215-
let params = &generics.params[has_own_self as usize..];
218+
if generics.has_self && own_params.start == 0 {
219+
own_params.start = 1;
220+
}
216221

217222
// Don't print args that are the defaults of their respective parameters.
218-
let num_supplied_defaults = params.iter().rev().take_while(|param| {
223+
own_params.end -= generics.params.iter().rev().take_while(|param| {
219224
match param.kind {
220225
ty::GenericParamDefKind::Lifetime => false,
221226
ty::GenericParamDefKind::Type { has_default, .. } => {
@@ -226,9 +231,8 @@ impl<P: Printer> PrintCx<'_, 'gcx, 'tcx, P> {
226231
ty::GenericParamDefKind::Const => false, // FIXME(const_generics:defaults)
227232
}
228233
}).count();
229-
params[..params.len() - num_supplied_defaults].iter().map(move |param| {
230-
substs[param.index as usize]
231-
})
234+
235+
&substs[own_params]
232236
}
233237

234238
fn default_print_impl_path(
@@ -261,7 +265,7 @@ impl<P: Printer> PrintCx<'_, 'gcx, 'tcx, P> {
261265
// trait-type, then fallback to a format that identifies
262266
// the module more clearly.
263267
self.path_append_impl(
264-
|cx| cx.print_def_path(parent_def_id, None, iter::empty()),
268+
|cx| cx.print_def_path(parent_def_id, None),
265269
self_ty,
266270
impl_trait_ref,
267271
)
@@ -344,3 +348,11 @@ impl<P: Printer> Print<'tcx, P> for Ty<'tcx> {
344348
cx.print_type(self)
345349
}
346350
}
351+
352+
impl<P: Printer> Print<'tcx, P> for &'tcx ty::List<ty::ExistentialPredicate<'tcx>> {
353+
type Output = P::DynExistential;
354+
type Error = P::Error;
355+
fn print(&self, cx: PrintCx<'_, '_, 'tcx, P>) -> Result<Self::Output, Self::Error> {
356+
cx.print_dyn_existential(self)
357+
}
358+
}

0 commit comments

Comments
 (0)