rustc: always hide defaulted generic args, even in verbose mode.
This commit is contained in:
parent
381fa7aa18
commit
72690d24f0
4 changed files with 30 additions and 27 deletions
|
@ -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;
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
@ -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();
|
||||
¶ms[..params.len() - num_supplied_defaults]
|
||||
}
|
||||
|
||||
fn default_print_impl_path(
|
||||
self,
|
||||
impl_def_id: DefId,
|
||||
|
|
|
@ -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 = ¶ms[..params.len() - num_supplied_defaults];
|
||||
let mut args = params.iter().map(|param| {
|
||||
substs[param.index as usize]
|
||||
}).filter(|arg| {
|
||||
|
@ -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()
|
||||
|
|
|
@ -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>}`
|
||||
|
|
|
@ -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>}`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/substs-ppaux.rs:33:17
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue