New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add signed num::NonZeroI* types #57475

Merged
merged 2 commits into from Jan 22, 2019

Conversation

@SimonSapin
Copy link
Contributor

SimonSapin commented Jan 9, 2019

Multiple people have asked for them in #49137. Given that the unsigned ones already exist, they are very easy to add and not an additional maintenance burden.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Jan 9, 2019

r? @aidanhs

(rust_highfive has picked a reviewer for you, use r? to override)

@SimonSapin

This comment has been minimized.

Copy link
Contributor

SimonSapin commented Jan 9, 2019

The new types are stable in this PR, so let’s get team sign-off:

@rfcbot fcp merge

They don’t really need to be. But they are very similar to the existing unsigned non-zero integer types, so it seems to me that having them as unstable for a period of time is very unlikely to bring new information. Also, making the signed and unsigned type behave differently (beyond signedness) or have different API seems like it would be unfortunate, and the latter are already stable.

@rfcbot

This comment has been minimized.

Copy link

rfcbot commented Jan 9, 2019

Team member @SimonSapin has proposed to merge this. The next step is review by the rest of the tagged teams:

No concerns currently listed.

Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Jan 9, 2019

The job x86_64-gnu-llvm-6.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:1ab20504:start=1547059796556912748,finish=1547059797474349550,duration=917436802
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-6.0
---
[00:04:38] 71  |                           Some(unsafe { $Ty(n) })
[00:04:38]     |                                ^^^^^^ unnecessary `unsafe` block
[00:04:38] ...
[00:04:38] 100 | / nonzero_integers! {
[00:04:38] 101 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU8(u8);
[00:04:38] 102 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU16(u16);
[00:04:38] 103 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU32(u32);
[00:04:38] ...   |
[00:04:38] 112 | |     #[stable(feature = "signed_nonzero", since = "1.33.0")] NonZeroIsize(isize);
[00:04:38]     | |_- in this macro invocation
[00:04:38]     |
[00:04:38]     = note: #[warn(unused_unsafe)] on by default
[00:04:38] 
[00:04:38] 
[00:04:38] warning: unnecessary `unsafe` block
[00:04:38]    --> src/libcore/num/mod.rs:71:30
[00:04:38]     |
[00:04:38] 71  |                           Some(unsafe { $Ty(n) })
[00:04:38]     |                                ^^^^^^ unnecessary `unsafe` block
[00:04:38] ...
[00:04:38] 100 | / nonzero_integers! {
[00:04:38] 101 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU8(u8);
[00:04:38] 102 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU16(u16);
[00:04:38] 103 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU32(u32);
[00:04:38] ...   |
[00:04:38] 112 | |     #[stable(feature = "signed_nonzero", since = "1.33.0")] NonZeroIsize(isize);
[00:04:38]     | |_- in this macro invocation
[00:04:38] 
[00:04:38] warning: unnecessary `unsafe` block
[00:04:38]     --> src/libcore/ptr.rs:2785:18
---
[00:04:38] 50  |                   #[rustc_layout_scalar_valid_range_start(1)]
[00:04:38]     |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[00:04:38] ...
[00:04:38] 100 | / nonzero_integers! {
[00:04:38] 101 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU8(u8);
[00:04:38] 102 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU16(u16);
[00:04:38] 103 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU32(u32);
[00:04:38] ...   |
[00:04:38] 112 | |     #[stable(feature = "signed_nonzero", since = "1.33.0")] NonZeroIsize(isize);
[00:04:38]     | |_- in this macro invocation
[00:04:38]     |
[00:04:38]     = note: #[warn(unused_attributes)] on by default
[00:04:38] 
[00:04:38] 
[00:04:38] warning: unused attribute
[00:04:38]    --> src/libcore/num/mod.rs:50:17
[00:04:38]     |
[00:04:38] 50  |                   #[rustc_layout_scalar_valid_range_start(1)]
[00:04:38]     |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[00:04:38] ...
[00:04:38] 100 | / nonzero_integers! {
[00:04:38] 101 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU8(u8);
[00:04:38] 102 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU16(u16);
[00:04:38] 103 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU32(u32);
[00:04:38] ...   |
[00:04:38] 112 | |     #[stable(feature = "signed_nonzero", since = "1.33.0")] NonZeroIsize(isize);
[00:04:38]     | |_- in this macro invocation
[00:04:38] 
[00:04:38] warning: unused attribute
[00:04:38]     --> src/libcore/ptr.rs:2720:1
---
[01:07:11] .................................................................................................... 4600/5298
[01:07:15] .................................................................................................... 4700/5298
[01:07:18] .................................................................................................... 4800/5298
[01:07:23] .................................................................................................... 4900/5298
[01:07:27] ..............................................F..................................................... 5000/5298
[01:07:33] .................................................................................................... 5200/5298
[01:07:36] .....................................i............................................................
[01:07:36] failures:
[01:07:36] 
[01:07:36] 
[01:07:36] ---- [ui] ui/try-block/try-block-bad-type.rs stdout ----
[01:07:36] diff of stderr:
[01:07:36] 
[01:07:36] 5    |         ^^^^^^^^ the trait `std::convert::From<&str>` is not implemented for `i32`
[01:07:36] 7    = help: the following implementations were found:
[01:07:36] 7    = help: the following implementations were found:
[01:07:36] -              <i32 as std::convert::From<bool>>
[01:07:36] +              <i32 as std::convert::From<core::num::NonZeroI32>>
[01:07:36] 9              <i32 as std::convert::From<i16>>
[01:07:36] 10              <i32 as std::convert::From<i8>>
[01:07:36] -              <i32 as std::convert::From<u16>>
[01:07:36] 12              <i32 as std::convert::From<u8>>
[01:07:36] 13    = note: required by `std::convert::From::from`
[01:07:36] 14 
[01:07:36] 14 
[01:07:36] 15 error[E0271]: type mismatch resolving `<std::result::Result<i32, i32> as std::ops::Try>::Ok == &str`
[01:07:36] 
[01:07:36] The actual stderr differed from the expected stderr.
[01:07:36] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/try-block/try-block-bad-type/try-block-bad-type.stderr
[01:07:36] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/try-block/try-block-bad-type/try-block-bad-type.stderr
[01:07:36] To update references, rerun the tests and pass the `--bless` flag
[01:07:36] To only update this specific test, also pass `--test-args try-block/try-block-bad-type.rs`
[01:07:36] error: 1 errors occurred comparing output.
[01:07:36] status: exit code: 1
[01:07:36] status: exit code: 1
[01:07:36] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/try-block/try-block-bad-type.rs" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/try-block/try-block-bad-type/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--edition" "2018" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/try-block/try-block-bad-type/auxiliary" "-A" "unused"
[01:07:36] ------------------------------------------
[01:07:36] 
[01:07:36] ------------------------------------------
[01:07:36] stderr:
[01:07:36] stderr:
[01:07:36] ------------------------------------------
[01:07:36] {"message":"the trait bound `i32: std::convert::From<&str>` is not satisfied","code":{"code":"E0277","explanation":"\nYou tried to use a type which doesn't implement some trait in a place which\nexpected that trait. Erroneous code example:\n\n```compile_fail,E0277\n// here we declare the Foo trait with a bar method\ntrait Foo {\n    fn bar(&self);\n}\n\n// we now declare a function which takes an object implementing the Foo trait\nfn some_func<T: Foo>(foo: T) {\n    foo.bar();\n}\n\nfn main() {\n    // we now call the method with the i32 type, which doesn't implement\n    // the Foo trait\n    some_func(5i32); // error: the trait bound `i32 : Foo` is not satisfied\n}\n```\n\nIn order to fix this error, verify that the type you're using does implement\nthe trait. Example:\n\n```\ntrait Foo {\n    fn bar(&self);\n}\n\nfn some_func<T: Foo>(foo: T) {\n    foo.bar(); // we can now use this method since i32 implements the\n               // Foo trait\n}\n\n// we implement the trait on the i32 type\nimpl Foo for i32 {\n    fn bar(&self) {}\n}\n\nfn main() {\n    some_func(5i32); // ok!\n}\n```\n\nOr in a generic context, an erroneous code example would look like:\n\n```compile_fail,E0277\nfn some_func<T>(foo: T) {\n    println!(\"{:?}\", foo); // error: the trait `core::fmt::Debug` is not\n                           //        implemented for the type `T`\n}\n\nfn main() {\n    // We now call the method with the i32 type,\n    // which *does* implement the Debug trait.\n    some_func(5i32);\n}\n```\n\nNote that the error here is in the definition of the generic function: Although\nwe only call it with a parameter that does implement `Debug`, the compiler\nstill rejects the function: It must work with all possible input types. In\norder to make this example compile, we need to restrict the generic type we're\naccepting:\n\n```\nuse std::fmt;\n\n// Restrict the input type to types that implement Debug.\nfn some_func<T: fmt::Debug>(foo: T) {\n    println!(\"{:?}\", foo);\n}\n\nfn main() {\n    // Calling the method is still fine, as i32 implements Debug.\n    some_func(5i32);\n\n    // This would fail to compile now:\n    // struct WithoutDebug;\n    // some_func(WithoutDebug);\n}\n```\n\nRust only looks at the signature of the called function, as such it must\nalready specify all requirements that will be used for every type parameter.\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":121,"byte_end":129,"line_start":7,"line_end":7,"column_start":9,"column_end":17,"is_primary":true,"text":[{"text":"        Err(\"\")?; //~ ERROR the trait bound `i32: std::convert::From<&str>` is not satisfied","highlight_start":9,"highlight_end":17}],"label":"the trait `std::convert::From<&str>` is not implemented for `i32`","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"the following implementations were found:\n  <i32 as std::convert::From<core::num::NonZeroI32>>\n  <i32 as std::convert::From<i16>>\n  <i32 as std::convert::From<i8>>\n  <i32 as std::convert::From<u8>>\nand 2 others","code":null,"level":"help","spans":[],"children":[],"rendered":null},{"message":"required by `std::convert::From::from`","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error[E0277]: the trait bound `i32: std::convert::From<&str>` is not satisfied\n  --> /checkout/src/test/ui/try-block/try-block-bad-type.rs:7:9\n   |\nLL |         Err(\"\")?; //~ ERROR the trait bound `i32: std::convert::From<&str>` is not satisfied\n   |         ^^^^^^^^ the trait `std::convert::From<&str>` is not implemented for `i32`\n   |\n   = help: the following implementations were found:\n             <i32 as std::convert::From<core::num::NonZeroI32>>\n             <i32 as std::convert::From<i16>>\n             <i32 as std::convert::From<i8>>\n             <i32 as std::convert::From<u8>>\n           and 2 others\n   = note: required by `std::convert::From::from`\n\n"}
[01:07:36] {"message":"type mismatch resolving `<std::result::Result<i32, i32> as std::ops::Try>::Ok == &str`","code":{"code":"E0271","explanation":"\nThis is because of a type mismatch between the associated type of some\ntrait (e.g., `T::Bar`, where `T` implements `trait Quux { type Bar; }`)\nand another type `U` that is required to be equal to `T::Bar`, but is not.\nExamples follow.\n\nHere is a basic example:\n\n```compile_fail,E0271\ntrait Trait { type AssociatedType; }\n\nfn foo<T>(t: T) where T: Trait<AssociatedType=u32> {\n    println!(\"in foo\");\n}\n\nimpl Trait for i8 { type AssociatedType = &'static str; }\n\nfoo(3_i8);\n```\n\nHere is that same example again, with some explanatory comments:\n\n```compile_fail,E0271\ntrait Trait { type AssociatedType; }\n\nfn foo<T_i8);\n\n// For-Loop Example:\nlet vs = vec![1, 2, 3, 4];\nfor v in &vs {\n    match v {\n        &1 => {}\n        _ => {}\n    }\n}\n```\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":270,"byte_end":272,"line_start":12,"line_end":12,"column_start":9,"column_end":11,"is_primary":true,"text":[{"text":"        \"\" //~ ERROR type mismatch","highlight_start":9,"highlight_end":11}],"label":"expected i32, found &str","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"expected type `i32`\n   found type `&str`","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error[E0271]: type mismatch resolving `<std::result::Result<i32, i32> as std::ops::Try>::Ok == &str`\n  --> /checkout/src/test/ui/try-block/try-block-bad-type.rs:12:9\n   |\nLL |         \"\" //~ ERROR type mismatch\n   |         ^^ expected i32, found &str\n   |\n   = note: expected type `i32`\n              found type `&str`\n\n"}
[01:07:36] {"message":"type mismatch resolving `<std::result::Result<i32, i32> as std::ops::Try>::Ok == ()`","code":{"code":"E0271","explanation":"\nThis is because of a type mismatch between the associated type of some\ntrait (e.g., `T::Bar`, where `T` implements `trait Quux { type Bar; }`)\nand another type `U` that is required to be equal to `T::Bar`, but is not.\nExamples follow.\n\nHere is a basic example:\n\n```compile_fail,E0271\ntrait Trait { type AssociatedType; }\n\nfn foo<T>(t: T) where T: Trait<AssociatedType=u32> {\n    println!(\"in foo\");\n}\n\nimpl Trait for i8 { type AssociatedType = &'static str; }\n\nfoo(3_i8);\n```\n\nHere is that same example again, with some explanatory comments:\n\n```compile_fail,E0271\ntrait Trait { type AssociatedType; }\n\nfn foo<T>(t: T) where T: Trait<AssociatedType=u32> {\n//                    ~~~~~~~~ ~~~~~~~~~~~~~~~~~~\n//                        |            |\n//         This says `foo` can         |\n//           only be used with         |\n//              some type that         |\n//         implements `Trait`.         |\n//                                     |\n//                             This says not only must\n//                             `T` be an impl of `Trait`\n//                             but also that the impl\n//                             must assign the type `u32`\n//                             to the associated type.\n    println!(\"in foo\");\n}\n\nimpl Trait for i8 { type AssociatedType = &'static str; }\n//~~~~~~~~~~~~~~~   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n//      |                             |\n// `i8` does have                     |\n// implementation                     |\n// of `Trait`...                      |\n//                     ... but it is an implementation\n//                     that assigns `&'static str` to\n//                     the associated type.\n\nfoo(3_i8);\n// Here, we invoke `foo` with an `i8`, which does not satisfy\n// the constraint `<i8 as Trait>::AssociatedType=u32`, and\n// therefore the type-checker complains with this error code.\n```\n\nTo avoid those issues, you have to make the types match correctly.\nSo we can fix the previous examples like this:\n\n```\n// Basic Example:\ntrait Trait { type AssociatedType; }\n\nfn foo<T>(t: T) where T: Trait<AssociatedType = &'static str> {\n    println!(\"in foo\");\n}\n\nimpl Trait for i8 { type AssociatedType = &'static str; }\n\nfoo(3_i8);\n\n// For-Loop Example:\nlet vs = vec![1, 2, 3, 4];\nfor v in &vs {\n    match v {\n        &1 => {}\n        _ => {}\n    }\n}\n```\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":343,"byte_end":344,"line_start":15,"line_end":15,"column_start":39,"column_end":40,"is_primary":true,"text":[{"text":"    let res: Result<i32, i32> = try { }; //~ ERROR type mismatch","highlight_start":39,"highlight_end":40}],"label":"expected i32, found ()","suggested_replacement":null,"suggestion_applicability":null,"expansion":{"span":{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":341,"byte_end":344,"line_start":15,"line_end":15,"column_start":37,"column_end":40,"is_primary":false,"text":[{"text":"    let res: Result<i32, i32> = try { }; //~ ERROR type mismatch","highlight_start":37,"highlight_end":40}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null},"macro_decl_name":"desugaring of `try block`","def_site_span":{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":341,"byte_end":344,"line_start":15,"line_end":15,"column_start":37,"column_end":40,"is_primary":false,"text":[{"text":"    let res: Result<i32, i32> = try { }; //~ ERROR type mismatch","highlight_start":37,"highlight_end":40}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}}}],"children":[{"message":"expected type `i32`\n   found type `()`","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error[E0271]: type mismatch resolving `<std::result::Result<i32, i32> as std::ops::Try>::Ok == ()`\n  --> /checkout/src/test/ui/try-block/try-block-bad-type.rs:15:39\n   |\nLL |     let res: Result<i32, i32> = try { }; //~ ERROR type mismatch\n   |                                       ^ expected i32, found ()\n   |\n   = note: expected type `i32`\n              found type `()`\n\n"}
[01:07:36] {"message":"the trait bound `(): std::ops::Try` is not satisfied","code":{"code":"E0277","explanation":"\nYou tried to use a type which doesn't implement some trait in a place which\nexpected that trait. Erroneous code example:\n\n```compile_fail,E0277\n// here we declare the Foo trait with a bar method\ntrait Foo {\n    fn bar(&self);\n}\n\n// we now declare a function which takes an object implementing the Foo trait\nfn some_func<T: Foo>(foo: T) {\n    foo.bar();\n}\n\nfn main() {\n    // we now call the method with the i32 type, which doesn't implement\n    // the Foo trait\n    some_func(5i32); // error: the trait bound `i32 : Foo` is not satisfied\n}\n```\n\nIn order to fix this error, verify that the type you're using does implement\nthe trait. Example:\n\n```\ntrait Foo {\n    fn bar(&self);\n}\n\nfn some_func<T: Foo>(foo: T) {\n    foo.bar(); // we can now use this method since i32 implements the\n               // Foo trait\n}\n\n// we implement the trait on the i32 type\nimpl Foo for i32 {\n    fn bar(&self) {}\n}\n\nfn main() {\n    some_func(5i32); // ok!\n}\n```\n\nOr in a generic context, an erroneous code example would look like:\n\n```compile_fail,E0277\nfn some_func<T>(foo: T) {\n    println!(\"{:?}\", foo); // error: the trait `core::fmt::Debug` is not\n                           //        implemented for the type `T`\n}\n\nfn main() {\n    // We now call the method with the i32 type,\n    // which *does* implement the Debug trait.\n    some_func(5i32);\n}\n```\n\nNote that the error here is in the definition of the generic function: Although\nwe only call it with a parameter that does implement `Debug`, the compiler\nstill rejects the function: It must work with all possible input types. In\norder to make this example compile, we need to restrict the generic type we're\naccepting:\n\n```\nuse std::fmt;\n\n// Restrict the input type to types that implement Debug.\nfn some_func<T: fmt::Debug>(foo: T) {\n    println!(\"{:?}\", foo);\n}\n\nfn main() {\n    // Calling the method is still fine, as i32 implements Debug.\n    some_func(5i32);\n\n    // This would fail to compile now:\n    // struct WithoutDebug;\n    // some_func(WithoutDebug);\n}\n```\n\nRust only looks at the signature of the called function, as such it must\nalready specify all requirements that will be used for every type parameter.\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":393,"byte_end":396,"line_start":17,"line_end":17,"column_start":23,"column_end":26,"is_primary":true,"text":[{"text":"    let res: () = try { }; //~ the trait bound `(): std::ops::Try` is not satisfied","highlight_start":23,"highlight_end":26}],"label":"the trait `std::ops::Try` is not implemented for `()`","suggested_replacement":null,"suggestion_applicability":null,"expansion":{"span":{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":393,"byte_end":396,"line_start":17,"line_end":17,"column_start":23,"column_end":26,"is_primary":false,"text":[{"text":"    let res: () = try { }; //~ the trait bound `(): std::ops::Try` is not satisfied","highlight_start":23,"highlight_end":26}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null},"macro_decl_name":"desugaring of `try block`","def_site_span":{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":393,"byte_end":396,"line_start":17,"line_end":17,"column_start":23,"column_end":26,"is_primary":false,"text":[{"text":"    let res: () = try { }; //~ the trait bound `(): std::ops::Try` is not satisfied","highlight_start":23,"highlight_end":26}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}}}],"children":[{"message":"required by `std::ops::Try::from_ok`","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error[E0277]: the trait bound `(): std::ops::Try` is not satisfied\n  --> /checkout/src/test/ui/try-block/try-block-bad-type.rs:17:23\n   |\nLL |     let res: () = try { }; //~ the trait bound `(): std::ops::Try` is not satisfied\n   |                       ^^^ the trait `std::ops::Try` is not implemented for `()`\n   |\n   = note: required by `std::ops::Try::from_ok`\n\n"}
[01:07:36] {"message":"the trait bound `i32: std::ops::Try` is not satisfied","code":{"code":"E0277","explanation":"\nYou tried to use a type which doesn't implement some trait in a place which\nexpected that trait. Erroneous code example:\n\n```compile_fail,E0277\n// here we declare the Foo trait with a bar method\ntrait Foo {\n    fn bar(&self);\n}\n\n// we now declare a function which takes an object implementing the Foo trait\nfn some_func<T: Foo>(foo: T) {\n    foo.bar();\n}\n\nfn main() {\n    // we now call the method with the i32 type, which doesn't implement\n    // the Foo trait\n    some_func(5i32); // error: the trait bound `i32 : Foo` is not satisfied\n}\n```\n\nIn order to fix this error, verify that the type you're using does implement\nthe trait. Example:\n\n```\ntrait Foo {\n    fn bar(&self);\n}\n\nfn some_func<T: Foo>(foo: T) {\n    foo.bar(); // we can now use this method since i32 implements the\n               // Foo trait\n}\n\n// we implement the trait on the i32 type\nimpl Foo for i32 {\n    fn bar(&self) {}\n}\n\nfn main() {\n    some_func(5i32); // ok!\n}\n```\n\nOr in a generic context, an erroneous code example would look like:\n\n```compile_fail,E0277\nfn some_func<T>(foo: T) {\n    println!(\"{:?}\", foo); // error: the trait `core::fmt::Debug` is not\n                           //        implemented for the type `T`\n}\n\nfn main() {\n    // We now call the method with the i32 type,\n    // which *does* implement the Debug trait.\n    some_func(5i32);\n}\n```\n\nNote that the error here is in the definition of the generic function: Although\nwe only call it with a parameter that does implement `Debug`, the compiler\nstill rejects the function: It must work with all possible input types. In\norder to make this example compile, we need to restrict the generic type we're\naccepting:\n\n```\nuse std::fmt;\n\n// Restrict the input type to types that implement Debug.\nfn some_func<T: fmt::Debug>(foo: T) {\n    println!(\"{:?}\", foo);\n}\n\nfn main() {\n    // Calling the method is still fine, as i32 implements Debug.\n    some_func(5i32);\n\n    // This would fail to compile now:\n    // struct WithoutDebug;\n    // some_func(WithoutDebug);\n}\n```\n\nRust only looks at the signature of the called function, as such it must\nalready specify all requirements that will be used for every type parameter.\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":479,"byte_end":484,"line_start":19,"line_end":19,"column_start":24,"column_end":29,"is_primary":true,"text":[{"text":"    let res: i32 = try { 5 }; //~ ERROR the trait bound `i32: std::ops::Try` is not satisfied","highlight_start":24,"highlight_end":29}],"label":"the trait `std::ops::Try` is not implemented for `i32`","suggested_replacement":null,"suggestion_applicability":null,"expansion":{"span":{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":479,"byte_end":484,"line_start":19,"line_end":19,"column_start":24,"column_end":29,"is_primary":false,"text":[{"text":"    let res: i32 = try { 5 }; //~ ERROR the trait bound `i32: std::ops::Try` is not satisfied","highlight_start":24,"highlight_end":29}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null},"macro_decl_name":"desugaring of `try block`","def_site_span":{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":479,"byte_end":484,"line_start":19,"line_end":19,"column_start":24,"column_end":29,"is_primary":false,"text":[{"text":"    let res: i32 = try { 5 }; //~ ERROR the trait bound `i32: std::ops::Try` is not satisfied","highlight_start":24,"highlight_end":29}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}}}],"children":[{"message":"required by `std::ops::Try::from_ok`","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error[E0277]: the trait bound `i32: std::ops::Try` is not satisfied\n  --> /checkout/src/test/ui/try-block/try-block-bad-type.rs:19:24\n   |\nLL |     let res: i32 = try { 5 }; //~ ERROR the trait bound `i32: std::ops::Try` is not satisfied\n   |                        ^^^^^ the trait `std::ops::Try` is not implemented for `i32`\n   |\n   = note: required by `std::ops::Try::from_ok`\n\n"}
[01:07:36] {"message":"aborting due to 5 previous errors","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to 5 previous errors\n\n"}
[01:07:36] {"message":"Some errors occurred: E0271, E0277.","code":null,"level":"","spans":[],"children":[],"rendered":"Some errors occurred: E0271, E0277.\n"}
[01:07:36] 
[01:07:36] ------------------------------------------
[01:07:36] 
[01:07:36] thread '[ui] ui/try-block/try-block-bad-type.rs' panicked at 'explicit panic', src/tools/compiletest/src/runtest.rs:3245:9
---
[01:07:36] 
[01:07:36] thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:495:22
[01:07:36] 
[01:07:36] 
[01:07:36] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-6.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "6.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:019fcfa8
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Wed Jan  9 19:57:44 UTC 2019
---
travis_time:end:0e47c818:start=1547063865844679373,finish=1547063865850683569,duration=6004196
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:1d1355fb
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:095f5020
travis_time:start:095f5020
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:02c4d506
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@scottmcm

This comment has been minimized.

Copy link
Member

scottmcm commented Jan 9, 2019

I was in favour of not having these before, but there have certainly been enough requests that if these are trivial to add, they might as well just exist.

@Amanieu

This comment has been minimized.

Copy link
Contributor

Amanieu commented Jan 10, 2019

I'm in favor of this since it would make NonZero* consistent with Atomic*, which has both signed and unsigned variants even though you could get away with just one.

@rfcbot

This comment has been minimized.

Copy link

rfcbot commented Jan 10, 2019

🔔 This is now entering its final comment period, as per the review above. 🔔

@xfix
Copy link
Contributor

xfix left a comment

I think it would make sense to have some tests for NonZeroI* types. Check whether they can store negative values without causing undefined behaviour, and so on.

@SimonSapin SimonSapin force-pushed the SimonSapin:signed branch from 5624341 to c59ea9f Jan 10, 2019

@Xaeroxe

This comment has been minimized.

Copy link
Contributor

Xaeroxe commented Jan 10, 2019

@SimonSapin SimonSapin force-pushed the SimonSapin:signed branch from c59ea9f to 75e15d4 Jan 10, 2019

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Jan 10, 2019

The job x86_64-gnu-llvm-6.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_fold:start:worker_info
Worker information
hostname: 2b5a4b35-2d7e-4056-a526-a3b927f0331d@1.production-2-worker-com-gce-btlt
version: v6.2.0 https://github.com/travis-ci/worker/tree/5e5476e01646095f48eec13196fdb3faf8f5cbf7
startup: 6.815506732s
travis_fold:end:worker_info
travis_fold:start:system_info
Build system information
---
travis_time:end:2865d998:start=1547137555748345823,finish=1547137556625158916,duration=876813093
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-6.0
---
[00:04:36] 71  |                           Some(unsafe { $Ty(n) })
[00:04:36]     |                                ^^^^^^ unnecessary `unsafe` block
[00:04:36] ...
[00:04:36] 100 | / nonzero_integers! {
[00:04:36] 101 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU8(u8);
[00:04:36] 102 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU16(u16);
[00:04:36] 103 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU32(u32);
[00:04:36] ...   |
[00:04:36] 112 | |     #[stable(feature = "signed_nonzero", since = "1.33.0")] NonZeroIsize(isize);
[00:04:36]     | |_- in this macro invocation
[00:04:36]     |
[00:04:36]     = note: #[warn(unused_unsafe)] on by default
[00:04:36] 
[00:04:36] 
[00:04:36] warning: unnecessary `unsafe` block
[00:04:36]    --> src/libcore/num/mod.rs:71:30
[00:04:36]     |
[00:04:36] 71  |                           Some(unsafe { $Ty(n) })
[00:04:36]     |                                ^^^^^^ unnecessary `unsafe` block
[00:04:36] ...
[00:04:36] 100 | / nonzero_integers! {
[00:04:36] 101 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU8(u8);
[00:04:36] 102 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU16(u16);
[00:04:36] 103 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU32(u32);
[00:04:36] ...   |
[00:04:36] 112 | |     #[stable(feature = "signed_nonzero", since = "1.33.0")] NonZeroIsize(isize);
[00:04:36]     | |_- in this macro invocation
[00:04:36] 
[00:04:36] warning: unnecessary `unsafe` block
[00:04:36]     --> src/libcore/ptr.rs:2785:18
---
[00:04:36] 50  |                   #[rustc_layout_scalar_valid_range_start(1)]
[00:04:36]     |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[00:04:36] ...
[00:04:36] 100 | / nonzero_integers! {
[00:04:36] 101 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU8(u8);
[00:04:36] 102 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU16(u16);
[00:04:36] 103 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU32(u32);
[00:04:36] ...   |
[00:04:36] 112 | |     #[stable(feature = "signed_nonzero", since = "1.33.0")] NonZeroIsize(isize);
[00:04:36]     | |_- in this macro invocation
[00:04:36]     |
[00:04:36]     = note: #[warn(unused_attributes)] on by default
[00:04:36] 
[00:04:36] 
[00:04:36] warning: unused attribute
[00:04:36]    --> src/libcore/num/mod.rs:50:17
[00:04:36]     |
[00:04:36] 50  |                   #[rustc_layout_scalar_valid_range_start(1)]
[00:04:36]     |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[00:04:36] ...
[00:04:36] 100 | / nonzero_integers! {
[00:04:36] 101 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU8(u8);
[00:04:36] 102 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU16(u16);
[00:04:36] 103 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU32(u32);
[00:04:36] ...   |
[00:04:36] 112 | |     #[stable(feature = "signed_nonzero", since = "1.33.0")] NonZeroIsize(isize);
[00:04:36]     | |_- in this macro invocation
[00:04:36] 
[00:04:36] warning: unused attribute
[00:04:36]     --> src/libcore/ptr.rs:2720:1
---
[01:05:29] .................................................................................................... 4600/5298
[01:05:32] .................................................................................................... 4700/5298
[01:05:35] .................................................................................................... 4800/5298
[01:05:39] .................................................................................................... 4900/5298
[01:05:43] ..............................................F..................................................... 5000/5298
[01:05:49] .................................................................................................... 5200/5298
[01:05:51] .....................................i............................................................
[01:05:51] failures:
[01:05:51] 
[01:05:51] 
[01:05:51] ---- [ui] ui/try-block/try-block-bad-type.rs stdout ----
[01:05:51] diff of stderr:
[01:05:51] 
[01:05:51] 5    |         ^^^^^^^^ the trait `std::convert::From<&str>` is not implemented for `i32`
[01:05:51] 7    = help: the following implementations were found:
[01:05:51] 7    = help: the following implementations were found:
[01:05:51] -              <i32 as std::convert::From<bool>>
[01:05:51] +              <i32 as std::convert::From<core::num::NonZer--------
[01:05:51] {"message":"the trait bound `i32: std::convert::From<&str>` is not satisfied","code":{"code":"E0277","explanation":"\nYou tried to use a type which doesn't implement some trait in a place which\nexpected that trait. Erroneous code example:\n\n```compile_fail,E0277\n// here we declare the Foo trait with a bar method\ntrait Foo {\n    fn bar(&self);\n}\n\n// we now declare a function which takes an object implementing the Foo trait\nfn some_func<T: Foo>(foo: T) {\n    foo.bar();\n}\n\nfn main() {\n    // we now call the method with the i32 type, which doesn't implement\n    // the Foo trait\n    some_func(5i32); // error: the trait bound `i32 : Foo` is not satisfied\n}\n```\n\nIn order to fix this error, verify that the type you're using does implement\nthe trait. Example:\n\n```\ntrait Foo {\n    fn bar(&self);\n}\n\nfn some_func<T: Foo>(foo: T) {\n    foo.bar(); // we can now use this method since i32 implements the\n               // Foo trait\n}\n\n// we implement the trait on the i32 type\nimpl Foo for i32 {\n    fn bar(&self) {}\n}\n\nfn main() {\n    some_func(5i32); // ok!\n}\n```\n\nOr in a generic context, an erroneous code example would look like:\n\n```compile_fail,E0277\nfn some_func<T>(foo: T) {\n    println!(\"{:?}\", foo); // error: the trait `core::fmt::Debug` is not\n                           //        implemented for the type `T`\n}\n\nfn main() {\n    // We now call the method with the i32 type,\n    // which *does* implement the Debug trait.\n    some_func(5i32);\n}\n```\n\nNote that the error here is in the definition of the generic function: Although\nwe only call it with a parameter that does implement `Debug`, the compiler\nstill rejects the function: It must work with all possible input types. In\norder to make this example compile, we need to restrict the generic type we're\naccepting:\n\n```\nuse std::fmt;\n\n// Restrict the input type to types that implement Debug.\nfn some_func<T: fmt::Debug>(foo: T) {\n    println!(\"{:?}\", foo);\n}\n\nfn main() {\n    // Calling the method is still fine, as i32 implements Debug.\n    some_func(5i32);\n\n    // This would fail to compile now:\n    // struct WithoutDebug;\n    // some_func(WithoutDebug);\n}\n```\n\nRust only looks at the signature of the called function, as such it must\nalready specify all requirements that will be used for every type parameter.\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":121,"byte_end":129,"line_start":7,"line_end":7,"column_start":9,"column_end":17,"is_primary":true,"text":[{"text":"        Err(\"\")?; //~ ERROR the trait bound `i32: std::convert::From<&str>` is not satisfied","highlight_start":9,"highlight_end":17}],"label":"the trait `std::convert::From<&str>` is not implemented for `i32`","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"the following implementations were found:\n  <i32 as std::convert::From<core::num::NonZeroI32>>\n  <i32 as std::convert::From<i16>>\n  <i32 as std::convert::From<i8>>\n  <i32 as std::convert::From<u8>>\nand 2 others","code":null,"level":"help","spans":[],"children":[],"rendered":null},{"message":"required by `std::convert::From::from`","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error[E0277]: the trait bound `i32: std::convert::From<&str>` is not satisfied\n  --> /checkout/src/test/ui/try-block/try-block-bad-type.rs:7:9\n   |\nLL |         Err(\"\")?; //~ ERROR the trait bound `i32: std::convert::From<&str>` is not satisfied\n   |         ^^^^^^^^ the trait `std::convert::From<&str>` is not implemented for `i32`\n   |\n   = help: the following implementations were found:\n             <i32 as std::convert::From<core::num::NonZeroI32>>\n             <i32 as std::convert::From<i16>>\n             <i32 as std::convert::From<i8>>\n             <i32 as std::convert::From<u8>>\n           and 2 others\n   = note: required by `std::convert::From::from`\n\n"}
[01:05:51] {"message":"type mismatch resolving `<std::result::Result<i32, i32> as std::ops::Try>::Ok == &str`","code":{"code":"E0271","explanation":"\nThis is because of a type mismatch between the associated type of some\ntrait (e.g., `T::Bar`, where `T` implements `trait Quux { type Bar; }`)\nand another type `U` that is required to be equal to `T::Bar`, but is not.\nExamples follow.\n\nHere is a basic example:\n\n```compile_fail,E0271\ntrait Trait { type AssociatedType; }\n\nfn foo<T>(t: T) where T: Trait<AssociatedType=u32> {\n    println!(\"in foo\");\n}\n\nimpl Trait for i8 { type AssociatedType = &'static str; }\n\nfoo(3_i8);\n```\n\nHere is that same example again, with some explanatory comments:\n\n```compile_fail,E0271\ntrait Trait { type AssociatedType; }\n\nfn foo<T>(t: T) where T: Trait<AssociatedType=u32> {\n//                    ~~~~~~~~ ~~~~~~~~~~~~~~~~~~\n//                        |            |\n//         This says `foo` can         |\n//           only be used with         |\n//              some type that         |\n//         implements `Trait`.         |\n//                                     |\n//                             This says not only must\n//                             `T` be an impl of `Trait`\n//                             but also that the impl\n//                             must assign the type `u32`\n//                             to the associated type.\n    println!(\"in foo\");\n}\n\nimpl Trait for i8 { type AssociatedType = &'static str; }\n//~~~~~~~~~~~~~~~   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n//      |                             |\n// `i8` does have                     |\n// implementation                     |\n// of `Trait`...                      |\n//                     ... but it is an implementation\n//                     that assigns `&'static str` to\n//                     the associated type.\n\nfoo(3_i8);\n// Here, we invoke `foo` with an `i8`, which does not satisfy\n// the constraint `<i8 as Trait>::AssociatedType=u32`, and\n// therefore the type-checker complains with this error code.\n```\n\nTo avoid those issues, you have to make the types match correctly.\nSo we can fix the previous examples like this:\n\n```\n// Basic Example:\ntrait Trait { type AssociatedType; }\n\nfn foo<T>(t: T) where T: Trait<AssociatedType = &'static str> {\n    println!(\"in foo\");\n}\n\nimpl Trait for i8 { type AssociatedType = &'static str; }\n\nfoo(3_i8);\n\n// For-Loop Example:\nlet vs = vec![1, 2, 3, 4];\nfor v in &vs {\n    match v {\n        &1 => {}\n        _ => {}\n    }\n}\n```\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":270,"byte_end":272,"line_start":12,"line_end":12,"column_start":9,"column_end":11,"is_primary":true,"text":[{"text":"        \"\" //~ ERROR type mismatch","highlight_start":9,"highlight_end":11}],"label":"expected i32, found &str","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"expected type `i32`\n   found type `&str`","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error[E0271]: type mismatch resolving `<std::result::Result<i32, i32> as std::ops::Try>::Ok == &str`\n  --> /checkout/src/test/ui/try-block/try-block-bad-type.rs:12:9\n   |\nLL |         \"\" //~ ERROR type mismatch\n   |         ^^ expected i32, found &str\n   |\n   = note: expected type `i32`\n              found type `&str`\n\n"}
[01:05:51] {"message":"type mismatch resolving `<std::result::Result<i32, i32> as std::ops::Try>::Ok == ()`","code":{"code":"E0271","explanation":"\nThis is because of a type mismatch between the associated type of some\ntrait (e.g., `T::Bar`, where `T` implements `trait Quux { type Bar; }`)\nand another type `U` that is required to be equal to `T::Bar`, but is not.\nExamples follow.\n\nHere is a basic example:\n\n```compile_fail,E0271\ntrait Trait { type AssociatedType; }\n\nfn foo<T>(t: T) where T: Trait<AssociatedType=u32> {\n    println!(\"in foo\");\n}\n\nimpl Trait for i8 { type AssociatedType = &'static str; }\n\nfoo(3_i8);\n```\n\nHere is that same example again, with some explanatory comments:\n\n```compile_fail,E0271\ntrait Trait { type AssociatedType; }\n\nfn foo<T>(t: T) where T: Trait<AssociatedType=u32> {\n//                    ~~~~~~~~ ~~~~~~~~~~~~~~~~~~\n//                        |            |\n//         This says `foo` can         |\n//           only be used with         |\n//              some type that         |\n//         implements `Trait`.         |\n//                                     |\n//                             This says not only must\n//                             `T` be an impl of `Trait`\n//                             but also that the impl\n//                             must assign the type `u32`\n//                             to the associated type.\n    println!(\"in foo\");\n}\n\nimpl Trait for i8 { type AssociatedType = &'static str; }\n//~~~~~~~~~~~~~~~   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n//      |                             |\n// `i8` does have                     |\n// implementation                     |\n// of `Trait`...                      |\n//                     ... but it is an implementation\n//                     that assigns `&'static str` to\n//                     the associated type.\n\nfoo(3_i8);\n// Here, we invoke `foo` with an `i8`, which does not satisfy\n// the constraint `<i8 as Trait>::AssociatedType=u32`, and\n// therefore the type-checker complains with this error code.\n```\n\nTo avoid those issues, you have to make the types match correctly.\nSo we can fix the previous examples like this:\n\n```\n// Basic Example:\ntrait Trait { type AssociatedType; }\n\nfn foo<T>(t: T) where T: Trait<AssociatedType = &'static str> {\n    println!(\"in foo\");\n}\n\nimpl Trait for i8 { type AssociatedType = &'static str; }\n\nfoo(3_i8);\n\n// For-Loop Example:\nlet vs = vec![1, 2, 3, 4];\nfor v in &vs {\n    match v {\n        &1 => {}\n        _ => {}\n    }\n}\n```\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":343,"byte_end":344,"line_start":15,"line_end":15,"column_start":39,"column_end":40,"is_primary":true,"text":[{"text":"    let res: Result<i32, i32> = try { }; //~ ERROR type mismatch","highlight_start":39,"highlight_end":40}],"label":"expected i32, found ()","suggested_replacement":null,"suggestion_applicability":null,"expansion":{"span":{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":341,"byte_end":344,"line_start":15,"line_end":15,"column_start":37,"column_end":40,"is_primary":false,"text":[{"text":"    let res: Result<i32, i32> = try { }; //~ ERROR type mismatch","highlight_start":37,"highlight_end":40}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null},"macro_decl_name":"desugaring of `try block`","def_site_span":{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":341,"byte_end":344,"line_start":15,"line_end":15,"column_start":37,"column_end":40,"is_primary":false,"text":[{"text":"    let res: Result<i32, i32> = try { }; //~ ERROR type mismatch","highlight_start":37,"highlight_end":40}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}}}],"children":[{"message":"expected type `i32`\n   found type `()`","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error[E0271]: type mismatch resolving `<std::result::Result<i32, i32> as std::ops::Try>::Ok == ()`\n  --> /checkout/src/test/ui/try-block/try-block-bad-type.rs:15:39\n   |\nLL |     let res: Result<i32, i32> = try { }; //~ ERROR type mismatch\n   |                                       ^ expected i32, found ()\n   |\n   = note: expected type `i32`\n              found type `()`\n\n"}
[01:05:51] {"message":"the trait bound `(): std::ops::Try` is not satisfied","code":{"code":"E0277","explanation":"\nYou tried to use a type which doesn't implement some trait in a place which\nexpected that trait. Erroneous code example:\n\n```compile_fail,E0277\n// here we declare the Foo trait with a bar method\ntrait Foo {\n    fn bar(&self);\n}\n\n// we now declare a function which takes an object implementing the Foo trait\nfn some_func<T: Foo>(foo: T) {\n    foo.bar();\n}\n\nfn main() {\n    // we now call the method with the i32 type, which doesn't implement\n    // the Foo trait\n    some_func(5i32); // error: the trait bound `i32 : Foo` is not satisfied\n}\n```\n\nIn order to fix this error, verify that the type you're using does implement\nthe trait. Example:\n\n```\ntrait Foo {\n    fn bar(&self);\n}\n\nfn some_func<T: Foo>(foo: T) {\n    foo.bar(); // we can now use this method since i32 implements the\n               // Foo trait\n}\n\n// we implement the trait on the i32 type\nimpl Foo for i32 {\n    fn bar(&self) {}\n}\n\nfn main() {\n    some_func(5i32); // ok!\n}\n```\n\nOr in a generic context, an erroneous code example would look like:\n\n```compile_fail,E0277\nfn some_func<T>(foo: T) {\n    println!(\"{:?}\", foo); // error: teclare the Foo trait with a bar method\ntrait Foo {\n    fn bar(&self);\n}\n\n// we now declare a function which takes an object implementing the Foo trait\nfn some_func<T: Foo>(foo: T) {\n    foo.bar();\n}\n\nfn main() {\n    // we now call the method with the i32 type, which doesn't implement\n    // the Foo trait\n    some_func(5i32); // error: the trait bound `i32 : Foo` is not satisfied\n}\n```\n\nIn order to fix this error, verify that the type you're using does implement\nthe trait. Example:\n\n```\ntrait Foo {\n    fn bar(&self);\n}\n\nfn some_func<T: Foo>(foo: T) {\n    foo.bar(); // we can now use this method since i32 implements the\n               // Foo trait\n}\n\n// we implement the trait on the i32 type\nimpl Foo for i32 {\n    fn bar(&self) {}\n}\n\nfn main() {\n    some_func(5i32); // ok!\n}\n```\n\nOr in a generic context, an erroneous code example would look like:\n\n```compile_fail,E0277\nfn some_func<T>(foo: T) {\n    println!(\"{:?}\", foo); // error: the trait `core::fmt::Debug` is not\n                           //        implemented for the type `T`\n}\n\nfn main() {\n    // We now call the method with the i32 type,\n    // which *does* implement the Debug trait.\n    some_func(5i32);\n}\n```\n\nNote that the error here is in the definition of the generic function: Although\nwe only call it with a parameter that does implement `Debug`, the compiler\nstill rejects the function: It must work with all possible input types. In\norder to make this example compile, we need to restrict the generic type we're\naccepting:\n\n```\nuse std::fmt;\n\n// Restrict the input type to types that implement Debug.\nfn some_func<T: fmt::Debug>(foo: T) {\n    println!(\"{:?}\", foo);\n}\n\nfn main() {\n    // Calling the method is still fine, as i32 implements Debug.\n    some_func(5i32);\n\n    // This would fail to compile now:\n    // struct WithoutDebug;\n    // some_func(WithoutDebug);\n}\n```\n\nRust only looks at the signature of the called function, as such it must\nalready specify all requirements that will be used for every type parameter.\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":479,"byte_end":484,"line_start":19,"line_end":19,"column_start":24,"column_end":29,"is_primary":true,"text":[{"text":"    let res: i32 = try { 5 }; //~ ERROR the trait bound `i32: std::ops::Try` is not satisfied","highlight_start":24,"highlight_end":29}],"label":"the trait `std::ops::Try` is not implemented for `i32`","suggested_replacement":null,"suggestion_applicability":null,"expansion":{"span":{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":479,"byte_end":484,"line_start":19,"line_end":19,"column_start":24,"column_end":29,"is_primary":false,"text":[{"text":"    let res: i32 = try { 5 }; //~ ERROR the trait bound `i32: std::ops::Try` is not satisfied","highlight_start":24,"highlight_end":29}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null},"macro_decl_name":"desugaring of `try block`","def_site_span":{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":479,"byte_end":484,"line_start":19,"line_end":19,"column_start":24,"column_end":29,"is_primary":false,"text":[{"text":"    let res: i32 = try { 5 }; //~ ERROR the trait bound `i32: std::ops::Try` is not satisfied","highlight_start":24,"highlight_end":29}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}}}],"children":[{"message":"required by `std::ops::Try::from_ok`","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error[E0277]: the trait bound `i32: std::ops::Try` is not satisfied\n  --> /checkout/src/test/ui/try-block/try-block-bad-type.rs:19:24\n   |\nLL |     let res: i32 = try { 5 }; //~ ERROR the trait bound `i32: std::ops::Try` is not satisfied\n   |                        ^^^^^ the trait `std::ops::Try` is not implemented for `i32`\n   |\n   = note: required by `std::ops::Try::from_ok`\n\n"}
[01:05:51] {"message":"aborting due to 5 previous errors","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to 5 previous errors\n\n"}
[01:05:51] {"message":"Some errors occurred: E0271, E0277.","code":null,"level":"","spans":[],"children":[],"rendered":"Some errors occurred: E0271, E0277.\n"}
[01:05:51] 
[01:05:51] ------------------------------------------
[01:05:51] 
[01:05:51] thread '[ui] ui/try-block/try-block-bad-type.rs' panicked at 'explicit panic', src/tools/compiletest/src/runtest.rs:3245:9
---
[01:05:51] 
[01:05:51] thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:495:22
[01:05:51] 
[01:05:51] 
[01:05:51] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-6.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "6.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[01:05:51] 
[01:05:51] 
[01:05:51] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:05:51] Build completed unsuccessfully in 0:04:11
[01:05:51] Build completed unsuccessfully in 0:04:11
[01:05:51] make: *** [check] Error 1
[01:05:51] Makefile:48: recipe for target 'check' failed
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:0180ced4
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Thu Jan 10 17:31:59 UTC 2019
---
travis_time:end:0535b124:start=1547141520598605699,finish=1547141520603683530,duration=5077831
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:24edfdc8
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:01a30b32
travis_time:start:01a30b32
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:180843ea
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@SimonSapin SimonSapin force-pushed the SimonSapin:signed branch from 75e15d4 to f1bf970 Jan 10, 2019

@SimonSapin

This comment has been minimized.

Copy link
Contributor

SimonSapin commented Jan 10, 2019

I’d appreciate some help. Maybe @alexcrichton?

I’m getting errors like

---- num/mod.rs - num::NonZeroI16 (line 33) stdout ----
error[E0412]: cannot find type `NonZeroI16` in module `std::num`
 --> num/mod.rs:35:39
  |
5 | assert_eq!(size_of::<Option<std::num::NonZeroI16>>(), size_of::<i16>());
  |                                       ^^^^^^^^^^ did you mean `NonZeroU16`?

thread 'num/mod.rs - num::NonZeroI16 (line 33)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:321:13

It looks like a newly-added type cannot be found in the doctests of that very type.

Later in the output:

command did not execute successfully: "/home/simon/rust3/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "test" "--target" "x86_64-unknown-linux-gnu" "-j" "8" "--release" "--features" "panic-unwind backtrace" "--manifest-path" "/home/simon/rust3/src/libstd/Cargo.toml" "-p" "core" "--" "--quiet"
expected success, got: exit code: 101

… which includes stage0. The error would make some sense if the bootstrap compiler’s libcore is used to run the new libcore’s doctests, but why would that be the case when running simply ./x.py test?

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Jan 11, 2019

The job x86_64-gnu-llvm-6.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:0fe5c89c:start=1547161308643622142,finish=1547161310979617799,duration=2335995657
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-6.0
---
    97% |███████████████████████████████▍| 532kB 84.1MB/s eta 0:00:01
    99% |████████████████████████████████| 542kB 83.9MB/s eta 0:00:01
    100% |████████████████████████████████| 552kB 29.6MB/s 
Collecting botocore==1.12.77 (from awscli)
  Downloading https://files.pythonhosted.org/packages/f3/cd/f58bacbfb28d92716bfb7af2a8c5d5230663335b6a5e4d78d8ccdfab469d/botocore-1.12.77-py2.py3-none-any.whl (5.2MB)
    0% |▏                               | 20kB 29.5MB/s eta 0:00:01
    0% |▏                               | 30kB 35.6MB/s eta 0:00:01
    0% |▎                               | 40kB 40.3MB/s eta 0:00:01
    0% |▎                               | 51kB 43.3MB/s eta 0:00:01
---
[00:04:02] 71  |                           Some(unsafe { $Ty(n) })
[00:04:02]     |                                ^^^^^^ unnecessary `unsafe` block
[00:04:02] ...
[00:04:02] 100 | / nonzero_integers! {
[00:04:02] 101 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU8(u8);
[00:04:02] 102 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU16(u16);
[00:04:02] 103 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU32(u32);
[00:04:02] ...   |
[00:04:02] 112 | |     #[stable(feature = "signed_nonzero", since = "1.33.0")] NonZeroIsize(isize);
[00:04:02]     | |_- in this macro invocation
[00:04:02]     |
[00:04:02]     = note: #[warn(unused_unsafe)] on by default
[00:04:02] 
[00:04:02] 
[00:04:02] warning: unnecessary `unsafe` block
[00:04:02]    --> src/libcore/num/mod.rs:71:30
[00:04:02]     |
[00:04:02] 71  |                           Some(unsafe { $Ty(n) })
[00:04:02]     |                                ^^^^^^ unnecessary `unsafe` block
[00:04:02] ...
[00:04:02] 100 | / nonzero_integers! {
[00:04:02] 101 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU8(u8);
[00:04:02] 102 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU16(u16);
[00:04:02] 103 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU32(u32);
[00:04:02] ...   |
[00:04:02] 112 | |     #[stable(feature = "signed_nonzero", since = "1.33.0")] NonZeroIsize(isize);
[00:04:02]     | |_- in this macro invocation
[00:04:02] 
[00:04:02] warning: unnecessary `unsafe` block
[00:04:02]     --> src/libcore/ptr.rs:2785:18
---
[00:04:02] 50  |                   #[rustc_layout_scalar_valid_range_start(1)]
[00:04:02]     |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[00:04:02] ...
[00:04:02] 100 | / nonzero_integers! {
[00:04:02] 101 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU8(u8);
[00:04:02] 102 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU16(u16);
[00:04:02] 103 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU32(u32);
[00:04:02] ...   |
[00:04:02] 112 | |     #[stable(feature = "signed_nonzero", since = "1.33.0")] NonZeroIsize(isize);
[00:04:02]     | |_- in this macro invocation
[00:04:02]     |
[00:04:02]     = note: #[warn(unused_attributes)] on by default
[00:04:02] 
[00:04:02] 
[00:04:02] warning: unused attribute
[00:04:02]    --> src/libcore/num/mod.rs:50:17
[00:04:02]     |
[00:04:02] 50  |                   #[rustc_layout_scalar_valid_range_start(1)]
[00:04:02]     |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[00:04:02] ...
[00:04:02] 100 | / nonzero_integers! {
[00:04:02] 101 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU8(u8);
[00:04:02] 102 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU16(u16);
[00:04:02] 103 | |     #[stable(feature = "nonzero", since = "1.28.0")] NonZeroU32(u32);
[00:04:02] ...   |
[00:04:02] 112 | |     #[stable(feature = "signed_nonzero", since = "1.33.0")] NonZeroIsize(isize);
[00:04:02]     | |_- in this macro invocation
[00:04:02] 
[00:04:02] warning: unused attribute
[00:04:02]     --> src/libcore/ptr.rs:2720:1
---
[01:03:37] .................................................................................................... 4600/5298
[01:03:40] .................................................................................................... 4700/5298
[01:03:43] .................................................................................................... 4800/5298
[01:03:47] .................................................................................................... 4900/5298
[01:03:51] ..............................................F..................................................... 5000/5298
[01:03:58] .................................................................................................... 5200/5298
[01:04:01] .....................................i............................................................
[01:04:01] failures:
[01:04:01] 
[01:04:01] 
[01:04:01] ---- [ui] ui/try-block/try-block-bad-type.rs stdout ----
[01:04:01] diff of stderr:
[01:04:01] 
[01:04:01] 5    |         ^^^^^^^^ the trait `std::convert::From<&str>` is not implemented for `i32`
[01:04:01] 7    = help: the following implementations were found:
[01:04:01] 7    = help: the following implementations were found:
[01:04:01] -              <i32 as std::convert::From<bool>>
[01:04:01] +              <i32 as std::convert::From<core::num::NonZeroI32>>
[01:04:01] 9              <i32 as std::convert::From<i16>>
[01:04:01] -              <i32 as std::convert::From<u16>>
[01:04:01] +              <i32 as std::convert::From<i8>>
[01:04:01] 11              <i32 as std::convert::From<u8>>
[01:04:01] 13    = note: required by `std::convert::From::from`
[01:04:01] 
[01:04:01] 
[01:04:01] The actual stderr differed from the expected stderr.
[01:04:01] The actual stderr differed from the expected stderr.
[01:04:01] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/try-block/try-block-bad-type/try-block-bad-type.stderr
[01:04:01] To update references, rerun the tests and pass the `--bless` flag
[01:04:01] To only update this specific test, also pass `--test-args try-block/try-block-bad-type.rs`
[01:04:01] error: 1 errors occurred comparing output.
[01:04:01] status: exit code: 1
[01:04:01] status: exit code: 1
[01:04:01] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/try-block/try-block-bad-type.rs" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/try-block/try-block-bad-type/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--edition" "2018" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/try-block/try-block-bad-type/auxiliary" "-A" "unused"
[01:04:01] ------------------------------------------
[01:04:01] 
[01:04:01] ------------------------------------------
[01:04:01] stderr:
[01:04:01] stderr:
[01:04:01] ------------------------------------------
[01:04:01] {"message":"the trait bound `i32: std::convert::From<&str>` is not satisfied","code":{"code":"E0277","explanation":"\nYou tried to use a type which doesn't implement some trait in a place which\nexpected that trait. Erroneous code example:\n\n```compile_fail,E0277\n// here we declare the Foo trait with a bar method\ntrait Foo {\n    fn bar(&self);\n}\n\n// we now declare a function which takes an object implementing the Foo trait\nfn some_func<T: Foo>(foo: T) {\n    foo.bar();\n}\n\nfn main() {\n    // we now call the method with the i32 type, which doesn't implement\n    // the Foo trait\n    some_func(5i32); // error: the trait bound `i32 : Foo` is not satisfied\n}\n```\n\nIn order to fix this error, verify that the type you're using does implement\nthe trait. Example:\n\n```\ntrait Foo {\n    fn bar(&self);\n}\n\nfn some_func<T: Foo>(foo: T) {\n    foo.bar(); // we can now use this method since i32 implements the\n               // Foo trait\n}\n\n// we implement the trait on the i32 type\nimpl Foo for i32 {\n    fn bar(&self) {}\n}\n\nfn main() {\n    some_func(5i32); // ok!\n}\n```\n\nOr in a generic context, an erroneous code example would look like:\n\n```compile_fail,E0277\nfn some_func<T>(foo: T) {\n    println!(\"{:?}\", foo); // error: the trait `core::fmt::Debug` is not\n                           //        implemented for the type `T`\n}\n\nfn main() {\n    // We now call the method with the i32 type,\n    // which *does* implement the Debug trait.\n    some_func(5i32);\n}\n```\n\nNote that the error here is in the definition of the generic function: Although\nwe only call it with a parameter that does implement `Debug`, the compiler\nstill rejects the function: It must work with all possible input types. In\norder to make this example compile, we need to restrict the generic type we're\naccepting:\n\n```\nuse std::fmt;\n\n// Restrict the input type to types that implement Debug.\nfn some_func<T: fmt::Debug>(foo: T) {\n    println!(\"{:?}\", foo);\n}\n\nfn main() {\n    // Calling the method is still fine, as i32 implements Debug.\n    some_func(5i32);\n\n    // This would fail to compile now:\n    // struct WithoutDebug;\n    // some_func(WithoutDebug);\n}\n```\n\nRust only looks at the signature of the called function, as such it must\nalready specify all requirements that will be used for every type parameter.\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":121,"byte_end":129,"line_start":7,"line_end":7,"column_start":9,"column_end":17,"is_primary":true,"text":[{"text":"        Err(\"\")?; //~ ERROR the trait bound `i32: std::convert::From<&str>` is not satisfied","highlight_start":9,"highlight_end":17}],"label":"the trait `std::convert::From<&str>` is not implemented for `i32`","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"the following implementations were found:\n  <i32 as std::convert::From<core::num::NonZeroI32>>\n  <i32 as std::convert::From<i16>>\n  <i32 as std::convert::From<i8>>\n  <i32 as std::convert::From<u8>>\nand 2 others","code":null,"level":"help","spans":[],"children":[],"rendered":null},{"message":"required by `std::convert::From::from`","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error[E0277]: the trait bound `i32: std::convert::From<&str>` is not satisfied\n  --> /checkout/src/test/ui/try-block/try-block-bad-type.rs:7:9\n   |\nLL |         Err(\"\")?; //~ ERROR the trait bound `i32: std::convert::From<&str>` is not satisfied\n   |         ^^^^^^^^ the trait `std::convert::From<&str>` is not implemented for `i32`\n   |\n   = help: the following implementations were found:\n             <i32 as std::convert::From<core::num::NonZeroI32>>\n             <i32 as std::convert::From<i16>>\n             <i32 as std::convert::From<i8>>\n             <i32 as std::convert::From<u8>>\n           and 2 others\n   = note: required by `std::convert::From::from`\n\n"}
[01:04:01] {"message":"type mismatch resolving `<std::result::Result<i32, i32> as std::ops::Try>::Ok == &str`","code":{"code":"E0271","explanation":"\nThis is because of a type mismatch between the associated type of some\ntrait (e.g., `T::Bar`, where `T` implements `trait Quux { type Bar; }`)\nand another type `U` that is required to be equal to `T::Bar`, but is not.\nExamples follow.\n\nHere is a basic example:\n\n```compile_fail,E0271\ntrait Trait { type AssociatedType; }\n\nfn foo<T>(t: T) where T: Trait<AssociatedType=u32> {\n    println!(\"in foo\");\n}\n\nimpl Trait for i8 { type AssociatedType = &'static str; }\n\nfoo(3_i8);\n```\n\nHere is that same example again, with some explanatory comments:\n\n```compile_fail,E0271\ntrait Trait { type AssociatedType; }\n\nfn foo<T>(t: T) where T: Trait<AssociatedType=u32> {\n//                    ~~~~~~~~ ~~~~~~~~~~~~~~~~~~\n//                        |            |\n//         This says `foo` can         |\n//           only be used with         |\n//              some type that         |\n//         implements `Trait`.         |\n//                                     |\n//                             This says not only must\n//                             `T` be an impl of `Trait`\n//                             but also that the impl\n//                             must assign the type `u32`\n//                             to the associated type.\n    println!(\"in foo\");\n}\n\nimpl Trait for i8 { type AssociatedType = &'static str; }\n//~~~~~~~~~~~~~~~   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n//      |                             |\n// `i8` does have                     |\n// implementation                     |\n// of `Trait`...                      |\n//                     ... but it is an implementation\n//                     that assigns `&'static str` to\n//                     the associated type.\n\nfoo(3_i8);\n// Here, we invoke `foo` with an `i8`, which does not satisfy\n// the constraint `<i8 as Trait>::AssociatedType=u32`, and\n// therefore the type-checker complains with this error code.\n```\n\nTo avoid those issues, you have to make the types match correctly.\nSo we can fix the previous examples like this:\n\n```\n// Basic Example:\ntrait Trait { type AssociatedType; }\n\nfn foo<T>(t: T) where T: Trait<AssociatedType = &'static str> {\n    println!(\"in foo\");\n}\n\nimpl Trait for i8 { type AssociatedType = &'static str; }\n\nfoo(3_i8);\n\n// For-Loop Example:\nlet vs = vec![1, 2, 3, 4];\nfor v in &vs {\n    match v {\n        &1 => {}\n        _ => {}\n    }\n}\n```\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":270,"byte_end":272,"line_start":12,"line_end":12,"column_start":9,"column_end":11,"is_primary":true,"text":[{"text":"        \"\" //~ ERROR type mismatch","highlight_start":9,"highlight_end":11}],"label":"expected i32, found &str","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"expected type `i32`\n   found type `&str`","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error[E0271]: type mismatch resolving `<std::result::Result<i32, i32> as std::ops::Try>::Ok == &str`\n  --> /checkout/src/test/ui/try-block/try-block-bad-type.rs:12:9\n   |\nLL |         \"\" //~ ERROR type mismatch\n   |         ^^ expected i32, found &str\n   |\n   = note: expected type `i32`\n              found type `&str`\n\n"}
[01:04:01] {"message":"type mismatch resolving `<std::result::Result<i32, i32> as std::ops::Try>::Ok == ()`","code":{"code":"E0271","explanation":"\nThis is because of a type mismatch between the associated type of some\ntrait (e.g., `T::Bar`, where `T` implements `trait Quux { type Bar; }`)\nand another type `U` that is required to be equal to `T::Bar`, but is not.\nExamples follow.\n\nHere is a basic example:\n\n```compile_fail,E0271\ntrait Trait { type AssociatedType; }\n\nfn foo<T>(t: T) where T: Trait<AssociatedType=u32> {\n    println!(\"in foo\");\n}\n\nimpl Trait for i8 { type AssociatedType = &'static str; }\n\nfoo(3_i8);\n```\n\nHere is that same example again, with some explanatory comments:\n\n```compile_fail,E0271\ntrait Trait { type AssociatedType; }\n\nfn foo<T>(t: T) where T: Trait<AssociatedType=u32> {\n//                    ~~~~~~~~ ~~~~~~~~~~~~~~~~~~\n//                        |            |\n//         This says `foo` can         |\n//           only be used with         |\n//              some type that         |\n//         implements `Trait`.         |\n//                                     |\n//                             This says not only must\n//                             `T` be an impl of `Trait`\n//                             but also that the impl\n//                             must assign the type `u32`\n//                             to the associated type.\n    println!(\"in foo\");\n}\n\nimpl Trait for i8 { type AssociatedType = &'static str; }\n//~~~~~~~~~~~~~~~   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n//      |                             |\n// `i8` does have                     |\n// implementation                     |\n// of `Trait`...                      |\n//                     ... but it is an implementation\n//                     that assigns `&'static str` to\n//                     the associated type.\n\nfoo(3_i8);\n// Here, we invoke `foo` with an `i8`, which does not satisfy\n// the constraint `<i8 as Trait>::AssociatedType=u32`, and\n// therefore the type-checker complains with this error code.\n```\n\nTo avoid those issues, you have to make the types match correctly.\nSo we can fix the previous examples like this:\n\n```\n// Basic Example:\ntrait Trait { type AssociatedType; }\n\nfn foo<T>(t: T) where T: Trait<AssociatedType = &'static str> {\n    println!(\"in foo\");\n}\n\nimpl Trait for i8 { type AssociatedType = &'static str; }\n\nfoo(3_i8);\n\n// For-Loop Example:\nlet vs = vec![1, 2, 3, 4];\nfor v in &vs {\n    match v {\n        &1 => {}\n        _ => {}\n    }\n}\n```\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":343,"byte_end":344,"line_start":15,"line_end":15,"column_start":39,"column_end":40,"is_primary":true,"text":[{"text":"    let res: Result<i32, i32> = try { }; //~ ERROR type mismatch","highlight_start":39,"highlight_end":40}],"label":"expected i32, found ()","suggested_replacement":null,"suggestion_applicability":null,"expansion":{"span":{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":341,"byte_end":344,"line_start":15,"line_end":15,"column_start":37,"column_end":40,"is_primary":false,"text":[{"text":"    let res: Result<i32, i32> = try { }; //~ ERROR type mismatch","highlight_start":37,"highlight_end":40}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null},"macro_decl_name":"desugaring of `try block`","def_site_span":{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":341,"byte_end":344,"line_start":15,"line_end":15,"column_start":37,"column_end":40,"is_primary":false,"text":[{"text":"    let res: Result<i32, i32> = try { }; //~ ERROR type mismatch","highlight_start":37,"highlight_end":40}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}}}],"children":[{"message":"expected type `i32`\n   found type `()`","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error[E0271]: type mismatch resolving `<std::result::Result<i32, i32> as std::ops::Try>::Ok == ()`\n  --> /checkout/src/test/ui/try-block/try-block-bad-type.rs:15:39\n   |\nLL |     let res: Result<i32, i32> = try { }; //~ ERROR type mismatch\n   |                                       ^ expected i32, found ()\n   |\n   = note: expected type `i32`\n              found type `()`\n\n"}
[01:04:01] {"message":"the trait bound `(): std::ops::Try` is not satisfied","code":{"code":"E0277","explanation":"\nYou tried to use a type which doesn't implement some trait in a place which\nexpected that trait. Erroneous code example:\n\n```compile_fail,E0277\n// here we declare the Foo trait with a bar method\ntrait Foo {\n    fn bar(&self);\n}\n\n// we now declare a function which takes an object implementing the Foo trait\nfn some_func<T: Foo>(foo: T) {\n    foo.bar();\n}\n\nfn main() {\n    // we now call the method with the i32 type, which doesn't implement\n    // the Foo trait\n    some_func(5i32); // error: the trait bound `i32 : Foo` is not satisfied\n}\n```\n\nIn order to fix this error, verify that the type you're using does implement\nthe trait. Example:\n\n```\ntrait Foo {\n    fn bar(&self);\n}\n\nfn some_func<T: Foo>(foo: T) {\n    foo.bar(); // we can now use this method since i32 implements the\n               // Foo trait\n}\n\n// we implement the trait on the i32 type\nimpl Foo for i32 {\n    fn bar(&self) {}\n}\n\nfn main() {\n    some_func(5i32); // ok!\n}\n```\n\nOr in a generic context, an erroneous code example would look like:\n\n```compile_fail,E0277\nfn some_func<T>(foo: T) {\n    println!(\"{:?}\", foo); // error: the trait `core::fmt::Debug` is not\n                           //        implemented for the type `T`\n}\n\nfn main() {\n    // We now call the method with the i32 type,\n    // which *does* implement the Debug trait.\n    some_func(5i32);\n}\n```\n\nNote that the error here is in the definition of the generic function: Although\nwe only call it with a parameter that does implement `Debug`, the compiler\nstill rejects the function: It must work with all possible input types. In\norder to make this example compile, we need to restrict the generic type we're\naccepting:\n\n```\nuse std::fmt;\n\n// Restrict the input type to types that implement Debug.\nfn some_func<T: fmt::Debug>(foo: T) {\n    println!(\"{:?}\", foo);\n}\n\nfn main() {\n    // Calling the method is still fine, as i32 implements Debug.\n    some_func(5i32);\n\n    // This would fail to compile now:\n    // struct WithoutDebug;\n    // some_func(WithoutDebug);\n}\n```\n\nRust only looks at the signature of the called function, as such it must\nalready specify all requirements that will be used for every type parameter.\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":393,"byte_end":396,"line_start":17,"line_end":17,"column_start":23,"column_end":26,"is_primary":true,"text":[{"text":"    let res: () = try { }; //~ the trait bound `(): std::ops::Try` is not satisfied","highlight_start":23,"highlight_end":26}],"label":"the trait `std::ops::Try` is not implemented for `()`","suggested_replacement":null,"suggestion_applicability":null,"expansion":{"span":{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":393,"byte_end":396,"line_start":17,"line_end":17,"column_start":23,"column_end":26,"is_primary":false,"text":[{"text":"    let res: () = try { }; //~ the trait bound `(): std::ops::Try` is not satisfied","highlight_start":23,"highlight_end":26}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null},"macro_decl_name":"desugaring of `try block`","def_site_span":{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":393,"byte_end":396,"line_start":17,"line_end":17,"column_start":23,"column_end":26,"is_primary":false,"text":[{"text":"    let res: () = try { }; //~ the trait bound `(): std::ops::Try` is not satisfied","highlight_start":23,"highlight_end":26}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}}}],"children":[{"message":"required by `std::ops::Try::from_ok`","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error[E0277]: the trait bound `(): std::ops::Try` is not satisfied\n  --> /checkout/src/test/ui/try-block/try-block-bad-type.rs:17:23\n   |\nLL |     let res: () = try { }; //~ the trait bound `(): std::ops::Try` is not satisfied\n   |                       ^^^ the trait `std::ops::Try` is not implemented for `()`\n   |\n   = note: required by `std::ops::Try::from_ok`\n\n"}
[01:04:01] {"message":"the trait bound `i32: std::ops::Try` is not satisfied","code":{"code":"E0277","explanation":"\nYou tried to use a type which doesn't implement some trait in a place which\nexpected that trait. Erroneous code example:\n\n```compile_fail,E0277\n// here we declare the Foo trait with a bar method\ntrait Foo {\n    fn bar(&self);\n}\n\n// we now declare a function which takes an object implementing the Foo trait\nfn some_func<T: Foo>(foo: T) {\n    foo.bar();\n}\n\nfn main() {\n    // we now call the method with the i32 type, which doesn't implement\n    // the Foo trait\n    some_func(5i32); // error: the trait bound `i32 : Foo` is not satisfied\n}\n```\n\nIn order to fix this error, verify that the type you're using does implement\nthe trait. Example:\n\n```\ntrait Foo {\n    fn bar(&self);\n}\n\nfn some_func<T: Foo>(foo: T) {\n    foo.bar(); // we can now use this method since i32 implements the\n               // Foo trait\n}\n\n// we implement the trait on the i32 type\nimpl Foo for i32 {\n    fn bar(&self) {}\n}\n\nfn main() {\n    some_func(5i32); // ok!\n}\n```\n\nOr in a generic context, an erroneous code example would look like:\n\n```compile_fail,E0277\nfn some_func<T>(foo: T) {\n    println!(\"{:?}\", foo); // error: the trait `core::fmt::Debug` is not\n                           //        implemented for the type `T`\n}\n\nfn main() {\n    // We now call the method with the i32 type,\n    // which *does* implement the Debug trait.\n    some_func(5i32);\n}\n```\n\nNote that the error here is in the definition of the generic function: Although\nwe only call it with a parameter that does implement `Debug`, the compiler\nstill rejects the function: It must work with all possible input types. In\norder to make this example compile, we need to restrict the generic type we're\naccepting:\n\n```\nuse std::fmt;\n\n// Restrict the input type to types that implement Debug.\nfn some_func<T: fmt::Debug>(foo: T) {\n    println!(\"{:?}\", foo);\n}\n\nfn main() {\n    // Calling the method is still fine, as i32 implements Debug.\n    some_func(5i32);\n\n    // This would fail to compile now:\n    // struct WithoutDebug;\n    // some_func(WithoutDebug);\n}\n```\n\nRust only looks at the signature of the called function, as such it must\nalready specify all requirements that will be used for every type parameter.\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":479,"byte_end":484,"line_start":19,"line_end":19,"column_start":24,"column_end":29,"is_primary":true,"text":[{"text":"    let res: i32 = try { 5 }; //~ ERROR the trait bound `i32: std::ops::Try` is not satisfied","highlight_start":24,"highlight_end":29}],"label":"the trait `std::ops::Try` is not implemented for `i32`","suggested_replacement":null,"suggestion_applicability":null,"expansion":{"span":{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":479,"byte_end":484,"line_start":19,"line_end":19,"column_start":24,"column_end":29,"is_primary":false,"text":[{"text":"    let res: i32 = try { 5 }; //~ ERROR the trait bound `i32: std::ops::Try` is not satisfied","highlight_start":24,"highlight_end":29}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null},"macro_decl_name":"desugaring of `try block`","def_site_span":{"file_name":"/checkout/src/test/ui/try-block/try-block-bad-type.rs","byte_start":479,"byte_end":484,"line_start":19,"line_end":19,"column_start":24,"column_end":29,"is_primary":false,"text":[{"text":"    let res: i32 = try { 5 }; //~ ERROR the trait bound `i32: std::ops::Try` is not satisfied","highlight_start":24,"highlight_end":29}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}}}],"children":[{"message":"required by `std::ops::Try::from_ok`","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error[E0277]: the trait bound `i32: std::ops::Try` is not satisfied\n  --> /checkout/src/test/ui/try-block/try-block-bad-type.rs:19:24\n   |\nLL |     let res: i32 = try { 5 }; //~ ERROR the trait bound `i32: std::ops::Try` is not satisfied\n   |                        ^^^^^ the trait `std::ops::Try` is not implemented for `i32`\n   |\n   = note: required by `std::ops::Try::from_ok`\n\n"}
[01:04:01] {"message":"aborting due to 5 previous errors","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to 5 previous errors\n\n"}
[01:04:01] {"message":"Some errors occurred: E0271, E0277.","code":null,"level":"","spans":[],"children":[],"rendered":"Some errors occurred: E0271, E0277.\n"}
[01:04:01] 
[01:04:01] ------------------------------------------
[01:04:01] 
[01:04:01] thread '[ui] ui/try-block/try-block-bad-type.rs' panicked at 'explicit panic', src/tools/compiletest/src/runtest.rs:3245:9
---
[01:04:01] 
[01:04:01] thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:495:22
[01:04:01] 
[01:04:01] 
[01:04:01] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-6.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "6.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[01:04:01] 
[01:04:01] 
[01:04:01] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:04:01] Build completed unsuccessfully in 0:04:07
[01:04:01] Build completed unsuccessfully in 0:04:07
[01:04:01] make: *** [check] Error 1
[01:04:01] Makefile:48: recipe for target 'check' failed
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:003155f5
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Fri Jan 11 00:06:02 UTC 2019
---
travis_time:end:01b4c68e:start=1547165164110832337,finish=1547165164117831544,duration=6999207
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:0adc2857
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:0371f7af
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@Centril Centril added the relnotes label Jan 11, 2019

@SimonSapin

This comment has been minimized.

Copy link
Contributor

SimonSapin commented Jan 11, 2019

Also, ./x.py test --test-args try-block/try-block-bad-type.rs succeeds on my machine, even after a rebase on master, while the same test fails on Travis :/

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jan 11, 2019

@SimonSapin hm something looks seriously wrong here! I wonder if this is a preexisting compiler bug you're running into. Can you reproduce the travis failure with ./src/ci/docker/run.sh x86_64-gnu-llvm-6.0?

@xfix

xfix approved these changes Jan 11, 2019

@SimonSapin

This comment has been minimized.

Copy link
Contributor

SimonSapin commented Jan 11, 2019

@alexcrichton Yes, that command on my machine gives the same output as on Travis.

@SimonSapin

This comment has been minimized.

Copy link
Contributor

SimonSapin commented Jan 12, 2019

If I tweak src/test/ui/try-block/try-block-bad-type.stderr to get past that error, I can get to the same error as #57475 (comment) in Docker (and presumably on Travis). But then it is ./x.py test on by Ubuntu 18.04 environment that fails try-block-bad-type.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jan 14, 2019

Sorry I don't really know what's going on here and what would cause that failure :(

It sounds like it may be a build configuration bug or maybe even a rustc bug, but I wouldn't know for sure without investigating.

Add signed num::NonZeroI* types
Multiple people have asked for them, in
#49137.
Given that the unsigned ones already exist,
they are very easy to add and not an additional maintenance burden.

@SimonSapin SimonSapin force-pushed the SimonSapin:signed branch from 1294e95 to 9be4c76 Jan 17, 2019

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jan 17, 2019

@bors: r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 17, 2019

📌 Commit 9be4c76 has been approved by alexcrichton

Centril added a commit to Centril/rust that referenced this pull request Jan 18, 2019

Rollup merge of rust-lang#57475 - SimonSapin:signed, r=alexcrichton
Add signed num::NonZeroI* types

Multiple people have asked for them in rust-lang#49137. Given that the unsigned ones already exist, they are very easy to add and not an additional maintenance burden.

bors added a commit that referenced this pull request Jan 18, 2019

Auto merge of #57727 - Centril:rollup, r=Centril
Rollup of 22 pull requests

Successful merges:

 - #56594 (Remove confusing comment about ideally using `!` for `c_void`)
 - #57107 (Add a regression test for mutating a non-mut #[thread_local])
 - #57340 (Use correct tracking issue for c_variadic)
 - #57357 (Cleanup PartialEq docs.)
 - #57370 (Support passing cflags/cxxflags/ldflags to LLVM build)
 - #57475 (Add signed num::NonZeroI* types)
 - #57501 (High priority resolutions for associated variants)
 - #57551 (resolve: Add a test for issue #57539)
 - #57610 (Fix nested `?` matchers)
 - #57634 (Remove an unused function argument)
 - #57635 (use structured macro and path resolve suggestions)
 - #57636 (Fix sources sidebar not showing up)
 - #57646 (Fixes text becoming invisible when element targetted)
 - #57649 (privacy: Account for associated existential types)
 - #57650 (librustc_metadata: Pass a default value when unwrapping a span)
 - #57654 (Add some links in std::fs.)
 - #57658 (Two HIR tweaks)
 - #57659 (Fix release manifest generation)
 - #57683 (Document Unpin in std::prelude documentation)
 - #57685 (Enhance `Pin` impl applicability for `PartialEq` and `PartialOrd`.)
 - #57698 (Fix typo bug in DepGraph::try_mark_green().)
 - #57720 (Fix suggestions given mulitple bad lifetimes)

Failed merges:

r? @ghost
@Centril

This comment has been minimized.

Copy link
Contributor

Centril commented Jan 18, 2019

Failed in rollup, #57727 (comment).

@bors r-

@SimonSapin

This comment has been minimized.

Copy link
Contributor

SimonSapin commented Jan 18, 2019

The set of impls printed (or at least their order) in the error[E0277] diagnostic varies between environments. The diff below would (likely) fix the mingw-check CI job like in #57727 (comment), but break x86_64-gnu-llvm-6.0 like in #57475 (comment).

Any idea what’s going on?

diff --git a/src/test/ui/try-block/try-block-bad-type.stderr b/src/test/ui/try-block/try-block-bad-type.stderr
index c2f9e9b52b..4e964f4b83 100644
--- a/src/test/ui/try-block/try-block-bad-type.stderr
+++ b/src/test/ui/try-block/try-block-bad-type.stderr
@@ -5,9 +5,9 @@ LL |         Err("")?; //~ ERROR the trait bound `i32: std::convert::From<&str>`
    |         ^^^^^^^^ the trait `std::convert::From<&str>` is not implemented for `i32`
    |
    = help: the following implementations were found:
-             <i32 as std::convert::From<core::num::NonZeroI32>>
+             <i32 as std::convert::From<bool>>
              <i32 as std::convert::From<i16>>
-             <i32 as std::convert::From<i8>>
+             <i32 as std::convert::From<u16>>
              <i32 as std::convert::From<u8>>
            and 2 others
    = note: required by `std::convert::From::from`
@rfcbot

This comment has been minimized.

Copy link

rfcbot commented Jan 20, 2019

The final comment period, with a disposition to merge, as per the review above, is now complete.

Fix some non-determinism in help messages for E0277 errors.
The diagnostic for this error prints `the following implementations
were found` followed by the first N relevant impls, sorted.

This commit makes the sort happen before slicing,
so that the set of impls being printed is deterministic
when the input is not.
@SimonSapin

This comment has been minimized.

Copy link
Contributor

SimonSapin commented Jan 21, 2019

I pushed a commit that I hope will fix this by removing some non-determinism.

@estebank, could you have a look? Can impl_candidates in report_similar_impl_candidates be very large? With this commit we’re doing some work (normalize and sort) on all of it, not just the first 4 or 5 impls.

@estebank

This comment has been minimized.

Copy link
Contributor

estebank commented Jan 21, 2019

@SimonSapin it is potentially huge, but in practice I would only imagine this being problematic in the case of generated code. But there are two things: 1) this is only relevant for failing code, so the cost only needs to be "human-speed", we're unlikely to hit problems there in any realistic scenario and 2) we might get away with changing fn all_impls(self, def_id: DefId) -> Vec<DefId> to return an Iterator. That wouldn't be a huge code change, nor performance change, but we're doing iter -> collect -> iter -> filter_map -> collect a few times on the same data :-|

I would go ahead with it, maybe adding a debug statement before and after to be able to check after the fact with a pathological case what the time is.

@SimonSapin

This comment has been minimized.

Copy link
Contributor

SimonSapin commented Jan 21, 2019

this is only relevant for failing code,

Good point. I think that means it’s probably not worth worrying about.

The other commits have already been reviewed (#57475 (comment)), could you r+ this?

@estebank

This comment has been minimized.

Copy link
Contributor

estebank commented Jan 21, 2019

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 21, 2019

📌 Commit e195ce6 has been approved by estebank

@xfix

This comment has been minimized.

Copy link
Contributor

xfix commented Jan 21, 2019

Sorting can be optimized by using a partial sorting algorithm, changing this from O(N log N) to O(N), but considering this is an error case, it's likely not worth doing.

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 22, 2019

⌛️ Testing commit e195ce6 with merge 8e9774f...

bors added a commit that referenced this pull request Jan 22, 2019

Auto merge of #57475 - SimonSapin:signed, r=estebank
Add signed num::NonZeroI* types

Multiple people have asked for them in #49137. Given that the unsigned ones already exist, they are very easy to add and not an additional maintenance burden.
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 22, 2019

☀️ Test successful - checks-travis, status-appveyor
Approved by: estebank
Pushing 8e9774f to master...

@bors bors merged commit e195ce6 into rust-lang:master Jan 22, 2019

1 check passed

homu Test successful
Details

@SimonSapin SimonSapin deleted the SimonSapin:signed branch Jan 22, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment