authorbors <bors@rust-lang.org> 2024-06-26 07:22:41 UTC
committerbors <bors@rust-lang.org> 2024-06-26 07:22:41 UTC
log773180257062f55ea1d8b5736d97b57c30a8b677
tree66a375558e3c1bf9a8d157df3214a1f24a29b27e
parenta299aa5df79dd8e5a1405b97ddd7b367b61eecc6
parentb2720867f1f2ae1a481e991e39a9725cacdce48d

Auto merge of #126979 - matthiaskrgr:rollup-fdqledz, r=matthiaskrgr

Rollup of 10 pull requests Successful merges: - #126724 (Fix a span in `parse_ty_bare_fn`.) - #126812 (Rename `tcx` to `cx` in new solver generic code) - #126879 (fix Drop items getting leaked in Filter::next_chunk) - #126925 (Change E0369 to give note informations for foreign items.) - #126938 (miri: make sure we can find link_section statics even for the local crate) - #126954 (resolve: Tweak some naming around import ambiguities) - #126964 (Migrate `lto-empty`, `invalid-so` and `issue-20626` `run-make` tests to rmake.rs) - #126968 (Don't ICE during RPITIT refinement checking for resolution errors after normalization) - #126971 (Bump black, ruff and platformdirs) - #126973 (Fix bad replacement for unsafe extern block suggestion) r? `@ghost` `@rustbot` modify labels: rollup

63 files changed, 919 insertions(+), 620 deletions(-)

compiler/rustc_ast/src/ast.rs+2-1
......@@ -2126,7 +2126,8 @@ pub struct BareFnTy {
21262126 pub ext: Extern,
21272127 pub generic_params: ThinVec<GenericParam>,
21282128 pub decl: P<FnDecl>,
2129 /// Span of the `fn(...) -> ...` part.
2129 /// Span of the `[unsafe] [extern] fn(...) -> ...` part, i.e. everything
2130 /// after the generic params (if there are any, e.g. `for<'a>`).
21302131 pub decl_span: Span,
21312132}
21322133
compiler/rustc_ast_passes/src/ast_validation.rs+1-1
......@@ -464,7 +464,7 @@ impl<'a> AstValidator<'a> {
464464 {
465465 self.dcx().emit_err(errors::InvalidSafetyOnExtern {
466466 item_span: span,
467 block: self.current_extern_span(),
467 block: self.current_extern_span().shrink_to_lo(),
468468 });
469469 }
470470 }
compiler/rustc_ast_passes/src/errors.rs+1-1
......@@ -221,7 +221,7 @@ pub enum ExternBlockSuggestion {
221221pub struct InvalidSafetyOnExtern {
222222 #[primary_span]
223223 pub item_span: Span,
224 #[suggestion(code = "", applicability = "maybe-incorrect")]
224 #[suggestion(code = "unsafe ", applicability = "machine-applicable", style = "verbose")]
225225 pub block: Span,
226226}
227227
compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs+4-4
......@@ -171,10 +171,10 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
171171 }
172172 // Resolve any lifetime variables that may have been introduced during normalization.
173173 let Ok((trait_bounds, impl_bounds)) = infcx.fully_resolve((trait_bounds, impl_bounds)) else {
174 // This code path is not reached in any tests, but may be reachable. If
175 // this is triggered, it should be converted to `delayed_bug` and the
176 // triggering case turned into a test.
177 tcx.dcx().bug("encountered errors when checking RPITIT refinement (resolution)");
174 // If resolution didn't fully complete, we cannot continue checking RPITIT refinement, and
175 // delay a bug as the original code contains load-bearing errors.
176 tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (resolution)");
177 return;
178178 };
179179
180180 // For quicker lookup, use an `IndexSet` (we don't use one earlier because
compiler/rustc_hir_typeck/src/method/suggest.rs+76-26
......@@ -2831,32 +2831,38 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
28312831 errors: Vec<FulfillmentError<'tcx>>,
28322832 suggest_derive: bool,
28332833 ) {
2834 let all_local_types_needing_impls =
2835 errors.iter().all(|e| match e.obligation.predicate.kind().skip_binder() {
2834 let preds: Vec<_> = errors
2835 .iter()
2836 .filter_map(|e| match e.obligation.predicate.kind().skip_binder() {
28362837 ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) => {
28372838 match pred.self_ty().kind() {
2838 ty::Adt(def, _) => def.did().is_local(),
2839 _ => false,
2839 ty::Adt(_, _) => Some(pred),
2840 _ => None,
28402841 }
28412842 }
2842 _ => false,
2843 });
2844 let mut preds: Vec<_> = errors
2845 .iter()
2846 .filter_map(|e| match e.obligation.predicate.kind().skip_binder() {
2847 ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) => Some(pred),
28482843 _ => None,
28492844 })
28502845 .collect();
2851 preds.sort_by_key(|pred| pred.trait_ref.to_string());
2852 let def_ids = preds
2846
2847 // Note for local items and foreign items respectively.
2848 let (mut local_preds, mut foreign_preds): (Vec<_>, Vec<_>) =
2849 preds.iter().partition(|&pred| {
2850 if let ty::Adt(def, _) = pred.self_ty().kind() {
2851 def.did().is_local()
2852 } else {
2853 false
2854 }
2855 });
2856
2857 local_preds.sort_by_key(|pred: &&ty::TraitPredicate<'_>| pred.trait_ref.to_string());
2858 let local_def_ids = local_preds
28532859 .iter()
28542860 .filter_map(|pred| match pred.self_ty().kind() {
28552861 ty::Adt(def, _) => Some(def.did()),
28562862 _ => None,
28572863 })
28582864 .collect::<FxIndexSet<_>>();
2859 let mut spans: MultiSpan = def_ids
2865 let mut local_spans: MultiSpan = local_def_ids
28602866 .iter()
28612867 .filter_map(|def_id| {
28622868 let span = self.tcx.def_span(*def_id);
......@@ -2864,11 +2870,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
28642870 })
28652871 .collect::<Vec<_>>()
28662872 .into();
2867
2868 for pred in &preds {
2873 for pred in &local_preds {
28692874 match pred.self_ty().kind() {
2870 ty::Adt(def, _) if def.did().is_local() => {
2871 spans.push_span_label(
2875 ty::Adt(def, _) => {
2876 local_spans.push_span_label(
28722877 self.tcx.def_span(def.did()),
28732878 format!("must implement `{}`", pred.trait_ref.print_trait_sugared()),
28742879 );
......@@ -2876,24 +2881,69 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
28762881 _ => {}
28772882 }
28782883 }
2879
2880 if all_local_types_needing_impls && spans.primary_span().is_some() {
2881 let msg = if preds.len() == 1 {
2884 if local_spans.primary_span().is_some() {
2885 let msg = if local_preds.len() == 1 {
28822886 format!(
28832887 "an implementation of `{}` might be missing for `{}`",
2884 preds[0].trait_ref.print_trait_sugared(),
2885 preds[0].self_ty()
2888 local_preds[0].trait_ref.print_trait_sugared(),
2889 local_preds[0].self_ty()
28862890 )
28872891 } else {
28882892 format!(
28892893 "the following type{} would have to `impl` {} required trait{} for this \
28902894 operation to be valid",
2891 pluralize!(def_ids.len()),
2892 if def_ids.len() == 1 { "its" } else { "their" },
2893 pluralize!(preds.len()),
2895 pluralize!(local_def_ids.len()),
2896 if local_def_ids.len() == 1 { "its" } else { "their" },
2897 pluralize!(local_preds.len()),
2898 )
2899 };
2900 err.span_note(local_spans, msg);
2901 }
2902
2903 foreign_preds.sort_by_key(|pred: &&ty::TraitPredicate<'_>| pred.trait_ref.to_string());
2904 let foreign_def_ids = foreign_preds
2905 .iter()
2906 .filter_map(|pred| match pred.self_ty().kind() {
2907 ty::Adt(def, _) => Some(def.did()),
2908 _ => None,
2909 })
2910 .collect::<FxIndexSet<_>>();
2911 let mut foreign_spans: MultiSpan = foreign_def_ids
2912 .iter()
2913 .filter_map(|def_id| {
2914 let span = self.tcx.def_span(*def_id);
2915 if span.is_dummy() { None } else { Some(span) }
2916 })
2917 .collect::<Vec<_>>()
2918 .into();
2919 for pred in &foreign_preds {
2920 match pred.self_ty().kind() {
2921 ty::Adt(def, _) => {
2922 foreign_spans.push_span_label(
2923 self.tcx.def_span(def.did()),
2924 format!("not implement `{}`", pred.trait_ref.print_trait_sugared()),
2925 );
2926 }
2927 _ => {}
2928 }
2929 }
2930 if foreign_spans.primary_span().is_some() {
2931 let msg = if foreign_preds.len() == 1 {
2932 format!(
2933 "the foreign item type `{}` doesn't implement `{}`",
2934 foreign_preds[0].self_ty(),
2935 foreign_preds[0].trait_ref.print_trait_sugared()
2936 )
2937 } else {
2938 format!(
2939 "the foreign item type{} {} implement required trait{} for this \
2940 operation to be valid",
2941 pluralize!(foreign_def_ids.len()),
2942 if foreign_def_ids.len() > 1 { "don't" } else { "doesn't" },
2943 pluralize!(foreign_preds.len()),
28942944 )
28952945 };
2896 err.span_note(spans, msg);
2946 err.span_note(foreign_spans, msg);
28972947 }
28982948
28992949 let preds: Vec<_> = errors
compiler/rustc_next_trait_solver/src/solve/alias_relate.rs+3-3
......@@ -32,14 +32,14 @@ where
3232 &mut self,
3333 goal: Goal<I, (I::Term, I::Term, ty::AliasRelationDirection)>,
3434 ) -> QueryResult<I> {
35 let tcx = self.cx();
35 let cx = self.cx();
3636 let Goal { param_env, predicate: (lhs, rhs, direction) } = goal;
3737 debug_assert!(lhs.to_alias_term().is_some() || rhs.to_alias_term().is_some());
3838
3939 // Structurally normalize the lhs.
4040 let lhs = if let Some(alias) = lhs.to_alias_term() {
4141 let term = self.next_term_infer_of_kind(lhs);
42 self.add_normalizes_to_goal(goal.with(tcx, ty::NormalizesTo { alias, term }));
42 self.add_normalizes_to_goal(goal.with(cx, ty::NormalizesTo { alias, term }));
4343 term
4444 } else {
4545 lhs
......@@ -48,7 +48,7 @@ where
4848 // Structurally normalize the rhs.
4949 let rhs = if let Some(alias) = rhs.to_alias_term() {
5050 let term = self.next_term_infer_of_kind(rhs);
51 self.add_normalizes_to_goal(goal.with(tcx, ty::NormalizesTo { alias, term }));
51 self.add_normalizes_to_goal(goal.with(cx, ty::NormalizesTo { alias, term }));
5252 term
5353 } else {
5454 rhs
compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs+42-43
......@@ -36,11 +36,11 @@ where
3636{
3737 fn self_ty(self) -> I::Ty;
3838
39 fn trait_ref(self, tcx: I) -> ty::TraitRef<I>;
39 fn trait_ref(self, cx: I) -> ty::TraitRef<I>;
4040
41 fn with_self_ty(self, tcx: I, self_ty: I::Ty) -> Self;
41 fn with_self_ty(self, cx: I, self_ty: I::Ty) -> Self;
4242
43 fn trait_def_id(self, tcx: I) -> I::DefId;
43 fn trait_def_id(self, cx: I) -> I::DefId;
4444
4545 /// Try equating an assumption predicate against a goal's predicate. If it
4646 /// holds, then execute the `then` callback, which should do any additional
......@@ -82,7 +82,7 @@ where
8282 assumption: I::Clause,
8383 ) -> Result<Candidate<I>, NoSolution> {
8484 Self::probe_and_match_goal_against_assumption(ecx, source, goal, assumption, |ecx| {
85 let tcx = ecx.cx();
85 let cx = ecx.cx();
8686 let ty::Dynamic(bounds, _, _) = goal.predicate.self_ty().kind() else {
8787 panic!("expected object type in `probe_and_consider_object_bound_candidate`");
8888 };
......@@ -91,7 +91,7 @@ where
9191 structural_traits::predicates_for_object_candidate(
9292 ecx,
9393 goal.param_env,
94 goal.predicate.trait_ref(tcx),
94 goal.predicate.trait_ref(cx),
9595 bounds,
9696 ),
9797 );
......@@ -340,15 +340,15 @@ where
340340 goal: Goal<I, G>,
341341 candidates: &mut Vec<Candidate<I>>,
342342 ) {
343 let tcx = self.cx();
344 tcx.for_each_relevant_impl(
345 goal.predicate.trait_def_id(tcx),
343 let cx = self.cx();
344 cx.for_each_relevant_impl(
345 goal.predicate.trait_def_id(cx),
346346 goal.predicate.self_ty(),
347347 |impl_def_id| {
348348 // For every `default impl`, there's always a non-default `impl`
349349 // that will *also* apply. There's no reason to register a candidate
350350 // for this impl, since it is *not* proof that the trait goal holds.
351 if tcx.impl_is_default(impl_def_id) {
351 if cx.impl_is_default(impl_def_id) {
352352 return;
353353 }
354354
......@@ -366,8 +366,8 @@ where
366366 goal: Goal<I, G>,
367367 candidates: &mut Vec<Candidate<I>>,
368368 ) {
369 let tcx = self.cx();
370 let trait_def_id = goal.predicate.trait_def_id(tcx);
369 let cx = self.cx();
370 let trait_def_id = goal.predicate.trait_def_id(cx);
371371
372372 // N.B. When assembling built-in candidates for lang items that are also
373373 // `auto` traits, then the auto trait candidate that is assembled in
......@@ -378,47 +378,47 @@ where
378378 // `solve::trait_goals` instead.
379379 let result = if let Err(guar) = goal.predicate.error_reported() {
380380 G::consider_error_guaranteed_candidate(self, guar)
381 } else if tcx.trait_is_auto(trait_def_id) {
381 } else if cx.trait_is_auto(trait_def_id) {
382382 G::consider_auto_trait_candidate(self, goal)
383 } else if tcx.trait_is_alias(trait_def_id) {
383 } else if cx.trait_is_alias(trait_def_id) {
384384 G::consider_trait_alias_candidate(self, goal)
385 } else if tcx.is_lang_item(trait_def_id, TraitSolverLangItem::Sized) {
385 } else if cx.is_lang_item(trait_def_id, TraitSolverLangItem::Sized) {
386386 G::consider_builtin_sized_candidate(self, goal)
387 } else if tcx.is_lang_item(trait_def_id, TraitSolverLangItem::Copy)
388 || tcx.is_lang_item(trait_def_id, TraitSolverLangItem::Clone)
387 } else if cx.is_lang_item(trait_def_id, TraitSolverLangItem::Copy)
388 || cx.is_lang_item(trait_def_id, TraitSolverLangItem::Clone)
389389 {
390390 G::consider_builtin_copy_clone_candidate(self, goal)
391 } else if tcx.is_lang_item(trait_def_id, TraitSolverLangItem::PointerLike) {
391 } else if cx.is_lang_item(trait_def_id, TraitSolverLangItem::PointerLike) {
392392 G::consider_builtin_pointer_like_candidate(self, goal)
393 } else if tcx.is_lang_item(trait_def_id, TraitSolverLangItem::FnPtrTrait) {
393 } else if cx.is_lang_item(trait_def_id, TraitSolverLangItem::FnPtrTrait) {
394394 G::consider_builtin_fn_ptr_trait_candidate(self, goal)
395395 } else if let Some(kind) = self.cx().fn_trait_kind_from_def_id(trait_def_id) {
396396 G::consider_builtin_fn_trait_candidates(self, goal, kind)
397397 } else if let Some(kind) = self.cx().async_fn_trait_kind_from_def_id(trait_def_id) {
398398 G::consider_builtin_async_fn_trait_candidates(self, goal, kind)
399 } else if tcx.is_lang_item(trait_def_id, TraitSolverLangItem::AsyncFnKindHelper) {
399 } else if cx.is_lang_item(trait_def_id, TraitSolverLangItem::AsyncFnKindHelper) {
400400 G::consider_builtin_async_fn_kind_helper_candidate(self, goal)
401 } else if tcx.is_lang_item(trait_def_id, TraitSolverLangItem::Tuple) {
401 } else if cx.is_lang_item(trait_def_id, TraitSolverLangItem::Tuple) {
402402 G::consider_builtin_tuple_candidate(self, goal)
403 } else if tcx.is_lang_item(trait_def_id, TraitSolverLangItem::PointeeTrait) {
403 } else if cx.is_lang_item(trait_def_id, TraitSolverLangItem::PointeeTrait) {
404404 G::consider_builtin_pointee_candidate(self, goal)
405 } else if tcx.is_lang_item(trait_def_id, TraitSolverLangItem::Future) {
405 } else if cx.is_lang_item(trait_def_id, TraitSolverLangItem::Future) {
406406 G::consider_builtin_future_candidate(self, goal)
407 } else if tcx.is_lang_item(trait_def_id, TraitSolverLangItem::Iterator) {
407 } else if cx.is_lang_item(trait_def_id, TraitSolverLangItem::Iterator) {
408408 G::consider_builtin_iterator_candidate(self, goal)
409 } else if tcx.is_lang_item(trait_def_id, TraitSolverLangItem::FusedIterator) {
409 } else if cx.is_lang_item(trait_def_id, TraitSolverLangItem::FusedIterator) {
410410 G::consider_builtin_fused_iterator_candidate(self, goal)
411 } else if tcx.is_lang_item(trait_def_id, TraitSolverLangItem::AsyncIterator) {
411 } else if cx.is_lang_item(trait_def_id, TraitSolverLangItem::AsyncIterator) {
412412 G::consider_builtin_async_iterator_candidate(self, goal)
413 } else if tcx.is_lang_item(trait_def_id, TraitSolverLangItem::Coroutine) {
413 } else if cx.is_lang_item(trait_def_id, TraitSolverLangItem::Coroutine) {
414414 G::consider_builtin_coroutine_candidate(self, goal)
415 } else if tcx.is_lang_item(trait_def_id, TraitSolverLangItem::DiscriminantKind) {
415 } else if cx.is_lang_item(trait_def_id, TraitSolverLangItem::DiscriminantKind) {
416416 G::consider_builtin_discriminant_kind_candidate(self, goal)
417 } else if tcx.is_lang_item(trait_def_id, TraitSolverLangItem::AsyncDestruct) {
417 } else if cx.is_lang_item(trait_def_id, TraitSolverLangItem::AsyncDestruct) {
418418 G::consider_builtin_async_destruct_candidate(self, goal)
419 } else if tcx.is_lang_item(trait_def_id, TraitSolverLangItem::Destruct) {
419 } else if cx.is_lang_item(trait_def_id, TraitSolverLangItem::Destruct) {
420420 G::consider_builtin_destruct_candidate(self, goal)
421 } else if tcx.is_lang_item(trait_def_id, TraitSolverLangItem::TransmuteTrait) {
421 } else if cx.is_lang_item(trait_def_id, TraitSolverLangItem::TransmuteTrait) {
422422 G::consider_builtin_transmute_candidate(self, goal)
423423 } else {
424424 Err(NoSolution)
......@@ -428,7 +428,7 @@ where
428428
429429 // There may be multiple unsize candidates for a trait with several supertraits:
430430 // `trait Foo: Bar<A> + Bar<B>` and `dyn Foo: Unsize<dyn Bar<_>>`
431 if tcx.is_lang_item(trait_def_id, TraitSolverLangItem::Unsize) {
431 if cx.is_lang_item(trait_def_id, TraitSolverLangItem::Unsize) {
432432 candidates.extend(G::consider_structural_builtin_unsize_candidates(self, goal));
433433 }
434434 }
......@@ -557,8 +557,8 @@ where
557557 goal: Goal<I, G>,
558558 candidates: &mut Vec<Candidate<I>>,
559559 ) {
560 let tcx = self.cx();
561 if !tcx.trait_may_be_implemented_via_object(goal.predicate.trait_def_id(tcx)) {
560 let cx = self.cx();
561 if !cx.trait_may_be_implemented_via_object(goal.predicate.trait_def_id(cx)) {
562562 return;
563563 }
564564
......@@ -596,7 +596,7 @@ where
596596 };
597597
598598 // Do not consider built-in object impls for non-object-safe types.
599 if bounds.principal_def_id().is_some_and(|def_id| !tcx.trait_is_object_safe(def_id)) {
599 if bounds.principal_def_id().is_some_and(|def_id| !cx.trait_is_object_safe(def_id)) {
600600 return;
601601 }
602602
......@@ -614,7 +614,7 @@ where
614614 self,
615615 CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
616616 goal,
617 bound.with_self_ty(tcx, self_ty),
617 bound.with_self_ty(cx, self_ty),
618618 ));
619619 }
620620 }
......@@ -624,14 +624,13 @@ where
624624 // since we don't need to look at any supertrait or anything if we are doing
625625 // a projection goal.
626626 if let Some(principal) = bounds.principal() {
627 let principal_trait_ref = principal.with_self_ty(tcx, self_ty);
628 for (idx, assumption) in D::elaborate_supertraits(tcx, principal_trait_ref).enumerate()
629 {
627 let principal_trait_ref = principal.with_self_ty(cx, self_ty);
628 for (idx, assumption) in D::elaborate_supertraits(cx, principal_trait_ref).enumerate() {
630629 candidates.extend(G::probe_and_consider_object_bound_candidate(
631630 self,
632631 CandidateSource::BuiltinImpl(BuiltinImplSource::Object(idx)),
633632 goal,
634 assumption.upcast(tcx),
633 assumption.upcast(cx),
635634 ));
636635 }
637636 }
......@@ -649,11 +648,11 @@ where
649648 goal: Goal<I, G>,
650649 candidates: &mut Vec<Candidate<I>>,
651650 ) {
652 let tcx = self.cx();
651 let cx = self.cx();
653652
654653 candidates.extend(self.probe_trait_candidate(CandidateSource::CoherenceUnknowable).enter(
655654 |ecx| {
656 let trait_ref = goal.predicate.trait_ref(tcx);
655 let trait_ref = goal.predicate.trait_ref(cx);
657656 if ecx.trait_ref_is_knowable(goal.param_env, trait_ref)? {
658657 Err(NoSolution)
659658 } else {
......@@ -678,9 +677,9 @@ where
678677 goal: Goal<I, G>,
679678 candidates: &mut Vec<Candidate<I>>,
680679 ) {
681 let tcx = self.cx();
680 let cx = self.cx();
682681 let trait_goal: Goal<I, ty::TraitPredicate<I>> =
683 goal.with(tcx, goal.predicate.trait_ref(tcx));
682 goal.with(cx, goal.predicate.trait_ref(cx));
684683
685684 let mut trait_candidates_from_env = vec![];
686685 self.probe(|_| ProbeKind::ShadowedEnvProbing).enter(|ecx| {
compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs+55-57
......@@ -23,7 +23,7 @@ where
2323 D: SolverDelegate<Interner = I>,
2424 I: Interner,
2525{
26 let tcx = ecx.cx();
26 let cx = ecx.cx();
2727 match ty.kind() {
2828 ty::Uint(_)
2929 | ty::Int(_)
......@@ -36,7 +36,7 @@ where
3636 | ty::Char => Ok(vec![]),
3737
3838 // Treat `str` like it's defined as `struct str([u8]);`
39 ty::Str => Ok(vec![ty::Binder::dummy(Ty::new_slice(tcx, Ty::new_u8(tcx)))]),
39 ty::Str => Ok(vec![ty::Binder::dummy(Ty::new_slice(cx, Ty::new_u8(cx)))]),
4040
4141 ty::Dynamic(..)
4242 | ty::Param(..)
......@@ -79,21 +79,21 @@ where
7979 .cx()
8080 .bound_coroutine_hidden_types(def_id)
8181 .into_iter()
82 .map(|bty| bty.instantiate(tcx, args))
82 .map(|bty| bty.instantiate(cx, args))
8383 .collect()),
8484
8585 // For `PhantomData<T>`, we pass `T`.
8686 ty::Adt(def, args) if def.is_phantom_data() => Ok(vec![ty::Binder::dummy(args.type_at(0))]),
8787
8888 ty::Adt(def, args) => {
89 Ok(def.all_field_tys(tcx).iter_instantiated(tcx, args).map(ty::Binder::dummy).collect())
89 Ok(def.all_field_tys(cx).iter_instantiated(cx, args).map(ty::Binder::dummy).collect())
9090 }
9191
9292 ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => {
9393 // We can resolve the `impl Trait` to its concrete type,
9494 // which enforces a DAG between the functions requiring
9595 // the auto trait bounds in question.
96 Ok(vec![ty::Binder::dummy(tcx.type_of(def_id).instantiate(tcx, args))])
96 Ok(vec![ty::Binder::dummy(cx.type_of(def_id).instantiate(cx, args))])
9797 }
9898 }
9999}
......@@ -247,18 +247,18 @@ where
247247
248248// Returns a binder of the tupled inputs types and output type from a builtin callable type.
249249pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable<I: Interner>(
250 tcx: I,
250 cx: I,
251251 self_ty: I::Ty,
252252 goal_kind: ty::ClosureKind,
253253) -> Result<Option<ty::Binder<I, (I::Ty, I::Ty)>>, NoSolution> {
254254 match self_ty.kind() {
255255 // keep this in sync with assemble_fn_pointer_candidates until the old solver is removed.
256256 ty::FnDef(def_id, args) => {
257 let sig = tcx.fn_sig(def_id);
258 if sig.skip_binder().is_fn_trait_compatible() && !tcx.has_target_features(def_id) {
257 let sig = cx.fn_sig(def_id);
258 if sig.skip_binder().is_fn_trait_compatible() && !cx.has_target_features(def_id) {
259259 Ok(Some(
260 sig.instantiate(tcx, args)
261 .map_bound(|sig| (Ty::new_tup(tcx, sig.inputs().as_slice()), sig.output())),
260 sig.instantiate(cx, args)
261 .map_bound(|sig| (Ty::new_tup(cx, sig.inputs().as_slice()), sig.output())),
262262 ))
263263 } else {
264264 Err(NoSolution)
......@@ -268,7 +268,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable<I: Intern
268268 ty::FnPtr(sig) => {
269269 if sig.is_fn_trait_compatible() {
270270 Ok(Some(
271 sig.map_bound(|sig| (Ty::new_tup(tcx, sig.inputs().as_slice()), sig.output())),
271 sig.map_bound(|sig| (Ty::new_tup(cx, sig.inputs().as_slice()), sig.output())),
272272 ))
273273 } else {
274274 Err(NoSolution)
......@@ -323,10 +323,10 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable<I: Intern
323323 }
324324
325325 coroutine_closure_to_certain_coroutine(
326 tcx,
326 cx,
327327 goal_kind,
328328 // No captures by ref, so this doesn't matter.
329 Region::new_static(tcx),
329 Region::new_static(cx),
330330 def_id,
331331 args,
332332 sig,
......@@ -339,9 +339,9 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable<I: Intern
339339 }
340340
341341 coroutine_closure_to_ambiguous_coroutine(
342 tcx,
342 cx,
343343 goal_kind, // No captures by ref, so this doesn't matter.
344 Region::new_static(tcx),
344 Region::new_static(cx),
345345 def_id,
346346 args,
347347 sig,
......@@ -403,7 +403,7 @@ pub(in crate::solve) struct AsyncCallableRelevantTypes<I: Interner> {
403403// which enforces the closure is actually callable with the given trait. When we
404404// know the kind already, we can short-circuit this check.
405405pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I: Interner>(
406 tcx: I,
406 cx: I,
407407 self_ty: I::Ty,
408408 goal_kind: ty::ClosureKind,
409409 env_region: I::Region,
......@@ -422,9 +422,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I:
422422 return Err(NoSolution);
423423 }
424424
425 coroutine_closure_to_certain_coroutine(
426 tcx, goal_kind, env_region, def_id, args, sig,
427 )
425 coroutine_closure_to_certain_coroutine(cx, goal_kind, env_region, def_id, args, sig)
428426 } else {
429427 // When we don't know the closure kind (and therefore also the closure's upvars,
430428 // which are computed at the same time), we must delay the computation of the
......@@ -435,15 +433,15 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I:
435433 // coroutine upvars respecting the closure kind.
436434 nested.push(
437435 ty::TraitRef::new(
438 tcx,
439 tcx.require_lang_item(TraitSolverLangItem::AsyncFnKindHelper),
440 [kind_ty, Ty::from_closure_kind(tcx, goal_kind)],
436 cx,
437 cx.require_lang_item(TraitSolverLangItem::AsyncFnKindHelper),
438 [kind_ty, Ty::from_closure_kind(cx, goal_kind)],
441439 )
442 .upcast(tcx),
440 .upcast(cx),
443441 );
444442
445443 coroutine_closure_to_ambiguous_coroutine(
446 tcx, goal_kind, env_region, def_id, args, sig,
444 cx, goal_kind, env_region, def_id, args, sig,
447445 )
448446 };
449447
......@@ -458,21 +456,21 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I:
458456 }
459457
460458 ty::FnDef(..) | ty::FnPtr(..) => {
461 let bound_sig = self_ty.fn_sig(tcx);
459 let bound_sig = self_ty.fn_sig(cx);
462460 let sig = bound_sig.skip_binder();
463 let future_trait_def_id = tcx.require_lang_item(TraitSolverLangItem::Future);
461 let future_trait_def_id = cx.require_lang_item(TraitSolverLangItem::Future);
464462 // `FnDef` and `FnPtr` only implement `AsyncFn*` when their
465463 // return type implements `Future`.
466464 let nested = vec![
467465 bound_sig
468 .rebind(ty::TraitRef::new(tcx, future_trait_def_id, [sig.output()]))
469 .upcast(tcx),
466 .rebind(ty::TraitRef::new(cx, future_trait_def_id, [sig.output()]))
467 .upcast(cx),
470468 ];
471 let future_output_def_id = tcx.require_lang_item(TraitSolverLangItem::FutureOutput);
472 let future_output_ty = Ty::new_projection(tcx, future_output_def_id, [sig.output()]);
469 let future_output_def_id = cx.require_lang_item(TraitSolverLangItem::FutureOutput);
470 let future_output_ty = Ty::new_projection(cx, future_output_def_id, [sig.output()]);
473471 Ok((
474472 bound_sig.rebind(AsyncCallableRelevantTypes {
475 tupled_inputs_ty: Ty::new_tup(tcx, sig.inputs().as_slice()),
473 tupled_inputs_ty: Ty::new_tup(cx, sig.inputs().as_slice()),
476474 output_coroutine_ty: sig.output(),
477475 coroutine_return_ty: future_output_ty,
478476 }),
......@@ -483,13 +481,13 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I:
483481 let args = args.as_closure();
484482 let bound_sig = args.sig();
485483 let sig = bound_sig.skip_binder();
486 let future_trait_def_id = tcx.require_lang_item(TraitSolverLangItem::Future);
484 let future_trait_def_id = cx.require_lang_item(TraitSolverLangItem::Future);
487485 // `Closure`s only implement `AsyncFn*` when their return type
488486 // implements `Future`.
489487 let mut nested = vec![
490488 bound_sig
491 .rebind(ty::TraitRef::new(tcx, future_trait_def_id, [sig.output()]))
492 .upcast(tcx),
489 .rebind(ty::TraitRef::new(cx, future_trait_def_id, [sig.output()]))
490 .upcast(cx),
493491 ];
494492
495493 // Additionally, we need to check that the closure kind
......@@ -501,7 +499,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I:
501499 }
502500 } else {
503501 let async_fn_kind_trait_def_id =
504 tcx.require_lang_item(TraitSolverLangItem::AsyncFnKindHelper);
502 cx.require_lang_item(TraitSolverLangItem::AsyncFnKindHelper);
505503 // When we don't know the closure kind (and therefore also the closure's upvars,
506504 // which are computed at the same time), we must delay the computation of the
507505 // generator's upvars. We do this using the `AsyncFnKindHelper`, which as a trait
......@@ -511,16 +509,16 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I:
511509 // coroutine upvars respecting the closure kind.
512510 nested.push(
513511 ty::TraitRef::new(
514 tcx,
512 cx,
515513 async_fn_kind_trait_def_id,
516 [kind_ty, Ty::from_closure_kind(tcx, goal_kind)],
514 [kind_ty, Ty::from_closure_kind(cx, goal_kind)],
517515 )
518 .upcast(tcx),
516 .upcast(cx),
519517 );
520518 }
521519
522 let future_output_def_id = tcx.require_lang_item(TraitSolverLangItem::FutureOutput);
523 let future_output_ty = Ty::new_projection(tcx, future_output_def_id, [sig.output()]);
520 let future_output_def_id = cx.require_lang_item(TraitSolverLangItem::FutureOutput);
521 let future_output_ty = Ty::new_projection(cx, future_output_def_id, [sig.output()]);
524522 Ok((
525523 bound_sig.rebind(AsyncCallableRelevantTypes {
526524 tupled_inputs_ty: sig.inputs().get(0).unwrap(),
......@@ -565,7 +563,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I:
565563/// Given a coroutine-closure, project to its returned coroutine when we are *certain*
566564/// that the closure's kind is compatible with the goal.
567565fn coroutine_closure_to_certain_coroutine<I: Interner>(
568 tcx: I,
566 cx: I,
569567 goal_kind: ty::ClosureKind,
570568 goal_region: I::Region,
571569 def_id: I::DefId,
......@@ -573,9 +571,9 @@ fn coroutine_closure_to_certain_coroutine<I: Interner>(
573571 sig: ty::CoroutineClosureSignature<I>,
574572) -> I::Ty {
575573 sig.to_coroutine_given_kind_and_upvars(
576 tcx,
574 cx,
577575 args.parent_args(),
578 tcx.coroutine_for_closure(def_id),
576 cx.coroutine_for_closure(def_id),
579577 goal_kind,
580578 goal_region,
581579 args.tupled_upvars_ty(),
......@@ -589,20 +587,20 @@ fn coroutine_closure_to_certain_coroutine<I: Interner>(
589587///
590588/// Note that we do not also push a `AsyncFnKindHelper` goal here.
591589fn coroutine_closure_to_ambiguous_coroutine<I: Interner>(
592 tcx: I,
590 cx: I,
593591 goal_kind: ty::ClosureKind,
594592 goal_region: I::Region,
595593 def_id: I::DefId,
596594 args: ty::CoroutineClosureArgs<I>,
597595 sig: ty::CoroutineClosureSignature<I>,
598596) -> I::Ty {
599 let upvars_projection_def_id = tcx.require_lang_item(TraitSolverLangItem::AsyncFnKindUpvars);
597 let upvars_projection_def_id = cx.require_lang_item(TraitSolverLangItem::AsyncFnKindUpvars);
600598 let tupled_upvars_ty = Ty::new_projection(
601 tcx,
599 cx,
602600 upvars_projection_def_id,
603601 [
604602 I::GenericArg::from(args.kind_ty()),
605 Ty::from_closure_kind(tcx, goal_kind).into(),
603 Ty::from_closure_kind(cx, goal_kind).into(),
606604 goal_region.into(),
607605 sig.tupled_inputs_ty.into(),
608606 args.tupled_upvars_ty().into(),
......@@ -610,10 +608,10 @@ fn coroutine_closure_to_ambiguous_coroutine<I: Interner>(
610608 ],
611609 );
612610 sig.to_coroutine(
613 tcx,
611 cx,
614612 args.parent_args(),
615 Ty::from_closure_kind(tcx, goal_kind),
616 tcx.coroutine_for_closure(def_id),
613 Ty::from_closure_kind(cx, goal_kind),
614 cx.coroutine_for_closure(def_id),
617615 tupled_upvars_ty,
618616 )
619617}
......@@ -668,28 +666,28 @@ where
668666 D: SolverDelegate<Interner = I>,
669667 I: Interner,
670668{
671 let tcx = ecx.cx();
669 let cx = ecx.cx();
672670 let mut requirements = vec![];
673671 requirements
674 .extend(tcx.super_predicates_of(trait_ref.def_id).iter_instantiated(tcx, trait_ref.args));
672 .extend(cx.super_predicates_of(trait_ref.def_id).iter_instantiated(cx, trait_ref.args));
675673
676674 // FIXME(associated_const_equality): Also add associated consts to
677675 // the requirements here.
678 for associated_type_def_id in tcx.associated_type_def_ids(trait_ref.def_id) {
676 for associated_type_def_id in cx.associated_type_def_ids(trait_ref.def_id) {
679677 // associated types that require `Self: Sized` do not show up in the built-in
680678 // implementation of `Trait for dyn Trait`, and can be dropped here.
681 if tcx.generics_require_sized_self(associated_type_def_id) {
679 if cx.generics_require_sized_self(associated_type_def_id) {
682680 continue;
683681 }
684682
685683 requirements
686 .extend(tcx.item_bounds(associated_type_def_id).iter_instantiated(tcx, trait_ref.args));
684 .extend(cx.item_bounds(associated_type_def_id).iter_instantiated(cx, trait_ref.args));
687685 }
688686
689687 let mut replace_projection_with = HashMap::default();
690688 for bound in object_bounds.iter() {
691689 if let ty::ExistentialPredicate::Projection(proj) = bound.skip_binder() {
692 let proj = proj.with_self_ty(tcx, trait_ref.self_ty());
690 let proj = proj.with_self_ty(cx, trait_ref.self_ty());
693691 let old_ty = replace_projection_with.insert(proj.def_id(), bound.rebind(proj));
694692 assert_eq!(
695693 old_ty,
......@@ -709,7 +707,7 @@ where
709707 folder
710708 .nested
711709 .into_iter()
712 .chain(folded_requirements.into_iter().map(|clause| Goal::new(tcx, param_env, clause)))
710 .chain(folded_requirements.into_iter().map(|clause| Goal::new(cx, param_env, clause)))
713711 .collect()
714712}
715713
compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs+11-11
......@@ -239,14 +239,14 @@ where
239239 /// This function takes care of setting up the inference context, setting the anchor,
240240 /// and registering opaques from the canonicalized input.
241241 fn enter_canonical<R>(
242 tcx: I,
242 cx: I,
243243 search_graph: &'a mut search_graph::SearchGraph<I>,
244244 canonical_input: CanonicalInput<I>,
245245 canonical_goal_evaluation: &mut ProofTreeBuilder<D>,
246246 f: impl FnOnce(&mut EvalCtxt<'_, D>, Goal<I, I::Predicate>) -> R,
247247 ) -> R {
248248 let (ref delegate, input, var_values) =
249 SolverDelegate::build_with_canonical(tcx, search_graph.solver_mode(), &canonical_input);
249 SolverDelegate::build_with_canonical(cx, search_graph.solver_mode(), &canonical_input);
250250
251251 let mut ecx = EvalCtxt {
252252 delegate,
......@@ -292,9 +292,9 @@ where
292292 /// Instead of calling this function directly, use either [EvalCtxt::evaluate_goal]
293293 /// if you're inside of the solver or [SolverDelegateEvalExt::evaluate_root_goal] if you're
294294 /// outside of it.
295 #[instrument(level = "debug", skip(tcx, search_graph, goal_evaluation), ret)]
295 #[instrument(level = "debug", skip(cx, search_graph, goal_evaluation), ret)]
296296 fn evaluate_canonical_goal(
297 tcx: I,
297 cx: I,
298298 search_graph: &'a mut search_graph::SearchGraph<I>,
299299 canonical_input: CanonicalInput<I>,
300300 goal_evaluation: &mut ProofTreeBuilder<D>,
......@@ -307,12 +307,12 @@ where
307307 // The actual solver logic happens in `ecx.compute_goal`.
308308 let result = ensure_sufficient_stack(|| {
309309 search_graph.with_new_goal(
310 tcx,
310 cx,
311311 canonical_input,
312312 &mut canonical_goal_evaluation,
313313 |search_graph, canonical_goal_evaluation| {
314314 EvalCtxt::enter_canonical(
315 tcx,
315 cx,
316316 search_graph,
317317 canonical_input,
318318 canonical_goal_evaluation,
......@@ -506,7 +506,7 @@ where
506506 ///
507507 /// Goals for the next step get directly added to the nested goals of the `EvalCtxt`.
508508 fn evaluate_added_goals_step(&mut self) -> Result<Option<Certainty>, NoSolution> {
509 let tcx = self.cx();
509 let cx = self.cx();
510510 let mut goals = core::mem::take(&mut self.nested_goals);
511511
512512 // If this loop did not result in any progress, what's our final certainty.
......@@ -516,7 +516,7 @@ where
516516 // RHS does not affect projection candidate assembly.
517517 let unconstrained_rhs = self.next_term_infer_of_kind(goal.predicate.term);
518518 let unconstrained_goal = goal.with(
519 tcx,
519 cx,
520520 ty::NormalizesTo { alias: goal.predicate.alias, term: unconstrained_rhs },
521521 );
522522
......@@ -777,7 +777,7 @@ where
777777 // NOTE: this check is purely an optimization, the structural eq would
778778 // always fail if the term is not an inference variable.
779779 if term.is_infer() {
780 let tcx = self.cx();
780 let cx = self.cx();
781781 // We need to relate `alias` to `term` treating only the outermost
782782 // constructor as rigid, relating any contained generic arguments as
783783 // normal. We do this by first structurally equating the `term`
......@@ -787,8 +787,8 @@ where
787787 // Alternatively we could modify `Equate` for this case by adding another
788788 // variant to `StructurallyRelateAliases`.
789789 let identity_args = self.fresh_args_for_item(alias.def_id);
790 let rigid_ctor = ty::AliasTerm::new_from_args(tcx, alias.def_id, identity_args);
791 let ctor_term = rigid_ctor.to_term(tcx);
790 let rigid_ctor = ty::AliasTerm::new_from_args(cx, alias.def_id, identity_args);
791 let ctor_term = rigid_ctor.to_term(cx);
792792 let obligations =
793793 self.delegate.eq_structurally_relating_aliases(param_env, term, ctor_term)?;
794794 debug_assert!(obligations.is_empty());
compiler/rustc_next_trait_solver/src/solve/inspect/build.rs+2-2
......@@ -323,13 +323,13 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> ProofTreeBuilder<D> {
323323
324324 pub fn finalize_canonical_goal_evaluation(
325325 &mut self,
326 tcx: I,
326 cx: I,
327327 ) -> Option<I::CanonicalGoalEvaluationStepRef> {
328328 self.as_mut().map(|this| match this {
329329 DebugSolver::CanonicalGoalEvaluation(evaluation) => {
330330 let final_revision = mem::take(&mut evaluation.final_revision).unwrap();
331331 let final_revision =
332 tcx.intern_canonical_goal_evaluation_step(final_revision.finalize());
332 cx.intern_canonical_goal_evaluation_step(final_revision.finalize());
333333 let kind = WipCanonicalGoalEvaluationKind::Interned { final_revision };
334334 assert_eq!(evaluation.kind.replace(kind), None);
335335 final_revision
compiler/rustc_next_trait_solver/src/solve/mod.rs+6-6
......@@ -34,7 +34,7 @@ use crate::delegate::SolverDelegate;
3434/// How many fixpoint iterations we should attempt inside of the solver before bailing
3535/// with overflow.
3636///
37/// We previously used `tcx.recursion_limit().0.checked_ilog2().unwrap_or(0)` for this.
37/// We previously used `cx.recursion_limit().0.checked_ilog2().unwrap_or(0)` for this.
3838/// However, it feels unlikely that uncreasing the recursion limit by a power of two
3939/// to get one more itereation is every useful or desirable. We now instead used a constant
4040/// here. If there ever ends up some use-cases where a bigger number of fixpoint iterations
......@@ -285,7 +285,7 @@ where
285285}
286286
287287fn response_no_constraints_raw<I: Interner>(
288 tcx: I,
288 cx: I,
289289 max_universe: ty::UniverseIndex,
290290 variables: I::CanonicalVars,
291291 certainty: Certainty,
......@@ -294,10 +294,10 @@ fn response_no_constraints_raw<I: Interner>(
294294 max_universe,
295295 variables,
296296 value: Response {
297 var_values: ty::CanonicalVarValues::make_identity(tcx, variables),
298 // FIXME: maybe we should store the "no response" version in tcx, like
299 // we do for tcx.types and stuff.
300 external_constraints: tcx.mk_external_constraints(ExternalConstraintsData::default()),
297 var_values: ty::CanonicalVarValues::make_identity(cx, variables),
298 // FIXME: maybe we should store the "no response" version in cx, like
299 // we do for cx.types and stuff.
300 external_constraints: cx.mk_external_constraints(ExternalConstraintsData::default()),
301301 certainty,
302302 },
303303 defining_opaque_types: Default::default(),
compiler/rustc_next_trait_solver/src/solve/normalizes_to/inherent.rs+9-9
......@@ -19,21 +19,21 @@ where
1919 &mut self,
2020 goal: Goal<I, ty::NormalizesTo<I>>,
2121 ) -> QueryResult<I> {
22 let tcx = self.cx();
23 let inherent = goal.predicate.alias.expect_ty(tcx);
22 let cx = self.cx();
23 let inherent = goal.predicate.alias.expect_ty(cx);
2424
25 let impl_def_id = tcx.parent(inherent.def_id);
25 let impl_def_id = cx.parent(inherent.def_id);
2626 let impl_args = self.fresh_args_for_item(impl_def_id);
2727
2828 // Equate impl header and add impl where clauses
2929 self.eq(
3030 goal.param_env,
3131 inherent.self_ty(),
32 tcx.type_of(impl_def_id).instantiate(tcx, impl_args),
32 cx.type_of(impl_def_id).instantiate(cx, impl_args),
3333 )?;
3434
3535 // Equate IAT with the RHS of the project goal
36 let inherent_args = inherent.rebase_inherent_args_onto_impl(impl_args, tcx);
36 let inherent_args = inherent.rebase_inherent_args_onto_impl(impl_args, cx);
3737
3838 // Check both where clauses on the impl and IAT
3939 //
......@@ -43,12 +43,12 @@ where
4343 // and I don't think the assoc item where-bounds are allowed to be coinductive.
4444 self.add_goals(
4545 GoalSource::Misc,
46 tcx.predicates_of(inherent.def_id)
47 .iter_instantiated(tcx, inherent_args)
48 .map(|pred| goal.with(tcx, pred)),
46 cx.predicates_of(inherent.def_id)
47 .iter_instantiated(cx, inherent_args)
48 .map(|pred| goal.with(cx, pred)),
4949 );
5050
51 let normalized = tcx.type_of(inherent.def_id).instantiate(tcx, inherent_args);
51 let normalized = cx.type_of(inherent.def_id).instantiate(cx, inherent_args);
5252 self.instantiate_normalizes_to_term(goal, normalized.into());
5353 self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
5454 }
compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs+97-102
......@@ -84,16 +84,16 @@ where
8484 self.self_ty()
8585 }
8686
87 fn trait_ref(self, tcx: I) -> ty::TraitRef<I> {
88 self.alias.trait_ref(tcx)
87 fn trait_ref(self, cx: I) -> ty::TraitRef<I> {
88 self.alias.trait_ref(cx)
8989 }
9090
91 fn with_self_ty(self, tcx: I, self_ty: I::Ty) -> Self {
92 self.with_self_ty(tcx, self_ty)
91 fn with_self_ty(self, cx: I, self_ty: I::Ty) -> Self {
92 self.with_self_ty(cx, self_ty)
9393 }
9494
95 fn trait_def_id(self, tcx: I) -> I::DefId {
96 self.trait_def_id(tcx)
95 fn trait_def_id(self, cx: I) -> I::DefId {
96 self.trait_def_id(cx)
9797 }
9898
9999 fn probe_and_match_goal_against_assumption(
......@@ -105,7 +105,7 @@ where
105105 ) -> Result<Candidate<I>, NoSolution> {
106106 if let Some(projection_pred) = assumption.as_projection_clause() {
107107 if projection_pred.projection_def_id() == goal.predicate.def_id() {
108 let tcx = ecx.cx();
108 let cx = ecx.cx();
109109 ecx.probe_trait_candidate(source).enter(|ecx| {
110110 let assumption_projection_pred =
111111 ecx.instantiate_binder_with_infer(projection_pred);
......@@ -120,9 +120,9 @@ where
120120 // Add GAT where clauses from the trait's definition
121121 ecx.add_goals(
122122 GoalSource::Misc,
123 tcx.own_predicates_of(goal.predicate.def_id())
124 .iter_instantiated(tcx, goal.predicate.alias.args)
125 .map(|pred| goal.with(tcx, pred)),
123 cx.own_predicates_of(goal.predicate.def_id())
124 .iter_instantiated(cx, goal.predicate.alias.args)
125 .map(|pred| goal.with(cx, pred)),
126126 );
127127
128128 then(ecx)
......@@ -140,19 +140,19 @@ where
140140 goal: Goal<I, NormalizesTo<I>>,
141141 impl_def_id: I::DefId,
142142 ) -> Result<Candidate<I>, NoSolution> {
143 let tcx = ecx.cx();
143 let cx = ecx.cx();
144144
145 let goal_trait_ref = goal.predicate.alias.trait_ref(tcx);
146 let impl_trait_ref = tcx.impl_trait_ref(impl_def_id);
145 let goal_trait_ref = goal.predicate.alias.trait_ref(cx);
146 let impl_trait_ref = cx.impl_trait_ref(impl_def_id);
147147 if !ecx.cx().args_may_unify_deep(
148 goal.predicate.alias.trait_ref(tcx).args,
148 goal.predicate.alias.trait_ref(cx).args,
149149 impl_trait_ref.skip_binder().args,
150150 ) {
151151 return Err(NoSolution);
152152 }
153153
154154 // We have to ignore negative impls when projecting.
155 let impl_polarity = tcx.impl_polarity(impl_def_id);
155 let impl_polarity = cx.impl_polarity(impl_def_id);
156156 match impl_polarity {
157157 ty::ImplPolarity::Negative => return Err(NoSolution),
158158 ty::ImplPolarity::Reservation => {
......@@ -163,22 +163,22 @@ where
163163
164164 ecx.probe_trait_candidate(CandidateSource::Impl(impl_def_id)).enter(|ecx| {
165165 let impl_args = ecx.fresh_args_for_item(impl_def_id);
166 let impl_trait_ref = impl_trait_ref.instantiate(tcx, impl_args);
166 let impl_trait_ref = impl_trait_ref.instantiate(cx, impl_args);
167167
168168 ecx.eq(goal.param_env, goal_trait_ref, impl_trait_ref)?;
169169
170 let where_clause_bounds = tcx
170 let where_clause_bounds = cx
171171 .predicates_of(impl_def_id)
172 .iter_instantiated(tcx, impl_args)
173 .map(|pred| goal.with(tcx, pred));
172 .iter_instantiated(cx, impl_args)
173 .map(|pred| goal.with(cx, pred));
174174 ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds);
175175
176176 // Add GAT where clauses from the trait's definition
177177 ecx.add_goals(
178178 GoalSource::Misc,
179 tcx.own_predicates_of(goal.predicate.def_id())
180 .iter_instantiated(tcx, goal.predicate.alias.args)
181 .map(|pred| goal.with(tcx, pred)),
179 cx.own_predicates_of(goal.predicate.def_id())
180 .iter_instantiated(cx, goal.predicate.alias.args)
181 .map(|pred| goal.with(cx, pred)),
182182 );
183183
184184 // In case the associated item is hidden due to specialization, we have to
......@@ -195,21 +195,21 @@ where
195195 };
196196
197197 let error_response = |ecx: &mut EvalCtxt<'_, D>, msg: &str| {
198 let guar = tcx.delay_bug(msg);
199 let error_term = match goal.predicate.alias.kind(tcx) {
200 ty::AliasTermKind::ProjectionTy => Ty::new_error(tcx, guar).into(),
201 ty::AliasTermKind::ProjectionConst => Const::new_error(tcx, guar).into(),
198 let guar = cx.delay_bug(msg);
199 let error_term = match goal.predicate.alias.kind(cx) {
200 ty::AliasTermKind::ProjectionTy => Ty::new_error(cx, guar).into(),
201 ty::AliasTermKind::ProjectionConst => Const::new_error(cx, guar).into(),
202202 kind => panic!("expected projection, found {kind:?}"),
203203 };
204204 ecx.instantiate_normalizes_to_term(goal, error_term);
205205 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
206206 };
207207
208 if !tcx.has_item_definition(target_item_def_id) {
208 if !cx.has_item_definition(target_item_def_id) {
209209 return error_response(ecx, "missing item");
210210 }
211211
212 let target_container_def_id = tcx.parent(target_item_def_id);
212 let target_container_def_id = cx.parent(target_item_def_id);
213213
214214 // Getting the right args here is complex, e.g. given:
215215 // - a goal `<Vec<u32> as Trait<i32>>::Assoc<u64>`
......@@ -229,22 +229,22 @@ where
229229 target_container_def_id,
230230 )?;
231231
232 if !tcx.check_args_compatible(target_item_def_id, target_args) {
232 if !cx.check_args_compatible(target_item_def_id, target_args) {
233233 return error_response(ecx, "associated item has mismatched arguments");
234234 }
235235
236236 // Finally we construct the actual value of the associated type.
237 let term = match goal.predicate.alias.kind(tcx) {
237 let term = match goal.predicate.alias.kind(cx) {
238238 ty::AliasTermKind::ProjectionTy => {
239 tcx.type_of(target_item_def_id).map_bound(|ty| ty.into())
239 cx.type_of(target_item_def_id).map_bound(|ty| ty.into())
240240 }
241241 ty::AliasTermKind::ProjectionConst => {
242 if tcx.features().associated_const_equality() {
242 if cx.features().associated_const_equality() {
243243 panic!("associated const projection is not supported yet")
244244 } else {
245245 ty::EarlyBinder::bind(
246246 Const::new_error_with_message(
247 tcx,
247 cx,
248248 "associated const projection is not supported yet",
249249 )
250250 .into(),
......@@ -254,7 +254,7 @@ where
254254 kind => panic!("expected projection, found {kind:?}"),
255255 };
256256
257 ecx.instantiate_normalizes_to_term(goal, term.instantiate(tcx, target_args));
257 ecx.instantiate_normalizes_to_term(goal, term.instantiate(cx, target_args));
258258 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
259259 })
260260 }
......@@ -316,10 +316,10 @@ where
316316 goal: Goal<I, Self>,
317317 goal_kind: ty::ClosureKind,
318318 ) -> Result<Candidate<I>, NoSolution> {
319 let tcx = ecx.cx();
319 let cx = ecx.cx();
320320 let tupled_inputs_and_output =
321321 match structural_traits::extract_tupled_inputs_and_output_from_callable(
322 tcx,
322 cx,
323323 goal.predicate.self_ty(),
324324 goal_kind,
325325 )? {
......@@ -329,19 +329,19 @@ where
329329 }
330330 };
331331 let output_is_sized_pred = tupled_inputs_and_output.map_bound(|(_, output)| {
332 ty::TraitRef::new(tcx, tcx.require_lang_item(TraitSolverLangItem::Sized), [output])
332 ty::TraitRef::new(cx, cx.require_lang_item(TraitSolverLangItem::Sized), [output])
333333 });
334334
335335 let pred = tupled_inputs_and_output
336336 .map_bound(|(inputs, output)| ty::ProjectionPredicate {
337337 projection_term: ty::AliasTerm::new(
338 tcx,
338 cx,
339339 goal.predicate.def_id(),
340340 [goal.predicate.self_ty(), inputs],
341341 ),
342342 term: output.into(),
343343 })
344 .upcast(tcx);
344 .upcast(cx);
345345
346346 // A built-in `Fn` impl only holds if the output is sized.
347347 // (FIXME: technically we only need to check this if the type is a fn ptr...)
......@@ -350,7 +350,7 @@ where
350350 CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
351351 goal,
352352 pred,
353 [(GoalSource::ImplWhereBound, goal.with(tcx, output_is_sized_pred))],
353 [(GoalSource::ImplWhereBound, goal.with(cx, output_is_sized_pred))],
354354 )
355355 }
356356
......@@ -359,27 +359,23 @@ where
359359 goal: Goal<I, Self>,
360360 goal_kind: ty::ClosureKind,
361361 ) -> Result<Candidate<I>, NoSolution> {
362 let tcx = ecx.cx();
362 let cx = ecx.cx();
363363
364364 let env_region = match goal_kind {
365365 ty::ClosureKind::Fn | ty::ClosureKind::FnMut => goal.predicate.alias.args.region_at(2),
366366 // Doesn't matter what this region is
367 ty::ClosureKind::FnOnce => Region::new_static(tcx),
367 ty::ClosureKind::FnOnce => Region::new_static(cx),
368368 };
369369 let (tupled_inputs_and_output_and_coroutine, nested_preds) =
370370 structural_traits::extract_tupled_inputs_and_output_from_async_callable(
371 tcx,
371 cx,
372372 goal.predicate.self_ty(),
373373 goal_kind,
374374 env_region,
375375 )?;
376376 let output_is_sized_pred = tupled_inputs_and_output_and_coroutine.map_bound(
377377 |AsyncCallableRelevantTypes { output_coroutine_ty: output_ty, .. }| {
378 ty::TraitRef::new(
379 tcx,
380 tcx.require_lang_item(TraitSolverLangItem::Sized),
381 [output_ty],
382 )
378 ty::TraitRef::new(cx, cx.require_lang_item(TraitSolverLangItem::Sized), [output_ty])
383379 },
384380 );
385381
......@@ -390,23 +386,23 @@ where
390386 output_coroutine_ty,
391387 coroutine_return_ty,
392388 }| {
393 let (projection_term, term) = if tcx
389 let (projection_term, term) = if cx
394390 .is_lang_item(goal.predicate.def_id(), TraitSolverLangItem::CallOnceFuture)
395391 {
396392 (
397393 ty::AliasTerm::new(
398 tcx,
394 cx,
399395 goal.predicate.def_id(),
400396 [goal.predicate.self_ty(), tupled_inputs_ty],
401397 ),
402398 output_coroutine_ty.into(),
403399 )
404 } else if tcx
400 } else if cx
405401 .is_lang_item(goal.predicate.def_id(), TraitSolverLangItem::CallRefFuture)
406402 {
407403 (
408404 ty::AliasTerm::new(
409 tcx,
405 cx,
410406 goal.predicate.def_id(),
411407 [
412408 I::GenericArg::from(goal.predicate.self_ty()),
......@@ -416,13 +412,13 @@ where
416412 ),
417413 output_coroutine_ty.into(),
418414 )
419 } else if tcx.is_lang_item(
415 } else if cx.is_lang_item(
420416 goal.predicate.def_id(),
421417 TraitSolverLangItem::AsyncFnOnceOutput,
422418 ) {
423419 (
424420 ty::AliasTerm::new(
425 tcx,
421 cx,
426422 goal.predicate.def_id(),
427423 [
428424 I::GenericArg::from(goal.predicate.self_ty()),
......@@ -440,7 +436,7 @@ where
440436 ty::ProjectionPredicate { projection_term, term }
441437 },
442438 )
443 .upcast(tcx);
439 .upcast(cx);
444440
445441 // A built-in `AsyncFn` impl only holds if the output is sized.
446442 // (FIXME: technically we only need to check this if the type is a fn ptr...)
......@@ -449,9 +445,9 @@ where
449445 CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
450446 goal,
451447 pred,
452 [goal.with(tcx, output_is_sized_pred)]
448 [goal.with(cx, output_is_sized_pred)]
453449 .into_iter()
454 .chain(nested_preds.into_iter().map(|pred| goal.with(tcx, pred)))
450 .chain(nested_preds.into_iter().map(|pred| goal.with(cx, pred)))
455451 .map(|goal| (GoalSource::ImplWhereBound, goal)),
456452 )
457453 }
......@@ -514,8 +510,8 @@ where
514510 ecx: &mut EvalCtxt<'_, D>,
515511 goal: Goal<I, Self>,
516512 ) -> Result<Candidate<I>, NoSolution> {
517 let tcx = ecx.cx();
518 let metadata_def_id = tcx.require_lang_item(TraitSolverLangItem::Metadata);
513 let cx = ecx.cx();
514 let metadata_def_id = cx.require_lang_item(TraitSolverLangItem::Metadata);
519515 assert_eq!(metadata_def_id, goal.predicate.def_id());
520516 ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| {
521517 let metadata_ty = match goal.predicate.self_ty().kind() {
......@@ -537,16 +533,16 @@ where
537533 | ty::CoroutineWitness(..)
538534 | ty::Never
539535 | ty::Foreign(..)
540 | ty::Dynamic(_, _, ty::DynStar) => Ty::new_unit(tcx),
536 | ty::Dynamic(_, _, ty::DynStar) => Ty::new_unit(cx),
541537
542 ty::Error(e) => Ty::new_error(tcx, e),
538 ty::Error(e) => Ty::new_error(cx, e),
543539
544 ty::Str | ty::Slice(_) => Ty::new_usize(tcx),
540 ty::Str | ty::Slice(_) => Ty::new_usize(cx),
545541
546542 ty::Dynamic(_, _, ty::Dyn) => {
547 let dyn_metadata = tcx.require_lang_item(TraitSolverLangItem::DynMetadata);
548 tcx.type_of(dyn_metadata)
549 .instantiate(tcx, &[I::GenericArg::from(goal.predicate.self_ty())])
543 let dyn_metadata = cx.require_lang_item(TraitSolverLangItem::DynMetadata);
544 cx.type_of(dyn_metadata)
545 .instantiate(cx, &[I::GenericArg::from(goal.predicate.self_ty())])
550546 }
551547
552548 ty::Alias(_, _) | ty::Param(_) | ty::Placeholder(..) => {
......@@ -555,26 +551,26 @@ where
555551 // FIXME(ptr_metadata): This impl overlaps with the other impls and shouldn't
556552 // exist. Instead, `Pointee<Metadata = ()>` should be a supertrait of `Sized`.
557553 let sized_predicate = ty::TraitRef::new(
558 tcx,
559 tcx.require_lang_item(TraitSolverLangItem::Sized),
554 cx,
555 cx.require_lang_item(TraitSolverLangItem::Sized),
560556 [I::GenericArg::from(goal.predicate.self_ty())],
561557 );
562558 // FIXME(-Znext-solver=coinductive): Should this be `GoalSource::ImplWhereBound`?
563 ecx.add_goal(GoalSource::Misc, goal.with(tcx, sized_predicate));
564 Ty::new_unit(tcx)
559 ecx.add_goal(GoalSource::Misc, goal.with(cx, sized_predicate));
560 Ty::new_unit(cx)
565561 }
566562
567 ty::Adt(def, args) if def.is_struct() => match def.struct_tail_ty(tcx) {
568 None => Ty::new_unit(tcx),
563 ty::Adt(def, args) if def.is_struct() => match def.struct_tail_ty(cx) {
564 None => Ty::new_unit(cx),
569565 Some(tail_ty) => {
570 Ty::new_projection(tcx, metadata_def_id, [tail_ty.instantiate(tcx, args)])
566 Ty::new_projection(cx, metadata_def_id, [tail_ty.instantiate(cx, args)])
571567 }
572568 },
573 ty::Adt(_, _) => Ty::new_unit(tcx),
569 ty::Adt(_, _) => Ty::new_unit(cx),
574570
575571 ty::Tuple(elements) => match elements.last() {
576 None => Ty::new_unit(tcx),
577 Some(tail_ty) => Ty::new_projection(tcx, metadata_def_id, [tail_ty]),
572 None => Ty::new_unit(cx),
573 Some(tail_ty) => Ty::new_projection(cx, metadata_def_id, [tail_ty]),
578574 },
579575
580576 ty::Infer(
......@@ -601,8 +597,8 @@ where
601597 };
602598
603599 // Coroutines are not futures unless they come from `async` desugaring
604 let tcx = ecx.cx();
605 if !tcx.coroutine_is_async(def_id) {
600 let cx = ecx.cx();
601 if !cx.coroutine_is_async(def_id) {
606602 return Err(NoSolution);
607603 }
608604
......@@ -616,7 +612,7 @@ where
616612 projection_term: ty::AliasTerm::new(ecx.cx(), goal.predicate.def_id(), [self_ty]),
617613 term,
618614 }
619 .upcast(tcx),
615 .upcast(cx),
620616 // Technically, we need to check that the future type is Sized,
621617 // but that's already proven by the coroutine being WF.
622618 [],
......@@ -633,8 +629,8 @@ where
633629 };
634630
635631 // Coroutines are not Iterators unless they come from `gen` desugaring
636 let tcx = ecx.cx();
637 if !tcx.coroutine_is_gen(def_id) {
632 let cx = ecx.cx();
633 if !cx.coroutine_is_gen(def_id) {
638634 return Err(NoSolution);
639635 }
640636
......@@ -648,7 +644,7 @@ where
648644 projection_term: ty::AliasTerm::new(ecx.cx(), goal.predicate.def_id(), [self_ty]),
649645 term,
650646 }
651 .upcast(tcx),
647 .upcast(cx),
652648 // Technically, we need to check that the iterator type is Sized,
653649 // but that's already proven by the generator being WF.
654650 [],
......@@ -672,8 +668,8 @@ where
672668 };
673669
674670 // Coroutines are not AsyncIterators unless they come from `gen` desugaring
675 let tcx = ecx.cx();
676 if !tcx.coroutine_is_async_gen(def_id) {
671 let cx = ecx.cx();
672 if !cx.coroutine_is_async_gen(def_id) {
677673 return Err(NoSolution);
678674 }
679675
......@@ -682,12 +678,12 @@ where
682678 // Take `AsyncIterator<Item = I>` and turn it into the corresponding
683679 // coroutine yield ty `Poll<Option<I>>`.
684680 let wrapped_expected_ty = Ty::new_adt(
685 tcx,
686 tcx.adt_def(tcx.require_lang_item(TraitSolverLangItem::Poll)),
687 tcx.mk_args(&[Ty::new_adt(
688 tcx,
689 tcx.adt_def(tcx.require_lang_item(TraitSolverLangItem::Option)),
690 tcx.mk_args(&[expected_ty.into()]),
681 cx,
682 cx.adt_def(cx.require_lang_item(TraitSolverLangItem::Poll)),
683 cx.mk_args(&[Ty::new_adt(
684 cx,
685 cx.adt_def(cx.require_lang_item(TraitSolverLangItem::Option)),
686 cx.mk_args(&[expected_ty.into()]),
691687 )
692688 .into()]),
693689 );
......@@ -708,18 +704,17 @@ where
708704 };
709705
710706 // `async`-desugared coroutines do not implement the coroutine trait
711 let tcx = ecx.cx();
712 if !tcx.is_general_coroutine(def_id) {
707 let cx = ecx.cx();
708 if !cx.is_general_coroutine(def_id) {
713709 return Err(NoSolution);
714710 }
715711
716712 let coroutine = args.as_coroutine();
717713
718 let term = if tcx
719 .is_lang_item(goal.predicate.def_id(), TraitSolverLangItem::CoroutineReturn)
714 let term = if cx.is_lang_item(goal.predicate.def_id(), TraitSolverLangItem::CoroutineReturn)
720715 {
721716 coroutine.return_ty().into()
722 } else if tcx.is_lang_item(goal.predicate.def_id(), TraitSolverLangItem::CoroutineYield) {
717 } else if cx.is_lang_item(goal.predicate.def_id(), TraitSolverLangItem::CoroutineYield) {
723718 coroutine.yield_ty().into()
724719 } else {
725720 panic!("unexpected associated item `{:?}` for `{self_ty:?}`", goal.predicate.def_id())
......@@ -737,7 +732,7 @@ where
737732 ),
738733 term,
739734 }
740 .upcast(tcx),
735 .upcast(cx),
741736 // Technically, we need to check that the coroutine type is Sized,
742737 // but that's already proven by the coroutine being WF.
743738 [],
......@@ -884,29 +879,29 @@ where
884879 impl_trait_ref: rustc_type_ir::TraitRef<I>,
885880 target_container_def_id: I::DefId,
886881 ) -> Result<I::GenericArgs, NoSolution> {
887 let tcx = self.cx();
882 let cx = self.cx();
888883 Ok(if target_container_def_id == impl_trait_ref.def_id {
889884 // Default value from the trait definition. No need to rebase.
890885 goal.predicate.alias.args
891886 } else if target_container_def_id == impl_def_id {
892887 // Same impl, no need to fully translate, just a rebase from
893888 // the trait is sufficient.
894 goal.predicate.alias.args.rebase_onto(tcx, impl_trait_ref.def_id, impl_args)
889 goal.predicate.alias.args.rebase_onto(cx, impl_trait_ref.def_id, impl_args)
895890 } else {
896891 let target_args = self.fresh_args_for_item(target_container_def_id);
897892 let target_trait_ref =
898 tcx.impl_trait_ref(target_container_def_id).instantiate(tcx, target_args);
893 cx.impl_trait_ref(target_container_def_id).instantiate(cx, target_args);
899894 // Relate source impl to target impl by equating trait refs.
900895 self.eq(goal.param_env, impl_trait_ref, target_trait_ref)?;
901896 // Also add predicates since they may be needed to constrain the
902897 // target impl's params.
903898 self.add_goals(
904899 GoalSource::Misc,
905 tcx.predicates_of(target_container_def_id)
906 .iter_instantiated(tcx, target_args)
907 .map(|pred| goal.with(tcx, pred)),
900 cx.predicates_of(target_container_def_id)
901 .iter_instantiated(cx, target_args)
902 .map(|pred| goal.with(cx, pred)),
908903 );
909 goal.predicate.alias.args.rebase_onto(tcx, impl_trait_ref.def_id, target_args)
904 goal.predicate.alias.args.rebase_onto(cx, impl_trait_ref.def_id, target_args)
910905 })
911906 }
912907}
compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs+3-3
......@@ -18,7 +18,7 @@ where
1818 &mut self,
1919 goal: Goal<I, ty::NormalizesTo<I>>,
2020 ) -> QueryResult<I> {
21 let tcx = self.cx();
21 let cx = self.cx();
2222 let opaque_ty = goal.predicate.alias;
2323 let expected = goal.predicate.term.as_type().expect("no such thing as an opaque const");
2424
......@@ -86,7 +86,7 @@ where
8686 }
8787 (Reveal::All, _) => {
8888 // FIXME: Add an assertion that opaque type storage is empty.
89 let actual = tcx.type_of(opaque_ty.def_id).instantiate(tcx, opaque_ty.args);
89 let actual = cx.type_of(opaque_ty.def_id).instantiate(cx, opaque_ty.args);
9090 self.eq(goal.param_env, expected, actual)?;
9191 self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
9292 }
......@@ -98,7 +98,7 @@ where
9898///
9999/// FIXME: Interner argument is needed to constrain the `I` parameter.
100100pub fn uses_unique_placeholders_ignoring_regions<I: Interner>(
101 _interner: I,
101 _cx: I,
102102 args: I::GenericArgs,
103103) -> Result<(), NotUniqueParam<I>> {
104104 let mut seen = GrowableBitSet::default();
compiler/rustc_next_trait_solver/src/solve/normalizes_to/weak_types.rs+5-5
......@@ -18,18 +18,18 @@ where
1818 &mut self,
1919 goal: Goal<I, ty::NormalizesTo<I>>,
2020 ) -> QueryResult<I> {
21 let tcx = self.cx();
21 let cx = self.cx();
2222 let weak_ty = goal.predicate.alias;
2323
2424 // Check where clauses
2525 self.add_goals(
2626 GoalSource::Misc,
27 tcx.predicates_of(weak_ty.def_id)
28 .iter_instantiated(tcx, weak_ty.args)
29 .map(|pred| goal.with(tcx, pred)),
27 cx.predicates_of(weak_ty.def_id)
28 .iter_instantiated(cx, weak_ty.args)
29 .map(|pred| goal.with(cx, pred)),
3030 );
3131
32 let actual = tcx.type_of(weak_ty.def_id).instantiate(tcx, weak_ty.args);
32 let actual = cx.type_of(weak_ty.def_id).instantiate(cx, weak_ty.args);
3333 self.instantiate_normalizes_to_term(goal, actual.into());
3434
3535 self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
compiler/rustc_next_trait_solver/src/solve/project_goals.rs+3-3
......@@ -14,10 +14,10 @@ where
1414 &mut self,
1515 goal: Goal<I, ProjectionPredicate<I>>,
1616 ) -> QueryResult<I> {
17 let tcx = self.cx();
18 let projection_term = goal.predicate.projection_term.to_term(tcx);
17 let cx = self.cx();
18 let projection_term = goal.predicate.projection_term.to_term(cx);
1919 let goal = goal.with(
20 tcx,
20 cx,
2121 ty::PredicateKind::AliasRelate(
2222 projection_term,
2323 goal.predicate.term,
compiler/rustc_next_trait_solver/src/solve/search_graph.rs+30-30
......@@ -164,7 +164,7 @@ impl<I: Interner> SearchGraph<I> {
164164 /// the remaining depth of all nested goals to prevent hangs
165165 /// in case there is exponential blowup.
166166 fn allowed_depth_for_nested(
167 tcx: I,
167 cx: I,
168168 stack: &IndexVec<StackDepth, StackEntry<I>>,
169169 ) -> Option<SolverLimit> {
170170 if let Some(last) = stack.raw.last() {
......@@ -178,18 +178,18 @@ impl<I: Interner> SearchGraph<I> {
178178 SolverLimit(last.available_depth.0 - 1)
179179 })
180180 } else {
181 Some(SolverLimit(tcx.recursion_limit()))
181 Some(SolverLimit(cx.recursion_limit()))
182182 }
183183 }
184184
185185 fn stack_coinductive_from(
186 tcx: I,
186 cx: I,
187187 stack: &IndexVec<StackDepth, StackEntry<I>>,
188188 head: StackDepth,
189189 ) -> bool {
190190 stack.raw[head.index()..]
191191 .iter()
192 .all(|entry| entry.input.value.goal.predicate.is_coinductive(tcx))
192 .all(|entry| entry.input.value.goal.predicate.is_coinductive(cx))
193193 }
194194
195195 // When encountering a solver cycle, the result of the current goal
......@@ -247,8 +247,8 @@ impl<I: Interner> SearchGraph<I> {
247247 /// so we use a separate cache. Alternatively we could use
248248 /// a single cache and share it between coherence and ordinary
249249 /// trait solving.
250 pub(super) fn global_cache(&self, tcx: I) -> I::EvaluationCache {
251 tcx.evaluation_cache(self.mode)
250 pub(super) fn global_cache(&self, cx: I) -> I::EvaluationCache {
251 cx.evaluation_cache(self.mode)
252252 }
253253
254254 /// Probably the most involved method of the whole solver.
......@@ -257,24 +257,24 @@ impl<I: Interner> SearchGraph<I> {
257257 /// handles caching, overflow, and coinductive cycles.
258258 pub(super) fn with_new_goal<D: SolverDelegate<Interner = I>>(
259259 &mut self,
260 tcx: I,
260 cx: I,
261261 input: CanonicalInput<I>,
262262 inspect: &mut ProofTreeBuilder<D>,
263263 mut prove_goal: impl FnMut(&mut Self, &mut ProofTreeBuilder<D>) -> QueryResult<I>,
264264 ) -> QueryResult<I> {
265265 self.check_invariants();
266266 // Check for overflow.
267 let Some(available_depth) = Self::allowed_depth_for_nested(tcx, &self.stack) else {
267 let Some(available_depth) = Self::allowed_depth_for_nested(cx, &self.stack) else {
268268 if let Some(last) = self.stack.raw.last_mut() {
269269 last.encountered_overflow = true;
270270 }
271271
272272 inspect
273273 .canonical_goal_evaluation_kind(inspect::WipCanonicalGoalEvaluationKind::Overflow);
274 return Self::response_no_constraints(tcx, input, Certainty::overflow(true));
274 return Self::response_no_constraints(cx, input, Certainty::overflow(true));
275275 };
276276
277 if let Some(result) = self.lookup_global_cache(tcx, input, available_depth, inspect) {
277 if let Some(result) = self.lookup_global_cache(cx, input, available_depth, inspect) {
278278 debug!("global cache hit");
279279 return result;
280280 }
......@@ -287,12 +287,12 @@ impl<I: Interner> SearchGraph<I> {
287287 if let Some(entry) = cache_entry
288288 .with_coinductive_stack
289289 .as_ref()
290 .filter(|p| Self::stack_coinductive_from(tcx, &self.stack, p.head))
290 .filter(|p| Self::stack_coinductive_from(cx, &self.stack, p.head))
291291 .or_else(|| {
292292 cache_entry
293293 .with_inductive_stack
294294 .as_ref()
295 .filter(|p| !Self::stack_coinductive_from(tcx, &self.stack, p.head))
295 .filter(|p| !Self::stack_coinductive_from(cx, &self.stack, p.head))
296296 })
297297 {
298298 debug!("provisional cache hit");
......@@ -315,7 +315,7 @@ impl<I: Interner> SearchGraph<I> {
315315 inspect.canonical_goal_evaluation_kind(
316316 inspect::WipCanonicalGoalEvaluationKind::CycleInStack,
317317 );
318 let is_coinductive_cycle = Self::stack_coinductive_from(tcx, &self.stack, stack_depth);
318 let is_coinductive_cycle = Self::stack_coinductive_from(cx, &self.stack, stack_depth);
319319 let usage_kind = if is_coinductive_cycle {
320320 HasBeenUsed::COINDUCTIVE_CYCLE
321321 } else {
......@@ -328,9 +328,9 @@ impl<I: Interner> SearchGraph<I> {
328328 return if let Some(result) = self.stack[stack_depth].provisional_result {
329329 result
330330 } else if is_coinductive_cycle {
331 Self::response_no_constraints(tcx, input, Certainty::Yes)
331 Self::response_no_constraints(cx, input, Certainty::Yes)
332332 } else {
333 Self::response_no_constraints(tcx, input, Certainty::overflow(false))
333 Self::response_no_constraints(cx, input, Certainty::overflow(false))
334334 };
335335 } else {
336336 // No entry, we push this goal on the stack and try to prove it.
......@@ -355,9 +355,9 @@ impl<I: Interner> SearchGraph<I> {
355355 // not tracked by the cache key and from outside of this anon task, it
356356 // must not be added to the global cache. Notably, this is the case for
357357 // trait solver cycles participants.
358 let ((final_entry, result), dep_node) = tcx.with_cached_task(|| {
358 let ((final_entry, result), dep_node) = cx.with_cached_task(|| {
359359 for _ in 0..FIXPOINT_STEP_LIMIT {
360 match self.fixpoint_step_in_task(tcx, input, inspect, &mut prove_goal) {
360 match self.fixpoint_step_in_task(cx, input, inspect, &mut prove_goal) {
361361 StepResult::Done(final_entry, result) => return (final_entry, result),
362362 StepResult::HasChanged => debug!("fixpoint changed provisional results"),
363363 }
......@@ -366,17 +366,17 @@ impl<I: Interner> SearchGraph<I> {
366366 debug!("canonical cycle overflow");
367367 let current_entry = self.pop_stack();
368368 debug_assert!(current_entry.has_been_used.is_empty());
369 let result = Self::response_no_constraints(tcx, input, Certainty::overflow(false));
369 let result = Self::response_no_constraints(cx, input, Certainty::overflow(false));
370370 (current_entry, result)
371371 });
372372
373 let proof_tree = inspect.finalize_canonical_goal_evaluation(tcx);
373 let proof_tree = inspect.finalize_canonical_goal_evaluation(cx);
374374
375375 // We're now done with this goal. In case this goal is involved in a larger cycle
376376 // do not remove it from the provisional cache and update its provisional result.
377377 // We only add the root of cycles to the global cache.
378378 if let Some(head) = final_entry.non_root_cycle_participant {
379 let coinductive_stack = Self::stack_coinductive_from(tcx, &self.stack, head);
379 let coinductive_stack = Self::stack_coinductive_from(cx, &self.stack, head);
380380
381381 let entry = self.provisional_cache.get_mut(&input).unwrap();
382382 entry.stack_depth = None;
......@@ -396,8 +396,8 @@ impl<I: Interner> SearchGraph<I> {
396396 // participant is on the stack. This is necessary to prevent unstable
397397 // results. See the comment of `StackEntry::cycle_participants` for
398398 // more details.
399 self.global_cache(tcx).insert(
400 tcx,
399 self.global_cache(cx).insert(
400 cx,
401401 input,
402402 proof_tree,
403403 reached_depth,
......@@ -418,15 +418,15 @@ impl<I: Interner> SearchGraph<I> {
418418 /// this goal.
419419 fn lookup_global_cache<D: SolverDelegate<Interner = I>>(
420420 &mut self,
421 tcx: I,
421 cx: I,
422422 input: CanonicalInput<I>,
423423 available_depth: SolverLimit,
424424 inspect: &mut ProofTreeBuilder<D>,
425425 ) -> Option<QueryResult<I>> {
426426 let CacheData { result, proof_tree, additional_depth, encountered_overflow } = self
427 .global_cache(tcx)
427 .global_cache(cx)
428428 // FIXME: Awkward `Limit -> usize -> Limit`.
429 .get(tcx, input, self.stack.iter().map(|e| e.input), available_depth.0)?;
429 .get(cx, input, self.stack.iter().map(|e| e.input), available_depth.0)?;
430430
431431 // If we're building a proof tree and the current cache entry does not
432432 // contain a proof tree, we do not use the entry but instead recompute
......@@ -467,7 +467,7 @@ impl<I: Interner> SearchGraph<I> {
467467 /// point we are done.
468468 fn fixpoint_step_in_task<D, F>(
469469 &mut self,
470 tcx: I,
470 cx: I,
471471 input: CanonicalInput<I>,
472472 inspect: &mut ProofTreeBuilder<D>,
473473 prove_goal: &mut F,
......@@ -506,9 +506,9 @@ impl<I: Interner> SearchGraph<I> {
506506 let reached_fixpoint = if let Some(r) = stack_entry.provisional_result {
507507 r == result
508508 } else if stack_entry.has_been_used == HasBeenUsed::COINDUCTIVE_CYCLE {
509 Self::response_no_constraints(tcx, input, Certainty::Yes) == result
509 Self::response_no_constraints(cx, input, Certainty::Yes) == result
510510 } else if stack_entry.has_been_used == HasBeenUsed::INDUCTIVE_CYCLE {
511 Self::response_no_constraints(tcx, input, Certainty::overflow(false)) == result
511 Self::response_no_constraints(cx, input, Certainty::overflow(false)) == result
512512 } else {
513513 false
514514 };
......@@ -528,11 +528,11 @@ impl<I: Interner> SearchGraph<I> {
528528 }
529529
530530 fn response_no_constraints(
531 tcx: I,
531 cx: I,
532532 goal: CanonicalInput<I>,
533533 certainty: Certainty,
534534 ) -> QueryResult<I> {
535 Ok(super::response_no_constraints_raw(tcx, goal.max_universe, goal.variables, certainty))
535 Ok(super::response_no_constraints_raw(cx, goal.max_universe, goal.variables, certainty))
536536 }
537537
538538 #[allow(rustc::potential_query_instability)]
compiler/rustc_next_trait_solver/src/solve/trait_goals.rs+67-73
......@@ -30,8 +30,8 @@ where
3030 self.trait_ref
3131 }
3232
33 fn with_self_ty(self, tcx: I, self_ty: I::Ty) -> Self {
34 self.with_self_ty(tcx, self_ty)
33 fn with_self_ty(self, cx: I, self_ty: I::Ty) -> Self {
34 self.with_self_ty(cx, self_ty)
3535 }
3636
3737 fn trait_def_id(self, _: I) -> I::DefId {
......@@ -43,18 +43,17 @@ where
4343 goal: Goal<I, TraitPredicate<I>>,
4444 impl_def_id: I::DefId,
4545 ) -> Result<Candidate<I>, NoSolution> {
46 let tcx = ecx.cx();
46 let cx = ecx.cx();
4747
48 let impl_trait_ref = tcx.impl_trait_ref(impl_def_id);
49 if !tcx
50 .args_may_unify_deep(goal.predicate.trait_ref.args, impl_trait_ref.skip_binder().args)
48 let impl_trait_ref = cx.impl_trait_ref(impl_def_id);
49 if !cx.args_may_unify_deep(goal.predicate.trait_ref.args, impl_trait_ref.skip_binder().args)
5150 {
5251 return Err(NoSolution);
5352 }
5453
5554 // An upper bound of the certainty of this goal, used to lower the certainty
5655 // of reservation impl to ambiguous during coherence.
57 let impl_polarity = tcx.impl_polarity(impl_def_id);
56 let impl_polarity = cx.impl_polarity(impl_def_id);
5857 let maximal_certainty = match (impl_polarity, goal.predicate.polarity) {
5958 // In intercrate mode, this is ambiguous. But outside of intercrate,
6059 // it's not a real impl.
......@@ -77,13 +76,13 @@ where
7776 ecx.probe_trait_candidate(CandidateSource::Impl(impl_def_id)).enter(|ecx| {
7877 let impl_args = ecx.fresh_args_for_item(impl_def_id);
7978 ecx.record_impl_args(impl_args);
80 let impl_trait_ref = impl_trait_ref.instantiate(tcx, impl_args);
79 let impl_trait_ref = impl_trait_ref.instantiate(cx, impl_args);
8180
8281 ecx.eq(goal.param_env, goal.predicate.trait_ref, impl_trait_ref)?;
83 let where_clause_bounds = tcx
82 let where_clause_bounds = cx
8483 .predicates_of(impl_def_id)
85 .iter_instantiated(tcx, impl_args)
86 .map(|pred| goal.with(tcx, pred));
84 .iter_instantiated(cx, impl_args)
85 .map(|pred| goal.with(cx, pred));
8786 ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds);
8887
8988 ecx.evaluate_added_goals_and_make_canonical_response(maximal_certainty)
......@@ -181,13 +180,13 @@ where
181180 return Err(NoSolution);
182181 }
183182
184 let tcx = ecx.cx();
183 let cx = ecx.cx();
185184
186185 ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| {
187 let nested_obligations = tcx
186 let nested_obligations = cx
188187 .predicates_of(goal.predicate.def_id())
189 .iter_instantiated(tcx, goal.predicate.trait_ref.args)
190 .map(|p| goal.with(tcx, p));
188 .iter_instantiated(cx, goal.predicate.trait_ref.args)
189 .map(|p| goal.with(cx, p));
191190 // FIXME(-Znext-solver=coinductive): Should this be `GoalSource::ImplWhereBound`?
192191 ecx.add_goals(GoalSource::Misc, nested_obligations);
193192 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
......@@ -232,13 +231,13 @@ where
232231 return Err(NoSolution);
233232 }
234233
235 let tcx = ecx.cx();
234 let cx = ecx.cx();
236235 // But if there are inference variables, we have to wait until it's resolved.
237236 if (goal.param_env, goal.predicate.self_ty()).has_non_region_infer() {
238237 return ecx.forced_ambiguity(MaybeCause::Ambiguity);
239238 }
240239
241 if tcx.layout_is_pointer_like(goal.param_env, goal.predicate.self_ty()) {
240 if cx.layout_is_pointer_like(goal.param_env, goal.predicate.self_ty()) {
242241 ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc)
243242 .enter(|ecx| ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes))
244243 } else {
......@@ -286,10 +285,10 @@ where
286285 return Err(NoSolution);
287286 }
288287
289 let tcx = ecx.cx();
288 let cx = ecx.cx();
290289 let tupled_inputs_and_output =
291290 match structural_traits::extract_tupled_inputs_and_output_from_callable(
292 tcx,
291 cx,
293292 goal.predicate.self_ty(),
294293 goal_kind,
295294 )? {
......@@ -299,14 +298,14 @@ where
299298 }
300299 };
301300 let output_is_sized_pred = tupled_inputs_and_output.map_bound(|(_, output)| {
302 ty::TraitRef::new(tcx, tcx.require_lang_item(TraitSolverLangItem::Sized), [output])
301 ty::TraitRef::new(cx, cx.require_lang_item(TraitSolverLangItem::Sized), [output])
303302 });
304303
305304 let pred = tupled_inputs_and_output
306305 .map_bound(|(inputs, _)| {
307 ty::TraitRef::new(tcx, goal.predicate.def_id(), [goal.predicate.self_ty(), inputs])
306 ty::TraitRef::new(cx, goal.predicate.def_id(), [goal.predicate.self_ty(), inputs])
308307 })
309 .upcast(tcx);
308 .upcast(cx);
310309 // A built-in `Fn` impl only holds if the output is sized.
311310 // (FIXME: technically we only need to check this if the type is a fn ptr...)
312311 Self::probe_and_consider_implied_clause(
......@@ -314,7 +313,7 @@ where
314313 CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
315314 goal,
316315 pred,
317 [(GoalSource::ImplWhereBound, goal.with(tcx, output_is_sized_pred))],
316 [(GoalSource::ImplWhereBound, goal.with(cx, output_is_sized_pred))],
318317 )
319318 }
320319
......@@ -327,20 +326,20 @@ where
327326 return Err(NoSolution);
328327 }
329328
330 let tcx = ecx.cx();
329 let cx = ecx.cx();
331330 let (tupled_inputs_and_output_and_coroutine, nested_preds) =
332331 structural_traits::extract_tupled_inputs_and_output_from_async_callable(
333 tcx,
332 cx,
334333 goal.predicate.self_ty(),
335334 goal_kind,
336335 // This region doesn't matter because we're throwing away the coroutine type
337 Region::new_static(tcx),
336 Region::new_static(cx),
338337 )?;
339338 let output_is_sized_pred = tupled_inputs_and_output_and_coroutine.map_bound(
340339 |AsyncCallableRelevantTypes { output_coroutine_ty, .. }| {
341340 ty::TraitRef::new(
342 tcx,
343 tcx.require_lang_item(TraitSolverLangItem::Sized),
341 cx,
342 cx.require_lang_item(TraitSolverLangItem::Sized),
344343 [output_coroutine_ty],
345344 )
346345 },
......@@ -349,12 +348,12 @@ where
349348 let pred = tupled_inputs_and_output_and_coroutine
350349 .map_bound(|AsyncCallableRelevantTypes { tupled_inputs_ty, .. }| {
351350 ty::TraitRef::new(
352 tcx,
351 cx,
353352 goal.predicate.def_id(),
354353 [goal.predicate.self_ty(), tupled_inputs_ty],
355354 )
356355 })
357 .upcast(tcx);
356 .upcast(cx);
358357 // A built-in `AsyncFn` impl only holds if the output is sized.
359358 // (FIXME: technically we only need to check this if the type is a fn ptr...)
360359 Self::probe_and_consider_implied_clause(
......@@ -362,9 +361,9 @@ where
362361 CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
363362 goal,
364363 pred,
365 [goal.with(tcx, output_is_sized_pred)]
364 [goal.with(cx, output_is_sized_pred)]
366365 .into_iter()
367 .chain(nested_preds.into_iter().map(|pred| goal.with(tcx, pred)))
366 .chain(nested_preds.into_iter().map(|pred| goal.with(cx, pred)))
368367 .map(|goal| (GoalSource::ImplWhereBound, goal)),
369368 )
370369 }
......@@ -437,8 +436,8 @@ where
437436 };
438437
439438 // Coroutines are not futures unless they come from `async` desugaring
440 let tcx = ecx.cx();
441 if !tcx.coroutine_is_async(def_id) {
439 let cx = ecx.cx();
440 if !cx.coroutine_is_async(def_id) {
442441 return Err(NoSolution);
443442 }
444443
......@@ -463,8 +462,8 @@ where
463462 };
464463
465464 // Coroutines are not iterators unless they come from `gen` desugaring
466 let tcx = ecx.cx();
467 if !tcx.coroutine_is_gen(def_id) {
465 let cx = ecx.cx();
466 if !cx.coroutine_is_gen(def_id) {
468467 return Err(NoSolution);
469468 }
470469
......@@ -489,8 +488,8 @@ where
489488 };
490489
491490 // Coroutines are not iterators unless they come from `gen` desugaring
492 let tcx = ecx.cx();
493 if !tcx.coroutine_is_gen(def_id) {
491 let cx = ecx.cx();
492 if !cx.coroutine_is_gen(def_id) {
494493 return Err(NoSolution);
495494 }
496495
......@@ -513,8 +512,8 @@ where
513512 };
514513
515514 // Coroutines are not iterators unless they come from `gen` desugaring
516 let tcx = ecx.cx();
517 if !tcx.coroutine_is_async_gen(def_id) {
515 let cx = ecx.cx();
516 if !cx.coroutine_is_async_gen(def_id) {
518517 return Err(NoSolution);
519518 }
520519
......@@ -540,8 +539,8 @@ where
540539 };
541540
542541 // `async`-desugared coroutines do not implement the coroutine trait
543 let tcx = ecx.cx();
544 if !tcx.is_general_coroutine(def_id) {
542 let cx = ecx.cx();
543 if !cx.is_general_coroutine(def_id) {
545544 return Err(NoSolution);
546545 }
547546
......@@ -550,8 +549,8 @@ where
550549 ecx,
551550 CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
552551 goal,
553 ty::TraitRef::new(tcx, goal.predicate.def_id(), [self_ty, coroutine.resume_ty()])
554 .upcast(tcx),
552 ty::TraitRef::new(cx, goal.predicate.def_id(), [self_ty, coroutine.resume_ty()])
553 .upcast(cx),
555554 // Technically, we need to check that the coroutine types are Sized,
556555 // but that's already proven by the coroutine being WF.
557556 [],
......@@ -727,7 +726,7 @@ where
727726 b_data: I::BoundExistentialPredicates,
728727 b_region: I::Region,
729728 ) -> Vec<Candidate<I>> {
730 let tcx = self.cx();
729 let cx = self.cx();
731730 let Goal { predicate: (a_ty, _b_ty), .. } = goal;
732731
733732 let mut responses = vec![];
......@@ -745,7 +744,7 @@ where
745744 ));
746745 } else if let Some(a_principal) = a_data.principal() {
747746 for new_a_principal in
748 D::elaborate_supertraits(self.cx(), a_principal.with_self_ty(tcx, a_ty)).skip(1)
747 D::elaborate_supertraits(self.cx(), a_principal.with_self_ty(cx, a_ty)).skip(1)
749748 {
750749 responses.extend(self.consider_builtin_upcast_to_principal(
751750 goal,
......@@ -755,7 +754,7 @@ where
755754 b_data,
756755 b_region,
757756 Some(new_a_principal.map_bound(|trait_ref| {
758 ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref)
757 ty::ExistentialTraitRef::erase_self_ty(cx, trait_ref)
759758 })),
760759 ));
761760 }
......@@ -770,11 +769,11 @@ where
770769 b_data: I::BoundExistentialPredicates,
771770 b_region: I::Region,
772771 ) -> Result<Candidate<I>, NoSolution> {
773 let tcx = self.cx();
772 let cx = self.cx();
774773 let Goal { predicate: (a_ty, _), .. } = goal;
775774
776775 // Can only unsize to an object-safe trait.
777 if b_data.principal_def_id().is_some_and(|def_id| !tcx.trait_is_object_safe(def_id)) {
776 if b_data.principal_def_id().is_some_and(|def_id| !cx.trait_is_object_safe(def_id)) {
778777 return Err(NoSolution);
779778 }
780779
......@@ -783,24 +782,20 @@ where
783782 // (i.e. the principal, all of the associated types match, and any auto traits)
784783 ecx.add_goals(
785784 GoalSource::ImplWhereBound,
786 b_data.iter().map(|pred| goal.with(tcx, pred.with_self_ty(tcx, a_ty))),
785 b_data.iter().map(|pred| goal.with(cx, pred.with_self_ty(cx, a_ty))),
787786 );
788787
789788 // The type must be `Sized` to be unsized.
790789 ecx.add_goal(
791790 GoalSource::ImplWhereBound,
792791 goal.with(
793 tcx,
794 ty::TraitRef::new(
795 tcx,
796 tcx.require_lang_item(TraitSolverLangItem::Sized),
797 [a_ty],
798 ),
792 cx,
793 ty::TraitRef::new(cx, cx.require_lang_item(TraitSolverLangItem::Sized), [a_ty]),
799794 ),
800795 );
801796
802797 // The type must outlive the lifetime of the `dyn` we're unsizing into.
803 ecx.add_goal(GoalSource::Misc, goal.with(tcx, ty::OutlivesPredicate(a_ty, b_region)));
798 ecx.add_goal(GoalSource::Misc, goal.with(cx, ty::OutlivesPredicate(a_ty, b_region)));
804799 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
805800 })
806801 }
......@@ -941,28 +936,28 @@ where
941936 a_args: I::GenericArgs,
942937 b_args: I::GenericArgs,
943938 ) -> Result<Candidate<I>, NoSolution> {
944 let tcx = self.cx();
939 let cx = self.cx();
945940 let Goal { predicate: (_a_ty, b_ty), .. } = goal;
946941
947 let unsizing_params = tcx.unsizing_params_for_adt(def.def_id());
942 let unsizing_params = cx.unsizing_params_for_adt(def.def_id());
948943 // We must be unsizing some type parameters. This also implies
949944 // that the struct has a tail field.
950945 if unsizing_params.is_empty() {
951946 return Err(NoSolution);
952947 }
953948
954 let tail_field_ty = def.struct_tail_ty(tcx).unwrap();
949 let tail_field_ty = def.struct_tail_ty(cx).unwrap();
955950
956 let a_tail_ty = tail_field_ty.instantiate(tcx, a_args);
957 let b_tail_ty = tail_field_ty.instantiate(tcx, b_args);
951 let a_tail_ty = tail_field_ty.instantiate(cx, a_args);
952 let b_tail_ty = tail_field_ty.instantiate(cx, b_args);
958953
959954 // Instantiate just the unsizing params from B into A. The type after
960955 // this instantiation must be equal to B. This is so we don't unsize
961956 // unrelated type parameters.
962 let new_a_args = tcx.mk_args_from_iter(a_args.iter().enumerate().map(|(i, a)| {
957 let new_a_args = cx.mk_args_from_iter(a_args.iter().enumerate().map(|(i, a)| {
963958 if unsizing_params.contains(i as u32) { b_args.get(i).unwrap() } else { a }
964959 }));
965 let unsized_a_ty = Ty::new_adt(tcx, def, new_a_args);
960 let unsized_a_ty = Ty::new_adt(cx, def, new_a_args);
966961
967962 // Finally, we require that `TailA: Unsize<TailB>` for the tail field
968963 // types.
......@@ -970,10 +965,10 @@ where
970965 self.add_goal(
971966 GoalSource::ImplWhereBound,
972967 goal.with(
973 tcx,
968 cx,
974969 ty::TraitRef::new(
975 tcx,
976 tcx.require_lang_item(TraitSolverLangItem::Unsize),
970 cx,
971 cx.require_lang_item(TraitSolverLangItem::Unsize),
977972 [a_tail_ty, b_tail_ty],
978973 ),
979974 ),
......@@ -998,25 +993,24 @@ where
998993 a_tys: I::Tys,
999994 b_tys: I::Tys,
1000995 ) -> Result<Candidate<I>, NoSolution> {
1001 let tcx = self.cx();
996 let cx = self.cx();
1002997 let Goal { predicate: (_a_ty, b_ty), .. } = goal;
1003998
1004999 let (&a_last_ty, a_rest_tys) = a_tys.split_last().unwrap();
10051000 let b_last_ty = b_tys.last().unwrap();
10061001
10071002 // Instantiate just the tail field of B., and require that they're equal.
1008 let unsized_a_ty =
1009 Ty::new_tup_from_iter(tcx, a_rest_tys.iter().copied().chain([b_last_ty]));
1003 let unsized_a_ty = Ty::new_tup_from_iter(cx, a_rest_tys.iter().copied().chain([b_last_ty]));
10101004 self.eq(goal.param_env, unsized_a_ty, b_ty)?;
10111005
10121006 // Similar to ADTs, require that we can unsize the tail.
10131007 self.add_goal(
10141008 GoalSource::ImplWhereBound,
10151009 goal.with(
1016 tcx,
1010 cx,
10171011 ty::TraitRef::new(
1018 tcx,
1019 tcx.require_lang_item(TraitSolverLangItem::Unsize),
1012 cx,
1013 cx.require_lang_item(TraitSolverLangItem::Unsize),
10201014 [a_last_ty, b_last_ty],
10211015 ),
10221016 ),
compiler/rustc_parse/src/parser/ty.rs+1-1
......@@ -608,7 +608,7 @@ impl<'a> Parser<'a> {
608608 self.dcx().emit_err(FnPointerCannotBeAsync { span: whole_span, qualifier: span });
609609 }
610610 // FIXME(gen_blocks): emit a similar error for `gen fn()`
611 let decl_span = span_start.to(self.token.span);
611 let decl_span = span_start.to(self.prev_token.span);
612612 Ok(TyKind::BareFn(P(BareFnTy { ext, safety, generic_params: params, decl, decl_span })))
613613 }
614614
compiler/rustc_passes/src/reachable.rs+2-10
......@@ -30,7 +30,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
3030use rustc_hir::intravisit::{self, Visitor};
3131use rustc_hir::Node;
3232use rustc_middle::bug;
33use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
33use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
3434use rustc_middle::middle::privacy::{self, Level};
3535use rustc_middle::mir::interpret::{ConstAllocation, ErrorHandled, GlobalAlloc};
3636use rustc_middle::query::Providers;
......@@ -178,15 +178,7 @@ impl<'tcx> ReachableContext<'tcx> {
178178 if !self.any_library {
179179 // If we are building an executable, only explicitly extern
180180 // types need to be exported.
181 let codegen_attrs = if self.tcx.def_kind(search_item).has_codegen_attrs() {
182 self.tcx.codegen_fn_attrs(search_item)
183 } else {
184 CodegenFnAttrs::EMPTY
185 };
186 let is_extern = codegen_attrs.contains_extern_indicator();
187 let std_internal =
188 codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL);
189 if is_extern || std_internal {
181 if has_custom_linkage(self.tcx, search_item) {
190182 self.reachable_symbols.insert(search_item);
191183 }
192184 } else {
compiler/rustc_resolve/src/effective_visibilities.rs+1-1
......@@ -99,7 +99,7 @@ impl<'r, 'a, 'tcx> EffectiveVisibilitiesVisitor<'r, 'a, 'tcx> {
9999 // is the maximum value among visibilities of bindings corresponding to that def id.
100100 for (binding, eff_vis) in visitor.import_effective_visibilities.iter() {
101101 let NameBindingKind::Import { import, .. } = binding.kind else { unreachable!() };
102 if !binding.is_ambiguity() {
102 if !binding.is_ambiguity_recursive() {
103103 if let Some(node_id) = import.id() {
104104 r.effective_visibilities.update_eff_vis(r.local_def_id(node_id), eff_vis, r.tcx)
105105 }
compiler/rustc_resolve/src/imports.rs+32-42
......@@ -325,8 +325,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
325325 }
326326 match (old_binding.is_glob_import(), binding.is_glob_import()) {
327327 (true, true) => {
328 // FIXME: remove `!binding.is_ambiguity()` after delete the warning ambiguity.
329 if !binding.is_ambiguity()
328 // FIXME: remove `!binding.is_ambiguity_recursive()` after delete the warning ambiguity.
329 if !binding.is_ambiguity_recursive()
330330 && let NameBindingKind::Import { import: old_import, .. } =
331331 old_binding.kind
332332 && let NameBindingKind::Import { import, .. } = binding.kind
......@@ -337,21 +337,17 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
337337 // imported from the same glob-import statement.
338338 resolution.binding = Some(binding);
339339 } else if res != old_binding.res() {
340 let binding = if warn_ambiguity {
341 this.warn_ambiguity(AmbiguityKind::GlobVsGlob, old_binding, binding)
342 } else {
343 this.ambiguity(AmbiguityKind::GlobVsGlob, old_binding, binding)
344 };
345 resolution.binding = Some(binding);
340 resolution.binding = Some(this.new_ambiguity_binding(
341 AmbiguityKind::GlobVsGlob,
342 old_binding,
343 binding,
344 warn_ambiguity,
345 ));
346346 } else if !old_binding.vis.is_at_least(binding.vis, this.tcx) {
347347 // We are glob-importing the same item but with greater visibility.
348348 resolution.binding = Some(binding);
349 } else if binding.is_ambiguity() {
350 resolution.binding =
351 Some(self.arenas.alloc_name_binding(NameBindingData {
352 warn_ambiguity: true,
353 ..(*binding).clone()
354 }));
349 } else if binding.is_ambiguity_recursive() {
350 resolution.binding = Some(this.new_warn_ambiguity_binding(binding));
355351 }
356352 }
357353 (old_glob @ true, false) | (old_glob @ false, true) => {
......@@ -361,24 +357,26 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
361357 && nonglob_binding.expansion != LocalExpnId::ROOT
362358 && glob_binding.res() != nonglob_binding.res()
363359 {
364 resolution.binding = Some(this.ambiguity(
360 resolution.binding = Some(this.new_ambiguity_binding(
365361 AmbiguityKind::GlobVsExpanded,
366362 nonglob_binding,
367363 glob_binding,
364 false,
368365 ));
369366 } else {
370367 resolution.binding = Some(nonglob_binding);
371368 }
372369
373 if let Some(old_binding) = resolution.shadowed_glob {
374 assert!(old_binding.is_glob_import());
375 if glob_binding.res() != old_binding.res() {
376 resolution.shadowed_glob = Some(this.ambiguity(
370 if let Some(old_shadowed_glob) = resolution.shadowed_glob {
371 assert!(old_shadowed_glob.is_glob_import());
372 if glob_binding.res() != old_shadowed_glob.res() {
373 resolution.shadowed_glob = Some(this.new_ambiguity_binding(
377374 AmbiguityKind::GlobVsGlob,
378 old_binding,
375 old_shadowed_glob,
379376 glob_binding,
377 false,
380378 ));
381 } else if !old_binding.vis.is_at_least(binding.vis, this.tcx) {
379 } else if !old_shadowed_glob.vis.is_at_least(binding.vis, this.tcx) {
382380 resolution.shadowed_glob = Some(glob_binding);
383381 }
384382 } else {
......@@ -397,29 +395,21 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
397395 })
398396 }
399397
400 fn ambiguity(
398 fn new_ambiguity_binding(
401399 &self,
402 kind: AmbiguityKind,
400 ambiguity_kind: AmbiguityKind,
403401 primary_binding: NameBinding<'a>,
404402 secondary_binding: NameBinding<'a>,
403 warn_ambiguity: bool,
405404 ) -> NameBinding<'a> {
406 self.arenas.alloc_name_binding(NameBindingData {
407 ambiguity: Some((secondary_binding, kind)),
408 ..(*primary_binding).clone()
409 })
405 let ambiguity = Some((secondary_binding, ambiguity_kind));
406 let data = NameBindingData { ambiguity, warn_ambiguity, ..*primary_binding };
407 self.arenas.alloc_name_binding(data)
410408 }
411409
412 fn warn_ambiguity(
413 &self,
414 kind: AmbiguityKind,
415 primary_binding: NameBinding<'a>,
416 secondary_binding: NameBinding<'a>,
417 ) -> NameBinding<'a> {
418 self.arenas.alloc_name_binding(NameBindingData {
419 ambiguity: Some((secondary_binding, kind)),
420 warn_ambiguity: true,
421 ..(*primary_binding).clone()
422 })
410 fn new_warn_ambiguity_binding(&self, binding: NameBinding<'a>) -> NameBinding<'a> {
411 assert!(binding.is_ambiguity_recursive());
412 self.arenas.alloc_name_binding(NameBindingData { warn_ambiguity: true, ..*binding })
423413 }
424414
425415 // Use `f` to mutate the resolution of the name in the module.
......@@ -1381,8 +1371,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13811371 target_bindings[ns].get(),
13821372 ) {
13831373 Ok(other_binding) => {
1384 is_redundant =
1385 binding.res() == other_binding.res() && !other_binding.is_ambiguity();
1374 is_redundant = binding.res() == other_binding.res()
1375 && !other_binding.is_ambiguity_recursive();
13861376 if is_redundant {
13871377 redundant_span[ns] =
13881378 Some((other_binding.span, other_binding.is_import()));
......@@ -1455,7 +1445,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
14551445 .resolution(import.parent_scope.module, key)
14561446 .borrow()
14571447 .binding()
1458 .is_some_and(|binding| binding.is_warn_ambiguity());
1448 .is_some_and(|binding| binding.warn_ambiguity_recursive());
14591449 let _ = self.try_define(
14601450 import.parent_scope.module,
14611451 key,
......@@ -1480,7 +1470,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
14801470
14811471 module.for_each_child(self, |this, ident, _, binding| {
14821472 let res = binding.res().expect_non_local();
1483 let error_ambiguity = binding.is_ambiguity() && !binding.warn_ambiguity;
1473 let error_ambiguity = binding.is_ambiguity_recursive() && !binding.warn_ambiguity;
14841474 if res != def::Res::Err && !error_ambiguity {
14851475 let mut reexport_chain = SmallVec::new();
14861476 let mut next_binding = binding;
compiler/rustc_resolve/src/late.rs+1-1
......@@ -3730,7 +3730,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
37303730 let ls_binding = self.maybe_resolve_ident_in_lexical_scope(ident, ValueNS)?;
37313731 let (res, binding) = match ls_binding {
37323732 LexicalScopeBinding::Item(binding)
3733 if is_syntactic_ambiguity && binding.is_ambiguity() =>
3733 if is_syntactic_ambiguity && binding.is_ambiguity_recursive() =>
37343734 {
37353735 // For ambiguous bindings we don't know all their definitions and cannot check
37363736 // whether they can be shadowed by fresh bindings or not, so force an error.
compiler/rustc_resolve/src/lib.rs+8-6
......@@ -694,10 +694,12 @@ impl<'a> fmt::Debug for Module<'a> {
694694}
695695
696696/// Records a possibly-private value, type, or module definition.
697#[derive(Clone, Debug)]
697#[derive(Clone, Copy, Debug)]
698698struct NameBindingData<'a> {
699699 kind: NameBindingKind<'a>,
700700 ambiguity: Option<(NameBinding<'a>, AmbiguityKind)>,
701 /// Produce a warning instead of an error when reporting ambiguities inside this binding.
702 /// May apply to indirect ambiguities under imports, so `ambiguity.is_some()` is not required.
701703 warn_ambiguity: bool,
702704 expansion: LocalExpnId,
703705 span: Span,
......@@ -718,7 +720,7 @@ impl<'a> ToNameBinding<'a> for NameBinding<'a> {
718720 }
719721}
720722
721#[derive(Clone, Debug)]
723#[derive(Clone, Copy, Debug)]
722724enum NameBindingKind<'a> {
723725 Res(Res),
724726 Module(Module<'a>),
......@@ -830,18 +832,18 @@ impl<'a> NameBindingData<'a> {
830832 }
831833 }
832834
833 fn is_ambiguity(&self) -> bool {
835 fn is_ambiguity_recursive(&self) -> bool {
834836 self.ambiguity.is_some()
835837 || match self.kind {
836 NameBindingKind::Import { binding, .. } => binding.is_ambiguity(),
838 NameBindingKind::Import { binding, .. } => binding.is_ambiguity_recursive(),
837839 _ => false,
838840 }
839841 }
840842
841 fn is_warn_ambiguity(&self) -> bool {
843 fn warn_ambiguity_recursive(&self) -> bool {
842844 self.warn_ambiguity
843845 || match self.kind {
844 NameBindingKind::Import { binding, .. } => binding.is_warn_ambiguity(),
846 NameBindingKind::Import { binding, .. } => binding.warn_ambiguity_recursive(),
845847 _ => false,
846848 }
847849 }
library/core/src/iter/adapters/filter.rs+45-45
......@@ -3,7 +3,7 @@ use crate::iter::{adapters::SourceIter, FusedIterator, InPlaceIterable, TrustedF
33use crate::num::NonZero;
44use crate::ops::Try;
55use core::array;
6use core::mem::{ManuallyDrop, MaybeUninit};
6use core::mem::MaybeUninit;
77use core::ops::ControlFlow;
88
99/// An iterator that filters the elements of `iter` with `predicate`.
......@@ -27,6 +27,42 @@ impl<I, P> Filter<I, P> {
2727 }
2828}
2929
30impl<I, P> Filter<I, P>
31where
32 I: Iterator,
33 P: FnMut(&I::Item) -> bool,
34{
35 #[inline]
36 fn next_chunk_dropless<const N: usize>(
37 &mut self,
38 ) -> Result<[I::Item; N], array::IntoIter<I::Item, N>> {
39 let mut array: [MaybeUninit<I::Item>; N] = [const { MaybeUninit::uninit() }; N];
40 let mut initialized = 0;
41
42 let result = self.iter.try_for_each(|element| {
43 let idx = initialized;
44 // branchless index update combined with unconditionally copying the value even when
45 // it is filtered reduces branching and dependencies in the loop.
46 initialized = idx + (self.predicate)(&element) as usize;
47 // SAFETY: Loop conditions ensure the index is in bounds.
48 unsafe { array.get_unchecked_mut(idx) }.write(element);
49
50 if initialized < N { ControlFlow::Continue(()) } else { ControlFlow::Break(()) }
51 });
52
53 match result {
54 ControlFlow::Break(()) => {
55 // SAFETY: The loop above is only explicitly broken when the array has been fully initialized
56 Ok(unsafe { MaybeUninit::array_assume_init(array) })
57 }
58 ControlFlow::Continue(()) => {
59 // SAFETY: The range is in bounds since the loop breaks when reaching N elements.
60 Err(unsafe { array::IntoIter::new_unchecked(array, 0..initialized) })
61 }
62 }
63 }
64}
65
3066#[stable(feature = "core_impl_debug", since = "1.9.0")]
3167impl<I: fmt::Debug, P> fmt::Debug for Filter<I, P> {
3268 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
......@@ -64,52 +100,16 @@ where
64100 fn next_chunk<const N: usize>(
65101 &mut self,
66102 ) -> Result<[Self::Item; N], array::IntoIter<Self::Item, N>> {
67 let mut array: [MaybeUninit<Self::Item>; N] = [const { MaybeUninit::uninit() }; N];
68
69 struct Guard<'a, T> {
70 array: &'a mut [MaybeUninit<T>],
71 initialized: usize,
72 }
73
74 impl<T> Drop for Guard<'_, T> {
75 #[inline]
76 fn drop(&mut self) {
77 if const { crate::mem::needs_drop::<T>() } {
78 // SAFETY: self.initialized is always <= N, which also is the length of the array.
79 unsafe {
80 core::ptr::drop_in_place(MaybeUninit::slice_assume_init_mut(
81 self.array.get_unchecked_mut(..self.initialized),
82 ));
83 }
84 }
103 // avoid codegen for the dead branch
104 let fun = const {
105 if crate::mem::needs_drop::<I::Item>() {
106 array::iter_next_chunk::<I::Item, N>
107 } else {
108 Self::next_chunk_dropless::<N>
85109 }
86 }
87
88 let mut guard = Guard { array: &mut array, initialized: 0 };
89
90 let result = self.iter.try_for_each(|element| {
91 let idx = guard.initialized;
92 guard.initialized = idx + (self.predicate)(&element) as usize;
93
94 // SAFETY: Loop conditions ensure the index is in bounds.
95 unsafe { guard.array.get_unchecked_mut(idx) }.write(element);
96
97 if guard.initialized < N { ControlFlow::Continue(()) } else { ControlFlow::Break(()) }
98 });
110 };
99111
100 let guard = ManuallyDrop::new(guard);
101
102 match result {
103 ControlFlow::Break(()) => {
104 // SAFETY: The loop above is only explicitly broken when the array has been fully initialized
105 Ok(unsafe { MaybeUninit::array_assume_init(array) })
106 }
107 ControlFlow::Continue(()) => {
108 let initialized = guard.initialized;
109 // SAFETY: The range is in bounds since the loop breaks when reaching N elements.
110 Err(unsafe { array::IntoIter::new_unchecked(array, 0..initialized) })
111 }
112 }
112 fun(self)
113113 }
114114
115115 #[inline]
library/core/tests/iter/adapters/filter.rs+13
......@@ -1,4 +1,5 @@
11use core::iter::*;
2use std::rc::Rc;
23
34#[test]
45fn test_iterator_filter_count() {
......@@ -50,3 +51,15 @@ fn test_double_ended_filter() {
5051 assert_eq!(it.next().unwrap(), &2);
5152 assert_eq!(it.next_back(), None);
5253}
54
55#[test]
56fn test_next_chunk_does_not_leak() {
57 let drop_witness: [_; 5] = std::array::from_fn(|_| Rc::new(()));
58
59 let v = (0..5).map(|i| drop_witness[i].clone()).collect::<Vec<_>>();
60 let _ = v.into_iter().filter(|_| false).next_chunk::<1>();
61
62 for ref w in drop_witness {
63 assert_eq!(Rc::strong_count(w), 1);
64 }
65}
src/tools/miri/tests/pass/tls/win_tls_callback.rs created+16
......@@ -0,0 +1,16 @@
1//! Ensure that we call Windows TLS callbacks in the local crate.
2//@only-target-windows
3// Calling eprintln in the callback seems to (re-)initialize some thread-local storage
4// and then leak the memory allocated for that. Let's just ignore these leaks,
5// that's not what this test is about.
6//@compile-flags: -Zmiri-ignore-leaks
7
8#[link_section = ".CRT$XLB"]
9#[used] // Miri only considers explicitly `#[used]` statics for `lookup_link_section`
10pub static CALLBACK: unsafe extern "system" fn(*const (), u32, *const ()) = tls_callback;
11
12unsafe extern "system" fn tls_callback(_h: *const (), _dw_reason: u32, _pv: *const ()) {
13 eprintln!("in tls_callback");
14}
15
16fn main() {}
src/tools/miri/tests/pass/tls/win_tls_callback.stderr created+1
......@@ -0,0 +1 @@
1in tls_callback
src/tools/tidy/config/requirements.in+2-2
......@@ -6,5 +6,5 @@
66# Note: this generation step should be run with the oldest supported python
77# version (currently 3.9) to ensure backward compatibility
88
9black==23.3.0
10ruff==0.0.272
9black==24.4.2
10ruff==0.4.9
src/tools/tidy/config/requirements.txt+44-47
......@@ -4,32 +4,29 @@
44#
55# pip-compile --generate-hashes --strip-extras src/tools/tidy/config/requirements.in
66#
7black==23.3.0 \
8 --hash=sha256:064101748afa12ad2291c2b91c960be28b817c0c7eaa35bec09cc63aa56493c5 \
9 --hash=sha256:0945e13506be58bf7db93ee5853243eb368ace1c08a24c65ce108986eac65915 \
10 --hash=sha256:11c410f71b876f961d1de77b9699ad19f939094c3a677323f43d7a29855fe326 \
11 --hash=sha256:1c7b8d606e728a41ea1ccbd7264677e494e87cf630e399262ced92d4a8dac940 \
12 --hash=sha256:1d06691f1eb8de91cd1b322f21e3bfc9efe0c7ca1f0e1eb1db44ea367dff656b \
13 --hash=sha256:3238f2aacf827d18d26db07524e44741233ae09a584273aa059066d644ca7b30 \
14 --hash=sha256:32daa9783106c28815d05b724238e30718f34155653d4d6e125dc7daec8e260c \
15 --hash=sha256:35d1381d7a22cc5b2be2f72c7dfdae4072a3336060635718cc7e1ede24221d6c \
16 --hash=sha256:3a150542a204124ed00683f0db1f5cf1c2aaaa9cc3495b7a3b5976fb136090ab \
17 --hash=sha256:48f9d345675bb7fbc3dd85821b12487e1b9a75242028adad0333ce36ed2a6d27 \
18 --hash=sha256:50cb33cac881766a5cd9913e10ff75b1e8eb71babf4c7104f2e9c52da1fb7de2 \
19 --hash=sha256:562bd3a70495facf56814293149e51aa1be9931567474993c7942ff7d3533961 \
20 --hash=sha256:67de8d0c209eb5b330cce2469503de11bca4085880d62f1628bd9972cc3366b9 \
21 --hash=sha256:6b39abdfb402002b8a7d030ccc85cf5afff64ee90fa4c5aebc531e3ad0175ddb \
22 --hash=sha256:6f3c333ea1dd6771b2d3777482429864f8e258899f6ff05826c3a4fcc5ce3f70 \
23 --hash=sha256:714290490c18fb0126baa0fca0a54ee795f7502b44177e1ce7624ba1c00f2331 \
24 --hash=sha256:7c3eb7cea23904399866c55826b31c1f55bbcd3890ce22ff70466b907b6775c2 \
25 --hash=sha256:92c543f6854c28a3c7f39f4d9b7694f9a6eb9d3c5e2ece488c327b6e7ea9b266 \
26 --hash=sha256:a6f6886c9869d4daae2d1715ce34a19bbc4b95006d20ed785ca00fa03cba312d \
27 --hash=sha256:a8a968125d0a6a404842fa1bf0b349a568634f856aa08ffaff40ae0dfa52e7c6 \
28 --hash=sha256:c7ab5790333c448903c4b721b59c0d80b11fe5e9803d8703e84dcb8da56fec1b \
29 --hash=sha256:e114420bf26b90d4b9daa597351337762b63039752bdf72bf361364c1aa05925 \
30 --hash=sha256:e198cf27888ad6f4ff331ca1c48ffc038848ea9f031a3b40ba36aced7e22f2c8 \
31 --hash=sha256:ec751418022185b0c1bb7d7736e6933d40bbb14c14a0abcf9123d1b159f98dd4 \
32 --hash=sha256:f0bd2f4a58d6666500542b26354978218a9babcdc972722f4bf90779524515f3
7black==24.4.2 \
8 --hash=sha256:257d724c2c9b1660f353b36c802ccece186a30accc7742c176d29c146df6e474 \
9 --hash=sha256:37aae07b029fa0174d39daf02748b379399b909652a806e5708199bd93899da1 \
10 --hash=sha256:415e686e87dbbe6f4cd5ef0fbf764af7b89f9057b97c908742b6008cc554b9c0 \
11 --hash=sha256:48a85f2cb5e6799a9ef05347b476cce6c182d6c71ee36925a6c194d074336ef8 \
12 --hash=sha256:7768a0dbf16a39aa5e9a3ded568bb545c8c2727396d063bbaf847df05b08cd96 \
13 --hash=sha256:7e122b1c4fb252fd85df3ca93578732b4749d9be076593076ef4d07a0233c3e1 \
14 --hash=sha256:88c57dc656038f1ab9f92b3eb5335ee9b021412feaa46330d5eba4e51fe49b04 \
15 --hash=sha256:8e537d281831ad0e71007dcdcbe50a71470b978c453fa41ce77186bbe0ed6021 \
16 --hash=sha256:98e123f1d5cfd42f886624d84464f7756f60ff6eab89ae845210631714f6db94 \
17 --hash=sha256:accf49e151c8ed2c0cdc528691838afd217c50412534e876a19270fea1e28e2d \
18 --hash=sha256:b1530ae42e9d6d5b670a34db49a94115a64596bc77710b1d05e9801e62ca0a7c \
19 --hash=sha256:b9176b9832e84308818a99a561e90aa479e73c523b3f77afd07913380ae2eab7 \
20 --hash=sha256:bdde6f877a18f24844e381d45e9947a49e97933573ac9d4345399be37621e26c \
21 --hash=sha256:be8bef99eb46d5021bf053114442914baeb3649a89dc5f3a555c88737e5e98fc \
22 --hash=sha256:bf10f7310db693bb62692609b397e8d67257c55f949abde4c67f9cc574492cc7 \
23 --hash=sha256:c872b53057f000085da66a19c55d68f6f8ddcac2642392ad3a355878406fbd4d \
24 --hash=sha256:d36ed1124bb81b32f8614555b34cc4259c3fbc7eec17870e8ff8ded335b58d8c \
25 --hash=sha256:da33a1a5e49c4122ccdfd56cd021ff1ebc4a1ec4e2d01594fef9b6f267a9e741 \
26 --hash=sha256:dd1b5a14e417189db4c7b64a6540f31730713d173f0b63e55fabd52d61d8fdce \
27 --hash=sha256:e151054aa00bad1f4e1f04919542885f89f5f7d086b8a59e5000e6c616896ffb \
28 --hash=sha256:eaea3008c281f1038edb473c1aa8ed8143a5535ff18f978a318f10302b254063 \
29 --hash=sha256:ef703f83fc32e131e9bcc0a5094cfe85599e7109f896fe8bc96cc402f3eb4b6e
3330 # via -r src/tools/tidy/config/requirements.in
3431click==8.1.3 \
3532 --hash=sha256:7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37ba7b8e \
......@@ -47,28 +44,28 @@ pathspec==0.11.1 \
4744 --hash=sha256:2798de800fa92780e33acca925945e9a19a133b715067cf165b8866c15a31687 \
4845 --hash=sha256:d8af70af76652554bd134c22b3e8a1cc46ed7d91edcdd721ef1a0c51a84a5293
4946 # via black
50platformdirs==3.6.0 \
51 --hash=sha256:57e28820ca8094678b807ff529196506d7a21e17156cb1cddb3e74cebce54640 \
52 --hash=sha256:ffa199e3fbab8365778c4a10e1fbf1b9cd50707de826eb304b50e57ec0cc8d38
47platformdirs==4.2.2 \
48 --hash=sha256:2d7a1657e36a80ea911db832a8a6ece5ee53d8de21edd5cc5879af6530b1bfee \
49 --hash=sha256:38b7b51f512eed9e84a22788b4bce1de17c0adb134d6becb09836e37d8654cd3
5350 # via black
54ruff==0.0.272 \
55 --hash=sha256:06b8ee4eb8711ab119db51028dd9f5384b44728c23586424fd6e241a5b9c4a3b \
56 --hash=sha256:1609b864a8d7ee75a8c07578bdea0a7db75a144404e75ef3162e0042bfdc100d \
57 --hash=sha256:19643d448f76b1eb8a764719072e9c885968971bfba872e14e7257e08bc2f2b7 \
58 --hash=sha256:273a01dc8c3c4fd4c2af7ea7a67c8d39bb09bce466e640dd170034da75d14cab \
59 --hash=sha256:27b2ea68d2aa69fff1b20b67636b1e3e22a6a39e476c880da1282c3e4bf6ee5a \
60 --hash=sha256:48eccf225615e106341a641f826b15224b8a4240b84269ead62f0afd6d7e2d95 \
61 --hash=sha256:677284430ac539bb23421a2b431b4ebc588097ef3ef918d0e0a8d8ed31fea216 \
62 --hash=sha256:691d72a00a99707a4e0b2846690961157aef7b17b6b884f6b4420a9f25cd39b5 \
63 --hash=sha256:86bc788245361a8148ff98667da938a01e1606b28a45e50ac977b09d3ad2c538 \
64 --hash=sha256:905ff8f3d6206ad56fcd70674453527b9011c8b0dc73ead27618426feff6908e \
65 --hash=sha256:9c4bfb75456a8e1efe14c52fcefb89cfb8f2a0d31ed8d804b82c6cf2dc29c42c \
66 --hash=sha256:a37ec80e238ead2969b746d7d1b6b0d31aa799498e9ba4281ab505b93e1f4b28 \
67 --hash=sha256:ae9b57546e118660175d45d264b87e9b4c19405c75b587b6e4d21e6a17bf4fdf \
68 --hash=sha256:bd2bbe337a3f84958f796c77820d55ac2db1e6753f39d1d1baed44e07f13f96d \
69 --hash=sha256:d5a208f8ef0e51d4746930589f54f9f92f84bb69a7d15b1de34ce80a7681bc00 \
70 --hash=sha256:dc406e5d756d932da95f3af082814d2467943631a587339ee65e5a4f4fbe83eb \
71 --hash=sha256:ee76b4f05fcfff37bd6ac209d1370520d509ea70b5a637bdf0a04d0c99e13dff
51ruff==0.4.9 \
52 --hash=sha256:06b60f91bfa5514bb689b500a25ba48e897d18fea14dce14b48a0c40d1635893 \
53 --hash=sha256:0e8e7b95673f22e0efd3571fb5b0cf71a5eaaa3cc8a776584f3b2cc878e46bff \
54 --hash=sha256:2d45ddc6d82e1190ea737341326ecbc9a61447ba331b0a8962869fcada758505 \
55 --hash=sha256:4555056049d46d8a381f746680db1c46e67ac3b00d714606304077682832998e \
56 --hash=sha256:5d5460f789ccf4efd43f265a58538a2c24dbce15dbf560676e430375f20a8198 \
57 --hash=sha256:673bddb893f21ab47a8334c8e0ea7fd6598ecc8e698da75bcd12a7b9d0a3206e \
58 --hash=sha256:732dd550bfa5d85af8c3c6cbc47ba5b67c6aed8a89e2f011b908fc88f87649db \
59 --hash=sha256:784d3ec9bd6493c3b720a0b76f741e6c2d7d44f6b2be87f5eef1ae8cc1d54c84 \
60 --hash=sha256:78de3fdb95c4af084087628132336772b1c5044f6e710739d440fc0bccf4d321 \
61 --hash=sha256:8064590fd1a50dcf4909c268b0e7c2498253273309ad3d97e4a752bb9df4f521 \
62 --hash=sha256:88bffe9c6a454bf8529f9ab9091c99490578a593cc9f9822b7fc065ee0712a06 \
63 --hash=sha256:8c1aff58c31948cc66d0b22951aa19edb5af0a3af40c936340cd32a8b1ab7438 \
64 --hash=sha256:98ec2775fd2d856dc405635e5ee4ff177920f2141b8e2d9eb5bd6efd50e80317 \
65 --hash=sha256:b262ed08d036ebe162123170b35703aaf9daffecb698cd367a8d585157732991 \
66 --hash=sha256:e0a22c4157e53d006530c902107c7f550b9233e9706313ab57b892d7197d8e52 \
67 --hash=sha256:e91175fbe48f8a2174c9aad70438fe9cb0a5732c4159b2a10a3565fea2d94cde \
68 --hash=sha256:f1cb0828ac9533ba0135d148d214e284711ede33640465e706772645483427e3
7269 # via -r src/tools/tidy/config/requirements.in
7370tomli==2.0.1 \
7471 --hash=sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc \
src/tools/tidy/config/ruff.toml+12-11
......@@ -1,17 +1,7 @@
11# Configuration for ruff python linter, run as part of tidy external tools
22
3# B (bugbear), E (pycodestyle, standard), EXE (executables) F (flakes, standard)
4# ERM for error messages would be beneficial at some point
5select = ["B", "E", "EXE", "F"]
6
7ignore = [
8 "E501", # line-too-long
9 "F403", # undefined-local-with-import-star
10 "F405", # undefined-local-with-import-star-usage
11]
12
133# lowest possible for ruff
14target-version = "py37"
4target-version = "py39"
155
166# Ignore all submodules
177extend-exclude = [
......@@ -41,3 +31,14 @@ extend-exclude = [
4131 "../library/backtrace/",
4232 "../src/tools/rustc-perf/",
4333]
34
35[lint]
36# B (bugbear), E (pycodestyle, standard), EXE (executables) F (flakes, standard)
37# ERM for error messages would be beneficial at some point
38select = ["B", "E", "EXE", "F"]
39
40ignore = [
41 "E501", # line-too-long
42 "F403", # undefined-local-with-import-star
43 "F405", # undefined-local-with-import-star-usage
44]
src/tools/tidy/src/allowed_run_make_makefiles.txt-3
......@@ -55,13 +55,11 @@ run-make/incr-foreign-head-span/Makefile
5555run-make/interdependent-c-libraries/Makefile
5656run-make/intrinsic-unreachable/Makefile
5757run-make/invalid-library/Makefile
58run-make/invalid-so/Makefile
5958run-make/issue-107094/Makefile
6059run-make/issue-109934-lto-debuginfo/Makefile
6160run-make/issue-14698/Makefile
6261run-make/issue-15460/Makefile
6362run-make/issue-18943/Makefile
64run-make/issue-20626/Makefile
6563run-make/issue-22131/Makefile
6664run-make/issue-25581/Makefile
6765run-make/issue-26006/Makefile
......@@ -97,7 +95,6 @@ run-make/long-linker-command-lines-cmd-exe/Makefile
9795run-make/long-linker-command-lines/Makefile
9896run-make/longjmp-across-rust/Makefile
9997run-make/lto-dylib-dep/Makefile
100run-make/lto-empty/Makefile
10198run-make/lto-linkage-used-attr/Makefile
10299run-make/lto-no-link-whole-rlib/Makefile
103100run-make/lto-smoke-c/Makefile
src/tools/tidy/src/ext_tool_checks.rs+2-1
......@@ -110,12 +110,13 @@ fn check_impl(
110110 }
111111
112112 let mut args = merge_args(&cfg_args_ruff, &file_args_ruff);
113 args.insert(0, "check".as_ref());
113114 let res = py_runner(py_path.as_ref().unwrap(), "ruff", &args);
114115
115116 if res.is_err() && show_diff {
116117 eprintln!("\npython linting failed! Printing diff suggestions:");
117118
118 args.insert(0, "--diff".as_ref());
119 args.insert(1, "--diff".as_ref());
119120 let _ = py_runner(py_path.as_ref().unwrap(), "ruff", &args);
120121 }
121122 // Rethrow error
tests/run-make/invalid-so/Makefile deleted-7
......@@ -1,7 +0,0 @@
1include ../tools.mk
2
3DYLIB_NAME := $(shell echo | $(RUSTC) --crate-name foo --crate-type dylib --print file-names -)
4
5all:
6 echo >> $(TMPDIR)/$(DYLIB_NAME)
7 $(RUSTC) --crate-type lib --extern foo=$(TMPDIR)/$(DYLIB_NAME) bar.rs 2>&1 | $(CGREP) 'invalid metadata files for crate `foo`'
tests/run-make/invalid-so/rmake.rs created+17
......@@ -0,0 +1,17 @@
1// When a fake library was given to the compiler, it would
2// result in an obscure and unhelpful error message. This test
3// creates a false "foo" dylib, and checks that the standard error
4// explains that the file exists, but that its metadata is incorrect.
5// See https://github.com/rust-lang/rust/pull/88368
6
7use run_make_support::{dynamic_lib_name, fs_wrapper, rustc};
8
9fn main() {
10 fs_wrapper::create_file(dynamic_lib_name("foo"));
11 rustc()
12 .crate_type("lib")
13 .extern_("foo", dynamic_lib_name("foo"))
14 .input("bar.rs")
15 .run_fail()
16 .assert_stderr_contains("invalid metadata files for crate `foo`");
17}
tests/run-make/issue-20626/Makefile deleted-9
......@@ -1,9 +0,0 @@
1# ignore-cross-compile
2include ../tools.mk
3
4# Test output to be four
5# The original error only occurred when printing, not when comparing using assert!
6
7all:
8 $(RUSTC) foo.rs -O
9 [ `$(call RUN,foo)` = "4" ]
tests/run-make/issue-20626/foo.rs deleted-15
......@@ -1,15 +0,0 @@
1fn identity(a: &u32) -> &u32 {
2 a
3}
4
5fn print_foo(f: &fn(&u32) -> &u32, x: &u32) {
6 print!("{}", (*f)(x));
7}
8
9fn main() {
10 let x = &4;
11 let f: fn(&u32) -> &u32 = identity;
12
13 // Didn't print 4 on optimized builds
14 print_foo(&f, x);
15}
tests/run-make/lto-empty/Makefile deleted-13
......@@ -1,13 +0,0 @@
1# ignore-cross-compile
2include ../tools.mk
3
4all: cdylib-fat cdylib-thin
5
6cdylib-fat:
7 $(RUSTC) lib.rs -C lto=fat -C opt-level=3 -C incremental=$(TMPDIR)/inc-fat
8 $(RUSTC) lib.rs -C lto=fat -C opt-level=3 -C incremental=$(TMPDIR)/inc-fat
9
10cdylib-thin:
11 $(RUSTC) lib.rs -C lto=thin -C opt-level=3 -C incremental=$(TMPDIR)/inc-thin
12 $(RUSTC) lib.rs -C lto=thin -C opt-level=3 -C incremental=$(TMPDIR)/inc-thin
13
tests/run-make/lto-empty/rmake.rs created+17
......@@ -0,0 +1,17 @@
1// Compiling Rust code twice in a row with "fat" link-time-optimizations used to cause
2// an internal compiler error (ICE). This was due to how the compiler would cache some modules
3// to make subsequent compilations faster, at least one of which was required for LTO to link
4// into. After this was patched in #63956, this test checks that the bug does not make
5// a resurgence.
6// See https://github.com/rust-lang/rust/issues/63349
7
8//@ ignore-cross-compile
9
10use run_make_support::rustc;
11
12fn main() {
13 rustc().input("lib.rs").arg("-Clto=fat").opt_level("3").incremental("inc-fat").run();
14 rustc().input("lib.rs").arg("-Clto=fat").opt_level("3").incremental("inc-fat").run();
15 rustc().input("lib.rs").arg("-Clto=thin").opt_level("3").incremental("inc-thin").run();
16 rustc().input("lib.rs").arg("-Clto=thin").opt_level("3").incremental("inc-thin").run();
17}
tests/run-make/raw-fn-pointer-opt-undefined-behavior/foo.rs created+15
......@@ -0,0 +1,15 @@
1fn identity(a: &u32) -> &u32 {
2 a
3}
4
5fn print_foo(f: &fn(&u32) -> &u32, x: &u32) {
6 print!("{}", (*f)(x));
7}
8
9fn main() {
10 let x = &4;
11 let f: fn(&u32) -> &u32 = identity;
12
13 // Didn't print 4 on optimized builds
14 print_foo(&f, x);
15}
tests/run-make/raw-fn-pointer-opt-undefined-behavior/rmake.rs created+16
......@@ -0,0 +1,16 @@
1// Despite the absence of any unsafe Rust code, foo.rs in this test would,
2// because of the raw function pointer,
3// cause undefined behavior and fail to print the expected result, "4" -
4// only when activating optimizations (opt-level 2). This test checks
5// that this bug does not make a resurgence.
6// Note that the bug cannot be observed in an assert_eq!, only in the stdout.
7// See https://github.com/rust-lang/rust/issues/20626
8
9//@ ignore-cross-compile
10
11use run_make_support::{run, rustc};
12
13fn main() {
14 rustc().input("foo.rs").opt().run();
15 run("foo").assert_stdout_equals("4");
16}
tests/ui/array-slice-vec/vec-res-add.stderr+5
......@@ -5,6 +5,11 @@ LL | let k = i + j;
55 | - ^ - Vec<R>
66 | |
77 | Vec<R>
8 |
9note: the foreign item type `Vec<R>` doesn't implement `Add`
10 --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
11 |
12 = note: not implement `Add`
813
914error: aborting due to 1 previous error
1015
tests/ui/autoderef-full-lval.stderr+12
......@@ -5,6 +5,12 @@ LL | let z: isize = a.x + b.y;
55 | --- ^ --- Box<isize>
66 | |
77 | Box<isize>
8 |
9note: the foreign item type `Box<isize>` doesn't implement `Add`
10 --> $SRC_DIR/alloc/src/boxed.rs:LL:COL
11 ::: $SRC_DIR/alloc/src/boxed.rs:LL:COL
12 |
13 = note: not implement `Add`
814
915error[E0369]: cannot add `Box<isize>` to `Box<isize>`
1016 --> $DIR/autoderef-full-lval.rs:21:33
......@@ -13,6 +19,12 @@ LL | let answer: isize = forty.a + two.a;
1319 | ------- ^ ----- Box<isize>
1420 | |
1521 | Box<isize>
22 |
23note: the foreign item type `Box<isize>` doesn't implement `Add`
24 --> $SRC_DIR/alloc/src/boxed.rs:LL:COL
25 ::: $SRC_DIR/alloc/src/boxed.rs:LL:COL
26 |
27 = note: not implement `Add`
1628
1729error: aborting due to 2 previous errors
1830
tests/ui/binop/binary-op-not-allowed-issue-125631.rs created+16
......@@ -0,0 +1,16 @@
1use std::io::{Error, ErrorKind};
2use std::thread;
3
4struct T1;
5struct T2;
6
7fn main() {
8 (Error::new(ErrorKind::Other, "1"), T1, 1) == (Error::new(ErrorKind::Other, "1"), T1, 2);
9 //~^ERROR binary operation `==` cannot be applied to type
10 (Error::new(ErrorKind::Other, "2"), thread::current())
11 == (Error::new(ErrorKind::Other, "2"), thread::current());
12 //~^ERROR binary operation `==` cannot be applied to type
13 (Error::new(ErrorKind::Other, "4"), thread::current(), T1, T2)
14 == (Error::new(ErrorKind::Other, "4"), thread::current(), T1, T2);
15 //~^ERROR binary operation `==` cannot be applied to type
16}
tests/ui/binop/binary-op-not-allowed-issue-125631.stderr created+75
......@@ -0,0 +1,75 @@
1error[E0369]: binary operation `==` cannot be applied to type `(std::io::Error, T1, {integer})`
2 --> $DIR/binary-op-not-allowed-issue-125631.rs:8:48
3 |
4LL | (Error::new(ErrorKind::Other, "1"), T1, 1) == (Error::new(ErrorKind::Other, "1"), T1, 2);
5 | ------------------------------------------ ^^ ------------------------------------------ (std::io::Error, T1, {integer})
6 | |
7 | (std::io::Error, T1, {integer})
8 |
9note: an implementation of `PartialEq` might be missing for `T1`
10 --> $DIR/binary-op-not-allowed-issue-125631.rs:4:1
11 |
12LL | struct T1;
13 | ^^^^^^^^^ must implement `PartialEq`
14note: the foreign item type `std::io::Error` doesn't implement `PartialEq`
15 --> $SRC_DIR/std/src/io/error.rs:LL:COL
16 |
17 = note: not implement `PartialEq`
18help: consider annotating `T1` with `#[derive(PartialEq)]`
19 |
20LL + #[derive(PartialEq)]
21LL | struct T1;
22 |
23
24error[E0369]: binary operation `==` cannot be applied to type `(std::io::Error, Thread)`
25 --> $DIR/binary-op-not-allowed-issue-125631.rs:11:9
26 |
27LL | (Error::new(ErrorKind::Other, "2"), thread::current())
28 | ------------------------------------------------------ (std::io::Error, Thread)
29LL | == (Error::new(ErrorKind::Other, "2"), thread::current());
30 | ^^ ------------------------------------------------------ (std::io::Error, Thread)
31 |
32note: the foreign item types don't implement required traits for this operation to be valid
33 --> $SRC_DIR/std/src/io/error.rs:LL:COL
34 |
35 = note: not implement `PartialEq`
36 --> $SRC_DIR/std/src/thread/mod.rs:LL:COL
37 |
38 = note: not implement `PartialEq`
39
40error[E0369]: binary operation `==` cannot be applied to type `(std::io::Error, Thread, T1, T2)`
41 --> $DIR/binary-op-not-allowed-issue-125631.rs:14:9
42 |
43LL | (Error::new(ErrorKind::Other, "4"), thread::current(), T1, T2)
44 | -------------------------------------------------------------- (std::io::Error, Thread, T1, T2)
45LL | == (Error::new(ErrorKind::Other, "4"), thread::current(), T1, T2);
46 | ^^ -------------------------------------------------------------- (std::io::Error, Thread, T1, T2)
47 |
48note: the following types would have to `impl` their required traits for this operation to be valid
49 --> $DIR/binary-op-not-allowed-issue-125631.rs:4:1
50 |
51LL | struct T1;
52 | ^^^^^^^^^ must implement `PartialEq`
53LL | struct T2;
54 | ^^^^^^^^^ must implement `PartialEq`
55note: the foreign item types don't implement required traits for this operation to be valid
56 --> $SRC_DIR/std/src/io/error.rs:LL:COL
57 |
58 = note: not implement `PartialEq`
59 --> $SRC_DIR/std/src/thread/mod.rs:LL:COL
60 |
61 = note: not implement `PartialEq`
62help: consider annotating `T1` with `#[derive(PartialEq)]`
63 |
64LL + #[derive(PartialEq)]
65LL | struct T1;
66 |
67help: consider annotating `T2` with `#[derive(PartialEq)]`
68 |
69LL + #[derive(PartialEq)]
70LL | struct T2;
71 |
72
73error: aborting due to 3 previous errors
74
75For more information about this error, try `rustc --explain E0369`.
tests/ui/binop/binop-bitxor-str.stderr+5
......@@ -5,6 +5,11 @@ LL | fn main() { let x = "a".to_string() ^ "b".to_string(); }
55 | --------------- ^ --------------- String
66 | |
77 | String
8 |
9note: the foreign item type `String` doesn't implement `BitXor`
10 --> $SRC_DIR/alloc/src/string.rs:LL:COL
11 |
12 = note: not implement `BitXor`
813
914error: aborting due to 1 previous error
1015
tests/ui/error-codes/E0067.stderr+6
......@@ -5,6 +5,12 @@ LL | LinkedList::new() += 1;
55 | -----------------^^^^^
66 | |
77 | cannot use `+=` on type `LinkedList<_>`
8 |
9note: the foreign item type `LinkedList<_>` doesn't implement `AddAssign<{integer}>`
10 --> $SRC_DIR/alloc/src/collections/linked_list.rs:LL:COL
11 ::: $SRC_DIR/alloc/src/collections/linked_list.rs:LL:COL
12 |
13 = note: not implement `AddAssign<{integer}>`
814
915error[E0067]: invalid left-hand side of assignment
1016 --> $DIR/E0067.rs:4:23
tests/ui/impl-trait/in-trait/refine-resolution-errors.rs created+23
......@@ -0,0 +1,23 @@
1// This is a non-regression test for issue #126670 where RPITIT refinement checking encountered
2// errors during resolution and ICEd.
3
4//@ edition: 2018
5
6pub trait Mirror {
7 type Assoc;
8}
9impl<T: ?Sized> Mirror for () {
10 //~^ ERROR the type parameter `T` is not constrained
11 type Assoc = T;
12}
13
14pub trait First {
15 async fn first() -> <() as Mirror>::Assoc;
16 //~^ ERROR type annotations needed
17}
18
19impl First for () {
20 async fn first() {}
21}
22
23fn main() {}
tests/ui/impl-trait/in-trait/refine-resolution-errors.stderr created+16
......@@ -0,0 +1,16 @@
1error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
2 --> $DIR/refine-resolution-errors.rs:9:6
3 |
4LL | impl<T: ?Sized> Mirror for () {
5 | ^ unconstrained type parameter
6
7error[E0282]: type annotations needed
8 --> $DIR/refine-resolution-errors.rs:15:5
9 |
10LL | async fn first() -> <() as Mirror>::Assoc;
11 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
12
13error: aborting due to 2 previous errors
14
15Some errors have detailed explanations: E0207, E0282.
16For more information about an error, try `rustc --explain E0207`.
tests/ui/issues/issue-14915.stderr+6
......@@ -5,6 +5,12 @@ LL | println!("{}", x + 1);
55 | - ^ - {integer}
66 | |
77 | Box<isize>
8 |
9note: the foreign item type `Box<isize>` doesn't implement `Add<{integer}>`
10 --> $SRC_DIR/alloc/src/boxed.rs:LL:COL
11 ::: $SRC_DIR/alloc/src/boxed.rs:LL:COL
12 |
13 = note: not implement `Add<{integer}>`
814
915error: aborting due to 1 previous error
1016
tests/ui/minus-string.stderr+5
......@@ -3,6 +3,11 @@ error[E0600]: cannot apply unary operator `-` to type `String`
33 |
44LL | fn main() { -"foo".to_string(); }
55 | ^^^^^^^^^^^^^^^^^^ cannot apply unary operator `-`
6 |
7note: the foreign item type `String` doesn't implement `Neg`
8 --> $SRC_DIR/alloc/src/string.rs:LL:COL
9 |
10 = note: not implement `Neg`
611
712error: aborting due to 1 previous error
813
tests/ui/parser/fn-header-semantic-fail.stderr+10-6
......@@ -81,11 +81,13 @@ LL | async fn fe1();
8181error: items in unadorned `extern` blocks cannot have safety qualifiers
8282 --> $DIR/fn-header-semantic-fail.rs:47:9
8383 |
84LL | extern "C" {
85 | ---------- help: add unsafe to this `extern` block
86LL | async fn fe1();
8784LL | unsafe fn fe2();
8885 | ^^^^^^^^^^^^^^^^
86 |
87help: add unsafe to this `extern` block
88 |
89LL | unsafe extern "C" {
90 | ++++++
8991
9092error: functions in `extern` blocks cannot have qualifiers
9193 --> $DIR/fn-header-semantic-fail.rs:48:9
......@@ -135,11 +137,13 @@ LL | const async unsafe extern "C" fn fe5();
135137error: items in unadorned `extern` blocks cannot have safety qualifiers
136138 --> $DIR/fn-header-semantic-fail.rs:50:9
137139 |
138LL | extern "C" {
139 | ---------- help: add unsafe to this `extern` block
140...
141140LL | const async unsafe extern "C" fn fe5();
142141 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
142 |
143help: add unsafe to this `extern` block
144 |
145LL | unsafe extern "C" {
146 | ++++++
143147
144148error: functions cannot be both `const` and `async`
145149 --> $DIR/fn-header-semantic-fail.rs:50:9
tests/ui/parser/no-const-fn-in-extern-block.stderr+5-3
......@@ -18,11 +18,13 @@ LL | const unsafe fn bar();
1818error: items in unadorned `extern` blocks cannot have safety qualifiers
1919 --> $DIR/no-const-fn-in-extern-block.rs:4:5
2020 |
21LL | extern "C" {
22 | ---------- help: add unsafe to this `extern` block
23...
2421LL | const unsafe fn bar();
2522 | ^^^^^^^^^^^^^^^^^^^^^^
23 |
24help: add unsafe to this `extern` block
25 |
26LL | unsafe extern "C" {
27 | ++++++
2628
2729error: aborting due to 3 previous errors
2830
tests/ui/parser/unsafe-foreign-mod-2.stderr+5-3
......@@ -13,11 +13,13 @@ LL | extern "C" unsafe {
1313error: items in unadorned `extern` blocks cannot have safety qualifiers
1414 --> $DIR/unsafe-foreign-mod-2.rs:4:5
1515 |
16LL | extern "C" unsafe {
17 | ----------------- help: add unsafe to this `extern` block
18...
1916LL | unsafe fn foo();
2017 | ^^^^^^^^^^^^^^^^
18 |
19help: add unsafe to this `extern` block
20 |
21LL | unsafe extern "C" unsafe {
22 | ++++++
2123
2224error: aborting due to 3 previous errors
2325
tests/ui/pattern/pattern-tyvar-2.stderr+5
......@@ -5,6 +5,11 @@ LL | fn foo(t: Bar) -> isize { match t { Bar::T1(_, Some(x)) => { return x * 3;
55 | - ^ - {integer}
66 | |
77 | Vec<isize>
8 |
9note: the foreign item type `Vec<isize>` doesn't implement `Mul<{integer}>`
10 --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
11 |
12 = note: not implement `Mul<{integer}>`
813
914error: aborting due to 1 previous error
1015
tests/ui/rust-2024/safe-outside-extern.gated.stderr+1-1
......@@ -26,7 +26,7 @@ error: function pointers cannot be declared with `safe` safety qualifier
2626 --> $DIR/safe-outside-extern.rs:24:14
2727 |
2828LL | type FnPtr = safe fn(i32, i32) -> i32;
29 | ^^^^^^^^^^^^^^^^^^^^^^^^^
29 | ^^^^^^^^^^^^^^^^^^^^^^^^
3030
3131error: aborting due to 5 previous errors
3232
tests/ui/rust-2024/safe-outside-extern.ungated.stderr+1-1
......@@ -26,7 +26,7 @@ error: function pointers cannot be declared with `safe` safety qualifier
2626 --> $DIR/safe-outside-extern.rs:24:14
2727 |
2828LL | type FnPtr = safe fn(i32, i32) -> i32;
29 | ^^^^^^^^^^^^^^^^^^^^^^^^^
29 | ^^^^^^^^^^^^^^^^^^^^^^^^
3030
3131error[E0658]: `unsafe extern {}` blocks and `safe` keyword are experimental
3232 --> $DIR/safe-outside-extern.rs:4:1
tests/ui/rust-2024/unsafe-extern-blocks/safe-unsafe-on-unadorned-extern-block.edition2021.stderr+10-6
......@@ -1,20 +1,24 @@
11error: items in unadorned `extern` blocks cannot have safety qualifiers
22 --> $DIR/safe-unsafe-on-unadorned-extern-block.rs:10:5
33 |
4LL | extern "C" {
5 | ---------- help: add unsafe to this `extern` block
6LL |
74LL | safe static TEST1: i32;
85 | ^^^^^^^^^^^^^^^^^^^^^^^
6 |
7help: add unsafe to this `extern` block
8 |
9LL | unsafe extern "C" {
10 | ++++++
911
1012error: items in unadorned `extern` blocks cannot have safety qualifiers
1113 --> $DIR/safe-unsafe-on-unadorned-extern-block.rs:12:5
1214 |
13LL | extern "C" {
14 | ---------- help: add unsafe to this `extern` block
15...
1615LL | safe fn test1(i: i32);
1716 | ^^^^^^^^^^^^^^^^^^^^^^
17 |
18help: add unsafe to this `extern` block
19 |
20LL | unsafe extern "C" {
21 | ++++++
1822
1923error: aborting due to 2 previous errors
2024
tests/ui/rust-2024/unsafe-extern-blocks/safe-unsafe-on-unadorned-extern-block.edition2024.stderr+10-6
......@@ -13,20 +13,24 @@ LL | | }
1313error: items in unadorned `extern` blocks cannot have safety qualifiers
1414 --> $DIR/safe-unsafe-on-unadorned-extern-block.rs:10:5
1515 |
16LL | extern "C" {
17 | ---------- help: add unsafe to this `extern` block
18LL |
1916LL | safe static TEST1: i32;
2017 | ^^^^^^^^^^^^^^^^^^^^^^^
18 |
19help: add unsafe to this `extern` block
20 |
21LL | unsafe extern "C" {
22 | ++++++
2123
2224error: items in unadorned `extern` blocks cannot have safety qualifiers
2325 --> $DIR/safe-unsafe-on-unadorned-extern-block.rs:12:5
2426 |
25LL | extern "C" {
26 | ---------- help: add unsafe to this `extern` block
27...
2827LL | safe fn test1(i: i32);
2928 | ^^^^^^^^^^^^^^^^^^^^^^
29 |
30help: add unsafe to this `extern` block
31 |
32LL | unsafe extern "C" {
33 | ++++++
3034
3135error: aborting due to 3 previous errors
3236
tests/ui/rust-2024/unsafe-extern-blocks/unsafe-on-extern-block-issue-126756.fixed created+10
......@@ -0,0 +1,10 @@
1//@ run-rustfix
2
3#![feature(unsafe_extern_blocks)]
4#![allow(dead_code)]
5
6unsafe extern "C" {
7 unsafe fn foo(); //~ ERROR items in unadorned `extern` blocks cannot have safety qualifiers
8}
9
10fn main() {}
tests/ui/rust-2024/unsafe-extern-blocks/unsafe-on-extern-block-issue-126756.rs created+10
......@@ -0,0 +1,10 @@
1//@ run-rustfix
2
3#![feature(unsafe_extern_blocks)]
4#![allow(dead_code)]
5
6extern "C" {
7 unsafe fn foo(); //~ ERROR items in unadorned `extern` blocks cannot have safety qualifiers
8}
9
10fn main() {}
tests/ui/rust-2024/unsafe-extern-blocks/unsafe-on-extern-block-issue-126756.stderr created+13
......@@ -0,0 +1,13 @@
1error: items in unadorned `extern` blocks cannot have safety qualifiers
2 --> $DIR/unsafe-on-extern-block-issue-126756.rs:7:5
3 |
4LL | unsafe fn foo();
5 | ^^^^^^^^^^^^^^^^
6 |
7help: add unsafe to this `extern` block
8 |
9LL | unsafe extern "C" {
10 | ++++++
11
12error: aborting due to 1 previous error
13
tests/ui/typeck/assign-non-lval-derefmut.stderr+8
......@@ -19,6 +19,10 @@ LL | x.lock().unwrap() += 1;
1919 | |
2020 | cannot use `+=` on type `MutexGuard<'_, usize>`
2121 |
22note: the foreign item type `MutexGuard<'_, usize>` doesn't implement `AddAssign<{integer}>`
23 --> $SRC_DIR/std/src/sync/mutex.rs:LL:COL
24 |
25 = note: not implement `AddAssign<{integer}>`
2226help: `+=` can be used on `usize` if you dereference the left-hand side
2327 |
2428LL | *x.lock().unwrap() += 1;
......@@ -47,6 +51,10 @@ LL | y += 1;
4751 | |
4852 | cannot use `+=` on type `MutexGuard<'_, usize>`
4953 |
54note: the foreign item type `MutexGuard<'_, usize>` doesn't implement `AddAssign<{integer}>`
55 --> $SRC_DIR/std/src/sync/mutex.rs:LL:COL
56 |
57 = note: not implement `AddAssign<{integer}>`
5058help: `+=` can be used on `usize` if you dereference the left-hand side
5159 |
5260LL | *y += 1;