Skip to content

Commit 5879827

Browse files
committed
Make deprecated_cfg_attr_crate_type_name a hard error
1 parent 4428a05 commit 5879827

12 files changed

+70
-118
lines changed

compiler/rustc_expand/messages.ftl

+8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ expand_collapse_debuginfo_illegal =
2727
expand_count_repetition_misplaced =
2828
`count` can not be placed inside the inner-most repetition
2929
30+
expand_crate_name_in_cfg_attr =
31+
`crate_name` within an `#![cfg_attr]` attribute is forbidden
32+
.help = this was previously accepted but is now an error
33+
34+
expand_crate_type_in_cfg_attr =
35+
`crate_type` within an `#![cfg_attr]` attribute is forbidden
36+
.help = this was previously accepted but is now an error
37+
3038
expand_custom_attribute_panicked =
3139
custom attribute panicked
3240
.help = message: {$message}

compiler/rustc_expand/src/config.rs

+5-14
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ use thin_vec::ThinVec;
2121
use tracing::instrument;
2222

2323
use crate::errors::{
24-
FeatureNotAllowed, FeatureRemoved, FeatureRemovedReason, InvalidCfg, MalformedFeatureAttribute,
25-
MalformedFeatureAttributeHelp, RemoveExprNotSupported,
24+
CrateNameInCfgAttr, CrateTypeInCfgAttr, FeatureNotAllowed, FeatureRemoved,
25+
FeatureRemovedReason, InvalidCfg, MalformedFeatureAttribute, MalformedFeatureAttributeHelp,
26+
RemoveExprNotSupported,
2627
};
2728

2829
/// A folder that strips out items that do not belong in the current configuration.
@@ -358,20 +359,10 @@ impl<'a> StripUnconfigured<'a> {
358359
item_span,
359360
);
360361
if attr.has_name(sym::crate_type) {
361-
self.sess.psess.buffer_lint(
362-
rustc_lint_defs::builtin::DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME,
363-
attr.span,
364-
ast::CRATE_NODE_ID,
365-
BuiltinLintDiag::CrateTypeInCfgAttr,
366-
);
362+
self.sess.dcx().emit_err(CrateTypeInCfgAttr { span: attr.span });
367363
}
368364
if attr.has_name(sym::crate_name) {
369-
self.sess.psess.buffer_lint(
370-
rustc_lint_defs::builtin::DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME,
371-
attr.span,
372-
ast::CRATE_NODE_ID,
373-
BuiltinLintDiag::CrateNameInCfgAttr,
374-
);
365+
self.sess.dcx().emit_err(CrateNameInCfgAttr { span: attr.span });
375366
}
376367
attr
377368
}

compiler/rustc_expand/src/errors.rs

+16
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,22 @@ pub(crate) struct GlobDelegationOutsideImpls {
467467
pub span: Span,
468468
}
469469

470+
#[derive(Diagnostic)]
471+
#[diag(expand_crate_name_in_cfg_attr)]
472+
#[help]
473+
pub(crate) struct CrateNameInCfgAttr {
474+
#[primary_span]
475+
pub span: Span,
476+
}
477+
478+
#[derive(Diagnostic)]
479+
#[diag(expand_crate_type_in_cfg_attr)]
480+
#[help]
481+
pub(crate) struct CrateTypeInCfgAttr {
482+
#[primary_span]
483+
pub span: Span,
484+
}
485+
470486
#[derive(Diagnostic)]
471487
#[diag(expand_glob_delegation_traitless_qpath)]
472488
pub(crate) struct GlobDelegationTraitlessQpath {

compiler/rustc_lint/messages.ftl

-6
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,6 @@ lint_confusable_identifier_pair = found both `{$existing_sym}` and `{$sym}` as i
203203
.current_use = this identifier can be confused with `{$existing_sym}`
204204
.other_use = other identifier used here
205205
206-
lint_crate_name_in_cfg_attr_deprecated =
207-
`crate_name` within an `#![cfg_attr]` attribute is deprecated
208-
209-
lint_crate_type_in_cfg_attr_deprecated =
210-
`crate_type` within an `#![cfg_attr]` attribute is deprecated
211-
212206
lint_cstring_ptr = getting the inner pointer of a temporary `CString`
213207
.as_ptr_label = this pointer will be invalid
214208
.unwrap_label = this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime

compiler/rustc_lint/src/context/diagnostics.rs

-6
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,6 @@ pub(super) fn decorate_lint(sess: &Session, diagnostic: BuiltinLintDiag, diag: &
400400
BuiltinLintDiag::CfgAttrNoAttributes => {
401401
lints::CfgAttrNoAttributes.decorate_lint(diag);
402402
}
403-
BuiltinLintDiag::CrateTypeInCfgAttr => {
404-
lints::CrateTypeInCfgAttr.decorate_lint(diag);
405-
}
406-
BuiltinLintDiag::CrateNameInCfgAttr => {
407-
lints::CrateNameInCfgAttr.decorate_lint(diag);
408-
}
409403
BuiltinLintDiag::MissingFragmentSpecifier => {
410404
lints::MissingFragmentSpecifier.decorate_lint(diag);
411405
}

compiler/rustc_lint/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,11 @@ fn register_builtins(store: &mut LintStore) {
570570
"converted into hard error, see RFC #3535 \
571571
<https://rust-lang.github.io/rfcs/3535-constants-in-patterns.html> for more information",
572572
);
573+
store.register_removed(
574+
"deprecated_cfg_attr_crate_type_name",
575+
"converted into hard error, see issue #91632 \
576+
<https://github.com/rust-lang/rust/issues/91632> for more information",
577+
);
573578
store.register_removed(
574579
"pointer_structural_match",
575580
"converted into hard error, see RFC #3535 \

compiler/rustc_lint/src/lints.rs

-8
Original file line numberDiff line numberDiff line change
@@ -2441,14 +2441,6 @@ pub(crate) struct DuplicateMacroAttribute;
24412441
#[diag(lint_cfg_attr_no_attributes)]
24422442
pub(crate) struct CfgAttrNoAttributes;
24432443

2444-
#[derive(LintDiagnostic)]
2445-
#[diag(lint_crate_type_in_cfg_attr_deprecated)]
2446-
pub(crate) struct CrateTypeInCfgAttr;
2447-
2448-
#[derive(LintDiagnostic)]
2449-
#[diag(lint_crate_name_in_cfg_attr_deprecated)]
2450-
pub(crate) struct CrateNameInCfgAttr;
2451-
24522444
#[derive(LintDiagnostic)]
24532445
#[diag(lint_missing_fragment_specifier)]
24542446
pub(crate) struct MissingFragmentSpecifier;

compiler/rustc_lint_defs/src/builtin.rs

-37
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ declare_lint_pass! {
3434
DEAD_CODE,
3535
DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK,
3636
DEPRECATED,
37-
DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME,
3837
DEPRECATED_IN_FUTURE,
3938
DEPRECATED_SAFE_2024,
4039
DEPRECATED_WHERE_CLAUSE_LOCATION,
@@ -3143,42 +3142,6 @@ declare_lint! {
31433142
"detects large moves or copies",
31443143
}
31453144

3146-
declare_lint! {
3147-
/// The `deprecated_cfg_attr_crate_type_name` lint detects uses of the
3148-
/// `#![cfg_attr(..., crate_type = "...")]` and
3149-
/// `#![cfg_attr(..., crate_name = "...")]` attributes to conditionally
3150-
/// specify the crate type and name in the source code.
3151-
///
3152-
/// ### Example
3153-
///
3154-
/// ```rust,compile_fail
3155-
/// #![cfg_attr(debug_assertions, crate_type = "lib")]
3156-
/// ```
3157-
///
3158-
/// {{produces}}
3159-
///
3160-
///
3161-
/// ### Explanation
3162-
///
3163-
/// The `#![crate_type]` and `#![crate_name]` attributes require a hack in
3164-
/// the compiler to be able to change the used crate type and crate name
3165-
/// after macros have been expanded. Neither attribute works in combination
3166-
/// with Cargo as it explicitly passes `--crate-type` and `--crate-name` on
3167-
/// the commandline. These values must match the value used in the source
3168-
/// code to prevent an error.
3169-
///
3170-
/// To fix the warning use `--crate-type` on the commandline when running
3171-
/// rustc instead of `#![cfg_attr(..., crate_type = "...")]` and
3172-
/// `--crate-name` instead of `#![cfg_attr(..., crate_name = "...")]`.
3173-
pub DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME,
3174-
Deny,
3175-
"detects usage of `#![cfg_attr(..., crate_type/crate_name = \"...\")]`",
3176-
@future_incompatible = FutureIncompatibleInfo {
3177-
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
3178-
reference: "issue #91632 <https://github.com/rust-lang/rust/issues/91632>",
3179-
};
3180-
}
3181-
31823145
declare_lint! {
31833146
/// The `unexpected_cfgs` lint detects unexpected conditional compilation conditions.
31843147
///

compiler/rustc_lint_defs/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -720,8 +720,6 @@ pub enum BuiltinLintDiag {
720720
UnnameableTestItems,
721721
DuplicateMacroAttribute,
722722
CfgAttrNoAttributes,
723-
CrateTypeInCfgAttr,
724-
CrateNameInCfgAttr,
725723
MissingFragmentSpecifier,
726724
MetaVariableStillRepeating(MacroRulesNormalizedIdent),
727725
MetaVariableWrongOperator,

tests/ui/cfg/future-compat-crate-attributes-using-cfg_attr.rs tests/ui/cfg/crate-attributes-using-cfg_attr.rs

-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33

44
#![cfg_attr(foo, crate_type="bin")]
55
//~^ERROR `crate_type` within
6-
//~| WARN this was previously accepted
76
//~|ERROR `crate_type` within
8-
//~| WARN this was previously accepted
97
#![cfg_attr(foo, crate_name="bar")]
108
//~^ERROR `crate_name` within
11-
//~| WARN this was previously accepted
129
//~|ERROR `crate_name` within
13-
//~| WARN this was previously accepted
1410

1511
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
error: `crate_type` within an `#![cfg_attr]` attribute is forbidden
2+
--> $DIR/crate-attributes-using-cfg_attr.rs:4:18
3+
|
4+
LL | #![cfg_attr(foo, crate_type="bin")]
5+
| ^^^^^^^^^^^^^^^^
6+
|
7+
= help: this was previously accepted but is now an error
8+
9+
error: `crate_name` within an `#![cfg_attr]` attribute is forbidden
10+
--> $DIR/crate-attributes-using-cfg_attr.rs:7:18
11+
|
12+
LL | #![cfg_attr(foo, crate_name="bar")]
13+
| ^^^^^^^^^^^^^^^^
14+
|
15+
= help: this was previously accepted but is now an error
16+
17+
error: `crate_type` within an `#![cfg_attr]` attribute is forbidden
18+
--> $DIR/crate-attributes-using-cfg_attr.rs:4:18
19+
|
20+
LL | #![cfg_attr(foo, crate_type="bin")]
21+
| ^^^^^^^^^^^^^^^^
22+
|
23+
= help: this was previously accepted but is now an error
24+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
25+
26+
error: `crate_name` within an `#![cfg_attr]` attribute is forbidden
27+
--> $DIR/crate-attributes-using-cfg_attr.rs:7:18
28+
|
29+
LL | #![cfg_attr(foo, crate_name="bar")]
30+
| ^^^^^^^^^^^^^^^^
31+
|
32+
= help: this was previously accepted but is now an error
33+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
34+
35+
error: aborting due to 4 previous errors
36+

tests/ui/cfg/future-compat-crate-attributes-using-cfg_attr.stderr

-41
This file was deleted.

0 commit comments

Comments
 (0)