summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_lint/src/context.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_lint/src/context.rs')
-rw-r--r--compiler/rustc_lint/src/context.rs42
1 files changed, 34 insertions, 8 deletions
diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs
index 8046cc21c..f5a711315 100644
--- a/compiler/rustc_lint/src/context.rs
+++ b/compiler/rustc_lint/src/context.rs
@@ -39,7 +39,7 @@ use rustc_middle::ty::{self, print::Printer, subst::GenericArg, RegisteredTools,
use rustc_session::lint::{BuiltinLintDiagnostics, LintExpectationId};
use rustc_session::lint::{FutureIncompatibleInfo, Level, Lint, LintBuffer, LintId};
use rustc_session::Session;
-use rustc_span::lev_distance::find_best_match_for_name;
+use rustc_span::edit_distance::find_best_match_for_name;
use rustc_span::symbol::{sym, Ident, Symbol};
use rustc_span::{BytePos, Span};
use rustc_target::abi;
@@ -487,7 +487,7 @@ impl LintStore {
let mut groups: Vec<_> = self
.lint_groups
.iter()
- .filter_map(|(k, LintGroup { depr, .. })| if depr.is_none() { Some(k) } else { None })
+ .filter_map(|(k, LintGroup { depr, .. })| depr.is_none().then_some(k))
.collect();
groups.sort();
let groups = groups.iter().map(|k| Symbol::intern(k));
@@ -837,9 +837,17 @@ pub trait LintContext: Sized {
(use_span, "'_".to_owned())
};
debug!(?deletion_span, ?use_span);
+
+ // issue 107998 for the case such as a wrong function pointer type
+ // `deletion_span` is empty and there is no need to report lifetime uses here
+ let suggestions = if deletion_span.is_empty() {
+ vec![(use_span, replace_lt)]
+ } else {
+ vec![(deletion_span, String::new()), (use_span, replace_lt)]
+ };
db.multipart_suggestion(
msg,
- vec![(deletion_span, String::new()), (use_span, replace_lt)],
+ suggestions,
Applicability::MachineApplicable,
);
}
@@ -882,6 +890,26 @@ pub trait LintContext: Sized {
);
}
}
+ BuiltinLintDiagnostics::ByteSliceInPackedStructWithDerive => {
+ db.help("consider implementing the trait by hand, or remove the `packed` attribute");
+ }
+ BuiltinLintDiagnostics::UnusedExternCrate { removal_span }=> {
+ db.span_suggestion(
+ removal_span,
+ "remove it",
+ "",
+ Applicability::MachineApplicable,
+ );
+ }
+ BuiltinLintDiagnostics::ExternCrateNotIdiomatic { vis_span, ident_span }=> {
+ let suggestion_span = vis_span.between(ident_span);
+ db.span_suggestion_verbose(
+ suggestion_span,
+ "convert it to a `use`",
+ if vis_span.is_empty() { "use " } else { " use " },
+ Applicability::MachineApplicable,
+ );
+ }
}
// Rewrap `db`, and pass control to the user.
decorate(db)
@@ -1101,11 +1129,9 @@ impl<'tcx> LateContext<'tcx> {
.maybe_typeck_results()
.filter(|typeck_results| typeck_results.hir_owner == id.owner)
.or_else(|| {
- if self.tcx.has_typeck_results(id.owner.to_def_id()) {
- Some(self.tcx.typeck(id.owner.def_id))
- } else {
- None
- }
+ self.tcx
+ .has_typeck_results(id.owner.to_def_id())
+ .then(|| self.tcx.typeck(id.owner.def_id))
})
.and_then(|typeck_results| typeck_results.type_dependent_def(id))
.map_or(Res::Err, |(kind, def_id)| Res::Def(kind, def_id)),