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

Warn about and ignore invalid crate-types #1914

Merged
merged 1 commit into from Aug 19, 2015
Merged

Warn about and ignore invalid crate-types #1914

merged 1 commit into from Aug 19, 2015

Conversation

thirtythreeforty
Copy link
Contributor

This fixes a problem with manifest parsing that I detailed here. Namely, requesting an invalid crate-type, as in the following:

[lib]
crate-type = ["bad_type"]

did not cause an error to be printed, but rather the bad list of types was silently converted to ["rlib"]. This was confusing to the user.

Cargo now properly rejects the above snippet.

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @huonw (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@alexcrichton alexcrichton assigned alexcrichton and unassigned huonw Aug 17, 2015
@alexcrichton
Copy link
Member

Thanks! In the interest of backwards-compatibility, however, I think that we'll probably just want to warn on situations like this for now. It's likely that some manifests have already been published to crates.io with invalid crate-types listed and I wouldn't want to break those.

Could you switch this over to just a warning instead? Perhaps a few months from now we can go back and turn it into a hard error.

@thirtythreeforty
Copy link
Contributor Author

thirtythreeforty commented Aug 17, 2015 via email

@alexcrichton
Copy link
Member

Yeah it's fine to just drop them aside, but a warning should be issued for each one that's dropped.

@thirtythreeforty
Copy link
Contributor Author

Alright. Should I propagate a reference to options to get a reference to the shell(), or can I just print them with println!()?

@alexcrichton
Copy link
Member

There's a few other places in the TOML parsing where warnings are added to a manifest (mainly because we don't want to warn about upstream manifests, only local ones), so following that pattern should do the trick!

@thirtythreeforty
Copy link
Contributor Author

Alright. The manifest doesn't exist when this parsing code runs, unfortunately (we're still in the middle of creating it). I'll have to store the warnings for when it does.

@thirtythreeforty
Copy link
Contributor Author

This should be ready to go, unless you have any further suggestions.

.set_doctest(toml.doctest.unwrap_or(t2.doctested()))
.set_benched(toml.bench.unwrap_or(t2.benched()))
.set_harness(toml.harness.unwrap_or(t2.harness()))
.set_for_host(toml.plugin.unwrap_or(t2.for_host()));
Copy link
Member

Choose a reason for hiding this comment

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

It looks like there weren't any substantial changes here, so could this stay the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes; this change is, strictly speaking, unrelated; just eliminates the call to clone(). I'll revert it.

@thirtythreeforty
Copy link
Contributor Author

Would you prefer I make a new commit fixing your review questions, or squash everything down into a new one (and force-push over the above ones)?

@alexcrichton
Copy link
Member

Feel free to go ahead and squash + force-push!

@thirtythreeforty
Copy link
Contributor Author

The above commit was rebased; it includes all the changes you wanted!

@thirtythreeforty thirtythreeforty changed the title Reject invalid crate types Warn about and ignore invalid crate-types Aug 18, 2015
if l.plugin == Some(true) {LibKind::Dylib}
else {LibKind::Lib}
]
};
Copy link
Member

Choose a reason for hiding this comment

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

Ah could you format this as:

let foo = match bar {
    Some(foo) => {
        foo.iter().filter_map(|a| {
            // ...
        }).collect()
    }
    None => {
        vec![...]
    }
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I understand what you meant now. Done. Needed a re-test anyway because Travis is having trouble.

@alexcrichton
Copy link
Member

@bors: r+ c2e6ba8

Thanks!

@bors
Copy link
Collaborator

bors commented Aug 19, 2015

⌛ Testing commit c2e6ba8 with merge 657e363...

bors added a commit that referenced this pull request Aug 19, 2015
This fixes a problem with manifest parsing that I detailed [here](http://stackoverflow.com/a/32055245/1830736).  Namely, requesting an invalid `crate-type`, as in the following:
```
[lib]
crate-type = ["bad_type"]
```
did not cause an error to be printed, but rather the bad list of types was silently converted to `["rlib"]`.  This was confusing to the user.

Cargo now properly rejects the above snippet.
@bors
Copy link
Collaborator

bors commented Aug 19, 2015

@bors bors merged commit c2e6ba8 into rust-lang:master Aug 19, 2015
@thirtythreeforty
Copy link
Contributor Author

Glad to help, thanks for your patience!

@matklad
Copy link
Member

matklad commented May 14, 2016

Created an issue for turning the warning into a hard error: #2692

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.

None yet

6 participants