mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Forbid ?Trait
bounds repetitions
This commit is contained in:
parent
2a73553513
commit
fd9d0bfbac
@ -75,16 +75,22 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if unbounds.len() > 1 && !tcx.features().more_maybe_bounds {
|
let mut unique_bounds = FxIndexSet::default();
|
||||||
self.tcx()
|
let mut seen_repeat = false;
|
||||||
.sess
|
for unbound in &unbounds {
|
||||||
.create_feature_err(
|
if let Res::Def(DefKind::Trait, unbound_def_id) = unbound.trait_ref.path.res {
|
||||||
errors::MultipleRelaxedDefaultBounds {
|
seen_repeat |= !unique_bounds.insert(unbound_def_id);
|
||||||
spans: unbounds.iter().map(|ptr| ptr.span).collect(),
|
}
|
||||||
},
|
}
|
||||||
sym::more_maybe_bounds,
|
if unbounds.len() > 1 {
|
||||||
)
|
let err = errors::MultipleRelaxedDefaultBounds {
|
||||||
.emit();
|
spans: unbounds.iter().map(|ptr| ptr.span).collect(),
|
||||||
|
};
|
||||||
|
if seen_repeat {
|
||||||
|
self.dcx().emit_err(err);
|
||||||
|
} else if !tcx.features().more_maybe_bounds {
|
||||||
|
self.tcx().sess.create_feature_err(err, sym::more_maybe_bounds).emit();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut seen_sized_unbound = false;
|
let mut seen_sized_unbound = false;
|
||||||
|
@ -14,4 +14,11 @@ fn bar<T: ?Trait1 + ?Trait2>(_: T) {}
|
|||||||
//~| WARN relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
//~| WARN relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
||||||
//~| WARN relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
//~| WARN relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
||||||
|
|
||||||
|
trait Trait {}
|
||||||
|
// Do not suggest `#![feature(more_maybe_bounds)]` for repetitions
|
||||||
|
fn baz<T: ?Trait + ?Trait>(_ : T) {}
|
||||||
|
//~^ ERROR type parameter has more than one relaxed default bound, only one is supported
|
||||||
|
//~| WARN relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
||||||
|
//~| WARN relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -47,7 +47,25 @@ warning: relaxing a default bound only does something for `?Sized`; all other tr
|
|||||||
LL | fn bar<T: ?Trait1 + ?Trait2>(_: T) {}
|
LL | fn bar<T: ?Trait1 + ?Trait2>(_: T) {}
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
|
|
||||||
error: aborting due to 4 previous errors; 2 warnings emitted
|
error[E0203]: type parameter has more than one relaxed default bound, only one is supported
|
||||||
|
--> $DIR/feature-gate-more-maybe-bounds.rs:19:11
|
||||||
|
|
|
||||||
|
LL | fn baz<T: ?Trait + ?Trait>(_ : T) {}
|
||||||
|
| ^^^^^^ ^^^^^^
|
||||||
|
|
||||||
|
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
||||||
|
--> $DIR/feature-gate-more-maybe-bounds.rs:19:11
|
||||||
|
|
|
||||||
|
LL | fn baz<T: ?Trait + ?Trait>(_ : T) {}
|
||||||
|
| ^^^^^^
|
||||||
|
|
||||||
|
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
||||||
|
--> $DIR/feature-gate-more-maybe-bounds.rs:19:20
|
||||||
|
|
|
||||||
|
LL | fn baz<T: ?Trait + ?Trait>(_ : T) {}
|
||||||
|
| ^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 5 previous errors; 4 warnings emitted
|
||||||
|
|
||||||
Some errors have detailed explanations: E0203, E0658.
|
Some errors have detailed explanations: E0203, E0658.
|
||||||
For more information about an error, try `rustc --explain E0203`.
|
For more information about an error, try `rustc --explain E0203`.
|
||||||
|
9
tests/ui/traits/maybe-polarity-repeated.rs
Normal file
9
tests/ui/traits/maybe-polarity-repeated.rs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#![feature(more_maybe_bounds)]
|
||||||
|
|
||||||
|
trait Trait {}
|
||||||
|
fn foo<T: ?Trait + ?Trait>(_: T) {}
|
||||||
|
//~^ ERROR type parameter has more than one relaxed default bound, only one is supported
|
||||||
|
//~| WARN relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
||||||
|
//~| WARN relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
||||||
|
|
||||||
|
fn main() {}
|
21
tests/ui/traits/maybe-polarity-repeated.stderr
Normal file
21
tests/ui/traits/maybe-polarity-repeated.stderr
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
error[E0203]: type parameter has more than one relaxed default bound, only one is supported
|
||||||
|
--> $DIR/maybe-polarity-repeated.rs:4:11
|
||||||
|
|
|
||||||
|
LL | fn foo<T: ?Trait + ?Trait>(_: T) {}
|
||||||
|
| ^^^^^^ ^^^^^^
|
||||||
|
|
||||||
|
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
||||||
|
--> $DIR/maybe-polarity-repeated.rs:4:11
|
||||||
|
|
|
||||||
|
LL | fn foo<T: ?Trait + ?Trait>(_: T) {}
|
||||||
|
| ^^^^^^
|
||||||
|
|
||||||
|
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
||||||
|
--> $DIR/maybe-polarity-repeated.rs:4:20
|
||||||
|
|
|
||||||
|
LL | fn foo<T: ?Trait + ?Trait>(_: T) {}
|
||||||
|
| ^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error; 2 warnings emitted
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0203`.
|
Loading…
Reference in New Issue
Block a user