Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 6f40082

Browse files
committed
Auto merge of rust-lang#118661 - fee1-dead-contrib:restore-const-partialEq, r=compiler-errors
Restore `const PartialEq` And thus fixes a number of tests. There is a bug that still needs to be fixed, so WIP for now. r? `@compiler-errors`
2 parents 8b1ba11 + c4c3555 commit 6f40082

38 files changed

+149
-194
lines changed

compiler/rustc_const_eval/src/util/type_name.rs

Lines changed: 0 additions & 1 deletion
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 =

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 2 additions & 3 deletions
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);

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

Lines changed: 1 addition & 2 deletions
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,

compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs

Lines changed: 4 additions & 8 deletions
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
}

compiler/rustc_lint/src/context.rs

Lines changed: 0 additions & 1 deletion
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
}

compiler/rustc_middle/src/hir/map/mod.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ impl<'hir> Map<'hir> {
336336
/// Returns the `BodyOwnerKind` of this `LocalDefId`.
337337
///
338338
/// Panics if `LocalDefId` does not have an associated body.
339-
pub fn body_owner_kind(self, def_id: LocalDefId) -> BodyOwnerKind {
339+
pub fn body_owner_kind(self, def_id: impl Into<DefId>) -> BodyOwnerKind {
340+
let def_id = def_id.into();
340341
match self.tcx.def_kind(def_id) {
341342
DefKind::Const | DefKind::AssocConst | DefKind::AnonConst => {
342343
BodyOwnerKind::Const { inline: false }
@@ -356,20 +357,17 @@ impl<'hir> Map<'hir> {
356357
/// This should only be used for determining the context of a body, a return
357358
/// value of `Some` does not always suggest that the owner of the body is `const`,
358359
/// just that it has to be checked as if it were.
359-
pub fn body_const_context(self, def_id: LocalDefId) -> Option<ConstContext> {
360+
pub fn body_const_context(self, def_id: impl Into<DefId>) -> Option<ConstContext> {
361+
let def_id = def_id.into();
360362
let ccx = match self.body_owner_kind(def_id) {
361363
BodyOwnerKind::Const { inline } => ConstContext::Const { inline },
362364
BodyOwnerKind::Static(mt) => ConstContext::Static(mt),
363365

364-
BodyOwnerKind::Fn if self.tcx.is_constructor(def_id.to_def_id()) => return None,
365-
BodyOwnerKind::Fn | BodyOwnerKind::Closure
366-
if self.tcx.is_const_fn_raw(def_id.to_def_id()) =>
367-
{
368-
ConstContext::ConstFn
369-
}
370-
BodyOwnerKind::Fn if self.tcx.is_const_default_method(def_id.to_def_id()) => {
366+
BodyOwnerKind::Fn if self.tcx.is_constructor(def_id) => return None,
367+
BodyOwnerKind::Fn | BodyOwnerKind::Closure if self.tcx.is_const_fn_raw(def_id) => {
371368
ConstContext::ConstFn
372369
}
370+
BodyOwnerKind::Fn if self.tcx.is_const_default_method(def_id) => ConstContext::ConstFn,
373371
BodyOwnerKind::Fn | BodyOwnerKind::Closure => return None,
374372
};
375373

compiler/rustc_middle/src/ty/generics.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -320,34 +320,34 @@ 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

329+
let verbose = tcx.sess.verbose();
330+
331331
// Filter the default arguments.
332332
//
333333
// This currently uses structural equality instead
334334
// of semantic equivalence. While not ideal, that's
335335
// good enough for now as this should only be used
336336
// for diagnostics anyways.
337-
let num_default_params = self
337+
own_params.end -= self
338338
.params
339339
.iter()
340340
.rev()
341341
.take_while(|param| {
342342
param.default_value(tcx).is_some_and(|default| {
343343
default.instantiate(tcx, args) == args[param.index as usize]
344344
})
345+
// filter out trailing effect params, if we're not in `-Zverbose`.
346+
|| (!verbose && matches!(param.kind, GenericParamDefKind::Const { is_host_effect: true, .. }))
345347
})
346348
.count();
347-
own_params.end -= num_default_params;
348-
own_args.end -= num_default_params;
349349

350-
(&args[own_args], &self.params[own_params])
350+
&args[own_params]
351351
}
352352

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

compiler/rustc_middle/src/ty/print/mod.rs

Lines changed: 1 addition & 4 deletions
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
}

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
965965
define_scoped_cx!(cx);
966966
// Get the (single) generic ty (the args) of this FnOnce trait ref.
967967
let generics = tcx.generics_of(trait_ref.def_id);
968-
let (own_args, _) = generics.own_args_no_defaults(tcx, trait_ref.args);
968+
let own_args = generics.own_args_no_defaults(tcx, trait_ref.args);
969969

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

10331033
let generics = tcx.generics_of(trait_ref.def_id);
1034-
let (own_args, _) = generics.own_args_no_defaults(tcx, trait_ref.args);
1034+
let own_args = generics.own_args_no_defaults(tcx, trait_ref.args);
10351035

10361036
if !own_args.is_empty() || !assoc_items.is_empty() {
10371037
let mut first = true;
@@ -1183,7 +1183,6 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
11831183
)
11841184
},
11851185
&alias_ty.args[1..],
1186-
&self.tcx().generics_of(alias_ty.def_id).params,
11871186
)
11881187
}
11891188

@@ -1232,7 +1231,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
12321231
let dummy_cx = Ty::new_fresh(cx.tcx(), 0);
12331232
let principal = principal.with_self_ty(cx.tcx(), dummy_cx);
12341233

1235-
let (args, _) = cx
1234+
let args = cx
12361235
.tcx()
12371236
.generics_of(principal.def_id)
12381237
.own_args_no_defaults(cx.tcx(), principal.args);
@@ -2030,26 +2029,14 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
20302029
&mut self,
20312030
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
20322031
args: &[GenericArg<'tcx>],
2033-
params: &[ty::GenericParamDef],
20342032
) -> Result<(), PrintError> {
20352033
print_prefix(self)?;
20362034

2037-
let tcx = self.tcx;
2038-
let verbose = tcx.sess.verbose();
2039-
let mut args = args
2040-
.iter()
2041-
.copied()
2042-
.zip(params)
2043-
// If -Zverbose is passed, we should print the host parameter instead
2044-
// of eating it.
2045-
.filter(|(_, param)| verbose || !param.is_host_effect())
2046-
.peekable();
2047-
2048-
if args.peek().is_some() {
2035+
if !args.is_empty() {
20492036
if self.in_value {
20502037
write!(self, "::")?;
20512038
}
2052-
self.generic_delimiters(|cx| cx.comma_sep(args.map(|(arg, _)| arg)))
2039+
self.generic_delimiters(|cx| cx.comma_sep(args.iter().copied()))
20532040
} else {
20542041
Ok(())
20552042
}
@@ -2881,7 +2868,8 @@ define_print_and_forward_display! {
28812868
TraitPredPrintModifiersAndPath<'tcx> {
28822869
if let Some(idx) = cx.tcx().generics_of(self.0.trait_ref.def_id).host_effect_index
28832870
{
2884-
if self.0.trait_ref.args.const_at(idx) != cx.tcx().consts.true_ {
2871+
let arg = self.0.trait_ref.args.const_at(idx);
2872+
if arg != cx.tcx().consts.true_ && !arg.has_infer() {
28852873
p!("~const ");
28862874
}
28872875
}

compiler/rustc_middle/src/ty/util.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,8 @@ impl<'tcx> TyCtxt<'tcx> {
782782
|| self.extern_crate(key.as_def_id()).is_some_and(|e| e.is_direct())
783783
}
784784

785-
pub fn expected_host_effect_param_for_body(self, def_id: LocalDefId) -> ty::Const<'tcx> {
785+
pub fn expected_host_effect_param_for_body(self, def_id: impl Into<DefId>) -> ty::Const<'tcx> {
786+
let def_id = def_id.into();
786787
// FIXME(effects): This is suspicious and should probably not be done,
787788
// especially now that we enforce host effects and then properly handle
788789
// effect vars during fallback.

0 commit comments

Comments
 (0)