Skip to content

Commit e9a16fd

Browse files
committed
Auto merge of rust-lang#121054 - matthiaskrgr:rollup-k3fuez5, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#118882 (Check normalized call signature for WF in mir typeck) - rust-lang#120999 (rustdoc: replace `clean::InstantiationParam` with `clean::GenericArg`) - rust-lang#121002 (remove unnecessary calls to `commit_if_ok`) - rust-lang#121005 (Remove jsha from the rustdoc review rotation) - rust-lang#121043 (add lcnr to the compiler-team assignment group) - rust-lang#121045 (Fix two UI tests with incorrect directive / invalid revision) - rust-lang#121046 (Fix incorrect use of `compile_fail`) - rust-lang#121047 (Do not assemble candidates for default impls) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a84bb95 + d879ba1 commit e9a16fd

26 files changed

+281
-209
lines changed

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

+20-4
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
14321432
return;
14331433
}
14341434
};
1435-
let (sig, map) = tcx.instantiate_bound_regions(sig, |br| {
1435+
let (unnormalized_sig, map) = tcx.instantiate_bound_regions(sig, |br| {
14361436
use crate::renumber::RegionCtxt;
14371437

14381438
let region_ctxt_fn = || {
@@ -1454,7 +1454,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
14541454
region_ctxt_fn,
14551455
)
14561456
});
1457-
debug!(?sig);
1457+
debug!(?unnormalized_sig);
14581458
// IMPORTANT: We have to prove well formed for the function signature before
14591459
// we normalize it, as otherwise types like `<&'a &'b () as Trait>::Assoc`
14601460
// get normalized away, causing us to ignore the `'b: 'a` bound used by the function.
@@ -1464,15 +1464,31 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
14641464
//
14651465
// See #91068 for an example.
14661466
self.prove_predicates(
1467-
sig.inputs_and_output.iter().map(|ty| {
1467+
unnormalized_sig.inputs_and_output.iter().map(|ty| {
14681468
ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(
14691469
ty.into(),
14701470
)))
14711471
}),
14721472
term_location.to_locations(),
14731473
ConstraintCategory::Boring,
14741474
);
1475-
let sig = self.normalize(sig, term_location);
1475+
1476+
let sig = self.normalize(unnormalized_sig, term_location);
1477+
// HACK(#114936): `WF(sig)` does not imply `WF(normalized(sig))`
1478+
// with built-in `Fn` implementations, since the impl may not be
1479+
// well-formed itself.
1480+
if sig != unnormalized_sig {
1481+
self.prove_predicates(
1482+
sig.inputs_and_output.iter().map(|ty| {
1483+
ty::Binder::dummy(ty::PredicateKind::Clause(
1484+
ty::ClauseKind::WellFormed(ty.into()),
1485+
))
1486+
}),
1487+
term_location.to_locations(),
1488+
ConstraintCategory::Boring,
1489+
);
1490+
}
1491+
14761492
self.check_call_dest(body, term, &sig, *destination, *target, term_location);
14771493

14781494
// The ordinary liveness rules will ensure that all

Diff for: compiler/rustc_infer/src/infer/at.rs

+20-28
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,11 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
285285
T: Relate<'tcx>,
286286
{
287287
let Trace { at, trace, a_is_expected } = self;
288-
at.infcx.commit_if_ok(|_| {
289-
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
290-
fields
291-
.sub(a_is_expected)
292-
.relate(a, b)
293-
.map(move |_| InferOk { value: (), obligations: fields.obligations })
294-
})
288+
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
289+
fields
290+
.sub(a_is_expected)
291+
.relate(a, b)
292+
.map(move |_| InferOk { value: (), obligations: fields.obligations })
295293
}
296294

297295
/// Makes `a == b`; the expectation is set by the call to
@@ -302,13 +300,11 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
302300
T: Relate<'tcx>,
303301
{
304302
let Trace { at, trace, a_is_expected } = self;
305-
at.infcx.commit_if_ok(|_| {
306-
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
307-
fields
308-
.equate(a_is_expected)
309-
.relate(a, b)
310-
.map(move |_| InferOk { value: (), obligations: fields.obligations })
311-
})
303+
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
304+
fields
305+
.equate(a_is_expected)
306+
.relate(a, b)
307+
.map(move |_| InferOk { value: (), obligations: fields.obligations })
312308
}
313309

314310
#[instrument(skip(self), level = "debug")]
@@ -317,13 +313,11 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
317313
T: Relate<'tcx>,
318314
{
319315
let Trace { at, trace, a_is_expected } = self;
320-
at.infcx.commit_if_ok(|_| {
321-
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
322-
fields
323-
.lub(a_is_expected)
324-
.relate(a, b)
325-
.map(move |t| InferOk { value: t, obligations: fields.obligations })
326-
})
316+
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
317+
fields
318+
.lub(a_is_expected)
319+
.relate(a, b)
320+
.map(move |t| InferOk { value: t, obligations: fields.obligations })
327321
}
328322

329323
#[instrument(skip(self), level = "debug")]
@@ -332,13 +326,11 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
332326
T: Relate<'tcx>,
333327
{
334328
let Trace { at, trace, a_is_expected } = self;
335-
at.infcx.commit_if_ok(|_| {
336-
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
337-
fields
338-
.glb(a_is_expected)
339-
.relate(a, b)
340-
.map(move |t| InferOk { value: t, obligations: fields.obligations })
341-
})
329+
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
330+
fields
331+
.glb(a_is_expected)
332+
.relate(a, b)
333+
.map(move |t| InferOk { value: t, obligations: fields.obligations })
342334
}
343335
}
344336

Diff for: compiler/rustc_infer/src/infer/canonical/query_response.rs

+32-34
Original file line numberDiff line numberDiff line change
@@ -620,42 +620,40 @@ impl<'tcx> InferCtxt<'tcx> {
620620
variables1: &OriginalQueryValues<'tcx>,
621621
variables2: impl Fn(BoundVar) -> GenericArg<'tcx>,
622622
) -> InferResult<'tcx, ()> {
623-
self.commit_if_ok(|_| {
624-
let mut obligations = vec![];
625-
for (index, value1) in variables1.var_values.iter().enumerate() {
626-
let value2 = variables2(BoundVar::new(index));
627-
628-
match (value1.unpack(), value2.unpack()) {
629-
(GenericArgKind::Type(v1), GenericArgKind::Type(v2)) => {
630-
obligations.extend(
631-
self.at(cause, param_env)
632-
.eq(DefineOpaqueTypes::Yes, v1, v2)?
633-
.into_obligations(),
634-
);
635-
}
636-
(GenericArgKind::Lifetime(re1), GenericArgKind::Lifetime(re2))
637-
if re1.is_erased() && re2.is_erased() =>
638-
{
639-
// no action needed
640-
}
641-
(GenericArgKind::Lifetime(v1), GenericArgKind::Lifetime(v2)) => {
642-
obligations.extend(
643-
self.at(cause, param_env)
644-
.eq(DefineOpaqueTypes::Yes, v1, v2)?
645-
.into_obligations(),
646-
);
647-
}
648-
(GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => {
649-
let ok = self.at(cause, param_env).eq(DefineOpaqueTypes::Yes, v1, v2)?;
650-
obligations.extend(ok.into_obligations());
651-
}
652-
_ => {
653-
bug!("kind mismatch, cannot unify {:?} and {:?}", value1, value2,);
654-
}
623+
let mut obligations = vec![];
624+
for (index, value1) in variables1.var_values.iter().enumerate() {
625+
let value2 = variables2(BoundVar::new(index));
626+
627+
match (value1.unpack(), value2.unpack()) {
628+
(GenericArgKind::Type(v1), GenericArgKind::Type(v2)) => {
629+
obligations.extend(
630+
self.at(cause, param_env)
631+
.eq(DefineOpaqueTypes::Yes, v1, v2)?
632+
.into_obligations(),
633+
);
634+
}
635+
(GenericArgKind::Lifetime(re1), GenericArgKind::Lifetime(re2))
636+
if re1.is_erased() && re2.is_erased() =>
637+
{
638+
// no action needed
639+
}
640+
(GenericArgKind::Lifetime(v1), GenericArgKind::Lifetime(v2)) => {
641+
obligations.extend(
642+
self.at(cause, param_env)
643+
.eq(DefineOpaqueTypes::Yes, v1, v2)?
644+
.into_obligations(),
645+
);
646+
}
647+
(GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => {
648+
let ok = self.at(cause, param_env).eq(DefineOpaqueTypes::Yes, v1, v2)?;
649+
obligations.extend(ok.into_obligations());
650+
}
651+
_ => {
652+
bug!("kind mismatch, cannot unify {:?} and {:?}", value1, value2,);
655653
}
656654
}
657-
Ok(InferOk { value: (), obligations })
658-
})
655+
}
656+
Ok(InferOk { value: (), obligations })
659657
}
660658
}
661659

Diff for: compiler/rustc_trait_selection/src/solve/assembly/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,13 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
337337
let mut consider_impls_for_simplified_type = |simp| {
338338
if let Some(impls_for_type) = trait_impls.non_blanket_impls().get(&simp) {
339339
for &impl_def_id in impls_for_type {
340+
// For every `default impl`, there's always a non-default `impl`
341+
// that will *also* apply. There's no reason to register a candidate
342+
// for this impl, since it is *not* proof that the trait goal holds.
343+
if tcx.defaultness(impl_def_id).is_default() {
344+
return;
345+
}
346+
340347
match G::consider_impl_candidate(self, goal, impl_def_id) {
341348
Ok(candidate) => candidates.push(candidate),
342349
Err(NoSolution) => (),
@@ -440,6 +447,13 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
440447
let tcx = self.tcx();
441448
let trait_impls = tcx.trait_impls_of(goal.predicate.trait_def_id(tcx));
442449
for &impl_def_id in trait_impls.blanket_impls() {
450+
// For every `default impl`, there's always a non-default `impl`
451+
// that will *also* apply. There's no reason to register a candidate
452+
// for this impl, since it is *not* proof that the trait goal holds.
453+
if tcx.defaultness(impl_def_id).is_default() {
454+
return;
455+
}
456+
443457
match G::consider_impl_candidate(self, goal, impl_def_id) {
444458
Ok(candidate) => candidates.push(candidate),
445459
Err(NoSolution) => (),

Diff for: compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

+8
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
566566
{
567567
return;
568568
}
569+
570+
// For every `default impl`, there's always a non-default `impl`
571+
// that will *also* apply. There's no reason to register a candidate
572+
// for this impl, since it is *not* proof that the trait goal holds.
573+
if self.tcx().defaultness(impl_def_id).is_default() {
574+
return;
575+
}
576+
569577
if self.reject_fn_ptr_impls(
570578
impl_def_id,
571579
obligation,

Diff for: compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
192192
&mut obligations,
193193
);
194194

195-
obligations.extend(self.infcx.commit_if_ok(|_| {
195+
obligations.extend(
196196
self.infcx
197197
.at(&obligation.cause, obligation.param_env)
198198
.sup(DefineOpaqueTypes::No, placeholder_trait_predicate, candidate)
199199
.map(|InferOk { obligations, .. }| obligations)
200-
.map_err(|_| Unimplemented)
201-
})?);
200+
.map_err(|_| Unimplemented)?,
201+
);
202202

203203
// FIXME(compiler-errors): I don't think this is needed.
204204
if let ty::Alias(ty::Projection, alias_ty) = placeholder_self_ty.kind() {
@@ -532,13 +532,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
532532
&mut nested,
533533
);
534534

535-
nested.extend(self.infcx.commit_if_ok(|_| {
535+
nested.extend(
536536
self.infcx
537537
.at(&obligation.cause, obligation.param_env)
538538
.sup(DefineOpaqueTypes::No, obligation_trait_ref, upcast_trait_ref)
539539
.map(|InferOk { obligations, .. }| obligations)
540-
.map_err(|_| Unimplemented)
541-
})?);
540+
.map_err(|_| Unimplemented)?,
541+
);
542542

543543
// Check supertraits hold. This is so that their associated type bounds
544544
// will be checked in the code below.

Diff for: library/std/src/process.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ pub struct Child {
171171
/// The handle for writing to the child's standard input (stdin), if it
172172
/// has been captured. You might find it helpful to do
173173
///
174-
/// ```compile_fail,E0425
174+
/// ```ignore (incomplete)
175175
/// let stdin = child.stdin.take().unwrap();
176176
/// ```
177177
///
@@ -183,7 +183,7 @@ pub struct Child {
183183
/// The handle for reading from the child's standard output (stdout), if it
184184
/// has been captured. You might find it helpful to do
185185
///
186-
/// ```compile_fail,E0425
186+
/// ```ignore (incomplete)
187187
/// let stdout = child.stdout.take().unwrap();
188188
/// ```
189189
///
@@ -195,7 +195,7 @@ pub struct Child {
195195
/// The handle for reading from the child's standard error (stderr), if it
196196
/// has been captured. You might find it helpful to do
197197
///
198-
/// ```compile_fail,E0425
198+
/// ```ignore (incomplete)
199199
/// let stderr = child.stderr.take().unwrap();
200200
/// ```
201201
///

Diff for: src/librustdoc/clean/mod.rs

+13-39
Original file line numberDiff line numberDiff line change
@@ -254,16 +254,14 @@ fn clean_poly_trait_ref_with_bindings<'tcx>(
254254
}
255255

256256
fn clean_lifetime<'tcx>(lifetime: &hir::Lifetime, cx: &mut DocContext<'tcx>) -> Lifetime {
257-
let def = cx.tcx.named_bound_var(lifetime.hir_id);
258257
if let Some(
259-
rbv::ResolvedArg::EarlyBound(node_id)
260-
| rbv::ResolvedArg::LateBound(_, _, node_id)
261-
| rbv::ResolvedArg::Free(_, node_id),
262-
) = def
258+
rbv::ResolvedArg::EarlyBound(did)
259+
| rbv::ResolvedArg::LateBound(_, _, did)
260+
| rbv::ResolvedArg::Free(_, did),
261+
) = cx.tcx.named_bound_var(lifetime.hir_id)
262+
&& let Some(lt) = cx.args.get(&did).and_then(|arg| arg.as_lt())
263263
{
264-
if let Some(lt) = cx.args.get(&node_id).and_then(|p| p.as_lt()).cloned() {
265-
return lt;
266-
}
264+
return lt.clone();
267265
}
268266
Lifetime(lifetime.ident.name)
269267
}
@@ -1791,12 +1789,12 @@ fn maybe_expand_private_type_alias<'tcx>(
17911789
_ => None,
17921790
});
17931791
if let Some(lt) = lifetime {
1794-
let cleaned = if !lt.is_anonymous() {
1792+
let lt = if !lt.is_anonymous() {
17951793
clean_lifetime(lt, cx)
17961794
} else {
17971795
Lifetime::elided()
17981796
};
1799-
args.insert(param.def_id.to_def_id(), InstantiationParam::Lifetime(cleaned));
1797+
args.insert(param.def_id.to_def_id(), GenericArg::Lifetime(lt));
18001798
}
18011799
indices.lifetimes += 1;
18021800
}
@@ -1805,44 +1803,20 @@ fn maybe_expand_private_type_alias<'tcx>(
18051803
let type_ = generic_args.args.iter().find_map(|arg| match arg {
18061804
hir::GenericArg::Type(ty) => {
18071805
if indices.types == j {
1808-
return Some(ty);
1806+
return Some(*ty);
18091807
}
18101808
j += 1;
18111809
None
18121810
}
18131811
_ => None,
18141812
});
1815-
if let Some(ty) = type_ {
1816-
args.insert(
1817-
param.def_id.to_def_id(),
1818-
InstantiationParam::Type(clean_ty(ty, cx)),
1819-
);
1820-
} else if let Some(default) = *default {
1821-
args.insert(
1822-
param.def_id.to_def_id(),
1823-
InstantiationParam::Type(clean_ty(default, cx)),
1824-
);
1813+
if let Some(ty) = type_.or(*default) {
1814+
args.insert(param.def_id.to_def_id(), GenericArg::Type(clean_ty(ty, cx)));
18251815
}
18261816
indices.types += 1;
18271817
}
1828-
hir::GenericParamKind::Const { .. } => {
1829-
let mut j = 0;
1830-
let const_ = generic_args.args.iter().find_map(|arg| match arg {
1831-
hir::GenericArg::Const(ct) => {
1832-
if indices.consts == j {
1833-
return Some(ct);
1834-
}
1835-
j += 1;
1836-
None
1837-
}
1838-
_ => None,
1839-
});
1840-
if let Some(_) = const_ {
1841-
args.insert(param.def_id.to_def_id(), InstantiationParam::Constant);
1842-
}
1843-
// FIXME(const_generics_defaults)
1844-
indices.consts += 1;
1845-
}
1818+
// FIXME(#82852): Instantiate const parameters.
1819+
hir::GenericParamKind::Const { .. } => {}
18461820
}
18471821
}
18481822

0 commit comments

Comments
 (0)