Skip to content

Commit ef3fe25

Browse files
committed
Auto merge of #28798 - steveklabnik:rollup, r=steveklabnik
- Successful merges: #28554, #28686, #28786, #28788, #28791, #28797 - Failed merges:
2 parents 168a23e + db27dca commit ef3fe25

File tree

7 files changed

+155
-9
lines changed

7 files changed

+155
-9
lines changed

src/doc/trpl/bibliography.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ Language](http://www.cs.indiana.edu/~eholk/papers/hips2013.pdf). Early GPU work
6161
Rust](http://scialex.github.io/reenix.pdf). Undergrad paper by Alex
6262
Light.
6363
* [Evaluation of performance and productivity metrics of potential
64-
programming languages in the HPC environment](). Bachelor's thesis by
65-
Florian Wilkens. Compares C, Go and Rust.
64+
programming languages in the HPC environment]
65+
(http://octarineparrot.com/assets/mrfloya-thesis-ba.pdf).
66+
Bachelor's thesis by Florian Wilkens. Compares C, Go and Rust.
6667
* [Nom, a byte oriented, streaming, zero copy, parser combinators library
6768
in Rust](http://spw15.langsec.org/papers/couprie-nom.pdf). By
6869
Geoffroy Couprie, research for VLC.
@@ -77,4 +78,4 @@ Language](http://www.cs.indiana.edu/~eholk/papers/hips2013.pdf). Early GPU work
7778
Farnstrand's master's thesis.
7879
* [Session Types for
7980
Rust](http://munksgaard.me/papers/laumann-munksgaard-larsen.pdf). Philip
80-
Munksgaard's master's thesis. Research for Servo.
81+
Munksgaard's master's thesis. Research for Servo.

src/libcollections/vec.rs

+75
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,81 @@ use super::range::RangeArgument;
148148
/// if the vector's length is increased to 11, it will have to reallocate, which
149149
/// can be slow. For this reason, it is recommended to use `Vec::with_capacity`
150150
/// whenever possible to specify how big the vector is expected to get.
151+
///
152+
/// # Guarantees
153+
///
154+
/// Due to its incredibly fundamental nature, Vec makes a lot of guarantees
155+
/// about its design. This ensures that it's as low-overhead as possible in
156+
/// the general case, and can be correctly manipulated in primitive ways
157+
/// by unsafe code. Note that these guarantees refer to an unqualified `Vec<T>`.
158+
/// If additional type parameters are added (e.g. to support custom allocators),
159+
/// overriding their defaults may change the behavior.
160+
///
161+
/// Most fundamentally, Vec is and always will be a (pointer, capacity, length)
162+
/// triplet. No more, no less. The order of these fields is completely
163+
/// unspecified, and you should use the appropriate methods to modify these.
164+
/// The pointer will never be null, so this type is null-pointer-optimized.
165+
///
166+
/// However, the pointer may not actually point to allocated memory. In particular,
167+
/// if you construct a Vec with capacity 0 via `Vec::new()`, `vec![]`,
168+
/// `Vec::with_capacity(0)`, or by calling `shrink_to_fit()` on an empty Vec, it
169+
/// will not allocate memory. Similarly, if you store zero-sized types inside
170+
/// a Vec, it will not allocate space for them. *Note that in this case the
171+
/// Vec may not report a `capacity()` of 0*. Vec will allocate if and only
172+
/// if `mem::size_of::<T>() * capacity() > 0`. In general, Vec's allocation
173+
/// details are subtle enough that it is strongly recommended that you only
174+
/// free memory allocated by a Vec by creating a new Vec and dropping it.
175+
///
176+
/// If a Vec *has* allocated memory, then the memory it points to is on the heap
177+
/// (as defined by the allocator Rust is configured to use by default), and its
178+
/// pointer points to `len()` initialized elements in order (what you would see
179+
/// if you coerced it to a slice), followed by `capacity() - len()` logically
180+
/// uninitialized elements.
181+
///
182+
/// Vec will never perform a "small optimization" where elements are actually
183+
/// stored on the stack for two reasons:
184+
///
185+
/// * It would make it more difficult for unsafe code to correctly manipulate
186+
/// a Vec. The contents of a Vec wouldn't have a stable address if it were
187+
/// only moved, and it would be more difficult to determine if a Vec had
188+
/// actually allocated memory.
189+
///
190+
/// * It would penalize the general case, incurring an additional branch
191+
/// on every access.
192+
///
193+
/// Vec will never automatically shrink itself, even if completely empty. This
194+
/// ensures no unnecessary allocations or deallocations occur. Emptying a Vec
195+
/// and then filling it back up to the same `len()` should incur no calls to
196+
/// the allocator. If you wish to free up unused memory, use `shrink_to_fit`.
197+
///
198+
/// `push` and `insert` will never (re)allocate if the reported capacity is
199+
/// sufficient. `push` and `insert` *will* (re)allocate if `len() == capacity()`.
200+
/// That is, the reported capacity is completely accurate, and can be relied on.
201+
/// It can even be used to manually free the memory allocated by a Vec if
202+
/// desired. Bulk insertion methods *may* reallocate, even when not necessary.
203+
///
204+
/// Vec does not guarantee any particular growth strategy when reallocating
205+
/// when full, nor when `reserve` is called. The current strategy is basic
206+
/// and it may prove desirable to use a non-constant growth factor. Whatever
207+
/// strategy is used will of course guarantee `O(1)` amortized `push`.
208+
///
209+
/// `vec![x; n]`, `vec![a, b, c, d]`, and `Vec::with_capacity(n)`, will all
210+
/// produce a Vec with exactly the requested capacity. If `len() == capacity()`,
211+
/// (as is the case for the `vec!` macro), then a `Vec<T>` can be converted
212+
/// to and from a `Box<[T]>` without reallocating or moving the elements.
213+
///
214+
/// Vec will not specifically overwrite any data that is removed from it,
215+
/// but also won't specifically preserve it. Its uninitialized memory is
216+
/// scratch space that it may use however it wants. It will generally just do
217+
/// whatever is most efficient or otherwise easy to implement. Do not rely on
218+
/// removed data to be erased for security purposes. Even if you drop a Vec, its
219+
/// buffer may simply be reused by another Vec. Even if you zero a Vec's memory
220+
/// first, that may not actually happen because the optimizer does not consider
221+
/// this a side-effect that must be preserved.
222+
///
223+
/// Vec does not currently guarantee the order in which elements are dropped
224+
/// (the order has changed in the past, and may change again).
225+
///
151226
#[unsafe_no_drop_flag]
152227
#[stable(feature = "rust1", since = "1.0.0")]
153228
pub struct Vec<T> {

src/librustc/middle/const_eval.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ pub enum ErrKind {
367367
ShiftRightWithOverflow,
368368
MissingStructField,
369369
NonConstPath,
370+
UnresolvedPath,
370371
ExpectedConstTuple,
371372
ExpectedConstStruct,
372373
TupleIndexOutOfBounds,
@@ -403,7 +404,8 @@ impl ConstEvalErr {
403404
ShiftLeftWithOverflow => "attempted left shift with overflow".into_cow(),
404405
ShiftRightWithOverflow => "attempted right shift with overflow".into_cow(),
405406
MissingStructField => "nonexistent struct field".into_cow(),
406-
NonConstPath => "non-constant path in constant expr".into_cow(),
407+
NonConstPath => "non-constant path in constant expression".into_cow(),
408+
UnresolvedPath => "unresolved path in constant expression".into_cow(),
407409
ExpectedConstTuple => "expected constant tuple".into_cow(),
408410
ExpectedConstStruct => "expected constant struct".into_cow(),
409411
TupleIndexOutOfBounds => "tuple index out of bounds".into_cow(),
@@ -895,7 +897,20 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
895897
}
896898
}
897899
hir::ExprPath(..) => {
898-
let opt_def = tcx.def_map.borrow().get(&e.id).map(|d| d.full_def());
900+
let opt_def = if let Some(def) = tcx.def_map.borrow().get(&e.id) {
901+
// After type-checking, def_map contains definition of the
902+
// item referred to by the path. During type-checking, it
903+
// can contain the raw output of path resolution, which
904+
// might be a partially resolved path.
905+
// FIXME: There's probably a better way to make sure we don't
906+
// panic here.
907+
if def.depth != 0 {
908+
signal!(e, UnresolvedPath);
909+
}
910+
Some(def.full_def())
911+
} else {
912+
None
913+
};
899914
let (const_expr, const_ty) = match opt_def {
900915
Some(def::DefConst(def_id)) => {
901916
if let Some(node_id) = tcx.map.as_local_node_id(def_id) {

src/librustc_resolve/diagnostics.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,29 @@ match Something::NotFoo {
609609
```
610610
"##,
611611

612+
E0422: r##"
613+
You are trying to use an identifier that is either undefined or not a
614+
struct. For instance:
615+
```
616+
fn main () {
617+
let x = Foo { x: 1, y: 2 };
618+
}
619+
```
620+
621+
In this case, `Foo` is undefined, so it inherently isn't anything, and
622+
definitely not a struct.
623+
624+
```
625+
fn main () {
626+
let foo = 1;
627+
let x = foo { x: 1, y: 2 };
628+
}
629+
```
630+
631+
In this case, `foo` is defined, but is not a struct, so Rust can't use
632+
it as one.
633+
"##,
634+
612635
E0423: r##"
613636
A `struct` variant name was used like a function name. Example of
614637
erroneous code:
@@ -888,7 +911,6 @@ register_diagnostics! {
888911
E0418, // is not an enum variant, struct or const
889912
E0420, // is not an associated const
890913
E0421, // unresolved associated const
891-
E0422, // does not name a structure
892914
E0427, // cannot use `ref` binding mode with ...
893915
E0429, // `self` imports are only allowed within a { } list
894916
E0434, // can't capture dynamic environment in a fn item

src/libstd/ffi/c_str.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl CString {
206206
/// Retakes ownership of a CString that was transferred to C.
207207
///
208208
/// The only appropriate argument is a pointer obtained by calling
209-
/// `into_ptr`. The length of the string will be recalculated
209+
/// `into_raw`. The length of the string will be recalculated
210210
/// using the pointer.
211211
#[unstable(feature = "cstr_memory2", reason = "recently added",
212212
issue = "27769")]
@@ -245,11 +245,11 @@ impl CString {
245245
/// Transfers ownership of the string to a C caller.
246246
///
247247
/// The pointer must be returned to Rust and reconstituted using
248-
/// `from_ptr` to be properly deallocated. Specifically, one
248+
/// `from_raw` to be properly deallocated. Specifically, one
249249
/// should *not* use the standard C `free` function to deallocate
250250
/// this string.
251251
///
252-
/// Failure to call `from_ptr` will lead to a memory leak.
252+
/// Failure to call `from_raw` will lead to a memory leak.
253253
#[stable(feature = "cstr_memory", since = "1.4.0")]
254254
pub fn into_raw(self) -> *mut libc::c_char {
255255
Box::into_raw(self.inner) as *mut libc::c_char
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
fn f(a: [u8; u32::DOESNOTEXIST]) {}
13+
//~^ ERROR unresolved path in constant expression
14+
}

src/test/run-pass/issue-25439.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct Helper<'a, F: 'a>(&'a F);
12+
13+
fn fix<F>(f: F) -> i32 where F: Fn(Helper<F>, i32) -> i32 {
14+
f(Helper(&f), 8)
15+
}
16+
17+
fn main() {
18+
fix(|_, x| x);
19+
}

0 commit comments

Comments
 (0)