Skip to content

Commit d1f4bc5

Browse files
committed
Revert "Don't print host effect param in pretty path_generic_args"
This reverts commit f1bf874.
1 parent 2f457d9 commit d1f4bc5

File tree

11 files changed

+41
-45
lines changed

11 files changed

+41
-45
lines changed

Diff for: compiler/rustc_const_eval/src/util/type_name.rs

-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
120120
&mut self,
121121
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
122122
args: &[GenericArg<'tcx>],
123-
_params: &[ty::GenericParamDef],
124123
) -> Result<(), PrintError> {
125124
print_prefix(self)?;
126125
let args =

Diff for: compiler/rustc_infer/src/infer/error_reporting/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
641641
&mut self,
642642
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
643643
_args: &[GenericArg<'tcx>],
644-
_params: &[ty::GenericParamDef],
645644
) -> Result<(), PrintError> {
646645
print_prefix(self)
647646
}
@@ -1237,9 +1236,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
12371236
(&ty::Adt(def1, sub1), &ty::Adt(def2, sub2)) => {
12381237
let did1 = def1.did();
12391238
let did2 = def2.did();
1240-
let (sub_no_defaults_1, _) =
1239+
let sub_no_defaults_1 =
12411240
self.tcx.generics_of(did1).own_args_no_defaults(self.tcx, sub1);
1242-
let (sub_no_defaults_2, _) =
1241+
let sub_no_defaults_2 =
12431242
self.tcx.generics_of(did2).own_args_no_defaults(self.tcx, sub2);
12441243
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
12451244
let path1 = self.tcx.def_path_str(did1);

Diff for: compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,6 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
757757
.tcx
758758
.generics_of(def.did())
759759
.own_args_no_defaults(self.tcx, args)
760-
.0
761760
.iter()
762761
.map(|&arg| self.arg_cost(arg))
763762
.sum::<usize>()
@@ -1186,7 +1185,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
11861185
}
11871186
let args = self.infcx.resolve_vars_if_possible(args);
11881187
let generic_args =
1189-
&generics.own_args_no_defaults(tcx, args).0[generics.own_counts().lifetimes..];
1188+
&generics.own_args_no_defaults(tcx, args)[generics.own_counts().lifetimes..];
11901189
let span = match expr.kind {
11911190
ExprKind::MethodCall(path, ..) => path.ident.span,
11921191
_ => expr.span,

Diff for: compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
116116
// FIXME: extract this logic for use in other diagnostics.
117117
let (trait_ref, assoc_args) = proj.trait_ref_and_own_args(tcx);
118118
let item_name = tcx.item_name(proj.def_id);
119-
let item_args = self.format_generic_args(proj.def_id, assoc_args);
119+
let item_args = self.format_generic_args(assoc_args);
120120

121121
// Here, we try to see if there's an existing
122122
// trait implementation that matches the one that
@@ -775,7 +775,7 @@ fn foo(&self) -> Self::T { String::new() }
775775
let span = Span::new(pos, pos, span.ctxt(), span.parent());
776776
(span, format!(", {} = {}", assoc.ident(tcx), ty))
777777
} else {
778-
let item_args = self.format_generic_args(assoc.def_id, assoc_args);
778+
let item_args = self.format_generic_args(assoc_args);
779779
(span.shrink_to_hi(), format!("<{}{} = {}>", assoc.ident(tcx), item_args, ty))
780780
};
781781
diag.span_suggestion_verbose(span, msg(), sugg, MaybeIncorrect);
@@ -784,13 +784,9 @@ fn foo(&self) -> Self::T { String::new() }
784784
false
785785
}
786786

787-
pub fn format_generic_args(
788-
&self,
789-
assoc_def_id: DefId,
790-
args: &[ty::GenericArg<'tcx>],
791-
) -> String {
787+
pub fn format_generic_args(&self, args: &[ty::GenericArg<'tcx>]) -> String {
792788
FmtPrinter::print_string(self.tcx, hir::def::Namespace::TypeNS, |cx| {
793-
cx.path_generic_args(|_| Ok(()), args, &self.infcx.tcx.generics_of(assoc_def_id).params)
789+
cx.path_generic_args(|_| Ok(()), args)
794790
})
795791
.expect("could not write to `String`.")
796792
}

Diff for: compiler/rustc_lint/src/context.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,6 @@ impl<'tcx> LateContext<'tcx> {
12851285
&mut self,
12861286
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
12871287
_args: &[GenericArg<'tcx>],
1288-
_params: &[ty::GenericParamDef],
12891288
) -> Result<(), PrintError> {
12901289
print_prefix(self)
12911290
}

Diff for: compiler/rustc_middle/src/ty/generics.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,9 @@ impl<'tcx> Generics {
320320
&'tcx self,
321321
tcx: TyCtxt<'tcx>,
322322
args: &'tcx [ty::GenericArg<'tcx>],
323-
) -> (&'tcx [ty::GenericArg<'tcx>], &'tcx [ty::GenericParamDef]) {
324-
let mut own_args = self.parent_count..self.count();
325-
let mut own_params = 0..self.params.len();
323+
) -> &'tcx [ty::GenericArg<'tcx>] {
324+
let mut own_params = self.parent_count..self.count();
326325
if self.has_self && self.parent.is_none() {
327-
own_args.start = 1;
328326
own_params.start = 1;
329327
}
330328

@@ -334,7 +332,7 @@ impl<'tcx> Generics {
334332
// of semantic equivalence. While not ideal, that's
335333
// good enough for now as this should only be used
336334
// for diagnostics anyways.
337-
let num_default_params = self
335+
own_params.end -= self
338336
.params
339337
.iter()
340338
.rev()
@@ -346,10 +344,8 @@ impl<'tcx> Generics {
346344
|| matches!(param.kind, GenericParamDefKind::Const { is_host_effect: true, .. })
347345
})
348346
.count();
349-
own_params.end -= num_default_params;
350-
own_args.end -= num_default_params;
351347

352-
(&args[own_args], &self.params[own_params])
348+
&args[own_params]
353349
}
354350

355351
/// Returns the args corresponding to the generic parameters of this item, excluding `Self`.

Diff for: compiler/rustc_middle/src/ty/print/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ pub trait Printer<'tcx>: Sized {
8383
&mut self,
8484
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
8585
args: &[GenericArg<'tcx>],
86-
params: &[ty::GenericParamDef],
8786
) -> Result<(), PrintError>;
8887

8988
// Defaults (should not be overridden):
@@ -142,12 +141,10 @@ pub trait Printer<'tcx>: Sized {
142141
// on top of the same path, but without its own generics.
143142
_ => {
144143
if !generics.params.is_empty() && args.len() >= generics.count() {
145-
let (args, params) =
146-
generics.own_args_no_defaults(self.tcx(), args);
144+
let args = generics.own_args_no_defaults(self.tcx(), args);
147145
return self.path_generic_args(
148146
|cx| cx.print_def_path(def_id, parent_args),
149147
args,
150-
params,
151148
);
152149
}
153150
}

Diff for: compiler/rustc_middle/src/ty/print/pretty.rs

+28-14
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc_hir::LangItem;
1919
use rustc_session::config::TrimmedDefPaths;
2020
use rustc_session::cstore::{ExternCrate, ExternCrateSource};
2121
use rustc_session::Limit;
22+
use rustc_span::sym;
2223
use rustc_span::symbol::{kw, Ident, Symbol};
2324
use rustc_span::FileNameDisplayPreference;
2425
use rustc_target::abi::Size;
@@ -966,7 +967,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
966967
define_scoped_cx!(cx);
967968
// Get the (single) generic ty (the args) of this FnOnce trait ref.
968969
let generics = tcx.generics_of(trait_ref.def_id);
969-
let (own_args, _) = generics.own_args_no_defaults(tcx, trait_ref.args);
970+
let own_args = generics.own_args_no_defaults(tcx, trait_ref.args);
970971

971972
match (entry.return_ty, own_args[0].expect_ty()) {
972973
// We can only print `impl Fn() -> ()` if we have a tuple of args and we recorded
@@ -1032,7 +1033,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
10321033
p!(print(trait_ref.print_only_trait_name()));
10331034

10341035
let generics = tcx.generics_of(trait_ref.def_id);
1035-
let (own_args, _) = generics.own_args_no_defaults(tcx, trait_ref.args);
1036+
let own_args = generics.own_args_no_defaults(tcx, trait_ref.args);
10361037

10371038
if !own_args.is_empty() || !assoc_items.is_empty() {
10381039
let mut first = true;
@@ -1184,7 +1185,6 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
11841185
)
11851186
},
11861187
&alias_ty.args[1..],
1187-
&self.tcx().generics_of(alias_ty.def_id).params,
11881188
)
11891189
}
11901190

@@ -1233,7 +1233,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
12331233
let dummy_cx = Ty::new_fresh(cx.tcx(), 0);
12341234
let principal = principal.with_self_ty(cx.tcx(), dummy_cx);
12351235

1236-
let (args, _) = cx
1236+
let args = cx
12371237
.tcx()
12381238
.generics_of(principal.def_id)
12391239
.own_args_no_defaults(cx.tcx(), principal.args);
@@ -2031,26 +2031,40 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
20312031
&mut self,
20322032
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
20332033
args: &[GenericArg<'tcx>],
2034-
params: &[ty::GenericParamDef],
20352034
) -> Result<(), PrintError> {
20362035
print_prefix(self)?;
20372036

20382037
let tcx = self.tcx;
2039-
let verbose = tcx.sess.verbose();
2040-
let mut args = args
2041-
.iter()
2042-
.copied()
2043-
.zip(params)
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 {
20442058
// If -Zverbose is passed, we should print the host parameter instead
20452059
// of eating it.
2046-
.filter(|(_, param)| verbose || !param.is_host_effect())
2047-
.peekable();
2060+
args.collect()
2061+
};
20482062

2049-
if args.peek().is_some() {
2063+
if !args.is_empty() {
20502064
if self.in_value {
20512065
write!(self, "::")?;
20522066
}
2053-
self.generic_delimiters(|cx| cx.comma_sep(args.map(|(arg, _)| arg)))
2067+
self.generic_delimiters(|cx| cx.comma_sep(args.into_iter()))
20542068
} else {
20552069
Ok(())
20562070
}

Diff for: compiler/rustc_symbol_mangling/src/legacy.rs

-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ impl<'tcx> Printer<'tcx> for SymbolPrinter<'tcx> {
342342
&mut self,
343343
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
344344
args: &[GenericArg<'tcx>],
345-
_params: &[ty::GenericParamDef],
346345
) -> Result<(), PrintError> {
347346
print_prefix(self)?;
348347

Diff for: compiler/rustc_symbol_mangling/src/v0.rs

-2
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
298298
)
299299
},
300300
args,
301-
&self.tcx.generics_of(impl_def_id).params,
302301
)?;
303302
} else {
304303
self.push_disambiguator(key.disambiguated_data.disambiguator as u64);
@@ -801,7 +800,6 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
801800
&mut self,
802801
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
803802
args: &[GenericArg<'tcx>],
804-
_params: &[ty::GenericParamDef],
805803
) -> Result<(), PrintError> {
806804
// Don't print any regions if they're all erased.
807805
let print_regions = args.iter().any(|arg| match arg.unpack() {

Diff for: tests/ui/rfcs/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0277]: the trait bound `S: ~const Foo` is not satisfied
1+
error[E0277]: the trait bound `S: ~const Foo<false>` is not satisfied
22
--> $DIR/call-generic-method-nonconst.rs:23:34
33
|
44
LL | pub const EQ: bool = equals_self(&S);

0 commit comments

Comments
 (0)