Rustup to 2018-05-11
This commit is contained in:
parent
be3cba8852
commit
665cf96221
@ -426,7 +426,7 @@ pub fn miri_to_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, result: &ty::Const<'
|
||||
_ => None,
|
||||
},
|
||||
ConstVal::Value(Value::ByValPair(PrimVal::Ptr(ptr), PrimVal::Bytes(n))) => match result.ty.sty {
|
||||
ty::TyRef(_, tam) => match tam.ty.sty {
|
||||
ty::TyRef(_, tam, _) => match tam.sty {
|
||||
ty::TyStr => {
|
||||
let alloc = tcx
|
||||
.interpret_interner
|
||||
|
@ -743,7 +743,7 @@ struct FixedOffsetVar {
|
||||
|
||||
fn is_slice_like<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty) -> bool {
|
||||
let is_slice = match ty.sty {
|
||||
ty::TyRef(_, ref subty) => is_slice_like(cx, subty.ty),
|
||||
ty::TyRef(_, subty, _) => is_slice_like(cx, subty),
|
||||
ty::TySlice(..) | ty::TyArray(..) => true,
|
||||
_ => false,
|
||||
};
|
||||
@ -1365,9 +1365,9 @@ fn check_for_loop_over_map_kv<'a, 'tcx>(
|
||||
if pat.len() == 2 {
|
||||
let arg_span = arg.span;
|
||||
let (new_pat_span, kind, ty, mutbl) = match cx.tables.expr_ty(arg).sty {
|
||||
ty::TyRef(_, ref tam) => match (&pat[0].node, &pat[1].node) {
|
||||
(key, _) if pat_is_wild(key, body) => (pat[1].span, "value", tam.ty, tam.mutbl),
|
||||
(_, value) if pat_is_wild(value, body) => (pat[0].span, "key", tam.ty, MutImmutable),
|
||||
ty::TyRef(_, ty, mutbl) => match (&pat[0].node, &pat[1].node) {
|
||||
(key, _) if pat_is_wild(key, body) => (pat[1].span, "value", ty, mutbl),
|
||||
(_, value) if pat_is_wild(value, body) => (pat[0].span, "key", ty, MutImmutable),
|
||||
_ => return,
|
||||
},
|
||||
_ => return,
|
||||
@ -1705,8 +1705,8 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
|
||||
for expr in args {
|
||||
let ty = self.cx.tables.expr_ty_adjusted(expr);
|
||||
self.prefer_mutable = false;
|
||||
if let ty::TyRef(_, mutbl) = ty.sty {
|
||||
if mutbl.mutbl == MutMutable {
|
||||
if let ty::TyRef(_, _, mutbl) = ty.sty {
|
||||
if mutbl == MutMutable {
|
||||
self.prefer_mutable = true;
|
||||
}
|
||||
}
|
||||
@ -1717,8 +1717,8 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
|
||||
let def_id = self.cx.tables.type_dependent_defs()[expr.hir_id].def_id();
|
||||
for (ty, expr) in self.cx.tcx.fn_sig(def_id).inputs().skip_binder().iter().zip(args) {
|
||||
self.prefer_mutable = false;
|
||||
if let ty::TyRef(_, mutbl) = ty.sty {
|
||||
if mutbl.mutbl == MutMutable {
|
||||
if let ty::TyRef(_, _, mutbl) = ty.sty {
|
||||
if mutbl == MutMutable {
|
||||
self.prefer_mutable = true;
|
||||
}
|
||||
}
|
||||
|
@ -51,8 +51,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||
walk_ptrs_ty_depth(cx.tables.pat_ty(&first_arg.pat)).1 == 1
|
||||
{
|
||||
// the argument is not an &mut T
|
||||
if let ty::TyRef(_, tam) = ty.sty {
|
||||
if tam.mutbl == MutImmutable {
|
||||
if let ty::TyRef(_, _, mutbl) = ty.sty {
|
||||
if mutbl == MutImmutable {
|
||||
span_help_and_lint(cx, MAP_CLONE, expr.span, &format!(
|
||||
"you seem to be using .map() to clone the contents of an {}, consider \
|
||||
using `.cloned()`", type_name),
|
||||
|
@ -749,7 +749,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||
}
|
||||
|
||||
match self_ty.sty {
|
||||
ty::TyRef(_, ty) if ty.ty.sty == ty::TyStr => for &(method, pos) in &PATTERN_METHODS {
|
||||
ty::TyRef(_, ty, _) if ty.sty == ty::TyStr => for &(method, pos) in &PATTERN_METHODS {
|
||||
if method_call.name == method && args.len() > pos {
|
||||
lint_single_char_pattern(cx, expr, &args[pos]);
|
||||
}
|
||||
@ -967,8 +967,8 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, method_span: Span, name:
|
||||
/// Checks for the `CLONE_ON_COPY` lint.
|
||||
fn lint_clone_on_copy(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr, arg_ty: Ty) {
|
||||
let ty = cx.tables.expr_ty(expr);
|
||||
if let ty::TyRef(_, ty::TypeAndMut { ty: inner, .. }) = arg_ty.sty {
|
||||
if let ty::TyRef(_, ty::TypeAndMut { ty: innermost, .. }) = inner.sty {
|
||||
if let ty::TyRef(_, inner, _) = arg_ty.sty {
|
||||
if let ty::TyRef(_, innermost, _) = inner.sty {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
CLONE_DOUBLE_REF,
|
||||
@ -978,7 +978,7 @@ fn lint_clone_on_copy(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr, arg_t
|
||||
|db| if let Some(snip) = sugg::Sugg::hir_opt(cx, arg) {
|
||||
let mut ty = innermost;
|
||||
let mut n = 0;
|
||||
while let ty::TyRef(_, ty::TypeAndMut { ty: inner, .. }) = ty.sty {
|
||||
while let ty::TyRef(_, inner, _) = ty.sty {
|
||||
ty = inner;
|
||||
n += 1;
|
||||
}
|
||||
@ -1300,7 +1300,7 @@ fn derefs_to_slice(cx: &LateContext, expr: &hir::Expr, ty: Ty) -> Option<sugg::S
|
||||
ty::TyAdt(def, _) if def.is_box() => may_slice(cx, ty.boxed_ty()),
|
||||
ty::TyAdt(..) => match_type(cx, ty, &paths::VEC),
|
||||
ty::TyArray(_, size) => size.val.to_raw_bits().expect("array length") < 32,
|
||||
ty::TyRef(_, ty::TypeAndMut { ty: inner, .. }) => may_slice(cx, inner),
|
||||
ty::TyRef(_, inner, _) => may_slice(cx, inner),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@ -1315,7 +1315,7 @@ fn derefs_to_slice(cx: &LateContext, expr: &hir::Expr, ty: Ty) -> Option<sugg::S
|
||||
match ty.sty {
|
||||
ty::TySlice(_) => sugg::Sugg::hir_opt(cx, expr),
|
||||
ty::TyAdt(def, _) if def.is_box() && may_slice(cx, ty.boxed_ty()) => sugg::Sugg::hir_opt(cx, expr),
|
||||
ty::TyRef(_, ty::TypeAndMut { ty: inner, .. }) => if may_slice(cx, inner) {
|
||||
ty::TyRef(_, inner, _) => if may_slice(cx, inner) {
|
||||
sugg::Sugg::hir_opt(cx, expr)
|
||||
} else {
|
||||
None
|
||||
|
@ -72,10 +72,8 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> {
|
||||
);
|
||||
} else if let ty::TyRef(
|
||||
_,
|
||||
ty::TypeAndMut {
|
||||
mutbl: hir::MutMutable,
|
||||
..
|
||||
},
|
||||
_,
|
||||
_,
|
||||
) = self.cx.tables.expr_ty(e).sty
|
||||
{
|
||||
span_lint(
|
||||
|
@ -63,10 +63,8 @@ fn check_arguments<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arguments: &[Expr], typ
|
||||
match parameter.sty {
|
||||
ty::TyRef(
|
||||
_,
|
||||
ty::TypeAndMut {
|
||||
mutbl: MutImmutable,
|
||||
..
|
||||
},
|
||||
_,
|
||||
_,
|
||||
) |
|
||||
ty::TyRawPtr(ty::TypeAndMut {
|
||||
mutbl: MutImmutable,
|
||||
|
@ -77,11 +77,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow {
|
||||
}
|
||||
if_chain! {
|
||||
if let PatKind::Binding(BindingAnnotation::Ref, _, name, _) = pat.node;
|
||||
if let ty::TyRef(_, ref tam) = cx.tables.pat_ty(pat).sty;
|
||||
if tam.mutbl == MutImmutable;
|
||||
if let ty::TyRef(_, ref tam) = tam.ty.sty;
|
||||
if let ty::TyRef(_, tam, mutbl) = cx.tables.pat_ty(pat).sty;
|
||||
if mutbl == MutImmutable;
|
||||
if let ty::TyRef(_, _, mutbl) = tam.sty;
|
||||
// only lint immutable refs, because borrowed `&mut T` cannot be moved out
|
||||
if tam.mutbl == MutImmutable;
|
||||
if mutbl == MutImmutable;
|
||||
then {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
|
@ -152,10 +152,8 @@ fn check_fn(cx: &LateContext, decl: &FnDecl, fn_id: NodeId, opt_body_id: Option<
|
||||
for (idx, (arg, ty)) in decl.inputs.iter().zip(fn_ty.inputs()).enumerate() {
|
||||
if let ty::TyRef(
|
||||
_,
|
||||
ty::TypeAndMut {
|
||||
ty,
|
||||
mutbl: MutImmutable,
|
||||
},
|
||||
ty,
|
||||
_
|
||||
) = ty.sty
|
||||
{
|
||||
if match_type(cx, ty, &paths::VEC) {
|
||||
|
@ -229,16 +229,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
||||
e.span,
|
||||
&format!("transmute from a type (`{}`) to itself", from_ty),
|
||||
),
|
||||
(&ty::TyRef(_, rty), &ty::TyRawPtr(ptr_ty)) => span_lint_and_then(
|
||||
(&ty::TyRef(_, rty, rty_mutbl), &ty::TyRawPtr(ptr_ty)) => span_lint_and_then(
|
||||
cx,
|
||||
USELESS_TRANSMUTE,
|
||||
e.span,
|
||||
"transmute from a reference to a pointer",
|
||||
|db| if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
|
||||
let sugg = if ptr_ty == rty {
|
||||
let rty_and_mut = ty::TypeAndMut { ty: rty, mutbl: rty_mutbl };
|
||||
|
||||
let sugg = if ptr_ty == rty_and_mut {
|
||||
arg.as_ty(to_ty)
|
||||
} else {
|
||||
arg.as_ty(cx.tcx.mk_ptr(rty)).as_ty(to_ty)
|
||||
arg.as_ty(cx.tcx.mk_ptr(rty_and_mut)).as_ty(to_ty)
|
||||
};
|
||||
|
||||
db.span_suggestion(e.span, "try", sugg.to_string());
|
||||
@ -284,7 +286,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
||||
to_ty
|
||||
),
|
||||
),
|
||||
(&ty::TyRawPtr(from_pty), &ty::TyRef(_, to_ref_ty)) => span_lint_and_then(
|
||||
(&ty::TyRawPtr(from_pty), &ty::TyRef(_, to_ref_ty, mutbl)) => span_lint_and_then(
|
||||
cx,
|
||||
TRANSMUTE_PTR_TO_REF,
|
||||
e.span,
|
||||
@ -296,16 +298,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
||||
),
|
||||
|db| {
|
||||
let arg = sugg::Sugg::hir(cx, &args[0], "..");
|
||||
let (deref, cast) = if to_ref_ty.mutbl == Mutability::MutMutable {
|
||||
let (deref, cast) = if mutbl == Mutability::MutMutable {
|
||||
("&mut *", "*mut")
|
||||
} else {
|
||||
("&*", "*const")
|
||||
};
|
||||
|
||||
let arg = if from_pty.ty == to_ref_ty.ty {
|
||||
let arg = if from_pty.ty == to_ref_ty {
|
||||
arg
|
||||
} else {
|
||||
arg.as_ty(&format!("{} {}", cast, get_type_snippet(cx, qpath, to_ref_ty.ty)))
|
||||
arg.as_ty(&format!("{} {}", cast, get_type_snippet(cx, qpath, to_ref_ty)))
|
||||
};
|
||||
|
||||
db.span_suggestion(e.span, "try", sugg::make_unop(deref, arg).to_string());
|
||||
@ -331,13 +333,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
||||
);
|
||||
},
|
||||
),
|
||||
(&ty::TyRef(_, ref ref_from), &ty::TyRef(_, ref ref_to)) => {
|
||||
(&ty::TyRef(_, ty_from, from_mutbl), &ty::TyRef(_, ty_to, to_mutbl)) => {
|
||||
if_chain! {
|
||||
if let (&ty::TySlice(slice_ty), &ty::TyStr) = (&ref_from.ty.sty, &ref_to.ty.sty);
|
||||
if let (&ty::TySlice(slice_ty), &ty::TyStr) = (&ty_from.sty, &ty_to.sty);
|
||||
if let ty::TyUint(ast::UintTy::U8) = slice_ty.sty;
|
||||
if ref_from.mutbl == ref_to.mutbl;
|
||||
if from_mutbl == to_mutbl;
|
||||
then {
|
||||
let postfix = if ref_from.mutbl == Mutability::MutMutable {
|
||||
let postfix = if from_mutbl == Mutability::MutMutable {
|
||||
"_mut"
|
||||
} else {
|
||||
""
|
||||
@ -367,8 +369,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
||||
e.span,
|
||||
"transmute from a reference to a reference",
|
||||
|db| if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
|
||||
let sugg_paren = arg.as_ty(cx.tcx.mk_ptr(*ref_from)).as_ty(cx.tcx.mk_ptr(*ref_to));
|
||||
let sugg = if ref_to.mutbl == Mutability::MutMutable {
|
||||
let ty_from_and_mut = ty::TypeAndMut { ty: ty_from, mutbl: from_mutbl };
|
||||
let ty_to_and_mut = ty::TypeAndMut { ty: ty_to, mutbl: to_mutbl };
|
||||
let sugg_paren = arg.as_ty(cx.tcx.mk_ptr(ty_from_and_mut)).as_ty(cx.tcx.mk_ptr(ty_to_and_mut));
|
||||
let sugg = if to_mutbl == Mutability::MutMutable {
|
||||
sugg_paren.mut_addr_deref()
|
||||
} else {
|
||||
sugg_paren.addr_deref()
|
||||
|
@ -674,7 +674,7 @@ pub fn walk_ptrs_hir_ty(ty: &hir::Ty) -> &hir::Ty {
|
||||
/// Return the base type for references and raw pointers.
|
||||
pub fn walk_ptrs_ty(ty: Ty) -> Ty {
|
||||
match ty.sty {
|
||||
ty::TyRef(_, ref tm) => walk_ptrs_ty(tm.ty),
|
||||
ty::TyRef(_, ty, _) => walk_ptrs_ty(ty),
|
||||
_ => ty,
|
||||
}
|
||||
}
|
||||
@ -684,7 +684,7 @@ pub fn walk_ptrs_ty(ty: Ty) -> Ty {
|
||||
pub fn walk_ptrs_ty_depth(ty: Ty) -> (Ty, usize) {
|
||||
fn inner(ty: Ty, depth: usize) -> (Ty, usize) {
|
||||
match ty.sty {
|
||||
ty::TyRef(_, ref tm) => inner(tm.ty, depth + 1),
|
||||
ty::TyRef(_, ty, _) => inner(ty, depth + 1),
|
||||
_ => (ty, depth),
|
||||
}
|
||||
}
|
||||
|
@ -35,8 +35,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
// search for `&vec![_]` expressions where the adjusted type is `&[_]`
|
||||
if_chain! {
|
||||
if let ty::TyRef(_, ref ty) = cx.tables.expr_ty_adjusted(expr).sty;
|
||||
if let ty::TySlice(..) = ty.ty.sty;
|
||||
if let ty::TyRef(_, ty, _) = cx.tables.expr_ty_adjusted(expr).sty;
|
||||
if let ty::TySlice(..) = ty.sty;
|
||||
if let ExprAddrOf(_, ref addressee) = expr.node;
|
||||
if let Some(vec_args) = higher::vec_macro(cx, addressee);
|
||||
then {
|
||||
|
Loading…
x
Reference in New Issue
Block a user