Skip to content

Commit 88f214c

Browse files
authored
Rollup merge of rust-lang#55453 - Aaron1011:fix/rustdoc-lifetime, r=pnkfelix
Choose predicates without inference variables over those with them Fixes rust-lang#54705 When constructing synthetic auto trait impls, we may come across multiple predicates involving the same type, trait, and substitutions. Since we can only display one of these, we pick the one with the 'most strict' lifetime paramters. This ensures that the impl we render the user is actually valid (that is, a struct matching that impl will actually implement the auto trait in question). This commit exapnds the definition of 'more strict' to take into account inference variables. We always choose a predicate without inference variables over a predicate with inference variables.
2 parents 0156dd2 + 20aa751 commit 88f214c

File tree

2 files changed

+73
-9
lines changed

2 files changed

+73
-9
lines changed

src/librustc/traits/auto_trait.rs

+33-9
Original file line numberDiff line numberDiff line change
@@ -447,27 +447,51 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
447447
ty::RegionKind::ReLateBound(_, _),
448448
) => {}
449449

450-
(ty::RegionKind::ReLateBound(_, _), _) => {
450+
(ty::RegionKind::ReLateBound(_, _), _) |
451+
(_, ty::RegionKind::ReVar(_)) => {
452+
// One of these is true:
451453
// The new predicate has a HRTB in a spot where the old
452454
// predicate does not (if they both had a HRTB, the previous
453-
// match arm would have executed).
455+
// match arm would have executed). A HRBT is a 'stricter'
456+
// bound than anything else, so we want to keep the newer
457+
// predicate (with the HRBT) in place of the old predicate.
454458
//
455-
// The means we want to remove the older predicate from
456-
// user_computed_preds, since having both it and the new
459+
// OR
460+
//
461+
// The old predicate has a region variable where the new
462+
// predicate has some other kind of region. An region
463+
// variable isn't something we can actually display to a user,
464+
// so we choose ther new predicate (which doesn't have a region
465+
// varaible).
466+
//
467+
// In both cases, we want to remove the old predicate,
468+
// from user_computed_preds, and replace it with the new
469+
// one. Having both the old and the new
457470
// predicate in a ParamEnv would confuse SelectionContext
471+
//
458472
// We're currently in the predicate passed to 'retain',
459473
// so we return 'false' to remove the old predicate from
460474
// user_computed_preds
461475
return false;
462476
}
463-
(_, ty::RegionKind::ReLateBound(_, _)) => {
464-
// This is the opposite situation as the previous arm - the
465-
// old predicate has a HRTB lifetime in a place where the
466-
// new predicate does not. We want to leave the old
477+
(_, ty::RegionKind::ReLateBound(_, _)) |
478+
(ty::RegionKind::ReVar(_), _) => {
479+
// This is the opposite situation as the previous arm.
480+
// One of these is true:
481+
//
482+
// The old predicate has a HRTB lifetime in a place where the
483+
// new predicate does not.
484+
//
485+
// OR
486+
//
487+
// The new predicate has a region variable where the old
488+
// predicate has some other type of region.
489+
//
490+
// We want to leave the old
467491
// predicate in user_computed_preds, and skip adding
468492
// new_pred to user_computed_params.
469493
should_add_new = false
470-
}
494+
},
471495
_ => {}
472496
}
473497
}

src/test/rustdoc/issue-54705.rs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
12+
pub trait ScopeHandle<'scope> {}
13+
14+
15+
16+
// @has issue_54705/struct.ScopeFutureContents.html
17+
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//*/code' "impl<'scope, S> \
18+
// Send for ScopeFutureContents<'scope, S> where S: Sync"
19+
//
20+
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//*/code' "impl<'scope, S> \
21+
// Sync for ScopeFutureContents<'scope, S> where S: Sync"
22+
pub struct ScopeFutureContents<'scope, S>
23+
where S: ScopeHandle<'scope>,
24+
{
25+
dummy: &'scope S,
26+
this: Box<ScopeFuture<'scope, S>>,
27+
}
28+
29+
struct ScopeFuture<'scope, S>
30+
where S: ScopeHandle<'scope>,
31+
{
32+
contents: ScopeFutureContents<'scope, S>,
33+
}
34+
35+
unsafe impl<'scope, S> Send for ScopeFuture<'scope, S>
36+
where S: ScopeHandle<'scope>,
37+
{}
38+
unsafe impl<'scope, S> Sync for ScopeFuture<'scope, S>
39+
where S: ScopeHandle<'scope>,
40+
{}

0 commit comments

Comments
 (0)