Skip to content

Commit 93742bd

Browse files
committed
Auto merge of rust-lang#131988 - matthiaskrgr:rollup-tx173wn, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - rust-lang#126588 (Added more scenarios where comma to be removed in the function arg) - rust-lang#131728 (bootstrap: extract builder cargo to its own module) - rust-lang#131968 (Rip out old effects var handling code from traits) - rust-lang#131981 (Remove the `BoundConstness::NotConst` variant) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f2ba411 + 62b7293 commit 93742bd

File tree

29 files changed

+1385
-1752
lines changed

29 files changed

+1385
-1752
lines changed

Diff for: compiler/rustc_const_eval/src/check_consts/qualifs.rs

+4-49
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ use rustc_errors::ErrorGuaranteed;
66
use rustc_hir::LangItem;
77
use rustc_infer::infer::TyCtxtInferExt;
88
use rustc_middle::mir::*;
9-
use rustc_middle::traits::BuiltinImplSource;
109
use rustc_middle::ty::{self, AdtDef, GenericArgsRef, Ty};
1110
use rustc_middle::{bug, mir};
12-
use rustc_trait_selection::traits::{
13-
ImplSource, Obligation, ObligationCause, ObligationCtxt, SelectionContext,
14-
};
15-
use tracing::{instrument, trace};
11+
use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt};
12+
use tracing::instrument;
1613

1714
use super::ConstCx;
1815

@@ -195,50 +192,8 @@ impl Qualif for NeedsNonConstDrop {
195192
return false;
196193
}
197194

198-
// FIXME(effects): If `destruct` is not a `const_trait`,
199-
// or effects are disabled in this crate, then give up.
200-
let destruct_def_id = cx.tcx.require_lang_item(LangItem::Destruct, Some(cx.body.span));
201-
if !cx.tcx.has_host_param(destruct_def_id) || !cx.tcx.features().effects {
202-
return NeedsDrop::in_any_value_of_ty(cx, ty);
203-
}
204-
205-
let obligation = Obligation::new(
206-
cx.tcx,
207-
ObligationCause::dummy_with_span(cx.body.span),
208-
cx.param_env,
209-
ty::TraitRef::new(cx.tcx, destruct_def_id, [
210-
ty::GenericArg::from(ty),
211-
ty::GenericArg::from(cx.tcx.expected_host_effect_param_for_body(cx.def_id())),
212-
]),
213-
);
214-
215-
let infcx = cx.tcx.infer_ctxt().build();
216-
let mut selcx = SelectionContext::new(&infcx);
217-
let Some(impl_src) = selcx.select(&obligation).ok().flatten() else {
218-
// If we couldn't select a const destruct candidate, then it's bad
219-
return true;
220-
};
221-
222-
trace!(?impl_src);
223-
224-
if !matches!(
225-
impl_src,
226-
ImplSource::Builtin(BuiltinImplSource::Misc, _) | ImplSource::Param(_)
227-
) {
228-
// If our const destruct candidate is not ConstDestruct or implied by the param env,
229-
// then it's bad
230-
return true;
231-
}
232-
233-
if impl_src.borrow_nested_obligations().is_empty() {
234-
return false;
235-
}
236-
237-
// If we had any errors, then it's bad
238-
let ocx = ObligationCtxt::new(&infcx);
239-
ocx.register_obligations(impl_src.nested_obligations());
240-
let errors = ocx.select_all_or_error();
241-
!errors.is_empty()
195+
// FIXME(effects): Reimplement const drop checking.
196+
NeedsDrop::in_any_value_of_ty(cx, ty)
242197
}
243198

244199
fn in_adt_inherently<'tcx>(

Diff for: compiler/rustc_hir_analysis/src/bounds.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'tcx> Bounds<'tcx> {
5151
bound_trait_ref: ty::PolyTraitRef<'tcx>,
5252
span: Span,
5353
polarity: ty::PredicatePolarity,
54-
constness: ty::BoundConstness,
54+
constness: Option<ty::BoundConstness>,
5555
predicate_filter: PredicateFilter,
5656
) {
5757
let clause = (
@@ -88,19 +88,20 @@ impl<'tcx> Bounds<'tcx> {
8888
// associated type of `<T as Tr>` and make sure that the effect is compatible.
8989
let compat_val = match (tcx.def_kind(defining_def_id), constness) {
9090
// FIXME(effects): revisit the correctness of this
91-
(_, ty::BoundConstness::Const) => tcx.consts.false_,
91+
(_, Some(ty::BoundConstness::Const)) => tcx.consts.false_,
9292
// body owners that can have trait bounds
93-
(DefKind::Const | DefKind::Fn | DefKind::AssocFn, ty::BoundConstness::ConstIfConst) => {
94-
tcx.expected_host_effect_param_for_body(defining_def_id)
95-
}
93+
(
94+
DefKind::Const | DefKind::Fn | DefKind::AssocFn,
95+
Some(ty::BoundConstness::ConstIfConst),
96+
) => tcx.expected_host_effect_param_for_body(defining_def_id),
9697

97-
(_, ty::BoundConstness::NotConst) => {
98+
(_, None) => {
9899
if !tcx.is_const_trait(bound_trait_ref.def_id()) {
99100
return;
100101
}
101102
tcx.consts.true_
102103
}
103-
(DefKind::Trait, ty::BoundConstness::ConstIfConst) => {
104+
(DefKind::Trait, Some(ty::BoundConstness::ConstIfConst)) => {
104105
// we are in a trait, where `bound_trait_ref` could be:
105106
// (1) a super trait `trait Foo: ~const Bar`.
106107
// - This generates `<Self as Foo>::Effects: TyCompat<<Self as Bar>::Effects>`
@@ -138,7 +139,7 @@ impl<'tcx> Bounds<'tcx> {
138139
return;
139140
}
140141

141-
(DefKind::Impl { of_trait: true }, ty::BoundConstness::ConstIfConst) => {
142+
(DefKind::Impl { of_trait: true }, Some(ty::BoundConstness::ConstIfConst)) => {
142143
// this is a where clause on an impl header.
143144
// push `<T as Tr>::Effects` into the set for the `Min` bound.
144145
let Some(assoc) = tcx.associated_type_for_effects(bound_trait_ref.def_id()) else {
@@ -172,12 +173,12 @@ impl<'tcx> Bounds<'tcx> {
172173
//
173174
// FIXME(effects) this is equality for now, which wouldn't be helpful for a non-const implementor
174175
// that uses a `Bar` that implements `Trait` with `Maybe` effects.
175-
(DefKind::AssocTy, ty::BoundConstness::ConstIfConst) => {
176+
(DefKind::AssocTy, Some(ty::BoundConstness::ConstIfConst)) => {
176177
// FIXME(effects): implement this
177178
return;
178179
}
179180
// probably illegal in this position.
180-
(_, ty::BoundConstness::ConstIfConst) => {
181+
(_, Some(ty::BoundConstness::ConstIfConst)) => {
181182
tcx.dcx().span_delayed_bug(span, "invalid `~const` encountered");
182183
return;
183184
}

Diff for: compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
171171
hir::GenericBound::Trait(poly_trait_ref) => {
172172
let (constness, polarity) = match poly_trait_ref.modifiers {
173173
hir::TraitBoundModifier::Const => {
174-
(ty::BoundConstness::Const, ty::PredicatePolarity::Positive)
175-
}
176-
hir::TraitBoundModifier::MaybeConst => {
177-
(ty::BoundConstness::ConstIfConst, ty::PredicatePolarity::Positive)
178-
}
179-
hir::TraitBoundModifier::None => {
180-
(ty::BoundConstness::NotConst, ty::PredicatePolarity::Positive)
174+
(Some(ty::BoundConstness::Const), ty::PredicatePolarity::Positive)
181175
}
176+
hir::TraitBoundModifier::MaybeConst => (
177+
Some(ty::BoundConstness::ConstIfConst),
178+
ty::PredicatePolarity::Positive,
179+
),
180+
hir::TraitBoundModifier::None => (None, ty::PredicatePolarity::Positive),
182181
hir::TraitBoundModifier::Negative => {
183-
(ty::BoundConstness::NotConst, ty::PredicatePolarity::Negative)
182+
(None, ty::PredicatePolarity::Negative)
184183
}
185184
hir::TraitBoundModifier::Maybe => continue,
186185
};

Diff for: compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
5151
} = self.lower_poly_trait_ref(
5252
&trait_bound.trait_ref,
5353
trait_bound.span,
54-
ty::BoundConstness::NotConst,
54+
None,
5555
ty::PredicatePolarity::Positive,
5656
dummy_self,
5757
&mut bounds,

Diff for: compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
652652
&self,
653653
trait_ref: &hir::TraitRef<'tcx>,
654654
span: Span,
655-
constness: ty::BoundConstness,
655+
constness: Option<ty::BoundConstness>,
656656
polarity: ty::PredicatePolarity,
657657
self_ty: Ty<'tcx>,
658658
bounds: &mut Bounds<'tcx>,
@@ -675,7 +675,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
675675
Some(self_ty),
676676
);
677677

678-
if let ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst = constness
678+
if let Some(constness) = constness
679679
&& !self.tcx().is_const_trait(trait_def_id)
680680
{
681681
self.dcx().emit_err(crate::errors::ConstBoundForNonConstTrait {

Diff for: compiler/rustc_hir_typeck/src/callee.rs

+1-34
Original file line numberDiff line numberDiff line change
@@ -537,40 +537,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
537537
//
538538
// This check is here because there is currently no way to express a trait bound for `FnDef` types only.
539539
if let ty::FnDef(def_id, _args) = *arg_ty.kind() {
540-
let fn_once_def_id =
541-
self.tcx.require_lang_item(hir::LangItem::FnOnce, Some(span));
542-
let fn_once_output_def_id =
543-
self.tcx.require_lang_item(hir::LangItem::FnOnceOutput, Some(span));
544-
if self.tcx.has_host_param(fn_once_def_id) {
545-
let const_param: ty::GenericArg<'tcx> =
546-
([self.tcx.consts.false_, self.tcx.consts.true_])[idx].into();
547-
self.register_predicate(traits::Obligation::new(
548-
self.tcx,
549-
self.misc(span),
550-
self.param_env,
551-
ty::TraitRef::new(self.tcx, fn_once_def_id, [
552-
arg_ty.into(),
553-
fn_sig.inputs()[0].into(),
554-
const_param,
555-
]),
556-
));
557-
558-
self.register_predicate(traits::Obligation::new(
559-
self.tcx,
560-
self.misc(span),
561-
self.param_env,
562-
ty::ProjectionPredicate {
563-
projection_term: ty::AliasTerm::new(
564-
self.tcx,
565-
fn_once_output_def_id,
566-
[arg_ty.into(), fn_sig.inputs()[0].into(), const_param],
567-
),
568-
term: fn_sig.output().into(),
569-
},
570-
));
571-
572-
self.select_obligations_where_possible(|_| {});
573-
} else if idx == 0 && !self.tcx.is_const_fn_raw(def_id) {
540+
if idx == 0 && !self.tcx.is_const_fn_raw(def_id) {
574541
self.dcx().emit_err(errors::ConstSelectMustBeConst { span });
575542
}
576543
} else {

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+25-5
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10971097
let mut only_extras_so_far = errors
10981098
.peek()
10991099
.is_some_and(|first| matches!(first, Error::Extra(arg_idx) if arg_idx.index() == 0));
1100+
let mut prev_extra_idx = None;
11001101
let mut suggestions = vec![];
11011102
while let Some(error) = errors.next() {
11021103
only_extras_so_far &= matches!(error, Error::Extra(_));
@@ -1165,11 +1166,29 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11651166
// fn f() {}
11661167
// - f(0, 1,)
11671168
// + f()
1168-
if only_extras_so_far
1169-
&& !errors
1170-
.peek()
1171-
.is_some_and(|next_error| matches!(next_error, Error::Extra(_)))
1172-
{
1169+
let trim_next_comma = match errors.peek() {
1170+
Some(Error::Extra(provided_idx))
1171+
if only_extras_so_far
1172+
&& provided_idx.index() > arg_idx.index() + 1 =>
1173+
// If the next Error::Extra ("next") doesn't next to current ("current"),
1174+
// fn foo(_: (), _: u32) {}
1175+
// - foo("current", (), 1u32, "next")
1176+
// + foo((), 1u32)
1177+
// If the previous error is not a `Error::Extra`, then do not trim the next comma
1178+
// - foo((), "current", 42u32, "next")
1179+
// + foo((), 42u32)
1180+
{
1181+
prev_extra_idx.map_or(true, |prev_extra_idx| {
1182+
prev_extra_idx + 1 == arg_idx.index()
1183+
})
1184+
}
1185+
// If no error left, we need to delete the next comma
1186+
None if only_extras_so_far => true,
1187+
// Not sure if other error type need to be handled as well
1188+
_ => false,
1189+
};
1190+
1191+
if trim_next_comma {
11731192
let next = provided_arg_tys
11741193
.get(arg_idx + 1)
11751194
.map(|&(_, sp)| sp)
@@ -1192,6 +1211,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11921211
SuggestionText::Remove(_) => SuggestionText::Remove(true),
11931212
_ => SuggestionText::DidYouMean,
11941213
};
1214+
prev_extra_idx = Some(arg_idx.index())
11951215
}
11961216
}
11971217
Error::Missing(expected_idx) => {

Diff for: compiler/rustc_middle/src/traits/select.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,7 @@ pub enum SelectionCandidate<'tcx> {
161161

162162
/// Implementation of a `Fn`-family trait by one of the anonymous
163163
/// types generated for a fn pointer type (e.g., `fn(int) -> int`)
164-
FnPointerCandidate {
165-
fn_host_effect: ty::Const<'tcx>,
166-
},
164+
FnPointerCandidate,
167165

168166
TraitAliasCandidate,
169167

@@ -180,9 +178,6 @@ pub enum SelectionCandidate<'tcx> {
180178
BuiltinObjectCandidate,
181179

182180
BuiltinUnsizeCandidate,
183-
184-
/// Implementation of `const Destruct`, optionally from a custom `impl const Drop`.
185-
ConstDestructCandidate(Option<DefId>),
186181
}
187182

188183
/// The result of trait evaluation. The order is important

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -1956,7 +1956,6 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
19561956
define_scoped_cx!(self);
19571957

19581958
match constness {
1959-
ty::BoundConstness::NotConst => {}
19601959
ty::BoundConstness::Const => {
19611960
p!("const ");
19621961
}
@@ -2948,7 +2947,10 @@ impl<'tcx> ty::TraitPredicate<'tcx> {
29482947
}
29492948

29502949
#[derive(Copy, Clone, TypeFoldable, TypeVisitable, Lift)]
2951-
pub struct TraitPredPrintWithBoundConstness<'tcx>(ty::TraitPredicate<'tcx>, ty::BoundConstness);
2950+
pub struct TraitPredPrintWithBoundConstness<'tcx>(
2951+
ty::TraitPredicate<'tcx>,
2952+
Option<ty::BoundConstness>,
2953+
);
29522954

29532955
impl<'tcx> fmt::Debug for TraitPredPrintWithBoundConstness<'tcx> {
29542956
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -2966,7 +2968,7 @@ impl<'tcx> ty::PolyTraitPredicate<'tcx> {
29662968

29672969
fn print_with_bound_constness(
29682970
self,
2969-
constness: ty::BoundConstness,
2971+
constness: Option<ty::BoundConstness>,
29702972
) -> ty::Binder<'tcx, TraitPredPrintWithBoundConstness<'tcx>> {
29712973
self.map_bound(|trait_pred| TraitPredPrintWithBoundConstness(trait_pred, constness))
29722974
}
@@ -3206,7 +3208,9 @@ define_print_and_forward_display! {
32063208

32073209
TraitPredPrintWithBoundConstness<'tcx> {
32083210
p!(print(self.0.trait_ref.self_ty()), ": ");
3209-
p!(pretty_print_bound_constness(self.1));
3211+
if let Some(constness) = self.1 {
3212+
p!(pretty_print_bound_constness(constness));
3213+
}
32103214
if let ty::PredicatePolarity::Negative = self.0.polarity {
32113215
p!("!");
32123216
}

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

-18
Original file line numberDiff line numberDiff line change
@@ -907,24 +907,6 @@ impl<'tcx> TyCtxt<'tcx> {
907907
}
908908
}
909909

910-
/// Constructs generic args for an item, optionally appending a const effect param type
911-
pub fn with_opt_host_effect_param(
912-
self,
913-
caller_def_id: LocalDefId,
914-
callee_def_id: DefId,
915-
args: impl IntoIterator<Item: Into<ty::GenericArg<'tcx>>>,
916-
) -> ty::GenericArgsRef<'tcx> {
917-
let generics = self.generics_of(callee_def_id);
918-
assert_eq!(generics.parent, None);
919-
920-
let opt_const_param = generics
921-
.host_effect_index
922-
.is_some()
923-
.then(|| ty::GenericArg::from(self.expected_host_effect_param_for_body(caller_def_id)));
924-
925-
self.mk_args_from_iter(args.into_iter().map(|arg| arg.into()).chain(opt_const_param))
926-
}
927-
928910
/// Expand any [weak alias types][weak] contained within the given `value`.
929911
///
930912
/// This should be used over other normalization routines in situations where

Diff for: compiler/rustc_mir_build/src/build/matches/test.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -454,12 +454,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
454454
};
455455

456456
let eq_def_id = self.tcx.require_lang_item(LangItem::PartialEq, Some(source_info.span));
457-
let method = trait_method(
458-
self.tcx,
459-
eq_def_id,
460-
sym::eq,
461-
self.tcx.with_opt_host_effect_param(self.def_id, eq_def_id, [compare_ty, compare_ty]),
462-
);
457+
let method = trait_method(self.tcx, eq_def_id, sym::eq, [compare_ty, compare_ty]);
463458

464459
let bool_ty = self.tcx.types.bool;
465460
let eq_result = self.temp(bool_ty, source_info.span);

0 commit comments

Comments
 (0)