Accessing Span internals is deprecated
This commit is contained in:
@@ -126,7 +126,7 @@ fn check_collapsible_no_if_let(cx: &EarlyContext, expr: &ast::Expr, check: &ast:
|
|||||||
let Some(inner) = expr_block(then),
|
let Some(inner) = expr_block(then),
|
||||||
let ast::ExprKind::If(ref check_inner, ref content, None) = inner.node,
|
let ast::ExprKind::If(ref check_inner, ref content, None) = inner.node,
|
||||||
], {
|
], {
|
||||||
if expr.span.ctxt != inner.span.ctxt {
|
if expr.span.ctxt() != inner.span.ctxt() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
span_lint_and_then(cx, COLLAPSIBLE_IF, expr.span, "this if statement can be collapsed", |db| {
|
span_lint_and_then(cx, COLLAPSIBLE_IF, expr.span, "this if statement can be collapsed", |db| {
|
||||||
|
|||||||
@@ -96,10 +96,7 @@ pub fn strip_doc_comment_decoration(comment: &str, span: Span) -> (String, Vec<(
|
|||||||
vec![
|
vec![
|
||||||
(
|
(
|
||||||
doc.len(),
|
doc.len(),
|
||||||
Span {
|
span.with_lo(span.lo() + BytePos(prefix.len() as u32)),
|
||||||
lo: span.lo + BytePos(prefix.len() as u32),
|
|
||||||
..span
|
|
||||||
}
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@@ -117,10 +114,7 @@ pub fn strip_doc_comment_decoration(comment: &str, span: Span) -> (String, Vec<(
|
|||||||
// +1 for the newline
|
// +1 for the newline
|
||||||
sizes.push((
|
sizes.push((
|
||||||
line.len() + 1,
|
line.len() + 1,
|
||||||
Span {
|
span.with_lo(span.lo() + BytePos(offset as u32)),
|
||||||
lo: span.lo + BytePos(offset as u32),
|
|
||||||
..span
|
|
||||||
},
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if !contains_initial_stars {
|
if !contains_initial_stars {
|
||||||
@@ -228,10 +222,7 @@ fn check_doc<'a, Events: Iterator<Item = (usize, pulldown_cmark::Event<'a>)>>(
|
|||||||
let (begin, span) = spans[index];
|
let (begin, span) = spans[index];
|
||||||
|
|
||||||
// Adjust for the begining of the current `Event`
|
// Adjust for the begining of the current `Event`
|
||||||
let span = Span {
|
let span = span.with_lo(span.lo() + BytePos::from_usize(offset - begin));
|
||||||
lo: span.lo + BytePos::from_usize(offset - begin),
|
|
||||||
..span
|
|
||||||
};
|
|
||||||
|
|
||||||
check_text(cx, valid_idents, &text, span);
|
check_text(cx, valid_idents, &text, span);
|
||||||
}
|
}
|
||||||
@@ -253,11 +244,11 @@ fn check_text(cx: &EarlyContext, valid_idents: &[String], text: &str, span: Span
|
|||||||
|
|
||||||
// Adjust for the current word
|
// Adjust for the current word
|
||||||
let offset = word.as_ptr() as usize - text.as_ptr() as usize;
|
let offset = word.as_ptr() as usize - text.as_ptr() as usize;
|
||||||
let span = Span {
|
let span = Span::new(
|
||||||
lo: span.lo + BytePos::from_usize(offset),
|
span.lo() + BytePos::from_usize(offset),
|
||||||
hi: span.lo + BytePos::from_usize(offset + word.len()),
|
span.lo() + BytePos::from_usize(offset + word.len()),
|
||||||
..span
|
span.ctxt(),
|
||||||
};
|
);
|
||||||
|
|
||||||
check_word(cx, word, span);
|
check_word(cx, word, span);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use rustc::lint::*;
|
use rustc::lint::*;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax_pos::{Span, NO_EXPANSION};
|
|
||||||
use utils::{differing_macro_contexts, in_macro, snippet_opt, span_note_and_lint};
|
use utils::{differing_macro_contexts, in_macro, snippet_opt, span_note_and_lint};
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
|
|
||||||
@@ -106,19 +105,11 @@ impl EarlyLintPass for Formatting {
|
|||||||
fn check_assign(cx: &EarlyContext, expr: &ast::Expr) {
|
fn check_assign(cx: &EarlyContext, expr: &ast::Expr) {
|
||||||
if let ast::ExprKind::Assign(ref lhs, ref rhs) = expr.node {
|
if let ast::ExprKind::Assign(ref lhs, ref rhs) = expr.node {
|
||||||
if !differing_macro_contexts(lhs.span, rhs.span) && !in_macro(lhs.span) {
|
if !differing_macro_contexts(lhs.span, rhs.span) && !in_macro(lhs.span) {
|
||||||
let eq_span = Span {
|
let eq_span = lhs.span.between(rhs.span);
|
||||||
lo: lhs.span.hi,
|
|
||||||
hi: rhs.span.lo,
|
|
||||||
ctxt: NO_EXPANSION,
|
|
||||||
};
|
|
||||||
if let ast::ExprKind::Unary(op, ref sub_rhs) = rhs.node {
|
if let ast::ExprKind::Unary(op, ref sub_rhs) = rhs.node {
|
||||||
if let Some(eq_snippet) = snippet_opt(cx, eq_span) {
|
if let Some(eq_snippet) = snippet_opt(cx, eq_span) {
|
||||||
let op = ast::UnOp::to_string(op);
|
let op = ast::UnOp::to_string(op);
|
||||||
let eqop_span = Span {
|
let eqop_span = lhs.span.between(sub_rhs.span);
|
||||||
lo: lhs.span.hi,
|
|
||||||
hi: sub_rhs.span.lo,
|
|
||||||
ctxt: NO_EXPANSION,
|
|
||||||
};
|
|
||||||
if eq_snippet.ends_with('=') {
|
if eq_snippet.ends_with('=') {
|
||||||
span_note_and_lint(
|
span_note_and_lint(
|
||||||
cx,
|
cx,
|
||||||
@@ -146,11 +137,7 @@ fn check_else_if(cx: &EarlyContext, expr: &ast::Expr) {
|
|||||||
// this will be a span from the closing ‘}’ of the “then” block (excluding) to
|
// this will be a span from the closing ‘}’ of the “then” block (excluding) to
|
||||||
// the
|
// the
|
||||||
// “if” of the “else if” block (excluding)
|
// “if” of the “else if” block (excluding)
|
||||||
let else_span = Span {
|
let else_span = then.span.between(else_.span);
|
||||||
lo: then.span.hi,
|
|
||||||
hi: else_.span.lo,
|
|
||||||
ctxt: NO_EXPANSION,
|
|
||||||
};
|
|
||||||
|
|
||||||
// the snippet should look like " else \n " with maybe comments anywhere
|
// the snippet should look like " else \n " with maybe comments anywhere
|
||||||
// it’s bad when there is a ‘\n’ after the “else”
|
// it’s bad when there is a ‘\n’ after the “else”
|
||||||
@@ -181,17 +168,9 @@ fn check_array(cx: &EarlyContext, expr: &ast::Expr) {
|
|||||||
for element in array {
|
for element in array {
|
||||||
if let ast::ExprKind::Binary(ref op, ref lhs, _) = element.node {
|
if let ast::ExprKind::Binary(ref op, ref lhs, _) = element.node {
|
||||||
if !differing_macro_contexts(lhs.span, op.span) {
|
if !differing_macro_contexts(lhs.span, op.span) {
|
||||||
let space_span = Span {
|
let space_span = lhs.span.between(op.span);
|
||||||
lo: lhs.span.hi,
|
|
||||||
hi: op.span.lo,
|
|
||||||
ctxt: NO_EXPANSION,
|
|
||||||
};
|
|
||||||
if let Some(space_snippet) = snippet_opt(cx, space_span) {
|
if let Some(space_snippet) = snippet_opt(cx, space_span) {
|
||||||
let lint_span = Span {
|
let lint_span = lhs.span.with_lo(lhs.span.hi());
|
||||||
lo: lhs.span.hi,
|
|
||||||
hi: lhs.span.hi,
|
|
||||||
ctxt: NO_EXPANSION,
|
|
||||||
};
|
|
||||||
if space_snippet.contains('\n') {
|
if space_snippet.contains('\n') {
|
||||||
span_note_and_lint(
|
span_note_and_lint(
|
||||||
cx,
|
cx,
|
||||||
@@ -215,11 +194,7 @@ fn check_consecutive_ifs(cx: &EarlyContext, first: &ast::Expr, second: &ast::Exp
|
|||||||
unsugar_if(second).is_some()
|
unsugar_if(second).is_some()
|
||||||
{
|
{
|
||||||
// where the else would be
|
// where the else would be
|
||||||
let else_span = Span {
|
let else_span = first.span.between(second.span);
|
||||||
lo: first.span.hi,
|
|
||||||
hi: second.span.lo,
|
|
||||||
ctxt: NO_EXPANSION,
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(else_snippet) = snippet_opt(cx, else_span) {
|
if let Some(else_snippet) = snippet_opt(cx, else_span) {
|
||||||
if !else_snippet.contains('\n') {
|
if !else_snippet.contains('\n') {
|
||||||
|
|||||||
@@ -74,11 +74,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||||||
arms[0].pats[0].span,
|
arms[0].pats[0].span,
|
||||||
&format!("redundant pattern matching, consider using `{}`", good_method),
|
&format!("redundant pattern matching, consider using `{}`", good_method),
|
||||||
|db| {
|
|db| {
|
||||||
let span = Span {
|
let span = Span::new(
|
||||||
lo: expr.span.lo,
|
expr.span.lo(),
|
||||||
hi: op.span.hi,
|
op.span.hi(),
|
||||||
ctxt: expr.span.ctxt,
|
expr.span.ctxt(),
|
||||||
};
|
);
|
||||||
db.span_suggestion(span, "try this", format!("if {}.{}", snippet(cx, op.span, "_"), good_method));
|
db.span_suggestion(span, "try this", format!("if {}.{}", snippet(cx, op.span, "_"), good_method));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
use rustc::lint::*;
|
use rustc::lint::*;
|
||||||
use rustc::hir;
|
use rustc::hir;
|
||||||
use rustc::hir::BindingAnnotation;
|
use rustc::hir::BindingAnnotation;
|
||||||
use syntax_pos::{Span, NO_EXPANSION};
|
|
||||||
use utils::{snippet, span_lint_and_then};
|
use utils::{snippet, span_lint_and_then};
|
||||||
|
|
||||||
/// **What it does:** Checks for variable declarations immediately followed by a
|
/// **What it does:** Checks for variable declarations immediately followed by a
|
||||||
@@ -74,7 +73,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
|
|||||||
let Some(value) = check_assign(cx, def_id, &*then),
|
let Some(value) = check_assign(cx, def_id, &*then),
|
||||||
!used_in_expr(cx, def_id, value),
|
!used_in_expr(cx, def_id, value),
|
||||||
], {
|
], {
|
||||||
let span = Span { lo: stmt.span.lo, hi: if_.span.hi, ctxt: NO_EXPANSION };
|
let span = stmt.span.to(if_.span);
|
||||||
|
|
||||||
let (default_multi_stmts, default) = if let Some(ref else_) = *else_ {
|
let (default_multi_stmts, default) = if let Some(ref else_) = *else_ {
|
||||||
if let hir::ExprBlock(ref else_) = else_.node {
|
if let hir::ExprBlock(ref else_) = else_.node {
|
||||||
|
|||||||
@@ -1092,7 +1092,7 @@ fn lint_map_unwrap_or(cx: &LateContext, expr: &hir::Expr, map_args: &[hir::Expr]
|
|||||||
// lint, with note if neither arg is > 1 line and both map() and
|
// lint, with note if neither arg is > 1 line and both map() and
|
||||||
// unwrap_or() have the same span
|
// unwrap_or() have the same span
|
||||||
let multiline = map_snippet.lines().count() > 1 || unwrap_snippet.lines().count() > 1;
|
let multiline = map_snippet.lines().count() > 1 || unwrap_snippet.lines().count() > 1;
|
||||||
let same_span = map_args[1].span.ctxt == unwrap_args[1].span.ctxt;
|
let same_span = map_args[1].span.ctxt() == unwrap_args[1].span.ctxt();
|
||||||
if same_span && !multiline {
|
if same_span && !multiline {
|
||||||
span_note_and_lint(
|
span_note_and_lint(
|
||||||
cx,
|
cx,
|
||||||
@@ -1125,7 +1125,7 @@ fn lint_map_unwrap_or_else(cx: &LateContext, expr: &hir::Expr, map_args: &[hir::
|
|||||||
// lint, with note if neither arg is > 1 line and both map() and
|
// lint, with note if neither arg is > 1 line and both map() and
|
||||||
// unwrap_or_else() have the same span
|
// unwrap_or_else() have the same span
|
||||||
let multiline = map_snippet.lines().count() > 1 || unwrap_snippet.lines().count() > 1;
|
let multiline = map_snippet.lines().count() > 1 || unwrap_snippet.lines().count() > 1;
|
||||||
let same_span = map_args[1].span.ctxt == unwrap_args[1].span.ctxt;
|
let same_span = map_args[1].span.ctxt() == unwrap_args[1].span.ctxt();
|
||||||
if same_span && !multiline {
|
if same_span && !multiline {
|
||||||
span_note_and_lint(
|
span_note_and_lint(
|
||||||
cx,
|
cx,
|
||||||
|
|||||||
@@ -567,7 +567,7 @@ fn is_used(cx: &LateContext, expr: &Expr) -> bool {
|
|||||||
/// generated by
|
/// generated by
|
||||||
/// `#[derive(...)`] or the like).
|
/// `#[derive(...)`] or the like).
|
||||||
fn in_attributes_expansion(expr: &Expr) -> bool {
|
fn in_attributes_expansion(expr: &Expr) -> bool {
|
||||||
expr.span.ctxt.outer().expn_info().map_or(
|
expr.span.ctxt().outer().expn_info().map_or(
|
||||||
false,
|
false,
|
||||||
|info| matches!(info.callee.format, ExpnFormat::MacroAttribute(_)),
|
|info| matches!(info.callee.format, ExpnFormat::MacroAttribute(_)),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -140,11 +140,11 @@ fn str_span(base: Span, s: &str, c: usize) -> Span {
|
|||||||
|
|
||||||
match (si.next(), si.next()) {
|
match (si.next(), si.next()) {
|
||||||
(Some((l, _)), Some((h, _))) => {
|
(Some((l, _)), Some((h, _))) => {
|
||||||
Span {
|
Span::new(
|
||||||
lo: base.lo + BytePos(l as u32),
|
base.lo() + BytePos(l as u32),
|
||||||
hi: base.lo + BytePos(h as u32),
|
base.lo() + BytePos(h as u32),
|
||||||
..base
|
base.ctxt(),
|
||||||
}
|
)
|
||||||
},
|
},
|
||||||
_ => base,
|
_ => base,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ use rustc::lint::*;
|
|||||||
use rustc::ty;
|
use rustc::ty;
|
||||||
use utils::{differing_macro_contexts, match_type, paths, snippet, span_lint_and_then, walk_ptrs_ty, SpanlessEq};
|
use utils::{differing_macro_contexts, match_type, paths, snippet, span_lint_and_then, walk_ptrs_ty, SpanlessEq};
|
||||||
use utils::sugg::Sugg;
|
use utils::sugg::Sugg;
|
||||||
use syntax_pos::{Span, NO_EXPANSION};
|
|
||||||
|
|
||||||
/// **What it does:** Checks for manual swapping.
|
/// **What it does:** Checks for manual swapping.
|
||||||
///
|
///
|
||||||
@@ -122,7 +121,7 @@ fn check_manual_swap(cx: &LateContext, block: &Block) {
|
|||||||
(true, "".to_owned(), "".to_owned())
|
(true, "".to_owned(), "".to_owned())
|
||||||
};
|
};
|
||||||
|
|
||||||
let span = Span { lo: w[0].span.lo, hi: second.span.hi, ctxt: NO_EXPANSION};
|
let span = w[0].span.to(second.span);
|
||||||
|
|
||||||
span_lint_and_then(cx,
|
span_lint_and_then(cx,
|
||||||
MANUAL_SWAP,
|
MANUAL_SWAP,
|
||||||
@@ -161,7 +160,7 @@ fn check_suspicious_swap(cx: &LateContext, block: &Block) {
|
|||||||
("".to_owned(), "".to_owned(), "".to_owned())
|
("".to_owned(), "".to_owned(), "".to_owned())
|
||||||
};
|
};
|
||||||
|
|
||||||
let span = Span{ lo: first.span.lo, hi: second.span.hi, ctxt: NO_EXPANSION};
|
let span = first.span.to(second.span);
|
||||||
|
|
||||||
span_lint_and_then(cx,
|
span_lint_and_then(cx,
|
||||||
ALMOST_SWAPPED,
|
ALMOST_SWAPPED,
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
|
|||||||
// Therefore, we need to climb the macro expansion tree and find the
|
// Therefore, we need to climb the macro expansion tree and find the
|
||||||
// actual span that invoked `declare_lint!`:
|
// actual span that invoked `declare_lint!`:
|
||||||
let lint_span = lint_span
|
let lint_span = lint_span
|
||||||
.ctxt
|
.ctxt()
|
||||||
.outer()
|
.outer()
|
||||||
.expn_info()
|
.expn_info()
|
||||||
.map(|ei| ei.call_site)
|
.map(|ei| ei.call_site)
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ pub mod higher;
|
|||||||
/// from a macro and one
|
/// from a macro and one
|
||||||
/// isn't).
|
/// isn't).
|
||||||
pub fn differing_macro_contexts(lhs: Span, rhs: Span) -> bool {
|
pub fn differing_macro_contexts(lhs: Span, rhs: Span) -> bool {
|
||||||
rhs.ctxt != lhs.ctxt
|
rhs.ctxt() != lhs.ctxt()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn in_constant(cx: &LateContext, id: NodeId) -> bool {
|
pub fn in_constant(cx: &LateContext, id: NodeId) -> bool {
|
||||||
@@ -114,7 +114,7 @@ pub fn in_constant(cx: &LateContext, id: NodeId) -> bool {
|
|||||||
|
|
||||||
/// Returns true if this `expn_info` was expanded by any macro.
|
/// Returns true if this `expn_info` was expanded by any macro.
|
||||||
pub fn in_macro(span: Span) -> bool {
|
pub fn in_macro(span: Span) -> bool {
|
||||||
span.ctxt.outer().expn_info().map_or(false, |info| {
|
span.ctxt().outer().expn_info().map_or(false, |info| {
|
||||||
match info.callee.format {// don't treat range expressions desugared to structs as "in_macro"
|
match info.callee.format {// don't treat range expressions desugared to structs as "in_macro"
|
||||||
ExpnFormat::CompilerDesugaring(kind) => kind != CompilerDesugaringKind::DotFill,
|
ExpnFormat::CompilerDesugaring(kind) => kind != CompilerDesugaringKind::DotFill,
|
||||||
_ => true,
|
_ => true,
|
||||||
@@ -147,7 +147,7 @@ pub fn in_external_macro<'a, T: LintContext<'a>>(cx: &T, span: Span) -> bool {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
span.ctxt.outer().expn_info().map_or(false, |info| {
|
span.ctxt().outer().expn_info().map_or(false, |info| {
|
||||||
in_macro_ext(cx, &info)
|
in_macro_ext(cx, &info)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -740,7 +740,7 @@ fn parse_attrs<F: FnMut(u64)>(sess: &Session, attrs: &[ast::Attribute], name: &'
|
|||||||
/// See also `is_direct_expn_of`.
|
/// See also `is_direct_expn_of`.
|
||||||
pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
|
pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
|
||||||
loop {
|
loop {
|
||||||
let span_name_span = span.ctxt.outer().expn_info().map(|ei| {
|
let span_name_span = span.ctxt().outer().expn_info().map(|ei| {
|
||||||
(ei.callee.name(), ei.call_site)
|
(ei.callee.name(), ei.call_site)
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -762,7 +762,7 @@ pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
|
|||||||
/// `bar!` by
|
/// `bar!` by
|
||||||
/// `is_direct_expn_of`.
|
/// `is_direct_expn_of`.
|
||||||
pub fn is_direct_expn_of(span: Span, name: &str) -> Option<Span> {
|
pub fn is_direct_expn_of(span: Span, name: &str) -> Option<Span> {
|
||||||
let span_name_span = span.ctxt.outer().expn_info().map(|ei| {
|
let span_name_span = span.ctxt().outer().expn_info().map(|ei| {
|
||||||
(ei.callee.name(), ei.call_site)
|
(ei.callee.name(), ei.call_site)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -392,7 +392,7 @@ fn astbinop2assignop(op: ast::BinOp) -> AssocOp {
|
|||||||
/// Return the indentation before `span` if there are nothing but `[ \t]`
|
/// Return the indentation before `span` if there are nothing but `[ \t]`
|
||||||
/// before it on its line.
|
/// before it on its line.
|
||||||
fn indentation<'a, T: LintContext<'a>>(cx: &T, span: Span) -> Option<String> {
|
fn indentation<'a, T: LintContext<'a>>(cx: &T, span: Span) -> Option<String> {
|
||||||
let lo = cx.sess().codemap().lookup_char_pos(span.lo);
|
let lo = cx.sess().codemap().lookup_char_pos(span.lo());
|
||||||
if let Some(line) = lo.file.get_line(
|
if let Some(line) = lo.file.get_line(
|
||||||
lo.line - 1, /* line numbers in `Loc` are 1-based */
|
lo.line - 1, /* line numbers in `Loc` are 1-based */
|
||||||
)
|
)
|
||||||
@@ -443,10 +443,7 @@ pub trait DiagnosticBuilderExt<'a, T: LintContext<'a>> {
|
|||||||
impl<'a, 'b, 'c, T: LintContext<'c>> DiagnosticBuilderExt<'c, T> for rustc_errors::DiagnosticBuilder<'b> {
|
impl<'a, 'b, 'c, T: LintContext<'c>> DiagnosticBuilderExt<'c, T> for rustc_errors::DiagnosticBuilder<'b> {
|
||||||
fn suggest_item_with_attr<D: Display + ?Sized>(&mut self, cx: &T, item: Span, msg: &str, attr: &D) {
|
fn suggest_item_with_attr<D: Display + ?Sized>(&mut self, cx: &T, item: Span, msg: &str, attr: &D) {
|
||||||
if let Some(indent) = indentation(cx, item) {
|
if let Some(indent) = indentation(cx, item) {
|
||||||
let span = Span {
|
let span = item.with_hi(item.lo());
|
||||||
hi: item.lo,
|
|
||||||
..item
|
|
||||||
};
|
|
||||||
|
|
||||||
self.span_suggestion(span, msg, format!("{}\n{}", attr, indent));
|
self.span_suggestion(span, msg, format!("{}\n{}", attr, indent));
|
||||||
}
|
}
|
||||||
@@ -454,10 +451,7 @@ impl<'a, 'b, 'c, T: LintContext<'c>> DiagnosticBuilderExt<'c, T> for rustc_error
|
|||||||
|
|
||||||
fn suggest_prepend_item(&mut self, cx: &T, item: Span, msg: &str, new_item: &str) {
|
fn suggest_prepend_item(&mut self, cx: &T, item: Span, msg: &str, new_item: &str) {
|
||||||
if let Some(indent) = indentation(cx, item) {
|
if let Some(indent) = indentation(cx, item) {
|
||||||
let span = Span {
|
let span = item.with_hi(item.lo());
|
||||||
hi: item.lo,
|
|
||||||
..item
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
let new_item = new_item
|
let new_item = new_item
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||||||
is_copy(cx, vec_type(cx.tables.expr_ty_adjusted(arg))),
|
is_copy(cx, vec_type(cx.tables.expr_ty_adjusted(arg))),
|
||||||
], {
|
], {
|
||||||
// report the error around the `vec!` not inside `<std macros>:`
|
// report the error around the `vec!` not inside `<std macros>:`
|
||||||
let span = arg.span.ctxt.outer().expn_info().map(|info| info.call_site).expect("unable to get call_site");
|
let span = arg.span.ctxt().outer().expn_info().map(|info| info.call_site).expect("unable to get call_site");
|
||||||
check_vec_macro(cx, &vec_args, span);
|
check_vec_macro(cx, &vec_args, span);
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
@@ -74,11 +74,7 @@ fn check_vec_macro(cx: &LateContext, vec_args: &higher::VecArgs, span: Span) {
|
|||||||
},
|
},
|
||||||
higher::VecArgs::Vec(args) => {
|
higher::VecArgs::Vec(args) => {
|
||||||
if let Some(last) = args.iter().last() {
|
if let Some(last) = args.iter().last() {
|
||||||
let span = Span {
|
let span = args[0].span.to(last.span);
|
||||||
lo: args[0].span.lo,
|
|
||||||
hi: last.span.hi,
|
|
||||||
ctxt: args[0].span.ctxt,
|
|
||||||
};
|
|
||||||
|
|
||||||
format!("&[{}]", snippet(cx, span, "..")).into()
|
format!("&[{}]", snippet(cx, span, "..")).into()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user