Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
228d6f4
rustc: remove unnecessary extern_prelude logic from ty::item_path.
eddyb Dec 9, 2018
382d24e
rustc: start moving util::ppaux to ty::print.
eddyb Dec 4, 2018
297546e
rustc: add a 'tcx parameter to Print.
eddyb Dec 4, 2018
372b1a5
rustc: uniformize all lift expect messages to "could not lift for pri…
eddyb Dec 4, 2018
852fc6d
rustc: don't support `tcx.lift` returning `None` in ppaux.
eddyb Dec 4, 2018
c684814
rustc: don't support missing TLS TyCtxt in ty::print.
eddyb Dec 4, 2018
5f3841c
rustc: rename PrintContext to PrintCx.
eddyb Dec 7, 2018
0b3ab40
rustc: keep a TyCtxt in PrintCx and use it instead of ty::tls.
eddyb Dec 7, 2018
01fa283
rustc: remove fmt::{Debug,Display} from ty::TyKind.
eddyb Dec 7, 2018
3bad9f7
rustc: implement fmt::{Debug,Display} on Ty instead of TyS.
eddyb Dec 7, 2018
eb525b0
rustc: tie the 'tcx between Print and PrintCx in ty::print.
eddyb Dec 7, 2018
939c69c
rustc: use define_print! to implement fmt::{Display,Debug} for Kind.
eddyb Dec 7, 2018
fbbc7e9
rustc: rewrite PrintCx::parameterized to be much simpler and more gen…
eddyb Dec 8, 2018
1c2a3c5
rustc: support impl's in PrintCx::parameterized.
eddyb Dec 9, 2018
7505bb6
rustc_codegen_utils: revert some symbol_names refactors (while keepin…
eddyb Feb 3, 2019
7d211e5
rustc: rewrite ty::item_path to be more functional than mutation-orie…
eddyb Dec 9, 2018
387cacf
rustc: remove ty::item_path::RootMode by moving local logic into the …
eddyb Dec 10, 2018
329b8ca
rustc: always rely on '_ to be not printed by ty::Region itself.
eddyb Dec 10, 2018
732b71a
rustc: add a ty::RegionKind::display_outputs_anything method to avoid…
eddyb Dec 12, 2018
08d2744
rustc: move the formatter into ty::print::PrintCx.
eddyb Dec 10, 2018
2386168
rustc: explicitly pass the namespace to PrintCx::parameterized.
eddyb Dec 12, 2018
ed2be6f
rustc: move the FORCE_IMPL_FILENAME_LINE handling into LocalPathPrinter.
eddyb Dec 12, 2018
3e1cef7
rustc: pass Option<&Substs> and Namespace around in ty::item_path.
eddyb Dec 19, 2018
6ca6c1a
rustc_mir: adjust the type_length_limit diagnostic to be more useful.
eddyb Dec 19, 2018
f1af5a7
rustc: remove TyCtxt::parent_def_id in favor of TyCtxt::parent.
eddyb Dec 19, 2018
e0c75ff
rustc: rename item_path to def_path (except the module in ty).
eddyb Dec 19, 2018
9f8aaa0
rustc: move the contents of ty::item_path to ty::print.
eddyb Dec 19, 2018
b0fbca9
rustc: integrate LocalPathPrinter's behavior into FmtPrinter.
eddyb Dec 19, 2018
a15bfc6
rustc: merge PrintCx::parameterized and def_path printing.
eddyb Dec 21, 2018
aec5a48
rustc: move <...>-less impl path special-case to pretty_path_qualified.
eddyb Dec 21, 2018
39fd54a
rustc: move the `FORCE_IMPL_FILENAME_LINE` hack into `print_def_path`.
eddyb Dec 21, 2018
df6650f
rustc: move `...::<impl ...>` printing into `pretty_path_qualified`.
eddyb Dec 28, 2018
66cc029
rustc: assert `ty::print::FORCE_ABSOLUTE` isn't needed anymore.
eddyb Dec 28, 2018
36f64f1
rustc: remove `ty::print::FORCE_ABSOLUTE` altogether.
eddyb Dec 28, 2018
27ddf2c
rustc: replace node_path_str with uses of def_path_str.
eddyb Dec 28, 2018
387ea61
rustc: make ppaux' print macro use only one closure.
eddyb Jan 9, 2019
972af5e
rustc: rename ppaux' print macro to just p and make its cx input impl…
eddyb Jan 9, 2019
5616ca8
rustc: uniformize ty::print's error handling by requiring Result.
eddyb Jan 9, 2019
37e9185
rustc: split off most of ty::print::PrintCx's fields into a separate …
eddyb Jan 10, 2019
ab5d6fb
rustc: remove the closure from ppaux's p! macro (by making ? implicit).
eddyb Jan 10, 2019
7c4eece
rustc: pass ty::print::PrintCx by value.
eddyb Jan 10, 2019
cafd83d
rustc: don't keep RegionHighlightMode in a thread-local.
eddyb Jan 11, 2019
fc914aa
rustc: centralize region printing in ty::RegionKind's Print impl.
eddyb Jan 14, 2019
88d96b2
rustc: support overriding region printing in ty::print::Printer.
eddyb Jan 14, 2019
35e5123
rustc: support overriding type printing in ty::print::Printer.
eddyb Jan 14, 2019
ab26b26
rustc: introduce a ty::print::PrettyPrinter helper for printing "<...>".
eddyb Jan 14, 2019
5211e37
rustc: don't pass Namespace explicitly, but rather track it in FmtPri…
eddyb Jan 14, 2019
6d67d68
rustc_codegen_utils: print all nominal types as paths, in symbol names.
eddyb Jan 14, 2019
26f1807
rustc: move ty/print.rs to ty/print/mod.rs.
eddyb Jan 18, 2019
55871aa
rustc: split out the pretty-printing parts of ty::print into a separa…
eddyb Jan 18, 2019
800ddb3
rustc: remove fields from ty::print::PrintConfig available from tcx.
eddyb Jan 18, 2019
d0a1bf5
rustc: make util::ppaux private.
eddyb Jan 18, 2019
9c42485
rustc: disconnect all the Debug functionality from ty::print.
eddyb Jan 19, 2019
fb53bb9
rustc: move Debug impls from ppaux to ty::structural_impls.
eddyb Jan 19, 2019
030cdc9
rustc: remove obsolete hacks from ppaux, relating to normalization un…
eddyb Jan 20, 2019
1a0f3a2
rustc: streamline the Print/fmt::Display impls in ppaux and move them…
eddyb Jan 20, 2019
381fa7a
rustc: move ty::print::PrintConfig's fields to FmtPrinter.
eddyb Jan 20, 2019
72690d2
rustc: always hide defaulted generic args, even in verbose mode.
eddyb Jan 23, 2019
4deaa69
rustc: print elided regions as '_ instead of nothing, and use a separ…
eddyb Jan 23, 2019
ffa00d4
rustc: make `pretty_path_generic_args`' task as simple as possible.
eddyb Jan 24, 2019
c0c485c
rustc: don't thread existential projections through path_generic_args.
eddyb Jan 24, 2019
2a65682
rustc: remove the ability for pretty-printers to override nesting.
eddyb Jan 25, 2019
52b4f2d
rustc: remove PrintCx from ty::Print and rely on printers carrying Ty…
eddyb Jan 25, 2019
9df7c3f
rustc: let ty::print::pretty's p! macro call arbitrary methods.
eddyb Jan 25, 2019
8619ede
rustc: slice substs in ty::print instead of passing the full ones.
eddyb Jan 29, 2019
a54a41c
rustc: provide DisambiguatedDefPathData in ty::print.
eddyb Feb 3, 2019
22d6c55
rustc: print ExistentialProjection with spaces around `=`, e.g. `dyn …
eddyb Feb 3, 2019
4653ae1
we can now print on entering/leaving the topmost frame, and make sure…
RalfJung Feb 7, 2019
0ee059d
Fix rebase fallout and address some review comments.
eddyb Mar 14, 2019
dbf19c3
rustbuild: remove obsolete fulldeps behavior from src/test/pretty tes…
eddyb Mar 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rustc: always hide defaulted generic args, even in verbose mode.
  • Loading branch information
eddyb committed Mar 15, 2019
commit 72690d24f02543f5a3c77a8506da48bb32fdc466
31 changes: 27 additions & 4 deletions src/librustc/ty/print/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::hir::map::DefPathData;
use crate::hir::def_id::{CrateNum, DefId};
use crate::ty::{self, DefIdTree, Ty, TyCtxt};
use crate::ty::subst::{Subst, SubstsRef};
use crate::ty::subst::{Kind, Subst, SubstsRef};

use rustc_data_structures::fx::FxHashSet;

Expand Down Expand Up @@ -129,7 +129,7 @@ pub trait Printer: Sized {
) -> Result<Self::Path, Self::Error>;
}

impl<P: Printer> PrintCx<'a, 'gcx, 'tcx, P> {
impl<P: Printer> PrintCx<'_, 'gcx, 'tcx, P> {
pub fn default_print_def_path(
self,
def_id: DefId,
Expand Down Expand Up @@ -197,8 +197,7 @@ impl<P: Printer> PrintCx<'a, 'gcx, 'tcx, P> {
};

if let (Some(generics), Some(substs)) = (generics, substs) {
let has_own_self = generics.has_self && generics.parent_count == 0;
let params = &generics.params[has_own_self as usize..];
let params = self.generic_params_to_print(generics, substs);
self.path_generic_args(print_path, params, substs, projections)
} else {
print_path(self)
Expand All @@ -207,6 +206,30 @@ impl<P: Printer> PrintCx<'a, 'gcx, 'tcx, P> {
}
}

pub fn generic_params_to_print(
&self,
generics: &'a ty::Generics,
substs: SubstsRef<'tcx>,
) -> &'a [ty::GenericParamDef] {
// Don't print args for `Self` parameters (of traits).
let has_own_self = generics.has_self && generics.parent_count == 0;
let params = &generics.params[has_own_self as usize..];

// Don't print args that are the defaults of their respective parameters.
let num_supplied_defaults = params.iter().rev().take_while(|param| {
match param.kind {
ty::GenericParamDefKind::Lifetime => false,
ty::GenericParamDefKind::Type { has_default, .. } => {
has_default && substs[param.index as usize] == Kind::from(
self.tcx.type_of(param.def_id).subst(self.tcx, substs)
)
}
ty::GenericParamDefKind::Const => false, // FIXME(const_generics:defaults)
}
}).count();
&params[..params.len() - num_supplied_defaults]
}

fn default_print_impl_path(
self,
impl_def_id: DefId,
Expand Down
22 changes: 1 addition & 21 deletions src/librustc/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,25 +502,6 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
_ => false,
}
});

// Don't print args that are the defaults of their respective parameters.
let num_supplied_defaults = if self.tcx.sess.verbose() {
0
} else {
params.iter().rev().take_while(|param| {
match param.kind {
ty::GenericParamDefKind::Lifetime => false,
ty::GenericParamDefKind::Type { has_default, .. } => {
has_default && substs[param.index as usize] == Kind::from(
self.tcx.type_of(param.def_id).subst(self.tcx, substs)
)
}
ty::GenericParamDefKind::Const => false, // FIXME(const_generics:defaults)
}
}).count()
};

let params = &params[..params.len() - num_supplied_defaults];
let mut args = params.iter().map(|param| {
substs[param.index as usize]
}).filter(|arg| {
Expand Down Expand Up @@ -657,8 +638,7 @@ impl<F: fmt::Write> Printer for FmtPrinter<F> {
})?;
if visible_path_success {
return if let (Some(generics), Some(substs)) = (generics, substs) {
let has_own_self = generics.has_self && generics.parent_count == 0;
let params = &generics.params[has_own_self as usize..];
let params = self.generic_params_to_print(generics, substs);
self.path_generic_args(|cx| cx.ok(), params, substs, projections)
} else {
self.ok()
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/substs-ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn foo<'z>() where &'z (): Sized {
let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>;
//[verbose]~^ ERROR mismatched types
//[verbose]~| expected type `()`
//[verbose]~| found type `fn() {<i8 as Foo<ReStatic, ReStatic, u32>>::bar::<ReStatic, char>}`
//[verbose]~| found type `fn() {<i8 as Foo<ReStatic, ReStatic>>::bar::<ReStatic, char>}`
//[normal]~^^^^ ERROR mismatched types
//[normal]~| expected type `()`
//[normal]~| found type `fn() {<i8 as Foo<'static, 'static>>::bar::<'static, char>}`
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/substs-ppaux.verbose.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found fn item
|
= note: expected type `()`
found type `fn() {<i8 as Foo<ReStatic, ReStatic, u32>>::bar::<ReStatic, char>}`
found type `fn() {<i8 as Foo<ReStatic, ReStatic>>::bar::<ReStatic, char>}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a regression in the output?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-Zverbose no longer control whether defaulted parameters are printed. This is because keeping the old behavior would mean no/less shared infrastracture for determining which generic arguments are used for which path segment.

Also, there is no information lost, because we don't check for an "approximation" of the default, but a perfectly exact match.
SO you can always refer to the definition (of Foo, in this case) for the default.


error[E0308]: mismatched types
--> $DIR/substs-ppaux.rs:33:17
Expand Down