Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 76d7a26

Browse files
committed
second part
1 parent 66883bc commit 76d7a26

File tree

24 files changed

+279
-307
lines changed

24 files changed

+279
-307
lines changed

‎compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3008,13 +3008,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
30083008

30093009
/// Returns whether the given expression is an `else if`.
30103010
fn is_else_if_block(&self, expr: &hir::Expr<'_>) -> bool {
3011-
if let hir::ExprKind::If(..) = expr.kind {
3012-
if let Node::Expr(hir::Expr {
3013-
kind: hir::ExprKind::If(_, _, Some(else_expr)), ..
3014-
}) = self.tcx.parent_hir_node(expr.hir_id)
3015-
{
3016-
return else_expr.hir_id == expr.hir_id;
3017-
}
3011+
if let hir::ExprKind::If(..) = expr.kind
3012+
&& let Node::Expr(hir::Expr { kind: hir::ExprKind::If(_, _, Some(else_expr)), .. }) =
3013+
self.tcx.parent_hir_node(expr.hir_id)
3014+
{
3015+
return else_expr.hir_id == expr.hir_id;
30183016
}
30193017
false
30203018
}

‎compiler/rustc_hir_typeck/src/method/confirm.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -669,17 +669,17 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
669669

670670
fn check_for_illegal_method_calls(&self, pick: &probe::Pick<'_>) {
671671
// Disallow calls to the method `drop` defined in the `Drop` trait.
672-
if let Some(trait_def_id) = pick.item.trait_container(self.tcx){
673-
if let Err(e) = callee::check_legal_trait_for_method_call(
672+
if let Some(trait_def_id) = pick.item.trait_container(self.tcx)
673+
&& let Err(e) = callee::check_legal_trait_for_method_call(
674674
self.tcx,
675675
self.span,
676676
Some(self.self_expr.span),
677677
self.call_expr.span,
678678
trait_def_id,
679679
self.body_id.to_def_id(),
680-
){
681-
self.set_tainted_by_errors(e);
682-
}
680+
)
681+
{
682+
self.set_tainted_by_errors(e);
683683
}
684684
}
685685

‎compiler/rustc_hir_typeck/src/typeck_root_ctxt.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,12 @@ impl<'tcx> TypeckRootCtxt<'tcx> {
165165

166166
if let ty::PredicateKind::Clause(ty::ClauseKind::Projection(predicate)) =
167167
obligation.predicate.kind().skip_binder()
168-
{
169168
// If the projection predicate (Foo::Bar == X) has X as a non-TyVid,
170169
// we need to make it into one.
171-
if let Some(vid) = predicate.term.as_type().and_then(|ty| ty.ty_vid()){
172-
debug!("infer_var_info: {:?}.output = true", vid);
173-
infer_var_info.entry(vid).or_default().output = true;
174-
}
170+
&& let Some(vid) = predicate.term.as_type().and_then(|ty| ty.ty_vid())
171+
{
172+
debug!("infer_var_info: {:?}.output = true", vid);
173+
infer_var_info.entry(vid).or_default().output = true;
175174
}
176175
}
177176
}

‎compiler/rustc_hir_typeck/src/writeback.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,21 +227,19 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
227227
self.typeck_results.type_dependent_defs_mut().remove(e.hir_id);
228228
self.typeck_results.node_args_mut().remove(e.hir_id);
229229

230-
if let Some(a) = self.typeck_results.adjustments_mut().get_mut(base.hir_id){
230+
if let Some(a) = self.typeck_results.adjustments_mut().get_mut(base.hir_id)
231231
// Discard the need for a mutable borrow
232-
233232
// Extra adjustment made when indexing causes a drop
234233
// of size information - we need to get rid of it
235234
// Since this is "after" the other adjustment to be
236235
// discarded, we do an extra `pop()`
237-
if let Some(Adjustment {
236+
&& let Some(Adjustment {
238237
kind: Adjust::Pointer(PointerCoercion::Unsize),
239238
..
240239
}) = a.pop()
241-
{
242-
// So the borrow discard actually happens here
243-
a.pop();
244-
}
240+
{
241+
// So the borrow discard actually happens here
242+
a.pop();
245243
}
246244
}
247245
}

‎compiler/rustc_lint/src/builtin.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,31 +2446,31 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
24462446

24472447
/// Determine if this expression is a "dangerous initialization".
24482448
fn is_dangerous_init(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option<InitKind> {
2449-
if let hir::ExprKind::Call(path_expr, args) = expr.kind{
2449+
if let hir::ExprKind::Call(path_expr, args) = expr.kind
24502450
// Find calls to `mem::{uninitialized,zeroed}` methods.
2451-
if let hir::ExprKind::Path(ref qpath) = path_expr.kind{
2452-
let def_id = cx.qpath_res(qpath, path_expr.hir_id).opt_def_id()?;
2453-
matchcx.tcx.get_diagnostic_name(def_id){
2454-
Some(sym::mem_zeroed) => returnSome(InitKind::Zeroed),
2455-
Some(sym::mem_uninitialized) => return Some(InitKind::Uninit),
2456-
Some(sym::transmute)ifis_zero(&args[0])=> return Some(InitKind::Zeroed),
2457-
_ => {}
2458-
}
2451+
&& let hir::ExprKind::Path(ref qpath) = path_expr.kind
2452+
{
2453+
let def_id = cx.qpath_res(qpath, path_expr.hir_id).opt_def_id()?;
2454+
match cx.tcx.get_diagnostic_name(def_id){
2455+
Some(sym::mem_zeroed) => return Some(InitKind::Zeroed),
2456+
Some(sym::mem_uninitialized)=> return Some(InitKind::Uninit),
2457+
Some(sym::transmute)ifis_zero(&args[0])=> returnSome(InitKind::Zeroed),
2458+
_ => {}
24592459
}
24602460
} else if let hir::ExprKind::MethodCall(_, receiver, ..) = expr.kind {
24612461
// Find problematic calls to `MaybeUninit::assume_init`.
24622462
let def_id = cx.typeck_results().type_dependent_def_id(expr.hir_id)?;
24632463
if cx.tcx.is_diagnostic_item(sym::assume_init, def_id) {
24642464
// This is a call to *some* method named `assume_init`.
24652465
// See if the `self` parameter is one of the dangerous constructors.
2466-
if let hir::ExprKind::Call(path_expr, _) = receiver.kind{
2467-
if let hir::ExprKind::Path(ref qpath) = path_expr.kind{
2468-
let def_id = cx.qpath_res(qpath, path_expr.hir_id).opt_def_id()?;
2469-
matchcx.tcx.get_diagnostic_name(def_id){
2470-
Some(sym::maybe_uninit_zeroed) => returnSome(InitKind::Zeroed),
2471-
Some(sym::maybe_uninit_uninit) => return Some(InitKind::Uninit),
2472-
_ => {}
2473-
}
2466+
if let hir::ExprKind::Call(path_expr, _) = receiver.kind
2467+
&& let hir::ExprKind::Path(ref qpath) = path_expr.kind
2468+
{
2469+
let def_id = cx.qpath_res(qpath, path_expr.hir_id).opt_def_id()?;
2470+
match cx.tcx.get_diagnostic_name(def_id){
2471+
Some(sym::maybe_uninit_zeroed) => return Some(InitKind::Zeroed),
2472+
Some(sym::maybe_uninit_uninit)=> returnSome(InitKind::Uninit),
2473+
_ => {}
24742474
}
24752475
}
24762476
}
@@ -2724,13 +2724,13 @@ impl<'tcx> LateLintPass<'tcx> for DerefNullPtr {
27242724
}
27252725
// check for call to `core::ptr::null` or `core::ptr::null_mut`
27262726
hir::ExprKind::Call(path, _) => {
2727-
if let hir::ExprKind::Path(ref qpath) = path.kind{
2728-
if let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id(){
2729-
returnmatches!(
2730-
cx.tcx.get_diagnostic_name(def_id),
2731-
Some(sym::ptr_null | sym::ptr_null_mut)
2732-
);
2733-
}
2727+
if let hir::ExprKind::Path(ref qpath) = path.kind
2728+
&& let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id()
2729+
{
2730+
returnmatches!(
2731+
cx.tcx.get_diagnostic_name(def_id),
2732+
Some(sym::ptr_null | sym::ptr_null_mut)
2733+
);
27342734
}
27352735
}
27362736
_ => {}

‎compiler/rustc_lint/src/internal.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -411,22 +411,21 @@ declare_lint_pass!(LintPassImpl => [LINT_PASS_IMPL_WITHOUT_MACRO]);
411411

412412
impl EarlyLintPass for LintPassImpl {
413413
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) {
414-
if let ast::ItemKind::Impl(box ast::Impl { of_trait: Some(lint_pass), .. }) = &item.kind {
415-
if let Some(last) = lint_pass.path.segments.last() {
416-
if last.ident.name == sym::LintPass {
417-
let expn_data = lint_pass.path.span.ctxt().outer_expn_data();
418-
let call_site = expn_data.call_site;
419-
if expn_data.kind != ExpnKind::Macro(MacroKind::Bang, sym::impl_lint_pass)
420-
&& call_site.ctxt().outer_expn_data().kind
421-
!= ExpnKind::Macro(MacroKind::Bang, sym::declare_lint_pass)
422-
{
423-
cx.emit_span_lint(
424-
LINT_PASS_IMPL_WITHOUT_MACRO,
425-
lint_pass.path.span,
426-
LintPassByHand,
427-
);
428-
}
429-
}
414+
if let ast::ItemKind::Impl(box ast::Impl { of_trait: Some(lint_pass), .. }) = &item.kind
415+
&& let Some(last) = lint_pass.path.segments.last()
416+
&& last.ident.name == sym::LintPass
417+
{
418+
let expn_data = lint_pass.path.span.ctxt().outer_expn_data();
419+
let call_site = expn_data.call_site;
420+
if expn_data.kind != ExpnKind::Macro(MacroKind::Bang, sym::impl_lint_pass)
421+
&& call_site.ctxt().outer_expn_data().kind
422+
!= ExpnKind::Macro(MacroKind::Bang, sym::declare_lint_pass)
423+
{
424+
cx.emit_span_lint(
425+
LINT_PASS_IMPL_WITHOUT_MACRO,
426+
lint_pass.path.span,
427+
LintPassByHand,
428+
);
430429
}
431430
}
432431
}

‎compiler/rustc_lint/src/map_unit_fn.rs

Lines changed: 52 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -43,56 +43,50 @@ impl<'tcx> LateLintPass<'tcx> for MapUnitFn {
4343
return;
4444
}
4545

46-
if let StmtKind::Semi(expr) = stmt.kind {
47-
if let ExprKind::MethodCall(path, receiver, args, span) = expr.kind {
48-
if path.ident.name.as_str() == "map" {
49-
if receiver.span.from_expansion()
50-
|| args.iter().any(|e| e.span.from_expansion())
51-
|| !is_impl_slice(cx, receiver)
52-
|| !is_diagnostic_name(cx, expr.hir_id, "IteratorMap")
53-
{
54-
return;
46+
if let StmtKind::Semi(expr) = stmt.kind
47+
&& let ExprKind::MethodCall(path, receiver, args, span) = expr.kind
48+
{
49+
if path.ident.name.as_str() == "map" {
50+
if receiver.span.from_expansion()
51+
|| args.iter().any(|e| e.span.from_expansion())
52+
|| !is_impl_slice(cx, receiver)
53+
|| !is_diagnostic_name(cx, expr.hir_id, "IteratorMap")
54+
{
55+
return;
56+
}
57+
let arg_ty = cx.typeck_results().expr_ty(&args[0]);
58+
let default_span = args[0].span;
59+
if let ty::FnDef(id, _) = arg_ty.kind() {
60+
let fn_ty = cx.tcx.fn_sig(id).skip_binder();
61+
let ret_ty = fn_ty.output().skip_binder();
62+
if is_unit_type(ret_ty) {
63+
cx.emit_span_lint(
64+
MAP_UNIT_FN,
65+
span,
66+
MappingToUnit {
67+
function_label: cx.tcx.span_of_impl(*id).unwrap_or(default_span),
68+
argument_label: args[0].span,
69+
map_label: span,
70+
suggestion: path.ident.span,
71+
replace: "for_each".to_string(),
72+
},
73+
)
5574
}
56-
let arg_ty = cx.typeck_results().expr_ty(&args[0]);
57-
let default_span = args[0].span;
58-
if let ty::FnDef(id, _) = arg_ty.kind() {
59-
let fn_ty = cx.tcx.fn_sig(id).skip_binder();
60-
let ret_ty = fn_ty.output().skip_binder();
61-
if is_unit_type(ret_ty) {
62-
cx.emit_span_lint(
63-
MAP_UNIT_FN,
64-
span,
65-
MappingToUnit {
66-
function_label: cx
67-
.tcx
68-
.span_of_impl(*id)
69-
.unwrap_or(default_span),
70-
argument_label: args[0].span,
71-
map_label: span,
72-
suggestion: path.ident.span,
73-
replace: "for_each".to_string(),
74-
},
75-
)
76-
}
77-
} else if let ty::Closure(id, subs) = arg_ty.kind() {
78-
let cl_ty = subs.as_closure().sig();
79-
let ret_ty = cl_ty.output().skip_binder();
80-
if is_unit_type(ret_ty) {
81-
cx.emit_span_lint(
82-
MAP_UNIT_FN,
83-
span,
84-
MappingToUnit {
85-
function_label: cx
86-
.tcx
87-
.span_of_impl(*id)
88-
.unwrap_or(default_span),
89-
argument_label: args[0].span,
90-
map_label: span,
91-
suggestion: path.ident.span,
92-
replace: "for_each".to_string(),
93-
},
94-
)
95-
}
75+
} else if let ty::Closure(id, subs) = arg_ty.kind() {
76+
let cl_ty = subs.as_closure().sig();
77+
let ret_ty = cl_ty.output().skip_binder();
78+
if is_unit_type(ret_ty) {
79+
cx.emit_span_lint(
80+
MAP_UNIT_FN,
81+
span,
82+
MappingToUnit {
83+
function_label: cx.tcx.span_of_impl(*id).unwrap_or(default_span),
84+
argument_label: args[0].span,
85+
map_label: span,
86+
suggestion: path.ident.span,
87+
replace: "for_each".to_string(),
88+
},
89+
)
9690
}
9791
}
9892
}
@@ -101,10 +95,10 @@ impl<'tcx> LateLintPass<'tcx> for MapUnitFn {
10195
}
10296

10397
fn is_impl_slice(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
104-
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id){
105-
if let Some(impl_id) = cx.tcx.impl_of_method(method_id){
106-
return cx.tcx.type_of(impl_id).skip_binder().is_slice();
107-
}
98+
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
99+
&& let Some(impl_id) = cx.tcx.impl_of_method(method_id)
100+
{
101+
return cx.tcx.type_of(impl_id).skip_binder().is_slice();
108102
}
109103
false
110104
}
@@ -114,11 +108,11 @@ fn is_unit_type(ty: Ty<'_>) -> bool {
114108
}
115109

116110
fn is_diagnostic_name(cx: &LateContext<'_>, id: HirId, name: &str) -> bool {
117-
if let Some(def_id) = cx.typeck_results().type_dependent_def_id(id){
118-
if let Some(item) = cx.tcx.get_diagnostic_name(def_id){
119-
if item.as_str() == name {
120-
returntrue;
121-
}
111+
if let Some(def_id) = cx.typeck_results().type_dependent_def_id(id)
112+
&& let Some(item) = cx.tcx.get_diagnostic_name(def_id)
113+
{
114+
if item.as_str() == name {
115+
returntrue;
122116
}
123117
}
124118
false

‎compiler/rustc_lint/src/non_fmt_panic.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -48,39 +48,39 @@ declare_lint_pass!(NonPanicFmt => [NON_FMT_PANICS]);
4848

4949
impl<'tcx> LateLintPass<'tcx> for NonPanicFmt {
5050
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
51-
if let hir::ExprKind::Call(f, [arg]) = &expr.kind {
52-
if let &ty::FnDef(def_id, _) = cx.typeck_results().expr_ty(f).kind() {
53-
let f_diagnostic_name = cx.tcx.get_diagnostic_name(def_id);
51+
if let hir::ExprKind::Call(f, [arg]) = &expr.kind
52+
&& let &ty::FnDef(def_id, _) = cx.typeck_results().expr_ty(f).kind()
53+
{
54+
let f_diagnostic_name = cx.tcx.get_diagnostic_name(def_id);
5455

55-
if cx.tcx.is_lang_item(def_id, LangItem::BeginPanic)
56-
|| cx.tcx.is_lang_item(def_id, LangItem::Panic)
57-
|| f_diagnostic_name == Some(sym::panic_str_2015)
58-
{
59-
if let Some(id) = f.span.ctxt().outer_expn_data().macro_def_id {
60-
if matches!(
61-
cx.tcx.get_diagnostic_name(id),
62-
Some(sym::core_panic_2015_macro | sym::std_panic_2015_macro)
63-
) {
64-
check_panic(cx, f, arg);
65-
}
66-
}
67-
} else if f_diagnostic_name == Some(sym::unreachable_display) {
68-
if let Some(id) = f.span.ctxt().outer_expn_data().macro_def_id {
69-
if cx.tcx.is_diagnostic_item(sym::unreachable_2015_macro, id) {
70-
check_panic(
71-
cx,
72-
f,
73-
// This is safe because we checked above that the callee is indeed
74-
// unreachable_display
75-
match &arg.kind {
76-
// Get the borrowed arg not the borrow
77-
hir::ExprKind::AddrOf(ast::BorrowKind::Ref, _, arg) => arg,
78-
_ => bug!("call to unreachable_display without borrow"),
79-
},
80-
);
81-
}
56+
if cx.tcx.is_lang_item(def_id, LangItem::BeginPanic)
57+
|| cx.tcx.is_lang_item(def_id, LangItem::Panic)
58+
|| f_diagnostic_name == Some(sym::panic_str_2015)
59+
{
60+
if let Some(id) = f.span.ctxt().outer_expn_data().macro_def_id {
61+
if matches!(
62+
cx.tcx.get_diagnostic_name(id),
63+
Some(sym::core_panic_2015_macro | sym::std_panic_2015_macro)
64+
) {
65+
check_panic(cx, f, arg);
8266
}
8367
}
68+
} else if f_diagnostic_name == Some(sym::unreachable_display) {
69+
if let Some(id) = f.span.ctxt().outer_expn_data().macro_def_id
70+
&& cx.tcx.is_diagnostic_item(sym::unreachable_2015_macro, id)
71+
{
72+
check_panic(
73+
cx,
74+
f,
75+
// This is safe because we checked above that the callee is indeed
76+
// unreachable_display
77+
match &arg.kind {
78+
// Get the borrowed arg not the borrow
79+
hir::ExprKind::AddrOf(ast::BorrowKind::Ref, _, arg) => arg,
80+
_ => bug!("call to unreachable_display without borrow"),
81+
},
82+
);
83+
}
8484
}
8585
}
8686
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /