From ac6a9eb1dd22b5546952327f14593012870b626d Mon Sep 17 00:00:00 2001 From: christopherdumas Date: Sat, 5 Sep 2015 16:42:04 -0700 Subject: [PATCH 01/17] Added --explain for E0118. --- src/librustc_typeck/diagnostics.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index e356f612cdef2..9a536a5e0a130 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1533,6 +1533,26 @@ For information on the design of the orphan rules, see [RFC 1023]. [RFC 1023]: https://github.com/rust-lang/rfcs/pull/1023 "##, +EO118: r##" +Rust can't find a base type for an implementation you are providing, or the type +cannot have an implementation. For example, a typedef can't have an implementation, +since it isn't its own type (this was done in PR #6087): + +``` +type NineString = [char, ..9] +impl NineString { + // Some code here +} +``` + +In the other, simpler case, Rust just can't find the type you are providing an +impelementation for: + +``` +impl SomeTypeThatDoesntExist { } +``` +"## + E0119: r##" There are conflicting trait implementations for the same type. Example of erroneous code: From 2575687532f8d3251e55c7e4b81fdefd46c820ed Mon Sep 17 00:00:00 2001 From: christopherdumas Date: Sat, 5 Sep 2015 16:49:42 -0700 Subject: [PATCH 02/17] Added commet too --- src/librustc_typeck/diagnostics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 9a536a5e0a130..c2ce16b02566c 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -3214,7 +3214,7 @@ register_diagnostics! { E0090, E0103, // @GuillaumeGomez: I was unable to get this error, try your best! E0104, - E0118, + E0118, // implementation for undefined or unsutable type // E0123, // E0127, // E0129, From 872f34934ce01897ff74c6b16b6052670deabd9d Mon Sep 17 00:00:00 2001 From: christopherdumas Date: Sat, 5 Sep 2015 16:50:58 -0700 Subject: [PATCH 03/17] E0118, not EO118! --- src/librustc_typeck/diagnostics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index c2ce16b02566c..694c633f116f1 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1533,7 +1533,7 @@ For information on the design of the orphan rules, see [RFC 1023]. [RFC 1023]: https://github.com/rust-lang/rfcs/pull/1023 "##, -EO118: r##" +E0118: r##" Rust can't find a base type for an implementation you are providing, or the type cannot have an implementation. For example, a typedef can't have an implementation, since it isn't its own type (this was done in PR #6087): From 1f4fe5f9c23cb0fa3cff998c3ff67e8b1d838f3b Mon Sep 17 00:00:00 2001 From: christopherdumas Date: Sat, 5 Sep 2015 16:55:37 -0700 Subject: [PATCH 04/17] Removed comment. Apparently that shouldnt be there. --- src/librustc_typeck/diagnostics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 694c633f116f1..bd001ff089ad3 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -3214,7 +3214,7 @@ register_diagnostics! { E0090, E0103, // @GuillaumeGomez: I was unable to get this error, try your best! E0104, - E0118, // implementation for undefined or unsutable type + E0118, // E0123, // E0127, // E0129, From a85bc05280b3e5e08d971cfa61458e8c4ee7d950 Mon Sep 17 00:00:00 2001 From: christopherdumas Date: Sat, 5 Sep 2015 16:59:06 -0700 Subject: [PATCH 05/17] De-registered the duplicate E0118 --- src/librustc_typeck/diagnostics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index bd001ff089ad3..31e5b4d90357b 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -3214,7 +3214,7 @@ register_diagnostics! { E0090, E0103, // @GuillaumeGomez: I was unable to get this error, try your best! E0104, - E0118, +// E0118, // E0123, // E0127, // E0129, From 5fa6095f2cc17a8476fa7b0e898a99fb6e3861ef Mon Sep 17 00:00:00 2001 From: christopherdumas Date: Sat, 5 Sep 2015 17:07:37 -0700 Subject: [PATCH 06/17] I think I found the bug! I was missing a comma. --- src/librustc_typeck/diagnostics.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 31e5b4d90357b..1e09a37644505 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1551,7 +1551,7 @@ impelementation for: ``` impl SomeTypeThatDoesntExist { } ``` -"## +"##, E0119: r##" There are conflicting trait implementations for the same type. @@ -3214,7 +3214,7 @@ register_diagnostics! { E0090, E0103, // @GuillaumeGomez: I was unable to get this error, try your best! E0104, -// E0118, + E0118, // E0123, // E0127, // E0129, From 1eb726217d3a8ff8849594e88df068c4a13fbdc9 Mon Sep 17 00:00:00 2001 From: christopherdumas Date: Sat, 5 Sep 2015 17:14:10 -0700 Subject: [PATCH 07/17] This time, I found the error' --- src/librustc_typeck/diagnostics.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 1e09a37644505..a7f1b7198e25c 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -3214,7 +3214,6 @@ register_diagnostics! { E0090, E0103, // @GuillaumeGomez: I was unable to get this error, try your best! E0104, - E0118, // E0123, // E0127, // E0129, From a8a8dfbe1a0aa917fb392bb8f3c037ef6a1ef27f Mon Sep 17 00:00:00 2001 From: christopherdumas Date: Sat, 5 Sep 2015 20:23:26 -0700 Subject: [PATCH 08/17] Line longer that 80 chars. --- src/librustc_typeck/diagnostics.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index a7f1b7198e25c..4e9bcab2e9c4a 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1535,8 +1535,8 @@ For information on the design of the orphan rules, see [RFC 1023]. E0118: r##" Rust can't find a base type for an implementation you are providing, or the type -cannot have an implementation. For example, a typedef can't have an implementation, -since it isn't its own type (this was done in PR #6087): +cannot have an implementation. For example, a typedef can't have an +implementation, since it isn't its own type (this was done in PR #6087): ``` type NineString = [char, ..9] From 5c5cca58f7c8e59703892d9500327aafdd44e45e Mon Sep 17 00:00:00 2001 From: Jack Wilson Date: Sun, 6 Sep 2015 16:23:44 -0700 Subject: [PATCH 09/17] Small syntax and formatting changes --- src/doc/trpl/guessing-game.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/doc/trpl/guessing-game.md b/src/doc/trpl/guessing-game.md index 4a35022b03c91..3a4328562f872 100644 --- a/src/doc/trpl/guessing-game.md +++ b/src/doc/trpl/guessing-game.md @@ -599,7 +599,7 @@ With this definition, anything of type `Foo` can be either a `Foo::Bar` or a `Foo::Baz`. We use the `::` to indicate the namespace for a particular `enum` variant. -The [`Ordering`][ordering] enum has three possible variants: `Less`, `Equal`, +The [`Ordering`][ordering] `enum` has three possible variants: `Less`, `Equal`, and `Greater`. The `match` statement takes a value of a type, and lets you create an ‘arm’ for each possible value. Since we have three types of `Ordering`, we have three arms: @@ -918,9 +918,9 @@ let guess: u32 = match guess.trim().parse() { This is how you generally move from ‘crash on error’ to ‘actually handle the error’, by switching from `ok().expect()` to a `match` statement. The `Result` -returned by `parse()` is an enum just like `Ordering`, but in this case, each +returned by `parse()` is an `enum` just like `Ordering`, but in this case, each variant has some data associated with it: `Ok` is a success, and `Err` is a -failure. Each contains more information: the successful parsed integer, or an +failure. Each contains more information: the successfully parsed integer, or an error type. In this case, we `match` on `Ok(num)`, which sets the inner value of the `Ok` to the name `num`, and then we just return it on the right-hand side. In the `Err` case, we don’t care what kind of error it is, so we just From eb53461b413063ab8a73fb542a537124a8b77f54 Mon Sep 17 00:00:00 2001 From: christopherdumas Date: Wed, 9 Sep 2015 07:00:39 -0700 Subject: [PATCH 10/17] Fixed incorrect error explanation --- src/librustc_typeck/diagnostics.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 4e9bcab2e9c4a..19ca825cf35a2 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1535,11 +1535,11 @@ For information on the design of the orphan rules, see [RFC 1023]. E0118: r##" Rust can't find a base type for an implementation you are providing, or the type -cannot have an implementation. For example, a typedef can't have an -implementation, since it isn't its own type (this was done in PR #6087): +cannot have an implementation. For example, only a named type or a trait can +have an implementation: ``` -type NineString = [char, ..9] +type NineString = [char, ..9] // This isn't a named type (struct, enum or trait) impl NineString { // Some code here } From e570e863afacd57c0fc8914ac9d02a9722b51d60 Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Wed, 9 Sep 2015 12:12:25 +0100 Subject: [PATCH 11/17] Add a comment that the `Atomic*` are all implicitly `Send` --- src/libcore/sync/atomic.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libcore/sync/atomic.rs b/src/libcore/sync/atomic.rs index 53952cdc9080b..0f72dcc1281a4 100644 --- a/src/libcore/sync/atomic.rs +++ b/src/libcore/sync/atomic.rs @@ -92,6 +92,7 @@ impl Default for AtomicBool { } } +// Send is implicitly implemented for AtomicBool. unsafe impl Sync for AtomicBool {} /// A signed integer type which can be safely shared between threads. @@ -106,6 +107,7 @@ impl Default for AtomicIsize { } } +// Send is implicitly implemented for AtomicIsize. unsafe impl Sync for AtomicIsize {} /// An unsigned integer type which can be safely shared between threads. @@ -120,6 +122,7 @@ impl Default for AtomicUsize { } } +// Send is implicitly implemented for AtomicUsize. unsafe impl Sync for AtomicUsize {} /// A raw pointer type which can be safely shared between threads. From 51354e97c24265607384524c977b3002c3582127 Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Wed, 9 Sep 2015 12:16:27 +0100 Subject: [PATCH 12/17] Add a compile-time test for the `Send`- and `Sync`-ness of `Atomic*` --- src/libcoretest/atomic.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/libcoretest/atomic.rs b/src/libcoretest/atomic.rs index b6bb5fddf4a4b..4a71546b0afa5 100644 --- a/src/libcoretest/atomic.rs +++ b/src/libcoretest/atomic.rs @@ -10,6 +10,7 @@ use core::sync::atomic::*; use core::sync::atomic::Ordering::SeqCst; +use core::marker::{Send, Sync}; #[test] fn bool_() { @@ -82,3 +83,13 @@ fn static_init() { assert!(S_INT.load(SeqCst) == 0); assert!(S_UINT.load(SeqCst) == 0); } + +#[test] +fn static_sync_and_send() { + fn ensure_sync_and_send() { } + + ensure_sync_and_send::(); + ensure_sync_and_send::(); + ensure_sync_and_send::(); + ensure_sync_and_send::(); +} From 35209dcda862c7aec95c77bcda759c3388a2914b Mon Sep 17 00:00:00 2001 From: christopherdumas Date: Mon, 14 Sep 2015 06:29:32 -0700 Subject: [PATCH 13/17] Fix typo --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f81bb0bd69dd8..4e4a4109fd0f5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -225,7 +225,7 @@ are: * Although out of date, [Tom Lee's great blog article][tlgba] is very helpful * [rustaceans.org][ro] is helpful, but mostly dedicated to IRC * The [Rust Compiler Testing Docs][rctd] -* For @bors, [this cheetsheat][cheetsheat] is helpful (Remember to replace `@homu` with `@bors` in the commands that you use.) +* For @bors, [this cheetsheet][cheetsheet] is helpful (Remember to replace `@homu` with `@bors` in the commands that you use.) * **Google**! * Don't be afraid to ask! The Rust community is friendly and helpful. @@ -235,4 +235,4 @@ are: [tlgba]: http://tomlee.co/2014/04/03/a-more-detailed-tour-of-the-rust-compiler/ [ro]: http://www.rustaceans.org/ [rctd]: ./COMPILER_TESTS.md -[cheetsheat]: http://buildbot.rust-lang.org/homu/ +[cheetsheet]: http://buildbot.rust-lang.org/homu/ From 4543dadd6bccdb7bf93872072c8b9d997049874e Mon Sep 17 00:00:00 2001 From: christopherdumas Date: Mon, 14 Sep 2015 07:28:06 -0700 Subject: [PATCH 14/17] Cheat sheet --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4e4a4109fd0f5..be938e6f35e04 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -225,7 +225,7 @@ are: * Although out of date, [Tom Lee's great blog article][tlgba] is very helpful * [rustaceans.org][ro] is helpful, but mostly dedicated to IRC * The [Rust Compiler Testing Docs][rctd] -* For @bors, [this cheetsheet][cheetsheet] is helpful (Remember to replace `@homu` with `@bors` in the commands that you use.) +* For @bors, [this cheat sheet][cheatsheet] is helpful (Remember to replace `@homu` with `@bors` in the commands that you use.) * **Google**! * Don't be afraid to ask! The Rust community is friendly and helpful. @@ -235,4 +235,4 @@ are: [tlgba]: http://tomlee.co/2014/04/03/a-more-detailed-tour-of-the-rust-compiler/ [ro]: http://www.rustaceans.org/ [rctd]: ./COMPILER_TESTS.md -[cheetsheet]: http://buildbot.rust-lang.org/homu/ +[cheatsheet]: http://buildbot.rust-lang.org/homu/ From 4e25329c5ed78edfb07240b038801a601183a7aa Mon Sep 17 00:00:00 2001 From: Andrew Paseltiner Date: Tue, 15 Sep 2015 10:14:11 -0400 Subject: [PATCH 15/17] Add test for #23036 Closes #23036. --- src/test/run-pass/issue-23036.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/test/run-pass/issue-23036.rs diff --git a/src/test/run-pass/issue-23036.rs b/src/test/run-pass/issue-23036.rs new file mode 100644 index 0000000000000..0ed4126e6cd71 --- /dev/null +++ b/src/test/run-pass/issue-23036.rs @@ -0,0 +1,18 @@ +// 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. + +use std::collections::HashMap; +use std::path::Path; + +fn main() { + let mut map = HashMap::new(); + map.insert(Path::new("a"), 0); + map.get(Path::new("a")); +} From 320880eed5e960f6107cfbe039a5eba33f209f32 Mon Sep 17 00:00:00 2001 From: christopherdumas Date: Tue, 15 Sep 2015 07:54:43 -0700 Subject: [PATCH 16/17] Fix option link and anchor links. --- src/doc/trpl/error-handling.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/doc/trpl/error-handling.md b/src/doc/trpl/error-handling.md index 673dc950ecce4..2b590c82a89bf 100644 --- a/src/doc/trpl/error-handling.md +++ b/src/doc/trpl/error-handling.md @@ -33,12 +33,12 @@ systems may want to jump around. * [Composing `Option` and `Result`](#composing-option-and-result) * [The limits of combinators](#the-limits-of-combinators) * [Early returns](#early-returns) - * [The `try!` macro](#the-try-macro) + * [The `try!` macro](#the-try!-macro) * [Defining your own error type](#defining-your-own-error-type) * [Standard library traits used for error handling](#standard-library-traits-used-for-error-handling) * [The `Error` trait](#the-error-trait) * [The `From` trait](#the-from-trait) - * [The real `try!` macro](#the-real-try-macro) + * [The real `try!` macro](#the-real-try!-macro) * [Composing custom error types](#composing-custom-error-types) * [Advice for library writers](#advice-for-library-writers) * [Case study: A program to read population data](#case-study-a-program-to-read-population-data) @@ -120,10 +120,9 @@ It would be better if we just showed the code for unwrapping because it is so simple, but to do that, we will first need to explore the `Option` and `Result` types. Both of these types have a method called `unwrap` defined on them. -## The `Option` type +### The `Option` type -The `Option` type is -[defined in the standard library][1]: +The `Option` type is [defined in the standard library][5]: ```rust enum Option { From b69a51164d078b00d97a4aa7d4a91ec3f4f5a074 Mon Sep 17 00:00:00 2001 From: christopherdumas Date: Tue, 15 Sep 2015 10:31:48 -0700 Subject: [PATCH 17/17] Added anchors for the code snippets. --- src/doc/trpl/error-handling.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/doc/trpl/error-handling.md b/src/doc/trpl/error-handling.md index 2b590c82a89bf..0687c2b13b5b5 100644 --- a/src/doc/trpl/error-handling.md +++ b/src/doc/trpl/error-handling.md @@ -87,7 +87,9 @@ thread '
' panicked at 'Invalid number: 11', src/bin/panic-simple.rs:5 Here's another example that is slightly less contrived. A program that accepts an integer as an argument, doubles it and prints it. + ```rust,should_panic + use std::env; fn main() { @@ -137,6 +139,7 @@ system is an important concept because it will cause the compiler to force the programmer to handle that absence. Let's take a look at an example that tries to find a character in a string: + ```rust // Searches `haystack` for the Unicode character `needle`. If one is found, the // byte offset of the character is returned. Otherwise, `None` is returned.