Skip to content

Add test checking that Index<T: ?Sized> works - #59527

Merged
bors merged 1 commit into
rust-lang:masterfrom
matklad:sized-index
Apr 17, 2019
Merged

Add test checking that Index<T: ?Sized> works#59527
bors merged 1 commit into
rust-lang:masterfrom
matklad:sized-index

Conversation

@matklad

@matkladmatklad commented Mar 29, 2019

Copy link
Copy Markdown
Contributor

I've noticed that we have an Idx: ?Sized bound on the index in the Index, which seems strange given that we accept index by value. My guess is that it was meant to be removed in #23601, but was overlooked.

If I remove this bound, ./x.py src/libstd/ src/libcore/ passes, which means at least that this is not covered by test.

I think there's three things we can do here:

  • run crater with the bound removed to check if there are any regressions, and merge this, to be consistent with other operator traits
  • run crater, get regressions, write a test for this with a note that "hey, we tried to fix it, its unfixable"
  • decide, in the light of by-value DSTs, that this is a feature rather than a bug, and add a test

cc @rust-lang/libs

EDIT: the forth alternative is that there exist a genuine reason why this is the case, but I failed to see it :D

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @joshtriplett

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

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 29, 2019
@CentrilCentril added T-lang Relevant to the language team T-libs-api [DEPRECATED; DO NOT USE] needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. labels Mar 29, 2019
@Centril

Copy link
Copy Markdown
Contributor

So this was not the PR I expected.

My guess is that it was meant to be removed in #23601, but was overlooked.

Perhaps. But if so, this is to me a happy accident.

run crater with the bound removed to check if there are any regressions, and merge this, to be consistent with other operator traits

I don't mind running crater, but I would not want to remove the bound when unsized_locals isn't stable and because its a future-compat hazard. Consistency is not a sufficient justification for that imo even if you find zero regressions.

decide, in the light of by-value DSTs, that this is a feature rather than a bug, and add a test

We can add a test now and later remove it if we change our minds.

@Centril

Copy link
Copy Markdown
Contributor

@bors try

@bors

bors commented Mar 29, 2019

Copy link
Copy Markdown
Collaborator

⌛ Trying commit a6b130e with merge 47f4f94...

bors added a commit that referenced this pull request Mar 29, 2019
remove ?Sized bounds from Index
I've noticed that we have an `Idx: ?Sized` bound on the **index** in the `Index`, which seems strange given that we accept index by value. My guess is that it was meant to be removed in #23601, but was overlooked.
If I remove this bound, `./x.py src/libstd/ src/libcore/` passes, which means at least that this is not covered by test.
I think there's three things we can do here:
* run crater with the bound removed to check if there are any regressions, and merge this, to be consistent with other operator traits
* run crater, get regressions, write a test for this with a note that "hey, we tried to fix it, its unfixable"
* decide, in the light of by-value DSTs, that this is a feature rather than a bug, and add a test
cc @rust-lang/libs
EDIT: the forth alternative is that there exist a genuine reason why this is the case, but I failed to see it :D
@bors

bors commented Mar 29, 2019

Copy link
Copy Markdown
Collaborator

☀️ Try build successful - checks-travis
Build commit: 47f4f94

@Centril

Copy link
Copy Markdown
Contributor

@craterbot run mode=check-only

@craterbot

Copy link
Copy Markdown
Collaborator

👌 Experiment pr-59527 created and queued.
🤖 Automatically detected try build 47f4f94
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbotcraterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 29, 2019
@craterbot

Copy link
Copy Markdown
Collaborator

🚧 Experiment pr-59527 is now running on agent aws-3-tmp.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@sfackler

Copy link
Copy Markdown
Member

What concrete problem is this solving, exactly? It's not clear to me why we should invest crater/person time on removing this bound.

@Centril

Copy link
Copy Markdown
Contributor

@matklad

Copy link
Copy Markdown
ContributorAuthor

@sfackler I agree that this is basically a non-issue, except for the mere fact that we have a random untested bound in std’s public API.

@craterbot

Copy link
Copy Markdown
Collaborator

🎉 Experiment pr-59527 is completed!
📊 0 regressed and 0 fixed (50551 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the blacklist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbotcraterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Mar 30, 2019
@Dylan-DPC-zz

Copy link
Copy Markdown

ping from triage @joshtriplett any updates?

@joshtriplett

Copy link
Copy Markdown
Member

r? @Centril

Can you please review the crater results and evaluate this?

@Centril

Copy link
Copy Markdown
Contributor

The crater results are clean so nothing would break as far as I can see (assuming that crater is representative).

However, I'm inclined to say that there is nothing notable to be gained by removing ?Sized here.
So imo let's treat this as a happy accident and add a test.

@matklad Can you add such a test? I'm happy to r+ the PR in that state.

@CentrilCentril removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-lang Relevant to the language team T-libs-api [DEPRECATED; DO NOT USE] labels Apr 8, 2019
@CentrilCentril added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Apr 8, 2019
@dtolnay

Copy link
Copy Markdown
Member

Adding back ?Sized later if necessary is guaranteed entirely backward compatible right? Is there code that could be broken by that?

@Centril

Copy link
Copy Markdown
Contributor

Not sure; it might have consequences wrt. implied bounds later on... but I would prefer not to take the risk since there's not much value in doing the change.

@pnkfelix

pnkfelix commented Apr 12, 2019

Copy link
Copy Markdown
Contributor

@Centril to be clear, was the PR you were expecting something that added a test that looks along these lines (play):

#![feature(unsized_locals)]use std::ops::Index;traitTrait{fnvalue(&self) -> usize;}structDrStrange(Vec<i32>);implIndex<Trait>forDrStrange{typeOutput = i32;fnindex(&self,index:Trait) -> &i32{&self.0[index.value()]}}implTraitforusize{fnvalue(&self) -> usize{*self}}fnmain(){let stephen = DrStrange(vec![1,2,3]);// ???? pnkfelix doesn't know offhand how to write// an input to fill into `stephen[...]`.}

Update: Ah, @Centril had an example of how to use the index operator on the linked internals post.

@pnkfelix

Copy link
Copy Markdown
Contributor

(If you leave off #![feature(unsized_locals)], you get an error at the trait definition site, that looks like this:

error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time
--> src/main.rs:12:21
|
12 | fn index(&self, index: Trait) -> &i32 {
| ^^^^^ doesn't have a size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `(dyn Trait + 'static)`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: all local variables must have a statically known size
= help: unsized locals are gated as an unstable feature

I'm assuming that the feedback one gets when the : ?Sized anti-bound removed isn't amazingly better than that. If it is much better than the above, that could be a reason to consider landing this PR as is.)

@Centril

Centril commented Apr 12, 2019

Copy link
Copy Markdown
Contributor

@pnkfelix I would be happy with just:

#![feature(unsized_locals)]use std::ops::Index;pubstructA;implIndex<str>forA{typeOutput = ();fnindex(&self, _:str) -> &Self::Output{panic!()}}fnmain(){}

In other words, testing the static semantics is good enough.

@matklad

Copy link
Copy Markdown
ContributorAuthor

Added the test!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move the test to test/ui/... and add // compile-pass to the top of the file;

Otherwise, r=me with green travis.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

@CentrilCentrilApr 17, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file ended up in /test/ui/... instead of /src/test/ui/... :D Aim for https://github.com/rust-lang/rust/tree/master/src/test/ui/unsized-locals

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That explains why I had to use -f to add it. Should be better now

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah; the rebase went wrong tho :P

@matklad
matkladforce-pushed the sized-index branch 4 times, most recently from f9dd09b to 12e921fCompareApril 17, 2019 10:36
@rust-highfive

Copy link
Copy Markdown
Contributor

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:030ad52c:start=1555497453158385892,finish=1555497453911678869,duration=753292977
$ 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
$ export GCP_CACHE_BUCKET=rust-lang-ci-cache
$ export AWS_ACCESS_KEY_ID=AKIA46X5W6CZEJZ6XT55
---
[01:16:55] failures:
[01:16:55] [01:16:55] ---- [run-pass] run-pass/unsized-locals/unsized-index.rs stdout ----
[01:16:55] [01:16:55] error: test compilation failed although it shouldn't!
[01:16:55] status: exit code: 1
[01:16:55] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/run-pass/unsized-locals/unsized-index.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/unsized-locals/unsized-index/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/unsized-locals/unsized-index/auxiliary"
[01:16:55] ------------------------------------------
[01:16:55] [01:16:55] ------------------------------------------
[01:16:55] stderr:
[01:16:55] stderr:
[01:16:55] ------------------------------------------
[01:16:55] {"message":"method `index` is not a member of trait `ops::IndexMut`","code":{"code":"E0407","explanation":"\nA definition of a method not in the implemented trait was given in a trait\nimplementation.\n\nErroneous code example:\n\n```compile_fail,E0407\ntrait Foo {\n fn a();\n}\n\nstruct Bar;\n\nimpl Foo for Bar {\n fn a() {}\n fn b() {} // error: method `b` is not a member of trait `Foo`\n}\n```\n\nPlease verify you didn't misspell the method name and you used the correct\ntrait. First example:\n\n```\ntrait Foo {\n fn a();\n fn b();\n}\n\nstruct Bar;\n\nimpl Foo for Bar {\n fn a() {}\n fn b() {} // ok!\n}\n```\n\nSecond example:\n\n```\ntrait Foo {\n fn a();\n}\n\nstruct Bar;\n\nimpl Foo for Bar {\n fn a() {}\n}\n\nimpl Bar {\n fn b() {}\n}\n```\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/run-pass/unsized-locals/unsized-index.rs","byte_start":567,"byte_end":620,"line_start":18,"line_end":18,"column_start":5,"column_end":58,"is_primary":true,"text":[{"text":" fn index(&self, _: str) -> &Self::Output { panic!() }","highlight_start":5,"highlight_end":58}],"label":"not a member of trait `ops::IndexMut`","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"error[E0407]: method `index` is not a member of trait `ops::IndexMut`\n --> /checkout/src/test/run-pass/unsized-locals/unsized-index.rs:18:5\n |\nLL | fn index(&self, _: str) -> &Self::Output { panic!() }\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a member of trait `ops::IndexMut`\n\n"}
[01:16:55] {"message":"not all trait items implemented, missing: `index_mut`","code":{"code":"E0046","explanation":"\nItems are missing in a trait implementation. Erroneous code example:\n\n```compile_fail,E0046\ntrait Foo {\n fn foo();\n}\n\nstruct Bar;\n\nimpl Foo for Bar {}\n// error: not all trait items implemented, missing: `foo`\n```\n\nWhen trying to make some type implement a trait `Foo`, you must, at minimum,\nprovide implementations for all of `Foo`'s required methods (meaning the\nmethods that do not have default implementations), as well as any required\ntrait items like associated types or constants. Example:\n\n```\ntrait Foo {\n fn foo();\n}\n\nstruct Bar;\n\nimpl Foo for Bar {\n fn foo() {} // ok!\n}\n```\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/run-pass/unsized-locals/unsized-index.rs","byte_start":531,"byte_end":560,"line_start":17,"line_end":17,"column_start":1,"column_end":30,"is_primary":true,"text":[{"text":"impl ops::IndexMut<str> for A {","highlight_start":1,"highlight_end":30}],"label":"missing `index_mut` in implementation","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"`index_mut` from trait: `fn(&mut Self, Idx) -> &mut <Self as std::ops::Index<Idx>>::Output`","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"error[E0046]: not all trait items implemented, missing: `index_mut`\n --> /checkout/src/test/run-pass/unsized-locals/unsized-index.rs:17:1\n |\nLL | impl ops::IndexMut<str> for A {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `index_mut` in implementation\n |\n = note: `index_mut` from trait: `fn(&mut Self, Idx) -> &mut <Self as std::ops::Index<Idx>>::Output`\n\n"}
[01:16:55] {"message":"aborting due to 2 previous errors","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to 2 previous errors\n\n"}
[01:16:55] {"message":"Some errors occurred: E0046, E0407.","code":null,"level":"","spans":[],"children":[],"rendered":"Some errors occurred: E0046, E0407.\n"}
[01:16:55] [01:16:55] ------------------------------------------
[01:16:55] [01:16:55] ---
[01:16:55] thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:517:22
[01:16:55] note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
[01:16:55] [01:16:55] [01:16:55] 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/run-pass" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "run-pass" "--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:16:55] [01:16:55] [01:16:55] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:16:55] Build completed unsuccessfully in 0:11:28
[01:16:55] Build completed unsuccessfully in 0:11:28
[01:16:55] make: *** [check] Error 1
[01:16:55] Makefile:48: recipe for target 'check' failed
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:0117c30a
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Wed Apr 17 11:54:39 UTC 2019
---
travis_time:end:016dd705:start=1555502081392724865,finish=1555502081397698946,duration=4974081
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:1ad25719
$ 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:26b06c1d
travis_time:start:26b06c1d
$ 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:0429ef82
$ 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

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@bors

bors commented Apr 17, 2019

Copy link
Copy Markdown
Collaborator

📌 Commit cc3abc4 has been approved by Centril

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 17, 2019
@jethrogb

Copy link
Copy Markdown
Contributor

Please rename the PR?

@matkladmatklad changed the title remove ?Sized bounds from IndexAdd test for ?Sized bound in ops::Index and ops::IndexMutApr 17, 2019
@CentrilCentril changed the title Add test for ?Sized bound in ops::Index and ops::IndexMutAdd test checking that Index<T: ?Sized> worksApr 17, 2019
bors added a commit that referenced this pull request Apr 17, 2019
Add test checking that Index<T: ?Sized> works
I've noticed that we have an `Idx: ?Sized` bound on the **index** in the `Index`, which seems strange given that we accept index by value. My guess is that it was meant to be removed in #23601, but was overlooked.
If I remove this bound, `./x.py src/libstd/ src/libcore/` passes, which means at least that this is not covered by test.
I think there's three things we can do here:
* run crater with the bound removed to check if there are any regressions, and merge this, to be consistent with other operator traits
* run crater, get regressions, write a test for this with a note that "hey, we tried to fix it, its unfixable"
* decide, in the light of by-value DSTs, that this is a feature rather than a bug, and add a test
cc @rust-lang/libs
EDIT: the forth alternative is that there exist a genuine reason why this is the case, but I failed to see it :D
@bors

bors commented Apr 17, 2019

Copy link
Copy Markdown
Collaborator

⌛ Testing commit cc3abc4 with merge 3c3d3c1...

@bors

bors commented Apr 17, 2019

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-travis, status-appveyor
Approved by: Centril
Pushing 3c3d3c1 to master...

@borsbors added the merged-by-bors This PR was explicitly merged by bors. label Apr 17, 2019
@bors
bors merged commit cc3abc4 into rust-lang:masterApr 17, 2019
@matklad
matklad deleted the sized-index branch July 9, 2019 12:33
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-borsThis PR was explicitly merged by bors.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

11 participants

@matklad@rust-highfive@Centril@bors@craterbot@sfackler@Dylan-DPC-zz@joshtriplett@dtolnay@pnkfelix@jethrogb