Don't print host effect param in pretty path_generic_args
This commit is contained in:
parent
08587a56f1
commit
f1bf874fb1
11 changed files with 46 additions and 42 deletions
|
@ -120,6 +120,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
|
||||||
&mut self,
|
&mut self,
|
||||||
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
|
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
|
||||||
args: &[GenericArg<'tcx>],
|
args: &[GenericArg<'tcx>],
|
||||||
|
_params: &[ty::GenericParamDef],
|
||||||
) -> Result<(), PrintError> {
|
) -> Result<(), PrintError> {
|
||||||
print_prefix(self)?;
|
print_prefix(self)?;
|
||||||
let args =
|
let args =
|
||||||
|
|
|
@ -641,6 +641,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
&mut self,
|
&mut self,
|
||||||
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
|
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
|
||||||
_args: &[GenericArg<'tcx>],
|
_args: &[GenericArg<'tcx>],
|
||||||
|
_params: &[ty::GenericParamDef],
|
||||||
) -> Result<(), PrintError> {
|
) -> Result<(), PrintError> {
|
||||||
print_prefix(self)
|
print_prefix(self)
|
||||||
}
|
}
|
||||||
|
@ -1236,9 +1237,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
(&ty::Adt(def1, sub1), &ty::Adt(def2, sub2)) => {
|
(&ty::Adt(def1, sub1), &ty::Adt(def2, sub2)) => {
|
||||||
let did1 = def1.did();
|
let did1 = def1.did();
|
||||||
let did2 = def2.did();
|
let did2 = def2.did();
|
||||||
let sub_no_defaults_1 =
|
let (sub_no_defaults_1, _) =
|
||||||
self.tcx.generics_of(did1).own_args_no_defaults(self.tcx, sub1);
|
self.tcx.generics_of(did1).own_args_no_defaults(self.tcx, sub1);
|
||||||
let sub_no_defaults_2 =
|
let (sub_no_defaults_2, _) =
|
||||||
self.tcx.generics_of(did2).own_args_no_defaults(self.tcx, sub2);
|
self.tcx.generics_of(did2).own_args_no_defaults(self.tcx, sub2);
|
||||||
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
|
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
|
||||||
let path1 = self.tcx.def_path_str(did1);
|
let path1 = self.tcx.def_path_str(did1);
|
||||||
|
|
|
@ -757,6 +757,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
|
||||||
.tcx
|
.tcx
|
||||||
.generics_of(def.did())
|
.generics_of(def.did())
|
||||||
.own_args_no_defaults(self.tcx, args)
|
.own_args_no_defaults(self.tcx, args)
|
||||||
|
.0
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&arg| self.arg_cost(arg))
|
.map(|&arg| self.arg_cost(arg))
|
||||||
.sum::<usize>()
|
.sum::<usize>()
|
||||||
|
@ -1185,7 +1186,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
let args = self.infcx.resolve_vars_if_possible(args);
|
let args = self.infcx.resolve_vars_if_possible(args);
|
||||||
let generic_args =
|
let generic_args =
|
||||||
&generics.own_args_no_defaults(tcx, args)[generics.own_counts().lifetimes..];
|
&generics.own_args_no_defaults(tcx, args).0[generics.own_counts().lifetimes..];
|
||||||
let span = match expr.kind {
|
let span = match expr.kind {
|
||||||
ExprKind::MethodCall(path, ..) => path.ident.span,
|
ExprKind::MethodCall(path, ..) => path.ident.span,
|
||||||
_ => expr.span,
|
_ => expr.span,
|
||||||
|
|
|
@ -116,7 +116,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
// FIXME: extract this logic for use in other diagnostics.
|
// FIXME: extract this logic for use in other diagnostics.
|
||||||
let (trait_ref, assoc_args) = proj.trait_ref_and_own_args(tcx);
|
let (trait_ref, assoc_args) = proj.trait_ref_and_own_args(tcx);
|
||||||
let item_name = tcx.item_name(proj.def_id);
|
let item_name = tcx.item_name(proj.def_id);
|
||||||
let item_args = self.format_generic_args(assoc_args);
|
let item_args = self.format_generic_args(proj.def_id, assoc_args);
|
||||||
|
|
||||||
// Here, we try to see if there's an existing
|
// Here, we try to see if there's an existing
|
||||||
// trait implementation that matches the one that
|
// trait implementation that matches the one that
|
||||||
|
@ -775,7 +775,7 @@ fn foo(&self) -> Self::T { String::new() }
|
||||||
let span = Span::new(pos, pos, span.ctxt(), span.parent());
|
let span = Span::new(pos, pos, span.ctxt(), span.parent());
|
||||||
(span, format!(", {} = {}", assoc.ident(tcx), ty))
|
(span, format!(", {} = {}", assoc.ident(tcx), ty))
|
||||||
} else {
|
} else {
|
||||||
let item_args = self.format_generic_args(assoc_args);
|
let item_args = self.format_generic_args(assoc.def_id, assoc_args);
|
||||||
(span.shrink_to_hi(), format!("<{}{} = {}>", assoc.ident(tcx), item_args, ty))
|
(span.shrink_to_hi(), format!("<{}{} = {}>", assoc.ident(tcx), item_args, ty))
|
||||||
};
|
};
|
||||||
diag.span_suggestion_verbose(span, msg(), sugg, MaybeIncorrect);
|
diag.span_suggestion_verbose(span, msg(), sugg, MaybeIncorrect);
|
||||||
|
@ -784,9 +784,13 @@ fn foo(&self) -> Self::T { String::new() }
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn format_generic_args(&self, args: &[ty::GenericArg<'tcx>]) -> String {
|
pub fn format_generic_args(
|
||||||
|
&self,
|
||||||
|
assoc_def_id: DefId,
|
||||||
|
args: &[ty::GenericArg<'tcx>],
|
||||||
|
) -> String {
|
||||||
FmtPrinter::print_string(self.tcx, hir::def::Namespace::TypeNS, |cx| {
|
FmtPrinter::print_string(self.tcx, hir::def::Namespace::TypeNS, |cx| {
|
||||||
cx.path_generic_args(|_| Ok(()), args)
|
cx.path_generic_args(|_| Ok(()), args, &self.infcx.tcx.generics_of(assoc_def_id).params)
|
||||||
})
|
})
|
||||||
.expect("could not write to `String`.")
|
.expect("could not write to `String`.")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1285,6 +1285,7 @@ impl<'tcx> LateContext<'tcx> {
|
||||||
&mut self,
|
&mut self,
|
||||||
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
|
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
|
||||||
_args: &[GenericArg<'tcx>],
|
_args: &[GenericArg<'tcx>],
|
||||||
|
_params: &[ty::GenericParamDef],
|
||||||
) -> Result<(), PrintError> {
|
) -> Result<(), PrintError> {
|
||||||
print_prefix(self)
|
print_prefix(self)
|
||||||
}
|
}
|
||||||
|
|
|
@ -320,9 +320,11 @@ impl<'tcx> Generics {
|
||||||
&'tcx self,
|
&'tcx self,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
args: &'tcx [ty::GenericArg<'tcx>],
|
args: &'tcx [ty::GenericArg<'tcx>],
|
||||||
) -> &'tcx [ty::GenericArg<'tcx>] {
|
) -> (&'tcx [ty::GenericArg<'tcx>], &'tcx [ty::GenericParamDef]) {
|
||||||
let mut own_params = self.parent_count..self.count();
|
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() {
|
if self.has_self && self.parent.is_none() {
|
||||||
|
own_args.start = 1;
|
||||||
own_params.start = 1;
|
own_params.start = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,7 +334,7 @@ impl<'tcx> Generics {
|
||||||
// of semantic equivalence. While not ideal, that's
|
// of semantic equivalence. While not ideal, that's
|
||||||
// good enough for now as this should only be used
|
// good enough for now as this should only be used
|
||||||
// for diagnostics anyways.
|
// for diagnostics anyways.
|
||||||
own_params.end -= self
|
let num_default_params = self
|
||||||
.params
|
.params
|
||||||
.iter()
|
.iter()
|
||||||
.rev()
|
.rev()
|
||||||
|
@ -342,8 +344,10 @@ impl<'tcx> Generics {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.count();
|
.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`.
|
/// Returns the args corresponding to the generic parameters of this item, excluding `Self`.
|
||||||
|
|
|
@ -83,6 +83,7 @@ pub trait Printer<'tcx>: Sized {
|
||||||
&mut self,
|
&mut self,
|
||||||
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
|
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
|
||||||
args: &[GenericArg<'tcx>],
|
args: &[GenericArg<'tcx>],
|
||||||
|
params: &[ty::GenericParamDef],
|
||||||
) -> Result<(), PrintError>;
|
) -> Result<(), PrintError>;
|
||||||
|
|
||||||
// Defaults (should not be overridden):
|
// 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.
|
// on top of the same path, but without its own generics.
|
||||||
_ => {
|
_ => {
|
||||||
if !generics.params.is_empty() && args.len() >= generics.count() {
|
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(
|
return self.path_generic_args(
|
||||||
|cx| cx.print_def_path(def_id, parent_args),
|
|cx| cx.print_def_path(def_id, parent_args),
|
||||||
args,
|
args,
|
||||||
|
params,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ use rustc_hir::LangItem;
|
||||||
use rustc_session::config::TrimmedDefPaths;
|
use rustc_session::config::TrimmedDefPaths;
|
||||||
use rustc_session::cstore::{ExternCrate, ExternCrateSource};
|
use rustc_session::cstore::{ExternCrate, ExternCrateSource};
|
||||||
use rustc_session::Limit;
|
use rustc_session::Limit;
|
||||||
use rustc_span::sym;
|
|
||||||
use rustc_span::symbol::{kw, Ident, Symbol};
|
use rustc_span::symbol::{kw, Ident, Symbol};
|
||||||
use rustc_span::FileNameDisplayPreference;
|
use rustc_span::FileNameDisplayPreference;
|
||||||
use rustc_target::abi::Size;
|
use rustc_target::abi::Size;
|
||||||
|
@ -967,7 +966,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
|
||||||
define_scoped_cx!(cx);
|
define_scoped_cx!(cx);
|
||||||
// Get the (single) generic ty (the args) of this FnOnce trait ref.
|
// Get the (single) generic ty (the args) of this FnOnce trait ref.
|
||||||
let generics = tcx.generics_of(trait_ref.def_id);
|
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()) {
|
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
|
// 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()));
|
p!(print(trait_ref.print_only_trait_name()));
|
||||||
|
|
||||||
let generics = tcx.generics_of(trait_ref.def_id);
|
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() {
|
if !own_args.is_empty() || !assoc_items.is_empty() {
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
|
@ -1185,6 +1184,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
&alias_ty.args[1..],
|
&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 dummy_cx = Ty::new_fresh(cx.tcx(), 0);
|
||||||
let principal = principal.with_self_ty(cx.tcx(), dummy_cx);
|
let principal = principal.with_self_ty(cx.tcx(), dummy_cx);
|
||||||
|
|
||||||
let args = cx
|
let (args, _) = cx
|
||||||
.tcx()
|
.tcx()
|
||||||
.generics_of(principal.def_id)
|
.generics_of(principal.def_id)
|
||||||
.own_args_no_defaults(cx.tcx(), principal.args);
|
.own_args_no_defaults(cx.tcx(), principal.args);
|
||||||
|
@ -2031,40 +2031,26 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
|
||||||
&mut self,
|
&mut self,
|
||||||
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
|
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
|
||||||
args: &[GenericArg<'tcx>],
|
args: &[GenericArg<'tcx>],
|
||||||
|
params: &[ty::GenericParamDef],
|
||||||
) -> Result<(), PrintError> {
|
) -> Result<(), PrintError> {
|
||||||
print_prefix(self)?;
|
print_prefix(self)?;
|
||||||
|
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
|
let verbose = tcx.sess.verbose();
|
||||||
let args = args.iter().copied();
|
let mut args = args
|
||||||
|
.iter()
|
||||||
let args: Vec<_> = if !tcx.sess.verbose() {
|
.copied()
|
||||||
// skip host param as those are printed as `~const`
|
.zip(params)
|
||||||
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 {
|
|
||||||
// If -Zverbose is passed, we should print the host parameter instead
|
// If -Zverbose is passed, we should print the host parameter instead
|
||||||
// of eating it.
|
// 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 {
|
if self.in_value {
|
||||||
write!(self, "::")?;
|
write!(self, "::")?;
|
||||||
}
|
}
|
||||||
self.generic_delimiters(|cx| cx.comma_sep(args.into_iter()))
|
self.generic_delimiters(|cx| cx.comma_sep(args.map(|(arg, _)| arg)))
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -342,6 +342,7 @@ impl<'tcx> Printer<'tcx> for SymbolPrinter<'tcx> {
|
||||||
&mut self,
|
&mut self,
|
||||||
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
|
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
|
||||||
args: &[GenericArg<'tcx>],
|
args: &[GenericArg<'tcx>],
|
||||||
|
_params: &[ty::GenericParamDef],
|
||||||
) -> Result<(), PrintError> {
|
) -> Result<(), PrintError> {
|
||||||
print_prefix(self)?;
|
print_prefix(self)?;
|
||||||
|
|
||||||
|
|
|
@ -298,6 +298,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
args,
|
args,
|
||||||
|
&self.tcx.generics_of(impl_def_id).params,
|
||||||
)?;
|
)?;
|
||||||
} else {
|
} else {
|
||||||
self.push_disambiguator(key.disambiguated_data.disambiguator as u64);
|
self.push_disambiguator(key.disambiguated_data.disambiguator as u64);
|
||||||
|
@ -800,6 +801,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
|
||||||
&mut self,
|
&mut self,
|
||||||
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
|
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
|
||||||
args: &[GenericArg<'tcx>],
|
args: &[GenericArg<'tcx>],
|
||||||
|
_params: &[ty::GenericParamDef],
|
||||||
) -> Result<(), PrintError> {
|
) -> Result<(), PrintError> {
|
||||||
// Don't print any regions if they're all erased.
|
// Don't print any regions if they're all erased.
|
||||||
let print_regions = args.iter().any(|arg| match arg.unpack() {
|
let print_regions = args.iter().any(|arg| match arg.unpack() {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
error[E0277]: the trait bound `S: ~const Foo<false>` is not satisfied
|
error[E0277]: the trait bound `S: ~const Foo` is not satisfied
|
||||||
--> $DIR/call-generic-method-nonconst.rs:23:34
|
--> $DIR/call-generic-method-nonconst.rs:23:34
|
||||||
|
|
|
|
||||||
LL | pub const EQ: bool = equals_self(&S);
|
LL | pub const EQ: bool = equals_self(&S);
|
||||||
| ----------- ^^ the trait `Foo<false>` is not implemented for `S`
|
| ----------- ^^ the trait `Foo` is not implemented for `S`
|
||||||
| |
|
| |
|
||||||
| required by a bound introduced by this call
|
| required by a bound introduced by this call
|
||||||
|
|
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue