Merge branch 'master' into issue-69276

This commit is contained in:
csmoe 2020-05-18 08:46:24 +08:00
commit 2f311b07c8
589 changed files with 7983 additions and 3099 deletions

View file

@ -120,6 +120,7 @@ E0223: include_str!("./error_codes/E0223.md"),
E0224: include_str!("./error_codes/E0224.md"),
E0225: include_str!("./error_codes/E0225.md"),
E0226: include_str!("./error_codes/E0226.md"),
E0228: include_str!("./error_codes/E0228.md"),
E0229: include_str!("./error_codes/E0229.md"),
E0230: include_str!("./error_codes/E0230.md"),
E0231: include_str!("./error_codes/E0231.md"),
@ -435,6 +436,7 @@ E0750: include_str!("./error_codes/E0750.md"),
E0751: include_str!("./error_codes/E0751.md"),
E0752: include_str!("./error_codes/E0752.md"),
E0753: include_str!("./error_codes/E0753.md"),
E0754: include_str!("./error_codes/E0754.md"),
E0755: include_str!("./error_codes/E0755.md"),
;
// E0006, // merged with E0005
@ -483,7 +485,6 @@ E0755: include_str!("./error_codes/E0755.md"),
// E0218, // no associated type defined
// E0219, // associated type defined in higher-ranked supertrait
E0227, // ambiguous lifetime bound, explicit lifetime bound required
E0228, // explicit lifetime bound required
// E0233,
// E0234,
// E0235, // structure constructor specifies a structure of type but

View file

@ -0,0 +1,40 @@
The lifetime bound for this object type cannot be deduced from context and must
be specified.
Erroneous code example:
```compile_fail,E0228
trait Trait { }
struct TwoBounds<'a, 'b, T: Sized + 'a + 'b> {
x: &'a i32,
y: &'b i32,
z: T,
}
type Foo<'a, 'b> = TwoBounds<'a, 'b, dyn Trait>;
```
When a trait object is used as a type argument of a generic type, Rust will try
to infer its lifetime if unspecified. However, this isn't possible when the
containing type has more than one lifetime bound.
The above example can be resolved by either reducing the number of lifetime
bounds to one or by making the trait object lifetime explicit, like so:
```
trait Trait { }
struct TwoBounds<'a, 'b, T: Sized + 'a + 'b> {
x: &'a i32,
y: &'b i32,
z: T,
}
type Foo<'a, 'b> = TwoBounds<'a, 'b, dyn Trait + 'b>;
```
For more information, see [RFC 599] and its amendment [RFC 1156].
[RFC 599]: https://github.com/rust-lang/rfcs/blob/master/text/0599-default-object-bound.md
[RFC 1156]: https://github.com/rust-lang/rfcs/blob/master/text/1156-adjust-default-object-bounds.md

View file

@ -64,7 +64,7 @@ impl Trait for Foo {
}
```
The nightly feature [Arbintrary self types][AST] extends the accepted
The nightly feature [Arbitrary self types][AST] extends the accepted
set of receiver types to also include any type that can dereference to
`Self`:

View file

@ -7,7 +7,7 @@ Example of erroneous code:
# fn satisfied(n: usize) -> bool { n % 23 == 0 }
let result = while true {
if satisfied(i) {
break 2*i; // error: `break` with value from a `while` loop
break 2 * i; // error: `break` with value from a `while` loop
}
i += 1;
};
@ -22,9 +22,9 @@ Make sure `break value;` statements only occur in `loop` loops:
```
# let mut i = 1;
# fn satisfied(n: usize) -> bool { n % 23 == 0 }
let result = loop { // ok!
let result = loop { // This is now a "loop" loop.
if satisfied(i) {
break 2*i;
break 2 * i; // ok!
}
i += 1;
};

View file

@ -1,7 +1,4 @@
When matching against an exclusive range, the compiler verifies that the range
is non-empty. Exclusive range patterns include the start point but not the end
point, so this is equivalent to requiring the start of the range to be less
than the end of the range.
A lower range wasn't less than the upper range.
Erroneous code example:
@ -17,3 +14,8 @@ fn main() {
}
}
```
When matching against an exclusive range, the compiler verifies that the range
is non-empty. Exclusive range patterns include the start point but not the end
point, so this is equivalent to requiring the start of the range to be less
than the end of the range.

View file

@ -1,4 +1,4 @@
In a `fn` type, a lifetime appears only in the return type,
In a `fn` type, a lifetime appears only in the return type
and not in the arguments types.
Erroneous code example:
@ -10,8 +10,11 @@ fn main() {
}
```
To fix this issue, either use the lifetime in the arguments, or use
`'static`. Example:
The problem here is that the lifetime isn't contrained by any of the arguments,
making it impossible to determine how long it's supposed to live.
To fix this issue, either use the lifetime in the arguments, or use the
`'static` lifetime. Example:
```
fn main() {

View file

@ -1,5 +1,5 @@
A lifetime appears only in an associated-type binding,
and not in the input types to the trait.
A lifetime is only present in an associated-type binding, and not in the input
types to the trait.
Erroneous code example:

View file

@ -1,6 +1,8 @@
The value of `N` that was specified for `repr(align(N))` was not a power
of two, or was greater than 2^29.
Erroneous code example:
```compile_fail,E0589
#[repr(align(15))] // error: invalid `repr(align)` attribute: not a power of two
enum Foo {

View file

@ -0,0 +1,33 @@
An non-ascii identifier was used in an invalid context.
Erroneous code example:
```compile_fail,E0754
# #![feature(non_ascii_idents)]
mod řųśť;
// ^ error!
fn main() {}
```
```compile_fail,E0754
# #![feature(non_ascii_idents)]
#[no_mangle]
fn řųśť() {}
// ^ error!
fn main() {}
```
Non-ascii can be used as module names if it is inline
or a #\[path\] attribute is specified. For example:
```
# #![feature(non_ascii_idents)]
mod řųśť {
const IS_GREAT: bool = true;
}
fn main() {}
```

View file

@ -3,7 +3,7 @@ or `Self` that references lifetimes from a parent scope.
Erroneous code example:
```compile_fail,E0754,edition2018
```compile_fail,E0755,edition2018
struct S<'a>(&'a i32);
impl<'a> S<'a> {