Auto merge of #118788 - compiler-errors:const-pretty, r=fee1-dead · rust-lang/rust@42dfac5 (original) (raw)

`@@ -19,7 +19,6 @@ use rustc_hir::LangItem;

`

19

19

`use rustc_session::config::TrimmedDefPaths;

`

20

20

`use rustc_session::cstore::{ExternCrate, ExternCrateSource};

`

21

21

`use rustc_session::Limit;

`

22

``

`-

use rustc_span::sym;

`

23

22

`use rustc_span::symbol::{kw, Ident, Symbol};

`

24

23

`use rustc_span::FileNameDisplayPreference;

`

25

24

`use rustc_target::abi::Size;

`

`@@ -967,7 +966,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {

`

967

966

`define_scoped_cx!(cx);

`

968

967

`// Get the (single) generic ty (the args) of this FnOnce trait ref.

`

969

968

`let generics = tcx.generics_of(trait_ref.def_id);

`

970

``

`-

let own_args = generics.own_args_no_defaults(tcx, trait_ref.args);

`

``

969

`+

let (own_args, _) = generics.own_args_no_defaults(tcx, trait_ref.args);

`

971

970

``

972

971

`match (entry.return_ty, own_args[0].expect_ty()) {

`

973

972

`` // 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 {

`

1033

1032

`p!(print(trait_ref.print_only_trait_name()));

`

1034

1033

``

1035

1034

`let generics = tcx.generics_of(trait_ref.def_id);

`

1036

``

`-

let own_args = generics.own_args_no_defaults(tcx, trait_ref.args);

`

``

1035

`+

let (own_args, _) = generics.own_args_no_defaults(tcx, trait_ref.args);

`

1037

1036

``

1038

1037

`if !own_args.is_empty() || !assoc_items.is_empty() {

`

1039

1038

`let mut first = true;

`

`@@ -1185,6 +1184,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {

`

1185

1184

`)

`

1186

1185

`},

`

1187

1186

`&alias_ty.args[1..],

`

``

1187

`+

&self.tcx().generics_of(alias_ty.def_id).params,

`

1188

1188

`)

`

1189

1189

`}

`

1190

1190

``

`@@ -1233,7 +1233,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {

`

1233

1233

`let dummy_cx = Ty::new_fresh(cx.tcx(), 0);

`

1234

1234

`let principal = principal.with_self_ty(cx.tcx(), dummy_cx);

`

1235

1235

``

1236

``

`-

let args = cx

`

``

1236

`+

let (args, _) = cx

`

1237

1237

`.tcx()

`

1238

1238

`.generics_of(principal.def_id)

`

1239

1239

`.own_args_no_defaults(cx.tcx(), principal.args);

`

`@@ -2031,40 +2031,26 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {

`

2031

2031

`&mut self,

`

2032

2032

`print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,

`

2033

2033

`args: &[GenericArg<'tcx>],

`

``

2034

`+

params: &[ty::GenericParamDef],

`

2034

2035

`) -> Result<(), PrintError> {

`

2035

2036

`print_prefix(self)?;

`

2036

2037

``

2037

2038

`let tcx = self.tcx;

`

2038

``

-

2039

``

`-

let args = args.iter().copied();

`

2040

``

-

2041

``

`-

let args: Vec<_> = if !tcx.sess.verbose() {

`

2042

``

`` -

// skip host param as those are printed as ~const

``

2043

``

`-

args.filter(|arg| match arg.unpack() {

`

2044

``

`-

// FIXME(effects) there should be a better way than just matching the name

`

2045

``

`-

GenericArgKind::Const(c)

`

2046

``

`-

if tcx.features().effects

`

2047

``

`-

&& matches!(

`

2048

``

`-

c.kind(),

`

2049

``

`-

ty::ConstKind::Param(ty::ParamConst { name: sym::host, .. })

`

2050

``

`-

) =>

`

2051

``

`-

{

`

2052

``

`-

false

`

2053

``

`-

}

`

2054

``

`-

_ => true,

`

2055

``

`-

})

`

2056

``

`-

.collect()

`

2057

``

`-

} else {

`

``

2039

`+

let verbose = tcx.sess.verbose();

`

``

2040

`+

let mut args = args

`

``

2041

`+

.iter()

`

``

2042

`+

.copied()

`

``

2043

`+

.zip(params)

`

2058

2044

`// If -Zverbose is passed, we should print the host parameter instead

`

2059

2045

`// of eating it.

`

2060

``

`-

args.collect()

`

2061

``

`-

};

`

``

2046

`+

.filter(|(_, param)| verbose || !param.is_host_effect())

`

``

2047

`+

.peekable();

`

2062

2048

``

2063

``

`-

if !args.is_empty() {

`

``

2049

`+

if args.peek().is_some() {

`

2064

2050

`if self.in_value {

`

2065

2051

`write!(self, "::")?;

`

2066

2052

`}

`

2067

``

`-

self.generic_delimiters(|cx| cx.comma_sep(args.into_iter()))

`

``

2053

`+

self.generic_delimiters(|cx| cx.comma_sep(args.map(|(arg, _)| arg)))

`

2068

2054

`} else {

`

2069

2055

`Ok(())

`

2070

2056

`}

`

`@@ -2894,11 +2880,15 @@ define_print_and_forward_display! {

`

2894

2880

`}

`

2895

2881

``

2896

2882

`TraitPredPrintModifiersAndPath<'tcx> {

`

2897

``

`` -

// FIXME(effects) print ~const here

``

``

2883

`+

if let Some(idx) = cx.tcx().generics_of(self.0.trait_ref.def_id).host_effect_index

`

``

2884

`+

{

`

``

2885

`+

if self.0.trait_ref.args.const_at(idx) != cx.tcx().consts.true_ {

`

``

2886

`+

p!("~const ");

`

``

2887

`+

}

`

``

2888

`+

}

`

2898

2889

`if let ty::ImplPolarity::Negative = self.0.polarity {

`

2899

2890

` p!("!")

`

2900

2891

`}

`

2901

``

-

2902

2892

` p!(print(self.0.trait_ref.print_only_trait_path()));

`

2903

2893

`}

`

2904

2894

``

`@@ -2933,7 +2923,6 @@ define_print_and_forward_display! {

`

2933

2923

` p!("~const ");

`

2934

2924

`}

`

2935

2925

`}

`

2936

``

`` -

// FIXME(effects) print ~const here

``

2937

2926

`if let ty::ImplPolarity::Negative = self.polarity {

`

2938

2927

` p!("!");

`

2939

2928

`}

`