Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to enforce correct spelling of features?

Let's assume I have the following feature defined in Cargo.toml:

[features]
my_feature = []

And the following code lives in src/lib.rs:

#[cfg(feature = "my_feature")]
fn f() { /* ... */ }

#[cfg(not(feature = "my_faeture"))] // <-- Mind the typo!
fn f() { /* ... */ }

How can I enforce, that the feature-strings are matched against the list of both explicitly defined and implicitly available features in Cargo.toml so that for instance typos could be avoided?

like image 321
Peter Varo Avatar asked Oct 12 '21 07:10

Peter Varo


People also ask

How do I force word to spell check?

Turn on (or off) automatic spelling and grammar checking In the Spelling & Grammar dialog box, under Spelling, check or clear the Check spelling as you type box. Under Grammar, check or clear the Check grammar as you type box. Close the dialog box to save your changes.

Which word feature helps with correcting spelling errors?

To automatically correct common errors as you type, use the options in the AutoCorrect tab of the AutoCorrect dialog box to set up automatic correction of capitalization errors and commonly misspelled words. You can also create special characters.

How do I enable dynamic spelling?

Use dynamic spelling To enable dynamic spelling, choose Edit > Spelling > Dynamic Spelling.

How do I ignore wrong spelling words?

Here's how. Select the text where you'd like to disable spell check or press Ctrl+A to select the entire document. On the Review tab, click Editor, and then click Set Proofing Language. In the Language box, click Don't check spelling or grammar, and then click OK.


Video Answer


1 Answers

When RFC 3013, "Checking conditional compilation at compile time", is implemented, there will be warnings for a #[cfg] referring to a feature name that is not declared by Cargo, just as you're asking for. However, the implementation only just got started (Sep 28, 2021).

The means of operation described in the RFC is just as you suggested, ‘cargo would pass down the flags to rustc’.


It may be worth noting that this will not check all conditions appearing in the source text; as described in the RFC:

This lint will not be able to detect invalid #[cfg] tests that are within modules that are not compiled, presumably because an ancestor mod is disabled.

So, it will not confirm that all #[cfg(feature)] are valid on a single cargo check — you will need to test with your various features or combinations of features. But those are the same combinations that you would need anyway to check for compile errors in all of the regular source code that could be enabled; once you do that, the lint will assure you that you don't have any #[cfg(feature)] that are never enabled due to a typo.

like image 91
Kevin Reid Avatar answered Oct 20 '22 20:10

Kevin Reid