1
Fork 0

use named_span in case of tuple variant

This commit is contained in:
Takayuki Maeda 2022-07-04 18:13:16 +09:00
parent 3d1b679a3c
commit 0541b4e034
14 changed files with 26 additions and 31 deletions

View file

@ -1012,12 +1012,7 @@ impl<'hir> Map<'hir> {
ItemKind::Use(path, _) => path.span, ItemKind::Use(path, _) => path.span,
_ => named_span(item.span, item.ident, item.kind.generics()), _ => named_span(item.span, item.ident, item.kind.generics()),
}, },
Node::Variant(variant) => match variant.data { Node::Variant(variant) => named_span(variant.span, variant.ident, None),
VariantData::Struct(..) | VariantData::Unit(..) => {
named_span(variant.span, variant.ident, None)
}
VariantData::Tuple(..) => variant.span,
},
Node::ImplItem(item) => named_span(item.span, item.ident, Some(item.generics)), Node::ImplItem(item) => named_span(item.span, item.ident, Some(item.generics)),
Node::ForeignItem(item) => match item.kind { Node::ForeignItem(item) => match item.kind {
ForeignItemKind::Fn(decl, _, _) => until_within(item.span, decl.output.span()), ForeignItemKind::Fn(decl, _, _) => until_within(item.span, decl.output.span()),

View file

@ -341,7 +341,7 @@ fn report_negative_positive_conflict(
positive_impl_def_id: DefId, positive_impl_def_id: DefId,
sg: &mut specialization_graph::Graph, sg: &mut specialization_graph::Graph,
) { ) {
let impl_span = tcx.span_of_impl(local_impl_def_id.to_def_id()).unwrap(); let impl_span = tcx.def_span(local_impl_def_id);
let mut err = struct_span_err!( let mut err = struct_span_err!(
tcx.sess, tcx.sess,

View file

@ -19,7 +19,7 @@ LL | XEmpty3 {},
| ------- `XE::XEmpty3` defined here | ------- `XE::XEmpty3` defined here
LL | XEmpty4, LL | XEmpty4,
LL | XEmpty5(), LL | XEmpty5(),
| --------- similarly named tuple variant `XEmpty5` defined here | ------- similarly named tuple variant `XEmpty5` defined here
| |
help: use struct pattern syntax instead help: use struct pattern syntax instead
| |
@ -51,7 +51,7 @@ LL | XEmpty3 {},
| ------- `XE::XEmpty3` defined here | ------- `XE::XEmpty3` defined here
LL | XEmpty4, LL | XEmpty4,
LL | XEmpty5(), LL | XEmpty5(),
| --------- similarly named tuple variant `XEmpty5` defined here | ------- similarly named tuple variant `XEmpty5` defined here
| |
help: use struct pattern syntax instead help: use struct pattern syntax instead
| |

View file

@ -36,7 +36,7 @@ LL | XE::XEmpty5 => (),
LL | XEmpty4, LL | XEmpty4,
| ------- similarly named unit variant `XEmpty4` defined here | ------- similarly named unit variant `XEmpty4` defined here
LL | XEmpty5(), LL | XEmpty5(),
| --------- `XE::XEmpty5` defined here | ------- `XE::XEmpty5` defined here
| |
help: use the tuple variant pattern syntax instead help: use the tuple variant pattern syntax instead
| |

View file

@ -108,7 +108,7 @@ LL | XE::XEmpty4() => (),
LL | XEmpty4, LL | XEmpty4,
| ------- `XE::XEmpty4` defined here | ------- `XE::XEmpty4` defined here
LL | XEmpty5(), LL | XEmpty5(),
| --------- similarly named tuple variant `XEmpty5` defined here | ------- similarly named tuple variant `XEmpty5` defined here
| |
help: use this syntax instead help: use this syntax instead
| |
@ -139,7 +139,7 @@ LL | XE::XEmpty4(..) => (),
LL | XEmpty4, LL | XEmpty4,
| ------- `XE::XEmpty4` defined here | ------- `XE::XEmpty4` defined here
LL | XEmpty5(), LL | XEmpty5(),
| --------- similarly named tuple variant `XEmpty5` defined here | ------- similarly named tuple variant `XEmpty5` defined here
| |
help: use this syntax instead help: use this syntax instead
| |

View file

@ -19,7 +19,7 @@ error[E0593]: function is expected to take 0 arguments, but it takes 1 argument
--> $DIR/issue-47706.rs:27:9 --> $DIR/issue-47706.rs:27:9
| |
LL | Bar(i32), LL | Bar(i32),
| -------- takes 1 argument | --- takes 1 argument
... ...
LL | foo(Qux::Bar); LL | foo(Qux::Bar);
| --- ^^^^^^^^ expected function that takes 0 arguments | --- ^^^^^^^^ expected function that takes 0 arguments

View file

@ -94,7 +94,7 @@ LL | check(xm7::V);
LL | V {}, LL | V {},
| - `xm7::V` defined here | - `xm7::V` defined here
LL | TV(), LL | TV(),
| ---- similarly named tuple variant `TV` defined here | -- similarly named tuple variant `TV` defined here
| |
help: use struct literal syntax instead help: use struct literal syntax instead
| |

View file

@ -60,7 +60,7 @@ LL | E1::Z0() => {}
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:15 ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:15
| |
LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) } LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) }
| -- ---- similarly named tuple variant `Z1` defined here | -- -- similarly named tuple variant `Z1` defined here
| | | |
| `E1::Z0` defined here | `E1::Z0` defined here
| |
@ -82,7 +82,7 @@ LL | E1::Z0(x) => {}
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:15 ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:15
| |
LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) } LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) }
| -- ---- similarly named tuple variant `Z1` defined here | -- -- similarly named tuple variant `Z1` defined here
| | | |
| `E1::Z0` defined here | `E1::Z0` defined here
| |
@ -104,7 +104,7 @@ LL | E1::Z1 => {}
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:19 ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:19
| |
LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) } LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) }
| -- ---- `E1::Z1` defined here | -- -- `E1::Z1` defined here
| | | |
| similarly named unit variant `Z0` defined here | similarly named unit variant `Z0` defined here
| |
@ -295,7 +295,7 @@ LL | E1::Z1(x) => {}
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:19 ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:19
| |
LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) } LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) }
| ---- tuple variant has 0 fields | -- tuple variant has 0 fields
error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 3 fields error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 3 fields
--> $DIR/pat-tuple-field-count-cross.rs:39:9 --> $DIR/pat-tuple-field-count-cross.rs:39:9

View file

@ -289,7 +289,7 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has
--> $DIR/pat-tuple-overfield.rs:71:16 --> $DIR/pat-tuple-overfield.rs:71:16
| |
LL | Z1(), LL | Z1(),
| ---- tuple variant has 0 fields | -- tuple variant has 0 fields
... ...
LL | E1::Z1(_) => {} LL | E1::Z1(_) => {}
| ^ expected 0 fields, found 1 | ^ expected 0 fields, found 1
@ -298,7 +298,7 @@ error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has
--> $DIR/pat-tuple-overfield.rs:72:16 --> $DIR/pat-tuple-overfield.rs:72:16
| |
LL | Z1(), LL | Z1(),
| ---- tuple variant has 0 fields | -- tuple variant has 0 fields
... ...
LL | E1::Z1(_, _) => {} LL | E1::Z1(_, _) => {}
| ^ ^ expected 0 fields, found 2 | ^ ^ expected 0 fields, found 2

View file

@ -148,7 +148,7 @@ LL | one!("hello", "world");
::: $SRC_DIR/core/src/result.rs:LL:COL ::: $SRC_DIR/core/src/result.rs:LL:COL
| |
LL | Ok(#[stable(feature = "rust1", since = "1.0.0")] T), LL | Ok(#[stable(feature = "rust1", since = "1.0.0")] T),
| --------------------------------------------------- similarly named tuple variant `Ok` defined here | -- similarly named tuple variant `Ok` defined here
| |
= note: this error originates in the macro `parent_source_spans` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `parent_source_spans` (in Nightly builds, run with -Z macro-backtrace for more info)
@ -164,7 +164,7 @@ LL | two!("yay", "rust");
::: $SRC_DIR/core/src/result.rs:LL:COL ::: $SRC_DIR/core/src/result.rs:LL:COL
| |
LL | Ok(#[stable(feature = "rust1", since = "1.0.0")] T), LL | Ok(#[stable(feature = "rust1", since = "1.0.0")] T),
| --------------------------------------------------- similarly named tuple variant `Ok` defined here | -- similarly named tuple variant `Ok` defined here
| |
= note: this error originates in the macro `parent_source_spans` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `parent_source_spans` (in Nightly builds, run with -Z macro-backtrace for more info)
@ -180,7 +180,7 @@ LL | three!("hip", "hop");
::: $SRC_DIR/core/src/result.rs:LL:COL ::: $SRC_DIR/core/src/result.rs:LL:COL
| |
LL | Ok(#[stable(feature = "rust1", since = "1.0.0")] T), LL | Ok(#[stable(feature = "rust1", since = "1.0.0")] T),
| --------------------------------------------------- similarly named tuple variant `Ok` defined here | -- similarly named tuple variant `Ok` defined here
| |
= note: this error originates in the macro `parent_source_spans` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `parent_source_spans` (in Nightly builds, run with -Z macro-backtrace for more info)

View file

@ -58,7 +58,7 @@ error[E0731]: transparent enum needs exactly one variant, but has 2
LL | enum MultipleVariants { LL | enum MultipleVariants {
| ^^^^^^^^^^^^^^^^^^^^^ needs exactly one variant, but has 2 | ^^^^^^^^^^^^^^^^^^^^^ needs exactly one variant, but has 2
LL | Foo(String), LL | Foo(String),
| ----------- | ---
LL | Bar, LL | Bar,
| --- too many variants in `MultipleVariants` | --- too many variants in `MultipleVariants`

View file

@ -318,7 +318,7 @@ error[E0308]: mismatched types
--> $DIR/privacy-enum-ctor.rs:27:20 --> $DIR/privacy-enum-ctor.rs:27:20
| |
LL | Fn(u8), LL | Fn(u8),
| ------ fn(u8) -> Z {Z::Fn} defined here | -- fn(u8) -> Z {Z::Fn} defined here
... ...
LL | let _: Z = Z::Fn; LL | let _: Z = Z::Fn;
| - ^^^^^ expected enum `Z`, found fn item | - ^^^^^ expected enum `Z`, found fn item
@ -353,7 +353,7 @@ error[E0308]: mismatched types
--> $DIR/privacy-enum-ctor.rs:43:16 --> $DIR/privacy-enum-ctor.rs:43:16
| |
LL | Fn(u8), LL | Fn(u8),
| ------ fn(u8) -> E {E::Fn} defined here | -- fn(u8) -> E {E::Fn} defined here
... ...
LL | let _: E = m::E::Fn; LL | let _: E = m::E::Fn;
| - ^^^^^^^^ expected enum `E`, found fn item | - ^^^^^^^^ expected enum `E`, found fn item
@ -388,7 +388,7 @@ error[E0308]: mismatched types
--> $DIR/privacy-enum-ctor.rs:51:16 --> $DIR/privacy-enum-ctor.rs:51:16
| |
LL | Fn(u8), LL | Fn(u8),
| ------ fn(u8) -> E {E::Fn} defined here | -- fn(u8) -> E {E::Fn} defined here
... ...
LL | let _: E = E::Fn; LL | let _: E = E::Fn;
| - ^^^^^ expected enum `E`, found fn item | - ^^^^^ expected enum `E`, found fn item

View file

@ -8,7 +8,7 @@ note: the tuple variant `Tuple` is defined here
--> $DIR/auxiliary/variants.rs:5:23 --> $DIR/auxiliary/variants.rs:5:23
| |
LL | #[non_exhaustive] Tuple(u32), LL | #[non_exhaustive] Tuple(u32),
| ^^^^^^^^^^ | ^^^^^
error[E0603]: unit variant `Unit` is private error[E0603]: unit variant `Unit` is private
--> $DIR/variant.rs:14:47 --> $DIR/variant.rs:14:47
@ -44,7 +44,7 @@ note: the tuple variant `Tuple` is defined here
--> $DIR/auxiliary/variants.rs:5:23 --> $DIR/auxiliary/variants.rs:5:23
| |
LL | #[non_exhaustive] Tuple(u32), LL | #[non_exhaustive] Tuple(u32),
| ^^^^^^^^^^ | ^^^^^
error[E0603]: tuple variant `Tuple` is private error[E0603]: tuple variant `Tuple` is private
--> $DIR/variant.rs:26:35 --> $DIR/variant.rs:26:35
@ -56,7 +56,7 @@ note: the tuple variant `Tuple` is defined here
--> $DIR/auxiliary/variants.rs:5:23 --> $DIR/auxiliary/variants.rs:5:23
| |
LL | #[non_exhaustive] Tuple(u32), LL | #[non_exhaustive] Tuple(u32),
| ^^^^^^^^^^ | ^^^^^
error[E0639]: cannot create non-exhaustive variant using struct expression error[E0639]: cannot create non-exhaustive variant using struct expression
--> $DIR/variant.rs:8:26 --> $DIR/variant.rs:8:26

View file

@ -130,7 +130,7 @@ error[E0308]: mismatched types
--> $DIR/fn-or-tuple-struct-without-args.rs:35:16 --> $DIR/fn-or-tuple-struct-without-args.rs:35:16
| |
LL | A(usize), LL | A(usize),
| -------- fn(usize) -> E {E::A} defined here | - fn(usize) -> E {E::A} defined here
... ...
LL | let _: E = E::A; LL | let _: E = E::A;
| - ^^^^ expected enum `E`, found fn item | - ^^^^ expected enum `E`, found fn item