-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Implementation of incompatible features error #76293
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
r? @lcnr |
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.
This is a good idea 👍
I think it would be better if this is a hard error instead, considering that there really shouldn't be a reason to opt into this. Afaik we also would have to be more reluctant if we were to ever remove this lint in the future, as users can reference it, for example by using #![allow(incomplete_features)]
.
compiler/rustc_lint/src/builtin.rs
Outdated
cx.struct_span_lint(INCOMPATIBLE_FEATURES, spans.clone(), |lint| { | ||
lint.build(&format!( | ||
"features `{}` and `{}` are incompatible, using them \ | ||
at the same time can result in an undefined behavior", |
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.
at the same time can result in an undefined behavior", | |
at the same time can result in undefined behavior", |
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.
Undefined behavior has a very specific meaning: the compiler is allowed to do anything to your code, up to and including segfaults, security vulnerabilities, and just giving an error. Is that's what's intended here? Or is this just saying 'rustc could be buggy'? I think we should distinguish between compiler bugs and behavior that is intended to be undefined.
cc @RalfJung
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.
Its not that 'rustc is buggy', to fix the issue we might have checked everytime min_const_generics
is used that const_generics
is not present, but I thought of making this general in case in the future we encountered something similar.
I intended to produce an error so that users cannot use them together, It thought rustc_lint was the correct place.
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.
Ok, in that case let's just say 'not allowed'. UB has other connotations which aren't applicable here.
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.
I think it's better to produce an error instead of the current warning. Do you know how to do that?
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.
UB would be accurate here if there are known soundness bugs -- like there are for incomplete features, though I think there I made the text say something like "unsafe to use" or so. I think it is important to drive home the point that even if compilation succeeds (no ICE or so), things could still go horribly wrong.
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.
Oh, but this seems different. We just want people to disable min_const_generic
when enabling const_generic
. And this is a hard error, not a warning. So yeah, it probably doesn't make sense to speak about UB here.
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.
yah, working on making it hard error
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.
Should I still do it in rustc_lint
? or which part of rustc
is better for this?
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.
I think rustc_ast_passes/feature_gate.rs
might be fitting, not too sure about that though
I also agree making it a hard error is better it will also have a better meaning for 'undefined behavior', but I don't know which rustc part is responsible for this, after some search I found I'm ready to change it into someplace else. |
fe85606
to
50a31b4
Compare
moved it to |
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.
A few optional nits about style, otherwise r=me
50a31b4
to
cd8fbfb
Compare
If two features are defined as incompatible, using them together would result in an error
cd8fbfb
to
8f2d906
Compare
@bors r+ rollup Thank you ❤️ |
📌 Commit 8f2d906 has been approved by |
…, r=lcnr Implementation of incompatible features error Proposal of a new error: Incompatible features This error should happen if two features which are not compatible are used together. For now the only incompatible features are `const_generics` and `min_const_generics` fixes rust-lang#76280
…, r=lcnr Implementation of incompatible features error Proposal of a new error: Incompatible features This error should happen if two features which are not compatible are used together. For now the only incompatible features are `const_generics` and `min_const_generics` fixes rust-lang#76280
Rollup of 18 pull requests Successful merges: - rust-lang#76273 (Move some Vec UI tests into alloc unit tests) - rust-lang#76274 (Allow try blocks as the argument to return expressions) - rust-lang#76287 (Remove an unnecessary allowed lint) - rust-lang#76293 (Implementation of incompatible features error) - rust-lang#76299 (Make `Ipv4Addr` and `Ipv6Addr` const tests unit tests under `library`) - rust-lang#76302 (Address review comments on `Peekable::next_if`) - rust-lang#76303 (Link to `#capacity-and-reallocation` when using with_capacity) - rust-lang#76305 (Move various ui const tests to `library`) - rust-lang#76309 (Indent a note to make folding work nicer) - rust-lang#76312 (time.rs: Make spelling of "Darwin" consistent) - rust-lang#76318 (Use ops::ControlFlow in rustc_data_structures::graph::iterate) - rust-lang#76324 (Move Vec slice UI tests in library) - rust-lang#76338 (add some intra-doc links to `Iterator`) - rust-lang#76340 (Remove unused duplicated `trivial_dropck_outlives`) - rust-lang#76344 (Improve docs for `std::env::args()`) - rust-lang#76346 (Docs: nlink example typo) - rust-lang#76358 (Minor grammar fix in doc comment for soft-deprecated methods) - rust-lang#76364 (Disable atomics on avr target.) Failed merges: - rust-lang#76304 (Make delegation methods of `std::net::IpAddr` unstably const) r? @ghost
Proposal of a new error: Incompatible features
This error should happen if two features which are not compatible are used together.
For now the only incompatible features are
const_generics
andmin_const_generics
fixes #76280