Skip to content
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

Allow crate:: in local paths #50131

Merged
merged 1 commit into from
Apr 26, 2018
Merged

Conversation

Manishearth
Copy link
Member

Currently if you want to use crate locally you have to do ::crate::. This shouldn't be necessary

(will fix up tests later)

r? @petrochenkov

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 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.
[00:57:16] ....i...............................................................................................
[00:57:24] ........i..ii.......................................................................................
[00:57:34] ....................................................................................................
[00:57:43] ....................................................................................................
[00:57:52] ..........................................................................i...F.FF..................
[00:58:13] ....................................................................................................
[00:58:22] ....................................................................................................
mpile-fail] compile-fail/rfc-2126-crate-paths/crate-visibility-ambiguity.rs stdout ----
[00:58:33]  
[00:58:33]  
[00:58:33] error: compile-fail test compiled successfully!
[00:58:33] status: exit code: 0
[00:58:33] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/compile-fail/rfc-2126-crate-paths/crate-visibility-ambiguity.rs" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail/rfc-2126-crate-paths/crate-visibility-ambiguity.stage2-x86_64-unknown-linux-gnu" "-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/compile-fail/rfc-2126-crate-paths/crate-visibility-ambiguity.stage2-x86_64-unknown-linux-gnu.aux" "-A" "unused"
[00:58:33] ------------------------------------------
[00:58:33] 
[00:58:33] ------------------------------------------
[00:58:33] stderr:
[00:58:33] stderr:
[00:58:33] ------------------------------------------
[00:58:33] 
[00:58:33] ------------------------------------------
[00:58:33] 
[00:58:33] thread '[compile-fail] compile-fail/rfc-2126-crate-paths/crate-visibility-ambiguity.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:2938:9
[00:58:33] ---- [compile-fail] compile-fail/rfc-2126-crate-paths/keyword-crate-as-identifier.rs stdout ----
[00:58:33]  
[00:58:33]  
[00:58:33] error: /checkout/src/test/compile-fail/rfc-2126-crate-paths/keyword-crate-as-identifier.rs:14: unexpected error: '14:9: 14:14: expected unit struct/variant or constant, found module `crate` [E0532]'
[00:58:33] 
[00:58:33] error: /checkout/src/test/compile-fail/rfc-2126-crate-paths/keyword-crate-as-identifier.rs:14: expected error not found: `crate` can only be used in absolute paths
[00:58:33] 
[00:58:33] error: 1 unexpected errors found, 1 expected errors not found
[00:58:33] status: exit code: 101
[00:58:33] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/compile-fail/rfc-2126-crate-paths/keyword-crate-as-identifier.rs" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail/rfc-2126-crate-paths/keyword-crate-as-identifier.stage2-x86_64-unknown-linux-gnu" "-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/compile-fail/rfc-2126-crate-paths/keyword-crate-as-identifier.stage2-x86_64-unknown-linux-gnu.aux" "-A" "unused"
[00:58:33] unexpected errors (from JSON output): [
[00:58:33]     Error {
[00:58:33]         line_num: 14,
[00:58:33]         kind: Some(
[00:58:33]             Error
[00:58:33]         ),
[00:58:33]         msg: "14:9: 14:14: expected unit struct/variant or constant, found module `crate` [E0532]"
[00:58:33] ]
[00:58:33] 
[00:58:33] not found errors (from test file): [
[00:58:33]     Error {

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)

@pietroalbini pietroalbini added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 21, 2018
@petrochenkov
Copy link
Contributor

The ::crate:: form is in line with the model from RFC 2126 (#44660), but crate:: fits better into the updated model from https://internals.rust-lang.org/t/the-great-module-adventure-continues/6678/183, so I agree with this change.
We may want to remove the ::crate:: form later.

r=me with tests updated

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 21, 2018
@Manishearth
Copy link
Member Author

Manishearth commented Apr 21, 2018 via email

@Manishearth
Copy link
Member Author

Ahh, I see why we didn't compile this previously.

The problem is within struct fields. struct S(crate::Foo) can mean struct S(crate (::Foo)) (where crate is a visibility modifier), or it can mean struct S(crate::Foo), the crate-relative path.

So we can fix this everywhere except in tuple struct fields. Gah. Parsing.

@aturon @cramertj if we still want to fix this, how should we address that ambiguity? Always parse it as a path? ::Foo will be linted anyway, however we expect both crate::Foo and crate-the-visibility to work on Rust 2015, yes? This isn't a problem on Rust 2018 since ::Foo no longer exists (though we still need to ensure we parse this right, the check for ::Foo will be in librustc_resolve).

@petrochenkov
Copy link
Contributor

@Manishearth
The ambiguity is not the reason why ::crate existed, it's also not a problem of any noticeable importance.

It can be trivially resolved by always parsing crate::Foo greedily as a path as it's done in any other context. Moreover, It's already resolved because the path is already parsed greedily, so everything that needs to be done is a test update.

} else if i == 0 && name == keywords::Crate.name() {
format!("{} can only be used in absolute paths", name_str)
} else if name == keywords::Crate.name() && path.len() == 1 {
"`crate` in paths must be followed by a module name".into()
Copy link
Contributor

@petrochenkov petrochenkov Apr 21, 2018

Choose a reason for hiding this comment

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

crate can be used as a single segment path with the meaning "root module", e.g. in use crate as something.
If this line is removed then keyword-crate-as-identifier.rs should report a correct error, something like "expected a unit struct or constand, found module".

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah. It was, but I thought that was a bug. Will fix.

@Manishearth Manishearth force-pushed the crate-in-local branch 4 times, most recently from fd00a97 to 27f5f56 Compare April 21, 2018 17:59
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 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.
[00:55:17] ....i...............................................................................................
[00:55:26] ........i..ii.......................................................................................
[00:55:35] ....................................................................................................
[00:55:44] ....................................................................................................
[00:55:53] ..........................................................................i...FF....................
[00:56:13] ....................................................................................................
[00:56:22] ....................................................................................................
[00:56:32] ....................................................................................................
[00:56:33] ..........
[00:56:33] ..........
[00:56:33] failures:
[00:56:33] 
[00:56:33] ---- [compile-fail] compile-fail/rfc-2126-crate-paths/crate-path-non-absolute.rs stdout ----
[00:56:33]  
[00:56:33] error: /checkout/src/test/compile-fail/rfc-2126-crate-paths/crate-path-non-absolute.rs:17: unexpected error: '17:22: 17:27: failed to resolve. Could not find `crate` in `m` [E0433]'
[00:56:33] 
[00:56:33] error: /checkout/src/test/compile-fail/rfc-2126-crate-paths/crate-path-non-absolute.rs:17: expected error not found: `expected unit struct/variant or
[00:56:33] 
[00:56:33] error: 1 unexpected errors found, 1 expected errors not found
[00:56:33] status: exit code: 101
[00:56:33] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/compile-fail/rfc-2126-crate-paths/crate-path-non-absolute.rs" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail/rfc-2126-crate-paths/crate-path-non-absolute.stage2-x86_64-unknown-linux-gnu" "-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/compile-fail/rfc-2126-crate-paths/crate-path-non-absolute.stage2-x86_64-unknown-linux-gnu.aux" "-A" "unused"
[00:56:33] unexpected errors (from JSON output): [
[00:56:33]     Error {
[00:56:33]         line_num: 17,
[0nored; 0 measured; 0 filtered out
[00:56:33] thread 'main' panicked at 'Some tests failed', tools/compiletest/src/main.rs:488:22
[00:56:33] 
[00:56:33] 
[00:56:33] 
[00:56:33] 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/compile-fail" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "compile-fail" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-3.9/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zunstable-options " "--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" "3.9.1\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[00:56:33] 
[00:56:33] 
[00:56:33] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[00:56:33] Build completed unsuccessfully in 0:17:16
[00:56:33] Build completed unsuccessfully in 0:17:16
[00:56:33] Makefile:58: recipe for targ./obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/incremental
110124 ./obj/build/x86_64-unknown-linux-gnu/stage0-tools/x86_64-unknown-linux-gnu/release
106224 ./obj/build/x86_64-unknown-linux-gnu/stage0-tools/x86_64-unknown-linux-gnu/release/deps
102812 ./obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends
101920 ./obj/build/bootstrap/debug/incremental/bootstrap-2s8ik7x786gic
101920 ./obj/build/bootstrap/debug/incremental/bootstrap-2s8ik7x786gic
101916 ./obj/build/bootstrap/debug/incremental/bootstrap-2s8ik7x786gic/s-f0byc8cf6f-1ninjgh-rdc42ohq9o1k
89236 ./obj/build/x86_64-unknown-linux-gnu/stage1
89212 ./obj/build/x86_64-unknown-linux-gnu/stage1/lib
87792 ./obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/incremental/core-31lccp6wy7orz
87792 ./obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/incremental/core-31lccp6wy7orz
87788 ./obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/incremental/core-31lccp6wy7orz/s-f0by9yos2t-mtfkkj-es32axngf1gk
84832 ./obj/build/x86_64-unknown-linux-gnu/stage1-rustc/x86_64-unknown-linux-gnu/release/deps
80872 ./obj/build/x86_64-unknown-linux-gnu/doc/std
78756 ./obj/build/x86_64-unknown-linux-gnu/stage0-tools/release
78580 ./obj/build/x86_64-unknown-linux-gnu/stage0-sysroot
---
56092 ./obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/bin
55348 ./obj/build/x86_64-unknown-linux-gnu/stage0-rustc/release
53568 ./obj/build/x86_64-unknown-linux-gnu/stage0-rustc/release/build
51920 ./obj/build/x86_64-unknown-linux-gnu/stage1-rustc/x86_64-unknown-linux-gnu/release/incremental/syntax-33oa6nnkk1g08
51916 ./obj/build/x86_64-unknown-linux-gnu/stage1-rustc/x86_64-unknown-linux-gnu/release/incremental/syntax-33oa6nnkk1g08/s-f0bybij43g-w1cmoj-133inn86rvydz
47832 ./obj/build/x86_64-unknown-linux-gnu/stage0-std
46660 ./obj/build/x86_64-unknown-linux-gnu/stage0-std/release
46656 ./obj/build/x86_64-unknown-linux-gnu/stage1-std/release
46652 ./src/test

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)

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 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.
[00:55:41] ....i....................................................................................test [run-pass] run-pass/mir_heavy_promoted.rs has been running for over 60 seconds
[00:55:47] ...........
[00:56:19] ....................................................................................................
[00:56:49] ......................................................................ii............................
[00:57:42] .................................i....................................................i.ii.....test [run-pass] run-pass/saturating-float-casts.rs has been running for over 60 seconds
[00:58:26] ..............................................................................................iiiiii
[00:58:54] i...................................................................................................
[00:59:24] ....................................................................................................
[00:59:50] ....................................................................................................
---
[01:02:09] ....i...............................................................................................
[01:02:18] ........i..ii.......................................................................................
[01:02:28] ....................................................................................................
[01:02:37] ....................................................................................................
[01:02:47] ..........................................................................i....F....................
[01:03:08] ....................................................................................................
[01:03:18] ....................................................................................................
[01:03:18] ....................................................................................................
/checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "compile-fail" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-3.9/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zunstable-options " "--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" "3.9.1\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:03:29] 
[01:03:29] 
[01:03:29] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:03:29] Build completed unsuccessfully in 0:18:35
[01:03:29] Build completed unsuccessfully in 0:18:35
[01:03:29] Makefile:58: recipe for target 'check' failed
[01:03:29] make: *** [check] Error 1
2747292 ./obj
2747260 ./obj/build
1988000 ./obj/build/x86_64-unknown-linux-gnu
721996 ./src
---
149112 ./src/llvm-emscripten/test
148324 ./.git/modules
148320 ./.git/modules/src
122700 ./obj/build/bootstrap/debug/incremental/bootstrap-1sil8jgb030ka
122696 ./obj/build/bootstrap/debug/incremental/bootstrap-1sil8jgb030ka/s-f0c8kaon6x-oa8ygl-2ud7sffvl82ye

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)

@Manishearth
Copy link
Member Author

We should be doing the same for extern_crate::foo::bar in local paths. Updated.

@Manishearth
Copy link
Member Author

(I can split that out into a second PR if you r+ the first commit. I'll be fixing the tests for the second commit on Monday)

@Manishearth
Copy link
Member Author

Oh, sorry, that's fixed by #49789

@aturon
Copy link
Member

aturon commented Apr 25, 2018

@bors: p=1

We want to get the edition-related changes landed ASAP.


fn main() {
crate struct S; // OK (item in statement position)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you keep this test in some compile-pass/run-pass form?

@petrochenkov
Copy link
Contributor

r=me after restoring the test and probably reverting the unintended (?) stdsimd submodule update

@Manishearth
Copy link
Member Author

@bors r=petrochenkov

@bors
Copy link
Contributor

bors commented Apr 25, 2018

📌 Commit 9f5e08e has been approved by petrochenkov

@bors bors 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 25, 2018
@bors
Copy link
Contributor

bors commented Apr 25, 2018

⌛ Testing commit 9f5e08e with merge 84ce67e...

bors added a commit that referenced this pull request Apr 25, 2018
Allow crate:: in local paths

Currently if you want to use `crate` locally you have to do `::crate::`. This shouldn't be necessary

(will fix up tests later)

r? @petrochenkov
@bors
Copy link
Contributor

bors commented Apr 26, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: petrochenkov
Pushing 84ce67e to master...

@bors bors merged commit 9f5e08e into rust-lang:master Apr 26, 2018
@Manishearth Manishearth deleted the crate-in-local branch April 26, 2018 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: 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.

6 participants