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

Implementation of incompatible features error #76293

Merged
merged 1 commit into from
Sep 7, 2020

Conversation

Amjad50
Copy link
Contributor

@Amjad50 Amjad50 commented Sep 3, 2020

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 #76280

@rust-highfive
Copy link
Collaborator

r? @nikomatsakis

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 3, 2020
@jonas-schievink
Copy link
Contributor

r? @lcnr

@rust-highfive rust-highfive assigned lcnr and unassigned nikomatsakis Sep 3, 2020
Copy link
Contributor

@lcnr lcnr left a 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 Show resolved Hide resolved
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",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
at the same time can result in an undefined behavior",
at the same time can result in undefined behavior",

Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

@RalfJung RalfJung Sep 4, 2020

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.

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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?

Copy link
Contributor

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

@jyn514 jyn514 added the requires-nightly This issue requires a nightly compiler in some way. label Sep 3, 2020
compiler/rustc_lint/src/builtin.rs Outdated Show resolved Hide resolved
compiler/rustc_feature/src/active.rs Outdated Show resolved Hide resolved
@Amjad50
Copy link
Contributor Author

Amjad50 commented Sep 3, 2020

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 rustc_lint so I thought it might work.

I'm ready to change it into someplace else.

@Amjad50
Copy link
Contributor Author

Amjad50 commented Sep 4, 2020

moved it to rustc_ast_passes/feature_gate.rs, but can be moved elsewhere if not appropriate. Now it produce hard error with message not allowed

Copy link
Contributor

@lcnr lcnr left a 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

compiler/rustc_ast_passes/src/feature_gate.rs Outdated Show resolved Hide resolved
compiler/rustc_ast_passes/src/feature_gate.rs Outdated Show resolved Hide resolved
If two features are defined as incompatible, using them together would
result in an error
@lcnr
Copy link
Contributor

lcnr commented Sep 4, 2020

@bors r+ rollup

Thank you ❤️

@bors
Copy link
Contributor

bors commented Sep 4, 2020

📌 Commit 8f2d906 has been approved by lcnr

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 4, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Sep 5, 2020
…, 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
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Sep 6, 2020
…, 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
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 7, 2020
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
@bors bors merged commit 3d834bc into rust-lang:master Sep 7, 2020
@rustbot rustbot added this to the 1.48.0 milestone Sep 7, 2020
@lcnr lcnr added the F-const_generics `#![feature(const_generics)]` label Nov 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

min_const_generic takes precedence over const_generics
9 participants