Skip to content

Commit 32c8a12

Browse files
committed
Tweak CheckLintNameResult::Tool.
It has a clumsy type, with repeated `&'a [LintId]`, and sometimes requires an empty string that isn't used in the `Err`+`None` case. This commit splits it into two variants.
1 parent d070e89 commit 32c8a12

File tree

2 files changed

+46
-53
lines changed

2 files changed

+46
-53
lines changed

compiler/rustc_lint/src/context.rs

+21-18
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,16 @@ pub enum CheckLintNameResult<'a> {
127127
Renamed(String),
128128
/// The lint has been removed due to the given reason.
129129
Removed(String),
130-
/// The lint is from a tool. If the Option is None, then either
131-
/// the lint does not exist in the tool or the code was not
132-
/// compiled with the tool and therefore the lint was never
133-
/// added to the `LintStore`. Otherwise the `LintId` will be
134-
/// returned as if it where a rustc lint.
135-
Tool(Result<&'a [LintId], (Option<&'a [LintId]>, String)>),
130+
131+
/// The lint is from a tool. The `LintId` will be returned as if it were a
132+
/// rustc lint. The `Option<String>` indicates if the lint has been
133+
/// renamed.
134+
Tool(&'a [LintId], Option<String>),
135+
136+
/// The lint is from a tool. Either the lint does not exist in the tool or
137+
/// the code was not compiled with the tool and therefore the lint was
138+
/// never added to the `LintStore`.
139+
MissingTool,
136140
}
137141

138142
impl LintStore {
@@ -385,14 +389,14 @@ impl LintStore {
385389
} else {
386390
// 2. The tool isn't currently running, so no lints will be registered.
387391
// To avoid giving a false positive, ignore all unknown lints.
388-
CheckLintNameResult::Tool(Err((None, String::new())))
392+
CheckLintNameResult::MissingTool
389393
};
390394
}
391395
Some(LintGroup { lint_ids, .. }) => {
392-
return CheckLintNameResult::Tool(Ok(lint_ids));
396+
return CheckLintNameResult::Tool(lint_ids, None);
393397
}
394398
},
395-
Some(Id(id)) => return CheckLintNameResult::Tool(Ok(slice::from_ref(id))),
399+
Some(Id(id)) => return CheckLintNameResult::Tool(slice::from_ref(id), None),
396400
// If the lint was registered as removed or renamed by the lint tool, we don't need
397401
// to treat tool_lints and rustc lints different and can use the code below.
398402
_ => {}
@@ -412,7 +416,7 @@ impl LintStore {
412416
return if *silent {
413417
CheckLintNameResult::Ok(lint_ids)
414418
} else {
415-
CheckLintNameResult::Tool(Err((Some(lint_ids), (*name).to_string())))
419+
CheckLintNameResult::Tool(lint_ids, Some((*name).to_string()))
416420
};
417421
}
418422
CheckLintNameResult::Ok(lint_ids)
@@ -473,18 +477,17 @@ impl LintStore {
473477
// Reaching this would be weird, but let's cover this case anyway
474478
if let Some(LintAlias { name, silent }) = depr {
475479
let LintGroup { lint_ids, .. } = self.lint_groups.get(name).unwrap();
476-
return if *silent {
477-
CheckLintNameResult::Tool(Err((Some(lint_ids), complete_name)))
480+
if *silent {
481+
CheckLintNameResult::Tool(lint_ids, Some(complete_name))
478482
} else {
479-
CheckLintNameResult::Tool(Err((Some(lint_ids), (*name).to_string())))
480-
};
483+
CheckLintNameResult::Tool(lint_ids, Some((*name).to_string()))
484+
}
485+
} else {
486+
CheckLintNameResult::Tool(lint_ids, Some(complete_name))
481487
}
482-
CheckLintNameResult::Tool(Err((Some(lint_ids), complete_name)))
483488
}
484489
},
485-
Some(Id(id)) => {
486-
CheckLintNameResult::Tool(Err((Some(slice::from_ref(id)), complete_name)))
487-
}
490+
Some(Id(id)) => CheckLintNameResult::Tool(slice::from_ref(id), Some(complete_name)),
488491
Some(other) => {
489492
debug!("got renamed lint {:?}", other);
490493
CheckLintNameResult::NoLint(None)

compiler/rustc_lint/src/levels.rs

+25-35
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
593593
let lint = UnknownLintFromCommandLine { name, suggestion, requested_level };
594594
self.emit_lint(UNKNOWN_LINTS, lint);
595595
}
596-
CheckLintNameResult::Tool(Err((Some(_), ref replace))) => {
596+
CheckLintNameResult::Tool(_, Some(ref replace)) => {
597597
let name = lint_name.clone();
598598
let requested_level = RequestedLevel { level, lint_name };
599599
let lint = DeprecatedLintNameFromCommandLine { name, replace, requested_level };
@@ -902,62 +902,52 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
902902
}
903903
}
904904

905-
CheckLintNameResult::Tool(result) => {
906-
match *result {
907-
Ok(ids) => {
905+
CheckLintNameResult::Tool(ids, new_lint_name) => {
906+
let src = match new_lint_name {
907+
None => {
908908
let complete_name =
909909
&format!("{}::{}", tool_ident.unwrap().name, name);
910-
let src = LintLevelSource::Node {
910+
LintLevelSource::Node {
911911
name: Symbol::intern(complete_name),
912912
span: sp,
913913
reason,
914-
};
915-
for &id in ids {
916-
if self.check_gated_lint(id, attr.span, false) {
917-
self.insert_spec(id, (level, src));
918-
}
919-
}
920-
if let Level::Expect(expect_id) = level {
921-
self.provider.push_expectation(
922-
expect_id,
923-
LintExpectation::new(reason, sp, false, tool_name),
924-
);
925914
}
926915
}
927-
Err((Some(ids), ref new_lint_name)) => {
928-
let lint = builtin::RENAMED_AND_REMOVED_LINTS;
916+
Some(new_lint_name) => {
929917
self.emit_span_lint(
930-
lint,
918+
builtin::RENAMED_AND_REMOVED_LINTS,
931919
sp.into(),
932920
DeprecatedLintName {
933921
name,
934922
suggestion: sp,
935923
replace: new_lint_name,
936924
},
937925
);
938-
939-
let src = LintLevelSource::Node {
926+
LintLevelSource::Node {
940927
name: Symbol::intern(new_lint_name),
941928
span: sp,
942929
reason,
943-
};
944-
for id in ids {
945-
self.insert_spec(*id, (level, src));
946-
}
947-
if let Level::Expect(expect_id) = level {
948-
self.provider.push_expectation(
949-
expect_id,
950-
LintExpectation::new(reason, sp, false, tool_name),
951-
);
952930
}
953931
}
954-
Err((None, _)) => {
955-
// If Tool(Err(None, _)) is returned, then either the lint does not
956-
// exist in the tool or the code was not compiled with the tool and
957-
// therefore the lint was never added to the `LintStore`. To detect
958-
// this is the responsibility of the lint tool.
932+
};
933+
for &id in *ids {
934+
if self.check_gated_lint(id, attr.span, false) {
935+
self.insert_spec(id, (level, src));
959936
}
960937
}
938+
if let Level::Expect(expect_id) = level {
939+
self.provider.push_expectation(
940+
expect_id,
941+
LintExpectation::new(reason, sp, false, tool_name),
942+
);
943+
}
944+
}
945+
946+
CheckLintNameResult::MissingTool => {
947+
// If `MissingTool` is returned, then either the lint does not
948+
// exist in the tool or the code was not compiled with the tool and
949+
// therefore the lint was never added to the `LintStore`. To detect
950+
// this is the responsibility of the lint tool.
961951
}
962952

963953
&CheckLintNameResult::NoTool => {

0 commit comments

Comments
 (0)