Skip to content

Commit 567937d

Browse files
committed
Auto merge of #32126 - steveklabnik:rollup, r=steveklabnik
Rollup of 7 pull requests - Successful merges: #31772, #32083, #32084, #32092, #32099, #32103, #32115 - Failed merges:
2 parents eabfc16 + 33fe4d1 commit 567937d

File tree

7 files changed

+105
-42
lines changed

7 files changed

+105
-42
lines changed

src/doc/book/ownership.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn foo() {
5151
}
5252
```
5353

54-
When `v` comes into scope, a new [vector] is created on [the stack][stack],
54+
When `v` comes into scope, a new [vector][vectors] is created on [the stack][stack],
5555
and it allocates space on [the heap][heap] for its elements. When `v` goes out
5656
of scope at the end of `foo()`, Rust will clean up everything related to the
5757
vector, even the heap-allocated memory. This happens deterministically, at the

src/doc/book/references-and-borrowing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Before we get to the details, two important notes about the ownership system.
2323
Rust has a focus on safety and speed. It accomplishes these goals through many
2424
‘zero-cost abstractions’, which means that in Rust, abstractions cost as little
2525
as possible in order to make them work. The ownership system is a prime example
26-
of a zero cost abstraction. All of the analysis we’ll talk about in this guide
26+
of a zero-cost abstraction. All of the analysis we’ll talk about in this guide
2727
is _done at compile time_. You do not pay any run-time cost for any of these
2828
features.
2929

src/doc/book/syntax-index.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,23 @@
4343
* `!` (`!expr`): bitwise or logical complement. Overloadable (`Not`).
4444
* `!=` (`var != expr`): nonequality comparison. Overloadable (`PartialEq`).
4545
* `%` (`expr % expr`): arithmetic remainder. Overloadable (`Rem`).
46-
* `%=` (`var %= expr`): arithmetic remainder & assignment.
46+
* `%=` (`var %= expr`): arithmetic remainder & assignment. Overloadable (`RemAssign`).
4747
* `&` (`expr & expr`): bitwise and. Overloadable (`BitAnd`).
4848
* `&` (`&expr`): borrow. See [References and Borrowing].
4949
* `&` (`&type`, `&mut type`, `&'a type`, `&'a mut type`): borrowed pointer type. See [References and Borrowing].
50-
* `&=` (`var &= expr`): bitwise and & assignment.
50+
* `&=` (`var &= expr`): bitwise and & assignment. Overloadable (`BitAndAssign`).
5151
* `&&` (`expr && expr`): logical and.
5252
* `*` (`expr * expr`): arithmetic multiplication. Overloadable (`Mul`).
5353
* `*` (`*expr`): dereference.
5454
* `*` (`*const type`, `*mut type`): raw pointer. See [Raw Pointers].
55-
* `*=` (`var *= expr`): arithmetic multiplication & assignment.
55+
* `*=` (`var *= expr`): arithmetic multiplication & assignment. Overloadable (`MulAssign`).
5656
* `+` (`expr + expr`): arithmetic addition. Overloadable (`Add`).
5757
* `+` (`trait + trait`, `'a + trait`): compound type constraint. See [Traits (Multiple Trait Bounds)].
58-
* `+=` (`var += expr`): arithmetic addition & assignment.
58+
* `+=` (`var += expr`): arithmetic addition & assignment. Overloadable (`AddAssign`).
5959
* `,`: argument and element separator. See [Attributes], [Functions], [Structs], [Generics], [Match], [Closures], [Crates and Modules (Importing Modules with `use`)].
6060
* `-` (`expr - expr`): arithmetic subtraction. Overloadable (`Sub`).
6161
* `-` (`- expr`): arithmetic negation. Overloadable (`Neg`).
62-
* `-=` (`var -= expr`): arithmetic subtraction & assignment.
62+
* `-=` (`var -= expr`): arithmetic subtraction & assignment. Overloadable (`SubAssign`).
6363
* `->` (`fn(…) -> type`, `|…| -> type`): function and closure return type. See [Functions], [Closures].
6464
* `-> !` (`fn(…) -> !`, `|…| -> !`): diverging function or closure. See [Diverging Functions].
6565
* `.` (`expr.ident`): member access. See [Structs], [Method Syntax].
@@ -69,14 +69,14 @@
6969
* `...` (`...expr`, `expr...expr`) *in an expression*: inclusive range expression. See [Iterators].
7070
* `...` (`expr...expr`) *in a pattern*: inclusive range pattern. See [Patterns (Ranges)].
7171
* `/` (`expr / expr`): arithmetic division. Overloadable (`Div`).
72-
* `/=` (`var /= expr`): arithmetic division & assignment.
72+
* `/=` (`var /= expr`): arithmetic division & assignment. Overloadable (`DivAssign`).
7373
* `:` (`pat: type`, `ident: type`): constraints. See [Variable Bindings], [Functions], [Structs], [Traits].
7474
* `:` (`ident: expr`): struct field initializer. See [Structs].
7575
* `:` (`'a: loop {…}`): loop label. See [Loops (Loops Labels)].
7676
* `;`: statement and item terminator.
7777
* `;` (`[…; len]`): part of fixed-size array syntax. See [Primitive Types (Arrays)].
7878
* `<<` (`expr << expr`): left-shift. Overloadable (`Shl`).
79-
* `<<=` (`var <<= expr`): left-shift & assignment.
79+
* `<<=` (`var <<= expr`): left-shift & assignment. Overloadable (`ShlAssign`).
8080
* `<` (`expr < expr`): less-than comparison. Overloadable (`PartialOrd`).
8181
* `<=` (`var <= expr`): less-than or equal-to comparison. Overloadable (`PartialOrd`).
8282
* `=` (`var = expr`, `ident = type`): assignment/equivalence. See [Variable Bindings], [`type` Aliases], generic parameter defaults.
@@ -85,14 +85,14 @@
8585
* `>` (`expr > expr`): greater-than comparison. Overloadable (`PartialOrd`).
8686
* `>=` (`var >= expr`): greater-than or equal-to comparison. Overloadable (`PartialOrd`).
8787
* `>>` (`expr >> expr`): right-shift. Overloadable (`Shr`).
88-
* `>>=` (`var >>= expr`): right-shift & assignment.
88+
* `>>=` (`var >>= expr`): right-shift & assignment. Overloadable (`ShrAssign`).
8989
* `@` (`ident @ pat`): pattern binding. See [Patterns (Bindings)].
9090
* `^` (`expr ^ expr`): bitwise exclusive or. Overloadable (`BitXor`).
91-
* `^=` (`var ^= expr`): bitwise exclusive or & assignment.
91+
* `^=` (`var ^= expr`): bitwise exclusive or & assignment. Overloadable (`BitXorAssign`).
9292
* `|` (`expr | expr`): bitwise or. Overloadable (`BitOr`).
9393
* `|` (`pat | pat`): pattern alternatives. See [Patterns (Multiple patterns)].
9494
* `|` (`|…| expr`): closures. See [Closures].
95-
* `|=` (`var |= expr`): bitwise or & assignment.
95+
* `|=` (`var |= expr`): bitwise or & assignment. Overloadable (`BitOrAssign`).
9696
* `||` (`expr || expr`): logical or.
9797
* `_`: "ignored" pattern binding. See [Patterns (Ignoring bindings)].
9898

src/doc/reference.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,16 @@ type Point = (u8, u8);
11181118
let p: Point = (41, 68);
11191119
```
11201120

1121+
Currently a type alias to an enum type cannot be used to qualify the
1122+
constructors:
1123+
1124+
```
1125+
enum E { A }
1126+
type F = E;
1127+
let _: F = E::A; // OK
1128+
// let _: F = F::A; // Doesn't work
1129+
```
1130+
11211131
### Structs
11221132

11231133
A _struct_ is a nominal [struct type](#struct-types) defined with the
@@ -1195,18 +1205,24 @@ a = Animal::Cat { name: "Spotty".to_string(), weight: 2.7 };
11951205
In this example, `Cat` is a _struct-like enum variant_,
11961206
whereas `Dog` is simply called an enum variant.
11971207

1198-
Enums have a discriminant. You can assign them explicitly:
1208+
Each enum value has a _discriminant_ which is an integer associated to it. You
1209+
can specify it explicitly:
11991210

12001211
```
12011212
enum Foo {
12021213
Bar = 123,
12031214
}
12041215
```
12051216

1206-
If a discriminant isn't assigned, they start at zero, and add one for each
1217+
The right hand side of the specification is interpreted as an `isize` value,
1218+
but the compiler is allowed to use a smaller type in the actual memory layout.
1219+
The [`repr` attribute](#ffi-attributes) can be added in order to change
1220+
the type of the right hand side and specify the memory layout.
1221+
1222+
If a discriminant isn't specified, they start at zero, and add one for each
12071223
variant, in order.
12081224

1209-
You can cast an enum to get this value:
1225+
You can cast an enum to get its discriminant:
12101226

12111227
```
12121228
# enum Foo { Bar = 123 }

src/libcollections/fmt.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,20 +429,20 @@
429429
//! For example, these:
430430
//!
431431
//! ```
432-
//! // Hello {arg 0 (x)} is {arg 1 (0.01} with precision specified inline (5)}
432+
//! // Hello {arg 0 (x)} is {arg 1 (0.01) with precision specified inline (5)}
433433
//! println!("Hello {0} is {1:.5}", "x", 0.01);
434434
//!
435-
//! // Hello {arg 1 (x)} is {arg 2 (0.01} with precision specified in arg 0 (5)}
435+
//! // Hello {arg 1 (x)} is {arg 2 (0.01) with precision specified in arg 0 (5)}
436436
//! println!("Hello {1} is {2:.0$}", 5, "x", 0.01);
437437
//!
438-
//! // Hello {arg 0 (x)} is {arg 2 (0.01} with precision specified in arg 1 (5)}
438+
//! // Hello {arg 0 (x)} is {arg 2 (0.01) with precision specified in arg 1 (5)}
439439
//! println!("Hello {0} is {2:.1$}", "x", 5, 0.01);
440440
//!
441-
//! // Hello {next arg (x)} is {second of next two args (0.01} with precision
441+
//! // Hello {next arg (x)} is {second of next two args (0.01) with precision
442442
//! // specified in first of next two args (5)}
443443
//! println!("Hello {} is {:.*}", "x", 5, 0.01);
444444
//!
445-
//! // Hello {next arg (x)} is {arg 2 (0.01} with precision
445+
//! // Hello {next arg (x)} is {arg 2 (0.01) with precision
446446
//! // specified in its predecessor (5)}
447447
//! println!("Hello {} is {2:.*}", "x", 5, 0.01);
448448
//! ```

src/libcore/str/mod.rs

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,13 +1311,19 @@ mod traits {
13111311
}
13121312
}
13131313

1314+
/// Implements substring slicing with syntax `&self[begin .. end]`.
1315+
///
13141316
/// Returns a slice of the given string from the byte range
13151317
/// [`begin`..`end`).
13161318
///
13171319
/// This operation is `O(1)`.
13181320
///
1319-
/// Panics when `begin` and `end` do not point to valid characters
1320-
/// or point beyond the last character of the string.
1321+
/// # Panics
1322+
///
1323+
/// Panics if `begin` or `end` does not point to the starting
1324+
/// byte offset of a character (as defined by `is_char_boundary`).
1325+
/// Requires that `begin <= end` and `end <= len` where `len` is the
1326+
/// length of the string.
13211327
///
13221328
/// # Examples
13231329
///
@@ -1353,8 +1359,20 @@ mod traits {
13531359
}
13541360
}
13551361

1362+
/// Implements mutable substring slicing with syntax
1363+
/// `&mut self[begin .. end]`.
1364+
///
13561365
/// Returns a mutable slice of the given string from the byte range
13571366
/// [`begin`..`end`).
1367+
///
1368+
/// This operation is `O(1)`.
1369+
///
1370+
/// # Panics
1371+
///
1372+
/// Panics if `begin` or `end` does not point to the starting
1373+
/// byte offset of a character (as defined by `is_char_boundary`).
1374+
/// Requires that `begin <= end` and `end <= len` where `len` is the
1375+
/// length of the string.
13581376
#[stable(feature = "derefmut_for_string", since = "1.2.0")]
13591377
impl ops::IndexMut<ops::Range<usize>> for str {
13601378
#[inline]
@@ -1370,13 +1388,12 @@ mod traits {
13701388
}
13711389
}
13721390

1373-
/// Returns a slice of the string from the beginning to byte
1374-
/// `end`.
1391+
/// Implements substring slicing with syntax `&self[.. end]`.
13751392
///
1376-
/// Equivalent to `self[0 .. end]`.
1393+
/// Returns a slice of the string from the beginning to byte offset
1394+
/// `end`.
13771395
///
1378-
/// Panics when `end` does not point to a valid character, or is
1379-
/// out of bounds.
1396+
/// Equivalent to `&self[0 .. end]`.
13801397
#[stable(feature = "rust1", since = "1.0.0")]
13811398
impl ops::Index<ops::RangeTo<usize>> for str {
13821399
type Output = str;
@@ -1392,8 +1409,12 @@ mod traits {
13921409
}
13931410
}
13941411

1395-
/// Returns a mutable slice of the string from the beginning to byte
1412+
/// Implements mutable substring slicing with syntax `&mut self[.. end]`.
1413+
///
1414+
/// Returns a mutable slice of the string from the beginning to byte offset
13961415
/// `end`.
1416+
///
1417+
/// Equivalent to `&mut self[0 .. end]`.
13971418
#[stable(feature = "derefmut_for_string", since = "1.2.0")]
13981419
impl ops::IndexMut<ops::RangeTo<usize>> for str {
13991420
#[inline]
@@ -1407,12 +1428,12 @@ mod traits {
14071428
}
14081429
}
14091430

1410-
/// Returns a slice of the string from `begin` to its end.
1431+
/// Implements substring slicing with syntax `&self[begin ..]`.
14111432
///
1412-
/// Equivalent to `self[begin .. self.len()]`.
1433+
/// Returns a slice of the string from byte offset `begin`
1434+
/// to the end of the string.
14131435
///
1414-
/// Panics when `begin` does not point to a valid character, or is
1415-
/// out of bounds.
1436+
/// Equivalent to `&self[begin .. len]`.
14161437
#[stable(feature = "rust1", since = "1.0.0")]
14171438
impl ops::Index<ops::RangeFrom<usize>> for str {
14181439
type Output = str;
@@ -1428,7 +1449,12 @@ mod traits {
14281449
}
14291450
}
14301451

1431-
/// Returns a slice of the string from `begin` to its end.
1452+
/// Implements mutable substring slicing with syntax `&mut self[begin ..]`.
1453+
///
1454+
/// Returns a mutable slice of the string from byte offset `begin`
1455+
/// to the end of the string.
1456+
///
1457+
/// Equivalent to `&mut self[begin .. len]`.
14321458
#[stable(feature = "derefmut_for_string", since = "1.2.0")]
14331459
impl ops::IndexMut<ops::RangeFrom<usize>> for str {
14341460
#[inline]
@@ -1443,6 +1469,12 @@ mod traits {
14431469
}
14441470
}
14451471

1472+
/// Implements substring slicing with syntax `&self[..]`.
1473+
///
1474+
/// Returns a slice of the whole string. This operation can
1475+
/// never panic.
1476+
///
1477+
/// Equivalent to `&self[0 .. len]`.
14461478
#[stable(feature = "rust1", since = "1.0.0")]
14471479
impl ops::Index<ops::RangeFull> for str {
14481480
type Output = str;
@@ -1453,6 +1485,12 @@ mod traits {
14531485
}
14541486
}
14551487

1488+
/// Implements mutable substring slicing with syntax `&mut self[..]`.
1489+
///
1490+
/// Returns a mutable slice of the whole string. This operation can
1491+
/// never panic.
1492+
///
1493+
/// Equivalent to `&mut self[0 .. len]`.
14561494
#[stable(feature = "derefmut_for_string", since = "1.2.0")]
14571495
impl ops::IndexMut<ops::RangeFull> for str {
14581496
#[inline]

src/librustc_typeck/diagnostics.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,15 +1133,16 @@ enum Bad {
11331133
}
11341134
```
11351135
1136-
Here `X` will have already been assigned the discriminant 0 by the time `Y` is
1136+
Here `X` will have already been specified the discriminant 0 by the time `Y` is
11371137
encountered, so a conflict occurs.
11381138
"##,
11391139

11401140
E0082: r##"
1141-
The default type for enum discriminants is `isize`, but it can be adjusted by
1142-
adding the `repr` attribute to the enum declaration. This error indicates that
1143-
an integer literal given as a discriminant is not a member of the discriminant
1144-
type. For example:
1141+
When you specify enum discriminants with `=`, the compiler expects `isize`
1142+
values by default. Or you can add the `repr` attibute to the enum declaration
1143+
for an explicit choice of the discriminant type. In either cases, the
1144+
discriminant values must fall within a valid range for the expected type;
1145+
otherwise this error is raised. For example:
11451146
11461147
```compile_fail
11471148
#[repr(u8)]
@@ -1152,11 +1153,19 @@ enum Thing {
11521153
```
11531154
11541155
Here, 1024 lies outside the valid range for `u8`, so the discriminant for `A` is
1155-
invalid. You may want to change representation types to fix this, or else change
1156-
invalid discriminant values so that they fit within the existing type.
1156+
invalid. Here is another, more subtle example which depends on target word size:
11571157
1158-
Note also that without a representation manually defined, the compiler will
1159-
optimize by using the smallest integer type possible.
1158+
```compile_fail
1159+
enum DependsOnPointerSize {
1160+
A = 1 << 32
1161+
}
1162+
```
1163+
1164+
Here, `1 << 32` is interpreted as an `isize` value. So it is invalid for 32 bit
1165+
target (`target_pointer_width = "32"`) but valid for 64 bit target.
1166+
1167+
You may want to change representation types to fix this, or else change invalid
1168+
discriminant values so that they fit within the existing type.
11601169
"##,
11611170

11621171
E0084: r##"

0 commit comments

Comments
 (0)