Review fixes.
- `span_suggestion` changed to `span_suggestion_short`; - `Span` used changed to contain only `&` refs; - Tests passing.
This commit is contained in:
parent
c1ba5ac62c
commit
74a4928ed4
@ -914,13 +914,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
new_trait_ref.to_predicate());
|
||||
|
||||
if selcx.evaluate_obligation(&new_obligation) {
|
||||
let sp = self.tcx.sess.codemap()
|
||||
.span_take_while(span, |c| c.is_whitespace() || *c == '&');
|
||||
|
||||
let remove_refs = refs_remaining + 1;
|
||||
let format_str = format!("consider removing {} leading `&`-references",
|
||||
remove_refs);
|
||||
|
||||
err.span_suggestion_short(span,
|
||||
&format!("consider removing {} leading `&`-references",
|
||||
remove_refs),
|
||||
String::from(""));
|
||||
|
||||
err.span_suggestion_short(sp, &format_str, String::from(""));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
|
@ -697,6 +697,22 @@ impl CodeMap {
|
||||
sp
|
||||
}
|
||||
|
||||
/// Given a `Span`, get a shorter one until `predicate` yields false.
|
||||
pub fn span_take_while<P>(&self, sp: Span, predicate: P) -> Span
|
||||
where P: for <'r> FnMut(&'r char) -> bool
|
||||
{
|
||||
if let Ok(snippet) = self.span_to_snippet(sp) {
|
||||
let offset = snippet.chars()
|
||||
.take_while(predicate)
|
||||
.map(|c| c.len_utf8())
|
||||
.sum::<usize>();
|
||||
|
||||
sp.with_hi(BytePos(sp.lo().0 + (offset as u32)))
|
||||
} else {
|
||||
sp
|
||||
}
|
||||
}
|
||||
|
||||
pub fn def_span(&self, sp: Span) -> Span {
|
||||
self.span_until_char(sp, '{')
|
||||
}
|
||||
|
@ -2,10 +2,10 @@ error[E0277]: the trait bound `&std::iter::Enumerate<std::slice::Iter<'_, {integ
|
||||
--> $DIR/suggest-remove-refs-1.rs:14:19
|
||||
|
|
||||
LL | for (i, n) in &v.iter().enumerate() {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
| -^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| `&std::iter::Enumerate<std::slice::Iter<'_, {integer}>>` is not an iterator; maybe try calling `.iter()` or a similar method
|
||||
| help: consider removing 1 references `&`: `v.iter().enumerate()`
|
||||
| help: consider removing 1 leading `&`-references
|
||||
|
|
||||
= help: the trait `std::iter::Iterator` is not implemented for `&std::iter::Enumerate<std::slice::Iter<'_, {integer}>>`
|
||||
= note: required by `std::iter::IntoIterator::into_iter`
|
||||
|
@ -2,10 +2,10 @@ error[E0277]: the trait bound `&&&&&std::iter::Enumerate<std::slice::Iter<'_, {i
|
||||
--> $DIR/suggest-remove-refs-2.rs:14:19
|
||||
|
|
||||
LL | for (i, n) in & & & & &v.iter().enumerate() {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ---------^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| `&&&&&std::iter::Enumerate<std::slice::Iter<'_, {integer}>>` is not an iterator; maybe try calling `.iter()` or a similar method
|
||||
| help: consider removing 5 references `&`: `v.iter().enumerate()`
|
||||
| help: consider removing 5 leading `&`-references
|
||||
|
|
||||
= help: the trait `std::iter::Iterator` is not implemented for `&&&&&std::iter::Enumerate<std::slice::Iter<'_, {integer}>>`
|
||||
= note: required by `std::iter::IntoIterator::into_iter`
|
||||
|
@ -1,21 +1,18 @@
|
||||
error[E0277]: the trait bound `&&&&&std::iter::Enumerate<std::slice::Iter<'_, {integer}>>: std::iter::Iterator` is not satisfied
|
||||
--> $DIR/suggest-remove-refs-3.rs:14:19
|
||||
|
|
||||
LL | for (i, n) in & & &
|
||||
| ___________________^
|
||||
LL | | & &v
|
||||
LL | | .iter()
|
||||
LL | | .enumerate() {
|
||||
| |____________________^ `&&&&&std::iter::Enumerate<std::slice::Iter<'_, {integer}>>` is not an iterator; maybe try calling `.iter()` or a similar method
|
||||
LL | for (i, n) in & & &
|
||||
| ___________________^
|
||||
| |___________________|
|
||||
| ||
|
||||
LL | || & &v
|
||||
| ||___________- help: consider removing 5 leading `&`-references
|
||||
LL | | .iter()
|
||||
LL | | .enumerate() {
|
||||
| |_____________________^ `&&&&&std::iter::Enumerate<std::slice::Iter<'_, {integer}>>` is not an iterator; maybe try calling `.iter()` or a similar method
|
||||
|
|
||||
= help: the trait `std::iter::Iterator` is not implemented for `&&&&&std::iter::Enumerate<std::slice::Iter<'_, {integer}>>`
|
||||
= note: required by `std::iter::IntoIterator::into_iter`
|
||||
help: consider removing 5 references `&`
|
||||
|
|
||||
LL | for (i, n) in v
|
||||
LL | .iter()
|
||||
LL | .enumerate() {
|
||||
|
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user