Skip to content

Commit

Permalink
Updated to use rustc-check-cfg (#340)
Browse files Browse the repository at this point in the history
* updated to use rustc-check-cfg

* allow unstable on nightly

* rustfmt

* removed duplicate lint

* rustfmt

* fix code coverage unstable issue

* allow unexpected_cfgs lint
  • Loading branch information
CraZySacX authored May 6, 2024
1 parent 66ce790 commit 54f95fb
Show file tree
Hide file tree
Showing 19 changed files with 261 additions and 236 deletions.
32 changes: 12 additions & 20 deletions test_util/build.rs
Original file line number Diff line number Diff line change
@@ -1,48 +1,40 @@
pub fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rustc-check-cfg=cfg(coverage_nightly)");
nightly();
beta();
stable();
msrv();
lints_fix();
}

#[rustversion::nightly]
fn nightly() {
println!("cargo:rustc-check-cfg=cfg(nightly)");
println!("cargo:rustc-cfg=nightly");
}

#[rustversion::not(nightly)]
fn nightly() {}
fn nightly() {
println!("cargo:rustc-check-cfg=cfg(nightly)");
}

#[rustversion::beta]
fn beta() {
println!("cargo:rustc-check-cfg=cfg(beta)");
println!("cargo:rustc-cfg=beta");
}

#[rustversion::not(beta)]
fn beta() {}
fn beta() {
println!("cargo:rustc-check-cfg=cfg(beta)");
}

#[rustversion::stable]
fn stable() {
println!("cargo:rustc-check-cfg=cfg(stable)");
println!("cargo:rustc-cfg=stable");
}

#[rustversion::not(stable)]
fn stable() {}

#[rustversion::before(1.70)]
fn msrv() {}

#[rustversion::since(1.70)]
fn msrv() {
println!("cargo:rustc-cfg=msrv");
}

#[rustversion::before(1.75)]
fn lints_fix() {}

#[rustversion::since(1.75)]
fn lints_fix() {
println!("cargo:rustc-cfg=lints_fix")
fn stable() {
println!("cargo:rustc-check-cfg=cfg(stable)");
}
40 changes: 27 additions & 13 deletions test_util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ the [`TestRepos`] struct to creat temporary git repositories useful for `vergen-
lint_reasons,
multiple_supertrait_upcastable,
must_not_suspend,
mut_preserve_binding_mode_2024,
non_exhaustive_omitted_patterns_lint,
rustdoc_missing_doc_code_examples,
strict_provenance,
)
)]
#![cfg_attr(nightly, allow(box_pointers))]
#![cfg_attr(nightly, allow(box_pointers, single_use_lifetimes, unexpected_cfgs))]
#![cfg_attr(
nightly,
deny(
Expand All @@ -98,6 +99,7 @@ the [`TestRepos`] struct to creat temporary git repositories useful for `vergen-
clashing_extern_declarations,
coherence_leak_check,
confusable_idents,
const_eval_mutable_ptr_in_final_value,
const_evaluatable_unchecked,
const_item_mutation,
dead_code,
Expand Down Expand Up @@ -125,17 +127,16 @@ the [`TestRepos`] struct to creat temporary git repositories useful for `vergen-
hidden_glob_reexports,
improper_ctypes,
improper_ctypes_definitions,
incomplete_features,
indirect_structural_match,
inline_no_sanitize,
internal_features,
invalid_doc_attributes,
invalid_from_utf8,
invalid_macro_export_arguments,
invalid_nan_comparisons,
invalid_value,
irrefutable_let_patterns,
keyword_idents,
keyword_idents_2018,
keyword_idents_2024,
large_assignments,
late_bound_lifetime_arguments,
legacy_derive_helpers,
Expand All @@ -149,10 +150,13 @@ the [`TestRepos`] struct to creat temporary git repositories useful for `vergen-
missing_docs,
mixed_script_confusables,
named_arguments_used_positionally,
never_type_fallback_flowing_into_unsafe,
no_mangle_generic_items,
non_ascii_idents,
non_camel_case_types,
non_contiguous_range_endpoints,
non_fmt_panics,
non_local_definitions,
non_shorthand_field_patterns,
non_snake_case,
non_upper_case_globals,
Expand All @@ -163,16 +167,17 @@ the [`TestRepos`] struct to creat temporary git repositories useful for `vergen-
pointer_structural_match,
private_bounds,
private_interfaces,
redundant_lifetimes,
redundant_semicolons,
refining_impl_trait,
refining_impl_trait_internal,
refining_impl_trait_reachable,
renamed_and_removed_lints,
repr_transparent_external_private_fields,
rust_2021_incompatible_closure_captures,
rust_2021_incompatible_or_patterns,
rust_2021_prefixes_incompatible_syntax,
rust_2021_prelude_collisions,
semicolon_in_expressions_from_macros,
single_use_lifetimes,
special_module_name,
stable_features,
static_mut_refs,
Expand All @@ -185,13 +190,15 @@ the [`TestRepos`] struct to creat temporary git repositories useful for `vergen-
tyvar_behind_raw_pointer,
uncommon_codepoints,
unconditional_recursion,
uncovered_param_in_projection,
undefined_naked_function_abi,
unexpected_cfgs,
ungated_async_fn_track_caller,
uninhabited_static,
unit_bindings,
unknown_lints,
unknown_or_malformed_diagnostic_attributes,
unnameable_test_items,
unnameable_types,
unreachable_code,
unreachable_patterns,
unreachable_pub,
Expand Down Expand Up @@ -225,27 +232,33 @@ the [`TestRepos`] struct to creat temporary git repositories useful for `vergen-
unused_variables,
useless_ptr_null_checks,
variant_size_differences,
wasm_c_abi,
where_clauses_object_safety,
while_true,
writes_through_immutable_pointer,
)
)]
// If nightly and unstable, allow `unstable_features`
#![cfg_attr(all(feature = "unstable", nightly), allow(unstable_features))]
// If nightly and not unstable, deny `unstable_features`
#![cfg_attr(all(not(feature = "unstable"), nightly), deny(unstable_features))]
// If nightly and unstable, allow `incomplete_features` and `unstable_features`
#![cfg_attr(
all(feature = "unstable", nightly),
allow(incomplete_features, unstable_features)
)]
// If nightly and not unstable, deny `incomplete_features` and `unstable_features`
#![cfg_attr(
all(not(feature = "unstable"), nightly),
deny(incomplete_features, unstable_features)
)]
// The unstable lints
#![cfg_attr(
all(feature = "unstable", nightly),
deny(
dereferencing_mut_binding,
fuzzy_provenance_casts,
lossy_provenance_casts,
multiple_supertrait_upcastable,
must_not_suspend,
non_exhaustive_omitted_patterns,
unfulfilled_lint_expectations,
// unknown_or_malformed_diagnostic_attributes,
unnameable_types,
)
)]
// clippy lints
Expand All @@ -269,6 +282,7 @@ the [`TestRepos`] struct to creat temporary git repositories useful for `vergen-
)]
#![cfg_attr(all(doc, nightly), feature(doc_auto_cfg))]
#![cfg_attr(all(docsrs, nightly), feature(doc_cfg))]
#![cfg_attr(all(nightly, coverage_nightly), feature(coverage_attribute))]

#[cfg(all(test, not(feature = "repo")))]
use {anyhow as _, serial_test as _};
Expand Down
2 changes: 1 addition & 1 deletion vergen-git2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ lazy_static = "1.4.0"
regex = "1.10.3"
serial_test = "3.0.0"
temp-env = "0.3.6"
test_util = { path = "../test_util", features = ["repo"] }
test_util = { path = "../test_util", features = ["repo", "unstable"] }

[package.metadata.docs.rs]
features = ["build", "cargo", "emit_and_set", "rustc", "si"]
Expand Down
32 changes: 12 additions & 20 deletions vergen-git2/build.rs
Original file line number Diff line number Diff line change
@@ -1,48 +1,40 @@
pub fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rustc-check-cfg=cfg(coverage_nightly)");
nightly();
beta();
stable();
msrv();
lints_fix();
}

#[rustversion::nightly]
fn nightly() {
println!("cargo:rustc-check-cfg=cfg(nightly)");
println!("cargo:rustc-cfg=nightly");
}

#[rustversion::not(nightly)]
fn nightly() {}
fn nightly() {
println!("cargo:rustc-check-cfg=cfg(nightly)");
}

#[rustversion::beta]
fn beta() {
println!("cargo:rustc-check-cfg=cfg(beta)");
println!("cargo:rustc-cfg=beta");
}

#[rustversion::not(beta)]
fn beta() {}
fn beta() {
println!("cargo:rustc-check-cfg=cfg(beta)");
}

#[rustversion::stable]
fn stable() {
println!("cargo:rustc-check-cfg=cfg(stable)");
println!("cargo:rustc-cfg=stable");
}

#[rustversion::not(stable)]
fn stable() {}

#[rustversion::before(1.70)]
fn msrv() {}

#[rustversion::since(1.70)]
fn msrv() {
println!("cargo:rustc-cfg=msrv");
}

#[rustversion::before(1.75)]
fn lints_fix() {}

#[rustversion::since(1.75)]
fn lints_fix() {
println!("cargo:rustc-cfg=lints_fix")
fn stable() {
println!("cargo:rustc-check-cfg=cfg(stable)");
}
Loading

0 comments on commit 54f95fb

Please sign in to comment.