Skip to content

Rollup of 10 pull requests #25887

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

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
16334e5
Add a missing space to the Glossary page of TRPL
maxjacobson May 26, 2015
d0e6396
Document #[repr] on non-C-like enums
May 20, 2015
15ab481
removed lonely closing parenthesis
azerupi May 28, 2015
15aeea5
Corrected typo
azerupi May 28, 2015
f607440
Update E0015 explanation, fix E0053.
May 27, 2015
eb15030
Add error explanations for E0040, E0087, E0378, E0379, E0394.
May 27, 2015
19cb2a7
add newline before list in functions-and-methods
dcampbell24 Feb 14, 2015
0670651
Make adjancent code examples more similar
frewsxcv Feb 21, 2015
4d90b4d
Update let.md -- follow whitespace style guideline
dcampbell24 Mar 30, 2015
31a007a
remove extra space from "over" code as well
dcampbell24 Mar 30, 2015
d0744ba
Fix mistake: "to to" -> "to"
nliberg May 23, 2015
adac861
Fix link to newtypes page
nliberg May 23, 2015
7e78e70
Convert mutable statics error to have error code and add explanation.
May 28, 2015
3640354
Revise E0015 according to feedback.
May 29, 2015
fdf3ce7
Change E0015 and E0378 explanations to link to text of RFC 911, not r…
May 29, 2015
deb4948
remove the last mention of IoResult
tshepang May 29, 2015
5e94187
Add syntax for multiple lifetimes
steveklabnik May 29, 2015
81a413b
trpl: eight sections, not seven
nhowell May 29, 2015
8746b1a
Improve mem::forget documentation
tringenbach May 28, 2015
e344792
Rollup merge of #25651 - bluss:doc-enum-repr, r=alexcrichton
steveklabnik May 29, 2015
233ab2d
Rollup merge of #25788 - maxjacobson:add-missing-space-to-glossary, r…
steveklabnik May 29, 2015
e7fc4ad
Rollup merge of #25861 - tringenbach:master, r=steveklabnik
steveklabnik May 29, 2015
070ac2c
Rollup merge of #25864 - azerupi:patch-1, r=alexcrichton
steveklabnik May 29, 2015
f2ab010
Rollup merge of #25865 - azerupi:patch-2, r=alexcrichton
steveklabnik May 29, 2015
2f6dc44
Rollup merge of #25866 - jooert:update_guidelines, r=steveklabnik
steveklabnik May 29, 2015
ab09557
Rollup merge of #25873 - nham:update_E0015, r=Aatch
steveklabnik May 29, 2015
0f4b980
Rollup merge of #25876 - tshepang:patch-3, r=steveklabnik
steveklabnik May 29, 2015
e84b816
Rollup merge of #25883 - steveklabnik:gh25417, r=alexcrichton
steveklabnik May 29, 2015
72a8c4c
Rollup merge of #25886 - nhowell:patch-1, r=steveklabnik
steveklabnik May 29, 2015
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
13 changes: 7 additions & 6 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1892,12 +1892,13 @@ interpreted:

On `enum`s:

- `repr` - on C-like enums, this sets the underlying type used for
representation. Takes one argument, which is the primitive
type this enum should be represented for, or `C`, which specifies that it
should be the default `enum` size of the C ABI for that platform. Note that
enum representation in C is undefined, and this may be incorrect when the C
code is compiled with certain flags.
- `repr` - this sets the underlying type used for representation of the
discriminant. Takes one argument, which is the primitive type this enum
should be represented as, or `C`, which specifies that it should be the
default `enum` size of the C ABI for that platform. Note that enum
representation in C is implementation defined, and this may be incorrect when
the C code is compiled with certain flags. The representation attribute
inhibits elision of the enum discriminant in layout optimizations.

On `struct`s:

Expand Down
1 change: 1 addition & 0 deletions src/doc/style/features/functions-and-methods/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ for any operation that is clearly associated with a particular
type.

Methods have numerous advantages over functions:

* They do not need to be imported or qualified to be used: all you
need is a value of the appropriate type.
* Their invocation performs autoborrowing (including mutable borrows).
Expand Down
2 changes: 1 addition & 1 deletion src/doc/style/features/functions-and-methods/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fn foo(a: u8) { ... }
Note that
[`ascii::Ascii`](http://static.rust-lang.org/doc/master/std/ascii/struct.Ascii.html)
is a _wrapper_ around `u8` that guarantees the highest bit is zero; see
[newtype patterns]() for more details on creating typesafe wrappers.
[newtype patterns](../types/newtype.md) for more details on creating typesafe wrappers.

Static enforcement usually comes at little run-time cost: it pushes the
costs to the boundaries (e.g. when a `u8` is first converted into an
Expand Down
8 changes: 4 additions & 4 deletions src/doc/style/features/let.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Prefer

```rust
let foo = match bar {
Baz => 0,
Baz => 0,
Quux => 1
};
```
Expand All @@ -44,7 +44,7 @@ over
```rust
let foo;
match bar {
Baz => {
Baz => {
foo = 0;
}
Quux => {
Expand All @@ -61,8 +61,8 @@ conditional expression.
Prefer

```rust
s.iter().map(|x| x * 2)
.collect::<Vec<_>>()
let v = s.iter().map(|x| x * 2)
.collect::<Vec<_>>();
```

over
Expand Down
2 changes: 1 addition & 1 deletion src/doc/style/ownership/builders.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ If `T` is such a data structure, consider introducing a `T` _builder_:
value. When possible, choose a better name: e.g. `Command` is the builder for
`Process`.
2. The builder constructor should take as parameters only the data _required_ to
to make a `T`.
make a `T`.
3. The builder should offer a suite of convenient methods for configuration,
including setting up compound inputs (like slices) incrementally.
These methods should return `self` to allow chaining.
Expand Down
2 changes: 1 addition & 1 deletion src/doc/trpl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ language would.

[rust]: http://rust-lang.org

“The Rust Programming Language” is split into seven sections. This introduction
“The Rust Programming Language” is split into eight sections. This introduction
is the first. After this:

* [Getting started][gs] - Set up your computer for Rust development.
Expand Down
2 changes: 1 addition & 1 deletion src/doc/trpl/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ In the example above `x` and `y` have arity 2. `z` has arity 3.

When a compiler is compiling your program, it does a number of different
things. One of the things that it does is turn the text of your program into an
‘abstract syntax tree’, or‘AST’. This tree is a representation of the
‘abstract syntax tree’, or ‘AST’. This tree is a representation of the
structure of your program. For example, `2 + 3` can be turned into a tree:

```text
Expand Down
25 changes: 23 additions & 2 deletions src/doc/trpl/lifetimes.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,29 @@ x: &'a i32,
# }
```

uses it. So why do we need a lifetime here? We need to ensure that any
reference to the contained `i32` does not outlive the containing `Foo`.
uses it. So why do we need a lifetime here? We need to ensure that any reference
to a `Foo` cannot outlive the reference to an `i32` it contains.

If you have multiple references, you can use the same lifetime multiple times:

```rust
fn x_or_y<'a>(x: &'a str, y: &'a str) -> &'a str {
# x
# }
```

This says that `x` and `y` both are alive for the same scope, and that the
return value is also alive for that scope. If you wanted `x` and `y` to have
different lifetimes, you can use multiple lifetime parameters:

```rust
fn x_or_y<'a, 'b>(x: &'a str, y: &'b str) -> &'a str {
# x
# }
```

In this example, `x` and `y` have different valid scopes, but the return value
has the same lifetime as `x`.

## Thinking in scopes

Expand Down
2 changes: 1 addition & 1 deletion src/doc/trpl/method-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Functions are great, but if you want to call a bunch of them on some data, it
can be awkward. Consider this code:

```rust,ignore
baz(bar(foo)));
baz(bar(foo));
```

We would read this left-to right, and so we see ‘baz bar foo’. But this isn’t the
Expand Down
2 changes: 1 addition & 1 deletion src/doc/trpl/traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ fn bar<T, K>(x: T, y: K) where T: Clone, K: Clone + Debug {

fn main() {
foo("Hello", "world");
bar("Hello", "workd");
bar("Hello", "world");
}
```

Expand Down
54 changes: 48 additions & 6 deletions src/libcore/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,61 @@ pub use intrinsics::transmute;
/// * `mpsc::{Sender, Receiver}` cycles (they use `Arc` internally)
/// * Panicking destructors are likely to leak local resources
///
/// # When To Use
///
/// There's only a few reasons to use this function. They mainly come
/// up in unsafe code or FFI code.
///
/// * You have an uninitialized value, perhaps for performance reasons, and
/// need to prevent the destructor from running on it.
/// * You have two copies of a value (like `std::mem::swap`), but need the
/// destructor to only run once to prevent a double free.
/// * Transferring resources across FFI boundries.
///
/// # Example
///
/// ```rust,no_run
/// Leak some heap memory by never deallocating it.
///
/// ```rust
/// use std::mem;
/// use std::fs::File;
///
/// // Leak some heap memory by never deallocating it
/// let heap_memory = Box::new(3);
/// mem::forget(heap_memory);
/// ```
///
/// Leak an I/O object, never closing the file.
///
/// ```rust,no_run
/// use std::mem;
/// use std::fs::File;
///
/// // Leak an I/O object, never closing the file
/// let file = File::open("foo.txt").unwrap();
/// mem::forget(file);
/// ```
///
/// The swap function uses forget to good effect.
///
/// ```rust
/// use std::mem;
/// use std::ptr;
///
/// fn swap<T>(x: &mut T, y: &mut T) {
/// unsafe {
/// // Give ourselves some scratch space to work with
/// let mut t: T = mem::uninitialized();
///
/// // Perform the swap, `&mut` pointers never alias
/// ptr::copy_nonoverlapping(&*x, &mut t, 1);
/// ptr::copy_nonoverlapping(&*y, x, 1);
/// ptr::copy_nonoverlapping(&t, y, 1);
///
/// // y and t now point to the same thing, but we need to completely
/// // forget `t` because we do not want to run the destructor for `T`
/// // on its value, which is still owned somewhere outside this function.
/// mem::forget(t);
/// }
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn forget<T>(t: T) {
unsafe { intrinsics::forget(t) }
Expand Down Expand Up @@ -267,8 +308,9 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
ptr::copy_nonoverlapping(&*y, x, 1);
ptr::copy_nonoverlapping(&t, y, 1);

// y and t now point to the same thing, but we need to completely forget `t`
// because it's no longer relevant.
// y and t now point to the same thing, but we need to completely
// forget `t` because we do not want to run the destructor for `T`
// on its value, which is still owned somewhere outside this function.
forget(t);
}
}
Expand Down
60 changes: 54 additions & 6 deletions src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,13 @@ const Y: i32 = A;
"##,

E0015: r##"
The only function calls allowed in static or constant expressions are enum
variant constructors or struct constructors (for unit or tuple structs). This
is because Rust currently does not support compile-time function execution.
The only functions that can be called in static or constant expressions are
`const` functions. Rust currently does not support more general compile-time
function execution.

See [RFC 911] for more details on the design of `const fn`s.

[RFC 911]: https://github.com/rust-lang/rfcs/blob/master/text/0911-const-fn.md
"##,

E0018: r##"
Expand Down Expand Up @@ -842,6 +846,53 @@ struct Foo<T: 'static> {
foo: &'static T
}
```
"##,

E0378: r##"
Method calls that aren't calls to inherent `const` methods are disallowed
in statics, constants, and constant functions.

For example:

```
const BAZ: i32 = Foo(25).bar(); // error, `bar` isn't `const`

struct Foo(i32);

impl Foo {
const fn foo(&self) -> i32 {
self.bar() // error, `bar` isn't `const`
}

fn bar(&self) -> i32 { self.0 }
}
```

For more information about `const fn`'s, see [RFC 911].

[RFC 911]: https://github.com/rust-lang/rfcs/blob/master/text/0911-const-fn.md
"##,

E0394: r##"
From [RFC 246]:

> It is illegal for a static to reference another static by value. It is
> required that all references be borrowed.

[RFC 246]: https://github.com/rust-lang/rfcs/pull/246
"##,

E0397: r##"
It is not allowed for a mutable static to allocate or have destructors. For
example:

```
// error: mutable statics are not allowed to have boxes
static mut FOO: Option<Box<usize>> = None;

// error: mutable statics are not allowed to have destructors
static mut BAR: Option<Vec<i32>> = None;
```
"##

}
Expand Down Expand Up @@ -891,9 +942,6 @@ register_diagnostics! {
E0315, // cannot invoke closure outside of its lifetime
E0316, // nested quantification of lifetimes
E0370, // discriminant overflow
E0378, // method calls limited to constant inherent methods
E0394, // cannot refer to other statics by value, use the address-of
// operator or a constant instead
E0395, // pointer comparison in const-expr
E0396 // pointer dereference in const-expr
}
6 changes: 3 additions & 3 deletions src/librustc/middle/check_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,13 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
let suffix = if tcontents.has_dtor() {
"destructors"
} else if tcontents.owns_owned() {
"owned pointers"
"boxes"
} else {
return
};

self.tcx.sess.span_err(e.span, &format!("mutable statics are not allowed \
to have {}", suffix));
span_err!(self.tcx.sess, e.span, E0397,
"mutable statics are not allowed to have {}", suffix);
}

fn check_static_type(&self, e: &ast::Expr) {
Expand Down
Loading