1
Fork 0

Don't print host effect param in pretty path_generic_args

This commit is contained in:
Michael Goulet 2023-12-09 17:42:33 +00:00
parent 08587a56f1
commit f1bf874fb1
11 changed files with 46 additions and 42 deletions

View file

@ -320,9 +320,11 @@ impl<'tcx> Generics {
&'tcx self,
tcx: TyCtxt<'tcx>,
args: &'tcx [ty::GenericArg<'tcx>],
) -> &'tcx [ty::GenericArg<'tcx>] {
let mut own_params = self.parent_count..self.count();
) -> (&'tcx [ty::GenericArg<'tcx>], &'tcx [ty::GenericParamDef]) {
let mut own_args = self.parent_count..self.count();
let mut own_params = 0..self.params.len();
if self.has_self && self.parent.is_none() {
own_args.start = 1;
own_params.start = 1;
}
@ -332,7 +334,7 @@ impl<'tcx> Generics {
// of semantic equivalence. While not ideal, that's
// good enough for now as this should only be used
// for diagnostics anyways.
own_params.end -= self
let num_default_params = self
.params
.iter()
.rev()
@ -342,8 +344,10 @@ impl<'tcx> Generics {
})
})
.count();
own_params.end -= num_default_params;
own_args.end -= num_default_params;
&args[own_params]
(&args[own_args], &self.params[own_params])
}
/// Returns the args corresponding to the generic parameters of this item, excluding `Self`.

View file

@ -83,6 +83,7 @@ pub trait Printer<'tcx>: Sized {
&mut self,
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
args: &[GenericArg<'tcx>],
params: &[ty::GenericParamDef],
) -> Result<(), PrintError>;
// Defaults (should not be overridden):
@ -141,10 +142,12 @@ pub trait Printer<'tcx>: Sized {
// on top of the same path, but without its own generics.
_ => {
if !generics.params.is_empty() && args.len() >= generics.count() {
let args = generics.own_args_no_defaults(self.tcx(), args);
let (args, params) =
generics.own_args_no_defaults(self.tcx(), args);
return self.path_generic_args(
|cx| cx.print_def_path(def_id, parent_args),
args,
params,
);
}
}

View file

@ -19,7 +19,6 @@ use rustc_hir::LangItem;
use rustc_session::config::TrimmedDefPaths;
use rustc_session::cstore::{ExternCrate, ExternCrateSource};
use rustc_session::Limit;
use rustc_span::sym;
use rustc_span::symbol::{kw, Ident, Symbol};
use rustc_span::FileNameDisplayPreference;
use rustc_target::abi::Size;
@ -967,7 +966,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
define_scoped_cx!(cx);
// Get the (single) generic ty (the args) of this FnOnce trait ref.
let generics = tcx.generics_of(trait_ref.def_id);
let own_args = generics.own_args_no_defaults(tcx, trait_ref.args);
let (own_args, _) = generics.own_args_no_defaults(tcx, trait_ref.args);
match (entry.return_ty, own_args[0].expect_ty()) {
// We can only print `impl Fn() -> ()` if we have a tuple of args and we recorded
@ -1033,7 +1032,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
p!(print(trait_ref.print_only_trait_name()));
let generics = tcx.generics_of(trait_ref.def_id);
let own_args = generics.own_args_no_defaults(tcx, trait_ref.args);
let (own_args, _) = generics.own_args_no_defaults(tcx, trait_ref.args);
if !own_args.is_empty() || !assoc_items.is_empty() {
let mut first = true;
@ -1185,6 +1184,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
)
},
&alias_ty.args[1..],
&self.tcx().generics_of(alias_ty.def_id).params,
)
}
@ -1233,7 +1233,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
let dummy_cx = Ty::new_fresh(cx.tcx(), 0);
let principal = principal.with_self_ty(cx.tcx(), dummy_cx);
let args = cx
let (args, _) = cx
.tcx()
.generics_of(principal.def_id)
.own_args_no_defaults(cx.tcx(), principal.args);
@ -2031,40 +2031,26 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
&mut self,
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
args: &[GenericArg<'tcx>],
params: &[ty::GenericParamDef],
) -> Result<(), PrintError> {
print_prefix(self)?;
let tcx = self.tcx;
let args = args.iter().copied();
let args: Vec<_> = if !tcx.sess.verbose() {
// skip host param as those are printed as `~const`
args.filter(|arg| match arg.unpack() {
// FIXME(effects) there should be a better way than just matching the name
GenericArgKind::Const(c)
if tcx.features().effects
&& matches!(
c.kind(),
ty::ConstKind::Param(ty::ParamConst { name: sym::host, .. })
) =>
{
false
}
_ => true,
})
.collect()
} else {
let verbose = tcx.sess.verbose();
let mut args = args
.iter()
.copied()
.zip(params)
// If -Zverbose is passed, we should print the host parameter instead
// of eating it.
args.collect()
};
.filter(|(_, param)| verbose || !param.is_host_effect())
.peekable();
if !args.is_empty() {
if args.peek().is_some() {
if self.in_value {
write!(self, "::")?;
}
self.generic_delimiters(|cx| cx.comma_sep(args.into_iter()))
self.generic_delimiters(|cx| cx.comma_sep(args.map(|(arg, _)| arg)))
} else {
Ok(())
}