Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ppaux out of existence. #58140

Merged
merged 70 commits into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion src/bootstrap/mk/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ check:
$(Q)$(BOOTSTRAP) test $(BOOTSTRAP_ARGS)
check-aux:
$(Q)$(BOOTSTRAP) test \
src/test/pretty \
src/test/run-pass/pretty \
src/test/run-fail/pretty \
src/test/run-pass-valgrind/pretty \
Expand Down
12 changes: 3 additions & 9 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,12 +897,10 @@ host_test!(Rustdoc {
suite: "rustdoc"
});

test!(Pretty {
host_test!(Pretty {
path: "src/test/pretty",
mode: "pretty",
suite: "pretty",
default: false,
host: true
suite: "pretty"
});
test!(RunPassPretty {
path: "src/test/run-pass/pretty",
Expand Down Expand Up @@ -993,11 +991,7 @@ impl Step for Compiletest {
});
}

if suite.ends_with("fulldeps") ||
// FIXME: Does pretty need librustc compiled? Note that there are
// fulldeps test suites with mode = pretty as well.
mode == "pretty"
{
if suite.ends_with("fulldeps") {
builder.ensure(compile::Rustc { compiler, target });
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for DefId {
}

fn to_debug_str(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> String {
tcx.item_path_str(*self)
tcx.def_path_str(*self)
}
}

Expand All @@ -736,7 +736,7 @@ impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for DefIndex {
}

fn to_debug_str(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> String {
tcx.item_path_str(DefId::local(*self))
tcx.def_path_str(DefId::local(*self))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/def_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl DefId {
if self.is_local() && self.index == CRATE_DEF_INDEX {
format!("top-level module")
} else {
format!("module `{}`", tcx.item_path_str(*self))
format!("module `{}`", tcx.def_path_str(*self))
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/hir/map/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,13 +679,13 @@ impl DefPathData {
return name
}
// note that this does not show up in user printouts
CrateRoot => "{{root}}",
CrateRoot => "{{crate}}",
Impl => "{{impl}}",
Misc => "{{?}}",
Misc => "{{misc}}",
ClosureExpr => "{{closure}}",
StructCtor => "{{constructor}}",
AnonConst => "{{constant}}",
ImplTrait => "{{impl-Trait}}",
ImplTrait => "{{opaque}}",
};

Symbol::intern(s).as_interned_str()
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,8 @@ fn node_id_to_string(map: &Map<'_>, id: NodeId, include_id: bool) -> String {
// the user-friendly path, otherwise fall back to stringifying DefPath.
crate::ty::tls::with_opt(|tcx| {
if let Some(tcx) = tcx {
tcx.node_path_str(id)
let def_id = map.local_def_id(id);
tcx.def_path_str(def_id)
} else if let Some(path) = map.def_path_from_id(id) {
path.data.into_iter().map(|elem| {
elem.data.to_string()
Expand Down
129 changes: 114 additions & 15 deletions src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
self.hir().span_by_hir_id(node),
),
_ => (
format!("the lifetime {} as defined on", fr.bound_region),
format!("the lifetime {} as defined on", region),
cm.def_span(self.hir().span_by_hir_id(node)),
),
},
Expand Down Expand Up @@ -444,17 +444,109 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
terr: &TypeError<'tcx>,
sp: Span,
) {
use hir::def_id::CrateNum;
use hir::map::DisambiguatedDefPathData;
use ty::print::Printer;
use ty::subst::Kind;

struct AbsolutePathPrinter<'a, 'gcx, 'tcx> {
tcx: TyCtxt<'a, 'gcx, 'tcx>,
}

struct NonTrivialPath;

impl<'gcx, 'tcx> Printer<'gcx, 'tcx> for AbsolutePathPrinter<'_, 'gcx, 'tcx> {
type Error = NonTrivialPath;

type Path = Vec<String>;
type Region = !;
type Type = !;
type DynExistential = !;

fn tcx<'a>(&'a self) -> TyCtxt<'a, 'gcx, 'tcx> {
self.tcx
}

fn print_region(
self,
_region: ty::Region<'_>,
) -> Result<Self::Region, Self::Error> {
Err(NonTrivialPath)
}

fn print_type(
self,
_ty: Ty<'tcx>,
) -> Result<Self::Type, Self::Error> {
Err(NonTrivialPath)
}

fn print_dyn_existential(
self,
_predicates: &'tcx ty::List<ty::ExistentialPredicate<'tcx>>,
) -> Result<Self::DynExistential, Self::Error> {
Err(NonTrivialPath)
}

fn path_crate(
self,
cnum: CrateNum,
) -> Result<Self::Path, Self::Error> {
Ok(vec![self.tcx.original_crate_name(cnum).to_string()])
}
fn path_qualified(
self,
_self_ty: Ty<'tcx>,
_trait_ref: Option<ty::TraitRef<'tcx>>,
) -> Result<Self::Path, Self::Error> {
Err(NonTrivialPath)
}

fn path_append_impl(
self,
_print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
_disambiguated_data: &DisambiguatedDefPathData,
_self_ty: Ty<'tcx>,
_trait_ref: Option<ty::TraitRef<'tcx>>,
) -> Result<Self::Path, Self::Error> {
Err(NonTrivialPath)
}
fn path_append(
self,
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
disambiguated_data: &DisambiguatedDefPathData,
) -> Result<Self::Path, Self::Error> {
let mut path = print_prefix(self)?;
path.push(disambiguated_data.data.as_interned_str().to_string());
Ok(path)
}
fn path_generic_args(
self,
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
_args: &[Kind<'tcx>],
) -> Result<Self::Path, Self::Error> {
print_prefix(self)
}
}

let report_path_match = |err: &mut DiagnosticBuilder<'_>, did1: DefId, did2: DefId| {
// Only external crates, if either is from a local
// module we could have false positives
if !(did1.is_local() || did2.is_local()) && did1.krate != did2.krate {
let exp_path = self.tcx.item_path_str(did1);
let found_path = self.tcx.item_path_str(did2);
let exp_abs_path = self.tcx.absolute_item_path_str(did1);
let found_abs_path = self.tcx.absolute_item_path_str(did2);
let abs_path = |def_id| {
AbsolutePathPrinter { tcx: self.tcx }
.print_def_path(def_id, &[])
};

// We compare strings because DefPath can be different
// for imported and non-imported crates
if exp_path == found_path || exp_abs_path == found_abs_path {
let same_path = || -> Result<_, NonTrivialPath> {
Ok(
self.tcx.def_path_str(did1) == self.tcx.def_path_str(did2) ||
abs_path(did1)? == abs_path(did2)?
)
};
if same_path().unwrap_or(false) {
let crate_name = self.tcx.crate_name(did1.krate);
err.span_note(
sp,
Expand Down Expand Up @@ -658,7 +750,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
return Some(());
}
if let &ty::Adt(def, _) = &ta.sty {
let path_ = self.tcx.item_path_str(def.did.clone());
let path_ = self.tcx.def_path_str(def.did.clone());
if path_ == other_path {
self.highlight_outer(&mut t1_out, &mut t2_out, path, sub, i, &other_ty);
return Some(());
Expand All @@ -683,7 +775,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
}

/// For generic types with parameters with defaults, remove the parameters corresponding to
/// the defaults. This repeats a lot of the logic found in `PrintContext::parameterized`.
/// the defaults. This repeats a lot of the logic found in `ty::print::pretty`.
fn strip_generic_default_params(
&self,
def_id: DefId,
Expand Down Expand Up @@ -742,11 +834,15 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
mutbl: hir::Mutability,
s: &mut DiagnosticStyledString,
) {
let r = &r.to_string();
let mut r = r.to_string();
if r == "'_" {
r.clear();
} else {
r.push(' ');
}
s.push_highlighted(format!(
"&{}{}{}",
"&{}{}",
r,
if r == "" { "" } else { " " },
if mutbl == hir::MutMutable { "mut " } else { "" }
));
s.push_normal(ty.to_string());
Expand All @@ -757,8 +853,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
let sub_no_defaults_1 = self.strip_generic_default_params(def1.did, sub1);
let sub_no_defaults_2 = self.strip_generic_default_params(def2.did, sub2);
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
let path1 = self.tcx.item_path_str(def1.did.clone());
let path2 = self.tcx.item_path_str(def2.did.clone());
let path1 = self.tcx.def_path_str(def1.did.clone());
let path2 = self.tcx.def_path_str(def2.did.clone());
if def1.did == def2.did {
// Easy case. Replace same types with `_` to shorten the output and highlight
// the differing ones.
Expand Down Expand Up @@ -1013,7 +1109,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
if exp_is_struct && &exp_found.expected == ret_ty.skip_binder() {
let message = format!(
"did you mean `{}(/* fields */)`?",
self.tcx.item_path_str(def_id)
self.tcx.def_path_str(def_id)
);
diag.span_label(span, message);
}
Expand Down Expand Up @@ -1425,7 +1521,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
var_origin: RegionVariableOrigin,
) -> DiagnosticBuilder<'tcx> {
let br_string = |br: ty::BoundRegion| {
let mut s = br.to_string();
let mut s = match br {
ty::BrNamed(_, name) => name.to_string(),
_ => String::new(),
};
if !s.is_empty() {
s.push_str(" ");
}
Expand Down
24 changes: 17 additions & 7 deletions src/librustc/infer/error_reporting/need_type_info.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::hir::def::Namespace;
use crate::hir::{self, Local, Pat, Body, HirId};
use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
use crate::infer::InferCtxt;
use crate::infer::type_variable::TypeVariableOrigin;
use crate::ty::{self, Ty, Infer, TyVar};
use crate::ty::print::Print;
use syntax::source_map::CompilerDesugaringKind;
use syntax_pos::Span;
use errors::DiagnosticBuilder;
Expand Down Expand Up @@ -64,18 +66,26 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindLocalByTypeVisitor<'a, 'gcx, 'tcx> {


impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
pub fn extract_type_name(&self, ty: &'a Ty<'tcx>) -> String {
pub fn extract_type_name(
&self,
ty: &'a Ty<'tcx>,
highlight: Option<ty::print::RegionHighlightMode>,
) -> String {
if let ty::Infer(ty::TyVar(ty_vid)) = (*ty).sty {
let ty_vars = self.type_variables.borrow();
if let TypeVariableOrigin::TypeParameterDefinition(_, name) =
*ty_vars.var_origin(ty_vid) {
name.to_string()
} else {
ty.to_string()
return name.to_string();
}
} else {
ty.to_string()
}

let mut s = String::new();
let mut printer = ty::print::FmtPrinter::new(self.tcx, &mut s, Namespace::TypeNS);
if let Some(highlight) = highlight {
printer.region_highlight_mode = highlight;
}
let _ = ty.print(printer);
s
}

pub fn need_type_info_err(&self,
Expand All @@ -84,7 +94,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
ty: Ty<'tcx>)
-> DiagnosticBuilder<'gcx> {
let ty = self.resolve_type_vars_if_possible(&ty);
let name = self.extract_type_name(&ty);
let name = self.extract_type_name(&ty, None);

let mut err_span = span;
let mut labels = vec![(
Expand Down
Loading