From 03f9dd21d6c181195e1ee024c9b8a188d23d5183 Mon Sep 17 00:00:00 2001 From: Fabian Vogt Date: Wed, 22 Jun 2016 15:09:11 +0200 Subject: [PATCH 1/8] Fix typo in bootstrap README "boostrap" instead of "bootstrap" --- src/bootstrap/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/README.md b/src/bootstrap/README.md index 942f070c82fd8..57d644d635cf7 100644 --- a/src/bootstrap/README.md +++ b/src/bootstrap/README.md @@ -50,7 +50,7 @@ compiler. What actually happens when you invoke rustbuild is: 1. The entry point script, `src/bootstrap/bootstrap.py` is run. This script is responsible for downloading the stage0 compiler/Cargo binaries, and it then compiles the build system itself (this folder). Finally, it then invokes the - actual `boostrap` binary build system. + actual `bootstrap` binary build system. 2. In Rust, `bootstrap` will slurp up all configuration, perform a number of sanity checks (compilers exist for example), and then start building the stage0 artifacts. From eb17527039c466f6f79c595f9f99a1a324a85955 Mon Sep 17 00:00:00 2001 From: Alfie John Date: Thu, 23 Jun 2016 06:20:29 +1000 Subject: [PATCH 2/8] Switched tense to clarify what is happening in the example --- src/doc/book/patterns.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/book/patterns.md b/src/doc/book/patterns.md index 7ecfdcfcc1e02..a0245d4c7b163 100644 --- a/src/doc/book/patterns.md +++ b/src/doc/book/patterns.md @@ -174,7 +174,7 @@ Here, we bind the first and last element of the tuple to `x` and `z`, but ignore the middle element. It’s worth noting that using `_` never binds the value in the first place, -which means a value may not move: +which means that the value does not move: ```rust let tuple: (u32, String) = (5, String::from("five")); From 2d7bac7d865a3c77f2fb05b9505d81d068df5551 Mon Sep 17 00:00:00 2001 From: Liigo Zhuang Date: Mon, 20 Jun 2016 16:19:19 +0800 Subject: [PATCH 3/8] Improve diagnostics E0425: `use` (public) items E0425: unresolved name --- src/librustc_resolve/diagnostics.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index 208b5f11e20d1..4e4f6e276d1dd 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -843,6 +843,17 @@ Or: let unknown_variable = 12u32; let x = unknown_variable; // ok! ``` + +If the item is not defined in the current module, it must be imported using a +`use` statement, like so: + +```ignore +use foo::bar; +bar(); +``` + +If the item you are importing is not defined in some super-module of the +current module, then it must also be declared as public (e.g., `pub fn`). "##, E0426: r##" From 5215acc27b05da8799e9cd5538e51d872989fe68 Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Fri, 24 Jun 2016 03:33:40 +0900 Subject: [PATCH 4/8] Fix typo in future incompatible lint --- src/librustc_lint/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index ed12d0d9f3c11..7baadb2b69a5f 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -163,7 +163,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { }, FutureIncompatibleInfo { id: LintId::of(INVALID_TYPE_PARAM_DEFAULT), - reference: "PR 30742 ", + reference: "PR 30724 ", }, FutureIncompatibleInfo { id: LintId::of(SUPER_OR_SELF_IN_GLOBAL_PATH), From 0187aec8e0f7cb148c5360ab5d3953ee86394061 Mon Sep 17 00:00:00 2001 From: Paul Jarrett Date: Thu, 23 Jun 2016 23:02:30 -0400 Subject: [PATCH 5/8] Renames "lets_do_this" macro more appropriately. The macro gets used to create a mapping of identifiers to names and their associated functions. Since it creates a table of language items, let's rename it in a similar manner to how vec! creates a vec. --- src/librustc/middle/lang_items.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 853477ac97c16..960305e10488d 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -37,7 +37,7 @@ use hir; // The actual lang items defined come at the end of this file in one handy table. // So you probably just want to nip down to the end. -macro_rules! lets_do_this { +macro_rules! language_item_table { ( $( $variant:ident, $name:expr, $method:ident; )* ) => { @@ -269,7 +269,7 @@ pub fn collect_language_items(session: &Session, } } -lets_do_this! { +language_item_table! { // Variant name, Name, Method name; CharImplItem, "char", char_impl; StrImplItem, "str", str_impl; From 6e848be5f8071f1fe6110b3ec2bee0776126f79b Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Thu, 23 Jun 2016 18:16:37 -0400 Subject: [PATCH 6/8] Indicate how the `JoinHandle` struct is created. --- src/libstd/thread/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 1f78b32bcf38e..355e0f50cef35 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -610,6 +610,12 @@ impl JoinInner { /// Due to platform restrictions, it is not possible to `Clone` this /// handle: the ability to join a child thread is a uniquely-owned /// permission. +/// +/// This `struct` is created by the [`thread::spawn`] function and the +/// [`thread::Builder::spawn`] method. +/// +/// [`thread::spawn`]: fn.spawn.html +/// [`thread::Builder::spawn`]: struct.Builder.html#method.spawn #[stable(feature = "rust1", since = "1.0.0")] pub struct JoinHandle(JoinInner); From 32ef89061e3c438c71c601a86294e5f72a6e96b5 Mon Sep 17 00:00:00 2001 From: Vincent Esche Date: Fri, 24 Jun 2016 13:14:34 +0200 Subject: [PATCH 7/8] Improve `syntax::ast::*` type docs (examples, etc) --- src/libsyntax/ast.rs | 171 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 135 insertions(+), 36 deletions(-) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 8537fcc221c95..c3cc84b770155 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -171,16 +171,19 @@ impl fmt::Debug for Lifetime { } } -/// A lifetime definition, eg `'a: 'b+'c+'d` +/// A lifetime definition, e.g. `'a: 'b+'c+'d` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct LifetimeDef { pub lifetime: Lifetime, pub bounds: Vec } -/// A "Path" is essentially Rust's notion of a name; for instance: -/// std::cmp::PartialEq . It's represented as a sequence of identifiers, +/// A "Path" is essentially Rust's notion of a name. +/// +/// It's represented as a sequence of identifiers, /// along with a bunch of supporting information. +/// +/// E.g. `std::cmp::PartialEq` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)] pub struct Path { pub span: Span, @@ -220,8 +223,9 @@ impl Path { } } -/// A segment of a path: an identifier, an optional lifetime, and a set of -/// types. +/// A segment of a path: an identifier, an optional lifetime, and a set of types. +/// +/// E.g. `std`, `String` or `Box` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct PathSegment { /// The identifier portion of this path segment. @@ -235,6 +239,9 @@ pub struct PathSegment { pub parameters: PathParameters, } +/// Parameters of a path segment. +/// +/// E.g. `` as in `Foo` or `(A, B)` as in `Foo(A, B)` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub enum PathParameters { /// The `<'a, A,B,C>` in `foo::bar::baz::<'a, A,B,C>` @@ -322,7 +329,8 @@ pub struct AngleBracketedParameterData { /// The type parameters for this path segment, if present. pub types: P<[P]>, /// Bindings (equality constraints) on associated types, if present. - /// e.g., `Foo`. + /// + /// E.g., `Foo`. pub bindings: P<[TypeBinding]>, } @@ -447,7 +455,9 @@ pub enum WherePredicate { EqPredicate(WhereEqPredicate), } -/// A type bound, e.g. `for<'c> Foo: Send+Clone+'c` +/// A type bound. +/// +/// E.g. `for<'c> Foo: Send+Clone+'c` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct WhereBoundPredicate { pub span: Span, @@ -459,7 +469,9 @@ pub struct WhereBoundPredicate { pub bounds: TyParamBounds, } -/// A lifetime predicate, e.g. `'a: 'b+'c` +/// A lifetime predicate. +/// +/// E.g. `'a: 'b+'c` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct WhereRegionPredicate { pub span: Span, @@ -467,7 +479,9 @@ pub struct WhereRegionPredicate { pub bounds: Vec, } -/// An equality predicate (unsupported), e.g. `T=int` +/// An equality predicate (unsupported). +/// +/// E.g. `T=int` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct WhereEqPredicate { pub id: NodeId, @@ -489,12 +503,27 @@ pub struct Crate { pub exported_macros: Vec, } +/// A spanned compile-time attribute item. +/// +/// E.g. `#[test]`, `#[derive(..)]` or `#[feature = "foo"]` pub type MetaItem = Spanned; +/// A compile-time attribute item. +/// +/// E.g. `#[test]`, `#[derive(..)]` or `#[feature = "foo"]` #[derive(Clone, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub enum MetaItemKind { + /// Word meta item. + /// + /// E.g. `test` as in `#[test]` Word(InternedString), + /// List meta item. + /// + /// E.g. `derive(..)` as in `#[derive(..)]` List(InternedString, Vec>), + /// Name value meta item. + /// + /// E.g. `feature = "foo"` as in `#[feature = "foo"]` NameValue(InternedString, Lit), } @@ -524,6 +553,9 @@ impl PartialEq for MetaItemKind { } } +/// A Block (`{ .. }`). +/// +/// E.g. `{ .. }` as in `fn foo() { .. }` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct Block { /// Statements in a block @@ -876,7 +908,16 @@ impl Decl { } } -/// represents one arm of a 'match' +/// An arm of a 'match'. +/// +/// E.g. `0...10 => { println!("match!") }` as in +/// +/// ```rust,ignore +/// match n { +/// 0...10 => { println!("match!") }, +/// // .. +/// } +/// ``` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct Arm { pub attrs: Vec, @@ -1033,7 +1074,7 @@ pub enum ExprKind { /// parameters, e.g. foo::bar::. /// /// Optionally "qualified", - /// e.g. ` as SomeTrait>::SomeType`. + /// E.g. ` as SomeTrait>::SomeType`. Path(Option, Path), /// A referencing operation (`&a` or `&mut a`) @@ -1075,7 +1116,7 @@ pub enum ExprKind { /// separately. `position` represents the index of the associated /// item qualified with this Self type. /// -/// ```ignore +/// ```rust,ignore /// as a::b::Trait>::AssociatedItem /// ^~~~~ ~~~~~~~~~~~~~~^ /// ty position = 3 @@ -1319,6 +1360,9 @@ pub enum LitIntType { Unsuffixed, } +/// Literal kind. +/// +/// E.g. `"foo"`, `42`, `12.34` or `bool` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub enum LitKind { /// A string literal (`"foo"`) @@ -1586,8 +1630,8 @@ pub struct BareFnTy { pub decl: P } -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] /// The different kinds of types recognized by the compiler +#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub enum TyKind { Vec(P), /// A fixed length array (`[T; n]`) @@ -1622,12 +1666,18 @@ pub enum TyKind { Mac(Mac), } +/// Inline assembly dialect. +/// +/// E.g. `"intel"` as in `asm!("mov eax, 2" : "={eax}"(result) : : : "intel")`` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] pub enum AsmDialect { Att, Intel, } +/// Inline assembly. +/// +/// E.g. `"={eax}"(result)` as in `asm!("mov eax, 2" : "={eax}"(result) : : : "intel")`` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct InlineAsmOutput { pub constraint: InternedString, @@ -1636,6 +1686,9 @@ pub struct InlineAsmOutput { pub is_indirect: bool, } +/// Inline assembly. +/// +/// E.g. `asm!("NOP");` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct InlineAsm { pub asm: InternedString, @@ -1649,7 +1702,9 @@ pub struct InlineAsm { pub expn_id: ExpnId, } -/// represents an argument in a function header +/// An argument in a function header. +/// +/// E.g. `bar: usize` as in `fn foo(bar: usize)` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct Arg { pub ty: P, @@ -1658,6 +1713,8 @@ pub struct Arg { } /// Alternative representation for `Arg`s describing `self` parameter of methods. +/// +/// E.g. `&mut self` as in `fn foo(&mut self)` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub enum SelfKind { /// `self`, `mut self` @@ -1724,7 +1781,9 @@ impl Arg { } } -/// Represents the header (not the body) of a function declaration +/// Header (not the body) of a function declaration. +/// +/// E.g. `fn foo(bar: baz)` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct FnDecl { pub inputs: Vec, @@ -1811,6 +1870,9 @@ impl FunctionRetTy { } } +/// Module declaration. +/// +/// E.g. `mod foo;` or `mod foo { .. }` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct Mod { /// A span from the first token past `{` to the last token until `}`. @@ -1820,6 +1882,9 @@ pub struct Mod { pub items: Vec>, } +/// Foreign module declaration. +/// +/// E.g. `extern { .. }` or `extern C { .. }` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct ForeignMod { pub abi: Abi, @@ -1836,7 +1901,7 @@ pub struct Variant_ { pub name: Ident, pub attrs: Vec, pub data: VariantData, - /// Explicit discriminant, eg `Foo = 1` + /// Explicit discriminant, e.g. `Foo = 1` pub disr_expr: Option>, } @@ -1846,12 +1911,12 @@ pub type Variant = Spanned; pub enum PathListItemKind { Ident { name: Ident, - /// renamed in list, eg `use foo::{bar as baz};` + /// renamed in list, e.g. `use foo::{bar as baz};` rename: Option, id: NodeId }, Mod { - /// renamed in list, eg `use foo::{self as baz};` + /// renamed in list, e.g. `use foo::{self as baz};` rename: Option, id: NodeId } @@ -1964,6 +2029,9 @@ pub enum Visibility { Inherited, } +/// Field of a struct. +/// +/// E.g. `bar: usize` as in `struct Foo { bar: usize }` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct StructField { pub span: Span, @@ -1987,8 +2055,17 @@ pub struct StructField { /// Id of the whole struct lives in `Item`. #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub enum VariantData { + /// Struct variant. + /// + /// E.g. `Bar { .. }` as in `enum Foo { Bar { .. } }` Struct(Vec, NodeId), + /// Tuple variant. + /// + /// E.g. `Bar(..)` as in `enum Foo { Bar(..) }` Tuple(Vec, NodeId), + /// Unit variant. + /// + /// E.g. `Bar = ..` as in `enum Foo { Bar = .. }` Unit(NodeId), } @@ -2040,44 +2117,66 @@ impl Item { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub enum ItemKind { - /// An`extern crate` item, with optional original crate name, + /// An`extern crate` item, with optional original crate name. /// - /// e.g. `extern crate foo` or `extern crate foo_bar as foo` + /// E.g. `extern crate foo` or `extern crate foo_bar as foo` ExternCrate(Option), - /// A `use` or `pub use` item + /// A use declaration (`use` or `pub use`) item. + /// + /// E.g. `use foo;`, `use foo::bar;` or `use foo::bar as FooBar;` Use(P), - - /// A `static` item + /// A static item (`static` or `pub static`). + /// + /// E.g. `static FOO: i32 = 42;` or `static FOO: &'static str = "bar";` Static(P, Mutability, P), - /// A `const` item + /// A constant item (`const` or `pub const`). + /// + /// E.g. `const FOO: i32 = 42;` Const(P, P), - /// A function declaration + /// A function declaration (`fn` or `pub fn`). + /// + /// E.g. `fn foo(bar: usize) -> usize { .. }` Fn(P, Unsafety, Constness, Abi, Generics, P), - /// A module + /// A module declaration (`mod` or `pub mod`). + /// + /// E.g. `mod foo;` or `mod foo { .. }` Mod(Mod), - /// An external module + /// An external module (`extern` or `pub extern`). + /// + /// E.g. `extern {}` or `extern "C" {}` ForeignMod(ForeignMod), - /// A type alias, e.g. `type Foo = Bar` + /// A type alias (`type` or `pub type`). + /// + /// E.g. `type Foo = Bar;` Ty(P, Generics), - /// An enum definition, e.g. `enum Foo {C, D}` + /// An enum definition (`enum` or `pub enum`). + /// + /// E.g. `enum Foo { C, D }` Enum(EnumDef, Generics), - /// A struct definition, e.g. `struct Foo {x: A}` + /// A struct definition (`struct` or `pub struct`). + /// + /// E.g. `struct Foo { x: A }` Struct(VariantData, Generics), - /// Represents a Trait Declaration + /// A Trait declaration (`trait` or `pub trait`). + /// + /// E.g. `trait Foo { .. }` or `trait Foo { .. }` Trait(Unsafety, Generics, TyParamBounds, Vec), - - // Default trait implementations + // Default trait implementation. /// - // `impl Trait for .. {}` + /// E.g. `impl Trait for .. {}` or `impl Trait for .. {}` DefaultImpl(Unsafety, TraitRef), - /// An implementation, eg `impl Trait for Foo { .. }` + /// An implementation. + /// + /// E.g. `impl Foo { .. }` or `impl Trait for Foo { .. }` Impl(Unsafety, ImplPolarity, Generics, Option, // (optional) trait this impl implements P, // self Vec), - /// A macro invocation (which includes macro definition) + /// A macro invocation (which includes macro definition). + /// + /// E.g. `macro_rules! foo { .. }` or `foo!(..)` Mac(Mac), } From 5e9b75e2dd440a5df2c7d90f88b2660c7581d964 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Fri, 24 Jun 2016 08:12:58 -0400 Subject: [PATCH 8/8] Add examples in docs for `JoinHandle`. --- src/libstd/thread/mod.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 355e0f50cef35..26085c86813ad 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -614,6 +614,30 @@ impl JoinInner { /// This `struct` is created by the [`thread::spawn`] function and the /// [`thread::Builder::spawn`] method. /// +/// # Examples +/// +/// Creation from [`thread::spawn`]: +/// +/// ```rust +/// use std::thread; +/// +/// let join_handle: thread::JoinHandle<_> = thread::spawn(|| { +/// // some work here +/// }); +/// ``` +/// +/// Creation from [`thread::Builder::spawn`]: +/// +/// ```rust +/// use std::thread; +/// +/// let builder = thread::Builder::new(); +/// +/// let join_handle: thread::JoinHandle<_> = builder.spawn(|| { +/// // some work here +/// }).unwrap(); +/// ``` +/// /// [`thread::spawn`]: fn.spawn.html /// [`thread::Builder::spawn`]: struct.Builder.html#method.spawn #[stable(feature = "rust1", since = "1.0.0")]