Remove index type check (review comment)

This commit is contained in:
Esteban Küber 2017-11-25 06:20:07 -08:00
parent cde0023b5b
commit 97d8d04f3f
3 changed files with 6 additions and 29 deletions

View File

@ -244,23 +244,6 @@ impl Path {
pub fn is_global(&self) -> bool {
!self.segments.is_empty() && self.segments[0].name == keywords::CrateRoot.name()
}
/// Wether this path is any of `::std::ops::{Range, RangeTo, RangeFrom}`.
pub fn is_range(&self) -> bool {
let mut base = ["{{root}}", "std", "ops"].iter().map(|p| p.to_string()).collect::<Vec<_>>();
let range_paths = ["Range", "RangeTo", "RangeFrom"];
let segments = self.segments.iter()
.map(|segment| format!("{}", segment.name))
.collect::<Vec<String>>();
for path in &range_paths {
base.push(path.to_string());
if base == segments {
return true;
}
base.pop();
}
false
}
}
impl fmt::Debug for Path {

View File

@ -832,17 +832,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
let parent_node = self.tcx.hir.get_parent_node(node_id);
if let Some(hir::map::NodeLocal(ref local)) = self.tcx.hir.find(parent_node) {
if let Some(ref expr) = local.init {
if let hir::ExprIndex(_, ref index) = expr.node {
if let hir::ExprStruct(hir::QPath::Resolved(None, ref path),
..) = index.node {
if let (Ok(snippet), true) = (
self.tcx.sess.codemap().span_to_snippet(expr.span),
path.is_range()
) {
err.span_suggestion(expr.span,
"consider a slice instead",
format!("&{}", snippet));
}
if let hir::ExprIndex(_, _) = expr.node {
if let Ok(snippet) = self.tcx.sess.codemap().span_to_snippet(expr.span) {
err.span_suggestion(expr.span,
"consider a slice instead",
format!("&{}", snippet));
}
}
}

View File

@ -20,7 +20,7 @@ fn main() { //~ NOTE expected `()` because of default return type
//~| NOTE expected type
let v = s[..2];
//~^ ERROR the trait bound `str: std::marker::Sized` is not satisfied
//~| NOTE consider a slice instead
//~| HELP consider a slice instead
//~| NOTE `str` does not have a constant size known at compile-time
//~| HELP the trait `std::marker::Sized` is not implemented for `str`
//~| NOTE all local variables must have a statically known size