Rollup merge of #83092 - petrochenkov:qspan, r=estebank

More precise spans for HIR paths

`Ty::assoc_item` is lowered to `<Ty>::assoc_item` in HIR, but `Ty` got span from the whole path.
This PR fixes that, and adjusts some diagnostic code that relied on `Ty` having the whole path span.

This is a pre-requisite for https://github.com/rust-lang/rust/pull/82868 (we cannot report suggestions like `Tr::assoc` -> `<dyn Tr>::assoc` with the current imprecise spans).
r? ````@estebank````
This commit is contained in:
Yuki Okushi 2021-03-17 15:20:54 +09:00 committed by GitHub
commit 5476382dda
5 changed files with 26 additions and 36 deletions

View file

@ -312,17 +312,18 @@ mod issue4140 {
fn try_from(value: T) -> Result<Self, Error<Self::From, Self::To>>; fn try_from(value: T) -> Result<Self, Error<Self::From, Self::To>>;
} }
impl<F, T> TryFrom<F> for T // FIXME: Suggested fix results in infinite recursion.
where // impl<F, T> TryFrom<F> for T
T: From<F>, // where
{ // T: From<F>,
type From = Self; // {
type To = Self; // type From = Self::From;
// type To = Self::To;
fn try_from(value: F) -> Result<Self, Error<Self::From, Self::To>> { // fn try_from(value: F) -> Result<Self, Error<Self::From, Self::To>> {
Ok(From::from(value)) // Ok(From::from(value))
} // }
} // }
impl From<bool> for i64 { impl From<bool> for i64 {
type From = bool; type From = bool;

View file

@ -312,17 +312,18 @@ mod issue4140 {
fn try_from(value: T) -> Result<Self, Error<Self::From, Self::To>>; fn try_from(value: T) -> Result<Self, Error<Self::From, Self::To>>;
} }
impl<F, T> TryFrom<F> for T // FIXME: Suggested fix results in infinite recursion.
where // impl<F, T> TryFrom<F> for T
T: From<F>, // where
{ // T: From<F>,
type From = T::From; // {
type To = T::To; // type From = Self::From;
// type To = Self::To;
fn try_from(value: F) -> Result<Self, Error<Self::From, Self::To>> { // fn try_from(value: F) -> Result<Self, Error<Self::From, Self::To>> {
Ok(From::from(value)) // Ok(From::from(value))
} // }
} // }
impl From<bool> for i64 { impl From<bool> for i64 {
type From = bool; type From = bool;

View file

@ -157,22 +157,10 @@ LL | Foo { value }
| ^^^ help: use the applicable keyword: `Self` | ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition error: unnecessary structure name repetition
--> $DIR/use_self.rs:319:21 --> $DIR/use_self.rs:454:13
|
LL | type From = T::From;
| ^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:320:19
|
LL | type To = T::To;
| ^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:453:13
| |
LL | A::new::<submod::B>(submod::B {}) LL | A::new::<submod::B>(submod::B {})
| ^ help: use the applicable keyword: `Self` | ^ help: use the applicable keyword: `Self`
error: aborting due to 29 previous errors error: aborting due to 27 previous errors

View file

@ -83,7 +83,7 @@ error: map with zero-sized value type
--> $DIR/zero_sized_btreemap_values.rs:64:35 --> $DIR/zero_sized_btreemap_values.rs:64:35
| |
LL | let _: BTreeMap<String, ()> = BTreeMap::new(); LL | let _: BTreeMap<String, ()> = BTreeMap::new();
| ^^^^^^^^^^^^^ | ^^^^^^^^
| |
= help: consider using a set instead = help: consider using a set instead

View file

@ -83,7 +83,7 @@ error: map with zero-sized value type
--> $DIR/zero_sized_hashmap_values.rs:64:34 --> $DIR/zero_sized_hashmap_values.rs:64:34
| |
LL | let _: HashMap<String, ()> = HashMap::new(); LL | let _: HashMap<String, ()> = HashMap::new();
| ^^^^^^^^^^^^ | ^^^^^^^
| |
= help: consider using a set instead = help: consider using a set instead