Skip to content

Commit 586893c

Browse files
committed
Auto merge of rust-lang#120722 - matthiaskrgr:rollup-9o32280, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#119939 (Improve 'generic param from outer item' error for `Self` and inside `static`/`const` items) - rust-lang#120331 (pattern_analysis: use a plain `Vec` in `DeconstructedPat`) - rust-lang#120396 (Account for unbounded type param receiver in suggestions) - rust-lang#120423 (update indirect structural match lints to match RFC and to show up for dependencies) - rust-lang#120435 (Suggest name value cfg when only value is used for check-cfg) - rust-lang#120502 (Remove `ffi_returns_twice` feature) - rust-lang#120507 (Account for non-overlapping unmet trait bounds in suggestion) - rust-lang#120513 (Normalize type outlives obligations in NLL for new solver) - rust-lang#120707 (Don't expect early-bound region to be local when reporting errors in RPITIT well-formedness) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 256b6fb + 84114fe commit 586893c

File tree

108 files changed

+1370
-746
lines changed

Some content is hidden

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

108 files changed

+1370
-746
lines changed

Diff for: compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

+96-22
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ use rustc_infer::infer::outlives::obligations::{TypeOutlives, TypeOutlivesDelega
55
use rustc_infer::infer::region_constraints::{GenericKind, VerifyBound};
66
use rustc_infer::infer::{self, InferCtxt, SubregionOrigin};
77
use rustc_middle::mir::{ClosureOutlivesSubject, ClosureRegionRequirements, ConstraintCategory};
8-
use rustc_middle::ty::GenericArgKind;
9-
use rustc_middle::ty::{self, TyCtxt};
10-
use rustc_middle::ty::{TypeFoldable, TypeVisitableExt};
8+
use rustc_middle::traits::query::NoSolution;
9+
use rustc_middle::traits::ObligationCause;
10+
use rustc_middle::ty::{self, GenericArgKind, Ty, TyCtxt, TypeFoldable, TypeVisitableExt};
1111
use rustc_span::{Span, DUMMY_SP};
12+
use rustc_trait_selection::solve::deeply_normalize;
13+
use rustc_trait_selection::traits::query::type_op::custom::CustomTypeOp;
14+
use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput};
1215

1316
use crate::{
1417
constraints::OutlivesConstraint,
@@ -33,6 +36,7 @@ pub(crate) struct ConstraintConversion<'a, 'tcx> {
3336
/// our special inference variable there, we would mess that up.
3437
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
3538
implicit_region_bound: ty::Region<'tcx>,
39+
param_env: ty::ParamEnv<'tcx>,
3640
known_type_outlives_obligations: &'tcx [ty::PolyTypeOutlivesPredicate<'tcx>],
3741
locations: Locations,
3842
span: Span,
@@ -47,6 +51,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
4751
universal_regions: &'a UniversalRegions<'tcx>,
4852
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
4953
implicit_region_bound: ty::Region<'tcx>,
54+
param_env: ty::ParamEnv<'tcx>,
5055
known_type_outlives_obligations: &'tcx [ty::PolyTypeOutlivesPredicate<'tcx>],
5156
locations: Locations,
5257
span: Span,
@@ -59,6 +64,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
5964
universal_regions,
6065
region_bound_pairs,
6166
implicit_region_bound,
67+
param_env,
6268
known_type_outlives_obligations,
6369
locations,
6470
span,
@@ -137,36 +143,68 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
137143
// Extract out various useful fields we'll need below.
138144
let ConstraintConversion {
139145
tcx,
146+
infcx,
140147
region_bound_pairs,
141148
implicit_region_bound,
142149
known_type_outlives_obligations,
143150
..
144151
} = *self;
145152

146-
let ty::OutlivesPredicate(k1, r2) = predicate;
147-
match k1.unpack() {
148-
GenericArgKind::Lifetime(r1) => {
149-
let r1_vid = self.to_region_vid(r1);
150-
let r2_vid = self.to_region_vid(r2);
151-
self.add_outlives(r1_vid, r2_vid, constraint_category);
153+
let mut outlives_predicates = vec![(predicate, constraint_category)];
154+
for iteration in 0.. {
155+
if outlives_predicates.is_empty() {
156+
break;
157+
}
158+
159+
if !self.tcx.recursion_limit().value_within_limit(iteration) {
160+
bug!(
161+
"FIXME(-Znext-solver): Overflowed when processing region obligations: {outlives_predicates:#?}"
162+
);
152163
}
153164

154-
GenericArgKind::Type(t1) => {
155-
// we don't actually use this for anything, but
156-
// the `TypeOutlives` code needs an origin.
157-
let origin = infer::RelateParamBound(DUMMY_SP, t1, None);
165+
let mut next_outlives_predicates = vec![];
166+
for (ty::OutlivesPredicate(k1, r2), constraint_category) in outlives_predicates {
167+
match k1.unpack() {
168+
GenericArgKind::Lifetime(r1) => {
169+
let r1_vid = self.to_region_vid(r1);
170+
let r2_vid = self.to_region_vid(r2);
171+
self.add_outlives(r1_vid, r2_vid, constraint_category);
172+
}
158173

159-
TypeOutlives::new(
160-
&mut *self,
161-
tcx,
162-
region_bound_pairs,
163-
Some(implicit_region_bound),
164-
known_type_outlives_obligations,
165-
)
166-
.type_must_outlive(origin, t1, r2, constraint_category);
174+
GenericArgKind::Type(mut t1) => {
175+
// Normalize the type we receive from a `TypeOutlives` obligation
176+
// in the new trait solver.
177+
if infcx.next_trait_solver() {
178+
t1 = self.normalize_and_add_type_outlives_constraints(
179+
t1,
180+
&mut next_outlives_predicates,
181+
);
182+
}
183+
184+
// we don't actually use this for anything, but
185+
// the `TypeOutlives` code needs an origin.
186+
let origin = infer::RelateParamBound(DUMMY_SP, t1, None);
187+
188+
TypeOutlives::new(
189+
&mut *self,
190+
tcx,
191+
region_bound_pairs,
192+
Some(implicit_region_bound),
193+
known_type_outlives_obligations,
194+
)
195+
.type_must_outlive(
196+
origin,
197+
t1,
198+
r2,
199+
constraint_category,
200+
);
201+
}
202+
203+
GenericArgKind::Const(_) => unreachable!(),
204+
}
167205
}
168206

169-
GenericArgKind::Const(_) => unreachable!(),
207+
outlives_predicates = next_outlives_predicates;
170208
}
171209
}
172210

@@ -232,6 +270,42 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
232270
debug!("add_type_test(type_test={:?})", type_test);
233271
self.constraints.type_tests.push(type_test);
234272
}
273+
274+
fn normalize_and_add_type_outlives_constraints(
275+
&self,
276+
ty: Ty<'tcx>,
277+
next_outlives_predicates: &mut Vec<(
278+
ty::OutlivesPredicate<ty::GenericArg<'tcx>, ty::Region<'tcx>>,
279+
ConstraintCategory<'tcx>,
280+
)>,
281+
) -> Ty<'tcx> {
282+
let result = CustomTypeOp::new(
283+
|ocx| {
284+
deeply_normalize(
285+
ocx.infcx.at(&ObligationCause::dummy_with_span(self.span), self.param_env),
286+
ty,
287+
)
288+
.map_err(|_| NoSolution)
289+
},
290+
"normalize type outlives obligation",
291+
)
292+
.fully_perform(self.infcx, self.span);
293+
294+
match result {
295+
Ok(TypeOpOutput { output: ty, constraints, .. }) => {
296+
if let Some(constraints) = constraints {
297+
assert!(
298+
constraints.member_constraints.is_empty(),
299+
"no member constraints expected from normalizing: {:#?}",
300+
constraints.member_constraints
301+
);
302+
next_outlives_predicates.extend(constraints.outlives.iter().copied());
303+
}
304+
ty
305+
}
306+
Err(_) => ty,
307+
}
308+
}
235309
}
236310

237311
impl<'a, 'b, 'tcx> TypeOutlivesDelegate<'tcx> for &'a mut ConstraintConversion<'b, 'tcx> {

Diff for: compiler/rustc_borrowck/src/type_check/free_region_relations.rs

+44-25
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ use rustc_infer::infer::region_constraints::GenericKind;
88
use rustc_infer::infer::InferCtxt;
99
use rustc_middle::mir::ConstraintCategory;
1010
use rustc_middle::traits::query::OutlivesBound;
11+
use rustc_middle::traits::ObligationCause;
1112
use rustc_middle::ty::{self, RegionVid, Ty, TypeVisitableExt};
12-
use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
13+
use rustc_span::{ErrorGuaranteed, DUMMY_SP};
14+
use rustc_trait_selection::solve::deeply_normalize;
15+
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt;
1316
use rustc_trait_selection::traits::query::type_op::{self, TypeOp};
1417
use std::rc::Rc;
1518
use type_op::TypeOpOutput;
@@ -52,15 +55,13 @@ pub(crate) struct CreateResult<'tcx> {
5255
pub(crate) fn create<'tcx>(
5356
infcx: &InferCtxt<'tcx>,
5457
param_env: ty::ParamEnv<'tcx>,
55-
known_type_outlives_obligations: &'tcx [ty::PolyTypeOutlivesPredicate<'tcx>],
5658
implicit_region_bound: ty::Region<'tcx>,
5759
universal_regions: &Rc<UniversalRegions<'tcx>>,
5860
constraints: &mut MirTypeckRegionConstraints<'tcx>,
5961
) -> CreateResult<'tcx> {
6062
UniversalRegionRelationsBuilder {
6163
infcx,
6264
param_env,
63-
known_type_outlives_obligations,
6465
implicit_region_bound,
6566
constraints,
6667
universal_regions: universal_regions.clone(),
@@ -178,7 +179,6 @@ impl UniversalRegionRelations<'_> {
178179
struct UniversalRegionRelationsBuilder<'this, 'tcx> {
179180
infcx: &'this InferCtxt<'tcx>,
180181
param_env: ty::ParamEnv<'tcx>,
181-
known_type_outlives_obligations: &'tcx [ty::PolyTypeOutlivesPredicate<'tcx>],
182182
universal_regions: Rc<UniversalRegions<'tcx>>,
183183
implicit_region_bound: ty::Region<'tcx>,
184184
constraints: &'this mut MirTypeckRegionConstraints<'tcx>,
@@ -222,6 +222,32 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
222222
self.relate_universal_regions(fr, fr_fn_body);
223223
}
224224

225+
// Normalize the assumptions we use to borrowck the program.
226+
let mut constraints = vec![];
227+
let mut known_type_outlives_obligations = vec![];
228+
for bound in param_env.caller_bounds() {
229+
let Some(mut outlives) = bound.as_type_outlives_clause() else { continue };
230+
231+
// In the new solver, normalize the type-outlives obligation assumptions.
232+
if self.infcx.next_trait_solver() {
233+
match deeply_normalize(
234+
self.infcx.at(&ObligationCause::misc(span, defining_ty_def_id), self.param_env),
235+
outlives,
236+
) {
237+
Ok(normalized_outlives) => {
238+
outlives = normalized_outlives;
239+
}
240+
Err(e) => {
241+
self.infcx.err_ctxt().report_fulfillment_errors(e);
242+
}
243+
}
244+
}
245+
246+
known_type_outlives_obligations.push(outlives);
247+
}
248+
let known_type_outlives_obligations =
249+
self.infcx.tcx.arena.alloc_slice(&known_type_outlives_obligations);
250+
225251
let unnormalized_input_output_tys = self
226252
.universal_regions
227253
.unnormalized_input_tys
@@ -239,7 +265,6 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
239265
// the `relations` is built.
240266
let mut normalized_inputs_and_output =
241267
Vec::with_capacity(self.universal_regions.unnormalized_input_tys.len() + 1);
242-
let mut constraints = vec![];
243268
for ty in unnormalized_input_output_tys {
244269
debug!("build: input_or_output={:?}", ty);
245270
// We add implied bounds from both the unnormalized and normalized ty.
@@ -304,7 +329,19 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
304329
}
305330

306331
for c in constraints {
307-
self.push_region_constraints(c, span);
332+
constraint_conversion::ConstraintConversion::new(
333+
self.infcx,
334+
&self.universal_regions,
335+
&self.region_bound_pairs,
336+
self.implicit_region_bound,
337+
param_env,
338+
known_type_outlives_obligations,
339+
Locations::All(span),
340+
span,
341+
ConstraintCategory::Internal,
342+
self.constraints,
343+
)
344+
.convert_all(c);
308345
}
309346

310347
CreateResult {
@@ -313,30 +350,12 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
313350
outlives: self.outlives.freeze(),
314351
inverse_outlives: self.inverse_outlives.freeze(),
315352
}),
316-
known_type_outlives_obligations: self.known_type_outlives_obligations,
353+
known_type_outlives_obligations,
317354
region_bound_pairs: self.region_bound_pairs,
318355
normalized_inputs_and_output,
319356
}
320357
}
321358

322-
#[instrument(skip(self, data), level = "debug")]
323-
fn push_region_constraints(&mut self, data: &QueryRegionConstraints<'tcx>, span: Span) {
324-
debug!("constraints generated: {:#?}", data);
325-
326-
constraint_conversion::ConstraintConversion::new(
327-
self.infcx,
328-
&self.universal_regions,
329-
&self.region_bound_pairs,
330-
self.implicit_region_bound,
331-
self.known_type_outlives_obligations,
332-
Locations::All(span),
333-
span,
334-
ConstraintCategory::Internal,
335-
self.constraints,
336-
)
337-
.convert_all(data);
338-
}
339-
340359
/// Update the type of a single local, which should represent
341360
/// either the return type of the MIR or one of its arguments. At
342361
/// the same time, compute and add any implied bounds that come

Diff for: compiler/rustc_borrowck/src/type_check/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,6 @@ pub(crate) fn type_check<'mir, 'tcx>(
156156
} = free_region_relations::create(
157157
infcx,
158158
param_env,
159-
// FIXME(-Znext-solver): These are unnormalized. Normalize them.
160-
infcx.tcx.arena.alloc_from_iter(
161-
param_env.caller_bounds().iter().filter_map(|clause| clause.as_type_outlives_clause()),
162-
),
163159
implicit_region_bound,
164160
universal_regions,
165161
&mut constraints,
@@ -1144,6 +1140,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
11441140
self.borrowck_context.universal_regions,
11451141
self.region_bound_pairs,
11461142
self.implicit_region_bound,
1143+
self.param_env,
11471144
self.known_type_outlives_obligations,
11481145
locations,
11491146
locations.span(self.body),
@@ -2759,6 +2756,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
27592756
self.borrowck_context.universal_regions,
27602757
self.region_bound_pairs,
27612758
self.implicit_region_bound,
2759+
self.param_env,
27622760
self.known_type_outlives_obligations,
27632761
locations,
27642762
DUMMY_SP, // irrelevant; will be overridden.

Diff for: compiler/rustc_codegen_gcc/src/attributes.rs

-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ pub fn from_fn_attrs<'gcc, 'tcx>(
6262
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::COLD) {
6363
func.add_attribute(FnAttribute::Cold);
6464
}
65-
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::FFI_RETURNS_TWICE) {
66-
func.add_attribute(FnAttribute::ReturnsTwice);
67-
}
6865
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::FFI_PURE) {
6966
func.add_attribute(FnAttribute::Pure);
7067
}

Diff for: compiler/rustc_codegen_llvm/src/attributes.rs

-3
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,6 @@ pub fn from_fn_attrs<'ll, 'tcx>(
356356
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::COLD) {
357357
to_add.push(AttributeKind::Cold.create_attr(cx.llcx));
358358
}
359-
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::FFI_RETURNS_TWICE) {
360-
to_add.push(AttributeKind::ReturnsTwice.create_attr(cx.llcx));
361-
}
362359
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::FFI_PURE) {
363360
to_add.push(MemoryEffects::ReadOnly.create_attr(cx.llcx));
364361
}

Diff for: compiler/rustc_codegen_llvm/src/llvm/ffi.rs

-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ pub enum AttributeKind {
184184
SanitizeMemory = 22,
185185
NonLazyBind = 23,
186186
OptimizeNone = 24,
187-
ReturnsTwice = 25,
188187
ReadNone = 26,
189188
SanitizeHWAddress = 28,
190189
WillReturn = 29,

Diff for: compiler/rustc_codegen_ssa/src/codegen_attrs.rs

-3
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
103103
match name {
104104
sym::cold => codegen_fn_attrs.flags |= CodegenFnAttrFlags::COLD,
105105
sym::rustc_allocator => codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR,
106-
sym::ffi_returns_twice => {
107-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_RETURNS_TWICE
108-
}
109106
sym::ffi_pure => codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_PURE,
110107
sym::ffi_const => codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_CONST,
111108
sym::rustc_nounwind => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NEVER_UNWIND,

0 commit comments

Comments
 (0)