Skip to content

Commit 8478acf

Browse files
committed
sort the existential bounds list in tydecode
The sort key is a (DefId, Name), which is *not* stable between runs, so we must re-sort when loading. Fixes #24063 Fixes #25467 Fixes #27222 Fixes #28377
1 parent cfd76b3 commit 8478acf

File tree

5 files changed

+59
-11
lines changed

5 files changed

+59
-11
lines changed

src/librustc/metadata/tydecode.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -680,9 +680,8 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
680680
}
681681
}
682682

683-
return ty::ExistentialBounds { region_bound: region_bound,
684-
builtin_bounds: builtin_bounds,
685-
projection_bounds: projection_bounds };
683+
ty::ExistentialBounds::new(
684+
region_bound, builtin_bounds, projection_bounds)
686685
}
687686

688687
fn parse_builtin_bounds(&mut self) -> ty::BuiltinBounds {

src/librustc/middle/ty.rs

+15
Original file line numberDiff line numberDiff line change
@@ -2137,6 +2137,21 @@ pub struct ExistentialBounds<'tcx> {
21372137
pub projection_bounds: Vec<PolyProjectionPredicate<'tcx>>,
21382138
}
21392139

2140+
impl<'tcx> ExistentialBounds<'tcx> {
2141+
pub fn new(region_bound: ty::Region,
2142+
builtin_bounds: BuiltinBounds,
2143+
projection_bounds: Vec<PolyProjectionPredicate<'tcx>>)
2144+
-> Self {
2145+
let mut projection_bounds = projection_bounds;
2146+
ty::sort_bounds_list(&mut projection_bounds);
2147+
ExistentialBounds {
2148+
region_bound: region_bound,
2149+
builtin_bounds: builtin_bounds,
2150+
projection_bounds: projection_bounds
2151+
}
2152+
}
2153+
}
2154+
21402155
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
21412156
pub struct BuiltinBounds(EnumSet<BuiltinBound>);
21422157

src/librustc_typeck/astconv.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -2019,7 +2019,7 @@ pub fn conv_existential_bounds_from_partitioned_bounds<'tcx>(
20192019
rscope: &RegionScope,
20202020
span: Span,
20212021
principal_trait_ref: ty::PolyTraitRef<'tcx>,
2022-
mut projection_bounds: Vec<ty::PolyProjectionPredicate<'tcx>>, // Empty for boxed closures
2022+
projection_bounds: Vec<ty::PolyProjectionPredicate<'tcx>>, // Empty for boxed closures
20232023
partitioned_bounds: PartitionedBounds)
20242024
-> ty::ExistentialBounds<'tcx>
20252025
{
@@ -2058,13 +2058,7 @@ pub fn conv_existential_bounds_from_partitioned_bounds<'tcx>(
20582058

20592059
debug!("region_bound: {:?}", region_bound);
20602060

2061-
ty::sort_bounds_list(&mut projection_bounds);
2062-
2063-
ty::ExistentialBounds {
2064-
region_bound: region_bound,
2065-
builtin_bounds: builtin_bounds,
2066-
projection_bounds: projection_bounds,
2067-
}
2061+
ty::ExistentialBounds::new(region_bound, builtin_bounds, projection_bounds)
20682062
}
20692063

20702064
/// Given the bounds on an object, determines what single region bound

src/test/auxiliary/issue-25467.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2015 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+
#![crate_type="lib"]
12+
13+
pub trait Trait {
14+
// the issue is sensitive to interning order - so use names
15+
// unlikely to appear in libstd.
16+
type Issue25467FooT;
17+
type Issue25467BarT;
18+
}
19+
20+
pub type Object = Option<Box<Trait<Issue25467FooT=(),Issue25467BarT=()>>>;

src/test/run-pass/issue-25467.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2014 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+
// aux-build:issue-25467.rs
12+
13+
pub type Issue25467BarT = ();
14+
pub type Issue25467FooT = ();
15+
16+
extern crate issue_25467 as aux;
17+
18+
fn main() {
19+
let o: aux::Object = None;
20+
}

0 commit comments

Comments
 (0)