Skip to content

Commit aebf7c4

Browse files
committed
Auto merge of rust-lang#103991 - matthiaskrgr:rollup-tj53nte, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#103868 (Use `TraitEngine` (by itself) less) - rust-lang#103878 (Fix artifact version/channel detection for stable) - rust-lang#103946 (Cleanup bind_pattern args) - rust-lang#103956 (Make mir opt unused file check blessable) - rust-lang#103977 (LLVM 16: Switch to using MemoryEffects) - rust-lang#103980 (rustdoc: simplify search results CSS and DOM) - rust-lang#103984 (Refactor tcx mk_const parameters.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 81ff7e7 + b101f3a commit aebf7c4

File tree

43 files changed

+284
-295
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+284
-295
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use rustc_span::hygiene::DesugaringKind;
2323
use rustc_span::symbol::sym;
2424
use rustc_span::{BytePos, Span, Symbol};
2525
use rustc_trait_selection::infer::InferCtxtExt;
26-
use rustc_trait_selection::traits::TraitEngineExt as _;
2726

2827
use crate::borrow_set::TwoPhaseActivation;
2928
use crate::borrowck_errors;
@@ -613,24 +612,20 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
613612
else { return; };
614613
// Try to find predicates on *generic params* that would allow copying `ty`
615614
let infcx = tcx.infer_ctxt().build();
616-
let mut fulfill_cx = <dyn rustc_infer::traits::TraitEngine<'_>>::new(infcx.tcx);
617-
618615
let copy_did = infcx.tcx.lang_items().copy_trait().unwrap();
619616
let cause = ObligationCause::new(
620617
span,
621618
self.mir_hir_id(),
622619
rustc_infer::traits::ObligationCauseCode::MiscObligation,
623620
);
624-
fulfill_cx.register_bound(
621+
let errors = rustc_trait_selection::traits::fully_solve_bound(
625622
&infcx,
623+
cause,
626624
self.param_env,
627625
// Erase any region vids from the type, which may not be resolved
628626
infcx.tcx.erase_regions(ty),
629627
copy_did,
630-
cause,
631628
);
632-
// Select all, including ambiguous predicates
633-
let errors = fulfill_cx.select_all_or_error(&infcx);
634629

635630
// Only emit suggestion if all required predicates are on generic
636631
let predicates: Result<Vec<_>, _> = errors

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+25-28
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ use rustc_hir::def_id::LocalDefId;
44
use rustc_hir::OpaqueTyOrigin;
55
use rustc_infer::infer::TyCtxtInferExt as _;
66
use rustc_infer::infer::{DefiningAnchor, InferCtxt};
7-
use rustc_infer::traits::{Obligation, ObligationCause, TraitEngine};
7+
use rustc_infer::traits::{Obligation, ObligationCause};
88
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts};
99
use rustc_middle::ty::visit::TypeVisitable;
1010
use rustc_middle::ty::{
1111
self, OpaqueHiddenType, OpaqueTypeKey, ToPredicate, Ty, TyCtxt, TypeFoldable,
1212
};
1313
use rustc_span::Span;
1414
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
15-
use rustc_trait_selection::traits::TraitEngineExt as _;
15+
use rustc_trait_selection::traits::ObligationCtxt;
1616

1717
use super::RegionInferenceContext;
1818

@@ -252,48 +252,45 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
252252
// type-alias-impl-trait/issue-67844-nested-opaque.rs
253253
let infcx =
254254
self.tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bubble).build();
255+
let ocx = ObligationCtxt::new(&infcx);
255256
// Require the hidden type to be well-formed with only the generics of the opaque type.
256257
// Defining use functions may have more bounds than the opaque type, which is ok, as long as the
257258
// hidden type is well formed even without those bounds.
258259
let predicate = ty::Binder::dummy(ty::PredicateKind::WellFormed(definition_ty.into()))
259260
.to_predicate(infcx.tcx);
260-
let mut fulfillment_cx = <dyn TraitEngine<'tcx>>::new(infcx.tcx);
261261

262262
let id_substs = InternalSubsts::identity_for_item(self.tcx, def_id.to_def_id());
263263

264264
// Require that the hidden type actually fulfills all the bounds of the opaque type, even without
265265
// the bounds that the function supplies.
266266
let opaque_ty = self.tcx.mk_opaque(def_id.to_def_id(), id_substs);
267-
match infcx
268-
.at(&ObligationCause::misc(instantiated_ty.span, body_id), param_env)
269-
.eq(opaque_ty, definition_ty)
270-
{
271-
Ok(infer_ok) => {
272-
for obligation in infer_ok.obligations {
273-
fulfillment_cx.register_predicate_obligation(&infcx, obligation);
274-
}
275-
}
276-
Err(err) => {
277-
infcx
278-
.err_ctxt()
279-
.report_mismatched_types(
280-
&ObligationCause::misc(instantiated_ty.span, body_id),
281-
opaque_ty,
282-
definition_ty,
283-
err,
284-
)
285-
.emit();
286-
}
267+
if let Err(err) = ocx.eq(
268+
&ObligationCause::misc(instantiated_ty.span, body_id),
269+
param_env,
270+
opaque_ty,
271+
definition_ty,
272+
) {
273+
infcx
274+
.err_ctxt()
275+
.report_mismatched_types(
276+
&ObligationCause::misc(instantiated_ty.span, body_id),
277+
opaque_ty,
278+
definition_ty,
279+
err,
280+
)
281+
.emit();
287282
}
288283

289-
fulfillment_cx.register_predicate_obligation(
290-
&infcx,
291-
Obligation::misc(instantiated_ty.span, body_id, param_env, predicate),
292-
);
284+
ocx.register_obligation(Obligation::misc(
285+
instantiated_ty.span,
286+
body_id,
287+
param_env,
288+
predicate,
289+
));
293290

294291
// Check that all obligations are satisfied by the implementation's
295292
// version.
296-
let errors = fulfillment_cx.select_all_or_error(&infcx);
293+
let errors = ocx.select_all_or_error();
297294

298295
// This is still required for many(half of the tests in ui/type-alias-impl-trait)
299296
// tests to pass

compiler/rustc_codegen_llvm/src/asm.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,13 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
285285
let mut attrs = SmallVec::<[_; 2]>::new();
286286
if options.contains(InlineAsmOptions::PURE) {
287287
if options.contains(InlineAsmOptions::NOMEM) {
288-
attrs.push(llvm::AttributeKind::ReadNone.create_attr(self.cx.llcx));
288+
attrs.push(llvm::MemoryEffects::None.create_attr(self.cx.llcx));
289289
} else if options.contains(InlineAsmOptions::READONLY) {
290-
attrs.push(llvm::AttributeKind::ReadOnly.create_attr(self.cx.llcx));
290+
attrs.push(llvm::MemoryEffects::ReadOnly.create_attr(self.cx.llcx));
291291
}
292292
attrs.push(llvm::AttributeKind::WillReturn.create_attr(self.cx.llcx));
293293
} else if options.contains(InlineAsmOptions::NOMEM) {
294-
attrs.push(llvm::AttributeKind::InaccessibleMemOnly.create_attr(self.cx.llcx));
294+
attrs.push(llvm::MemoryEffects::InaccessibleMemOnly.create_attr(self.cx.llcx));
295295
} else {
296296
// LLVM doesn't have an attribute to represent ReadOnly + SideEffect
297297
}

compiler/rustc_codegen_llvm/src/attributes.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use smallvec::SmallVec;
1313

1414
use crate::attributes;
1515
use crate::llvm::AttributePlace::Function;
16-
use crate::llvm::{self, AllocKindFlags, Attribute, AttributeKind, AttributePlace};
16+
use crate::llvm::{self, AllocKindFlags, Attribute, AttributeKind, AttributePlace, MemoryEffects};
1717
use crate::llvm_util;
1818
pub use rustc_attr::{InlineAttr, InstructionSetAttr, OptimizeAttr};
1919

@@ -303,10 +303,10 @@ pub fn from_fn_attrs<'ll, 'tcx>(
303303
to_add.push(AttributeKind::ReturnsTwice.create_attr(cx.llcx));
304304
}
305305
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::FFI_PURE) {
306-
to_add.push(AttributeKind::ReadOnly.create_attr(cx.llcx));
306+
to_add.push(MemoryEffects::ReadOnly.create_attr(cx.llcx));
307307
}
308308
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::FFI_CONST) {
309-
to_add.push(AttributeKind::ReadNone.create_attr(cx.llcx));
309+
to_add.push(MemoryEffects::None.create_attr(cx.llcx));
310310
}
311311
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
312312
to_add.push(AttributeKind::Naked.create_attr(cx.llcx));

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ pub enum AttributeKind {
183183
OptimizeNone = 24,
184184
ReturnsTwice = 25,
185185
ReadNone = 26,
186-
InaccessibleMemOnly = 27,
187186
SanitizeHWAddress = 28,
188187
WillReturn = 29,
189188
StackProtectReq = 30,
@@ -590,6 +589,15 @@ pub enum ChecksumKind {
590589
SHA256,
591590
}
592591

592+
/// LLVMRustMemoryEffects
593+
#[derive(Copy, Clone)]
594+
#[repr(C)]
595+
pub enum MemoryEffects {
596+
None,
597+
ReadOnly,
598+
InaccessibleMemOnly,
599+
}
600+
593601
extern "C" {
594602
type Opaque;
595603
}
@@ -1175,6 +1183,7 @@ extern "C" {
11751183
pub fn LLVMRustCreateUWTableAttr(C: &Context, async_: bool) -> &Attribute;
11761184
pub fn LLVMRustCreateAllocSizeAttr(C: &Context, size_arg: u32) -> &Attribute;
11771185
pub fn LLVMRustCreateAllocKindAttr(C: &Context, size_arg: u64) -> &Attribute;
1186+
pub fn LLVMRustCreateMemoryEffectsAttr(C: &Context, effects: MemoryEffects) -> &Attribute;
11781187

11791188
// Operations on functions
11801189
pub fn LLVMRustGetOrInsertFunction<'a>(

compiler/rustc_codegen_llvm/src/llvm/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,13 @@ impl AttributeKind {
185185
}
186186
}
187187

188+
impl MemoryEffects {
189+
/// Create an LLVM Attribute with these memory effects.
190+
pub fn create_attr(self, llcx: &Context) -> &Attribute {
191+
unsafe { LLVMRustCreateMemoryEffectsAttr(llcx, self) }
192+
}
193+
}
194+
188195
pub fn set_section(llglobal: &Value, section_name: &str) {
189196
let section_name_cstr = CString::new(section_name).expect("unexpected CString error");
190197
unsafe {

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+15-27
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@ use rustc_middle::ty::{self, adjustment::PointerCast, Instance, InstanceDef, Ty,
1313
use rustc_middle::ty::{Binder, TraitPredicate, TraitRef, TypeVisitable};
1414
use rustc_mir_dataflow::{self, Analysis};
1515
use rustc_span::{sym, Span, Symbol};
16-
use rustc_trait_selection::infer::InferCtxtExt;
1716
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
18-
use rustc_trait_selection::traits::{
19-
self, ObligationCauseCode, SelectionContext, TraitEngine, TraitEngineExt,
20-
};
17+
use rustc_trait_selection::traits::{self, ObligationCauseCode, ObligationCtxt, SelectionContext};
2118

2219
use std::mem;
2320
use std::ops::Deref;
@@ -747,35 +744,26 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
747744
// "non-const" check. This is required for correctness here.
748745
{
749746
let infcx = tcx.infer_ctxt().build();
750-
let mut fulfill_cx = <dyn TraitEngine<'_>>::new(infcx.tcx);
747+
let ocx = ObligationCtxt::new(&infcx);
748+
751749
let predicates = tcx.predicates_of(callee).instantiate(tcx, substs);
752750
let hir_id = tcx
753751
.hir()
754752
.local_def_id_to_hir_id(self.body.source.def_id().expect_local());
755-
let cause = || {
756-
ObligationCause::new(
757-
terminator.source_info.span,
758-
hir_id,
759-
ObligationCauseCode::ItemObligation(callee),
760-
)
761-
};
762-
let normalized = infcx.partially_normalize_associated_types_in(
763-
cause(),
764-
param_env,
765-
predicates,
753+
let cause = ObligationCause::new(
754+
terminator.source_info.span,
755+
hir_id,
756+
ObligationCauseCode::ItemObligation(callee),
766757
);
767-
768-
for p in normalized.obligations {
769-
fulfill_cx.register_predicate_obligation(&infcx, p);
770-
}
771-
for obligation in traits::predicates_for_generics(
772-
|_, _| cause(),
758+
let normalized_predicates =
759+
ocx.normalize(cause.clone(), param_env, predicates);
760+
ocx.register_obligations(traits::predicates_for_generics(
761+
|_, _| cause.clone(),
773762
self.param_env,
774-
normalized.value,
775-
) {
776-
fulfill_cx.register_predicate_obligation(&infcx, obligation);
777-
}
778-
let errors = fulfill_cx.select_all_or_error(&infcx);
763+
normalized_predicates,
764+
));
765+
766+
let errors = ocx.select_all_or_error();
779767
if !errors.is_empty() {
780768
infcx.err_ctxt().report_fulfillment_errors(&errors, None, false);
781769
}

compiler/rustc_hir_analysis/src/check/compare_method.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -1655,13 +1655,10 @@ pub fn check_type_bounds<'tcx>(
16551655
GenericParamDefKind::Const { .. } => {
16561656
let bound_var = ty::BoundVariableKind::Const;
16571657
bound_vars.push(bound_var);
1658-
tcx.mk_const(ty::ConstS {
1659-
ty: tcx.type_of(param.def_id),
1660-
kind: ty::ConstKind::Bound(
1661-
ty::INNERMOST,
1662-
ty::BoundVar::from_usize(bound_vars.len() - 1),
1663-
),
1664-
})
1658+
tcx.mk_const(
1659+
ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from_usize(bound_vars.len() - 1)),
1660+
tcx.type_of(param.def_id),
1661+
)
16651662
.into()
16661663
}
16671664
});

compiler/rustc_hir_typeck/src/op.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_span::symbol::{sym, Ident};
1919
use rustc_span::Span;
2020
use rustc_trait_selection::infer::InferCtxtExt;
2121
use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt as _;
22-
use rustc_trait_selection::traits::{FulfillmentError, TraitEngine, TraitEngineExt};
22+
use rustc_trait_selection::traits::FulfillmentError;
2323
use rustc_type_ir::sty::TyKind::*;
2424

2525
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
@@ -785,9 +785,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
785785
other_ty_expr,
786786
expected,
787787
);
788-
let mut fulfill = <dyn TraitEngine<'_>>::new(self.tcx);
789-
fulfill.register_predicate_obligation(self, obligation);
790-
Err(fulfill.select_where_possible(&self.infcx))
788+
Err(rustc_trait_selection::traits::fully_solve_obligation(self, obligation))
791789
}
792790
}
793791
}

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -773,10 +773,10 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
773773
self.fold_const(bound_to)
774774
} else {
775775
let var = self.canonical_var(info, const_var.into());
776-
self.tcx().mk_const(ty::ConstS {
777-
kind: ty::ConstKind::Bound(self.binder_index, var),
778-
ty: self.fold_ty(const_var.ty()),
779-
})
776+
self.tcx().mk_const(
777+
ty::ConstKind::Bound(self.binder_index, var),
778+
self.fold_ty(const_var.ty()),
779+
)
780780
}
781781
}
782782
}

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

+1-6
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,7 @@ impl<'tcx> InferCtxt<'tcx> {
147147
CanonicalVarKind::PlaceholderConst(ty::PlaceholderConst { universe, name }, ty) => {
148148
let universe_mapped = universe_map(universe);
149149
let placeholder_mapped = ty::PlaceholderConst { universe: universe_mapped, name };
150-
self.tcx
151-
.mk_const(ty::ConstS {
152-
kind: ty::ConstKind::Placeholder(placeholder_mapped),
153-
ty,
154-
})
155-
.into()
150+
self.tcx.mk_const(ty::ConstKind::Placeholder(placeholder_mapped), ty).into()
156151
}
157152
}
158153
}

compiler/rustc_infer/src/infer/combine.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -741,10 +741,10 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
741741
substs,
742742
substs,
743743
)?;
744-
Ok(self.tcx().mk_const(ty::ConstS {
745-
ty: c.ty(),
746-
kind: ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }),
747-
}))
744+
Ok(self.tcx().mk_const(
745+
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }),
746+
c.ty(),
747+
))
748748
}
749749
_ => relate::super_relate_consts(self, c, c),
750750
}
@@ -955,10 +955,10 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
955955
substs,
956956
)?;
957957

958-
Ok(self.tcx().mk_const(ty::ConstS {
959-
ty: c.ty(),
960-
kind: ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }),
961-
}))
958+
Ok(self.tcx().mk_const(
959+
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }),
960+
c.ty(),
961+
))
962962
}
963963
_ => relate::super_relate_consts(self, c, c),
964964
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ impl<'tcx> InferCtxt<'tcx> {
9494
}))
9595
},
9696
consts: &mut |bound_var: ty::BoundVar, ty| {
97-
self.tcx.mk_const(ty::ConstS {
98-
kind: ty::ConstKind::Placeholder(ty::PlaceholderConst {
97+
self.tcx.mk_const(
98+
ty::ConstKind::Placeholder(ty::PlaceholderConst {
9999
universe: next_universe,
100100
name: bound_var,
101101
}),
102102
ty,
103-
})
103+
)
104104
},
105105
};
106106

0 commit comments

Comments
 (0)