Skip to content

Commit acb3aa0

Browse files
committed
Auto merge of #25175 - steveklabnik:rollup, r=steveklabnik
- Successful merges: #24576, #24966, #25052, #25131, #25137, #25138, #25139, #25141, #25142, #25144, #25146, #25148, #25154, #25156, #25160, #25173 - Failed merges:
2 parents 9560754 + 5ac5203 commit acb3aa0

31 files changed

+199
-128
lines changed

src/doc/complement-design-faq.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ representation as a primitive. This allows using Rust `enum`s in FFI where C
3939
`enum`s are also used, for most use cases. The attribute can also be applied
4040
to `struct`s to get the same layout as a C struct would.
4141

42-
[repr]: reference.html#miscellaneous-attributes
42+
[repr]: reference.html#ffi-attributes
4343

4444
## There is no GC
4545

src/doc/reference.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -1867,13 +1867,12 @@ macro scope.
18671867
lower to the target's SIMD instructions, if any; the `simd` feature gate
18681868
is necessary to use this attribute.
18691869
- `static_assert` - on statics whose type is `bool`, terminates compilation
1870-
with an error if it is not initialized to `true`.
1871-
- `unsafe_destructor` - allow implementations of the "drop" language item
1872-
where the type it is implemented for does not implement the "send" language
1873-
item; the `unsafe_destructor` feature gate is needed to use this attribute
1870+
with an error if it is not initialized to `true`. To use this, the `static_assert`
1871+
feature gate must be enabled.
18741872
- `unsafe_no_drop_flag` - on structs, remove the flag that prevents
18751873
destructors from being run twice. Destructors might be run multiple times on
1876-
the same object with this attribute.
1874+
the same object with this attribute. To use this, the `unsafe_no_drop_flag` feature
1875+
gate must be enabled.
18771876
- `doc` - Doc comments such as `/// foo` are equivalent to `#[doc = "foo"]`.
18781877
- `rustc_on_unimplemented` - Write a custom note to be shown along with the error
18791878
when the trait is found to be unimplemented on a type.

src/doc/trpl/guessing-game.md

+18-15
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ fn main() {
8282
8383
let mut guess = String::new();
8484
85-
let input = io::stdin().read_line(&mut guess)
85+
io::stdin().read_line(&mut guess)
8686
.ok()
8787
.expect("Failed to read line");
8888
89-
println!("You guessed: {}", input);
89+
println!("You guessed: {}", guess);
9090
}
9191
```
9292

@@ -302,12 +302,12 @@ project.
302302
There’s just one line of this first example left:
303303

304304
```rust,ignore
305-
println!("You guessed: {}", input);
305+
println!("You guessed: {}", guess);
306306
}
307307
```
308308

309309
This prints out the string we saved our input in. The `{}`s are a placeholder,
310-
and so we pass it `input` as an argument. If we had multiple `{}`s, we would
310+
and so we pass it `guess` as an argument. If we had multiple `{}`s, we would
311311
pass multiple arguments:
312312

313313
```rust
@@ -410,24 +410,29 @@ $ cargo build
410410
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
411411
```
412412

413-
So, we told Cargo we wanted any version of `rand`, and so it fetched the
414-
latest version at the time this was written, `v0.3.8`. But what happens
415-
when next week, version `v0.4.0` comes out, which changes something with
416-
`rand`, and it includes a breaking change? After all, a `v0.y.z` version
417-
in SemVer can change every release.
413+
So, we told Cargo we wanted any version of `rand`, and so it fetched the latest
414+
version at the time this was written, `v0.3.8`. But what happens when next
415+
week, version `v0.3.9` comes out, with an important bugfix? While getting
416+
bugfixes is important, what if `0.3.9` contains a regression that breaks our
417+
code?
418418

419419
The answer to this problem is the `Cargo.lock` file you’ll now find in your
420420
project directory. When you build your project for the first time, Cargo
421421
figures out all of the versions that fit your criteria, and then writes them
422422
to the `Cargo.lock` file. When you build your project in the future, Cargo
423423
will see that the `Cargo.lock` file exists, and then use that specific version
424424
rather than do all the work of figuring out versions again. This lets you
425-
have a repeatable build automatically.
425+
have a repeatable build automatically. In other words, we’ll stay at `0.3.8`
426+
until we explicitly upgrade, and so will anyone who we share our code with,
427+
thanks to the lock file.
426428

427-
What about when we _do_ want to use `v0.4.0`? Cargo has another command,
429+
What about when we _do_ want to use `v0.3.9`? Cargo has another command,
428430
`update`, which says ‘ignore the lock, figure out all the latest versions that
429431
fit what we’ve specified. If that works, write those versions out to the lock
430-
file’.
432+
file’. But, by default, Cargo will only look for versions larger than `0.3.0`
433+
and smaller than `0.4.0`. If we want to move to `0.4.x`, we’d have to update
434+
the `Cargo.toml` directly. When we do, the next time we `cargo build`, Cargo
435+
will update the index and re-evaluate our `rand` requirements.
431436

432437
There’s a lot more to say about [Cargo][doccargo] and [its
433438
ecosystem][doccratesio], but for now, that’s all we need to know. Cargo makes
@@ -843,7 +848,7 @@ fn main() {
843848
Ordering::Less => println!("Too small!"),
844849
Ordering::Greater => println!("Too big!"),
845850
Ordering::Equal => {
846-
println!("You win!"),
851+
println!("You win!");
847852
break;
848853
}
849854
}
@@ -960,8 +965,6 @@ fn main() {
960965
961966
let secret_number = rand::thread_rng().gen_range(1, 101);
962967
963-
println!("The secret number is: {}", secret_number);
964-
965968
loop {
966969
println!("Please input your guess.");
967970

src/doc/trpl/strings.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ individual bytes, or as codepoints:
7373
let hachiko = "忠犬ハチ公";
7474

7575
for b in hachiko.as_bytes() {
76-
print!("{}, ", b);
76+
print!("{}, ", b);
7777
}
7878

7979
println!("");
8080

8181
for c in hachiko.chars() {
82-
print!("{}, ", c);
82+
print!("{}, ", c);
8383
}
8484

8585
println!("");

src/grammar/RustLexer.g4

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ lexer grammar RustLexer;
88

99

1010
tokens {
11-
EQ, LT, LE, EQEQ, NE, GE, GT, ANDAND, OROR, NOT, TILDE, PLUT,
11+
EQ, LT, LE, EQEQ, NE, GE, GT, ANDAND, OROR, NOT, TILDE, PLUS,
1212
MINUS, STAR, SLASH, PERCENT, CARET, AND, OR, SHL, SHR, BINOP,
1313
BINOPEQ, AT, DOT, DOTDOT, DOTDOTDOT, COMMA, SEMI, COLON,
1414
MOD_SEP, RARROW, FAT_ARROW, LPAREN, RPAREN, LBRACKET, RBRACKET,
15-
LBRACE, RBRACE, POUND, DOLLAR, UNDERSCORE, LIT_CHAR,
15+
LBRACE, RBRACE, POUND, DOLLAR, UNDERSCORE, LIT_CHAR, LIT_BYTE,
1616
LIT_INTEGER, LIT_FLOAT, LIT_STR, LIT_STR_RAW, LIT_BINARY,
17-
LIT_BINARY_RAW, IDENT, LIFETIME, WHITESPACE, DOC_COMMENT,
18-
COMMENT, SHEBANG
17+
LIT_BINARY_RAW, QUESTION, IDENT, LIFETIME, WHITESPACE, DOC_COMMENT,
18+
COMMENT, SHEBANG, UTF8_BOM
1919
}
2020

2121
import xidstart , xidcontinue;

src/grammar/verify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn parse_token_list(file: &str) -> HashMap<String, token::Token> {
111111
"LIT_BINARY_RAW" => token::Literal(token::BinaryRaw(Name(0), 0), None),
112112
"QUESTION" => token::Question,
113113
"SHEBANG" => token::Shebang(Name(0)),
114-
_ => continue,
114+
_ => panic!("Bad token str `{}`", val),
115115
};
116116

117117
res.insert(num.to_string(), tok);

src/liballoc/boxed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
//! }
3838
//! ```
3939
//!
40-
//! This will print `Cons(1, Box(Cons(2, Box(Nil))))`.
40+
//! This will print `Cons(1, Cons(2, Nil))`.
4141
//!
4242
//! Recursive structures must be boxed, because if the definition of `Cons` looked like this:
4343
//!

src/libcore/iter.rs

+2
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,8 @@ pub trait Iterator {
602602
/// Performs a fold operation over the entire iterator, returning the
603603
/// eventual state at the end of the iteration.
604604
///
605+
/// This operation is sometimes called 'reduce' or 'inject'.
606+
///
605607
/// # Examples
606608
///
607609
/// ```

src/librustc/diagnostics.rs

+123-4
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,74 @@ of a loop. Without a loop to break out of or continue in, no sensible action can
419419
be taken.
420420
"##,
421421

422+
E0282: r##"
423+
This error indicates that type inference did not result in one unique possible
424+
type, and extra information is required. In most cases this can be provided
425+
by adding a type annotation. Sometimes you need to specify a generic type
426+
parameter manually.
427+
428+
A common example is the `collect` method on `Iterator`. It has a generic type
429+
parameter with a `FromIterator` bound, which for a `char` iterator is
430+
implemented by `Vec` and `String` among others. Consider the following snippet
431+
that reverses the characters of a string:
432+
433+
```
434+
let x = "hello".chars().rev().collect();
435+
```
436+
437+
In this case, the compiler cannot infer what the type of `x` should be:
438+
`Vec<char>` and `String` are both suitable candidates. To specify which type to
439+
use, you can use a type annotation on `x`:
440+
441+
```
442+
let x: Vec<char> = "hello".chars().rev().collect();
443+
```
444+
445+
It is not necessary to annotate the full type. Once the ambiguity is resolved,
446+
the compiler can infer the rest:
447+
448+
```
449+
let x: Vec<_> = "hello".chars().rev().collect();
450+
```
451+
452+
Another way to provide the compiler with enough information, is to specify the
453+
generic type parameter:
454+
455+
```
456+
let x = "hello".chars().rev().collect::<Vec<char>>();
457+
```
458+
459+
Again, you need not specify the full type if the compiler can infer it:
460+
461+
```
462+
let x = "hello".chars().rev().collect::<Vec<_>>();
463+
```
464+
465+
Apart from a method or function with a generic type parameter, this error can
466+
occur when a type parameter of a struct or trait cannot be inferred. In that
467+
case it is not always possible to use a type annotation, because all candidates
468+
have the same return type. For instance:
469+
470+
```
471+
struct Foo<T> {
472+
// Some fields omitted.
473+
}
474+
475+
impl<T> Foo<T> {
476+
fn bar() -> i32 {
477+
0
478+
}
479+
480+
fn baz() {
481+
let number = Foo::bar();
482+
}
483+
}
484+
```
485+
486+
This will fail because the compiler does not know which instance of `Foo` to
487+
call `bar` on. Change `Foo::bar()` to `Foo::<T>::bar()` to resolve the error.
488+
"##,
489+
422490
E0296: r##"
423491
This error indicates that the given recursion limit could not be parsed. Ensure
424492
that the value provided is a positive integer between quotes, like so:
@@ -524,10 +592,65 @@ number cannot be negative.
524592
E0307: r##"
525593
The length of an array is part of its type. For this reason, this length must be
526594
a compile-time constant.
595+
"##,
596+
597+
E0308: r##"
598+
This error occurs when the compiler was unable to infer the concrete type of a
599+
variable. This error can occur for several cases, the most common of which is a
600+
mismatch in the expected type that the compiler inferred for a variable's
601+
initializing expression, and the actual type explicitly assigned to the
602+
variable.
603+
604+
For example:
605+
606+
let x: i32 = "I am not a number!";
607+
// ~~~ ~~~~~~~~~~~~~~~~~~~~
608+
// | |
609+
// | initializing expression;
610+
// | compiler infers type `&str`
611+
// |
612+
// type `i32` assigned to variable `x`
613+
"##,
614+
615+
E0309: r##"
616+
Types in type definitions have lifetimes associated with them that represent
617+
how long the data stored within them is guaranteed to be live. This lifetime
618+
must be as long as the data needs to be alive, and missing the constraint that
619+
denotes this will cause this error.
620+
621+
// This won't compile because T is not constrained, meaning the data
622+
// stored in it is not guaranteed to last as long as the reference
623+
struct Foo<'a, T> {
624+
foo: &'a T
625+
}
626+
627+
// This will compile, because it has the constraint on the type parameter
628+
struct Foo<'a, T: 'a> {
629+
foo: &'a T
630+
}
631+
"##,
632+
633+
E0310: r##"
634+
Types in type definitions have lifetimes associated with them that represent
635+
how long the data stored within them is guaranteed to be live. This lifetime
636+
must be as long as the data needs to be alive, and missing the constraint that
637+
denotes this will cause this error.
638+
639+
// This won't compile because T is not constrained to the static lifetime
640+
// the reference needs
641+
struct Foo<T> {
642+
foo: &'static T
643+
}
644+
645+
// This will compile, because it has the constraint on the type parameter
646+
struct Foo<T: 'static> {
647+
foo: &'static T
648+
}
527649
"##
528650

529651
}
530652

653+
531654
register_diagnostics! {
532655
E0011,
533656
E0012,
@@ -562,7 +685,6 @@ register_diagnostics! {
562685
E0279, // requirement is not satisfied
563686
E0280, // requirement is not satisfied
564687
E0281, // type implements trait but other trait is required
565-
E0282, // unable to infer enough type information about
566688
E0283, // cannot resolve type
567689
E0284, // cannot resolve type
568690
E0285, // overflow evaluation builtin bounds
@@ -571,9 +693,6 @@ register_diagnostics! {
571693
E0300, // unexpanded macro
572694
E0304, // expected signed integer constant
573695
E0305, // expected constant
574-
E0308,
575-
E0309, // thing may not live long enough
576-
E0310, // thing may not live long enough
577696
E0311, // thing may not live long enough
578697
E0312, // lifetime of reference outlives lifetime of borrowed content
579698
E0313, // lifetime of borrowed pointer outlives lifetime of captured variable

src/librustc/middle/resolve_lifetime.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ fn extract_labels<'v, 'a>(ctxt: &mut LifetimeContext<'a>, b: &'v ast::Block) {
374374
fn visit_expr(&mut self, ex: &'v ast::Expr) {
375375
if let Some(label) = expression_label(ex) {
376376
for &(prior, prior_span) in &self.labels_in_fn[..] {
377-
// FIXME (#24278): non-hygienic comparision
377+
// FIXME (#24278): non-hygienic comparison
378378
if label.name == prior.name {
379379
signal_shadowing_problem(self.sess,
380380
label.name,
@@ -420,7 +420,7 @@ fn extract_labels<'v, 'a>(ctxt: &mut LifetimeContext<'a>, b: &'v ast::Block) {
420420
EarlyScope(_, lifetimes, s) |
421421
LateScope(lifetimes, s) => {
422422
for lifetime_def in lifetimes {
423-
// FIXME (#24278): non-hygienic comparision
423+
// FIXME (#24278): non-hygienic comparison
424424
if label.name == lifetime_def.lifetime.name {
425425
signal_shadowing_problem(
426426
sess,
@@ -677,7 +677,7 @@ impl<'a> LifetimeContext<'a> {
677677
lifetime: &ast::Lifetime)
678678
{
679679
for &(label, label_span) in &self.labels_in_fn {
680-
// FIXME (#24278): non-hygienic comparision
680+
// FIXME (#24278): non-hygienic comparison
681681
if lifetime.name == label.name {
682682
signal_shadowing_problem(self.sess,
683683
lifetime.name,

src/librustc/middle/traits/error_reporting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ pub fn maybe_report_ambiguity<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
290290
{
291291
span_err!(infcx.tcx.sess, obligation.cause.span, E0282,
292292
"unable to infer enough type information about `{}`; \
293-
type annotations required",
293+
type annotations or generic parameter binding required",
294294
self_ty.user_string(infcx.tcx));
295295
} else {
296296
span_err!(infcx.tcx.sess, obligation.cause.span, E0283,

0 commit comments

Comments
 (0)