diff --git a/.mailmap b/.mailmap index 8eaf8f16e4b6a..317a92b8f43cb 100644 --- a/.mailmap +++ b/.mailmap @@ -7,142 +7,218 @@ Aaron Todd Abhishek Chanda Abhishek Chanda +Adolfo Ochagavía +Adrien Tétar Ahmed Charles -Aydin Kim aydin.kim Alex Burka Alex Burka Alex Lyon Alex Newman Alex HotShot Newman Alex Rønne Petersen +Alexander Light Alexander Light +Alexis Beingessner Alfie John Alfie John +Anatoly Ikorsky +Andre Bogus Andreas Gal Andrew Kuchev <0coming.soon@gmail.com> Andrew <0coming.soon@gmail.com> Andrew Poelstra Anton Löfgren -Ariel Ben-Yehuda arielb1 +Areski Belaid areski Ariel Ben-Yehuda Ariel Ben-Yehuda +Ariel Ben-Yehuda arielb1 Austin Seipp +Aydin Kim aydin.kim +Barosl Lee Barosl LEE Ben Alpert -Ben Sago Ben S Ben S +Ben Sago Ben S +Ben Sago Ben S Benjamin Jackman +Bheesham Persaud Bheesham Persaud Björn Steinbrink blake2-ppc Boris Egorov +Brandon Sanderson Brandon Sanderson +Brett Cannon Brett Cannon Brian Anderson Brian Dawn +Brian Leibig Brian Leibig Carl-Anton Ingmarsson Carol (Nichols || Goulding) Carol Nichols +Carol (Nichols || Goulding) Carol Nichols Carol Willing Chris C Cerami Chris C Cerami Chris Pressey +Chris Thorn Chris Thorn Clark Gaebel +Clinton Ryan Corey Farwell Corey Farwell Corey Richardson Elaine "See More" Nemo +Damien Schoof +Daniel Ramos David Klein David Manescu -Damien Schoof +David Ross Derek Chiang Derek Chiang (Enchi Jiang) Diggory Hardy Diggory Hardy Dylan Braithwaite -Eduardo Bautista +Dzmitry Malyshau Eduardo Bautista <=> +Eduardo Bautista Elliott Slaughter Elly Fong-Jones Emily Dunham edunham -Eric Holk Eric Holk +Eric Holk Eric Holmes Eric Reed Erick Tryzelaar Evgeny Sologubov Falco Hirschenberger Felix S. Klock II Felix S Klock II +Flaper Fesp +Florian Wilkens Florian Wilkens Gareth Daniel Smith gareth +Gareth Daniel Smith Gareth Smith Georges Dubus -Graham Fawcett +Graham Fawcett Graham Fawcett Graydon Hoare Graydon Hoare -Heather +Guillaume Gomez Heather +Heather +Herman J. Radtke III Herman J. Radtke III Ilyong Cho +Ivan Ivaschenko J. J. Weber Jakub Bukaj Jakub Bukaj +Jakub Bukaj Jakub Bukaj James Deng James Miller -Jason Orendorff +James Perry +Jason Fager Jason Orendorff +Jason Orendorff +Jason Toffaletti Jason Toffaletti +Jauhien Piatlicki Jauhien Piatlicki +Jay True Jeremy Letang -Jihyun Yu jihyun -Jihyun Yu -Johann Hofmann Johann Johann Hofmann +Jihyun Yu +Jihyun Yu jihyun +Jihyun Yu Jihyun Yu +Johann Hofmann Johann John Clements John Hodge John Hodge -Jorge Aparicio +John Kåre Alsaker +John Talling Jonathan Bailey +Jonathan S Jonathan S +Jorge Aparicio +Joseph Martin +João Oliveira joaoxsouls Junyoung Cho Jyun-Yan You Kang Seonghoon -Keegan McAllister +Keegan McAllister +Kevin Butler Kyeongwoon Lee -Lee Wondong Lee Jeffery Lee Jeffery +Lee Wondong Lennart Kudling +Léo Testard Lindsey Kuper Lindsey Kuper -Luqman Aden -Luqman Aden Luke Metz +Luqman Aden +Luqman Aden Makoto Nakashima Makoto Nakashima gifnksm -Markus Westerlind Markus +Makoto Nakashima NAKASHIMA, Makoto +Marcell Pardavi Margaret Meyerhofer Mark Sinclair Mark Sinclair =Mark Sinclair <=125axel125@gmail.com> +Markus Westerlind Markus Matej Lach Matej Ľach Matt Brubeck Matthew Auld Matthew McPherrin Matthijs Hofstra Michael Williams -Michael Woerister Michael Woerister +Michael Woerister +Mickaël Raybaud-Roig m-r-r Ms2ger +Mukilan Thiagarajan +NAKASHIMA, Makoto +Nathan Wilson +Nathaniel Herman Nathaniel Herman Neil Pankey Nicholas Mazzuca Nicholas -Oliver Schneider Oliver 'ker' Schneider -Oliver Schneider Oliver Schneider Oliver Schneider Oliver Schneider +Nick Platt +Nif Ward +Oliver Schneider oli-obk +Oliver Schneider Oliver 'ker' Schneider +Oliver Schneider Oliver Schneider +Oliver Schneider Oliver Schneider +Oliver Schneider Oliver Schneider +Oliver Schneider Oliver Schneider Ožbolt Menegatti gareins Paul Faria Paul Faria Peer Aramillo Irizar parir Peter Elmers +Peter Zotov +Phil Dawes Phil Dawes Philipp Brüschweiler Philipp Brüschweiler -Pradeep Kumar Przemysław Wesołek Przemek Wesołek +Rafael Ávila de Espíndola Rafael Avila de Espindola Ralph Giles Ralph Giles +Renato Riccieri Santos Zannon Richard Diamond Rob Arnold +Rob Arnold Rob Arnold Robert Foss robertfoss Robert Gawdzik Robert Gawdzik ☢ Robert Millar +Rohit Joshi Rohit Joshi +Russell Johnston Ruud van Asseldonk Ruud van Asseldonk Ryan Scheel +S Pradeep Kumar +Scott Olson Scott Olson Sean Gillespie swgillespie Seonghyun Kim Simon Barber-Dueck Simon BD Simon Sapin +Simonas Kazlauskas Simonas Kazlauskas startling +Stepan Koltsov Stepan Koltsov Steven Fackler Steven Stewart-Gallus +Stuart Pernsteiner Stuart Pernsteiner Tamir Duberstein Tamir Duberstein +Tero Hänninen Tero Hänninen +Theo Belaire Theo Belaire Thiago Pontes thiagopnts +Thomas Bracht Laumann Jespersen Ticki Ticki <@> +Tim Brooks Tim Brooks Tim Chevalier +Tim JIANG +Tim Joseph Dumol Torsten Weber -Ulrik Sverdrup Ulrik Sverdrup +Ty Overby +Ulrik Sverdrup bluss Ulrik Sverdrup bluss bluss +Ulrik Sverdrup Ulrik Sverdrup +Vadim Petrochenkov Vadim Petrochenkov petrochenkov Vitali Haravy Vitali Haravy William Ting -Xuefeng Wu Xuefeng Wu XuefengWu +Xuefeng Wu Xuefeng Wu +Xuefeng Wu XuefengWu +York Xiang Youngsoo Son +Zach Pomerantz Zack Corr Zack Slayton +Zbigniew Siciarz Zbigniew Siciarz diff --git a/AUTHORS.txt b/AUTHORS.txt index 5f316744021ef..b7fa4a5a4a73b 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -98,7 +98,6 @@ Anton Löfgren Antti Keränen Aram Visser arcnmx -Arcterus Areski Belaid Ariel Ben-Yehuda Arjan Topolovec @@ -136,7 +135,6 @@ Ben Gesoff Ben Harris Ben Kelly Ben Noordhuis -Ben S Ben Sago Ben Striegel benaryorg @@ -434,7 +432,6 @@ Gábor Horváth Gábor Lehel Gabriel gamazeps -gareth Gareth Daniel Smith Garming Sam Garrett Heel @@ -495,7 +492,6 @@ Igor Strebezhev Ilya Dmitrichenko Ilyong Cho Ingo Blechschmidt -inrustwetrust Irving A.J. Rivas Z. Isaac Aggrey Isaac Dupree @@ -733,7 +729,6 @@ Liam Monahan Liigo Zhuang Lindsey Kuper Lionel Flandrin -llogiq Logan Chien Loïc Damien Lorenz @@ -760,7 +755,7 @@ Manuel Hoffmann Marc-Antoine Perennou Marcel Müller Marcel Rodrigues -marcell +Marcell Pardavi Marcello Seri Marcus Klaas Margaret Meyerhofer @@ -924,9 +919,7 @@ Oak OGINO Masanori OlegTsyba Oliver Schneider -Oliver Schneider -Oliver Schneider -Oliver Schneider +Oliver Schneider Olivier Saut olivren Olle Jonsson @@ -937,7 +930,6 @@ Oren Hazi Orphée Lafond-Lummis Orpheus Lummis osa1 -Overmind JIANG Ožbolt Menegatti P1start Pablo Brasero @@ -978,7 +970,6 @@ Peter Schuller Peter Williams Peter Zotov Petter Remen -pez Phil Dawes Phil Ruffwind Philip Munksgaard @@ -1065,7 +1056,6 @@ Ryan Pendleton Ryan Prichard Ryan Riginding Ryan Scheel -Ryman Ryo Munakata S Pradeep Kumar Sae-bom Kim @@ -1153,7 +1143,6 @@ Swaroop C H Sylvestre Ledru Taliesin Beynon Tamir Duberstein -Tamir Duberstein Taras Shpot tav Taylor Hutchison @@ -1169,7 +1158,6 @@ Thiago Pontes Thomas Backman Thomas Bracht Laumann Jespersen Thomas Daede -Thomas Jespersen Thomas Karpiniec Tiago Nobrega Tibor Benke @@ -1255,7 +1243,6 @@ Wei-Ming Yang Wendell Smith Wesley Wiser whataloadofwhat -whitequark wickerwaka Wilfred Hughes Will @@ -1275,8 +1262,6 @@ Xavier Shay Xiao Chuan Yu Xue Fuqiao Xuefeng Wu -Xuefeng Wu -XuefengWu Yasuhiro Fujii YawarRaza7349 Yazhong Liu diff --git a/mk/docs.mk b/mk/docs.mk index 644fbde323c93..b0872c88c141a 100644 --- a/mk/docs.mk +++ b/mk/docs.mk @@ -22,14 +22,14 @@ # L10N_LANGS are the languages for which the docs have been # translated. ###################################################################### -DOCS := index intro tutorial \ +DOCS := index \ complement-lang-faq complement-design-faq complement-project-faq \ rustdoc reference grammar # Legacy guides, preserved for a while to reduce the number of 404s DOCS += guide-crates guide-error-handling guide-ffi guide-macros guide \ guide-ownership guide-plugins guide-pointers guide-strings guide-tasks \ - guide-testing + guide-testing tutorial intro RUSTDOC_DEPS_reference := doc/full-toc.inc diff --git a/mk/platform.mk b/mk/platform.mk index b8058882f9d94..e6669f5c58d41 100644 --- a/mk/platform.mk +++ b/mk/platform.mk @@ -14,7 +14,7 @@ # would create a variable HOST_i686-darwin-macos with the value # i386. define DEF_HOST_VAR - HOST_$(1) = $(subst i686,i386,$(word 1,$(subst -, ,$(1)))) + HOST_$(1) = $(patsubst i%86,i386,$(word 1,$(subst -, ,$(1)))) endef $(foreach t,$(CFG_TARGET),$(eval $(call DEF_HOST_VAR,$(t)))) $(foreach t,$(CFG_TARGET),$(info cfg: host for $(t) is $(HOST_$(t)))) @@ -214,9 +214,11 @@ define CFG_MAKE_TOOLCHAIN # On OpenBSD, we need to pass the path of libstdc++.so to the linker # (use path of libstdc++.a which is a known name for the same path) ifeq ($(OSTYPE_$(1)),unknown-openbsd) - RUSTC_FLAGS_$(1)=-L "$$(dir $$(shell $$(CC_$(1)) $$(CFG_GCCISH_CFLAGS_$(1)) \ - -print-file-name=lib$(CFG_STDCPP_NAME).a))" \ - $(RUSTC_FLAGS_$(1)) + STDCPP_LIBDIR_RUSTFLAGS_$(1)= \ + -L "$$(dir $$(shell $$(CC_$(1)) $$(CFG_GCCISH_CFLAGS_$(1)) \ + -print-file-name=lib$(CFG_STDCPP_NAME).a))" + else + STDCPP_LIBDIR_RUSTFLAGS_$(1)= endif # On Bitrig, we need the relocation model to be PIC for everything diff --git a/mk/target.mk b/mk/target.mk index ae9fd9d1adacf..a88f0a33c0731 100644 --- a/mk/target.mk +++ b/mk/target.mk @@ -95,6 +95,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): \ $$(RUSTFLAGS_$(4)) \ $$(RUSTFLAGS$(1)_$(4)) \ $$(RUSTFLAGS$(1)_$(4)_T_$(2)) \ + $$(STDCPP_LIBDIR_RUSTFLAGS_$(2)) \ --out-dir $$(@D) \ -C extra-filename=-$$(CFG_FILENAME_EXTRA) \ $$< @@ -128,7 +129,9 @@ $$(TBIN$(1)_T_$(2)_H_$(3))/$(4)$$(X_$(2)): \ $$(TSREQ$(1)_T_$(2)_H_$(3)) \ | $$(TBIN$(1)_T_$(2)_H_$(3))/ @$$(call E, rustc: $$@) - $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --cfg $(4) + $$(STAGE$(1)_T_$(2)_H_$(3)) \ + $$(STDCPP_LIBDIR_RUSTFLAGS_$(2)) \ + -o $$@ $$< --cfg $(4) endef diff --git a/mk/tests.mk b/mk/tests.mk index 73aec5de8da32..3a0aee77d6805 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -393,7 +393,8 @@ $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)): \ $$(subst @,,$$(STAGE$(1)_T_$(2)_H_$(3))) -o $$@ $$< --test \ -L "$$(RT_OUTPUT_DIR_$(2))" \ $$(LLVM_LIBDIR_RUSTFLAGS_$(2)) \ - $$(RUSTFLAGS_$(4)) + $$(RUSTFLAGS_$(4)) \ + $$(STDCPP_LIBDIR_RUSTFLAGS_$(2)) endef @@ -663,9 +664,9 @@ CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \ --android-cross-path=$(CFG_ANDROID_CROSS_PATH) \ --adb-path=$(CFG_ADB) \ --adb-test-dir=$(CFG_ADB_TEST_DIR) \ - --host-rustcflags "$(RUSTC_FLAGS_$(3)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(3))" \ + --host-rustcflags "$(RUSTC_FLAGS_$(3)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(3)) $$(STDCPP_LIBDIR_RUSTFLAGS_$(3))" \ --lldb-python-dir=$(CFG_LLDB_PYTHON_DIR) \ - --target-rustcflags "$(RUSTC_FLAGS_$(2)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(2))" \ + --target-rustcflags "$(RUSTC_FLAGS_$(2)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(2)) $$(STDCPP_LIBDIR_RUSTFLAGS_$(2))" \ $$(CTEST_TESTARGS) ifdef CFG_VALGRIND_RPASS diff --git a/src/doc/index.md b/src/doc/index.md index 992b6eef5e801..5f2ef6107298c 100644 --- a/src/doc/index.md +++ b/src/doc/index.md @@ -14,9 +14,8 @@ concepts. Upon completing the book, you'll be an intermediate Rust developer, and will have a good grasp of the fundamental ideas behind Rust. -[Rust By Example][rbe] was originally a community resource, but was then -donated to the Rust project. As the name implies, it teaches you Rust through a -series of small examples. +[Rust By Example][rbe] teaches you Rust through a series of small +examples. [rbe]: http://rustbyexample.com/ @@ -32,49 +31,21 @@ library](std/index.html). There's a list of crates on the left with more specific sections, or you can use the search bar at the top to search for something if you know its name. +# The Rustonomicon + +[The Rustonomicon] is an entire book dedicated to explaining +how to write `unsafe` Rust code. It is for advanced Rust programmers. + +[The Rustonomicon]: nomicon/index.html + # Tools -[Cargo](https://crates.io) is the Rust's package manager providing access to libraries +[Cargo](http://doc.crates.io/index.html) is the Rust package manager providing access to libraries beyond the standard one, and its website contains lots of good documentation. [`rustdoc`](book/documentation.html) is the Rust's documentation generator, a tool converting annotated source code into HTML docs. -A bunch of non-official tools are available, such as [Racer](https://github.com/phildawes/racer) -(code completion engine), or [rustfmt](https://github.com/nrc/rustfmt) (source code formatter), -or text editor plugins. - -# Community & Getting Help - -If you need help with something, or just want to talk about Rust with others, -there are a few places you can do that: - -The Rust IRC channels on [irc.mozilla.org](irc://irc.mozilla.org/) are the -fastest way to get help. -[`#rust`](http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust) is -the general discussion channel, and you'll find people willing to help you with -any questions you may have. - -There are also three specialty channels: -[`#rust-gamedev`](http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust-gamedev) -and -[`#rust-osdev`](http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust-osdev) -are for game development and operating system development, respectively. -There's also -[`#rust-internals`](http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust-internals), which is for discussion of the development of Rust itself. - -You can also get help on [Stack -Overflow](https://stackoverflow.com/questions/tagged/rust). Searching for your -problem might reveal someone who has asked it before! - -There is an active [subreddit](https://reddit.com/r/rust) with lots of -discussion and news about Rust. - -There is also a [user forum](https://users.rust-lang.org), for all -user-oriented discussion, and a [developer -forum](https://internals.rust-lang.org/), where the development of Rust -itself is discussed. - # FAQs There are questions that are asked quite often, so we've made FAQs for them: diff --git a/src/doc/nomicon/other-reprs.md b/src/doc/nomicon/other-reprs.md index e361fbb7ae868..2639c1d4d6f76 100644 --- a/src/doc/nomicon/other-reprs.md +++ b/src/doc/nomicon/other-reprs.md @@ -26,6 +26,9 @@ still consumes a byte of space. * DSTs, tuples, and tagged unions are not a concept in C and as such are never FFI safe. +* Tuple structs are like structs with regards to `repr(C)`, as the only + difference from a struct is that the fields aren’t named. + * **If the type would have any [drop flags], they will still be added** * This is equivalent to one of `repr(u*)` (see the next section) for enums. The diff --git a/src/doc/nomicon/unbounded-lifetimes.md b/src/doc/nomicon/unbounded-lifetimes.md index 2c5ba79a5078f..1f2961b586136 100644 --- a/src/doc/nomicon/unbounded-lifetimes.md +++ b/src/doc/nomicon/unbounded-lifetimes.md @@ -32,6 +32,5 @@ Within a function, bounding lifetimes is more error-prone. The safest and easies way to bound a lifetime is to return it from a function with a bound lifetime. However if this is unacceptable, the reference can be placed in a location with a specific lifetime. Unfortunately it's impossible to name all lifetimes involved -in a function. To get around this, you can in principle use `copy_lifetime`, though -these are unstable due to their awkward nature and questionable utility. +in a function. diff --git a/src/doc/reference.md b/src/doc/reference.md index de9352a42753c..b1aa400d1e2a7 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -147,11 +147,11 @@ a form of constant expression, so is evaluated (primarily) at compile time. | | Example | `#` sets | Characters | Escapes | |----------------------------------------------|-----------------|------------|-------------|---------------------| -| [Character](#character-literals) | `'H'` | `N/A` | All Unicode | `\'` & [Byte](#byte-escapes) & [Unicode](#unicode-escapes) | -| [String](#string-literals) | `"hello"` | `N/A` | All Unicode | `\"` & [Byte](#byte-escapes) & [Unicode](#unicode-escapes) | +| [Character](#character-literals) | `'H'` | `N/A` | All Unicode | [Quote](#quote-escapes) & [Byte](#byte-escapes) & [Unicode](#unicode-escapes) | +| [String](#string-literals) | `"hello"` | `N/A` | All Unicode | [Quote](#quote-escapes) & [Byte](#byte-escapes) & [Unicode](#unicode-escapes) | | [Raw](#raw-string-literals) | `r#"hello"#` | `0...` | All Unicode | `N/A` | -| [Byte](#byte-literals) | `b'H'` | `N/A` | All ASCII | `\'` & [Byte](#byte-escapes) | -| [Byte string](#byte-string-literals) | `b"hello"` | `N/A` | All ASCII | `\"` & [Byte](#byte-escapes) | +| [Byte](#byte-literals) | `b'H'` | `N/A` | All ASCII | [Quote](#quote-escapes) & [Byte](#byte-escapes) | +| [Byte string](#byte-string-literals) | `b"hello"` | `N/A` | All ASCII | [Quote](#quote-escapes) & [Byte](#byte-escapes) | | [Raw byte string](#raw-byte-string-literals) | `br#"hello"#` | `0...` | All ASCII | `N/A` | ##### Byte escapes @@ -163,12 +163,19 @@ a form of constant expression, so is evaluated (primarily) at compile time. | `\r` | Carriage return | | `\t` | Tab | | `\\` | Backslash | +| `\0` | Null | ##### Unicode escapes | | Name | |---|------| | `\u{7FFF}` | 24-bit Unicode character code (up to 6 digits) | +##### Quote escapes +| | Name | +|---|------| +| `\'` | Single quote | +| `\"` | Double quote | + ##### Numbers | [Number literals](#number-literals)`*` | Example | Exponentiation | Suffixes | @@ -2415,9 +2422,9 @@ in meaning to declaring the item outside the statement block. > **Note**: there is no implicit capture of the function's dynamic environment when > declaring a function-local item. -#### Variable declarations +#### `let` statements -A _variable declaration_ introduces a new set of variable, given by a pattern. The +A _`let` statement_ introduces a new set of variables, given by a pattern. The pattern may be followed by a type annotation, and/or an initializer expression. When no type annotation is given, the compiler will infer the type, or signal an error if insufficient type information is available for definite inference. @@ -3190,10 +3197,11 @@ let message = match maybe_digit { ### `if let` expressions -An `if let` expression is semantically identical to an `if` expression but in place -of a condition expression it expects a refutable let statement. If the value of the -expression on the right hand side of the let statement matches the pattern, the corresponding -block will execute, otherwise flow proceeds to the first `else` block that follows. +An `if let` expression is semantically identical to an `if` expression but in +place of a condition expression it expects a `let` statement with a refutable +pattern. If the value of the expression on the right hand side of the `let` +statement matches the pattern, the corresponding block will execute, otherwise +flow proceeds to the first `else` block that follows. ``` let dish = ("Ham", "Eggs"); @@ -3211,11 +3219,11 @@ if let ("Ham", b) = dish { ### `while let` loops -A `while let` loop is semantically identical to a `while` loop but in place of a -condition expression it expects a refutable let statement. If the value of the -expression on the right hand side of the let statement matches the pattern, the -loop body block executes and control returns to the pattern matching statement. -Otherwise, the while expression completes. +A `while let` loop is semantically identical to a `while` loop but in place of +a condition expression it expects `let` statement with a refutable pattern. If +the value of the expression on the right hand side of the `let` statement +matches the pattern, the loop body block executes and control returns to the +pattern matching statement. Otherwise, the while expression completes. ### `return` expressions diff --git a/src/doc/trpl/ffi.md b/src/doc/trpl/ffi.md index 7a58a327b9f95..d949bf33b6eea 100644 --- a/src/doc/trpl/ffi.md +++ b/src/doc/trpl/ffi.md @@ -8,6 +8,23 @@ foreign code. Rust is currently unable to call directly into a C++ library, but snappy includes a C interface (documented in [`snappy-c.h`](https://github.com/google/snappy/blob/master/snappy-c.h)). +## A note about libc + +Many of these examples use [the `libc` crate][libc], which provides various +type definitions for C types, among other things. If you’re trying these +examples yourself, you’ll need to add `libc` to your `Cargo.toml`: + +```toml +[dependencies] +libc = "0.2.0" +``` + +[libc]: https://crates.io/crates/libc + +and add `extern crate libc;` to your crate root. + +## Calling foreign functions + The following is a minimal example of calling a foreign function which will compile if snappy is installed: diff --git a/src/doc/trpl/lifetimes.md b/src/doc/trpl/lifetimes.md index 13265ab1eba12..68bbd0c98993d 100644 --- a/src/doc/trpl/lifetimes.md +++ b/src/doc/trpl/lifetimes.md @@ -116,7 +116,8 @@ reference to an `i32` with the lifetime `'a`’. # In `struct`s -You’ll also need explicit lifetimes when working with [`struct`][structs]s: +You’ll also need explicit lifetimes when working with [`struct`][structs]s that +contain references: ```rust struct Foo<'a> { diff --git a/src/doc/trpl/ownership.md b/src/doc/trpl/ownership.md index d8ef44b782a1d..17b263ef00ab7 100644 --- a/src/doc/trpl/ownership.md +++ b/src/doc/trpl/ownership.md @@ -187,7 +187,7 @@ fn change_truth(x: bool) -> bool { } ``` -If we would have used types that do not implement the `Copy` trait, +If we had used types that do not implement the `Copy` trait, we would have gotten a compile error because we tried to use a moved value. ```text diff --git a/src/doc/trpl/references-and-borrowing.md b/src/doc/trpl/references-and-borrowing.md index 944417d1096b0..d8758e0c695c2 100644 --- a/src/doc/trpl/references-and-borrowing.md +++ b/src/doc/trpl/references-and-borrowing.md @@ -171,9 +171,9 @@ to the definition of a data race: > operations are not synchronized. With references, you may have as many as you’d like, since none of them are -writing. If you are writing, you need two or more pointers to the same memory, -and you can only have one `&mut` at a time. This is how Rust prevents data -races at compile time: we’ll get errors if we break the rules. +writing. However, as we can only have one `&mut` at a time, it is impossible to +have a data race. This is how Rust prevents data races at compile time: we’ll +get errors if we break the rules. With this in mind, let’s consider our example again. @@ -378,3 +378,4 @@ statement 1 at 3:14 In the above example, `y` is declared before `x`, meaning that `y` lives longer than `x`, which is not allowed. + diff --git a/src/doc/trpl/the-stack-and-the-heap.md b/src/doc/trpl/the-stack-and-the-heap.md index f835322ee716e..0c78f876aa037 100644 --- a/src/doc/trpl/the-stack-and-the-heap.md +++ b/src/doc/trpl/the-stack-and-the-heap.md @@ -7,6 +7,14 @@ and a heap. If you’re familiar with how C-like languages use stack allocation, this chapter will be a refresher. If you’re not, you’ll learn about this more general concept, but with a Rust-y focus. +As with most things, when learning about them, we’ll use a simplified model to +start. This lets you get a handle on the basics, without getting bogged down +with details which are, for now, irrelevant. The examples we’ll use aren’t 100% +accurate, but are representative for the level we’re trying to learn at right +now. Once you have the basics down, learning more about how allocators are +implemented, virtual memory, and other advanced topics will reveal the leaks in +this particular abstraction. + # Memory management These two terms are about memory management. The stack and the heap are diff --git a/src/doc/trpl/ufcs.md b/src/doc/trpl/ufcs.md index 2353c63a606af..7725970564be0 100644 --- a/src/doc/trpl/ufcs.md +++ b/src/doc/trpl/ufcs.md @@ -109,19 +109,28 @@ Here’s an example of using the longer form. ```rust trait Foo { - fn clone(&self); + fn foo() -> i32; } -#[derive(Clone)] struct Bar; -impl Foo for Bar { - fn clone(&self) { - println!("Making a clone of Bar"); +impl Bar { + fn foo() -> i32 { + 20 + } +} - ::clone(self); +impl Foo for Bar { + fn foo() -> i32 { + 10 } } + +fn main() { + assert_eq!(10, ::foo()); + assert_eq!(20, Bar::foo()); +} ``` -This will call the `Clone` trait’s `clone()` method, rather than `Foo`’s. +Using the angle bracket syntax lets you call the trait method instead of the +inherent one. diff --git a/src/etc/add-authors.sh b/src/etc/add-authors.sh old mode 100644 new mode 100755 index 3ae0ec73957e7..e45b803fa07e2 --- a/src/etc/add-authors.sh +++ b/src/etc/add-authors.sh @@ -30,8 +30,8 @@ range="$1" authors_file="./AUTHORS.txt" tmp_file="./AUTHORS.txt.tmp" old_authors="$(cat "$authors_file" | tail -n +2 | sed "/^$/d" | sort)" -new_authors="$(git log "$range" --format="%aN <%aE>" | sort | uniq)" +new_authors="$(git log "$range" --use-mailmap --format="%aN <%aE>" | sort | uniq)" printf "%s\n\n" "Rust was written by these fine people:" > "$tmp_file" -printf "%s\n%s" "$old_authors" "$new_authors" | sort | uniq >> "$tmp_file" +printf "%s\n%s" "$old_authors" "$new_authors" | sort -fs | uniq >> "$tmp_file" mv -f "$tmp_file" "$authors_file" diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 34c8b5d4139fc..8205e13205ff8 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -87,6 +87,7 @@ use core::ptr::{self, Shared}; use core::marker::Unsize; use core::hash::{Hash, Hasher}; use core::{usize, isize}; +use core::convert::From; use heap::deallocate; const MAX_REFCOUNT: usize = (isize::MAX) as usize; @@ -896,6 +897,13 @@ impl Hash for Arc { } } +#[stable(feature = "from_for_ptrs", since = "1.6.0")] +impl From for Arc { + fn from(t: T) -> Self { + Arc::new(t) + } +} + #[cfg(test)] mod tests { use std::clone::Clone; @@ -910,6 +918,7 @@ mod tests { use std::vec::Vec; use super::{Arc, Weak}; use std::sync::Mutex; + use std::convert::From; struct Canary(*mut atomic::AtomicUsize); @@ -1139,6 +1148,13 @@ mod tests { drop(x); assert!(y.upgrade().is_none()); } + + #[test] + fn test_from_owned() { + let foo = 123; + let foo_arc = Arc::from(foo); + assert!(123 == *foo_arc); + } } impl borrow::Borrow for Arc { diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 2e4ac13b34d02..b5c6cdff119d6 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -67,6 +67,7 @@ use core::ops::{CoerceUnsized, Deref, DerefMut}; use core::ops::{Placer, Boxed, Place, InPlace, BoxPlace}; use core::ptr::{self, Unique}; use core::raw::TraitObject; +use core::convert::From; /// A value that represents the heap. This is the default place that the `box` /// keyword allocates into when no place is supplied. @@ -373,6 +374,13 @@ impl Hash for Box { } } +#[stable(feature = "from_for_ptrs", since = "1.6.0")] +impl From for Box { + fn from(t: T) -> Self { + Box::new(t) + } +} + impl Box { #[inline] #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index b94e74ada9cef..88db3cfe4b612 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -169,6 +169,7 @@ use core::ops::Deref; #[cfg(not(stage0))] use core::ops::CoerceUnsized; use core::ptr::{self, Shared}; +use core::convert::From; use heap::deallocate; @@ -701,6 +702,13 @@ impl fmt::Pointer for Rc { } } +#[stable(feature = "from_for_ptrs", since = "1.6.0")] +impl From for Rc { + fn from(t: T) -> Self { + Rc::new(t) + } +} + /// A weak version of `Rc`. /// /// Weak references do not count when determining if the inner value should be @@ -906,6 +914,7 @@ mod tests { use std::result::Result::{Err, Ok}; use std::mem::drop; use std::clone::Clone; + use std::convert::From; #[test] fn test_clone() { @@ -1108,6 +1117,13 @@ mod tests { let foo: Rc<[i32]> = Rc::new([1, 2, 3]); assert_eq!(foo, foo.clone()); } + + #[test] + fn test_from_owned() { + let foo = 123; + let foo_rc = Rc::from(foo); + assert!(123 == *foo_rc); + } } impl borrow::Borrow for Rc { diff --git a/src/libcore/clone.rs b/src/libcore/clone.rs index 979ddd454121d..769faedf46e8e 100644 --- a/src/libcore/clone.rs +++ b/src/libcore/clone.rs @@ -24,6 +24,8 @@ use marker::Sized; /// A common trait for cloning an object. +/// +/// This trait can be used with `#[derive]`. #[stable(feature = "rust1", since = "1.0.0")] pub trait Clone : Sized { /// Returns a copy of the value. diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 5458a7b9c38b0..3ac4ffb22364f 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -43,6 +43,8 @@ use option::Option::{self, Some}; /// in terms of it by default. Any manual implementation of `ne` *must* respect /// the rule that `eq` is a strict inverse of `ne`; that is, `!(a == b)` if and /// only if `a != b`. +/// +/// This trait can be used with `#[derive]`. #[lang = "eq"] #[stable(feature = "rust1", since = "1.0.0")] pub trait PartialEq { @@ -69,6 +71,8 @@ pub trait PartialEq { /// /// This property cannot be checked by the compiler, and therefore `Eq` implies /// `PartialEq`, and has no extra methods. +/// +/// This trait can be used with `#[derive]`. #[stable(feature = "rust1", since = "1.0.0")] pub trait Eq: PartialEq { // FIXME #13101: this method is used solely by #[deriving] to @@ -171,6 +175,8 @@ impl Ordering { /// - transitive, `a < b` and `b < c` implies `a < c`. The same must hold for both `==` and `>`. /// /// When this trait is `derive`d, it produces a lexicographic ordering. +/// +/// This trait can be used with `#[derive]`. #[stable(feature = "rust1", since = "1.0.0")] pub trait Ord: Eq + PartialOrd { /// This method returns an `Ordering` between `self` and `other`. @@ -227,6 +233,8 @@ impl PartialOrd for Ordering { /// However it remains possible to implement the others separately for types which do not have a /// total order. For example, for floating point numbers, `NaN < 0 == false` and `NaN >= 0 == /// false` (cf. IEEE 754-2008 section 5.11). +/// +/// This trait can be used with `#[derive]`. #[lang = "ord"] #[stable(feature = "rust1", since = "1.0.0")] pub trait PartialOrd: PartialEq { diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 8fe65e27c0308..dfcc5781f0873 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -300,6 +300,8 @@ impl<'a> Display for Arguments<'a> { /// /// [module]: ../../std/fmt/index.html /// +/// This trait can be used with `#[derive]`. +/// /// # Examples /// /// Deriving an implementation: diff --git a/src/libcore/hash/mod.rs b/src/libcore/hash/mod.rs index 0899dc2884819..ea3a2f78d564a 100644 --- a/src/libcore/hash/mod.rs +++ b/src/libcore/hash/mod.rs @@ -93,6 +93,8 @@ mod sip; /// /// In other words, if two keys are equal, their hashes should also be equal. /// `HashMap` and `HashSet` both rely on this behavior. +/// +/// This trait can be used with `#[derive]`. #[stable(feature = "rust1", since = "1.0.0")] pub trait Hash { /// Feeds this value into the state given, updating the hasher as necessary. diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index df7b7c437c3cc..263d01a5d2637 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -10,12 +10,15 @@ //! # The Rust Core Library //! -//! The Rust Core Library is the dependency-free foundation of [The +//! The Rust Core Library is the dependency-free[^free] foundation of [The //! Rust Standard Library](../std/index.html). It is the portable glue //! between the language and its libraries, defining the intrinsic and //! primitive building blocks of all Rust code. It links to no //! upstream libraries, no system libraries, and no libc. //! +//! [^free]: Strictly speaking, there are some symbols which are needed but +//! they aren't always neccesary. +//! //! The core library is *minimal*: it isn't even aware of heap allocation, //! nor does it provide concurrency or I/O. These things require //! platform integration, and this library is platform-agnostic. diff --git a/src/libcore/marker.rs b/src/libcore/marker.rs index 6e6ae61852787..84a6196cc87ae 100644 --- a/src/libcore/marker.rs +++ b/src/libcore/marker.rs @@ -165,6 +165,10 @@ pub trait Unsize { /// to consider though: if you think your type may _not_ be able to implement `Copy` in the future, /// then it might be prudent to not implement `Copy`. This is because removing `Copy` is a breaking /// change: that second example would fail to compile if we made `Foo` non-`Copy`. +/// +/// # Derivable +/// +/// This trait can be used with `#[derive]`. #[stable(feature = "rust1", since = "1.0.0")] #[lang = "copy"] pub trait Copy : Clone { diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 3afc89c984142..c0f65fea7db38 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -124,15 +124,15 @@ macro_rules! int_impl { /// Returns the smallest value that can be represented by this integer type. #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn min_value() -> Self { + pub const fn min_value() -> Self { (-1 as Self) << ($BITS - 1) } /// Returns the largest value that can be represented by this integer type. #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn max_value() -> Self { - let min = Self::min_value(); !min + pub const fn max_value() -> Self { + !Self::min_value() } /// Converts a string slice in a given base to an integer. @@ -891,12 +891,12 @@ macro_rules! uint_impl { /// Returns the smallest value that can be represented by this integer type. #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn min_value() -> Self { 0 } + pub const fn min_value() -> Self { 0 } /// Returns the largest value that can be represented by this integer type. #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn max_value() -> Self { !0 } + pub const fn max_value() -> Self { !0 } /// Converts a string slice in a given base to an integer. /// diff --git a/src/librustc/front/map/blocks.rs b/src/librustc/front/map/blocks.rs index 7d4809d457c80..e6c165193f032 100644 --- a/src/librustc/front/map/blocks.rs +++ b/src/librustc/front/map/blocks.rs @@ -236,7 +236,7 @@ impl<'a> FnLikeNode<'a> { }, map::NodeImplItem(ii) => { match ii.node { - ast::MethodImplItem(ref sig, ref body) => { + ast::ImplItemKind::Method(ref sig, ref body) => { method(ii.id, ii.name, sig, Some(ii.vis), body, ii.span) } _ => { diff --git a/src/librustc/front/map/collector.rs b/src/librustc/front/map/collector.rs index f255949a9f519..54e2563a123ba 100644 --- a/src/librustc/front/map/collector.rs +++ b/src/librustc/front/map/collector.rs @@ -224,8 +224,8 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> { fn visit_impl_item(&mut self, ii: &'ast ImplItem) { let def_data = match ii.node { - MethodImplItem(..) | ConstImplItem(..) => DefPathData::Value(ii.name), - TypeImplItem(..) => DefPathData::Type(ii.name), + ImplItemKind::Method(..) | ImplItemKind::Const(..) => DefPathData::Value(ii.name), + ImplItemKind::Type(..) => DefPathData::Type(ii.name), }; self.insert_def(ii.id, NodeImplItem(ii), def_data); @@ -234,7 +234,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> { self.parent_node = ii.id; match ii.node { - ConstImplItem(_, ref expr) => { + ImplItemKind::Const(_, ref expr) => { self.create_def(expr.id, DefPathData::Initializer); } _ => { } @@ -313,4 +313,3 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> { self.create_def(macro_def.id, DefPathData::MacroDef(macro_def.name)); } } - diff --git a/src/librustc/front/map/mod.rs b/src/librustc/front/map/mod.rs index 11f0fd1bb2c5e..fb883c0ca0c08 100644 --- a/src/librustc/front/map/mod.rs +++ b/src/librustc/front/map/mod.rs @@ -937,18 +937,18 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String { } Some(NodeImplItem(ii)) => { match ii.node { - ConstImplItem(..) => { + ImplItemKind::Const(..) => { format!("assoc const {} in {}{}", ii.name, map.path_to_string(id), id_str) } - MethodImplItem(..) => { + ImplItemKind::Method(..) => { format!("method {} in {}{}", ii.name, map.path_to_string(id), id_str) } - TypeImplItem(_) => { + ImplItemKind::Type(_) => { format!("assoc type {} in {}{}", ii.name, map.path_to_string(id), diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 1cd196895e3a4..bfdbb6dadd43c 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -739,7 +739,7 @@ fn encode_info_for_method<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, let elem = ast_map::PathName(m.name); encode_path(rbml_w, impl_path.chain(Some(elem))); if let Some(impl_item) = impl_item_opt { - if let hir::MethodImplItem(ref sig, _) = impl_item.node { + if let hir::ImplItemKind::Method(ref sig, _) = impl_item.node { encode_attributes(rbml_w, &impl_item.attrs); let scheme = ecx.tcx.lookup_item_type(m.def_id); let any_types = !scheme.generics.types.is_empty(); diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index a3eeb12da0114..814c7c990bd6a 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -348,7 +348,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> { fn visit_impl_item(&mut self, i: &'v hir::ImplItem) { match i.node { - hir::ConstImplItem(_, ref expr) => { + hir::ImplItemKind::Const(_, ref expr) => { self.global_expr(Mode::Const, &*expr); } _ => self.with_mode(Mode::Var, |v| visit::walk_impl_item(v, i)), diff --git a/src/librustc/middle/check_static_recursion.rs b/src/librustc/middle/check_static_recursion.rs index dd49010c43672..ede37eb737f83 100644 --- a/src/librustc/middle/check_static_recursion.rs +++ b/src/librustc/middle/check_static_recursion.rs @@ -79,7 +79,7 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckCrateVisitor<'a, 'ast> { fn visit_impl_item(&mut self, ii: &'ast hir::ImplItem) { match ii.node { - hir::ConstImplItem(..) => { + hir::ImplItemKind::Const(..) => { let mut recursion_visitor = CheckItemRecursionVisitor::new(self, &ii.span); recursion_visitor.visit_impl_item(ii); diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index 34d002d334277..2660b6447fae7 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -129,7 +129,7 @@ pub fn lookup_const_by_id<'a, 'tcx: 'a>(tcx: &'a ty::ctxt<'tcx>, _ => None }, Some(ast_map::NodeImplItem(ii)) => match ii.node { - hir::ConstImplItem(_, ref expr) => { + hir::ImplItemKind::Const(_, ref expr) => { Some(&*expr) } _ => None @@ -171,7 +171,7 @@ pub fn lookup_const_by_id<'a, 'tcx: 'a>(tcx: &'a ty::ctxt<'tcx>, _ => None }, csearch::FoundAst::Found(&InlinedItem::ImplItem(_, ref ii)) => match ii.node { - hir::ConstImplItem(_, ref expr) => Some(expr.id), + hir::ImplItemKind::Const(_, ref expr) => Some(expr.id), _ => None }, _ => None @@ -996,7 +996,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>, }, ty::ImplContainer(_) => match tcx.map.find(node_id) { Some(ast_map::NodeImplItem(ii)) => match ii.node { - hir::ConstImplItem(ref ty, ref expr) => { + hir::ImplItemKind::Const(ref ty, ref expr) => { (Some(&**expr), Some(&**ty)) } _ => (None, None) diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index fff080a70e622..5892067ab08fe 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -358,14 +358,14 @@ impl<'v> Visitor<'v> for LifeSeeder { hir::ItemImpl(_, _, _, ref opt_trait, _, ref impl_items) => { for impl_item in impl_items { match impl_item.node { - hir::ConstImplItem(..) | - hir::MethodImplItem(..) => { + hir::ImplItemKind::Const(..) | + hir::ImplItemKind::Method(..) => { if opt_trait.is_some() || has_allow_dead_code_or_lang_attr(&impl_item.attrs) { self.worklist.push(impl_item.id); } } - hir::TypeImplItem(_) => {} + hir::ImplItemKind::Type(_) => {} } } } @@ -571,21 +571,21 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> { fn visit_impl_item(&mut self, impl_item: &hir::ImplItem) { match impl_item.node { - hir::ConstImplItem(_, ref expr) => { + hir::ImplItemKind::Const(_, ref expr) => { if !self.symbol_is_live(impl_item.id, None) { self.warn_dead_code(impl_item.id, impl_item.span, impl_item.name, "associated const"); } visit::walk_expr(self, expr) } - hir::MethodImplItem(_, ref body) => { + hir::ImplItemKind::Method(_, ref body) => { if !self.symbol_is_live(impl_item.id, None) { self.warn_dead_code(impl_item.id, impl_item.span, impl_item.name, "method"); } visit::walk_block(self, body) } - hir::TypeImplItem(..) => {} + hir::ImplItemKind::Type(..) => {} } } diff --git a/src/librustc/middle/infer/error_reporting.rs b/src/librustc/middle/infer/error_reporting.rs index a16ef808bb6d3..111872f1784cc 100644 --- a/src/librustc/middle/infer/error_reporting.rs +++ b/src/librustc/middle/infer/error_reporting.rs @@ -948,7 +948,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> { } ast_map::NodeImplItem(item) => { match item.node { - hir::MethodImplItem(ref sig, _) => { + hir::ImplItemKind::Method(ref sig, _) => { Some((&sig.decl, &sig.generics, sig.unsafety, @@ -1444,7 +1444,6 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { hir::TyTup(tys) => { hir::TyTup(tys.into_iter().map(|ty| build_to(ty, to)).collect()) } - hir::TyParen(typ) => hir::TyParen(build_to(typ, to)), other => other }; hir::Ty { id: id, node: new_node, span: span } @@ -1839,7 +1838,7 @@ fn lifetimes_in_scope(tcx: &ty::ctxt, }, ast_map::NodeImplItem(ii) => { match ii.node { - hir::MethodImplItem(ref sig, _) => { + hir::ImplItemKind::Method(ref sig, _) => { taken.push_all(&sig.generics.lifetimes); Some(ii.id) } diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 7175fbe0e570d..e5bc9030fc97d 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -185,8 +185,8 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { } Some(ast_map::NodeImplItem(impl_item)) => { match impl_item.node { - hir::ConstImplItem(..) => true, - hir::MethodImplItem(ref sig, _) => { + hir::ImplItemKind::Const(..) => true, + hir::ImplItemKind::Method(ref sig, _) => { if generics_require_inlining(&sig.generics) || attr::requests_inline(&impl_item.attrs) { true @@ -206,7 +206,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { } } } - hir::TypeImplItem(_) => false, + hir::ImplItemKind::Type(_) => false, } } Some(_) => false, @@ -299,16 +299,16 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { } ast_map::NodeImplItem(impl_item) => { match impl_item.node { - hir::ConstImplItem(_, ref expr) => { + hir::ImplItemKind::Const(_, ref expr) => { self.visit_expr(&*expr); } - hir::MethodImplItem(ref sig, ref body) => { + hir::ImplItemKind::Method(ref sig, ref body) => { let did = self.tcx.map.get_parent_did(search_item); if method_might_be_inlined(self.tcx, sig, impl_item, did) { visit::walk_block(self, body) } } - hir::TypeImplItem(_) => {} + hir::ImplItemKind::Type(_) => {} } } // Nothing to recurse on for these diff --git a/src/librustc/middle/ty/mod.rs b/src/librustc/middle/ty/mod.rs index 0a9fa1d6ce394..42bba0c8aeff6 100644 --- a/src/librustc/middle/ty/mod.rs +++ b/src/librustc/middle/ty/mod.rs @@ -1124,7 +1124,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> { match cx.map.find(id) { Some(ast_map::NodeImplItem(ref impl_item)) => { match impl_item.node { - hir::TypeImplItem(_) => { + hir::ImplItemKind::Type(_) => { // associated types don't have their own entry (for some reason), // so for now just grab environment for the impl let impl_id = cx.map.get_parent(id); @@ -1136,7 +1136,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> { &predicates, id) } - hir::ConstImplItem(_, _) => { + hir::ImplItemKind::Const(_, _) => { let def_id = cx.map.local_def_id(id); let scheme = cx.lookup_item_type(def_id); let predicates = cx.lookup_predicates(def_id); @@ -1145,7 +1145,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> { &predicates, id) } - hir::MethodImplItem(_, ref body) => { + hir::ImplItemKind::Method(_, ref body) => { let method_def_id = cx.map.local_def_id(id); match cx.impl_or_trait_item(method_def_id) { MethodTraitItem(ref method_ty) => { @@ -2158,7 +2158,7 @@ impl<'tcx> ctxt<'tcx> { } ItemImpl(_, _, _, _, _, ref iis) => { iis.iter().filter_map(|ii| { - if let hir::ConstImplItem(_, _) = ii.node { + if let hir::ImplItemKind::Const(_, _) = ii.node { match self.impl_or_trait_item(self.map.local_def_id(ii.id)) { ConstTraitItem(ac) => Some(ac), _ => { diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index ccb48ed2edfaa..f1eff5f55f29c 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -89,7 +89,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for BorrowckCtxt<'a, 'tcx> { } fn visit_impl_item(&mut self, ii: &hir::ImplItem) { - if let hir::ConstImplItem(_, ref expr) = ii.node { + if let hir::ImplItemKind::Const(_, ref expr) = ii.node { gather_loans::gather_loans_in_static_initializer(self, &*expr); } visit::walk_impl_item(self, ii); diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index bdad13526b882..04f7938e9ba4f 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -623,7 +623,7 @@ impl fold::Folder for ReplaceBodyWithLoop { fn fold_impl_item(&mut self, i: P) -> SmallVector> { match i.node { - ast::ConstImplItem(..) => { + ast::ImplItemKind::Const(..) => { self.within_static_or_const = true; let ret = fold::noop_fold_impl_item(i, self); self.within_static_or_const = false; diff --git a/src/librustc_front/fold.rs b/src/librustc_front/fold.rs index 955de44b43f6e..b963aba9c07eb 100644 --- a/src/librustc_front/fold.rs +++ b/src/librustc_front/fold.rs @@ -382,7 +382,6 @@ pub fn noop_fold_ty(t: P, fld: &mut T) -> P { })) } TyTup(tys) => TyTup(tys.move_map(|ty| fld.fold_ty(ty))), - TyParen(ty) => TyParen(fld.fold_ty(ty)), TyPath(qself, path) => { let qself = qself.map(|QSelf { ty, position }| { QSelf { @@ -867,13 +866,13 @@ pub fn noop_fold_impl_item(i: P, folder: &mut T) -> P { - ConstImplItem(folder.fold_ty(ty), folder.fold_expr(expr)) + ImplItemKind::Const(ty, expr) => { + ImplItemKind::Const(folder.fold_ty(ty), folder.fold_expr(expr)) } - MethodImplItem(sig, body) => { - MethodImplItem(noop_fold_method_sig(sig, folder), folder.fold_block(body)) + ImplItemKind::Method(sig, body) => { + ImplItemKind::Method(noop_fold_method_sig(sig, folder), folder.fold_block(body)) } - TypeImplItem(ty) => TypeImplItem(folder.fold_ty(ty)), + ImplItemKind::Type(ty) => ImplItemKind::Type(folder.fold_ty(ty)), }, span: folder.new_span(span), } diff --git a/src/librustc_front/hir.rs b/src/librustc_front/hir.rs index b017a07dde0a1..1fa7c9d301c0d 100644 --- a/src/librustc_front/hir.rs +++ b/src/librustc_front/hir.rs @@ -19,7 +19,6 @@ pub use self::ExplicitSelf_::*; pub use self::Expr_::*; pub use self::FunctionRetTy::*; pub use self::ForeignItem_::*; -pub use self::ImplItem_::*; pub use self::Item_::*; pub use self::Mutability::*; pub use self::Pat_::*; @@ -771,15 +770,15 @@ pub struct ImplItem { pub name: Name, pub vis: Visibility, pub attrs: Vec, - pub node: ImplItem_, + pub node: ImplItemKind, pub span: Span, } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum ImplItem_ { - ConstImplItem(P, P), - MethodImplItem(MethodSig, P), - TypeImplItem(P), +pub enum ImplItemKind { + Const(P, P), + Method(MethodSig, P), + Type(P), } // Bind a type to an associated type: `A=Foo`. @@ -848,8 +847,6 @@ pub enum Ty_ { TyObjectSum(P, TyParamBounds), /// A type like `for<'a> Foo<&'a Bar>` TyPolyTraitRef(TyParamBounds), - /// No-op; kept solely so that we can pretty-print faithfully - TyParen(P), /// Unused for now TyTypeof(P), /// TyInfer means the type should be inferred instead of it having been diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index d13b92c04f82a..8ef49d185f727 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -225,7 +225,9 @@ pub fn lower_ty(_lctx: &LoweringContext, t: &Ty) -> P { })) } TyTup(ref tys) => hir::TyTup(tys.iter().map(|ty| lower_ty(_lctx, ty)).collect()), - TyParen(ref ty) => hir::TyParen(lower_ty(_lctx, ty)), + TyParen(ref ty) => { + return lower_ty(_lctx, ty); + } TyPath(ref qself, ref path) => { let qself = qself.as_ref().map(|&QSelf { ref ty, position }| { hir::QSelf { @@ -675,14 +677,14 @@ pub fn lower_impl_item(_lctx: &LoweringContext, i: &ImplItem) -> P { - hir::ConstImplItem(lower_ty(_lctx, ty), lower_expr(_lctx, expr)) + ImplItemKind::Const(ref ty, ref expr) => { + hir::ImplItemKind::Const(lower_ty(_lctx, ty), lower_expr(_lctx, expr)) } - MethodImplItem(ref sig, ref body) => { - hir::MethodImplItem(lower_method_sig(_lctx, sig), lower_block(_lctx, body)) + ImplItemKind::Method(ref sig, ref body) => { + hir::ImplItemKind::Method(lower_method_sig(_lctx, sig), lower_block(_lctx, body)) } - TypeImplItem(ref ty) => hir::TypeImplItem(lower_ty(_lctx, ty)), - MacImplItem(..) => panic!("Shouldn't exist any more"), + ImplItemKind::Type(ref ty) => hir::ImplItemKind::Type(lower_ty(_lctx, ty)), + ImplItemKind::Macro(..) => panic!("Shouldn't exist any more"), }, span: i.span, }) diff --git a/src/librustc_front/print/pprust.rs b/src/librustc_front/print/pprust.rs index 2fd374f756050..09c814449a9bc 100644 --- a/src/librustc_front/print/pprust.rs +++ b/src/librustc_front/print/pprust.rs @@ -506,11 +506,6 @@ impl<'a> State<'a> { } try!(self.pclose()); } - hir::TyParen(ref typ) => { - try!(self.popen()); - try!(self.print_type(&**typ)); - try!(self.pclose()); - } hir::TyBareFn(ref f) => { let generics = hir::Generics { lifetimes: f.lifetimes.clone(), @@ -1011,16 +1006,16 @@ impl<'a> State<'a> { try!(self.maybe_print_comment(ii.span.lo)); try!(self.print_outer_attributes(&ii.attrs)); match ii.node { - hir::ConstImplItem(ref ty, ref expr) => { + hir::ImplItemKind::Const(ref ty, ref expr) => { try!(self.print_associated_const(ii.name, &ty, Some(&expr), ii.vis)); } - hir::MethodImplItem(ref sig, ref body) => { + hir::ImplItemKind::Method(ref sig, ref body) => { try!(self.head("")); try!(self.print_method_sig(ii.name, sig, ii.vis)); try!(self.nbsp()); try!(self.print_block_with_attrs(body, &ii.attrs)); } - hir::TypeImplItem(ref ty) => { + hir::ImplItemKind::Type(ref ty) => { try!(self.print_associated_type(ii.name, None, Some(ty))); } } diff --git a/src/librustc_front/visit.rs b/src/librustc_front/visit.rs index 94986ceced60a..ec58f31b6decd 100644 --- a/src/librustc_front/visit.rs +++ b/src/librustc_front/visit.rs @@ -349,7 +349,7 @@ pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V, pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) { match typ.node { - TyVec(ref ty) | TyParen(ref ty) => { + TyVec(ref ty) => { visitor.visit_ty(ty) } TyPtr(ref mutable_type) => { @@ -614,18 +614,18 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt visitor.visit_name(impl_item.span, impl_item.name); walk_list!(visitor, visit_attribute, &impl_item.attrs); match impl_item.node { - ConstImplItem(ref ty, ref expr) => { + ImplItemKind::Const(ref ty, ref expr) => { visitor.visit_ty(ty); visitor.visit_expr(expr); } - MethodImplItem(ref sig, ref body) => { + ImplItemKind::Method(ref sig, ref body) => { visitor.visit_fn(FnKind::Method(impl_item.name, sig, Some(impl_item.vis)), &sig.decl, body, impl_item.span, impl_item.id); } - TypeImplItem(ref ty) => { + ImplItemKind::Type(ref ty) => { visitor.visit_ty(ty); } } diff --git a/src/librustc_lint/bad_style.rs b/src/librustc_lint/bad_style.rs index 693de1740bfee..53fc0824d9673 100644 --- a/src/librustc_lint/bad_style.rs +++ b/src/librustc_lint/bad_style.rs @@ -351,7 +351,7 @@ impl LateLintPass for NonUpperCaseGlobals { fn check_impl_item(&mut self, cx: &LateContext, ii: &hir::ImplItem) { match ii.node { - hir::ConstImplItem(..) => { + hir::ImplItemKind::Const(..) => { NonUpperCaseGlobals::check_upper_case(cx, "associated constant", ii.name, ii.span); } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index a001289b196a9..516c9dcae71a3 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -505,9 +505,9 @@ impl LateLintPass for MissingDoc { } let desc = match impl_item.node { - hir::ConstImplItem(..) => "an associated constant", - hir::MethodImplItem(..) => "a method", - hir::TypeImplItem(_) => "an associated type", + hir::ImplItemKind::Const(..) => "an associated constant", + hir::ImplItemKind::Method(..) => "a method", + hir::ImplItemKind::Type(_) => "an associated type", }; self.check_missing_docs_attrs(cx, Some(impl_item.id), &impl_item.attrs, diff --git a/src/librustc_mir/mir_map.rs b/src/librustc_mir/mir_map.rs index 1359cbc82a662..a6b7169e18b40 100644 --- a/src/librustc_mir/mir_map.rs +++ b/src/librustc_mir/mir_map.rs @@ -99,10 +99,10 @@ impl<'a, 'tcx> visit::Visitor<'tcx> for OuterDump<'a, 'tcx> { fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) { match impl_item.node { - hir::MethodImplItem(..) => { + hir::ImplItemKind::Method(..) => { self.visit_mir(&impl_item.attrs, |c| visit::walk_impl_item(c, impl_item)); } - hir::ConstImplItem(..) | hir::TypeImplItem(..) => {} + hir::ImplItemKind::Const(..) | hir::ImplItemKind::Type(..) => {} } visit::walk_impl_item(self, impl_item); } diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index a8600d91a2689..ab9b32383b221 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -553,8 +553,8 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> { // where the method was defined? Some(ast_map::NodeImplItem(ii)) => { match ii.node { - hir::ConstImplItem(..) | - hir::MethodImplItem(..) => { + hir::ImplItemKind::Const(..) | + hir::ImplItemKind::Method(..) => { let imp = self.tcx.map .get_parent_did(closest_private_id); match self.tcx.impl_trait_ref(imp) { @@ -565,7 +565,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> { _ => ii.vis } } - hir::TypeImplItem(_) => return Allowable, + hir::ImplItemKind::Type(_) => return Allowable, } } Some(ast_map::NodeTraitItem(_)) => { @@ -1293,11 +1293,11 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> { impl_items.iter() .any(|impl_item| { match impl_item.node { - hir::ConstImplItem(..) | - hir::MethodImplItem(..) => { + hir::ImplItemKind::Const(..) | + hir::ImplItemKind::Method(..) => { self.exported_items.contains(&impl_item.id) } - hir::TypeImplItem(_) => false, + hir::ImplItemKind::Type(_) => false, } }); @@ -1316,13 +1316,13 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> { // don't erroneously report errors for private // types in private items. match impl_item.node { - hir::ConstImplItem(..) | - hir::MethodImplItem(..) + hir::ImplItemKind::Const(..) | + hir::ImplItemKind::Method(..) if self.item_is_public(&impl_item.id, impl_item.vis) => { visit::walk_impl_item(self, impl_item) } - hir::TypeImplItem(..) => { + hir::ImplItemKind::Type(..) => { visit::walk_impl_item(self, impl_item) } _ => {} @@ -1347,7 +1347,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> { // Those in 3. are warned with this call. for impl_item in impl_items { - if let hir::TypeImplItem(ref ty) = impl_item.node { + if let hir::ImplItemKind::Type(ref ty) = impl_item.node { self.visit_ty(ty); } } @@ -1359,13 +1359,13 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> { let mut found_pub_static = false; for impl_item in impl_items { match impl_item.node { - hir::ConstImplItem(..) => { + hir::ImplItemKind::Const(..) => { if self.item_is_public(&impl_item.id, impl_item.vis) { found_pub_static = true; visit::walk_impl_item(self, impl_item); } } - hir::MethodImplItem(ref sig, _) => { + hir::ImplItemKind::Method(ref sig, _) => { if sig.explicit_self.node == hir::SelfStatic && self.item_is_public(&impl_item.id, impl_item.vis) { found_pub_static = true; diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index a6665a137865d..f35b554d6cf2b 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -806,6 +806,15 @@ mod something { pub struct Foo; } ``` + +Or, if you tried to use a module from an external crate, you may have missed +the `extern crate` declaration: + +``` +extern crate homura; // Required to use the `homura` crate + +use homura::Madoka; +``` "##, E0433: r##" diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index a402d8310f96a..0ead5fad92f82 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -79,7 +79,7 @@ use syntax::codemap::{self, Span, Pos}; use rustc_front::visit::{self, FnKind, Visitor}; use rustc_front::hir; use rustc_front::hir::{Arm, BindByRef, BindByValue, BindingMode, Block}; -use rustc_front::hir::{ConstImplItem, Crate}; +use rustc_front::hir::Crate; use rustc_front::hir::{Expr, ExprAgain, ExprBreak, ExprField}; use rustc_front::hir::{ExprLoop, ExprWhile, ExprMethodCall}; use rustc_front::hir::{ExprPath, ExprStruct, FnDecl}; @@ -87,12 +87,11 @@ use rustc_front::hir::{ForeignItemFn, ForeignItemStatic, Generics}; use rustc_front::hir::{ImplItem, Item, ItemConst, ItemEnum, ItemExternCrate}; use rustc_front::hir::{ItemFn, ItemForeignMod, ItemImpl, ItemMod, ItemStatic, ItemDefaultImpl}; use rustc_front::hir::{ItemStruct, ItemTrait, ItemTy, ItemUse}; -use rustc_front::hir::{Local, MethodImplItem}; +use rustc_front::hir::Local; use rustc_front::hir::{Pat, PatEnum, PatIdent, PatLit, PatQPath}; use rustc_front::hir::{PatRange, PatStruct, Path, PrimTy}; use rustc_front::hir::{TraitRef, Ty, TyBool, TyChar, TyFloat, TyInt}; use rustc_front::hir::{TyRptr, TyStr, TyUint, TyPath, TyPtr}; -use rustc_front::hir::TypeImplItem; use rustc_front::util::walk_pat; use std::collections::{HashMap, HashSet}; @@ -2421,7 +2420,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { this.with_current_self_type(self_type, |this| { for impl_item in impl_items { match impl_item.node { - ConstImplItem(..) => { + hir::ImplItemKind::Const(..) => { // If this is a trait impl, ensure the const // exists in trait this.check_trait_item(impl_item.name, @@ -2431,7 +2430,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { visit::walk_impl_item(this, impl_item); }); } - MethodImplItem(ref sig, _) => { + hir::ImplItemKind::Method(ref sig, _) => { // If this is a trait impl, ensure the method // exists in trait this.check_trait_item(impl_item.name, @@ -2448,7 +2447,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { visit::walk_impl_item(this, impl_item); }); } - TypeImplItem(ref ty) => { + hir::ImplItemKind::Type(ref ty) => { // If this is a trait impl, ensure the type // exists in trait this.check_trait_item(impl_item.name, @@ -3545,7 +3544,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { _ => return false, }, hir_map::NodeImplItem(impl_item) => match impl_item.node { - hir::MethodImplItem(ref sig, _) => sig, + hir::ImplItemKind::Method(ref sig, _) => sig, _ => return false, }, _ => return false, diff --git a/src/librustc_trans/save/dump_csv.rs b/src/librustc_trans/save/dump_csv.rs index 3ea631bd7fb67..682e203f85617 100644 --- a/src/librustc_trans/save/dump_csv.rs +++ b/src/librustc_trans/save/dump_csv.rs @@ -992,22 +992,22 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> { fn visit_impl_item(&mut self, impl_item: &ast::ImplItem) { match impl_item.node { - ast::ConstImplItem(ref ty, ref expr) => { + ast::ImplItemKind::Const(ref ty, ref expr) => { self.process_const(impl_item.id, impl_item.ident.name, impl_item.span, &ty, &expr); } - ast::MethodImplItem(ref sig, ref body) => { + ast::ImplItemKind::Method(ref sig, ref body) => { self.process_method(sig, Some(body), impl_item.id, impl_item.ident.name, impl_item.span); } - ast::TypeImplItem(_) | - ast::MacImplItem(_) => {} + ast::ImplItemKind::Type(_) | + ast::ImplItemKind::Macro(_) => {} } } diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index ecd4c75c9d35d..c87d9ab7bf049 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -1326,7 +1326,7 @@ fn build_cfg(tcx: &ty::ctxt, id: ast::NodeId) -> (ast::NodeId, Option) } Some(hir_map::NodeImplItem(impl_item)) => { match impl_item.node { - hir::MethodImplItem(_, ref body) => body, + hir::ImplItemKind::Method(_, ref body) => body, _ => { tcx.sess.bug("unexpected variant: non-method impl item in \ has_nested_returns") @@ -2614,7 +2614,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef { hir_map::NodeImplItem(impl_item) => { match impl_item.node { - hir::MethodImplItem(..) => { + hir::ImplItemKind::Method(..) => { register_method(ccx, id, &impl_item.attrs, impl_item.span) } _ => { diff --git a/src/librustc_trans/trans/debuginfo/mod.rs b/src/librustc_trans/trans/debuginfo/mod.rs index 9e53d72cfb8b9..74510de3f318a 100644 --- a/src/librustc_trans/trans/debuginfo/mod.rs +++ b/src/librustc_trans/trans/debuginfo/mod.rs @@ -253,7 +253,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, } hir_map::NodeImplItem(impl_item) => { match impl_item.node { - hir::MethodImplItem(ref sig, ref body) => { + hir::ImplItemKind::Method(ref sig, ref body) => { if contains_nodebug_attribute(&impl_item.attrs) { return FunctionDebugContext::FunctionWithoutDebugInfo; } diff --git a/src/librustc_trans/trans/inline.rs b/src/librustc_trans/trans/inline.rs index 14e1ca7675f79..0e837d83686af 100644 --- a/src/librustc_trans/trans/inline.rs +++ b/src/librustc_trans/trans/inline.rs @@ -160,7 +160,7 @@ fn instantiate_inline(ccx: &CrateContext, fn_id: DefId) ccx.stats().n_inlines.set(ccx.stats().n_inlines.get() + 1); // Translate monomorphic impl methods immediately. - if let hir::MethodImplItem(ref sig, ref body) = impl_item.node { + if let hir::ImplItemKind::Method(ref sig, ref body) = impl_item.node { let impl_tpt = ccx.tcx().lookup_item_type(impl_did); if impl_tpt.generics.types.is_empty() && sig.generics.ty_params.is_empty() { diff --git a/src/librustc_trans/trans/meth.rs b/src/librustc_trans/trans/meth.rs index ff94e4feda216..20388929cbd7a 100644 --- a/src/librustc_trans/trans/meth.rs +++ b/src/librustc_trans/trans/meth.rs @@ -70,7 +70,7 @@ pub fn trans_impl(ccx: &CrateContext, if !generics.ty_params.is_empty() { for impl_item in impl_items { match impl_item.node { - hir::MethodImplItem(..) => { + hir::ImplItemKind::Method(..) => { visit::walk_impl_item(&mut v, impl_item); } _ => {} @@ -80,7 +80,7 @@ pub fn trans_impl(ccx: &CrateContext, } for impl_item in impl_items { match impl_item.node { - hir::MethodImplItem(ref sig, ref body) => { + hir::ImplItemKind::Method(ref sig, ref body) => { if sig.generics.ty_params.is_empty() { let trans_everywhere = attr::requests_inline(&impl_item.attrs); for (ref ccx, is_origin) in ccx.maybe_iter(trans_everywhere) { diff --git a/src/librustc_trans/trans/monomorphize.rs b/src/librustc_trans/trans/monomorphize.rs index 1f9116f7491d1..9c1fcaff7c895 100644 --- a/src/librustc_trans/trans/monomorphize.rs +++ b/src/librustc_trans/trans/monomorphize.rs @@ -206,7 +206,7 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, } hir_map::NodeImplItem(impl_item) => { match impl_item.node { - hir::MethodImplItem(ref sig, ref body) => { + hir::ImplItemKind::Method(ref sig, ref body) => { let d = mk_lldecl(abi::Rust); let needs_body = setup_lldecl(d, &impl_item.attrs); if needs_body { diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 34378445c6087..7de262dfa5b95 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1624,7 +1624,6 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>, .collect(); tcx.mk_tup(flds) } - hir::TyParen(ref typ) => ast_ty_to_ty(this, rscope, &**typ), hir::TyBareFn(ref bf) => { require_c_abi_if_variadic(tcx, &bf.decl, bf.abi, ast_ty.span); let bare_fn = ty_of_bare_fn(this, bf.unsafety, bf.abi, &*bf.decl); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index cfa32bc073a1f..5ed6b62e8c3ef 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -764,14 +764,14 @@ pub fn check_item_body<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, it: &'tcx hir::Item) { for impl_item in impl_items { match impl_item.node { - hir::ConstImplItem(_, ref expr) => { + hir::ImplItemKind::Const(_, ref expr) => { check_const(ccx, impl_item.span, &*expr, impl_item.id) } - hir::MethodImplItem(ref sig, ref body) => { + hir::ImplItemKind::Method(ref sig, ref body) => { check_method_body(ccx, &impl_pty.generics, sig, body, impl_item.id, impl_item.span); } - hir::TypeImplItem(_) => { + hir::ImplItemKind::Type(_) => { // Nothing to do here. } } @@ -908,7 +908,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, impl_trait_ref)); }); match impl_item.node { - hir::ConstImplItem(..) => { + hir::ImplItemKind::Const(..) => { let impl_const = match ty_impl_item { ty::ConstTraitItem(ref cti) => cti, _ => tcx.sess.span_bug(impl_item.span, "non-const impl-item for const") @@ -929,7 +929,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, impl_trait_ref) } } - hir::MethodImplItem(ref sig, ref body) => { + hir::ImplItemKind::Method(ref sig, ref body) => { check_trait_fn_not_const(ccx, impl_item.span, sig.constness); let impl_method = match ty_impl_item { @@ -952,7 +952,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, impl_trait_ref) } } - hir::TypeImplItem(_) => { + hir::ImplItemKind::Type(_) => { let impl_type = match ty_impl_item { ty::TypeTraitItem(ref tti) => tti, _ => tcx.sess.span_bug(impl_item.span, "non-type impl-item for type") @@ -983,7 +983,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, ty::ConstTraitItem(ref associated_const) => { let is_implemented = impl_items.iter().any(|ii| { match ii.node { - hir::ConstImplItem(..) => { + hir::ImplItemKind::Const(..) => { ii.name == associated_const.name } _ => false, @@ -1003,7 +1003,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, let is_implemented = impl_items.iter().any(|ii| { match ii.node { - hir::MethodImplItem(..) => { + hir::ImplItemKind::Method(..) => { ii.name == trait_method.name } _ => false, @@ -1022,7 +1022,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, ty::TypeTraitItem(ref associated_type) => { let is_implemented = impl_items.iter().any(|ii| { match ii.node { - hir::TypeImplItem(_) => { + hir::ImplItemKind::Type(_) => { ii.name == associated_type.name } _ => false, diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index b3ec10a8941dc..6b2994d9dc06a 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -196,13 +196,13 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { impl_items.iter().map(|impl_item| { let impl_def_id = self.crate_context.tcx.map.local_def_id(impl_item.id); match impl_item.node { - hir::ConstImplItem(..) => { + hir::ImplItemKind::Const(..) => { ConstTraitItemId(impl_def_id) } - hir::MethodImplItem(..) => { + hir::ImplItemKind::Method(..) => { MethodTraitItemId(impl_def_id) } - hir::TypeImplItem(_) => { + hir::ImplItemKind::Type(_) => { TypeTraitItemId(impl_def_id) } } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 185623a440253..80f9018299245 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -821,14 +821,14 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) { for impl_item in impl_items { let seen_items = match impl_item.node { - hir::TypeImplItem(_) => &mut seen_type_items, + hir::ImplItemKind::Type(_) => &mut seen_type_items, _ => &mut seen_value_items, }; if !seen_items.insert(impl_item.name) { let desc = match impl_item.node { - hir::ConstImplItem(_, _) => "associated constant", - hir::TypeImplItem(_) => "associated type", - hir::MethodImplItem(ref sig, _) => + hir::ImplItemKind::Const(_, _) => "associated constant", + hir::ImplItemKind::Type(_) => "associated type", + hir::ImplItemKind::Method(ref sig, _) => match sig.explicit_self.node { hir::SelfStatic => "associated function", _ => "method", @@ -838,7 +838,7 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) { span_err!(tcx.sess, impl_item.span, E0201, "duplicate {}", desc); } - if let hir::ConstImplItem(ref ty, _) = impl_item.node { + if let hir::ImplItemKind::Const(ref ty, _) = impl_item.node { let ty = ccx.icx(&ty_predicates) .to_ty(&ExplicitRscope, &*ty); tcx.register_item_type(ccx.tcx.map.local_def_id(impl_item.id), @@ -855,7 +855,7 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) { // Convert all the associated types. for impl_item in impl_items { - if let hir::TypeImplItem(ref ty) = impl_item.node { + if let hir::ImplItemKind::Type(ref ty) = impl_item.node { if opt_trait_ref.is_none() { span_err!(tcx.sess, impl_item.span, E0202, "associated types are not allowed in inherent impls"); @@ -870,7 +870,7 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) { } let methods = impl_items.iter().filter_map(|ii| { - if let hir::MethodImplItem(ref sig, _) = ii.node { + if let hir::ImplItemKind::Method(ref sig, _) = ii.node { // if the method specifies a visibility, use that, otherwise // inherit the visibility from the impl (so `foo` in `pub impl // { fn foo(); }` is public, but private in `impl { fn @@ -889,7 +889,7 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) { &ty_predicates); for impl_item in impl_items { - if let hir::MethodImplItem(ref sig, ref body) = impl_item.node { + if let hir::ImplItemKind::Method(ref sig, ref body) = impl_item.node { let body_id = body.id; check_method_self_type(ccx, &BindingRscope::new(), diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 34ddd5726d385..c88b2dcdb748b 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1271,16 +1271,16 @@ impl Clean for hir::TraitItem { impl Clean for hir::ImplItem { fn clean(&self, cx: &DocContext) -> Item { let inner = match self.node { - hir::ConstImplItem(ref ty, ref expr) => { + hir::ImplItemKind::Const(ref ty, ref expr) => { ConstantItem(Constant{ type_: ty.clean(cx), expr: expr.span.to_src(cx), }) } - hir::MethodImplItem(ref sig, _) => { + hir::ImplItemKind::Method(ref sig, _) => { MethodItem(sig.clean(cx)) } - hir::TypeImplItem(ref ty) => TypedefItem(Typedef { + hir::ImplItemKind::Type(ref ty) => TypedefItem(Typedef { type_: ty.clean(cx), generics: Generics { lifetimes: Vec::new(), @@ -1606,7 +1606,6 @@ impl Clean for hir::Ty { } } TyBareFn(ref barefn) => BareFunction(box barefn.clean(cx)), - TyParen(ref ty) => ty.clean(cx), TyPolyTraitRef(ref bounds) => { PolyTraitRef(bounds.clean(cx)) }, diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index c0cd6d127d285..48631bfc5f9de 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -66,7 +66,7 @@ use sys_common::poison::{self, TryLockError, TryLockResult, LockResult}; /// for _ in 0..10 { /// let (data, tx) = (data.clone(), tx.clone()); /// thread::spawn(move || { -/// // The shared static can only be accessed once the lock is held. +/// // The shared state can only be accessed once the lock is held. /// // Our non-atomic increment is safe because we're the only thread /// // which can access the shared state when the lock is held. /// // diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 3c53db53f85f1..dabc809027029 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -167,22 +167,20 @@ impl StdError for JoinPathsError { #[cfg(target_os = "freebsd")] pub fn current_exe() -> io::Result { unsafe { - use libc::funcs::bsd44::*; - use libc::consts::os::extra::*; - let mut mib = [CTL_KERN as c_int, - KERN_PROC as c_int, - KERN_PROC_PATHNAME as c_int, + let mut mib = [libc::CTL_KERN as c_int, + libc::KERN_PROC as c_int, + libc::KERN_PROC_PATHNAME as c_int, -1 as c_int]; let mut sz: libc::size_t = 0; - let err = sysctl(mib.as_mut_ptr(), mib.len() as ::libc::c_uint, - ptr::null_mut(), &mut sz, ptr::null_mut(), - 0 as libc::size_t); + let err = libc::sysctl(mib.as_mut_ptr(), mib.len() as ::libc::c_uint, + ptr::null_mut(), &mut sz, ptr::null_mut(), + 0 as libc::size_t); if err != 0 { return Err(io::Error::last_os_error()); } if sz == 0 { return Err(io::Error::last_os_error()); } let mut v: Vec = Vec::with_capacity(sz as usize); - let err = sysctl(mib.as_mut_ptr(), mib.len() as ::libc::c_uint, - v.as_mut_ptr() as *mut libc::c_void, &mut sz, - ptr::null_mut(), 0 as libc::size_t); + let err = libc::sysctl(mib.as_mut_ptr(), mib.len() as ::libc::c_uint, + v.as_mut_ptr() as *mut libc::c_void, &mut sz, + ptr::null_mut(), 0 as libc::size_t); if err != 0 { return Err(io::Error::last_os_error()); } if sz == 0 { return Err(io::Error::last_os_error()); } v.set_len(sz as usize - 1); // chop off trailing NUL @@ -386,24 +384,33 @@ pub fn env() -> Env { let _g = ENV_LOCK.lock(); return unsafe { let mut environ = *environ(); - if environ as usize == 0 { + if environ == ptr::null() { panic!("os::env() failure getting env string from OS: {}", io::Error::last_os_error()); } let mut result = Vec::new(); while *environ != ptr::null() { - result.push(parse(CStr::from_ptr(*environ).to_bytes())); + if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) { + result.push(key_value); + } environ = environ.offset(1); } Env { iter: result.into_iter(), _dont_send_or_sync_me: ptr::null_mut() } }; - fn parse(input: &[u8]) -> (OsString, OsString) { - let mut it = input.splitn(2, |b| *b == b'='); - let key = it.next().unwrap().to_vec(); - let default: &[u8] = &[]; - let val = it.next().unwrap_or(default).to_vec(); - (OsStringExt::from_vec(key), OsStringExt::from_vec(val)) + fn parse(input: &[u8]) -> Option<(OsString, OsString)> { + // Strategy (copied from glibc): Variable name and value are separated + // by an ASCII equals sign '='. Since a variable name must not be + // empty, allow variable names starting with an equals sign. Skip all + // malformed lines. + if input.is_empty() { + return None; + } + let pos = input[1..].iter().position(|&b| b == b'=').map(|p| p + 1); + pos.map(|p| ( + OsStringExt::from_vec(input[..p].to_vec()), + OsStringExt::from_vec(input[p+1..].to_vec()), + )) } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 1f34af617d588..e4697a7fd9149 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -20,7 +20,6 @@ pub use self::Expr_::*; pub use self::FloatTy::*; pub use self::FunctionRetTy::*; pub use self::ForeignItem_::*; -pub use self::ImplItem_::*; pub use self::IntTy::*; pub use self::Item_::*; pub use self::KleeneOp::*; @@ -1230,16 +1229,16 @@ pub struct ImplItem { pub ident: Ident, pub vis: Visibility, pub attrs: Vec, - pub node: ImplItem_, + pub node: ImplItemKind, pub span: Span, } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum ImplItem_ { - ConstImplItem(P, P), - MethodImplItem(MethodSig, P), - TypeImplItem(P), - MacImplItem(Mac), +pub enum ImplItemKind { + Const(P, P), + Method(MethodSig, P), + Type(P), + Macro(Mac), } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] @@ -1687,9 +1686,9 @@ pub enum Visibility { impl Visibility { pub fn inherit_from(&self, parent_visibility: Visibility) -> Visibility { - match self { - &Inherited => parent_visibility, - &Public => *self + match *self { + Inherited => parent_visibility, + Public => *self } } } diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index f1fd8be472830..870dea02212d1 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -174,6 +174,10 @@ impl SpanHandler { self.handler.emit(Some((&self.cm, sp)), msg, Bug); panic!(ExplicitBug); } + pub fn span_bug_no_panic(&self, sp: Span, msg: &str) { + self.handler.emit(Some((&self.cm, sp)), msg, Bug); + self.handler.bump_err_count(); + } pub fn span_unimpl(&self, sp: Span, msg: &str) -> ! { self.span_bug(sp, &format!("unimplemented {}", msg)); } diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index 5a0fc4fda0cca..625abf706caa4 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -480,7 +480,7 @@ impl<'a> TraitDef<'a> { ident: ident, vis: ast::Inherited, attrs: Vec::new(), - node: ast::TypeImplItem(type_def.to_ty(cx, + node: ast::ImplItemKind::Type(type_def.to_ty(cx, self.span, type_ident, generics @@ -895,7 +895,7 @@ impl<'a> MethodDef<'a> { span: trait_.span, vis: ast::Inherited, ident: method_ident, - node: ast::MethodImplItem(ast::MethodSig { + node: ast::ImplItemKind::Method(ast::MethodSig { generics: fn_generics, abi: abi, explicit_self: explicit_self, diff --git a/src/libsyntax/ext/deriving/generic/ty.rs b/src/libsyntax/ext/deriving/generic/ty.rs index 9e8e68c0b8cce..67826c9c6cdff 100644 --- a/src/libsyntax/ext/deriving/generic/ty.rs +++ b/src/libsyntax/ext/deriving/generic/ty.rs @@ -242,8 +242,8 @@ impl<'a> LifetimeBounds<'a> { cx.lifetime_def(span, cx.ident_of(*lt).name, bounds) }).collect(); let ty_params = self.bounds.iter().map(|t| { - match t { - &(ref name, ref bounds) => { + match *t { + (ref name, ref bounds) => { mk_ty_param(cx, span, *name, diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index ba07c452e2a59..a0e4fd301a2fb 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1030,23 +1030,23 @@ fn expand_item_multi_modifier(mut it: Annotatable, fn expand_impl_item(ii: P, fld: &mut MacroExpander) -> SmallVector> { match ii.node { - ast::MethodImplItem(..) => SmallVector::one(ii.map(|ii| ast::ImplItem { + ast::ImplItemKind::Method(..) => SmallVector::one(ii.map(|ii| ast::ImplItem { id: ii.id, ident: ii.ident, attrs: ii.attrs, vis: ii.vis, node: match ii.node { - ast::MethodImplItem(sig, body) => { + ast::ImplItemKind::Method(sig, body) => { let (sig, body) = expand_and_rename_method(sig, body, fld); - ast::MethodImplItem(sig, body) + ast::ImplItemKind::Method(sig, body) } _ => unreachable!() }, span: fld.new_span(ii.span) })), - ast::MacImplItem(_) => { + ast::ImplItemKind::Macro(_) => { let (span, mac) = ii.and_then(|ii| match ii.node { - ast::MacImplItem(mac) => (ii.span, mac), + ast::ImplItemKind::Macro(mac) => (ii.span, mac), _ => unreachable!() }); let maybe_new_items = diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index d743a601bbb4b..5e5b815818161 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -63,9 +63,9 @@ pub mod rt { impl ToTokens for Option { fn to_tokens(&self, cx: &ExtCtxt) -> Vec { - match self { - &Some(ref t) => t.to_tokens(cx), - &None => Vec::new(), + match *self { + Some(ref t) => t.to_tokens(cx), + None => Vec::new(), } } } diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index dded634882dc1..675482fd644cd 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -107,16 +107,16 @@ enum TokenTreeOrTokenTreeVec { impl TokenTreeOrTokenTreeVec { fn len(&self) -> usize { - match self { - &TtSeq(ref v) => v.len(), - &Tt(ref tt) => tt.len(), + match *self { + TtSeq(ref v) => v.len(), + Tt(ref tt) => tt.len(), } } fn get_tt(&self, index: usize) -> TokenTree { - match self { - &TtSeq(ref v) => v[index].clone(), - &Tt(ref tt) => tt.get_tt(index), + match *self { + TtSeq(ref v) => v[index].clone(), + Tt(ref tt) => tt.get_tt(index), } } } @@ -144,17 +144,17 @@ pub struct MatcherPos { pub fn count_names(ms: &[TokenTree]) -> usize { ms.iter().fold(0, |count, elt| { - count + match elt { - &TokenTree::Sequence(_, ref seq) => { + count + match *elt { + TokenTree::Sequence(_, ref seq) => { seq.num_captures } - &TokenTree::Delimited(_, ref delim) => { + TokenTree::Delimited(_, ref delim) => { count_names(&delim.tts) } - &TokenTree::Token(_, MatchNt(..)) => { + TokenTree::Token(_, MatchNt(..)) => { 1 } - &TokenTree::Token(_, _) => 0, + TokenTree::Token(_, _) => 0, } }) } @@ -203,18 +203,18 @@ pub fn nameize(p_s: &ParseSess, ms: &[TokenTree], res: &[Rc]) -> HashMap> { fn n_rec(p_s: &ParseSess, m: &TokenTree, res: &[Rc], ret_val: &mut HashMap>, idx: &mut usize) { - match m { - &TokenTree::Sequence(_, ref seq) => { + match *m { + TokenTree::Sequence(_, ref seq) => { for next_m in &seq.tts { n_rec(p_s, next_m, res, ret_val, idx) } } - &TokenTree::Delimited(_, ref delim) => { + TokenTree::Delimited(_, ref delim) => { for next_m in &delim.tts { n_rec(p_s, next_m, res, ret_val, idx) } } - &TokenTree::Token(sp, MatchNt(bind_name, _, _, _)) => { + TokenTree::Token(sp, MatchNt(bind_name, _, _, _)) => { match ret_val.entry(bind_name.name) { Vacant(spot) => { spot.insert(res[*idx].clone()); @@ -228,8 +228,8 @@ pub fn nameize(p_s: &ParseSess, ms: &[TokenTree], res: &[Rc]) } } } - &TokenTree::Token(_, SubstNt(..)) => panic!("Cannot fill in a NT"), - &TokenTree::Token(_, _) => (), + TokenTree::Token(_, SubstNt(..)) => panic!("Cannot fill in a NT"), + TokenTree::Token(_, _) => (), } } let mut ret_val = HashMap::new(); diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 64429336562c5..ca232963e65a9 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -998,12 +998,12 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { fn visit_impl_item(&mut self, ii: &'v ast::ImplItem) { match ii.node { - ast::ConstImplItem(..) => { + ast::ImplItemKind::Const(..) => { self.gate_feature("associated_consts", ii.span, "associated constants are experimental") } - ast::MethodImplItem(ref sig, _) => { + ast::ImplItemKind::Method(ref sig, _) => { if sig.constness == ast::Constness::Const { self.gate_feature("const_fn", ii.span, "const fn is unstable"); } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 66ee5aa12ca88..3dba6cbecbd1c 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -1001,15 +1001,15 @@ pub fn noop_fold_impl_item(i: P, folder: &mut T) attrs: fold_attrs(attrs, folder), vis: vis, node: match node { - ConstImplItem(ty, expr) => { - ConstImplItem(folder.fold_ty(ty), folder.fold_expr(expr)) + ast::ImplItemKind::Const(ty, expr) => { + ast::ImplItemKind::Const(folder.fold_ty(ty), folder.fold_expr(expr)) } - MethodImplItem(sig, body) => { - MethodImplItem(noop_fold_method_sig(sig, folder), + ast::ImplItemKind::Method(sig, body) => { + ast::ImplItemKind::Method(noop_fold_method_sig(sig, folder), folder.fold_block(body)) } - TypeImplItem(ty) => TypeImplItem(folder.fold_ty(ty)), - MacImplItem(mac) => MacImplItem(folder.fold_mac(mac)) + ast::ImplItemKind::Type(ty) => ast::ImplItemKind::Type(folder.fold_ty(ty)), + ast::ImplItemKind::Macro(mac) => ast::ImplItemKind::Macro(folder.fold_mac(mac)) }, span: folder.new_span(span) })) diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index e1d8a4d8c5423..cb2181a083177 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -26,6 +26,7 @@ use std::rc::Rc; pub use ext::tt::transcribe::{TtReader, new_tt_reader, new_tt_reader_with_doc_flag}; pub mod comments; +mod unicode_chars; pub trait Reader { fn is_eof(&self) -> bool; @@ -1224,7 +1225,8 @@ impl<'a> StringReader<'a> { c => { let last_bpos = self.last_pos; let bpos = self.pos; - panic!(self.fatal_span_char(last_bpos, bpos, "unknown start of token", c)); + unicode_chars::check_for_substitution(&self, c); + panic!(self.fatal_span_char(last_bpos, bpos, "unknown start of token", c)) } } } diff --git a/src/libsyntax/parse/lexer/unicode_chars.rs b/src/libsyntax/parse/lexer/unicode_chars.rs new file mode 100644 index 0000000000000..dbec1a8851cfe --- /dev/null +++ b/src/libsyntax/parse/lexer/unicode_chars.rs @@ -0,0 +1,186 @@ +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Characters and their corresponding confusables were collected from +// http://www.unicode.org/Public/security/revision-06/confusables.txt + +use codemap::mk_sp as make_span; +use super::StringReader; + +const UNICODE_ARRAY: &'static [(char, &'static str, char)] = &[ + ('ߺ', "Nko Lajanyalan", '_'), + ('﹍', "Dashed Low Line", '_'), + ('﹎', "Centreline Low Line", '_'), + ('﹏', "Wavy Low Line", '_'), + ('‐', "Hyphen", '-'), + ('‑', "Non-Breaking Hyphen", '-'), + ('‒', "Figure Dash", '-'), + ('–', "En Dash", '-'), + ('﹘', "Small Em Dash", '-'), + ('⁃', "Hyphen Bullet", '-'), + ('˗', "Modifier Letter Minus Sign", '-'), + ('−', "Minus Sign", '-'), + ('٫', "Arabic Decimal Separator", ','), + ('‚', "Single Low-9 Quotation Mark", ','), + ('ꓹ', "Lisu Letter Tone Na Po", ','), + (';', "Greek Question Mark", ';'), + ('ः', "Devanagari Sign Visarga", ':'), + ('ઃ', "Gujarati Sign Visarga", ':'), + (':', "Fullwidth Colon", ':'), + ('։', "Armenian Full Stop", ':'), + ('܃', "Syriac Supralinear Colon", ':'), + ('܄', "Syriac Sublinear Colon", ':'), + ('︰', "Presentation Form For Vertical Two Dot Leader", ':'), + ('᠃', "Mongolian Full Stop", ':'), + ('᠉', "Mongolian Manchu Full Stop", ':'), + ('⁚', "Two Dot Punctuation", ':'), + ('׃', "Hebrew Punctuation Sof Pasuq", ':'), + ('˸', "Modifier Letter Raised Colon", ':'), + ('꞉', "Modifier Letter Colon", ':'), + ('∶', "Ratio", ':'), + ('ː', "Modifier Letter Triangular Colon", ':'), + ('ꓽ', "Lisu Letter Tone Mya Jeu", ':'), + ('!', "Fullwidth Exclamation Mark", '!'), + ('ǃ', "Latin Letter Retroflex Click", '!'), + ('ʔ', "Latin Letter Glottal Stop", '?'), + ('ॽ', "Devanagari Letter Glottal Stop", '?'), + ('Ꭾ', "Cherokee Letter He", '?'), + ('𝅭', "Musical Symbol Combining Augmentation Dot", '.'), + ('․', "One Dot Leader", '.'), + ('۔', "Arabic Full Stop", '.'), + ('܁', "Syriac Supralinear Full Stop", '.'), + ('܂', "Syriac Sublinear Full Stop", '.'), + ('꘎', "Vai Full Stop", '.'), + ('𐩐', "Kharoshthi Punctuation Dot", '.'), + ('٠', "Arabic-Indic Digit Zero", '.'), + ('۰', "Extended Arabic-Indic Digit Zero", '.'), + ('ꓸ', "Lisu Letter Tone Mya Ti", '.'), + ('՝', "Armenian Comma", '\''), + (''', "Fullwidth Apostrophe", '\''), + ('‘', "Left Single Quotation Mark", '\''), + ('’', "Right Single Quotation Mark", '\''), + ('‛', "Single High-Reversed-9 Quotation Mark", '\''), + ('′', "Prime", '\''), + ('‵', "Reversed Prime", '\''), + ('՚', "Armenian Apostrophe", '\''), + ('׳', "Hebrew Punctuation Geresh", '\''), + ('`', "Greek Varia", '\''), + ('`', "Fullwidth Grave Accent", '\''), + ('΄', "Greek Tonos", '\''), + ('´', "Greek Oxia", '\''), + ('᾽', "Greek Koronis", '\''), + ('᾿', "Greek Psili", '\''), + ('῾', "Greek Dasia", '\''), + ('ʹ', "Modifier Letter Prime", '\''), + ('ʹ', "Greek Numeral Sign", '\''), + ('ˊ', "Modifier Letter Acute Accent", '\''), + ('ˋ', "Modifier Letter Grave Accent", '\''), + ('˴', "Modifier Letter Middle Grave Accent", '\''), + ('ʻ', "Modifier Letter Turned Comma", '\''), + ('ʽ', "Modifier Letter Reversed Comma", '\''), + ('ʼ', "Modifier Letter Apostrophe", '\''), + ('ʾ', "Modifier Letter Right Half Ring", '\''), + ('ꞌ', "Latin Small Letter Saltillo", '\''), + ('י', "Hebrew Letter Yod", '\''), + ('ߴ', "Nko High Tone Apostrophe", '\''), + ('ߵ', "Nko Low Tone Apostrophe", '\''), + ('[', "Fullwidth Left Square Bracket", '('), + ('❨', "Medium Left Parenthesis Ornament", '('), + ('❲', "Light Left Tortoise Shell Bracket Ornament", '('), + ('〔', "Left Tortoise Shell Bracket", '('), + ('﴾', "Ornate Left Parenthesis", '('), + (']', "Fullwidth Right Square Bracket", ')'), + ('❩', "Medium Right Parenthesis Ornament", ')'), + ('❳', "Light Right Tortoise Shell Bracket Ornament", ')'), + ('〕', "Right Tortoise Shell Bracket", ')'), + ('﴿', "Ornate Right Parenthesis", ')'), + ('❴', "Medium Left Curly Bracket Ornament", '{'), + ('❵', "Medium Right Curly Bracket Ornament", '}'), + ('⁎', "Low Asterisk", '*'), + ('٭', "Arabic Five Pointed Star", '*'), + ('∗', "Asterisk Operator", '*'), + ('᜵', "Philippine Single Punctuation", '/'), + ('⁁', "Caret Insertion Point", '/'), + ('∕', "Division Slash", '/'), + ('⁄', "Fraction Slash", '/'), + ('╱', "Box Drawings Light Diagonal Upper Right To Lower Left", '/'), + ('⟋', "Mathematical Rising Diagonal", '/'), + ('⧸', "Big Solidus", '/'), + ('㇓', "Cjk Stroke Sp", '/'), + ('〳', "Vertical Kana Repeat Mark Upper Half", '/'), + ('丿', "Cjk Unified Ideograph-4E3F", '/'), + ('⼃', "Kangxi Radical Slash", '/'), + ('\', "Fullwidth Reverse Solidus", '\\'), + ('﹨', "Small Reverse Solidus", '\\'), + ('∖', "Set Minus", '\\'), + ('⟍', "Mathematical Falling Diagonal", '\\'), + ('⧵', "Reverse Solidus Operator", '\\'), + ('⧹', "Big Reverse Solidus", '\\'), + ('㇔', "Cjk Stroke D", '\\'), + ('丶', "Cjk Unified Ideograph-4E36", '\\'), + ('⼂', "Kangxi Radical Dot", '\\'), + ('ꝸ', "Latin Small Letter Um", '&'), + ('﬩', "Hebrew Letter Alternative Plus Sign", '+'), + ('‹', "Single Left-Pointing Angle Quotation Mark", '<'), + ('❮', "Heavy Left-Pointing Angle Quotation Mark Ornament", '<'), + ('˂', "Modifier Letter Left Arrowhead", '<'), + ('꓿', "Lisu Punctuation Full Stop", '='), + ('›', "Single Right-Pointing Angle Quotation Mark", '>'), + ('❯', "Heavy Right-Pointing Angle Quotation Mark Ornament", '>'), + ('˃', "Modifier Letter Right Arrowhead", '>'), + ('Ⲻ', "Coptic Capital Letter Dialect-P Ni", '-'), + ('Ɂ', "Latin Capital Letter Glottal Stop", '?'), + ('Ⳇ', "Coptic Capital Letter Old Coptic Esh", '/'), ]; + +const ASCII_ARRAY: &'static [(char, &'static str)] = &[ + ('_', "Underscore"), + ('-', "Minus/Hyphen"), + (',', "Comma"), + (';', "Semicolon"), + (':', "Colon"), + ('!', "Exclamation Mark"), + ('?', "Question Mark"), + ('.', "Period"), + ('\'', "Single Quote"), + ('(', "Left Parenthesis"), + (')', "Right Parenthesis"), + ('{', "Left Curly Brace"), + ('}', "Right Curly Brace"), + ('*', "Asterisk"), + ('/', "Slash"), + ('\\', "Backslash"), + ('&', "Ampersand"), + ('+', "Plus Sign"), + ('<', "Less-Than Sign"), + ('=', "Equals Sign"), + ('>', "Greater-Than Sign"), ]; + +pub fn check_for_substitution(reader: &StringReader, ch: char) { + UNICODE_ARRAY + .iter() + .find(|&&(c, _, _)| c == ch) + .map(|&(_, u_name, ascii_char)| { + let span = make_span(reader.last_pos, reader.pos); + match ASCII_ARRAY.iter().find(|&&(c, _)| c == ascii_char) { + Some(&(ascii_char, ascii_name)) => { + let msg = + format!("unicode character '{}' ({}) looks much like '{}' ({}), but it's not", + ch, u_name, ascii_char, ascii_name); + reader.help_span(span, &msg); + }, + None => { + reader + .span_diagnostic + .span_bug_no_panic(span, + &format!("substitution character not found for '{}'", ch)); + } + } + }); +} diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index bde910838cbae..56a06f70ed4b4 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -17,7 +17,7 @@ use ast::{Public, Unsafety}; use ast::{Mod, BiAdd, Arg, Arm, Attribute, BindByRef, BindByValue}; use ast::{BiBitAnd, BiBitOr, BiBitXor, BiRem, BiLt, Block}; use ast::{BlockCheckMode, CaptureByRef, CaptureByValue, CaptureClause}; -use ast::{Constness, ConstImplItem, ConstTraitItem, Crate, CrateConfig}; +use ast::{Constness, ConstTraitItem, Crate, CrateConfig}; use ast::{Decl, DeclItem, DeclLocal, DefaultBlock, DefaultReturn}; use ast::{UnDeref, BiDiv, EMPTY_CTXT, EnumDef, ExplicitSelf}; use ast::{Expr, Expr_, ExprAddrOf, ExprMatch, ExprAgain}; @@ -39,7 +39,7 @@ use ast::{LitStr, LitInt, Local}; use ast::{MacStmtWithBraces, MacStmtWithSemicolon, MacStmtWithoutBraces}; use ast::{MutImmutable, MutMutable, Mac_}; use ast::{MutTy, BiMul, Mutability}; -use ast::{MethodImplItem, NamedField, UnNeg, NoReturn, UnNot}; +use ast::{NamedField, UnNeg, NoReturn, UnNot}; use ast::{Pat, PatBox, PatEnum, PatIdent, PatLit, PatQPath, PatMac, PatRange}; use ast::{PatRegion, PatStruct, PatTup, PatVec, PatWild}; use ast::{PolyTraitRef, QSelf}; @@ -52,7 +52,7 @@ use ast::{Ty, Ty_, TypeBinding, TyMac}; use ast::{TyFixedLengthVec, TyBareFn, TyTypeof, TyInfer}; use ast::{TyParam, TyParamBound, TyParen, TyPath, TyPolyTraitRef, TyPtr}; use ast::{TyRptr, TyTup, TyU32, TyVec}; -use ast::{TypeImplItem, TypeTraitItem}; +use ast::TypeTraitItem; use ast::{UnnamedField, UnsafeBlock}; use ast::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple}; use ast::{Visibility, WhereClause}; @@ -4425,7 +4425,7 @@ impl<'a> Parser<'a> { try!(self.expect(&token::Eq)); let typ = try!(self.parse_ty_sum()); try!(self.expect(&token::Semi)); - (name, TypeImplItem(typ)) + (name, ast::ImplItemKind::Type(typ)) } else if self.is_const_item() { try!(self.expect_keyword(keywords::Const)); let name = try!(self.parse_ident()); @@ -4434,7 +4434,7 @@ impl<'a> Parser<'a> { try!(self.expect(&token::Eq)); let expr = try!(self.parse_expr()); try!(self.commit_expr_expecting(&expr, token::Semi)); - (name, ConstImplItem(typ, expr)) + (name, ast::ImplItemKind::Const(typ, expr)) } else { let (name, inner_attrs, node) = try!(self.parse_impl_method(vis)); attrs.extend(inner_attrs); @@ -4464,7 +4464,7 @@ impl<'a> Parser<'a> { /// Parse a method or a macro invocation in a trait impl. fn parse_impl_method(&mut self, vis: Visibility) - -> PResult<(Ident, Vec, ast::ImplItem_)> { + -> PResult<(Ident, Vec, ast::ImplItemKind)> { // code copied from parse_macro_use_or_failure... abstraction! if !self.token.is_any_keyword() && self.look_ahead(1, |t| *t == token::Not) @@ -4490,7 +4490,7 @@ impl<'a> Parser<'a> { if delim != token::Brace { try!(self.expect(&token::Semi)) } - Ok((token::special_idents::invalid, vec![], ast::MacImplItem(m))) + Ok((token::special_idents::invalid, vec![], ast::ImplItemKind::Macro(m))) } else { let (constness, unsafety, abi) = try!(self.parse_fn_front_matter()); let ident = try!(self.parse_ident()); @@ -4500,7 +4500,7 @@ impl<'a> Parser<'a> { })); generics.where_clause = try!(self.parse_where_clause()); let (inner_attrs, body) = try!(self.parse_inner_attrs_and_block()); - Ok((ident, inner_attrs, MethodImplItem(ast::MethodSig { + Ok((ident, inner_attrs, ast::ImplItemKind::Method(ast::MethodSig { generics: generics, abi: abi, explicit_self: explicit_self, diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 5b8f5c0aef6f7..e9c716017c0b3 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1263,13 +1263,13 @@ impl<'a> State<'a> { _ => {} } - match opt_trait { - &Some(ref t) => { + match *opt_trait { + Some(ref t) => { try!(self.print_trait_ref(t)); try!(space(&mut self.s)); try!(self.word_space("for")); } - &None => {} + None => {} } try!(self.print_type(&**ty)); @@ -1499,10 +1499,10 @@ impl<'a> State<'a> { try!(self.print_tt(tt)); // There should be no space between the module name and the following `::` in paths, // otherwise imported macros get re-parsed from crate metadata incorrectly (#20701) - suppress_space = match tt { - &TokenTree::Token(_, token::Ident(_, token::ModName)) | - &TokenTree::Token(_, token::MatchNt(_, _, _, token::ModName)) | - &TokenTree::Token(_, token::SubstNt(_, token::ModName)) => true, + suppress_space = match *tt { + TokenTree::Token(_, token::Ident(_, token::ModName)) | + TokenTree::Token(_, token::MatchNt(_, _, _, token::ModName)) | + TokenTree::Token(_, token::SubstNt(_, token::ModName)) => true, _ => false } } @@ -1576,19 +1576,19 @@ impl<'a> State<'a> { try!(self.maybe_print_comment(ii.span.lo)); try!(self.print_outer_attributes(&ii.attrs)); match ii.node { - ast::ConstImplItem(ref ty, ref expr) => { + ast::ImplItemKind::Const(ref ty, ref expr) => { try!(self.print_associated_const(ii.ident, &ty, Some(&expr), ii.vis)); } - ast::MethodImplItem(ref sig, ref body) => { + ast::ImplItemKind::Method(ref sig, ref body) => { try!(self.head("")); try!(self.print_method_sig(ii.ident, sig, ii.vis)); try!(self.nbsp()); try!(self.print_block_with_attrs(body, &ii.attrs)); } - ast::TypeImplItem(ref ty) => { + ast::ImplItemKind::Type(ref ty) => { try!(self.print_associated_type(ii.ident, None, Some(ty))); } - ast::MacImplItem(codemap::Spanned { ref node, .. }) => { + ast::ImplItemKind::Macro(codemap::Spanned { ref node, .. }) => { // code copied from ItemMac: try!(self.print_path(&node.path, false, 0)); try!(word(&mut self.s, "! ")); @@ -2618,8 +2618,8 @@ impl<'a> State<'a> { try!(self.rbox(0, Inconsistent)); let mut first = true; if let Some(explicit_self) = opt_explicit_self { - let m = match explicit_self { - &ast::SelfStatic => ast::MutImmutable, + let m = match *explicit_self { + ast::SelfStatic => ast::MutImmutable, _ => match decl.inputs[0].pat.node { ast::PatIdent(ast::BindByValue(m), _, _) => m, _ => ast::MutImmutable @@ -2804,18 +2804,18 @@ impl<'a> State<'a> { try!(self.word_space(",")); } - match predicate { - &ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate{ref bound_lifetimes, - ref bounded_ty, - ref bounds, - ..}) => { + match *predicate { + ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate{ref bound_lifetimes, + ref bounded_ty, + ref bounds, + ..}) => { try!(self.print_formal_lifetime_list(bound_lifetimes)); try!(self.print_type(&**bounded_ty)); try!(self.print_bounds(":", bounds)); } - &ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate{ref lifetime, - ref bounds, - ..}) => { + ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate{ref lifetime, + ref bounds, + ..}) => { try!(self.print_lifetime(lifetime)); try!(word(&mut self.s, ":")); @@ -2827,7 +2827,7 @@ impl<'a> State<'a> { } } } - &ast::WherePredicate::EqPredicate(ast::WhereEqPredicate{ref path, ref ty, ..}) => { + ast::WherePredicate::EqPredicate(ast::WhereEqPredicate{ref path, ref ty, ..}) => { try!(self.print_path(path, false, 0)); try!(space(&mut self.s)); try!(self.word_space("=")); diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 7cd44e5fb4eff..3e02476443a99 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -353,8 +353,8 @@ fn is_test_fn(cx: &TestCtxt, i: &ast::Item) -> bool { let has_test_attr = attr::contains_name(&i.attrs, "test"); fn has_test_signature(i: &ast::Item) -> HasTestSignature { - match &i.node { - &ast::ItemFn(ref decl, _, _, _, ref generics, _) => { + match i.node { + ast::ItemFn(ref decl, _, _, _, ref generics, _) => { let no_output = match decl.output { ast::DefaultReturn(..) => true, ast::Return(ref t) if t.node == ast::TyTup(vec![]) => true, diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index a35a1c1cffd28..5d4a462e84491 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -496,25 +496,25 @@ pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics } walk_list!(visitor, visit_lifetime_def, &generics.lifetimes); for predicate in &generics.where_clause.predicates { - match predicate { - &WherePredicate::BoundPredicate(WhereBoundPredicate{ref bounded_ty, - ref bounds, - ref bound_lifetimes, - ..}) => { + match *predicate { + WherePredicate::BoundPredicate(WhereBoundPredicate{ref bounded_ty, + ref bounds, + ref bound_lifetimes, + ..}) => { visitor.visit_ty(bounded_ty); walk_list!(visitor, visit_ty_param_bound, bounds); walk_list!(visitor, visit_lifetime_def, bound_lifetimes); } - &WherePredicate::RegionPredicate(WhereRegionPredicate{ref lifetime, - ref bounds, - ..}) => { + WherePredicate::RegionPredicate(WhereRegionPredicate{ref lifetime, + ref bounds, + ..}) => { visitor.visit_lifetime(lifetime); walk_list!(visitor, visit_lifetime, bounds); } - &WherePredicate::EqPredicate(WhereEqPredicate{id, - ref path, - ref ty, - ..}) => { + WherePredicate::EqPredicate(WhereEqPredicate{id, + ref path, + ref ty, + ..}) => { visitor.visit_path(path, id); visitor.visit_ty(ty); } @@ -588,18 +588,18 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt visitor.visit_ident(impl_item.span, impl_item.ident); walk_list!(visitor, visit_attribute, &impl_item.attrs); match impl_item.node { - ConstImplItem(ref ty, ref expr) => { + ImplItemKind::Const(ref ty, ref expr) => { visitor.visit_ty(ty); visitor.visit_expr(expr); } - MethodImplItem(ref sig, ref body) => { + ImplItemKind::Method(ref sig, ref body) => { visitor.visit_fn(FnKind::Method(impl_item.ident, sig, Some(impl_item.vis)), &sig.decl, body, impl_item.span, impl_item.id); } - TypeImplItem(ref ty) => { + ImplItemKind::Type(ref ty) => { visitor.visit_ty(ty); } - MacImplItem(ref mac) => { + ImplItemKind::Macro(ref mac) => { visitor.visit_mac(mac); } } diff --git a/src/test/compile-fail/issue-28586.rs b/src/test/compile-fail/issue-28586.rs new file mode 100644 index 0000000000000..c8a1e424da2e2 --- /dev/null +++ b/src/test/compile-fail/issue-28586.rs @@ -0,0 +1,16 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Regression test for issue #28586 + +pub trait Foo {} +impl Foo for [u8; usize::BYTES] {} //~ ERROR E0250 + +fn main() { } diff --git a/src/test/parse-fail/unicode-chars.rs b/src/test/parse-fail/unicode-chars.rs new file mode 100644 index 0000000000000..adfaf62b5d3cc --- /dev/null +++ b/src/test/parse-fail/unicode-chars.rs @@ -0,0 +1,18 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags: -Z parse-only +// ignore-tidy-linelength + +fn main() { + let y = 0; + //~^ ERROR unknown start of token: \u{37e} + //~^^ HELP unicode character ';' (Greek Question Mark) looks much like ';' (Semicolon), but it's not +} diff --git a/src/test/run-pass/env-funky-keys.rs b/src/test/run-pass/env-funky-keys.rs new file mode 100644 index 0000000000000..3ee20980747ee --- /dev/null +++ b/src/test/run-pass/env-funky-keys.rs @@ -0,0 +1,45 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Ignore this test on Android, because it segfaults there. + +// ignore-android +// ignore-windows +// no-prefer-dynamic + +#![feature(convert)] +#![feature(libc)] + +extern crate libc; + +use libc::c_char; +use libc::execve; +use std::env; +use std::ffi::OsStr; +use std::ptr; + +fn main() { + if env::args_os().next().is_none() { + for (key, value) in env::vars_os() { + panic!("found env value {:?} {:?}", key, value); + } + return; + } + + let current_exe = env::current_exe().unwrap().into_os_string().to_cstring().unwrap(); + let new_env_var = OsStr::new("FOOBAR").to_cstring().unwrap(); + let filename: *const c_char = current_exe.as_ptr(); + let argv: &[*const c_char] = &[ptr::null()]; + let envp: &[*const c_char] = &[new_env_var.as_ptr(), ptr::null()]; + unsafe { + execve(filename, &argv[0], &envp[0]); + } + panic!("execve failed"); +} diff --git a/src/test/run-pass/env-vars.rs b/src/test/run-pass/env-vars.rs index d86f63c9cb91d..933d9a728dbe7 100644 --- a/src/test/run-pass/env-vars.rs +++ b/src/test/run-pass/env-vars.rs @@ -14,10 +14,7 @@ use std::env::*; fn main() { for (k, v) in vars_os() { let v2 = var_os(&k); - // MingW seems to set some funky environment variables like - // "=C:=C:\MinGW\msys\1.0\bin" and "!::=::\" that are returned - // from vars() but not visible from var(). - assert!(v2.is_none() || v2.as_ref().map(|s| &**s) == Some(&*v), + assert!(v2.as_ref().map(|s| &**s) == Some(&*v), "bad vars->var transition: {:?} {:?} {:?}", k, v, v2); } } diff --git a/src/test/run-pass/mir_raw_fat_ptr.rs b/src/test/run-pass/mir_raw_fat_ptr.rs index 20c3357d7d232..9bbfbb6822463 100644 --- a/src/test/run-pass/mir_raw_fat_ptr.rs +++ b/src/test/run-pass/mir_raw_fat_ptr.rs @@ -76,7 +76,7 @@ fn compare_au8(a: *const [u8], b: *const [u8]) -> ComparisonResults { } } -#[rustc_mir(graphviz="comparefoo.gv")] +#[rustc_mir] fn compare_foo<'a>(a: *const (Foo+'a), b: *const (Foo+'a)) -> ComparisonResults { ComparisonResults { lt: a < b, @@ -88,7 +88,7 @@ fn compare_foo<'a>(a: *const (Foo+'a), b: *const (Foo+'a)) -> ComparisonResults } } -#[rustc_mir(graphviz="simpleeq.gv")] +#[rustc_mir] fn simple_eq<'a>(a: *const (Foo+'a), b: *const (Foo+'a)) -> bool { let result = a == b; result