Skip to content
Merged

Rustup #5621

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::{walk_block, walk_expr, walk_pat, walk_stmt, NestedVisitorMap, Visitor};
use rustc_hir::{
def_id, BinOpKind, BindingAnnotation, Block, BorrowKind, Expr, ExprKind, GenericArg, HirId, LoopSource,
MatchSource, Mutability, Node, Pat, PatKind, QPath, Stmt, StmtKind,
def_id, BinOpKind, BindingAnnotation, Block, BorrowKind, Expr, ExprKind, GenericArg, HirId, InlineAsmOperand,
LoopSource, MatchSource, Mutability, Node, Pat, PatKind, QPath, Stmt, StmtKind,
};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::{LateContext, LateLintPass, LintContext};
Expand Down Expand Up @@ -693,6 +693,20 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult {
NeverLoopResult::AlwaysBreak
}
},
ExprKind::InlineAsm(ref asm) => asm
.operands
.iter()
.map(|o| match o {
InlineAsmOperand::In { expr, .. }
| InlineAsmOperand::InOut { expr, .. }
| InlineAsmOperand::Const { expr }
| InlineAsmOperand::Sym { expr } => never_loop_expr(expr, main_loop_id),
InlineAsmOperand::Out { expr, .. } => never_loop_expr_all(&mut expr.iter(), main_loop_id),
InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
never_loop_expr_all(&mut once(in_expr).chain(out_expr.iter()), main_loop_id)
},
})
.fold(NeverLoopResult::Otherwise, combine_both),
ExprKind::Struct(_, _, None)
| ExprKind::Yield(_, _)
| ExprKind::Closure(_, _, _, _, _)
Expand Down
4 changes: 4 additions & 0 deletions clippy_lints/src/utils/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,10 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
println!("Ret(None) = {};", current);
}
},
ExprKind::InlineAsm(_) => {
println!("InlineAsm(_) = {};", current);
println!(" // unimplemented: `ExprKind::InlineAsm` is not further destructured at the moment");
},
ExprKind::LlvmInlineAsm(_) => {
println!("LlvmInlineAsm(_) = {};", current);
println!(" // unimplemented: `ExprKind::LlvmInlineAsm` is not further destructured at the moment");
Expand Down
55 changes: 53 additions & 2 deletions clippy_lints/src/utils/hir_utils.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::consts::{constant_context, constant_simple};
use crate::utils::differing_macro_contexts;
use rustc_ast::ast::InlineAsmTemplatePiece;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_hir::{
BinOpKind, Block, BlockCheckMode, BodyId, BorrowKind, CaptureBy, Expr, ExprKind, Field, FnRetTy, GenericArg,
GenericArgs, Guard, Lifetime, LifetimeName, ParamName, Pat, PatKind, Path, PathSegment, QPath, Stmt, StmtKind, Ty,
TyKind, TypeBinding,
GenericArgs, Guard, InlineAsmOperand, Lifetime, LifetimeName, ParamName, Pat, PatKind, Path, PathSegment, QPath,
Stmt, StmtKind, Ty, TyKind, TypeBinding,
};
use rustc_lint::LateContext;
use rustc_middle::ich::StableHashingContextProvider;
Expand Down Expand Up @@ -474,6 +475,56 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
self.hash_expr(a);
self.hash_expr(i);
},
ExprKind::InlineAsm(ref asm) => {
for piece in asm.template {
match piece {
InlineAsmTemplatePiece::String(s) => s.hash(&mut self.s),
InlineAsmTemplatePiece::Placeholder {
operand_idx,
modifier,
span: _,
} => {
operand_idx.hash(&mut self.s);
modifier.hash(&mut self.s);
},
}
}
asm.options.hash(&mut self.s);
for op in asm.operands {
match op {
InlineAsmOperand::In { reg, expr } => {
reg.hash(&mut self.s);
self.hash_expr(expr);
},
InlineAsmOperand::Out { reg, late, expr } => {
reg.hash(&mut self.s);
late.hash(&mut self.s);
if let Some(expr) = expr {
self.hash_expr(expr);
}
},
InlineAsmOperand::InOut { reg, late, expr } => {
reg.hash(&mut self.s);
late.hash(&mut self.s);
self.hash_expr(expr);
},
InlineAsmOperand::SplitInOut {
reg,
late,
in_expr,
out_expr,
} => {
reg.hash(&mut self.s);
late.hash(&mut self.s);
self.hash_expr(in_expr);
if let Some(out_expr) = out_expr {
self.hash_expr(out_expr);
}
},
InlineAsmOperand::Const { expr } | InlineAsmOperand::Sym { expr } => self.hash_expr(expr),
}
}
},
ExprKind::LlvmInlineAsm(..) | ExprKind::Err => {},
ExprKind::Lit(ref l) => {
l.node.hash(&mut self.s);
Expand Down
27 changes: 26 additions & 1 deletion clippy_lints/src/utils/inspector.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! checks for attributes

use crate::utils::get_attr;
use rustc_ast::ast::Attribute;
use rustc_ast::ast::{Attribute, InlineAsmTemplatePiece};
use rustc_hir as hir;
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_session::Session;
Expand Down Expand Up @@ -282,6 +282,31 @@ fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, indent: usize) {
print_expr(cx, e, indent + 1);
}
},
hir::ExprKind::InlineAsm(ref asm) => {
println!("{}InlineAsm", ind);
println!("{}template: {}", ind, InlineAsmTemplatePiece::to_string(asm.template));
println!("{}options: {:?}", ind, asm.options);
println!("{}operands:", ind);
for op in asm.operands {
match op {
hir::InlineAsmOperand::In { expr, .. }
| hir::InlineAsmOperand::InOut { expr, .. }
| hir::InlineAsmOperand::Const { expr }
| hir::InlineAsmOperand::Sym { expr } => print_expr(cx, expr, indent + 1),
hir::InlineAsmOperand::Out { expr, .. } => {
if let Some(expr) = expr {
print_expr(cx, expr, indent + 1);
}
},
hir::InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
print_expr(cx, in_expr, indent + 1);
if let Some(out_expr) = out_expr {
print_expr(cx, out_expr, indent + 1);
}
},
}
}
},
hir::ExprKind::LlvmInlineAsm(ref asm) => {
let inputs = &asm.inputs_exprs;
let outputs = &asm.outputs_exprs;
Expand Down
2 changes: 2 additions & 0 deletions clippy_lints/src/utils/sugg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ impl<'a> Sugg<'a> {
| hir::ExprKind::Call(..)
| hir::ExprKind::Field(..)
| hir::ExprKind::Index(..)
| hir::ExprKind::InlineAsm(..)
| hir::ExprKind::LlvmInlineAsm(..)
| hir::ExprKind::Lit(..)
| hir::ExprKind::Loop(..)
Expand Down Expand Up @@ -150,6 +151,7 @@ impl<'a> Sugg<'a> {
| ast::ExprKind::Field(..)
| ast::ExprKind::ForLoop(..)
| ast::ExprKind::Index(..)
| ast::ExprKind::InlineAsm(..)
| ast::ExprKind::LlvmInlineAsm(..)
| ast::ExprKind::Lit(..)
| ast::ExprKind::Loop(..)
Expand Down
5 changes: 3 additions & 2 deletions clippy_lints/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ impl Write {
is_write: bool,
) -> (Option<StrLit>, Option<Expr>) {
use fmt_macros::{
AlignUnknown, ArgumentImplicitlyIs, ArgumentIs, ArgumentNamed, CountImplied, FormatSpec, Parser, Piece,
AlignUnknown, ArgumentImplicitlyIs, ArgumentIs, ArgumentNamed, CountImplied, FormatSpec, ParseMode, Parser,
Piece,
};
let tts = tts.clone();

Expand All @@ -376,7 +377,7 @@ impl Write {
};
let tmp = fmtstr.symbol.as_str();
let mut args = vec![];
let mut fmt_parser = Parser::new(&tmp, None, Vec::new(), false);
let mut fmt_parser = Parser::new(&tmp, None, None, false, ParseMode::Format);
while let Some(piece) = fmt_parser.next() {
if !fmt_parser.errors.is_empty() {
return (None, expr);
Expand Down
2 changes: 1 addition & 1 deletion mini-macro/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(proc_macro_quote, proc_macro_hygiene)]
#![feature(proc_macro_quote)]
#![deny(rust_2018_idioms)]
// FIXME: Remove this attribute once the weird failure is gone.
#![allow(unused_extern_crates)]
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/auxiliary/proc_macro_derive.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// no-prefer-dynamic

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

extern crate proc_macro;

Expand Down
1 change: 0 additions & 1 deletion tests/ui/crashes/ice-3741.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// aux-build:proc_macro_crash.rs
// run-pass

#![feature(proc_macro_hygiene)]
#![warn(clippy::suspicious_else_formatting)]

extern crate proc_macro_crash;
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/ptr_offset_with_cast.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ fn main() {
let offset_isize = 1_isize;

unsafe {
ptr.add(offset_usize);
ptr.offset(offset_isize as isize);
ptr.offset(offset_u8 as isize);
let _ = ptr.add(offset_usize);
let _ = ptr.offset(offset_isize as isize);
let _ = ptr.offset(offset_u8 as isize);

ptr.wrapping_add(offset_usize);
ptr.wrapping_offset(offset_isize as isize);
ptr.wrapping_offset(offset_u8 as isize);
let _ = ptr.wrapping_add(offset_usize);
let _ = ptr.wrapping_offset(offset_isize as isize);
let _ = ptr.wrapping_offset(offset_u8 as isize);
}
}
12 changes: 6 additions & 6 deletions tests/ui/ptr_offset_with_cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ fn main() {
let offset_isize = 1_isize;

unsafe {
ptr.offset(offset_usize as isize);
ptr.offset(offset_isize as isize);
ptr.offset(offset_u8 as isize);
let _ = ptr.offset(offset_usize as isize);
let _ = ptr.offset(offset_isize as isize);
let _ = ptr.offset(offset_u8 as isize);

ptr.wrapping_offset(offset_usize as isize);
ptr.wrapping_offset(offset_isize as isize);
ptr.wrapping_offset(offset_u8 as isize);
let _ = ptr.wrapping_offset(offset_usize as isize);
let _ = ptr.wrapping_offset(offset_isize as isize);
let _ = ptr.wrapping_offset(offset_u8 as isize);
}
}
12 changes: 6 additions & 6 deletions tests/ui/ptr_offset_with_cast.stderr
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
error: use of `offset` with a `usize` casted to an `isize`
--> $DIR/ptr_offset_with_cast.rs:12:9
--> $DIR/ptr_offset_with_cast.rs:12:17
|
LL | ptr.offset(offset_usize as isize);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr.add(offset_usize)`
LL | let _ = ptr.offset(offset_usize as isize);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr.add(offset_usize)`
|
= note: `-D clippy::ptr-offset-with-cast` implied by `-D warnings`

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

error: aborting due to 2 previous errors