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

more useful rustpkg init #10651

Closed
wants to merge 1 commit into from
Closed

more useful rustpkg init #10651

wants to merge 1 commit into from

Conversation

minhnhdo
Copy link
Contributor

This PR modifies the behavior of rustpkg init.

rustpkg init now accepts two more arguments, the first is the type of package to initialize (bin or lib), and the second is the package name. Instead of initializing a workspace in the current directory, rustpkg init now initializes a workspace under the directory with the same name as the supplied package name. In addition, it also creates some default crates (i.e. lib.rs or main.rs) under src/<package-name>/.

E.g. rustpkg init lib awesome_lib will create the following directory tree in the current directory.

awesome_lib/ 
 - bin/
 - build/
 - lib/
 - src/
    - awesome_lib/
       - lib.rs

The content of lib.rs is the following.

pub fn get_answer() -> int {
    42
}

EDIT: test.rs is no longer generated.

@huonw
Copy link
Member

huonw commented Nov 25, 2013

FWIW, mod lib; in test.rs will not be correct in the common case, it would require writing all use statements in the package as relative statements since the crate root goes up one level when testing.

@huonw
Copy link
Member

huonw commented Nov 25, 2013

(Also, how rustpkg runs tests is still undecided (#9003), so I think it'd be better to not "promote" the current sub-par situation by having it generated by default.)

@minhnhdo
Copy link
Contributor Author

@huonw could you please elaborate the testing behaviour or point me to some materials on it? I'm asking because with that layout, I can still run rustpkg test awesome_lib inside awesome_lib/.

@huonw
Copy link
Member

huonw commented Nov 25, 2013

@mrordinaire I don't know any more than listed on #9003, but, an example:

lib.rs:

use foo::useful;

pub mod foo;

pub fn more_useful() { useful() }

foo.rs

pub fn useful() {}

test.rs

mod lib;

The mod lib will mean that the use foo::useful line is invalid (since there is no foo in test.rs, which the root of the crate) and so compiling test will fail.


So what I'm saying is we shouldn't be dictating a testing structure until #9003 is solved, i.e. don't create a default test.rs.

@klutzy
Copy link
Contributor

klutzy commented Nov 25, 2013

I've thought the bin/build/lib directories are for workspaces, not for source directories (aka git repos).
Similarly, I think lib.rs doesn't need to be inside awesome_lib/. librustpkg/testsuite/pass/src/ contains some sample "repos", and some repos (e.g. hello-world and fancy-lib) doesn't have recursive directory structure.
That being said, I don't know what is "standard" way to organize source directory. I'm just guessing now.

@huonw
Copy link
Member

huonw commented Nov 25, 2013

@klutzy isn't the point of rustpkg init to create a workspace (and in this case, it's being extended to automatically add a one default package to the workspace)?

@klutzy
Copy link
Contributor

klutzy commented Nov 25, 2013

@huonw Ah right, I was wrong.

@metajack
Copy link
Contributor

I'm -1 on this patch as is.

  1. rustpkg init is supposed to create a workspace. For example, you'd use this to create a place to work on some collection of rust packages like Servo. rustpkg init and then rustpkg install github.com/mozilla/servo
  2. A better name for something that created a package scaffolding is rustpkg new PKGID which would create just the package dir and not a workspace.
  3. Many other similar tools add a test as well, but this test is bad because it will start failing as soon as you make any change to the package. Whatever test is added to the scaffolding should always pass (or always fail I suppose depending on your point of view).

@minhnhdo
Copy link
Contributor Author

@huonw Thank you for the clarification. I tried it and it really didn't work.
@metajack if this PR reverts to only creating a package directory, to the user, the amount of typing wouldn't be justified by the handicapped capability (rustpkg new PKGID versus mkdir PKGID). test.rs is added in order to encourage writing tests by means of examples. When the test fails because of modifications or by default, the user can always delete the file or comment out the test. Thus, by adding test.rs, we risk confusing the new user at first in exchange for better engineering practices in the community. This, I think, is worthwhile.

@alexcrichton
Copy link
Member

Closing this temporarily in an attempt to un-stick bors.

@alexcrichton
Copy link
Member

Hm, it appears that bors does not like this pull request, would you mind reopening again? Bors normally has no problems with fresh pull requests.

@minhnhdo
Copy link
Contributor Author

minhnhdo commented Dec 2, 2013

@alexcrichton done. The new PR is now #10760

@alexcrichton
Copy link
Member

Sorry about that, but thanks!

flip1995 pushed a commit to flip1995/rust that referenced this pull request Apr 23, 2023
Add size-parameter to unecessary_box_returns

Fixes rust-lang#10641

This adds a configuration-knob to the `unecessary_box_returns`-lint which allows _not_ linting a `fn() -> Box<T>` if `T` is "large". The default byte size above which we no longer lint is 128 bytes (due to rust-lang/rust-clippy#4652 (comment), also used in rust-lang#9373). The overall rational is given in rust-lang#10641.

---

changelog: Enhancement: [`unnecessary_box_returns`]: Added new lint configuration `unnecessary-box-size` to set the maximum size of `T` in `Box<T>` to be linted
[rust-lang#10651](rust-lang/rust-clippy#10651)
<!-- changelog_checked -->
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.

5 participants