Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove index type check (review comment)
  • Loading branch information
estebank committed Nov 25, 2017
commit 97d8d04f3fffd0984a2d2af2f24c104e75be8f01
17 changes: 0 additions & 17 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 5 additions & 11 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/suggestions/str-array-assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down