Skip to content

Commit bddbaa6

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 e90c0f8 commit bddbaa6

File tree

2 files changed

+43
-45
lines changed

2 files changed

+43
-45
lines changed

compiler/rustc_lint/src/context.rs

+21-16
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,17 +477,18 @@ 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
},
485490
Some(Id(id)) => {
486-
CheckLintNameResult::Tool(Err((Some(slice::from_ref(id)), complete_name)))
491+
CheckLintNameResult::Tool(slice::from_ref(id), Some(complete_name))
487492
}
488493
Some(other) => {
489494
debug!("got renamed lint {:?}", other);

compiler/rustc_lint/src/levels.rs

+22-29
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
591591
let lint = UnknownLintFromCommandLine { name, suggestion, requested_level };
592592
self.emit_lint(UNKNOWN_LINTS, lint);
593593
}
594-
CheckLintNameResult::Tool(Err((Some(_), ref replace))) => {
594+
CheckLintNameResult::Tool(_, Some(ref replace)) => {
595595
let name = lint_name.clone();
596596
let requested_level = RequestedLevel { level, lint_name };
597597
let lint = DeprecatedLintNameFromCommandLine { name, replace, requested_level };
@@ -900,62 +900,55 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
900900
}
901901
}
902902

903-
CheckLintNameResult::Tool(result) => {
904-
match *result {
905-
Ok(ids) => {
903+
CheckLintNameResult::Tool(ids, new_lint_name) => {
904+
match new_lint_name {
905+
None => {
906906
let complete_name =
907907
&format!("{}::{}", tool_ident.unwrap().name, name);
908908
let src = LintLevelSource::Node {
909909
name: Symbol::intern(complete_name),
910910
span: sp,
911911
reason,
912912
};
913-
for &id in ids {
913+
for &id in *ids {
914914
if self.check_gated_lint(id, attr.span, false) {
915915
self.insert_spec(id, (level, src));
916916
}
917917
}
918-
if let Level::Expect(expect_id) = level {
919-
self.provider.push_expectation(
920-
expect_id,
921-
LintExpectation::new(reason, sp, false, tool_name),
922-
);
923-
}
924918
}
925-
Err((Some(ids), ref new_lint_name)) => {
926-
let lint = builtin::RENAMED_AND_REMOVED_LINTS;
919+
Some(new_lint_name) => {
927920
self.emit_span_lint(
928-
lint,
921+
builtin::RENAMED_AND_REMOVED_LINTS,
929922
sp.into(),
930923
DeprecatedLintName {
931924
name,
932925
suggestion: sp,
933926
replace: new_lint_name,
934927
},
935928
);
936-
937929
let src = LintLevelSource::Node {
938930
name: Symbol::intern(new_lint_name),
939931
span: sp,
940932
reason,
941933
};
942-
for id in ids {
943-
self.insert_spec(*id, (level, src));
944-
}
945-
if let Level::Expect(expect_id) = level {
946-
self.provider.push_expectation(
947-
expect_id,
948-
LintExpectation::new(reason, sp, false, tool_name),
949-
);
934+
for &id in *ids {
935+
self.insert_spec(id, (level, src));
950936
}
951937
}
952-
Err((None, _)) => {
953-
// If Tool(Err(None, _)) is returned, then either the lint does not
954-
// exist in the tool or the code was not compiled with the tool and
955-
// therefore the lint was never added to the `LintStore`. To detect
956-
// this is the responsibility of the lint tool.
957-
}
958938
}
939+
if let Level::Expect(expect_id) = level {
940+
self.provider.push_expectation(
941+
expect_id,
942+
LintExpectation::new(reason, sp, false, tool_name),
943+
);
944+
}
945+
}
946+
947+
CheckLintNameResult::MissingTool => {
948+
// If `MissingTool` is returned, then either the lint does not
949+
// exist in the tool or the code was not compiled with the tool and
950+
// therefore the lint was never added to the `LintStore`. To detect
951+
// this is the responsibility of the lint tool.
959952
}
960953

961954
&CheckLintNameResult::NoTool => {

0 commit comments

Comments
 (0)