Skip to content

Commit 6b42110

Browse files
committed
rustc: don't thread existential projections through path_generic_args.
1 parent ac3c32c commit 6b42110

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
@@ -55,7 +55,7 @@ use hir;
5555
use hir::def_id::DefId;
5656
use hir::Node;
5757
use middle::region;
58-
use std::{cmp, fmt, iter};
58+
use std::{cmp, fmt};
5959
use syntax::ast::DUMMY_NODE_ID;
6060
use syntax_pos::{Pos, Span};
6161
use traits::{ObligationCause, ObligationCauseCode};
@@ -459,6 +459,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
459459
type Path = Vec<String>;
460460
type Region = !;
461461
type Type = !;
462+
type DynExistential = !;
462463

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

478+
fn print_dyn_existential<'tcx>(
479+
self: PrintCx<'_, '_, 'tcx, Self>,
480+
_predicates: &'tcx ty::List<ty::ExistentialPredicate<'tcx>>,
481+
) -> Result<Self::DynExistential, Self::Error> {
482+
Err(NonTrivialPath)
483+
}
484+
477485
fn path_crate(
478486
self: PrintCx<'_, '_, '_, Self>,
479487
cnum: CrateNum,
@@ -514,8 +522,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
514522
print_prefix: impl FnOnce(
515523
PrintCx<'_, 'gcx, 'tcx, Self>,
516524
) -> Result<Self::Path, Self::Error>,
517-
_args: impl Iterator<Item = Kind<'tcx>> + Clone,
518-
_projections: impl Iterator<Item = ty::ExistentialProjection<'tcx>>,
525+
_args: &[Kind<'tcx>],
519526
) -> Result<Self::Path, Self::Error> {
520527
print_prefix(self)
521528
}
@@ -527,7 +534,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
527534
if !(did1.is_local() || did2.is_local()) && did1.krate != did2.krate {
528535
let abs_path = |def_id| {
529536
PrintCx::new(self.tcx, AbsolutePathPrinter)
530-
.print_def_path(def_id, None, iter::empty())
537+
.print_def_path(def_id, None)
531538
};
532539

533540
// 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
@@ -2381,7 +2381,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
23812381
let f = &mut *fmt;
23822382
PrintCx::with_tls_tcx(FmtPrinter::new(f, Namespace::ValueNS), |cx| {
23832383
let substs = cx.tcx.lift(&substs).expect("could not lift for printing");
2384-
cx.print_def_path(variant_def.did, Some(substs), iter::empty())?;
2384+
cx.print_def_path(variant_def.did, Some(substs))?;
23852385
Ok(())
23862386
})?;
23872387

src/librustc/ty/instance.rs

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

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 ty::subst::{Kind, Subst, Substs};
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<&'tcx Substs<'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<&'tcx Substs<'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: &'tcx Substs<'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, .. } => {
@@ -225,9 +230,8 @@ impl<P: Printer> PrintCx<'_, 'gcx, 'tcx, P> {
225230
}
226231
}
227232
}).count();
228-
params[..params.len() - num_supplied_defaults].iter().map(move |param| {
229-
substs[param.index as usize]
230-
})
233+
234+
&substs[own_params]
231235
}
232236

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

0 commit comments

Comments
 (0)