From 6244314798f80ff81d522c54ac8410268af401e4 Mon Sep 17 00:00:00 2001 From: mitaa Date: Tue, 15 Dec 2015 01:55:14 +0100 Subject: [PATCH 1/5] Remove emoji from docs --- src/libcore/iter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index f063c6b06767b..526c2e1c6b523 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -604,7 +604,7 @@ pub trait Iterator { /// iterators, returning a tuple where the first element comes from the /// first iterator, and the second element comes from the second iterator. /// - /// In other words, it zips two iterators together, into a single one. 🤐 + /// In other words, it zips two iterators together, into a single one. /// /// When either iterator returns `None`, all further calls to `next()` /// will return `None`. From 4423463465827f8ad48437b9438e3bc4757f2834 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 7 Dec 2015 14:58:26 +0530 Subject: [PATCH 2/5] Improve E0401 diagnostics to mention other items. --- src/librustc_resolve/diagnostics.rs | 48 ++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index 85fb5d9ccf9e5..04ab3fe70e9fa 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -274,7 +274,7 @@ https://doc.rust-lang.org/reference.html#use-declarations "##, E0401: r##" -Inner functions do not inherit type parameters from the functions they are +Inner items do not inherit type parameters from the functions they are embedded in. For example, this will not compile: ``` @@ -286,12 +286,32 @@ fn foo(x: T) { } ``` -Functions inside functions are basically just like top-level functions, except -that they can only be called from the function they are in. +nor will this: + +``` +fn foo(x: T) { + type MaybeT = Option; + // ... +} +``` + +or this: + +``` +fn foo(x: T) { + struct Foo { + x: T, + } + // ... +} +``` + +Items inside functions are basically just like top-level items, except +that they can only be used from the function they are in. There are a couple of solutions for this. -You can use a closure: +If the item is a function, you may use a closure: ``` fn foo(x: T) { @@ -302,7 +322,7 @@ fn foo(x: T) { } ``` -or copy over the parameters: +For a generic item, you can copy over the parameters: ``` fn foo(x: T) { @@ -313,6 +333,12 @@ fn foo(x: T) { } ``` +``` +fn foo(x: T) { + type MaybeT = Option; +} +``` + Be sure to copy over any bounds as well: ``` @@ -324,10 +350,18 @@ fn foo(x: T) { } ``` +``` +fn foo(x: T) { + struct Foo { + x: T, + } +} +``` + This may require additional type hints in the function body. -In case the function is in an `impl`, defining a private helper function might -be easier: +In case the item is a function inside an `impl`, defining a private helper +function might be easier: ``` impl Foo { From 74c384bc8efcd17b28688f94cdae5500d7f1d1bf Mon Sep 17 00:00:00 2001 From: Alex Burka Date: Tue, 15 Dec 2015 20:26:10 -0500 Subject: [PATCH 3/5] remove claim that $crate is a single identifier Fixes #30217. --- src/doc/book/macros.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/doc/book/macros.md b/src/doc/book/macros.md index f7f27858cd240..7d8284608e189 100644 --- a/src/doc/book/macros.md +++ b/src/doc/book/macros.md @@ -611,8 +611,7 @@ to define a single macro that works both inside and outside our library. The function name will expand to either `::increment` or `::mylib::increment`. To keep this system simple and correct, `#[macro_use] extern crate ...` may -only appear at the root of your crate, not inside `mod`. This ensures that -`$crate` is a single identifier. +only appear at the root of your crate, not inside `mod`. # The deep end From 08222480e9232cc25f7884afe11264aeed0fc486 Mon Sep 17 00:00:00 2001 From: mitaa Date: Thu, 24 Dec 2015 08:15:58 +0100 Subject: [PATCH 4/5] Fix link to `Formatter::debug_struct` --- src/libcore/fmt/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 04676c0c9c8b4..628bf654873c7 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -356,7 +356,7 @@ impl<'a> Display for Arguments<'a> { /// `Debug` implementations using either `derive` or the debug builder API /// on `Formatter` support pretty printing using the alternate flag: `{:#?}`. /// -/// [debug_struct]: ../std/fmt/struct.Formatter.html#method.debug_struct +/// [debug_struct]: ../../std/fmt/struct.Formatter.html#method.debug_struct /// /// Pretty printing with `#?`: /// From 992feab697ee51d9bd89e693c5106c6cbf0b0a12 Mon Sep 17 00:00:00 2001 From: Corey Richardson Date: Tue, 29 Dec 2015 00:11:52 -0500 Subject: [PATCH 5/5] Add a hint when given --extern with an indeterminate type @ubsan brought up this relatively poor error message. This adds a help message hinting when the problem actually is, and how to fix it. --- src/librustc_metadata/loader.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/librustc_metadata/loader.rs b/src/librustc_metadata/loader.rs index 81788e08c7ef2..d1892b87f8bcc 100644 --- a/src/librustc_metadata/loader.rs +++ b/src/librustc_metadata/loader.rs @@ -664,6 +664,8 @@ impl<'a> Context<'a> { } sess.err(&format!("extern location for {} is of an unknown type: {}", self.crate_name, loc.display())); + sess.help(&format!("file name should be lib*.rlib or {}*.{}", + dylibname.0, dylibname.1)); false });