Skip to content

Commit 34ba597

Browse files
committed
Auto merge of #5621 - flip1995:rustup, r=phansch
Rustup @oli-obk Do you know, how we can enforce (ui-)tests pass in rust-lang/rust for Clippy? I can open a PR for this, if you tell me what would be necessary for this. changelog: none
2 parents e214ea8 + f28f1f1 commit 34ba597

File tree

12 files changed

+124
-28
lines changed

12 files changed

+124
-28
lines changed

clippy_lints/src/loops.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use rustc_errors::Applicability;
1616
use rustc_hir::def::{DefKind, Res};
1717
use rustc_hir::intravisit::{walk_block, walk_expr, walk_pat, walk_stmt, NestedVisitorMap, Visitor};
1818
use rustc_hir::{
19-
def_id, BinOpKind, BindingAnnotation, Block, BorrowKind, Expr, ExprKind, GenericArg, HirId, LoopSource,
20-
MatchSource, Mutability, Node, Pat, PatKind, QPath, Stmt, StmtKind,
19+
def_id, BinOpKind, BindingAnnotation, Block, BorrowKind, Expr, ExprKind, GenericArg, HirId, InlineAsmOperand,
20+
LoopSource, MatchSource, Mutability, Node, Pat, PatKind, QPath, Stmt, StmtKind,
2121
};
2222
use rustc_infer::infer::TyCtxtInferExt;
2323
use rustc_lint::{LateContext, LateLintPass, LintContext};
@@ -693,6 +693,20 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult {
693693
NeverLoopResult::AlwaysBreak
694694
}
695695
},
696+
ExprKind::InlineAsm(ref asm) => asm
697+
.operands
698+
.iter()
699+
.map(|o| match o {
700+
InlineAsmOperand::In { expr, .. }
701+
| InlineAsmOperand::InOut { expr, .. }
702+
| InlineAsmOperand::Const { expr }
703+
| InlineAsmOperand::Sym { expr } => never_loop_expr(expr, main_loop_id),
704+
InlineAsmOperand::Out { expr, .. } => never_loop_expr_all(&mut expr.iter(), main_loop_id),
705+
InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
706+
never_loop_expr_all(&mut once(in_expr).chain(out_expr.iter()), main_loop_id)
707+
},
708+
})
709+
.fold(NeverLoopResult::Otherwise, combine_both),
696710
ExprKind::Struct(_, _, None)
697711
| ExprKind::Yield(_, _)
698712
| ExprKind::Closure(_, _, _, _, _)

clippy_lints/src/utils/author.rs

+4
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,10 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
469469
println!("Ret(None) = {};", current);
470470
}
471471
},
472+
ExprKind::InlineAsm(_) => {
473+
println!("InlineAsm(_) = {};", current);
474+
println!(" // unimplemented: `ExprKind::InlineAsm` is not further destructured at the moment");
475+
},
472476
ExprKind::LlvmInlineAsm(_) => {
473477
println!("LlvmInlineAsm(_) = {};", current);
474478
println!(" // unimplemented: `ExprKind::LlvmInlineAsm` is not further destructured at the moment");

clippy_lints/src/utils/hir_utils.rs

+53-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use crate::consts::{constant_context, constant_simple};
22
use crate::utils::differing_macro_contexts;
3+
use rustc_ast::ast::InlineAsmTemplatePiece;
34
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
45
use rustc_hir::{
56
BinOpKind, Block, BlockCheckMode, BodyId, BorrowKind, CaptureBy, Expr, ExprKind, Field, FnRetTy, GenericArg,
6-
GenericArgs, Guard, Lifetime, LifetimeName, ParamName, Pat, PatKind, Path, PathSegment, QPath, Stmt, StmtKind, Ty,
7-
TyKind, TypeBinding,
7+
GenericArgs, Guard, InlineAsmOperand, Lifetime, LifetimeName, ParamName, Pat, PatKind, Path, PathSegment, QPath,
8+
Stmt, StmtKind, Ty, TyKind, TypeBinding,
89
};
910
use rustc_lint::LateContext;
1011
use rustc_middle::ich::StableHashingContextProvider;
@@ -474,6 +475,56 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
474475
self.hash_expr(a);
475476
self.hash_expr(i);
476477
},
478+
ExprKind::InlineAsm(ref asm) => {
479+
for piece in asm.template {
480+
match piece {
481+
InlineAsmTemplatePiece::String(s) => s.hash(&mut self.s),
482+
InlineAsmTemplatePiece::Placeholder {
483+
operand_idx,
484+
modifier,
485+
span: _,
486+
} => {
487+
operand_idx.hash(&mut self.s);
488+
modifier.hash(&mut self.s);
489+
},
490+
}
491+
}
492+
asm.options.hash(&mut self.s);
493+
for op in asm.operands {
494+
match op {
495+
InlineAsmOperand::In { reg, expr } => {
496+
reg.hash(&mut self.s);
497+
self.hash_expr(expr);
498+
},
499+
InlineAsmOperand::Out { reg, late, expr } => {
500+
reg.hash(&mut self.s);
501+
late.hash(&mut self.s);
502+
if let Some(expr) = expr {
503+
self.hash_expr(expr);
504+
}
505+
},
506+
InlineAsmOperand::InOut { reg, late, expr } => {
507+
reg.hash(&mut self.s);
508+
late.hash(&mut self.s);
509+
self.hash_expr(expr);
510+
},
511+
InlineAsmOperand::SplitInOut {
512+
reg,
513+
late,
514+
in_expr,
515+
out_expr,
516+
} => {
517+
reg.hash(&mut self.s);
518+
late.hash(&mut self.s);
519+
self.hash_expr(in_expr);
520+
if let Some(out_expr) = out_expr {
521+
self.hash_expr(out_expr);
522+
}
523+
},
524+
InlineAsmOperand::Const { expr } | InlineAsmOperand::Sym { expr } => self.hash_expr(expr),
525+
}
526+
}
527+
},
477528
ExprKind::LlvmInlineAsm(..) | ExprKind::Err => {},
478529
ExprKind::Lit(ref l) => {
479530
l.node.hash(&mut self.s);

clippy_lints/src/utils/inspector.rs

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! checks for attributes
22
33
use crate::utils::get_attr;
4-
use rustc_ast::ast::Attribute;
4+
use rustc_ast::ast::{Attribute, InlineAsmTemplatePiece};
55
use rustc_hir as hir;
66
use rustc_lint::{LateContext, LateLintPass, LintContext};
77
use rustc_session::Session;
@@ -282,6 +282,31 @@ fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, indent: usize) {
282282
print_expr(cx, e, indent + 1);
283283
}
284284
},
285+
hir::ExprKind::InlineAsm(ref asm) => {
286+
println!("{}InlineAsm", ind);
287+
println!("{}template: {}", ind, InlineAsmTemplatePiece::to_string(asm.template));
288+
println!("{}options: {:?}", ind, asm.options);
289+
println!("{}operands:", ind);
290+
for op in asm.operands {
291+
match op {
292+
hir::InlineAsmOperand::In { expr, .. }
293+
| hir::InlineAsmOperand::InOut { expr, .. }
294+
| hir::InlineAsmOperand::Const { expr }
295+
| hir::InlineAsmOperand::Sym { expr } => print_expr(cx, expr, indent + 1),
296+
hir::InlineAsmOperand::Out { expr, .. } => {
297+
if let Some(expr) = expr {
298+
print_expr(cx, expr, indent + 1);
299+
}
300+
},
301+
hir::InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
302+
print_expr(cx, in_expr, indent + 1);
303+
if let Some(out_expr) = out_expr {
304+
print_expr(cx, out_expr, indent + 1);
305+
}
306+
},
307+
}
308+
}
309+
},
285310
hir::ExprKind::LlvmInlineAsm(ref asm) => {
286311
let inputs = &asm.inputs_exprs;
287312
let outputs = &asm.outputs_exprs;

clippy_lints/src/utils/sugg.rs

+2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ impl<'a> Sugg<'a> {
108108
| hir::ExprKind::Call(..)
109109
| hir::ExprKind::Field(..)
110110
| hir::ExprKind::Index(..)
111+
| hir::ExprKind::InlineAsm(..)
111112
| hir::ExprKind::LlvmInlineAsm(..)
112113
| hir::ExprKind::Lit(..)
113114
| hir::ExprKind::Loop(..)
@@ -150,6 +151,7 @@ impl<'a> Sugg<'a> {
150151
| ast::ExprKind::Field(..)
151152
| ast::ExprKind::ForLoop(..)
152153
| ast::ExprKind::Index(..)
154+
| ast::ExprKind::InlineAsm(..)
153155
| ast::ExprKind::LlvmInlineAsm(..)
154156
| ast::ExprKind::Lit(..)
155157
| ast::ExprKind::Loop(..)

clippy_lints/src/write.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ impl Write {
353353
is_write: bool,
354354
) -> (Option<StrLit>, Option<Expr>) {
355355
use fmt_macros::{
356-
AlignUnknown, ArgumentImplicitlyIs, ArgumentIs, ArgumentNamed, CountImplied, FormatSpec, Parser, Piece,
356+
AlignUnknown, ArgumentImplicitlyIs, ArgumentIs, ArgumentNamed, CountImplied, FormatSpec, ParseMode, Parser,
357+
Piece,
357358
};
358359
let tts = tts.clone();
359360

@@ -376,7 +377,7 @@ impl Write {
376377
};
377378
let tmp = fmtstr.symbol.as_str();
378379
let mut args = vec![];
379-
let mut fmt_parser = Parser::new(&tmp, None, Vec::new(), false);
380+
let mut fmt_parser = Parser::new(&tmp, None, None, false, ParseMode::Format);
380381
while let Some(piece) = fmt_parser.next() {
381382
if !fmt_parser.errors.is_empty() {
382383
return (None, expr);

mini-macro/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(proc_macro_quote, proc_macro_hygiene)]
1+
#![feature(proc_macro_quote)]
22
#![deny(rust_2018_idioms)]
33
// FIXME: Remove this attribute once the weird failure is gone.
44
#![allow(unused_extern_crates)]

tests/ui/auxiliary/proc_macro_derive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// no-prefer-dynamic
22

33
#![crate_type = "proc-macro"]
4-
#![feature(repr128, proc_macro_hygiene, proc_macro_quote)]
4+
#![feature(repr128, proc_macro_quote)]
55

66
extern crate proc_macro;
77

tests/ui/crashes/ice-3741.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// aux-build:proc_macro_crash.rs
22
// run-pass
33

4-
#![feature(proc_macro_hygiene)]
54
#![warn(clippy::suspicious_else_formatting)]
65

76
extern crate proc_macro_crash;

tests/ui/ptr_offset_with_cast.fixed

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ fn main() {
99
let offset_isize = 1_isize;
1010

1111
unsafe {
12-
ptr.add(offset_usize);
13-
ptr.offset(offset_isize as isize);
14-
ptr.offset(offset_u8 as isize);
12+
let _ = ptr.add(offset_usize);
13+
let _ = ptr.offset(offset_isize as isize);
14+
let _ = ptr.offset(offset_u8 as isize);
1515

16-
ptr.wrapping_add(offset_usize);
17-
ptr.wrapping_offset(offset_isize as isize);
18-
ptr.wrapping_offset(offset_u8 as isize);
16+
let _ = ptr.wrapping_add(offset_usize);
17+
let _ = ptr.wrapping_offset(offset_isize as isize);
18+
let _ = ptr.wrapping_offset(offset_u8 as isize);
1919
}
2020
}

tests/ui/ptr_offset_with_cast.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ fn main() {
99
let offset_isize = 1_isize;
1010

1111
unsafe {
12-
ptr.offset(offset_usize as isize);
13-
ptr.offset(offset_isize as isize);
14-
ptr.offset(offset_u8 as isize);
12+
let _ = ptr.offset(offset_usize as isize);
13+
let _ = ptr.offset(offset_isize as isize);
14+
let _ = ptr.offset(offset_u8 as isize);
1515

16-
ptr.wrapping_offset(offset_usize as isize);
17-
ptr.wrapping_offset(offset_isize as isize);
18-
ptr.wrapping_offset(offset_u8 as isize);
16+
let _ = ptr.wrapping_offset(offset_usize as isize);
17+
let _ = ptr.wrapping_offset(offset_isize as isize);
18+
let _ = ptr.wrapping_offset(offset_u8 as isize);
1919
}
2020
}

tests/ui/ptr_offset_with_cast.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
error: use of `offset` with a `usize` casted to an `isize`
2-
--> $DIR/ptr_offset_with_cast.rs:12:9
2+
--> $DIR/ptr_offset_with_cast.rs:12:17
33
|
4-
LL | ptr.offset(offset_usize as isize);
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr.add(offset_usize)`
4+
LL | let _ = ptr.offset(offset_usize as isize);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr.add(offset_usize)`
66
|
77
= note: `-D clippy::ptr-offset-with-cast` implied by `-D warnings`
88

99
error: use of `wrapping_offset` with a `usize` casted to an `isize`
10-
--> $DIR/ptr_offset_with_cast.rs:16:9
10+
--> $DIR/ptr_offset_with_cast.rs:16:17
1111
|
12-
LL | ptr.wrapping_offset(offset_usize as isize);
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr.wrapping_add(offset_usize)`
12+
LL | let _ = ptr.wrapping_offset(offset_usize as isize);
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr.wrapping_add(offset_usize)`
1414

1515
error: aborting due to 2 previous errors
1616

0 commit comments

Comments
 (0)