Skip to content

Commit 76d4806

Browse files
committed
---
yaml --- r: 212971 b: refs/heads/master c: fba9cec h: refs/heads/master i: 212969: ec108dc 212967: cf2a935 v: v3
1 parent 5c069b0 commit 76d4806

File tree

14 files changed

+134
-172
lines changed

14 files changed

+134
-172
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 81024d9931ef63316995294fc41accb641646c4f
2+
refs/heads/master: fba9cecab753a87957b9eac19f3c1cc27e048817
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ba0e1cd8147d452c356aacb29fb87568ca26f111
55
refs/heads/try: 1864973ae17213c5a58c4dd3f9af6d1b6c7d2e05

trunk/src/doc/reference.md

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -944,20 +944,9 @@ fn foo<T>(x: T) where T: Debug {
944944
```
945945

946946
When a generic function is referenced, its type is instantiated based on the
947-
context of the reference. For example, calling the `foo` function here:
948-
949-
```
950-
use std::fmt::Debug;
951-
952-
fn foo<T>(x: &[T]) where T: Debug {
953-
// details elided
954-
# ()
955-
}
956-
957-
foo(&[1, 2]);
958-
```
959-
960-
will instantiate type parameter `T` with `i32`.
947+
context of the reference. For example, calling the `iter` function defined
948+
above on `[1, 2]` will instantiate type parameter `T` with `i32`, and require
949+
the closure parameter to have type `Fn(i32)`.
961950

962951
The type parameters can also be explicitly supplied in a trailing
963952
[path](#paths) component after the function name. This might be necessary if
@@ -2779,24 +2768,22 @@ meaning of the operators on standard types is given here.
27792768
Like the [arithmetic operators](#arithmetic-operators), bitwise operators are
27802769
syntactic sugar for calls to methods of built-in traits. This means that
27812770
bitwise operators can be overridden for user-defined types. The default
2782-
meaning of the operators on standard types is given here. Bitwise `&`, `|` and
2783-
`^` applied to boolean arguments are equivalent to logical `&&`, `||` and `!=`
2784-
evaluated in non-lazy fashion.
2771+
meaning of the operators on standard types is given here.
27852772

27862773
* `&`
2787-
: Bitwise AND.
2774+
: And.
27882775
Calls the `bitand` method of the `std::ops::BitAnd` trait.
27892776
* `|`
2790-
: Bitwise inclusive OR.
2777+
: Inclusive or.
27912778
Calls the `bitor` method of the `std::ops::BitOr` trait.
27922779
* `^`
2793-
: Bitwise exclusive OR.
2780+
: Exclusive or.
27942781
Calls the `bitxor` method of the `std::ops::BitXor` trait.
27952782
* `<<`
27962783
: Left shift.
27972784
Calls the `shl` method of the `std::ops::Shl` trait.
27982785
* `>>`
2799-
: Right shift (arithmetic).
2786+
: Right shift.
28002787
Calls the `shr` method of the `std::ops::Shr` trait.
28012788

28022789
#### Lazy boolean operators

trunk/src/librustc/middle/mem_categorization.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ pub use self::InteriorKind::*;
6565
pub use self::FieldName::*;
6666
pub use self::ElementKind::*;
6767
pub use self::MutabilityCategory::*;
68+
pub use self::InteriorSafety::*;
6869
pub use self::AliasableReason::*;
6970
pub use self::Note::*;
7071
pub use self::deref_kind::*;
@@ -1384,6 +1385,12 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
13841385
}
13851386
}
13861387

1388+
#[derive(Copy, Clone, Debug)]
1389+
pub enum InteriorSafety {
1390+
InteriorUnsafe,
1391+
InteriorSafe
1392+
}
1393+
13871394
#[derive(Clone, Debug)]
13881395
pub enum Aliasability {
13891396
FreelyAliasable(AliasableReason),
@@ -1397,8 +1404,8 @@ pub enum AliasableReason {
13971404
AliasableClosure(ast::NodeId), // Aliasable due to capture Fn closure env
13981405
AliasableOther,
13991406
UnaliasableImmutable, // Created as needed upon seeing ImmutableUnique
1400-
AliasableStatic,
1401-
AliasableStaticMut,
1407+
AliasableStatic(InteriorSafety),
1408+
AliasableStaticMut(InteriorSafety),
14021409
}
14031410

14041411
impl<'tcx> cmt_<'tcx> {
@@ -1462,10 +1469,16 @@ impl<'tcx> cmt_<'tcx> {
14621469
}
14631470

14641471
cat_static_item(..) => {
1472+
let int_safe = if ty::type_interior_is_unsafe(ctxt, self.ty) {
1473+
InteriorUnsafe
1474+
} else {
1475+
InteriorSafe
1476+
};
1477+
14651478
if self.mutbl.is_mutable() {
1466-
FreelyAliasable(AliasableStaticMut)
1479+
FreelyAliasable(AliasableStaticMut(int_safe))
14671480
} else {
1468-
FreelyAliasable(AliasableStatic)
1481+
FreelyAliasable(AliasableStatic(int_safe))
14691482
}
14701483
}
14711484

trunk/src/librustc/middle/ty.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3787,6 +3787,10 @@ impl fmt::Debug for TypeContents {
37873787
}
37883788
}
37893789

3790+
pub fn type_interior_is_unsafe<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> bool {
3791+
type_contents(cx, ty).interior_unsafe()
3792+
}
3793+
37903794
pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
37913795
return memoized(&cx.tc_cache, ty, |ty| {
37923796
tc_ty(cx, ty, &mut FnvHashMap())

trunk/src/librustc_borrowck/borrowck/gather_loans/mod.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,23 @@ fn check_aliasability<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
191191
/* Uniquely accessible path -- OK for `&` and `&mut` */
192192
Ok(())
193193
}
194-
(mc::Aliasability::FreelyAliasable(mc::AliasableStatic), ty::ImmBorrow) => {
195-
// Borrow of an immutable static item.
196-
Ok(())
194+
(mc::Aliasability::FreelyAliasable(mc::AliasableStatic(safety)), ty::ImmBorrow) => {
195+
// Borrow of an immutable static item:
196+
match safety {
197+
mc::InteriorUnsafe => {
198+
// If the static item contains an Unsafe<T>, it has interior
199+
// mutability. In such cases, another phase of the compiler
200+
// will ensure that the type is `Sync` and then trans will
201+
// not put it in rodata, so this is ok to allow.
202+
Ok(())
203+
}
204+
mc::InteriorSafe => {
205+
// Immutable static can be borrowed, no problem.
206+
Ok(())
207+
}
208+
}
197209
}
198-
(mc::Aliasability::FreelyAliasable(mc::AliasableStaticMut), _) => {
210+
(mc::Aliasability::FreelyAliasable(mc::AliasableStaticMut(..)), _) => {
199211
// Even touching a static mut is considered unsafe. We assume the
200212
// user knows what they're doing in these cases.
201213
Ok(())

trunk/src/librustc_typeck/check/coercion.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
403403
a.repr(self.tcx()),
404404
b.repr(self.tcx()));
405405

406-
let (is_ref, mt_a) = match a.sty {
407-
ty::TyRef(_, mt) => (true, mt),
408-
ty::TyRawPtr(mt) => (false, mt),
406+
let mt_a = match a.sty {
407+
ty::TyRef(_, mt) | ty::TyRawPtr(mt) => mt,
409408
_ => {
410409
return self.subtype(a, b);
411410
}
@@ -419,15 +418,11 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
419418
// Although references and unsafe ptrs have the same
420419
// representation, we still register an AutoDerefRef so that
421420
// regionck knows that the region for `a` must be valid here.
422-
if is_ref {
423-
Ok(Some(AdjustDerefRef(AutoDerefRef {
424-
autoderefs: 1,
425-
autoref: Some(ty::AutoUnsafe(mutbl_b)),
426-
unsize: None
427-
})))
428-
} else {
429-
Ok(None)
430-
}
421+
Ok(Some(AdjustDerefRef(AutoDerefRef {
422+
autoderefs: 1,
423+
autoref: Some(ty::AutoUnsafe(mutbl_b)),
424+
unsize: None
425+
})))
431426
}
432427
}
433428

trunk/src/libstd/collections/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
//! ### Use a `BTreeMap` when:
6767
//! * You're interested in what the smallest or largest key-value pair is.
6868
//! * You want to find the largest or smallest key that is smaller or larger
69-
//! than something.
69+
//! than something
7070
//! * You want to be able to get all of the entries in order on-demand.
7171
//! * You want a sorted map.
7272
//!
@@ -147,7 +147,7 @@
147147
//! relation to the number of elements in the collection. VecMap should only be
148148
//! seriously considered for small keys.
149149
//!
150-
//! Note also that BTreeMap's precise performance depends on the value of B.
150+
//! Note also that BTreeMap's precise preformance depends on the value of B.
151151
//!
152152
//! # Correct and Efficient Usage of Collections
153153
//!
@@ -309,7 +309,7 @@
309309
//! If a `Vacant(entry)` is yielded, then the key *was not* found. In this case
310310
//! the only valid operation is to `insert` a value into the entry. When this is
311311
//! done, the vacant entry is consumed and converted into a mutable reference to
312-
//! the value that was inserted. This allows for further manipulation of the
312+
//! the the value that was inserted. This allows for further manipulation of the
313313
//! value beyond the lifetime of the search itself. This is useful if complex
314314
//! logic needs to be performed on the value regardless of whether the value was
315315
//! just inserted.

trunk/src/libsyntax/codemap.rs

Lines changed: 53 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//! within the CodeMap, which upon request can be converted to line and column
1818
//! information, source code snippets, etc.
1919
20-
pub use self::ExpnFormat::*;
20+
pub use self::MacroFormat::*;
2121

2222
use std::cell::RefCell;
2323
use std::ops::{Add, Sub};
@@ -228,17 +228,17 @@ pub struct FileMapAndBytePos { pub fm: Rc<FileMap>, pub pos: BytePos }
228228

229229

230230
// _____________________________________________________________________________
231-
// ExpnFormat, NameAndSpan, ExpnInfo, ExpnId
231+
// MacroFormat, NameAndSpan, ExpnInfo, ExpnId
232232
//
233233

234-
/// The source of expansion.
235-
#[derive(Clone, Copy, Hash, Debug, PartialEq, Eq)]
236-
pub enum ExpnFormat {
234+
/// The syntax with which a macro was invoked.
235+
#[derive(Clone, Copy, Hash, Debug)]
236+
pub enum MacroFormat {
237237
/// e.g. #[derive(...)] <item>
238238
MacroAttribute,
239239
/// e.g. `format!()`
240240
MacroBang,
241-
/// Syntax sugar expansion performed by the compiler (libsyntax::expand).
241+
/// Expansion performed by the compiler (libsyntax::expand).
242242
CompilerExpansion,
243243
}
244244

@@ -248,7 +248,7 @@ pub struct NameAndSpan {
248248
/// with this Span.
249249
pub name: String,
250250
/// The format with which the macro was invoked.
251-
pub format: ExpnFormat,
251+
pub format: MacroFormat,
252252
/// Whether the macro is allowed to use #[unstable]/feature-gated
253253
/// features internally without forcing the whole crate to opt-in
254254
/// to them.
@@ -259,11 +259,11 @@ pub struct NameAndSpan {
259259
pub span: Option<Span>
260260
}
261261

262-
/// Extra information for tracking spans of macro and syntax sugar expansion
262+
/// Extra information for tracking macro expansion of spans
263263
#[derive(Hash, Debug)]
264264
pub struct ExpnInfo {
265-
/// The location of the actual macro invocation or syntax sugar , e.g.
266-
/// `let x = foo!();` or `if let Some(y) = x {}`
265+
/// The location of the actual macro invocation, e.g. `let x =
266+
/// foo!();`
267267
///
268268
/// This may recursively refer to other macro invocations, e.g. if
269269
/// `foo!()` invoked `bar!()` internally, and there was an
@@ -272,7 +272,12 @@ pub struct ExpnInfo {
272272
/// call_site span would have its own ExpnInfo, with the call_site
273273
/// pointing to the `foo!` invocation.
274274
pub call_site: Span,
275-
/// Information about the expansion.
275+
/// Information about the macro and its definition.
276+
///
277+
/// The `callee` of the inner expression in the `call_site`
278+
/// example would point to the `macro_rules! bar { ... }` and that
279+
/// of the `bar!()` invocation would point to the `macro_rules!
280+
/// foo { ... }`.
276281
pub callee: NameAndSpan
277282
}
278283

@@ -672,39 +677,7 @@ impl CodeMap {
672677

673678
/// Lookup source information about a BytePos
674679
pub fn lookup_char_pos(&self, pos: BytePos) -> Loc {
675-
let FileMapAndLine {fm: f, line: a} = self.lookup_line(pos);
676-
let line = a + 1; // Line numbers start at 1
677-
let chpos = self.bytepos_to_file_charpos(pos);
678-
let linebpos = (*f.lines.borrow())[a];
679-
let linechpos = self.bytepos_to_file_charpos(linebpos);
680-
debug!("byte pos {:?} is on the line at byte pos {:?}",
681-
pos, linebpos);
682-
debug!("char pos {:?} is on the line at char pos {:?}",
683-
chpos, linechpos);
684-
debug!("byte is on line: {}", line);
685-
assert!(chpos >= linechpos);
686-
Loc {
687-
file: f,
688-
line: line,
689-
col: chpos - linechpos
690-
}
691-
}
692-
693-
fn lookup_line(&self, pos: BytePos) -> FileMapAndLine {
694-
let idx = self.lookup_filemap_idx(pos);
695-
696-
let files = self.files.borrow();
697-
let f = (*files)[idx].clone();
698-
let mut a = 0;
699-
{
700-
let lines = f.lines.borrow();
701-
let mut b = lines.len();
702-
while b - a > 1 {
703-
let m = (a + b) / 2;
704-
if (*lines)[m] > pos { b = m; } else { a = m; }
705-
}
706-
}
707-
FileMapAndLine {fm: f, line: a}
680+
self.lookup_pos(pos)
708681
}
709682

710683
pub fn lookup_char_pos_adj(&self, pos: BytePos) -> LocWithOpt {
@@ -904,6 +877,42 @@ impl CodeMap {
904877
return a;
905878
}
906879

880+
fn lookup_line(&self, pos: BytePos) -> FileMapAndLine {
881+
let idx = self.lookup_filemap_idx(pos);
882+
883+
let files = self.files.borrow();
884+
let f = (*files)[idx].clone();
885+
let mut a = 0;
886+
{
887+
let lines = f.lines.borrow();
888+
let mut b = lines.len();
889+
while b - a > 1 {
890+
let m = (a + b) / 2;
891+
if (*lines)[m] > pos { b = m; } else { a = m; }
892+
}
893+
}
894+
FileMapAndLine {fm: f, line: a}
895+
}
896+
897+
fn lookup_pos(&self, pos: BytePos) -> Loc {
898+
let FileMapAndLine {fm: f, line: a} = self.lookup_line(pos);
899+
let line = a + 1; // Line numbers start at 1
900+
let chpos = self.bytepos_to_file_charpos(pos);
901+
let linebpos = (*f.lines.borrow())[a];
902+
let linechpos = self.bytepos_to_file_charpos(linebpos);
903+
debug!("byte pos {:?} is on the line at byte pos {:?}",
904+
pos, linebpos);
905+
debug!("char pos {:?} is on the line at char pos {:?}",
906+
chpos, linechpos);
907+
debug!("byte is on line: {}", line);
908+
assert!(chpos >= linechpos);
909+
Loc {
910+
file: f,
911+
line: line,
912+
col: chpos - linechpos
913+
}
914+
}
915+
907916
pub fn record_expansion(&self, expn_info: ExpnInfo) -> ExpnId {
908917
let mut expansions = self.expansions.borrow_mut();
909918
expansions.push(expn_info);

0 commit comments

Comments
 (0)