Skip to content

Commit 9743c66

Browse files
committed
Auto merge of #33710 - Manishearth:rollup, r=Manishearth
Rollup of 5 pull requests - Successful merges: #33656, #33666, #33673, #33675, #33695 - Failed merges:
2 parents 310d899 + 07194a0 commit 9743c66

File tree

7 files changed

+55
-24
lines changed

7 files changed

+55
-24
lines changed

src/librustc/traits/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub use self::select::{EvaluationCache, SelectionContext, SelectionCache};
3838
pub use self::select::{MethodMatchResult, MethodMatched, MethodAmbiguous, MethodDidNotMatch};
3939
pub use self::select::{MethodMatchedData}; // intentionally don't export variants
4040
pub use self::specialize::{OverlapError, specialization_graph, specializes, translate_substs};
41+
pub use self::specialize::{SpecializesCache};
4142
pub use self::util::elaborate_predicates;
4243
pub use self::util::supertraits;
4344
pub use self::util::Supertraits;

src/librustc/traits/specialize/mod.rs

+30-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use super::{SelectionContext, FulfillmentContext};
2121
use super::util::{fresh_type_vars_for_impl, impl_trait_ref_and_oblig};
2222

23+
use rustc_data_structures::fnv::FnvHashMap;
2324
use hir::def_id::DefId;
2425
use infer::{InferCtxt, TypeOrigin};
2526
use middle::region;
@@ -111,6 +112,10 @@ pub fn translate_substs<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
111112
pub fn specializes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
112113
impl1_def_id: DefId,
113114
impl2_def_id: DefId) -> bool {
115+
if let Some(r) = tcx.specializes_cache.borrow().check(impl1_def_id, impl2_def_id) {
116+
return r;
117+
}
118+
114119
// The feature gate should prevent introducing new specializations, but not
115120
// taking advantage of upstream ones.
116121
if !tcx.sess.features.borrow().specialization &&
@@ -146,7 +151,7 @@ pub fn specializes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
146151
.unwrap()
147152
.subst(tcx, &penv.free_substs);
148153

149-
tcx.normalizing_infer_ctxt(ProjectionMode::Topmost).enter(|mut infcx| {
154+
let result = tcx.normalizing_infer_ctxt(ProjectionMode::Topmost).enter(|mut infcx| {
150155
// Normalize the trait reference, adding any obligations
151156
// that arise into the impl1 assumptions.
152157
let Normalized { value: impl1_trait_ref, obligations: normalization_obligations } = {
@@ -167,7 +172,10 @@ pub fn specializes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
167172

168173
// Attempt to prove that impl2 applies, given all of the above.
169174
fulfill_implication(&infcx, impl1_trait_ref, impl2_def_id).is_ok()
170-
})
175+
});
176+
177+
tcx.specializes_cache.borrow_mut().insert(impl1_def_id, impl2_def_id, result);
178+
result
171179
}
172180

173181
/// Attempt to fulfill all obligations of `target_impl` after unification with
@@ -225,3 +233,23 @@ fn fulfill_implication<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
225233
}
226234
})
227235
}
236+
237+
pub struct SpecializesCache {
238+
map: FnvHashMap<(DefId, DefId), bool>
239+
}
240+
241+
impl SpecializesCache {
242+
pub fn new() -> Self {
243+
SpecializesCache {
244+
map: FnvHashMap()
245+
}
246+
}
247+
248+
pub fn check(&self, a: DefId, b: DefId) -> Option<bool> {
249+
self.map.get(&(a, b)).cloned()
250+
}
251+
252+
pub fn insert(&mut self, a: DefId, b: DefId, result: bool) {
253+
self.map.insert((a, b), result);
254+
}
255+
}

src/librustc/ty/context.rs

+3
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ impl<'a, 'gcx, 'tcx> Deref for TyCtxt<'a, 'gcx, 'tcx> {
291291
pub struct GlobalCtxt<'tcx> {
292292
global_interners: CtxtInterners<'tcx>,
293293

294+
pub specializes_cache: RefCell<traits::SpecializesCache>,
295+
294296
pub dep_graph: DepGraph,
295297

296298
/// Common types, pre-interned for your convenience.
@@ -637,6 +639,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
637639
let dep_graph = map.dep_graph.clone();
638640
let fulfilled_predicates = traits::GlobalFulfilledPredicates::new(dep_graph.clone());
639641
tls::enter_global(GlobalCtxt {
642+
specializes_cache: RefCell::new(traits::SpecializesCache::new()),
640643
global_interners: interners,
641644
dep_graph: dep_graph.clone(),
642645
types: common_types,

src/librustc_borrowck/diagnostics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ fn you_know_nothing(jon_snow: &mut i32) {
391391
// but it is already borrowed
392392
};
393393
}
394+
```
394395
395396
In here, `jon_snow` is already borrowed by the `nights_watch` closure, so it
396397
cannot be borrowed by the `starks` closure at the same time. To fix this issue,

src/librustdoc/clean/mod.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,17 @@ impl Clean<Lifetime> for hir::Lifetime {
795795

796796
impl Clean<Lifetime> for hir::LifetimeDef {
797797
fn clean(&self, _: &DocContext) -> Lifetime {
798-
Lifetime(self.lifetime.name.to_string())
798+
if self.bounds.len() > 0 {
799+
let mut s = format!("{}: {}",
800+
self.lifetime.name.to_string(),
801+
self.bounds[0].name.to_string());
802+
for bound in self.bounds.iter().skip(1) {
803+
s.push_str(&format!(" + {}", bound.name.to_string()));
804+
}
805+
Lifetime(s)
806+
} else {
807+
Lifetime(self.lifetime.name.to_string())
808+
}
799809
}
800810
}
801811

src/librustdoc/html/static/rustdoc.css

+4
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,10 @@ span.since {
640640
margin-right: 5px;
641641
}
642642

643+
:target > code {
644+
background: #FDFFD3;
645+
}
646+
643647
/* Media Queries */
644648

645649
@media (max-width: 700px) {

src/libsyntax_ext/format.rs

+5-21
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ struct Context<'a, 'b:'a> {
6767

6868
name_positions: HashMap<String, usize>,
6969

70-
/// Updated as arguments are consumed or methods are entered
71-
nest_level: usize,
70+
/// Updated as arguments are consumed
7271
next_arg: usize,
7372
}
7473

@@ -164,9 +163,7 @@ impl<'a, 'b> Context<'a, 'b> {
164163
let pos = match arg.position {
165164
parse::ArgumentNext => {
166165
let i = self.next_arg;
167-
if self.check_positional_ok() {
168-
self.next_arg += 1;
169-
}
166+
self.next_arg += 1;
170167
Exact(i)
171168
}
172169
parse::ArgumentIs(i) => Exact(i),
@@ -189,25 +186,13 @@ impl<'a, 'b> Context<'a, 'b> {
189186
self.verify_arg_type(Named(s.to_string()), Unsigned);
190187
}
191188
parse::CountIsNextParam => {
192-
if self.check_positional_ok() {
193-
let next_arg = self.next_arg;
194-
self.verify_arg_type(Exact(next_arg), Unsigned);
195-
self.next_arg += 1;
196-
}
189+
let next_arg = self.next_arg;
190+
self.verify_arg_type(Exact(next_arg), Unsigned);
191+
self.next_arg += 1;
197192
}
198193
}
199194
}
200195

201-
fn check_positional_ok(&mut self) -> bool {
202-
if self.nest_level != 0 {
203-
self.ecx.span_err(self.fmtsp, "cannot use implicit positional \
204-
arguments nested inside methods");
205-
false
206-
} else {
207-
true
208-
}
209-
}
210-
211196
fn describe_num_args(&self) -> String {
212197
match self.args.len() {
213198
0 => "no arguments given".to_string(),
@@ -655,7 +640,6 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span,
655640
name_positions: HashMap::new(),
656641
name_types: HashMap::new(),
657642
name_ordering: name_ordering,
658-
nest_level: 0,
659643
next_arg: 0,
660644
literal: String::new(),
661645
pieces: Vec::new(),

0 commit comments

Comments
 (0)