1
Fork 0

Tweak rustc_must_implement_one_of diagnostic output

This commit is contained in:
Esteban Küber 2022-12-09 10:44:11 -08:00
parent e10201c9bb
commit b3b17bde31
5 changed files with 36 additions and 39 deletions

View file

@ -987,7 +987,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {
tcx.sess tcx.sess
.struct_span_err( .struct_span_err(
item.span, item.span,
"This function doesn't have a default implementation", "function doesn't have a default implementation",
) )
.span_note(attr_span, "required by this annotation") .span_note(attr_span, "required by this annotation")
.emit(); .emit();
@ -999,17 +999,17 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {
} }
Some(item) => { Some(item) => {
tcx.sess tcx.sess
.struct_span_err(item.span, "Not a function") .struct_span_err(item.span, "not a function")
.span_note(attr_span, "required by this annotation") .span_note(attr_span, "required by this annotation")
.note( .note(
"All `#[rustc_must_implement_one_of]` arguments \ "all `#[rustc_must_implement_one_of]` arguments must be associated \
must be associated function names", function names",
) )
.emit(); .emit();
} }
None => { None => {
tcx.sess tcx.sess
.struct_span_err(ident.span, "Function not found in this trait") .struct_span_err(ident.span, "function not found in this trait")
.emit(); .emit();
} }
} }
@ -1027,11 +1027,8 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {
for ident in &*list { for ident in &*list {
if let Some(dup) = set.insert(ident.name, ident.span) { if let Some(dup) = set.insert(ident.name, ident.span) {
tcx.sess tcx.sess
.struct_span_err(vec![dup, ident.span], "Functions names are duplicated") .struct_span_err(vec![dup, ident.span], "functions names are duplicated")
.note( .note("all `#[rustc_must_implement_one_of]` arguments must be unique")
"All `#[rustc_must_implement_one_of]` arguments \
must be unique",
)
.emit(); .emit();
no_dups = false; no_dups = false;

View file

@ -1,15 +1,15 @@
#![feature(rustc_attrs)] #![feature(rustc_attrs)]
#[rustc_must_implement_one_of(a, a)] #[rustc_must_implement_one_of(a, a)]
//~^ Functions names are duplicated //~^ functions names are duplicated
trait Trait { trait Trait {
fn a() {} fn a() {}
} }
#[rustc_must_implement_one_of(b, a, a, c, b, c)] #[rustc_must_implement_one_of(b, a, a, c, b, c)]
//~^ Functions names are duplicated //~^ functions names are duplicated
//~| Functions names are duplicated //~| functions names are duplicated
//~| Functions names are duplicated //~| functions names are duplicated
trait Trait1 { trait Trait1 {
fn a() {} fn a() {}
fn b() {} fn b() {}

View file

@ -1,34 +1,34 @@
error: Functions names are duplicated error: functions names are duplicated
--> $DIR/rustc_must_implement_one_of_duplicates.rs:3:31 --> $DIR/rustc_must_implement_one_of_duplicates.rs:3:31
| |
LL | #[rustc_must_implement_one_of(a, a)] LL | #[rustc_must_implement_one_of(a, a)]
| ^ ^ | ^ ^
| |
= note: All `#[rustc_must_implement_one_of]` arguments must be unique = note: all `#[rustc_must_implement_one_of]` arguments must be unique
error: Functions names are duplicated error: functions names are duplicated
--> $DIR/rustc_must_implement_one_of_duplicates.rs:9:34 --> $DIR/rustc_must_implement_one_of_duplicates.rs:9:34
| |
LL | #[rustc_must_implement_one_of(b, a, a, c, b, c)] LL | #[rustc_must_implement_one_of(b, a, a, c, b, c)]
| ^ ^ | ^ ^
| |
= note: All `#[rustc_must_implement_one_of]` arguments must be unique = note: all `#[rustc_must_implement_one_of]` arguments must be unique
error: Functions names are duplicated error: functions names are duplicated
--> $DIR/rustc_must_implement_one_of_duplicates.rs:9:31 --> $DIR/rustc_must_implement_one_of_duplicates.rs:9:31
| |
LL | #[rustc_must_implement_one_of(b, a, a, c, b, c)] LL | #[rustc_must_implement_one_of(b, a, a, c, b, c)]
| ^ ^ | ^ ^
| |
= note: All `#[rustc_must_implement_one_of]` arguments must be unique = note: all `#[rustc_must_implement_one_of]` arguments must be unique
error: Functions names are duplicated error: functions names are duplicated
--> $DIR/rustc_must_implement_one_of_duplicates.rs:9:40 --> $DIR/rustc_must_implement_one_of_duplicates.rs:9:40
| |
LL | #[rustc_must_implement_one_of(b, a, a, c, b, c)] LL | #[rustc_must_implement_one_of(b, a, a, c, b, c)]
| ^ ^ | ^ ^
| |
= note: All `#[rustc_must_implement_one_of]` arguments must be unique = note: all `#[rustc_must_implement_one_of]` arguments must be unique
error: aborting due to 4 previous errors error: aborting due to 4 previous errors

View file

@ -1,12 +1,12 @@
#![feature(rustc_attrs)] #![feature(rustc_attrs)]
#[rustc_must_implement_one_of(a, b)] #[rustc_must_implement_one_of(a, b)]
//~^ Function not found in this trait //~^ function not found in this trait
//~| Function not found in this trait //~| function not found in this trait
trait Tr0 {} trait Tr0 {}
#[rustc_must_implement_one_of(a, b)] #[rustc_must_implement_one_of(a, b)]
//~^ Function not found in this trait //~^ function not found in this trait
trait Tr1 { trait Tr1 {
fn a() {} fn a() {}
} }
@ -23,16 +23,16 @@ trait Tr3 {}
#[rustc_must_implement_one_of(A, B)] #[rustc_must_implement_one_of(A, B)]
trait Tr4 { trait Tr4 {
const A: u8 = 1; //~ Not a function const A: u8 = 1; //~ not a function
type B; //~ Not a function type B; //~ not a function
} }
#[rustc_must_implement_one_of(a, b)] #[rustc_must_implement_one_of(a, b)]
trait Tr5 { trait Tr5 {
fn a(); //~ This function doesn't have a default implementation fn a(); //~ function doesn't have a default implementation
fn b(); //~ This function doesn't have a default implementation fn b(); //~ function doesn't have a default implementation
} }
#[rustc_must_implement_one_of(abc, xyz)] #[rustc_must_implement_one_of(abc, xyz)]

View file

@ -22,19 +22,19 @@ LL |
LL | struct Struct {} LL | struct Struct {}
| ---------------- not a trait | ---------------- not a trait
error: Function not found in this trait error: function not found in this trait
--> $DIR/rustc_must_implement_one_of_misuse.rs:3:31 --> $DIR/rustc_must_implement_one_of_misuse.rs:3:31
| |
LL | #[rustc_must_implement_one_of(a, b)] LL | #[rustc_must_implement_one_of(a, b)]
| ^ | ^
error: Function not found in this trait error: function not found in this trait
--> $DIR/rustc_must_implement_one_of_misuse.rs:3:34 --> $DIR/rustc_must_implement_one_of_misuse.rs:3:34
| |
LL | #[rustc_must_implement_one_of(a, b)] LL | #[rustc_must_implement_one_of(a, b)]
| ^ | ^
error: Function not found in this trait error: function not found in this trait
--> $DIR/rustc_must_implement_one_of_misuse.rs:8:34 --> $DIR/rustc_must_implement_one_of_misuse.rs:8:34
| |
LL | #[rustc_must_implement_one_of(a, b)] LL | #[rustc_must_implement_one_of(a, b)]
@ -46,7 +46,7 @@ error: the `#[rustc_must_implement_one_of]` attribute must be used with at least
LL | #[rustc_must_implement_one_of(a)] LL | #[rustc_must_implement_one_of(a)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Not a function error: not a function
--> $DIR/rustc_must_implement_one_of_misuse.rs:26:5 --> $DIR/rustc_must_implement_one_of_misuse.rs:26:5
| |
LL | const A: u8 = 1; LL | const A: u8 = 1;
@ -57,9 +57,9 @@ note: required by this annotation
| |
LL | #[rustc_must_implement_one_of(A, B)] LL | #[rustc_must_implement_one_of(A, B)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: All `#[rustc_must_implement_one_of]` arguments must be associated function names = note: all `#[rustc_must_implement_one_of]` arguments must be associated function names
error: Not a function error: not a function
--> $DIR/rustc_must_implement_one_of_misuse.rs:28:5 --> $DIR/rustc_must_implement_one_of_misuse.rs:28:5
| |
LL | type B; LL | type B;
@ -70,9 +70,9 @@ note: required by this annotation
| |
LL | #[rustc_must_implement_one_of(A, B)] LL | #[rustc_must_implement_one_of(A, B)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: All `#[rustc_must_implement_one_of]` arguments must be associated function names = note: all `#[rustc_must_implement_one_of]` arguments must be associated function names
error: This function doesn't have a default implementation error: function doesn't have a default implementation
--> $DIR/rustc_must_implement_one_of_misuse.rs:33:5 --> $DIR/rustc_must_implement_one_of_misuse.rs:33:5
| |
LL | fn a(); LL | fn a();
@ -84,7 +84,7 @@ note: required by this annotation
LL | #[rustc_must_implement_one_of(a, b)] LL | #[rustc_must_implement_one_of(a, b)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: This function doesn't have a default implementation error: function doesn't have a default implementation
--> $DIR/rustc_must_implement_one_of_misuse.rs:35:5 --> $DIR/rustc_must_implement_one_of_misuse.rs:35:5
| |
LL | fn b(); LL | fn b();