Skip to content

Commit 7846dbe

Browse files
committed
Auto merge of #40826 - frewsxcv:rollup, r=frewsxcv
Rollup of 7 pull requests - Successful merges: #40642, #40734, #40740, #40771, #40807, #40820, #40821 - Failed merges:
2 parents bcfd5c4 + dc52625 commit 7846dbe

File tree

26 files changed

+240
-146
lines changed

26 files changed

+240
-146
lines changed

src/doc/unstable-book/src/inclusive-range-syntax.md

+10
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,15 @@ The tracking issue for this feature is: [#28237]
66

77
------------------------
88

9+
To get a range that goes from 0 to 10 and includes the value 10, you
10+
can write `0...10`:
911

12+
```rust
13+
#![feature(inclusive_range_syntax)]
1014

15+
fn main() {
16+
for i in 0...10 {
17+
println!("{}", i);
18+
}
19+
}
20+
```

src/libcore/num/dec2flt/algorithm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ pub fn fast_path<T: RawFloat>(integral: &[u8], fractional: &[u8], e: i64) -> Opt
141141
///
142142
/// It rounds ``f`` to a float with 64 bit significand and multiplies it by the best approximation
143143
/// of `10^e` (in the same floating point format). This is often enough to get the correct result.
144-
/// However, when the result is close to halfway between two adjecent (ordinary) floats, the
144+
/// However, when the result is close to halfway between two adjacent (ordinary) floats, the
145145
/// compound rounding error from multiplying two approximation means the result may be off by a
146146
/// few bits. When this happens, the iterative Algorithm R fixes things up.
147147
///
@@ -392,7 +392,7 @@ fn underflow<T: RawFloat>(x: Big, v: Big, rem: Big) -> T {
392392
//
393393
// Therefore, when the rounded-off bits are != 0.5 ULP, they decide the rounding
394394
// on their own. When they are equal and the remainder is non-zero, the value still
395-
// needs to be rounded up. Only when the rounded off bits are 1/2 and the remainer
395+
// needs to be rounded up. Only when the rounded off bits are 1/2 and the remainder
396396
// is zero, we have a half-to-even situation.
397397
let bits = x.bit_length();
398398
let lsb = bits - T::sig_bits() as usize;

src/libcore/slice/sort.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ fn partial_insertion_sort<T, F>(v: &mut [T], is_less: &mut F) -> bool
152152
fn insertion_sort<T, F>(v: &mut [T], is_less: &mut F)
153153
where F: FnMut(&T, &T) -> bool
154154
{
155-
for i in 2..v.len()+1 {
156-
shift_tail(&mut v[..i], is_less);
155+
for i in 1..v.len() {
156+
shift_tail(&mut v[..i+1], is_less);
157157
}
158158
}
159159

src/librustc/dep_graph/dep_node.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use hir::def_id::CrateNum;
1112
use std::fmt::Debug;
1213
use std::sync::Arc;
1314

@@ -81,7 +82,7 @@ pub enum DepNode<D: Clone + Debug> {
8182
TypeckItemType(D),
8283
UnusedTraitCheck,
8384
CheckConst(D),
84-
Privacy,
85+
PrivacyAccessLevels(CrateNum),
8586
IntrinsicCheck(D),
8687
MatchCheck(D),
8788

@@ -230,7 +231,7 @@ impl<D: Clone + Debug> DepNode<D> {
230231
CheckEntryFn => Some(CheckEntryFn),
231232
Variance => Some(Variance),
232233
UnusedTraitCheck => Some(UnusedTraitCheck),
233-
Privacy => Some(Privacy),
234+
PrivacyAccessLevels(k) => Some(PrivacyAccessLevels(k)),
234235
Reachability => Some(Reachability),
235236
DeadCheck => Some(DeadCheck),
236237
LateLintCheck => Some(LateLintCheck),

src/librustc/dep_graph/edges.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,15 @@ impl<D: Clone + Debug + Eq + Hash> DepGraphEdges<D> {
101101
}
102102

103103
/// Indicates that the current task `C` reads `v` by adding an
104-
/// edge from `v` to `C`. If there is no current task, panics. If
105-
/// you want to suppress this edge, use `ignore`.
104+
/// edge from `v` to `C`. If there is no current task, has no
105+
/// effect. Note that *reading* from tracked state is harmless if
106+
/// you are not in a task; what is bad is *writing* to tracked
107+
/// state (and leaking data that you read into a tracked task).
106108
pub fn read(&mut self, v: DepNode<D>) {
107-
let source = self.make_node(v);
108-
self.add_edge_from_current_node(|current| (source, current))
109+
if self.current_node().is_some() {
110+
let source = self.make_node(v);
111+
self.add_edge_from_current_node(|current| (source, current))
112+
}
109113
}
110114

111115
/// Indicates that the current task `C` writes `v` by adding an

src/librustc/dep_graph/shadow.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ impl ShadowGraph {
8080

8181
let mut stack = self.stack.borrow_mut();
8282
match *message {
83-
DepMessage::Read(ref n) => self.check_edge(Some(Some(n)), top(&stack)),
83+
// It is ok to READ shared state outside of a
84+
// task. That can't do any harm (at least, the only
85+
// way it can do harm is by leaking that data into a
86+
// query or task, which would be a problem
87+
// anyway). What would be bad is WRITING to that
88+
// state.
89+
DepMessage::Read(_) => { }
8490
DepMessage::Write(ref n) => self.check_edge(top(&stack), Some(Some(n))),
8591
DepMessage::PushTask(ref n) => stack.push(Some(n.clone())),
8692
DepMessage::PushIgnore => stack.push(None),
@@ -116,7 +122,7 @@ impl ShadowGraph {
116122
(None, None) => unreachable!(),
117123

118124
// nothing on top of the stack
119-
(None, Some(n)) | (Some(n), None) => bug!("read/write of {:?} but no current task", n),
125+
(None, Some(n)) | (Some(n), None) => bug!("write of {:?} but no current task", n),
120126

121127
// this corresponds to an Ignore being top of the stack
122128
(Some(None), _) | (_, Some(None)) => (),

src/librustc/hir/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ impl Lifetime {
159159
pub fn is_elided(&self) -> bool {
160160
self.name == keywords::Invalid.name()
161161
}
162+
163+
pub fn is_static(&self) -> bool {
164+
self.name == keywords::StaticLifetime.name()
165+
}
162166
}
163167

164168
/// A lifetime definition, eg `'a: 'b+'c+'d`

src/librustc/lint/context.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ use std::ops::Deref;
4444
use syntax::attr;
4545
use syntax::ast;
4646
use syntax::symbol::Symbol;
47-
use syntax_pos::{MultiSpan, Span};
47+
use syntax_pos::{DUMMY_SP, MultiSpan, Span};
4848
use errors::{self, Diagnostic, DiagnosticBuilder};
4949
use hir;
50+
use hir::def_id::LOCAL_CRATE;
5051
use hir::intravisit as hir_visit;
5152
use syntax::visit as ast_visit;
5253

@@ -1231,10 +1232,11 @@ fn check_lint_name_cmdline(sess: &Session, lint_cx: &LintStore,
12311232
/// Perform lint checking on a crate.
12321233
///
12331234
/// Consumes the `lint_store` field of the `Session`.
1234-
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1235-
access_levels: &AccessLevels) {
1235+
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
12361236
let _task = tcx.dep_graph.in_task(DepNode::LateLintCheck);
12371237

1238+
let access_levels = &ty::queries::privacy_access_levels::get(tcx, DUMMY_SP, LOCAL_CRATE);
1239+
12381240
let krate = tcx.hir.krate();
12391241

12401242
// We want to own the lint store, so move it out of the session.

src/librustc/middle/cstore.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ pub trait CrateStore {
255255
fn used_crates(&self, prefer: LinkagePreference) -> Vec<(CrateNum, LibSource)>;
256256
fn used_crate_source(&self, cnum: CrateNum) -> CrateSource;
257257
fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum>;
258-
fn encode_metadata<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
259-
reexports: &def::ExportMap,
258+
fn encode_metadata<'a, 'tcx>(&self,
259+
tcx: TyCtxt<'a, 'tcx, 'tcx>,
260260
link_meta: &LinkMeta,
261261
reachable: &NodeSet) -> Vec<u8>;
262262
fn metadata_encoding_version(&self) -> &[u8];
@@ -412,10 +412,10 @@ impl CrateStore for DummyCrateStore {
412412
{ vec![] }
413413
fn used_crate_source(&self, cnum: CrateNum) -> CrateSource { bug!("used_crate_source") }
414414
fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum> { None }
415-
fn encode_metadata<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
416-
reexports: &def::ExportMap,
417-
link_meta: &LinkMeta,
418-
reachable: &NodeSet) -> Vec<u8> { vec![] }
415+
fn encode_metadata<'a, 'tcx>(&self,
416+
tcx: TyCtxt<'a, 'tcx, 'tcx>,
417+
link_meta: &LinkMeta,
418+
reachable: &NodeSet) -> Vec<u8> { vec![] }
419419
fn metadata_encoding_version(&self) -> &[u8] { bug!("metadata_encoding_version") }
420420
}
421421

src/librustc/middle/dead.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ use hir::itemlikevisit::ItemLikeVisitor;
2121
use middle::privacy;
2222
use ty::{self, TyCtxt};
2323
use hir::def::Def;
24-
use hir::def_id::{DefId};
24+
use hir::def_id::{DefId, LOCAL_CRATE};
2525
use lint;
2626
use util::nodemap::FxHashSet;
2727

2828
use syntax::{ast, codemap};
2929
use syntax::attr;
30+
use syntax::codemap::DUMMY_SP;
3031
use syntax_pos;
3132

3233
// Any local node that may call something in its body block should be
@@ -592,9 +593,9 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
592593
}
593594
}
594595

595-
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
596-
access_levels: &privacy::AccessLevels) {
596+
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
597597
let _task = tcx.dep_graph.in_task(DepNode::DeadCheck);
598+
let access_levels = &ty::queries::privacy_access_levels::get(tcx, DUMMY_SP, LOCAL_CRATE);
598599
let krate = tcx.hir.krate();
599600
let live_symbols = find_live(tcx, access_levels, krate);
600601
let mut visitor = DeadVisitor { tcx: tcx, live_symbols: live_symbols };

src/librustc/middle/reachable.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ use util::nodemap::{NodeSet, FxHashSet};
2727
use syntax::abi::Abi;
2828
use syntax::ast;
2929
use syntax::attr;
30+
use syntax::codemap::DUMMY_SP;
3031
use hir;
32+
use hir::def_id::LOCAL_CRATE;
3133
use hir::intravisit::{Visitor, NestedVisitorMap};
3234
use hir::itemlikevisit::ItemLikeVisitor;
3335
use hir::intravisit;
@@ -359,11 +361,11 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a,
359361
}
360362
}
361363

362-
pub fn find_reachable<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
363-
access_levels: &privacy::AccessLevels)
364-
-> NodeSet {
364+
pub fn find_reachable<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> NodeSet {
365365
let _task = tcx.dep_graph.in_task(DepNode::Reachability);
366366

367+
let access_levels = &ty::queries::privacy_access_levels::get(tcx, DUMMY_SP, LOCAL_CRATE);
368+
367369
let any_library = tcx.sess.crate_types.borrow().iter().any(|ty| {
368370
*ty == config::CrateTypeRlib || *ty == config::CrateTypeDylib ||
369371
*ty == config::CrateTypeProcMacro

src/librustc/middle/resolve_lifetime.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use syntax::ast;
2929
use syntax::attr;
3030
use syntax::ptr::P;
3131
use syntax::symbol::keywords;
32-
use syntax_pos::Span;
32+
use syntax_pos::{mk_sp, Span};
3333
use errors::DiagnosticBuilder;
3434
use util::nodemap::{NodeMap, NodeSet, FxHashSet, FxHashMap, DefIdMap};
3535
use rustc_back::slice;
@@ -434,7 +434,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
434434
self.resolve_elided_lifetimes(slice::ref_slice(lifetime_ref));
435435
return;
436436
}
437-
if lifetime_ref.name == keywords::StaticLifetime.name() {
437+
if lifetime_ref.is_static() {
438438
self.insert_lifetime(lifetime_ref, Region::Static);
439439
return;
440440
}
@@ -1434,7 +1434,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
14341434
let lifetime_i = &lifetimes[i];
14351435

14361436
for lifetime in lifetimes {
1437-
if lifetime.lifetime.name == keywords::StaticLifetime.name() {
1437+
if lifetime.lifetime.is_static() {
14381438
let lifetime = lifetime.lifetime;
14391439
let mut err = struct_span_err!(self.sess, lifetime.span, E0262,
14401440
"invalid lifetime parameter name: `{}`", lifetime.name);
@@ -1464,7 +1464,17 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
14641464
self.check_lifetime_def_for_shadowing(old_scope, &lifetime_i.lifetime);
14651465

14661466
for bound in &lifetime_i.bounds {
1467-
self.resolve_lifetime_ref(bound);
1467+
if !bound.is_static() {
1468+
self.resolve_lifetime_ref(bound);
1469+
} else {
1470+
self.insert_lifetime(bound, Region::Static);
1471+
let full_span = mk_sp(lifetime_i.lifetime.span.lo, bound.span.hi);
1472+
self.sess.struct_span_warn(full_span,
1473+
&format!("unnecessary lifetime parameter `{}`", lifetime_i.lifetime.name))
1474+
.help(&format!("you can use the `'static` lifetime directly, in place \
1475+
of `{}`", lifetime_i.lifetime.name))
1476+
.emit();
1477+
}
14681478
}
14691479
}
14701480
}

src/librustc/middle/stability.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -656,10 +656,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
656656
/// Given the list of enabled features that were not language features (i.e. that
657657
/// were expected to be library features), and the list of features used from
658658
/// libraries, identify activated features that don't exist and error about them.
659-
pub fn check_unused_or_stable_features<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
660-
access_levels: &AccessLevels) {
659+
pub fn check_unused_or_stable_features<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
661660
let sess = &tcx.sess;
662661

662+
let access_levels = &ty::queries::privacy_access_levels::get(tcx, DUMMY_SP, LOCAL_CRATE);
663+
663664
if tcx.stability.borrow().staged_api[&LOCAL_CRATE] && tcx.sess.features.borrow().staged_api {
664665
let _task = tcx.dep_graph.in_task(DepNode::StabilityIndex);
665666
let krate = tcx.hir.krate();

src/librustc/ty/context.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use session::Session;
1515
use lint;
1616
use middle;
1717
use hir::TraitMap;
18-
use hir::def::Def;
18+
use hir::def::{Def, ExportMap};
1919
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
2020
use hir::map as hir_map;
2121
use hir::map::DisambiguatedDefPathData;
@@ -416,6 +416,9 @@ pub struct GlobalCtxt<'tcx> {
416416
/// is relevant; generated by resolve.
417417
pub trait_map: TraitMap,
418418

419+
/// Export map produced by name resolution.
420+
pub export_map: ExportMap,
421+
419422
pub named_region_map: resolve_lifetime::NamedRegionMap,
420423

421424
pub region_maps: RegionMaps,
@@ -698,6 +701,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
698701
region_maps: region_maps,
699702
variance_computed: Cell::new(false),
700703
trait_map: resolutions.trait_map,
704+
export_map: resolutions.export_map,
701705
fulfilled_predicates: RefCell::new(fulfilled_predicates),
702706
hir: hir,
703707
maps: maps::Maps::new(dep_graph, providers),

src/librustc/ty/maps.rs

+10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use dep_graph::{DepGraph, DepNode, DepTrackingMap, DepTrackingMapConfig};
1212
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
1313
use middle::const_val::ConstVal;
14+
use middle::privacy::AccessLevels;
1415
use mir;
1516
use ty::{self, Ty, TyCtxt};
1617

@@ -189,6 +190,12 @@ impl<'tcx> QueryDescription for queries::mir_shims<'tcx> {
189190
}
190191
}
191192

193+
impl<'tcx> QueryDescription for queries::privacy_access_levels<'tcx> {
194+
fn describe(_: TyCtxt, _: CrateNum) -> String {
195+
format!("privacy access levels")
196+
}
197+
}
198+
192199
macro_rules! define_maps {
193200
(<$tcx:tt>
194201
$($(#[$attr:meta])*
@@ -406,6 +413,9 @@ define_maps! { <'tcx>
406413
/// other items, such as enum variant explicit discriminants.
407414
pub monomorphic_const_eval: MonomorphicConstEval(DefId) -> Result<ConstVal<'tcx>, ()>,
408415

416+
/// Performs the privacy check and computes "access levels".
417+
pub privacy_access_levels: PrivacyAccessLevels(CrateNum) -> Rc<AccessLevels>,
418+
409419
pub mir_shims: mir_shim(ty::InstanceDef<'tcx>) -> &'tcx RefCell<mir::Mir<'tcx>>
410420
}
411421

src/librustc/ty/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ pub use self::fold::TypeFoldable;
1717

1818
use dep_graph::{self, DepNode};
1919
use hir::{map as hir_map, FreevarMap, TraitMap};
20-
use middle;
2120
use hir::def::{Def, CtorKind, ExportMap};
2221
use hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE};
2322
use middle::const_val::ConstVal;
2423
use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem};
24+
use middle::privacy::AccessLevels;
2525
use middle::region::{CodeExtent, ROOT_CODE_EXTENT};
2626
use middle::resolve_lifetime::ObjectLifetimeDefault;
2727
use mir::Mir;
@@ -108,10 +108,12 @@ mod sty;
108108

109109
/// The complete set of all analyses described in this module. This is
110110
/// produced by the driver and fed to trans and later passes.
111+
///
112+
/// NB: These contents are being migrated into queries using the
113+
/// *on-demand* infrastructure.
111114
#[derive(Clone)]
112115
pub struct CrateAnalysis {
113-
pub export_map: ExportMap,
114-
pub access_levels: middle::privacy::AccessLevels,
116+
pub access_levels: Rc<AccessLevels>,
115117
pub reachable: NodeSet,
116118
pub name: String,
117119
pub glob_map: Option<hir::GlobMap>,
@@ -122,6 +124,7 @@ pub struct Resolutions {
122124
pub freevars: FreevarMap,
123125
pub trait_map: TraitMap,
124126
pub maybe_unused_trait_imports: NodeSet,
127+
pub export_map: ExportMap,
125128
}
126129

127130
#[derive(Clone, Copy, PartialEq, Eq, Debug)]

0 commit comments

Comments
 (0)