Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 15 pull requests #75308

Merged
merged 32 commits into from
Aug 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a4fb1d0
adjust remaining targets
stlankes Jul 27, 2020
e1ef3fa
Consistent variable name alloc for raw_vec
pickfire Aug 4, 2020
d243fa1
Fix the documentation for move about Fn traits implementations
poliorcetics Aug 4, 2020
a784729
Add `as_mut_ptr` to `NonNull<[T]>`
TimDiekmann Aug 6, 2020
06cf40f
Show multi extension example for Path in doctests
pickfire Aug 7, 2020
7e68b7d
Update E0271.md
strom-und-spiele Jul 24, 2020
a11c279
Show relative example for Path ancestors
pickfire Aug 8, 2020
6dffd2d
Separate example for Path strip_prefix
pickfire Aug 8, 2020
9532b83
Show Path extension example change multi extension
pickfire Aug 8, 2020
b3ae88f
Use assert! for Path exists example to check bool
pickfire Aug 8, 2020
4b15b80
Remove abmiguity from PathBuf pop example
pickfire Aug 8, 2020
ad6d237
fix `min_const_generics` version
lcnr Aug 8, 2020
c2099b5
Add safety section to `NonNull::as_*` method docs
aticu Aug 7, 2020
d8cf9aa
Use `&` instead of `let ref` in E0502
slanterns Aug 8, 2020
1cd8dff
Add an example about the behaviour of move and Fn* traits
poliorcetics Aug 8, 2020
259d350
Clean up E0750 explanation
GuillaumeGomez Aug 8, 2020
17db7a4
Remove E0750 from unchecked error codes
GuillaumeGomez Aug 8, 2020
5bbdc73
Rollup merge of #74712 - strom-und-spiele:E0271-cleanup, r=Mark-Simul…
JohnTitor Aug 8, 2020
dde4fb3
Rollup merge of #74842 - hermitcore:thread_local, r=Mark-Simulacrum
JohnTitor Aug 8, 2020
3370ac0
Rollup merge of #75151 - pickfire:patch-4, r=LukasKalbertodt
JohnTitor Aug 8, 2020
ccffe18
Rollup merge of #75162 - poliorcetics:move-documentation-fix, r=jyn514
JohnTitor Aug 8, 2020
c85075d
Rollup merge of #75248 - TimDiekmann:NonNull-as_mut_ptr, r=RalfJung
JohnTitor Aug 8, 2020
cbc6914
Rollup merge of #75262 - pickfire:patch-6, r=jyn514
JohnTitor Aug 8, 2020
cb75fea
Rollup merge of #75266 - aticu:master, r=RalfJung
JohnTitor Aug 8, 2020
27b864b
Rollup merge of #75284 - pickfire:patch-7, r=LukasKalbertodt
JohnTitor Aug 8, 2020
28ab318
Rollup merge of #75285 - pickfire:patch-8, r=jonas-schievink
JohnTitor Aug 8, 2020
42e163b
Rollup merge of #75287 - pickfire:patch-10, r=jonas-schievink
JohnTitor Aug 8, 2020
6baee95
Rollup merge of #75288 - pickfire:patch-11, r=jonas-schievink
JohnTitor Aug 8, 2020
3038ecb
Rollup merge of #75289 - pickfire:patch-12, r=jonas-schievink
JohnTitor Aug 8, 2020
55f2490
Rollup merge of #75290 - rust-lang:min_const_generics-version, r=jona…
JohnTitor Aug 8, 2020
bc3ee48
Rollup merge of #75291 - GuillaumeGomez:cleanup-e0750, r=pickfire
JohnTitor Aug 8, 2020
e6dfd30
Rollup merge of #75292 - slanterns:cleanup-E0502, r=GuillaumeGomez
JohnTitor Aug 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions library/alloc/src/raw_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,15 @@ impl<T, A: AllocRef> RawVec<T, A> {
///
/// # Safety
///
/// The `ptr` must be allocated (via the given allocator `a`), and with the given `capacity`.
/// The `ptr` must be allocated (via the given allocator `alloc`), and with the given
/// `capacity`.
/// The `capacity` cannot exceed `isize::MAX` for sized types. (only a concern on 32-bit
/// systems). ZST vectors may have a capacity up to `usize::MAX`.
/// If the `ptr` and `capacity` come from a `RawVec` created via `a`, then this is guaranteed.
/// If the `ptr` and `capacity` come from a `RawVec` created via `alloc`, then this is
/// guaranteed.
#[inline]
pub unsafe fn from_raw_parts_in(ptr: *mut T, capacity: usize, a: A) -> Self {
Self { ptr: unsafe { Unique::new_unchecked(ptr) }, cap: capacity, alloc: a }
pub unsafe fn from_raw_parts_in(ptr: *mut T, capacity: usize, alloc: A) -> Self {
Self { ptr: unsafe { Unique::new_unchecked(ptr) }, cap: capacity, alloc }
}

/// Gets a raw pointer to the start of the allocation. Note that this is
Expand Down
54 changes: 54 additions & 0 deletions library/core/src/ptr/non_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,24 @@ impl<T: ?Sized> NonNull<T> {
/// The resulting lifetime is bound to self so this behaves "as if"
/// it were actually an instance of T that is getting borrowed. If a longer
/// (unbound) lifetime is needed, use `&*my_ptr.as_ptr()`.
///
/// # Safety
///
/// When calling this method, you have to ensure that all of the following is true:
/// - `self` is properly aligned
/// - `self` must point to an initialized instance of T; in particular, the pointer must be
/// "dereferencable" in the sense defined [here].
///
/// This applies even if the result of this method is unused!
/// (The part about being initialized is not yet fully decided, but until
/// it is, the only safe approach is to ensure that they are indeed initialized.)
///
/// Additionally, the lifetime of `self` does not necessarily reflect the actual
/// lifetime of the data. *You* must enforce Rust's aliasing rules. In particular,
/// for the duration of this lifetime, the memory the pointer points to must not
/// get mutated (except inside `UnsafeCell`).
///
/// [here]: crate::ptr#safety
#[stable(feature = "nonnull", since = "1.25.0")]
#[inline]
pub unsafe fn as_ref(&self) -> &T {
Expand All @@ -130,6 +148,24 @@ impl<T: ?Sized> NonNull<T> {
/// The resulting lifetime is bound to self so this behaves "as if"
/// it were actually an instance of T that is getting borrowed. If a longer
/// (unbound) lifetime is needed, use `&mut *my_ptr.as_ptr()`.
///
/// # Safety
///
/// When calling this method, you have to ensure that all of the following is true:
/// - `self` is properly aligned
/// - `self` must point to an initialized instance of T; in particular, the pointer must be
/// "dereferenceable" in the sense defined [here].
///
/// This applies even if the result of this method is unused!
/// (The part about being initialized is not yet fully decided, but until
/// it is the only safe approach is to ensure that they are indeed initialized.)
///
/// Additionally, the lifetime of `self` does not necessarily reflect the actual
/// lifetime of the data. *You* must enforce Rust's aliasing rules. In particular,
/// for the duration of this lifetime, the memory this pointer points to must not
/// get accessed (read or written) through any other pointer.
///
/// [here]: crate::ptr#safety
#[stable(feature = "nonnull", since = "1.25.0")]
#[inline]
pub unsafe fn as_mut(&mut self) -> &mut T {
Expand Down Expand Up @@ -224,6 +260,24 @@ impl<T> NonNull<[T]> {
unsafe { NonNull::new_unchecked(self.as_ptr().as_mut_ptr()) }
}

/// Returns a raw pointer to the slice's buffer.
///
/// # Examples
///
/// ```rust
/// #![feature(slice_ptr_get, nonnull_slice_from_raw_parts)]
/// use std::ptr::NonNull;
///
/// let slice: NonNull<[i8]> = NonNull::slice_from_raw_parts(NonNull::dangling(), 3);
/// assert_eq!(slice.as_mut_ptr(), 1 as *mut i8);
/// ```
#[inline]
#[unstable(feature = "slice_ptr_get", issue = "74265")]
#[rustc_const_unstable(feature = "slice_ptr_get", issue = "74265")]
pub const fn as_mut_ptr(self) -> *mut T {
self.as_non_null_ptr().as_ptr()
}

/// Returns a raw pointer to an element or subslice, without doing bounds
/// checking.
///
Expand Down
20 changes: 18 additions & 2 deletions library/std/src/keyword_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -943,8 +943,7 @@ mod mod_keyword {}
/// Capture a [closure]'s environment by value.
///
/// `move` converts any variables captured by reference or mutable reference
/// to owned by value variables. The three [`Fn` trait]'s mirror the ways to capture
/// variables, when `move` is used, the closures is represented by the `FnOnce` trait.
/// to owned by value variables.
///
/// ```rust
/// let capture = "hello";
Expand All @@ -953,6 +952,23 @@ mod mod_keyword {}
/// };
/// ```
///
/// Note: `move` closures may still implement [`Fn`] or [`FnMut`], even though
/// they capture variables by `move`. This is because the traits implemented by
/// a closure type are determined by *what* the closure does with captured
/// values, not *how* it captures them:
///
/// ```rust
/// fn create_fn() -> impl Fn() {
/// let text = "Fn".to_owned();
///
/// move || println!("This is a: {}", text)
/// }
///
/// let fn_plain = create_fn();
///
/// fn_plain();
/// ```
///
/// `move` is often used when [threads] are involved.
///
/// ```rust
Expand Down
30 changes: 19 additions & 11 deletions library/std/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1232,10 +1232,10 @@ impl PathBuf {
/// ```
/// use std::path::{Path, PathBuf};
///
/// let mut p = PathBuf::from("/test/test.rs");
/// let mut p = PathBuf::from("/spirited/away.rs");
///
/// p.pop();
/// assert_eq!(Path::new("/test"), p);
/// assert_eq!(Path::new("/spirited"), p);
/// p.pop();
/// assert_eq!(Path::new("/"), p);
/// ```
Expand Down Expand Up @@ -1992,6 +1992,13 @@ impl Path {
/// assert_eq!(ancestors.next(), Some(Path::new("/foo")));
/// assert_eq!(ancestors.next(), Some(Path::new("/")));
/// assert_eq!(ancestors.next(), None);
///
/// let mut ancestors = Path::new("../foo/bar").ancestors();
/// assert_eq!(ancestors.next(), Some(Path::new("../foo/bar")));
/// assert_eq!(ancestors.next(), Some(Path::new("../foo")));
/// assert_eq!(ancestors.next(), Some(Path::new("..")));
/// assert_eq!(ancestors.next(), Some(Path::new("")));
/// assert_eq!(ancestors.next(), None);
/// ```
///
/// [`None`]: ../../std/option/enum.Option.html#variant.None
Expand Down Expand Up @@ -2053,8 +2060,9 @@ impl Path {
/// assert_eq!(path.strip_prefix("/test/"), Ok(Path::new("haha/foo.txt")));
/// assert_eq!(path.strip_prefix("/test/haha/foo.txt"), Ok(Path::new("")));
/// assert_eq!(path.strip_prefix("/test/haha/foo.txt/"), Ok(Path::new("")));
/// assert_eq!(path.strip_prefix("test").is_ok(), false);
/// assert_eq!(path.strip_prefix("/haha").is_ok(), false);
///
/// assert!(path.strip_prefix("test").is_err());
/// assert!(path.strip_prefix("/haha").is_err());
///
/// let prefix = PathBuf::from("/test/");
/// assert_eq!(path.strip_prefix(prefix), Ok(Path::new("haha/foo.txt")));
Expand Down Expand Up @@ -2140,9 +2148,8 @@ impl Path {
/// ```
/// use std::path::Path;
///
/// let path = Path::new("foo.rs");
///
/// assert_eq!("foo", path.file_stem().unwrap());
/// assert_eq!("foo", Path::new("foo.rs").file_stem().unwrap());
/// assert_eq!("foo.tar", Path::new("foo.tar.gz").file_stem().unwrap());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn file_stem(&self) -> Option<&OsStr> {
Expand All @@ -2166,9 +2173,8 @@ impl Path {
/// ```
/// use std::path::Path;
///
/// let path = Path::new("foo.rs");
///
/// assert_eq!("rs", path.extension().unwrap());
/// assert_eq!("rs", Path::new("foo.rs").extension().unwrap());
/// assert_eq!("gz", Path::new("foo.tar.gz").extension().unwrap());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn extension(&self) -> Option<&OsStr> {
Expand Down Expand Up @@ -2247,6 +2253,8 @@ impl Path {
///
/// let path = Path::new("foo.tar.gz");
/// assert_eq!(path.with_extension(""), PathBuf::from("foo.tar"));
/// assert_eq!(path.with_extension("xz"), PathBuf::from("foo.tar.xz"));
/// assert_eq!(path.with_extension("").with_extension("txt"), PathBuf::from("foo.txt"));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn with_extension<S: AsRef<OsStr>>(&self, extension: S) -> PathBuf {
Expand Down Expand Up @@ -2473,7 +2481,7 @@ impl Path {
///
/// ```no_run
/// use std::path::Path;
/// assert_eq!(Path::new("does_not_exist.txt").exists(), false);
/// assert!(!Path::new("does_not_exist.txt").exists());
/// ```
///
/// # See Also
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/hermit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub unsafe extern "C" fn runtime_entry(
argv: *const *const c_char,
env: *const *const c_char,
) -> ! {
use crate::sys::hermit::fast_thread_local::run_dtors;
use crate::sys::hermit::thread_local_dtor::run_dtors;
extern "C" {
fn main(argc: isize, argv: *const *const c_char) -> i32;
}
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/hermit/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::ffi::CStr;
use crate::io;
use crate::mem;
use crate::sys::hermit::abi;
use crate::sys::hermit::fast_thread_local::run_dtors;
use crate::sys::hermit::thread_local_dtor::run_dtors;
use crate::time::Duration;

pub type Tid = abi::Tid;
Expand Down
43 changes: 13 additions & 30 deletions src/librustc_error_codes/error_codes/E0271.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,6 @@ Erroneous code example:
```compile_fail,E0271
trait Trait { type AssociatedType; }

fn foo<T>(t: T) where T: Trait<AssociatedType=u32> {
println!("in foo");
}

impl Trait for i8 { type AssociatedType = &'static str; }

foo(3_i8);
```

This is because of a type mismatch between the associated type of some
trait (e.g., `T::Bar`, where `T` implements `trait Quux { type Bar; }`)
and another type `U` that is required to be equal to `T::Bar`, but is not.
Examples follow.

Here is that same example again, with some explanatory comments:

```compile_fail,E0271
trait Trait { type AssociatedType; }

fn foo<T>(t: T) where T: Trait<AssociatedType=u32> {
// ~~~~~~~~ ~~~~~~~~~~~~~~~~~~
// | |
Expand Down Expand Up @@ -56,11 +37,9 @@ foo(3_i8);
// therefore the type-checker complains with this error code.
```

To avoid those issues, you have to make the types match correctly.
So we can fix the previous examples like this:

The issue can be resolved by changing the associated type:
1) in the `foo` implementation:
```
// Basic Example:
trait Trait { type AssociatedType; }

fn foo<T>(t: T) where T: Trait<AssociatedType = &'static str> {
Expand All @@ -70,13 +49,17 @@ fn foo<T>(t: T) where T: Trait<AssociatedType = &'static str> {
impl Trait for i8 { type AssociatedType = &'static str; }

foo(3_i8);
```

// For-Loop Example:
let vs = vec![1, 2, 3, 4];
for v in &vs {
match v {
&1 => {}
_ => {}
}
2) in the `Trait` implementation for `i8`:
```
trait Trait { type AssociatedType; }

fn foo<T>(t: T) where T: Trait<AssociatedType = u32> {
println!("in foo");
}

impl Trait for i8 { type AssociatedType = u32; }

foo(3_i8);
```
4 changes: 2 additions & 2 deletions src/librustc_error_codes/error_codes/E0502.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Erroneous code example:
```compile_fail,E0502
fn bar(x: &mut i32) {}
fn foo(a: &mut i32) {
let ref y = a; // a is borrowed as immutable.
let y = &a; // a is borrowed as immutable.
bar(a); // error: cannot borrow `*a` as mutable because `a` is also borrowed
// as immutable
println!("{}", y);
Expand All @@ -19,7 +19,7 @@ variable before trying to access it mutably:
fn bar(x: &mut i32) {}
fn foo(a: &mut i32) {
bar(a);
let ref y = a; // ok!
let y = &a; // ok!
println!("{}", y);
}
```
Expand Down
22 changes: 18 additions & 4 deletions src/librustc_error_codes/error_codes/E0750.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
Negative impls cannot be default impls. A default impl supplies
default values for the items within to be used by other impls, whereas
a negative impl declares that there are no other impls. These don't
make sense to combine.
A negative impl was made default impl.

Erroneous code example:

```compile_fail,E0750
# #![feature(negative_impls)]
# #![feature(specialization)]
trait MyTrait {
type Foo;
}

default impl !MyTrait for u32 {} // error!
# fn main() {}
```

Negative impls cannot be default impls. A default impl supplies default values
for the items within to be used by other impls, whereas a negative impl declares
that there are no other impls. Combining it does not make sense.
2 changes: 1 addition & 1 deletion src/librustc_feature/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ declare_features! (
(active, const_fn_transmute, "1.46.0", Some(53605), None),

/// The smallest useful subset of `const_generics`.
(active, min_const_generics, "1.46.0", Some(74878), None),
(active, min_const_generics, "1.47.0", Some(74878), None),

// -------------------------------------------------------------------------
// feature-group-end: actual feature gates
Expand Down
3 changes: 1 addition & 2 deletions src/tools/tidy/src/error_codes_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ const EXEMPTED_FROM_TEST: &[&str] = &[
];

// Some error codes don't have any tests apparently...
const IGNORE_EXPLANATION_CHECK: &[&str] =
&["E0570", "E0601", "E0602", "E0639", "E0729", "E0749", "E0750"];
const IGNORE_EXPLANATION_CHECK: &[&str] = &["E0570", "E0601", "E0602", "E0639", "E0729", "E0749"];

fn check_error_code_explanation(
f: &str,
Expand Down