Skip to content

Commit 571182a

Browse files
author
Alexander Regueiro
committed
Several small fixes
1 parent c650069 commit 571182a

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

src/librustc/traits/specialize/specialization_graph.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ struct Children {
6262
pub enum FutureCompatOverlapErrorKind {
6363
Issue43355,
6464
Issue33140,
65-
Issue57057,
6665
}
6766

6867
#[derive(Debug)]

src/librustc_typeck/astconv.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,10 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
11391139
})
11401140
});
11411141

1142+
// HACK(#57057): see below.
1143+
let extra_principal_trait = auto_traits.iter().skip(1).any(
1144+
|tr| tr.trait_ref().def_id() == principal.def_id());
1145+
11421146
// Lint duplicate auto traits, and then remove duplicates.
11431147
auto_traits.sort_by_key(|i| i.trait_ref().def_id());
11441148
let emit_dup_traits_err = |range: Range<usize>| {
@@ -1166,14 +1170,19 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
11661170
if auto_traits.len() - seq_start > 1 {
11671171
emit_dup_traits_err(seq_start..auto_traits.len());
11681172
}
1169-
// Remove first auto trait if it is the principal trait.
1170-
// HACK(alexreg): we really want to do this *after* dedup, but we must maintain this
1171-
// behaviour for the sake of backwards compatibility, until the duplicate traits lint
1172-
// becomes a hard error.
1173-
if auto_traits.first().map_or(false, |tr| tr.trait_ref().def_id() == principal.def_id()) {
1174-
auto_traits.remove(0);
1175-
}
11761173
auto_traits.dedup_by_key(|i| i.trait_ref().def_id());
1174+
1175+
// If principal is auto trait, remove it from list of auto traits.
1176+
// HACK(#57057): we don't do this if the trait was mentioned multiple times.
1177+
// Previous behaviour was buggy in this respect, but we want to maintain backwards
1178+
// compatibility for now. This check will eventually be removed.
1179+
if !extra_principal_trait {
1180+
if let Some(principal_index) = auto_traits.iter().position(
1181+
|tr| tr.trait_ref().def_id() == principal.def_id()) {
1182+
auto_traits.remove(principal_index);
1183+
}
1184+
}
1185+
11771186
debug!("auto_traits: {:?}", auto_traits);
11781187

11791188
// Calling `skip_binder` is okay, since the predicates are re-bound.

src/test/ui/lint/lint-duplicate-traits.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
#![feature(trait_alias)]
44

55
trait Foo {}
6+
trait Bar {}
7+
trait Baz {}
68

79
trait SyncAlias = Sync;
810

911
impl Foo for dyn Send {}
1012

11-
impl Foo for dyn Send + Send {}
13+
impl Bar for dyn Send + Send {}
1214

13-
impl Foo for dyn Send + Sync + Send + SyncAlias {}
15+
impl Baz for dyn Send + Sync + Send + SyncAlias {}
1416

1517
fn main() {}

0 commit comments

Comments
 (0)