diff --git a/src/doc/reference.md b/src/doc/reference.md index 5be61a51bf0a4..a3e13acccae28 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -944,9 +944,20 @@ fn foo(x: T) where T: Debug { ``` When a generic function is referenced, its type is instantiated based on the -context of the reference. For example, calling the `iter` function defined -above on `[1, 2]` will instantiate type parameter `T` with `i32`, and require -the closure parameter to have type `Fn(i32)`. +context of the reference. For example, calling the `foo` function here: + +``` +use std::fmt::Debug; + +fn foo(x: &[T]) where T: Debug { + // details elided + # () +} + +foo(&[1, 2]); +``` + +will instantiate type parameter `T` with `i32`. The type parameters can also be explicitly supplied in a trailing [path](#paths) component after the function name. This might be necessary if @@ -2768,22 +2779,24 @@ meaning of the operators on standard types is given here. Like the [arithmetic operators](#arithmetic-operators), bitwise operators are syntactic sugar for calls to methods of built-in traits. This means that bitwise operators can be overridden for user-defined types. The default -meaning of the operators on standard types is given here. +meaning of the operators on standard types is given here. Bitwise `&`, `|` and +`^` applied to boolean arguments are equivalent to logical `&&`, `||` and `!=` +evaluated in non-lazy fashion. * `&` - : And. + : Bitwise AND. Calls the `bitand` method of the `std::ops::BitAnd` trait. * `|` - : Inclusive or. + : Bitwise inclusive OR. Calls the `bitor` method of the `std::ops::BitOr` trait. * `^` - : Exclusive or. + : Bitwise exclusive OR. Calls the `bitxor` method of the `std::ops::BitXor` trait. * `<<` : Left shift. Calls the `shl` method of the `std::ops::Shl` trait. * `>>` - : Right shift. + : Right shift (arithmetic). Calls the `shr` method of the `std::ops::Shr` trait. #### Lazy boolean operators diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 6d8e412c8a5dd..9d0a1821debc1 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -65,7 +65,6 @@ pub use self::InteriorKind::*; pub use self::FieldName::*; pub use self::ElementKind::*; pub use self::MutabilityCategory::*; -pub use self::InteriorSafety::*; pub use self::AliasableReason::*; pub use self::Note::*; pub use self::deref_kind::*; @@ -1385,12 +1384,6 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { } } -#[derive(Copy, Clone, Debug)] -pub enum InteriorSafety { - InteriorUnsafe, - InteriorSafe -} - #[derive(Clone, Debug)] pub enum Aliasability { FreelyAliasable(AliasableReason), @@ -1404,8 +1397,8 @@ pub enum AliasableReason { AliasableClosure(ast::NodeId), // Aliasable due to capture Fn closure env AliasableOther, UnaliasableImmutable, // Created as needed upon seeing ImmutableUnique - AliasableStatic(InteriorSafety), - AliasableStaticMut(InteriorSafety), + AliasableStatic, + AliasableStaticMut, } impl<'tcx> cmt_<'tcx> { @@ -1469,16 +1462,10 @@ impl<'tcx> cmt_<'tcx> { } cat_static_item(..) => { - let int_safe = if ty::type_interior_is_unsafe(ctxt, self.ty) { - InteriorUnsafe - } else { - InteriorSafe - }; - if self.mutbl.is_mutable() { - FreelyAliasable(AliasableStaticMut(int_safe)) + FreelyAliasable(AliasableStaticMut) } else { - FreelyAliasable(AliasableStatic(int_safe)) + FreelyAliasable(AliasableStatic) } } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 6662e3ef4b3b9..f5fcb72c5c1c9 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -3787,10 +3787,6 @@ impl fmt::Debug for TypeContents { } } -pub fn type_interior_is_unsafe<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> bool { - type_contents(cx, ty).interior_unsafe() -} - pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents { return memoized(&cx.tc_cache, ty, |ty| { tc_ty(cx, ty, &mut FnvHashMap()) diff --git a/src/librustc_borrowck/borrowck/gather_loans/mod.rs b/src/librustc_borrowck/borrowck/gather_loans/mod.rs index 733d486d2d22d..012e01507de72 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/mod.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/mod.rs @@ -191,23 +191,11 @@ fn check_aliasability<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, /* Uniquely accessible path -- OK for `&` and `&mut` */ Ok(()) } - (mc::Aliasability::FreelyAliasable(mc::AliasableStatic(safety)), ty::ImmBorrow) => { - // Borrow of an immutable static item: - match safety { - mc::InteriorUnsafe => { - // If the static item contains an Unsafe, it has interior - // mutability. In such cases, another phase of the compiler - // will ensure that the type is `Sync` and then trans will - // not put it in rodata, so this is ok to allow. - Ok(()) - } - mc::InteriorSafe => { - // Immutable static can be borrowed, no problem. - Ok(()) - } - } + (mc::Aliasability::FreelyAliasable(mc::AliasableStatic), ty::ImmBorrow) => { + // Borrow of an immutable static item. + Ok(()) } - (mc::Aliasability::FreelyAliasable(mc::AliasableStaticMut(..)), _) => { + (mc::Aliasability::FreelyAliasable(mc::AliasableStaticMut), _) => { // Even touching a static mut is considered unsafe. We assume the // user knows what they're doing in these cases. Ok(()) diff --git a/src/libstd/collections/mod.rs b/src/libstd/collections/mod.rs index 4781f2b47548f..1da3bb7c5b38a 100644 --- a/src/libstd/collections/mod.rs +++ b/src/libstd/collections/mod.rs @@ -66,7 +66,7 @@ //! ### Use a `BTreeMap` when: //! * You're interested in what the smallest or largest key-value pair is. //! * You want to find the largest or smallest key that is smaller or larger -//! than something +//! than something. //! * You want to be able to get all of the entries in order on-demand. //! * You want a sorted map. //! @@ -147,7 +147,7 @@ //! relation to the number of elements in the collection. VecMap should only be //! seriously considered for small keys. //! -//! Note also that BTreeMap's precise preformance depends on the value of B. +//! Note also that BTreeMap's precise performance depends on the value of B. //! //! # Correct and Efficient Usage of Collections //! @@ -309,7 +309,7 @@ //! If a `Vacant(entry)` is yielded, then the key *was not* found. In this case //! the only valid operation is to `insert` a value into the entry. When this is //! done, the vacant entry is consumed and converted into a mutable reference to -//! the the value that was inserted. This allows for further manipulation of the +//! the value that was inserted. This allows for further manipulation of the //! value beyond the lifetime of the search itself. This is useful if complex //! logic needs to be performed on the value regardless of whether the value was //! just inserted. diff --git a/src/test/run-pass/issue-25180.rs b/src/test/run-pass/issue-25180.rs new file mode 100644 index 0000000000000..4e6f9b321bab4 --- /dev/null +++ b/src/test/run-pass/issue-25180.rs @@ -0,0 +1,13 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +const x: &'static Fn() = &|| println!("ICE here"); + +fn main() {}