Skip to content

Commit

Permalink
Rollup merge of #105506 - estebank:rustc_must_implement_one_of, r=com…
Browse files Browse the repository at this point in the history
…piler-errors

Tweak `rustc_must_implement_one_of` diagnostic output
  • Loading branch information
matthiaskrgr committed Dec 9, 2022
2 parents d0563c6 + b3b17bd commit 376b0bc
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 39 deletions.
19 changes: 8 additions & 11 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {
.struct_span_err(
attr.span,
"the `#[rustc_must_implement_one_of]` attribute must be \
used with at least 2 args",
used with at least 2 args",
)
.emit();

Expand Down Expand Up @@ -987,7 +987,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {
tcx.sess
.struct_span_err(
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")
.emit();
Expand All @@ -999,17 +999,17 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {
}
Some(item) => {
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")
.note(
"All `#[rustc_must_implement_one_of]` arguments \
must be associated function names",
"all `#[rustc_must_implement_one_of]` arguments must be associated \
function names",
)
.emit();
}
None => {
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();
}
}
Expand All @@ -1027,11 +1027,8 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {
for ident in &*list {
if let Some(dup) = set.insert(ident.name, ident.span) {
tcx.sess
.struct_span_err(vec![dup, ident.span], "Functions names are duplicated")
.note(
"All `#[rustc_must_implement_one_of]` arguments \
must be unique",
)
.struct_span_err(vec![dup, ident.span], "functions names are duplicated")
.note("all `#[rustc_must_implement_one_of]` arguments must be unique")
.emit();

no_dups = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#![feature(rustc_attrs)]

#[rustc_must_implement_one_of(a, a)]
//~^ Functions names are duplicated
//~^ functions names are duplicated
trait Trait {
fn a() {}
}

#[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 {
fn a() {}
fn b() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
error: Functions names are duplicated
error: functions names are duplicated
--> $DIR/rustc_must_implement_one_of_duplicates.rs:3:31
|
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
|
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
|
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
|
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

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#![feature(rustc_attrs)]

#[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 {}

#[rustc_must_implement_one_of(a, b)]
//~^ Function not found in this trait
//~^ function not found in this trait
trait Tr1 {
fn a() {}
}
Expand All @@ -23,16 +23,16 @@ trait Tr3 {}

#[rustc_must_implement_one_of(A, B)]
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)]
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)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ LL |
LL | struct Struct {}
| ---------------- 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
|
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
|
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
|
LL | #[rustc_must_implement_one_of(a, b)]
Expand All @@ -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)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: Not a function
error: not a function
--> $DIR/rustc_must_implement_one_of_misuse.rs:26:5
|
LL | const A: u8 = 1;
Expand All @@ -57,9 +57,9 @@ note: required by this annotation
|
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
|
LL | type B;
Expand All @@ -70,9 +70,9 @@ note: required by this annotation
|
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
|
LL | fn a();
Expand All @@ -84,7 +84,7 @@ note: required by this annotation
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
|
LL | fn b();
Expand Down

0 comments on commit 376b0bc

Please sign in to comment.