1
Fork 0

Rustup to 2018-05-11

This commit is contained in:
Philipp Hansch 2018-05-11 08:37:48 +02:00 committed by Oliver Schneider
parent be3cba8852
commit 665cf96221
No known key found for this signature in database
GPG key ID: 1D5CB4FC597C3004
11 changed files with 48 additions and 50 deletions

View file

@ -426,7 +426,7 @@ pub fn miri_to_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, result: &ty::Const<'
_ => None, _ => None,
}, },
ConstVal::Value(Value::ByValPair(PrimVal::Ptr(ptr), PrimVal::Bytes(n))) => match result.ty.sty { 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 => { ty::TyStr => {
let alloc = tcx let alloc = tcx
.interpret_interner .interpret_interner

View file

@ -743,7 +743,7 @@ struct FixedOffsetVar {
fn is_slice_like<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty) -> bool { fn is_slice_like<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty) -> bool {
let is_slice = match ty.sty { 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, ty::TySlice(..) | ty::TyArray(..) => true,
_ => false, _ => false,
}; };
@ -1365,9 +1365,9 @@ fn check_for_loop_over_map_kv<'a, 'tcx>(
if pat.len() == 2 { if pat.len() == 2 {
let arg_span = arg.span; let arg_span = arg.span;
let (new_pat_span, kind, ty, mutbl) = match cx.tables.expr_ty(arg).sty { 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) { ty::TyRef(_, ty, mutbl) => match (&pat[0].node, &pat[1].node) {
(key, _) if pat_is_wild(key, body) => (pat[1].span, "value", tam.ty, tam.mutbl), (key, _) if pat_is_wild(key, body) => (pat[1].span, "value", ty, mutbl),
(_, value) if pat_is_wild(value, body) => (pat[0].span, "key", tam.ty, MutImmutable), (_, value) if pat_is_wild(value, body) => (pat[0].span, "key", ty, MutImmutable),
_ => return, _ => return,
}, },
_ => return, _ => return,
@ -1705,8 +1705,8 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
for expr in args { for expr in args {
let ty = self.cx.tables.expr_ty_adjusted(expr); let ty = self.cx.tables.expr_ty_adjusted(expr);
self.prefer_mutable = false; self.prefer_mutable = false;
if let ty::TyRef(_, mutbl) = ty.sty { if let ty::TyRef(_, _, mutbl) = ty.sty {
if mutbl.mutbl == MutMutable { if mutbl == MutMutable {
self.prefer_mutable = true; 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(); 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) { for (ty, expr) in self.cx.tcx.fn_sig(def_id).inputs().skip_binder().iter().zip(args) {
self.prefer_mutable = false; self.prefer_mutable = false;
if let ty::TyRef(_, mutbl) = ty.sty { if let ty::TyRef(_, _, mutbl) = ty.sty {
if mutbl.mutbl == MutMutable { if mutbl == MutMutable {
self.prefer_mutable = true; self.prefer_mutable = true;
} }
} }

View file

@ -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 walk_ptrs_ty_depth(cx.tables.pat_ty(&first_arg.pat)).1 == 1
{ {
// the argument is not an &mut T // the argument is not an &mut T
if let ty::TyRef(_, tam) = ty.sty { if let ty::TyRef(_, _, mutbl) = ty.sty {
if tam.mutbl == MutImmutable { if mutbl == MutImmutable {
span_help_and_lint(cx, MAP_CLONE, expr.span, &format!( span_help_and_lint(cx, MAP_CLONE, expr.span, &format!(
"you seem to be using .map() to clone the contents of an {}, consider \ "you seem to be using .map() to clone the contents of an {}, consider \
using `.cloned()`", type_name), using `.cloned()`", type_name),

View file

@ -749,7 +749,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
} }
match self_ty.sty { 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 { if method_call.name == method && args.len() > pos {
lint_single_char_pattern(cx, expr, &args[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. /// Checks for the `CLONE_ON_COPY` lint.
fn lint_clone_on_copy(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr, arg_ty: Ty) { fn lint_clone_on_copy(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr, arg_ty: Ty) {
let ty = cx.tables.expr_ty(expr); let ty = cx.tables.expr_ty(expr);
if let ty::TyRef(_, ty::TypeAndMut { ty: inner, .. }) = arg_ty.sty { if let ty::TyRef(_, inner, _) = arg_ty.sty {
if let ty::TyRef(_, ty::TypeAndMut { ty: innermost, .. }) = inner.sty { if let ty::TyRef(_, innermost, _) = inner.sty {
span_lint_and_then( span_lint_and_then(
cx, cx,
CLONE_DOUBLE_REF, 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) { |db| if let Some(snip) = sugg::Sugg::hir_opt(cx, arg) {
let mut ty = innermost; let mut ty = innermost;
let mut n = 0; let mut n = 0;
while let ty::TyRef(_, ty::TypeAndMut { ty: inner, .. }) = ty.sty { while let ty::TyRef(_, inner, _) = ty.sty {
ty = inner; ty = inner;
n += 1; 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(def, _) if def.is_box() => may_slice(cx, ty.boxed_ty()),
ty::TyAdt(..) => match_type(cx, ty, &paths::VEC), ty::TyAdt(..) => match_type(cx, ty, &paths::VEC),
ty::TyArray(_, size) => size.val.to_raw_bits().expect("array length") < 32, 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, _ => false,
} }
} }
@ -1315,7 +1315,7 @@ fn derefs_to_slice(cx: &LateContext, expr: &hir::Expr, ty: Ty) -> Option<sugg::S
match ty.sty { match ty.sty {
ty::TySlice(_) => sugg::Sugg::hir_opt(cx, expr), 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::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) sugg::Sugg::hir_opt(cx, expr)
} else { } else {
None None

View file

@ -72,10 +72,8 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> {
); );
} else if let ty::TyRef( } else if let ty::TyRef(
_, _,
ty::TypeAndMut { _,
mutbl: hir::MutMutable, _,
..
},
) = self.cx.tables.expr_ty(e).sty ) = self.cx.tables.expr_ty(e).sty
{ {
span_lint( span_lint(

View file

@ -63,10 +63,8 @@ fn check_arguments<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arguments: &[Expr], typ
match parameter.sty { match parameter.sty {
ty::TyRef( ty::TyRef(
_, _,
ty::TypeAndMut { _,
mutbl: MutImmutable, _,
..
},
) | ) |
ty::TyRawPtr(ty::TypeAndMut { ty::TyRawPtr(ty::TypeAndMut {
mutbl: MutImmutable, mutbl: MutImmutable,

View file

@ -77,11 +77,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow {
} }
if_chain! { if_chain! {
if let PatKind::Binding(BindingAnnotation::Ref, _, name, _) = pat.node; if let PatKind::Binding(BindingAnnotation::Ref, _, name, _) = pat.node;
if let ty::TyRef(_, ref tam) = cx.tables.pat_ty(pat).sty; if let ty::TyRef(_, tam, mutbl) = cx.tables.pat_ty(pat).sty;
if tam.mutbl == MutImmutable; if mutbl == MutImmutable;
if let ty::TyRef(_, ref tam) = tam.ty.sty; if let ty::TyRef(_, _, mutbl) = tam.sty;
// only lint immutable refs, because borrowed `&mut T` cannot be moved out // only lint immutable refs, because borrowed `&mut T` cannot be moved out
if tam.mutbl == MutImmutable; if mutbl == MutImmutable;
then { then {
span_lint_and_then( span_lint_and_then(
cx, cx,

View file

@ -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() { for (idx, (arg, ty)) in decl.inputs.iter().zip(fn_ty.inputs()).enumerate() {
if let ty::TyRef( if let ty::TyRef(
_, _,
ty::TypeAndMut {
ty, ty,
mutbl: MutImmutable, _
},
) = ty.sty ) = ty.sty
{ {
if match_type(cx, ty, &paths::VEC) { if match_type(cx, ty, &paths::VEC) {

View file

@ -229,16 +229,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
e.span, e.span,
&format!("transmute from a type (`{}`) to itself", from_ty), &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, cx,
USELESS_TRANSMUTE, USELESS_TRANSMUTE,
e.span, e.span,
"transmute from a reference to a pointer", "transmute from a reference to a pointer",
|db| if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) { |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) arg.as_ty(to_ty)
} else { } 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()); db.span_suggestion(e.span, "try", sugg.to_string());
@ -284,7 +286,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
to_ty 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, cx,
TRANSMUTE_PTR_TO_REF, TRANSMUTE_PTR_TO_REF,
e.span, e.span,
@ -296,16 +298,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
), ),
|db| { |db| {
let arg = sugg::Sugg::hir(cx, &args[0], ".."); 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") ("&mut *", "*mut")
} else { } else {
("&*", "*const") ("&*", "*const")
}; };
let arg = if from_pty.ty == to_ref_ty.ty { let arg = if from_pty.ty == to_ref_ty {
arg arg
} else { } 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()); 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_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 let ty::TyUint(ast::UintTy::U8) = slice_ty.sty;
if ref_from.mutbl == ref_to.mutbl; if from_mutbl == to_mutbl;
then { then {
let postfix = if ref_from.mutbl == Mutability::MutMutable { let postfix = if from_mutbl == Mutability::MutMutable {
"_mut" "_mut"
} else { } else {
"" ""
@ -367,8 +369,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
e.span, e.span,
"transmute from a reference to a reference", "transmute from a reference to a reference",
|db| if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) { |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 ty_from_and_mut = ty::TypeAndMut { ty: ty_from, mutbl: from_mutbl };
let sugg = if ref_to.mutbl == Mutability::MutMutable { 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() sugg_paren.mut_addr_deref()
} else { } else {
sugg_paren.addr_deref() sugg_paren.addr_deref()

View file

@ -674,7 +674,7 @@ pub fn walk_ptrs_hir_ty(ty: &hir::Ty) -> &hir::Ty {
/// Return the base type for references and raw pointers. /// Return the base type for references and raw pointers.
pub fn walk_ptrs_ty(ty: Ty) -> Ty { pub fn walk_ptrs_ty(ty: Ty) -> Ty {
match ty.sty { match ty.sty {
ty::TyRef(_, ref tm) => walk_ptrs_ty(tm.ty), ty::TyRef(_, ty, _) => walk_ptrs_ty(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) { pub fn walk_ptrs_ty_depth(ty: Ty) -> (Ty, usize) {
fn inner(ty: Ty, depth: usize) -> (Ty, usize) { fn inner(ty: Ty, depth: usize) -> (Ty, usize) {
match ty.sty { match ty.sty {
ty::TyRef(_, ref tm) => inner(tm.ty, depth + 1), ty::TyRef(_, ty, _) => inner(ty, depth + 1),
_ => (ty, depth), _ => (ty, depth),
} }
} }

View file

@ -35,8 +35,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
// search for `&vec![_]` expressions where the adjusted type is `&[_]` // search for `&vec![_]` expressions where the adjusted type is `&[_]`
if_chain! { if_chain! {
if let ty::TyRef(_, ref ty) = cx.tables.expr_ty_adjusted(expr).sty; if let ty::TyRef(_, ty, _) = cx.tables.expr_ty_adjusted(expr).sty;
if let ty::TySlice(..) = ty.ty.sty; if let ty::TySlice(..) = ty.sty;
if let ExprAddrOf(_, ref addressee) = expr.node; if let ExprAddrOf(_, ref addressee) = expr.node;
if let Some(vec_args) = higher::vec_macro(cx, addressee); if let Some(vec_args) = higher::vec_macro(cx, addressee);
then { then {