Skip to content

Commit 8177e49

Browse files
committedMar 27, 2020
1 parent 2ff568d commit 8177e49

File tree

7 files changed

+34
-18
lines changed

7 files changed

+34
-18
lines changed
 

‎clippy_lints/src/derive.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ fn check_hash_peq<'a, 'tcx>(
9494
if_chain! {
9595
if match_path(&trait_ref.path, &paths::HASH);
9696
if let Some(peq_trait_def_id) = cx.tcx.lang_items().eq_trait();
97-
if !&trait_ref.trait_def_id().is_local();
97+
if let Some(def_id) = &trait_ref.trait_def_id();
98+
if !def_id.is_local();
9899
then {
99100
// Look for the PartialEq implementations for `ty`
100101
cx.tcx.for_each_relevant_impl(peq_trait_def_id, ty, |impl_id| {

‎clippy_lints/src/if_let_some_result.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::utils::{match_type, method_chain_args, paths, snippet_with_applicability, span_lint_and_sugg};
22
use if_chain::if_chain;
33
use rustc_errors::Applicability;
4-
use rustc_hir::{print, Expr, ExprKind, MatchSource, PatKind, QPath};
4+
use rustc_hir::{Expr, ExprKind, MatchSource, PatKind, QPath};
5+
use rustc_hir_pretty;
56
use rustc_lint::{LateContext, LateLintPass};
67
use rustc_session::{declare_lint_pass, declare_tool_lint};
78

@@ -46,7 +47,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OkIfLet {
4647
if let PatKind::TupleStruct(QPath::Resolved(_, ref x), ref y, _) = body[0].pat.kind; //get operation
4748
if method_chain_args(op, &["ok"]).is_some(); //test to see if using ok() methoduse std::marker::Sized;
4849
let is_result_type = match_type(cx, cx.tables.expr_ty(&result_types[0]), &paths::RESULT);
49-
if print::to_string(print::NO_ANN, |s| s.print_path(x, false)) == "Some" && is_result_type;
50+
if rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_path(x, false)) == "Some" && is_result_type;
5051

5152
then {
5253
let mut applicability = Applicability::MachineApplicable;

‎clippy_lints/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ extern crate rustc_errors;
3434
#[allow(unused_extern_crates)]
3535
extern crate rustc_hir;
3636
#[allow(unused_extern_crates)]
37+
extern crate rustc_hir_pretty;
38+
#[allow(unused_extern_crates)]
3739
extern crate rustc_index;
3840
#[allow(unused_extern_crates)]
3941
extern crate rustc_infer;

‎clippy_lints/src/matches.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ use rustc_ast::ast::LitKind;
1515
use rustc_errors::Applicability;
1616
use rustc_hir::def::CtorKind;
1717
use rustc_hir::{
18-
print, Arm, BindingAnnotation, Block, BorrowKind, Expr, ExprKind, Local, MatchSource, Mutability, Node, Pat,
19-
PatKind, QPath, RangeEnd,
18+
Arm, BindingAnnotation, Block, BorrowKind, Expr, ExprKind, Local, MatchSource, Mutability, Node, Pat, PatKind,
19+
QPath, RangeEnd,
2020
};
21+
use rustc_hir_pretty;
2122
use rustc_lint::{LateContext, LateLintPass, LintContext};
2223
use rustc_session::{declare_tool_lint, impl_lint_pass};
2324
use rustc_span::source_map::Span;
@@ -536,10 +537,12 @@ fn check_single_match_opt_like(
536537
if !inner.iter().all(is_wild) {
537538
return;
538539
}
539-
print::to_string(print::NO_ANN, |s| s.print_qpath(path, false))
540+
rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false))
540541
},
541542
PatKind::Binding(BindingAnnotation::Unannotated, .., ident, None) => ident.to_string(),
542-
PatKind::Path(ref path) => print::to_string(print::NO_ANN, |s| s.print_qpath(path, false)),
543+
PatKind::Path(ref path) => {
544+
rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false))
545+
},
543546
_ => return,
544547
};
545548

@@ -638,7 +641,7 @@ fn check_wild_err_arm(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>])
638641
if match_type(cx, ex_ty, &paths::RESULT) {
639642
for arm in arms {
640643
if let PatKind::TupleStruct(ref path, ref inner, _) = arm.pat.kind {
641-
let path_str = print::to_string(print::NO_ANN, |s| s.print_qpath(path, false));
644+
let path_str = rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false));
642645
if path_str == "Err" {
643646
let mut matching_wild = inner.iter().any(is_wild);
644647
let mut ident_bind_name = String::from("_");

‎clippy_lints/src/mut_reference.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::utils::span_lint;
22
use rustc::ty::subst::Subst;
33
use rustc::ty::{self, Ty};
4-
use rustc_hir::{print, BorrowKind, Expr, ExprKind, Mutability};
4+
use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability};
5+
use rustc_hir_pretty;
56
use rustc_lint::{LateContext, LateLintPass};
67
use rustc_session::{declare_lint_pass, declare_tool_lint};
78

@@ -34,7 +35,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnecessaryMutPassed {
3435
cx,
3536
arguments,
3637
cx.tables.expr_ty(fn_expr),
37-
&print::to_string(print::NO_ANN, |s| s.print_qpath(path, false)),
38+
&rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false)),
3839
);
3940
}
4041
},

‎clippy_lints/src/trait_bounds.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use crate::utils::{in_macro, snippet, span_lint_and_help, SpanlessHash};
1+
use crate::utils::{in_macro, snippet, snippet_with_applicability, span_lint_and_help, SpanlessHash};
22
use rustc_data_structures::fx::FxHashMap;
3+
use rustc_errors::Applicability;
34
use rustc_hir::{GenericBound, Generics, WherePredicate};
45
use rustc_lint::{LateContext, LateLintPass};
56
use rustc_session::{declare_tool_lint, impl_lint_pass};
@@ -41,6 +42,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TraitBounds {
4142
hasher.finish()
4243
};
4344
let mut map = FxHashMap::default();
45+
let mut applicability = Applicability::MaybeIncorrect;
4446
for bound in gen.where_clause.predicates {
4547
if let WherePredicate::BoundPredicate(ref p) = bound {
4648
let h = hash(&p.bounded_ty);
@@ -52,13 +54,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TraitBounds {
5254
for b in v.iter() {
5355
if let GenericBound::Trait(ref poly_trait_ref, _) = b {
5456
let path = &poly_trait_ref.trait_ref.path;
55-
hint_string.push_str(&format!(" {} +", path));
57+
hint_string.push_str(&format!(
58+
" {} +",
59+
snippet_with_applicability(cx, path.span, "..", &mut applicability)
60+
));
5661
}
5762
}
5863
for b in p.bounds.iter() {
5964
if let GenericBound::Trait(ref poly_trait_ref, _) = b {
6065
let path = &poly_trait_ref.trait_ref.path;
61-
hint_string.push_str(&format!(" {} +", path));
66+
hint_string.push_str(&format!(
67+
" {} +",
68+
snippet_with_applicability(cx, path.span, "..", &mut applicability)
69+
));
6270
}
6371
}
6472
hint_string.truncate(hint_string.len() - 2);

‎clippy_lints/src/utils/inspector.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::utils::get_attr;
44
use rustc_ast::ast::Attribute;
55
use rustc_hir as hir;
6-
use rustc_hir::print;
6+
use rustc_hir_pretty;
77
use rustc_lint::{LateContext, LateLintPass, LintContext};
88
use rustc_session::Session;
99
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -50,7 +50,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DeepCodeInspector {
5050
hir::VisibilityKind::Crate(_) => println!("visible crate wide"),
5151
hir::VisibilityKind::Restricted { ref path, .. } => println!(
5252
"visible in module `{}`",
53-
print::to_string(print::NO_ANN, |s| s.print_path(path, false))
53+
rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_path(path, false))
5454
),
5555
hir::VisibilityKind::Inherited => println!("visibility inherited from outer item"),
5656
}
@@ -333,7 +333,7 @@ fn print_item(cx: &LateContext<'_, '_>, item: &hir::Item<'_>) {
333333
hir::VisibilityKind::Crate(_) => println!("visible crate wide"),
334334
hir::VisibilityKind::Restricted { ref path, .. } => println!(
335335
"visible in module `{}`",
336-
print::to_string(print::NO_ANN, |s| s.print_path(path, false))
336+
rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_path(path, false))
337337
),
338338
hir::VisibilityKind::Inherited => println!("visibility inherited from outer item"),
339339
}
@@ -427,7 +427,7 @@ fn print_pat(cx: &LateContext<'_, '_>, pat: &hir::Pat<'_>, indent: usize) {
427427
println!(
428428
"{}name: {}",
429429
ind,
430-
print::to_string(print::NO_ANN, |s| s.print_qpath(path, false))
430+
rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false))
431431
);
432432
println!("{}ignore leftover fields: {}", ind, ignore);
433433
println!("{}fields:", ind);
@@ -444,7 +444,7 @@ fn print_pat(cx: &LateContext<'_, '_>, pat: &hir::Pat<'_>, indent: usize) {
444444
println!(
445445
"{}path: {}",
446446
ind,
447-
print::to_string(print::NO_ANN, |s| s.print_qpath(path, false))
447+
rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false))
448448
);
449449
if let Some(dot_position) = opt_dots_position {
450450
println!("{}dot position: {}", ind, dot_position);

0 commit comments

Comments
 (0)
Please sign in to comment.