Check for duplicate arguments in #[rustc_must_implement_one_of]
This commit is contained in:
parent
4ccfa97021
commit
c30ec5a6fd
@ -1303,6 +1303,32 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {
|
||||
});
|
||||
|
||||
(errors.count() == 0).then_some(list)
|
||||
})
|
||||
// Check for duplicates
|
||||
.and_then(|list| {
|
||||
let mut set: FxHashSet<&Ident> = FxHashSet::default();
|
||||
let mut no_dups = true;
|
||||
|
||||
for ident in &*list {
|
||||
if let Some(dup) = set.replace(ident) {
|
||||
let dup2 = set.get(&dup).copied().unwrap(); // We've just inserted it
|
||||
|
||||
tcx.sess
|
||||
.struct_span_err(
|
||||
vec![dup.span, dup2.span],
|
||||
"Functions names are duplicated",
|
||||
)
|
||||
.note(
|
||||
"All `#[rustc_must_implement_one_of]` arguments \
|
||||
must be unique",
|
||||
)
|
||||
.emit();
|
||||
|
||||
no_dups = false;
|
||||
}
|
||||
}
|
||||
|
||||
no_dups.then_some(list)
|
||||
});
|
||||
|
||||
ty::TraitDef::new(
|
||||
|
@ -0,0 +1,19 @@
|
||||
#![feature(rustc_attrs)]
|
||||
|
||||
#[rustc_must_implement_one_of(a, a)]
|
||||
//~^ 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
|
||||
trait Trait1 {
|
||||
fn a() {}
|
||||
fn b() {}
|
||||
fn c() {}
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -0,0 +1,34 @@
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
Loading…
x
Reference in New Issue
Block a user