-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Emit a warning when manifest specifies empty dependency constraints #2270
Conversation
r? @huonw (rust_highfive has picked a reviewer for you, use r? to override) |
@@ -680,6 +681,12 @@ fn process_dependencies<F>(cx: &mut Context, | |||
} | |||
TomlDependency::Detailed(ref details) => details.clone(), | |||
}; | |||
|
|||
if details.version.is_none() && details.path.is_none() && details.git.is_none() { | |||
warnings.push(format!("warning: Dependency ({}) specified without providing a local \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question for reviewer: Is there a convention for phrasing to indicate this really should be changed and may become a hard error in the future?
Similarly, is there anything (comment, annotation, etc) that should be left here in the code as a marker for future cleanup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah this looks ok to me, we typically avoid capital letters and ending punctuation, however
In the related bug (#2147), @alexcrichton suggests this should perhaps become a hard error (breaking change) in the future.
|
Thanks! Can you be sure to add a test for this as well? Also, could you reword the warning to indicate that it will become a hard error in the future? |
Ah and to clarify, we don't currently have a process for ensuring this becomes a hard error, but it's fine if we just wander across this in a few months and flip the switch. |
I've updated the wording of the warning as suggested, but am having trouble writing a sensible test. By definition the test manifest has to list an empty dependency for us to try and compile. That means I can't create some dummy files and use Is there a better way? Or at least a designated empty test crate that's controlled by the Cargo developers and used for this kind of purpose? For reference, I've got something like this: test!(empty_dependencies {
let p = project("empty_deps")
.file("Cargo.toml", r#"
[package]
name = "empty_deps"
version = "0.0.0"
authors = []
[dependencies]
foo = {}
"#)
.file("src/main.rs", "fn main() {}");
assert_that(p.cargo_process("build"),
execs().with_status(0).with_stderr_contains("\
warning: dependency (foo) specified without providing a local path, Git repository, or version \
to use. This will be considered an error in future versions
"));
}); At present, this fails because |
Ah there are some examples throughout the test codebase for this sort of dependency. I believe you just need to do this. |
This warns when encountering dependencies of either of these forms: [dependencies] foo = {} and [dependencies.foo] (with nothing further provided). In the future, this should likely become a hard error.
Thanks for the pointer! Beautifully simple. Tests added and PR updated. |
This warns when encountering dependencies of either of these forms: ``` [dependencies] foo = {} ``` and ``` [dependencies.foo] ``` (with nothing further provided). In the future, this should likely become a hard error. Related to #2147
☀️ Test successful - cargo-linux-32, cargo-linux-64, cargo-mac-32, cargo-mac-64, cargo-win-gnu-32, cargo-win-gnu-64, cargo-win-msvc-32, cargo-win-msvc-64 |
This warns when encountering dependencies of either of these forms:
and
(with nothing further provided).
In the future, this should likely become a hard error.
Related to #2147