Skip to content

Commit 52b6e2c

Browse files
committed
Auto merge of #155760 - GuillaumeGomez:rm-attributelintkind, r=JonathanBrouwer,petrochenkov
Remove `AttributeLintKind` Part of #153099. The `AttributeLintKind` type is finally gone! \o/ Diff is this big because I moved a file and a lot of `Diagnostic` types. :') r? @JonathanBrouwer
2 parents 345a975 + faecc47 commit 52b6e2c

22 files changed

Lines changed: 564 additions & 658 deletions

File tree

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use std::sync::Arc;
4141
use rustc_ast::node_id::NodeMap;
4242
use rustc_ast::visit::Visitor;
4343
use rustc_ast::{self as ast, *};
44-
use rustc_attr_parsing::{AttributeParser, EmitAttribute, Late, OmitDoc};
44+
use rustc_attr_parsing::{AttributeParser, Late, OmitDoc};
4545
use rustc_data_structures::fingerprint::Fingerprint;
4646
use rustc_data_structures::fx::FxIndexSet;
4747
use rustc_data_structures::sorted_map::SortedMap;
@@ -52,7 +52,7 @@ use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle};
5252
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
5353
use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId};
5454
use rustc_hir::definitions::PerParentDisambiguatorState;
55-
use rustc_hir::lints::{AttributeLint, DelayedLint, DynAttribute};
55+
use rustc_hir::lints::DelayedLint;
5656
use rustc_hir::{
5757
self as hir, AngleBrackets, ConstArg, GenericArg, HirId, ItemLocalMap, LifetimeSource,
5858
LifetimeSyntax, ParamName, Target, TraitCandidate, find_attr,
@@ -1096,23 +1096,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
10961096
target,
10971097
OmitDoc::Lower,
10981098
|s| l.lower(s),
1099-
|lint_id, span, kind| match kind {
1100-
EmitAttribute::Static(attr_kind) => {
1101-
self.delayed_lints.push(DelayedLint::AttributeParsing(AttributeLint {
1102-
lint_id,
1103-
id: target_hir_id,
1104-
span,
1105-
kind: attr_kind,
1106-
}));
1107-
}
1108-
EmitAttribute::Dynamic(callback) => {
1109-
self.delayed_lints.push(DelayedLint::Dynamic(DynAttribute {
1110-
lint_id,
1111-
id: target_hir_id,
1112-
span,
1113-
callback,
1114-
}));
1115-
}
1099+
|lint_id, span, kind| {
1100+
self.delayed_lints.push(DelayedLint {
1101+
lint_id,
1102+
id: target_hir_id,
1103+
span,
1104+
callback: Box::new(move |dcx, level, sess: &dyn std::any::Any| {
1105+
let sess = sess
1106+
.downcast_ref::<rustc_session::Session>()
1107+
.expect("expected `Session`");
1108+
(kind.0)(dcx, level, sess)
1109+
}),
1110+
});
11161111
},
11171112
)
11181113
}

compiler/rustc_attr_parsing/src/attributes/cfg.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ use std::convert::identity;
33
use rustc_ast::token::Delimiter;
44
use rustc_ast::tokenstream::DelimSpan;
55
use rustc_ast::{AttrItem, Attribute, LitKind, ast, token};
6-
use rustc_errors::{Applicability, PResult, msg};
6+
use rustc_errors::{Applicability, Diagnostic, PResult, msg};
77
use rustc_feature::{
88
AttrSuggestionStyle, AttributeTemplate, Features, GatedCfg, find_gated_cfg, template,
99
};
1010
use rustc_hir::attrs::CfgEntry;
11-
use rustc_hir::lints::AttributeLintKind;
1211
use rustc_hir::{AttrPath, RustcVersion, Target};
1312
use rustc_parse::parser::{ForceCollect, Parser, Recovery};
1413
use rustc_parse::{exp, parse_in};
@@ -20,6 +19,7 @@ use rustc_span::{ErrorGuaranteed, Span, Symbol, sym};
2019
use thin_vec::ThinVec;
2120

2221
use crate::attributes::AttributeSafety;
22+
use crate::attributes::diagnostic::check_cfg;
2323
use crate::context::{AcceptContext, ShouldEmit, Stage};
2424
use crate::parser::{
2525
AllowExprMetavar, ArgParser, MetaItemListParser, MetaItemOrLitParser, NameValueParser,
@@ -224,14 +224,19 @@ pub(crate) fn parse_name_value<S: Stage>(
224224

225225
match cx.sess.psess.check_config.expecteds.get(&name) {
226226
Some(ExpectedValues::Some(values)) if !values.contains(&value.map(|(v, _)| v)) => cx
227-
.emit_lint(
227+
.emit_dyn_lint_with_sess(
228228
UNEXPECTED_CFGS,
229-
AttributeLintKind::UnexpectedCfgValue((name, name_span), value),
229+
move |dcx, level, sess| {
230+
check_cfg::unexpected_cfg_value(sess, (name, name_span), value)
231+
.into_diag(dcx, level)
232+
},
230233
span,
231234
),
232-
None if cx.sess.psess.check_config.exhaustive_names => cx.emit_lint(
235+
None if cx.sess.psess.check_config.exhaustive_names => cx.emit_dyn_lint_with_sess(
233236
UNEXPECTED_CFGS,
234-
AttributeLintKind::UnexpectedCfgName((name, name_span), value),
237+
move |dcx, level, sess| {
238+
check_cfg::unexpected_cfg_name(sess, (name, name_span), value).into_diag(dcx, level)
239+
},
235240
span,
236241
),
237242
_ => { /* not unexpected */ }

0 commit comments

Comments
 (0)