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

Turn extern crate and use into first-class items. #20179

Merged
merged 15 commits into from
Jan 22, 2015

Conversation

eddyb
Copy link
Member

@eddyb eddyb commented Dec 23, 2014

This implements an important part of RFC PR 385 (see #18219).

@rust-highfive
Copy link
Collaborator

r? @huonw

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

}
}
visit::walk_view_item(self, i);
}
Copy link
Member

Choose a reason for hiding this comment

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

These checks seem to have gone away with no replacement, was that intentional?

Copy link
Member Author

Choose a reason for hiding this comment

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

They're duplicated in the item checking path, though they use a slightly different error message.

@alexcrichton
Copy link
Member

Nice! I'll review the parser changes in more detail soon, but everything else looked pretty good to me (just one small nit). Some tests I'd like to see as well:

  • Mixing imports/items
  • Mixing imports/extern crate/items
  • Shadowing a previously declared item with an extern crate or import (just to see what happens)
  • Imports in the middle of a block expression

@eddyb eddyb assigned alexcrichton and unassigned huonw Dec 24, 2014
@eddyb eddyb force-pushed the blind-items branch 4 times, most recently from 9562473 to 2b978f0 Compare December 31, 2014 11:20
@eddyb
Copy link
Member Author

eddyb commented Dec 31, 2014

@alexcrichton r? this has had rustdoc fixed for a while - tests are still missing but @Kimundi has expressed interest in working on that while I deal with other things.

@alexcrichton
Copy link
Member

Can you update the description to not close #18219? The changes there are quite extensive and look like they go beyond just the changes made here.

@alexcrichton
Copy link
Member

I'm also pretty worried about allowing view items anywhere within blocks just yet. The RFC says that the original reason for the ordering restriction was due to the way shadowing was implemented (to make it more clear), but with shadowing now removed the semantics are clear not matter what order items are in.

I'm not sure this is true for blocks though:

let foo = 3;
use bar::foo;
println!("{}", foo); // what does this print?

I think that lifting the restriction for items are fine, but due to our allowance of shadowing with local variables, I don't think we should lift the restriction in expressions.

@alexcrichton
Copy link
Member

I also do not want to land this without any tests, new features like this really do need to be extensively tested so we don't have to hold up a release (for an otherwise backwards-compatible change) with another blocking issue while we fix a bug that may have been turned up with tests.

@eddyb
Copy link
Member Author

eddyb commented Jan 1, 2015

I think I would handle such ordering restrictions in resolve, since I expect that's where the proper logic will be -eventually- implemented.
Does that make sense, @alexcrichton?
cc @nikomatsakis

@Kimundi
Copy link
Member

Kimundi commented Jan 1, 2015

As far as I know, those ordering restrictions don't apply to items, as those are mutually recursive visible:

// In a block:

static FOO ... // visible before and after
use Bar ... // visible before and after
extern crate Baz ... // visible before and after
fn f() ... // visible before and after
let x ... // visible _after_

So, what a construct like let foo; use foo means in regard to shadowing depends on what items in those positions are supposed to mean in general, and is not specific to view items.

@eddyb
Copy link
Member Author

eddyb commented Jan 1, 2015

Ah, this causes the weird "only irrefutable patterns allowed here" error (can we stop matching constants in irrefutable patterns already?):

fn main() {
    let foo = 5u;
    const foo: uint = 42;
    println!("{}", foo);
}

And when that is not an issue, it seems that local bindings shadow items:

fn main() {
    let foo = || 5u;
    fn foo() -> uint { 42 }
    println!("{}", foo()); // prints 5
}

@alexcrichton
Copy link
Member

This is partly why I would like to be conservative here and lift the restriction at a later date. I don't want to allow rearranging items hoping for changes to resolve to land soon, I would rather land the two at the same time.

@Kimundi has a good point though that other items are already plagued by this unfortunate shadowing, so it may not be as dire as I think, but I'd prefer to stem the flow of awkward questions rather than pile more on.

@Kimundi
Copy link
Member

Kimundi commented Jan 2, 2015

I guess the forward compatible thing would be to either artificially keep the order restriction in blocks, or to make local bindings with the same name as an item in the same flat scope a hard error.


This is of course not the place to discuss those things, but I guess the only "sane" semantic for items in blocks in general is the current situation: items are visible everywhere in a scope, but locals, having the property of allowing forward-only shadowing of elements in the same scope, can shadow them.

Otherwise you get weird inconsistent semantic between those two entities:

  • items: shadowable with scope only, visible forward and backwards
  • locals: shadowable with scope and later locals, visible forward-only

@eddyb eddyb force-pushed the blind-items branch 2 times, most recently from cb84d38 to 210cb5d Compare January 13, 2015 09:06
@eddyb
Copy link
Member Author

eddyb commented Jan 13, 2015

@alexcrichton now that alpha's over, I've rebased this branch and added that error you requested, in the last commit. r?

@eddyb eddyb force-pushed the blind-items branch 4 times, most recently from 4000a49 to 9574724 Compare January 14, 2015 04:03
"compile time crate loading is \
experimental and possibly buggy");
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I think this may have snuck back in

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, indeed, a few of these were merged automatically during the rebase.

@alexcrichton
Copy link
Member

Alright, this all looks great to me, thanks @eddyb! This is a pretty big change though so I would like to bring it up at the next weekly meeting just to make sure everyone's comfortable with pulling the trigger.

@alexcrichton
Copy link
Member

@bors: retry

@bors
Copy link
Contributor

bors commented Jan 22, 2015

⌛ Testing commit 2d17a33 with merge 4a0ed0d...

@bors
Copy link
Contributor

bors commented Jan 22, 2015

💔 Test failed - auto-linux-64-nopt-t

@alexcrichton
Copy link
Member

@bors: retry

@bors
Copy link
Contributor

bors commented Jan 22, 2015

⌛ Testing commit 2d17a33 with merge 7f674df...

@bors
Copy link
Contributor

bors commented Jan 22, 2015

💔 Test failed - auto-linux-32-nopt-t

@alexcrichton
Copy link
Member

@bors: retry

@bors
Copy link
Contributor

bors commented Jan 22, 2015

⌛ Testing commit 2d17a33 with merge 1499596...

@bors
Copy link
Contributor

bors commented Jan 22, 2015

💔 Test failed - auto-linux-64-x-android-t

@alexcrichton
Copy link
Member

@bors: retry

@bors
Copy link
Contributor

bors commented Jan 22, 2015

⌛ Testing commit 2d17a33 with merge 4b417b8...

@bors
Copy link
Contributor

bors commented Jan 22, 2015

💔 Test failed - auto-linux-32-opt

@alexcrichton
Copy link
Member

@bors: retry

@bors bors merged commit 2d17a33 into rust-lang:master Jan 22, 2015
@eddyb eddyb deleted the blind-items branch January 22, 2015 09:16
@SimonSapin
Copy link
Contributor

Does this fix #18810 ?

SimonSapin added a commit to SimonSapin/servo that referenced this pull request May 22, 2015
bors-servo pushed a commit to servo/servo that referenced this pull request May 22, 2015
rust-lang/rust#20179 makes its use case much weaker.

r? @Manishearth

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6159)
<!-- Reviewable:end -->
jrmuizel pushed a commit to jrmuizel/gecko-cinnabar that referenced this pull request Jun 12, 2017
…om SimonSapin:no_mod_path); r=Manishearth

rust-lang/rust#20179 makes its use case much weaker.

r? @Manishearth

Source-Repo: https://github.com/servo/servo
Source-Revision: e04d9c32a98ff4673f413ed17f66e7466e2ff974
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Sep 30, 2019
…om SimonSapin:no_mod_path); r=Manishearth

rust-lang/rust#20179 makes its use case much weaker.

r? Manishearth

Source-Repo: https://github.com/servo/servo
Source-Revision: e04d9c32a98ff4673f413ed17f66e7466e2ff974

UltraBlame original commit: 81933413281cee300e35174beae0d9bf87083c71
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Oct 1, 2019
…om SimonSapin:no_mod_path); r=Manishearth

rust-lang/rust#20179 makes its use case much weaker.

r? Manishearth

Source-Repo: https://github.com/servo/servo
Source-Revision: e04d9c32a98ff4673f413ed17f66e7466e2ff974

UltraBlame original commit: 81933413281cee300e35174beae0d9bf87083c71
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Oct 1, 2019
…om SimonSapin:no_mod_path); r=Manishearth

rust-lang/rust#20179 makes its use case much weaker.

r? Manishearth

Source-Repo: https://github.com/servo/servo
Source-Revision: e04d9c32a98ff4673f413ed17f66e7466e2ff974

UltraBlame original commit: 81933413281cee300e35174beae0d9bf87083c71
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants