Reword diagnostics about relaxed bounds in invalid contexts
This commit is contained in:
@@ -60,7 +60,7 @@ use rustc_index::{Idx, IndexSlice, IndexVec};
|
|||||||
use rustc_macros::extension;
|
use rustc_macros::extension;
|
||||||
use rustc_middle::span_bug;
|
use rustc_middle::span_bug;
|
||||||
use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
|
use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
|
||||||
use rustc_session::parse::{add_feature_diagnostics, feature_err};
|
use rustc_session::parse::add_feature_diagnostics;
|
||||||
use rustc_span::symbol::{Ident, Symbol, kw, sym};
|
use rustc_span::symbol::{Ident, Symbol, kw, sym};
|
||||||
use rustc_span::{DUMMY_SP, DesugaringKind, Span};
|
use rustc_span::{DUMMY_SP, DesugaringKind, Span};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
@@ -2071,7 +2071,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
span: Span,
|
span: Span,
|
||||||
rbp: RelaxedBoundPolicy<'_>,
|
rbp: RelaxedBoundPolicy<'_>,
|
||||||
) {
|
) {
|
||||||
let err = |message| feature_err(&self.tcx.sess, sym::more_maybe_bounds, span, message);
|
// Even though feature `more_maybe_bounds` bypasses the given policy and (currently) enables
|
||||||
|
// relaxed bounds in every conceivable position[^1], we don't want to advertise it to the user
|
||||||
|
// (via a feature gate) since it's super internal. Besides this, it'd be quite distracting.
|
||||||
|
//
|
||||||
|
// [^1]: Strictly speaking, this is incorrect (at the very least for `Sized`) because it's
|
||||||
|
// no longer fully consistent with default trait elaboration in HIR ty lowering.
|
||||||
|
|
||||||
match rbp {
|
match rbp {
|
||||||
RelaxedBoundPolicy::Allowed => return,
|
RelaxedBoundPolicy::Allowed => return,
|
||||||
@@ -2093,11 +2098,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
|
|
||||||
match reason {
|
match reason {
|
||||||
RelaxedBoundForbiddenReason::TraitObjectTy => {
|
RelaxedBoundForbiddenReason::TraitObjectTy => {
|
||||||
err("`?Trait` is not permitted in trait object types").emit();
|
self.dcx().span_err(
|
||||||
|
span,
|
||||||
|
"relaxed bounds are not permitted in trait object types",
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RelaxedBoundForbiddenReason::SuperTrait => {
|
RelaxedBoundForbiddenReason::SuperTrait => {
|
||||||
let mut diag = err("`?Trait` is not permitted in supertraits");
|
let mut diag = self.dcx().struct_span_err(
|
||||||
|
span,
|
||||||
|
"relaxed bounds are not permitted in supertrait bounds",
|
||||||
|
);
|
||||||
if let Some(def_id) = trait_ref.trait_def_id()
|
if let Some(def_id) = trait_ref.trait_def_id()
|
||||||
&& self.tcx.is_lang_item(def_id, hir::LangItem::Sized)
|
&& self.tcx.is_lang_item(def_id, hir::LangItem::Sized)
|
||||||
{
|
{
|
||||||
@@ -2111,7 +2122,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err("`?Trait` bounds are only permitted at the point where a type parameter is declared")
|
self.dcx()
|
||||||
|
.struct_span_err(span, "this relaxed bound is not permitted here")
|
||||||
|
.with_note(
|
||||||
|
"in this context, relaxed bounds are only allowed on \
|
||||||
|
type parameters defined by the closest item",
|
||||||
|
)
|
||||||
.emit();
|
.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
fn main() -> dyn Iterator + ?Iterator::advance_by(usize) {
|
fn main() -> dyn Iterator + ?Iterator::advance_by(usize) {
|
||||||
//~^ ERROR expected trait, found associated function `Iterator::advance_by`
|
//~^ ERROR expected trait, found associated function `Iterator::advance_by`
|
||||||
//~| ERROR `?Trait` is not permitted in trait object types
|
//~| ERROR relaxed bounds are not permitted in trait object types
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,16 +4,12 @@ error[E0404]: expected trait, found associated function `Iterator::advance_by`
|
|||||||
LL | fn main() -> dyn Iterator + ?Iterator::advance_by(usize) {
|
LL | fn main() -> dyn Iterator + ?Iterator::advance_by(usize) {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a trait
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a trait
|
||||||
|
|
||||||
error[E0658]: `?Trait` is not permitted in trait object types
|
error: relaxed bounds are not permitted in trait object types
|
||||||
--> $DIR/missing-associated_item_or_field_def_ids.rs:3:29
|
--> $DIR/missing-associated_item_or_field_def_ids.rs:3:29
|
||||||
|
|
|
|
||||||
LL | fn main() -> dyn Iterator + ?Iterator::advance_by(usize) {
|
LL | fn main() -> dyn Iterator + ?Iterator::advance_by(usize) {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
|
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0404, E0658.
|
For more information about this error, try `rustc --explain E0404`.
|
||||||
For more information about an error, try `rustc --explain E0404`.
|
|
||||||
|
|||||||
@@ -7,5 +7,5 @@ trait Tr {
|
|||||||
fn main() {
|
fn main() {
|
||||||
let _: dyn Tr + ?Foo<Assoc = ()>;
|
let _: dyn Tr + ?Foo<Assoc = ()>;
|
||||||
//~^ ERROR: cannot find trait `Foo` in this scope
|
//~^ ERROR: cannot find trait `Foo` in this scope
|
||||||
//~| ERROR: `?Trait` is not permitted in trait object types
|
//~| ERROR: relaxed bounds are not permitted in trait object types
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,16 +4,12 @@ error[E0405]: cannot find trait `Foo` in this scope
|
|||||||
LL | let _: dyn Tr + ?Foo<Assoc = ()>;
|
LL | let _: dyn Tr + ?Foo<Assoc = ()>;
|
||||||
| ^^^ not found in this scope
|
| ^^^ not found in this scope
|
||||||
|
|
||||||
error[E0658]: `?Trait` is not permitted in trait object types
|
error: relaxed bounds are not permitted in trait object types
|
||||||
--> $DIR/avoid-getting-associated-items-of-undefined-trait.rs:8:21
|
--> $DIR/avoid-getting-associated-items-of-undefined-trait.rs:8:21
|
||||||
|
|
|
|
||||||
LL | let _: dyn Tr + ?Foo<Assoc = ()>;
|
LL | let _: dyn Tr + ?Foo<Assoc = ()>;
|
||||||
| ^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
|
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0405, E0658.
|
For more information about this error, try `rustc --explain E0405`.
|
||||||
For more information about an error, try `rustc --explain E0405`.
|
|
||||||
|
|||||||
@@ -2,13 +2,11 @@
|
|||||||
|
|
||||||
trait Trait1 {}
|
trait Trait1 {}
|
||||||
auto trait Trait2 {}
|
auto trait Trait2 {}
|
||||||
trait Trait3: ?Trait1 {}
|
trait Trait3: ?Trait1 {} //~ ERROR relaxed bounds are not permitted in supertrait bounds
|
||||||
//~^ ERROR `?Trait` is not permitted in supertraits
|
trait Trait4 where Self: ?Trait1 {} //~ ERROR this relaxed bound is not permitted here
|
||||||
trait Trait4 where Self: ?Trait1 {}
|
|
||||||
//~^ ERROR ?Trait` bounds are only permitted at the point where a type parameter is declared
|
|
||||||
|
|
||||||
fn foo(_: Box<dyn Trait1 + ?Trait2>) {}
|
fn foo(_: Box<dyn Trait1 + ?Trait2>) {}
|
||||||
//~^ ERROR `?Trait` is not permitted in trait object types
|
//~^ ERROR relaxed bounds are not permitted in trait object types
|
||||||
fn bar<T: ?Trait1 + ?Trait2>(_: T) {}
|
fn bar<T: ?Trait1 + ?Trait2>(_: T) {}
|
||||||
//~^ ERROR type parameter has more than one relaxed default bound, only one is supported
|
//~^ ERROR type parameter has more than one relaxed default bound, only one is supported
|
||||||
//~| ERROR relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
//~| ERROR relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
||||||
|
|||||||
@@ -1,32 +1,25 @@
|
|||||||
error[E0658]: `?Trait` is not permitted in supertraits
|
error: relaxed bounds are not permitted in supertrait bounds
|
||||||
--> $DIR/feature-gate-more-maybe-bounds.rs:5:15
|
--> $DIR/feature-gate-more-maybe-bounds.rs:5:15
|
||||||
|
|
|
|
||||||
LL | trait Trait3: ?Trait1 {}
|
LL | trait Trait3: ?Trait1 {}
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
|
|
|
||||||
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
|
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
|
|
||||||
error[E0658]: `?Trait` bounds are only permitted at the point where a type parameter is declared
|
error: this relaxed bound is not permitted here
|
||||||
--> $DIR/feature-gate-more-maybe-bounds.rs:7:26
|
--> $DIR/feature-gate-more-maybe-bounds.rs:6:26
|
||||||
|
|
|
|
||||||
LL | trait Trait4 where Self: ?Trait1 {}
|
LL | trait Trait4 where Self: ?Trait1 {}
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
|
|
|
|
||||||
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
|
= note: in this context, relaxed bounds are only allowed on type parameters defined by the closest item
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
|
|
||||||
error[E0658]: `?Trait` is not permitted in trait object types
|
error: relaxed bounds are not permitted in trait object types
|
||||||
--> $DIR/feature-gate-more-maybe-bounds.rs:10:28
|
--> $DIR/feature-gate-more-maybe-bounds.rs:8:28
|
||||||
|
|
|
|
||||||
LL | fn foo(_: Box<dyn Trait1 + ?Trait2>) {}
|
LL | fn foo(_: Box<dyn Trait1 + ?Trait2>) {}
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
|
|
|
||||||
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
|
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
|
|
||||||
error[E0203]: type parameter has more than one relaxed default bound, only one is supported
|
error[E0203]: type parameter has more than one relaxed default bound, only one is supported
|
||||||
--> $DIR/feature-gate-more-maybe-bounds.rs:12:11
|
--> $DIR/feature-gate-more-maybe-bounds.rs:10:11
|
||||||
|
|
|
|
||||||
LL | fn bar<T: ?Trait1 + ?Trait2>(_: T) {}
|
LL | fn bar<T: ?Trait1 + ?Trait2>(_: T) {}
|
||||||
| ^^^^^^^ ^^^^^^^
|
| ^^^^^^^ ^^^^^^^
|
||||||
@@ -35,36 +28,35 @@ LL | fn bar<T: ?Trait1 + ?Trait2>(_: T) {}
|
|||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||||
|
|
||||||
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
||||||
--> $DIR/feature-gate-more-maybe-bounds.rs:12:11
|
--> $DIR/feature-gate-more-maybe-bounds.rs:10:11
|
||||||
|
|
|
|
||||||
LL | fn bar<T: ?Trait1 + ?Trait2>(_: T) {}
|
LL | fn bar<T: ?Trait1 + ?Trait2>(_: T) {}
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
|
|
||||||
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
||||||
--> $DIR/feature-gate-more-maybe-bounds.rs:12:21
|
--> $DIR/feature-gate-more-maybe-bounds.rs:10:21
|
||||||
|
|
|
|
||||||
LL | fn bar<T: ?Trait1 + ?Trait2>(_: T) {}
|
LL | fn bar<T: ?Trait1 + ?Trait2>(_: T) {}
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
|
|
||||||
error[E0203]: type parameter has more than one relaxed default bound, only one is supported
|
error[E0203]: type parameter has more than one relaxed default bound, only one is supported
|
||||||
--> $DIR/feature-gate-more-maybe-bounds.rs:19:11
|
--> $DIR/feature-gate-more-maybe-bounds.rs:17:11
|
||||||
|
|
|
|
||||||
LL | fn baz<T: ?Trait + ?Trait>(_ : T) {}
|
LL | fn baz<T: ?Trait + ?Trait>(_ : T) {}
|
||||||
| ^^^^^^ ^^^^^^
|
| ^^^^^^ ^^^^^^
|
||||||
|
|
||||||
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
error: 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
|
--> $DIR/feature-gate-more-maybe-bounds.rs:17:11
|
||||||
|
|
|
|
||||||
LL | fn baz<T: ?Trait + ?Trait>(_ : T) {}
|
LL | fn baz<T: ?Trait + ?Trait>(_ : T) {}
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
||||||
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
error: 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
|
--> $DIR/feature-gate-more-maybe-bounds.rs:17:20
|
||||||
|
|
|
|
||||||
LL | fn baz<T: ?Trait + ?Trait>(_ : T) {}
|
LL | fn baz<T: ?Trait + ?Trait>(_ : T) {}
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
||||||
error: aborting due to 9 previous errors
|
error: aborting due to 9 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0203, E0658.
|
For more information about this error, try `rustc --explain E0203`.
|
||||||
For more information about an error, try `rustc --explain E0203`.
|
|
||||||
|
|||||||
@@ -6,17 +6,17 @@ fn f<T: (Copy) + (?Sized) + (for<'a> Trait<'a>)>() {}
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _: Box<(Obj) + (?Sized) + (for<'a> Trait<'a>)>;
|
let _: Box<(Obj) + (?Sized) + (for<'a> Trait<'a>)>;
|
||||||
//~^ ERROR `?Trait` is not permitted in trait object types
|
//~^ ERROR relaxed bounds are not permitted in trait object types
|
||||||
//~| ERROR only auto traits can be used as additional traits
|
//~| ERROR only auto traits can be used as additional traits
|
||||||
//~| WARN trait objects without an explicit `dyn` are deprecated
|
//~| WARN trait objects without an explicit `dyn` are deprecated
|
||||||
//~| WARN this is accepted in the current edition
|
//~| WARN this is accepted in the current edition
|
||||||
let _: Box<?Sized + (for<'a> Trait<'a>) + (Obj)>;
|
let _: Box<?Sized + (for<'a> Trait<'a>) + (Obj)>;
|
||||||
//~^ ERROR `?Trait` is not permitted in trait object types
|
//~^ ERROR relaxed bounds are not permitted in trait object types
|
||||||
//~| ERROR only auto traits can be used as additional traits
|
//~| ERROR only auto traits can be used as additional traits
|
||||||
//~| WARN trait objects without an explicit `dyn` are deprecated
|
//~| WARN trait objects without an explicit `dyn` are deprecated
|
||||||
//~| WARN this is accepted in the current edition
|
//~| WARN this is accepted in the current edition
|
||||||
let _: Box<for<'a> Trait<'a> + (Obj) + (?Sized)>;
|
let _: Box<for<'a> Trait<'a> + (Obj) + (?Sized)>;
|
||||||
//~^ ERROR `?Trait` is not permitted in trait object types
|
//~^ ERROR relaxed bounds are not permitted in trait object types
|
||||||
//~| ERROR only auto traits can be used as additional traits
|
//~| ERROR only auto traits can be used as additional traits
|
||||||
//~| WARN trait objects without an explicit `dyn` are deprecated
|
//~| WARN trait objects without an explicit `dyn` are deprecated
|
||||||
//~| WARN this is accepted in the current edition
|
//~| WARN this is accepted in the current edition
|
||||||
|
|||||||
@@ -1,29 +1,20 @@
|
|||||||
error[E0658]: `?Trait` is not permitted in trait object types
|
error: relaxed bounds are not permitted in trait object types
|
||||||
--> $DIR/trait-object-trait-parens.rs:8:24
|
--> $DIR/trait-object-trait-parens.rs:8:24
|
||||||
|
|
|
|
||||||
LL | let _: Box<(Obj) + (?Sized) + (for<'a> Trait<'a>)>;
|
LL | let _: Box<(Obj) + (?Sized) + (for<'a> Trait<'a>)>;
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^
|
||||||
|
|
|
||||||
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
|
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
|
|
||||||
error[E0658]: `?Trait` is not permitted in trait object types
|
error: relaxed bounds are not permitted in trait object types
|
||||||
--> $DIR/trait-object-trait-parens.rs:13:16
|
--> $DIR/trait-object-trait-parens.rs:13:16
|
||||||
|
|
|
|
||||||
LL | let _: Box<?Sized + (for<'a> Trait<'a>) + (Obj)>;
|
LL | let _: Box<?Sized + (for<'a> Trait<'a>) + (Obj)>;
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
|
||||||
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
|
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
|
|
||||||
error[E0658]: `?Trait` is not permitted in trait object types
|
error: relaxed bounds are not permitted in trait object types
|
||||||
--> $DIR/trait-object-trait-parens.rs:18:44
|
--> $DIR/trait-object-trait-parens.rs:18:44
|
||||||
|
|
|
|
||||||
LL | let _: Box<for<'a> Trait<'a> + (Obj) + (?Sized)>;
|
LL | let _: Box<for<'a> Trait<'a> + (Obj) + (?Sized)>;
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^
|
||||||
|
|
|
||||||
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
|
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
|
|
||||||
warning: trait objects without an explicit `dyn` are deprecated
|
warning: trait objects without an explicit `dyn` are deprecated
|
||||||
--> $DIR/trait-object-trait-parens.rs:8:16
|
--> $DIR/trait-object-trait-parens.rs:8:16
|
||||||
@@ -100,5 +91,4 @@ LL | let _: Box<for<'a> Trait<'a> + (Obj) + (?Sized)>;
|
|||||||
|
|
||||||
error: aborting due to 6 previous errors; 3 warnings emitted
|
error: aborting due to 6 previous errors; 3 warnings emitted
|
||||||
|
|
||||||
Some errors have detailed explanations: E0225, E0658.
|
For more information about this error, try `rustc --explain E0225`.
|
||||||
For more information about an error, try `rustc --explain E0225`.
|
|
||||||
|
|||||||
@@ -6,18 +6,18 @@ use std::marker::{MetaSized, PointeeSized};
|
|||||||
trait Sized_: Sized { }
|
trait Sized_: Sized { }
|
||||||
|
|
||||||
trait NegSized: ?Sized { }
|
trait NegSized: ?Sized { }
|
||||||
//~^ ERROR `?Trait` is not permitted in supertraits
|
//~^ ERROR relaxed bounds are not permitted in supertrait bounds
|
||||||
|
|
||||||
trait MetaSized_: MetaSized { }
|
trait MetaSized_: MetaSized { }
|
||||||
|
|
||||||
trait NegMetaSized: ?MetaSized { }
|
trait NegMetaSized: ?MetaSized { }
|
||||||
//~^ ERROR `?Trait` is not permitted in supertraits
|
//~^ ERROR relaxed bounds are not permitted in supertrait bounds
|
||||||
|
|
||||||
|
|
||||||
trait PointeeSized_: PointeeSized { }
|
trait PointeeSized_: PointeeSized { }
|
||||||
|
|
||||||
trait NegPointeeSized: ?PointeeSized { }
|
trait NegPointeeSized: ?PointeeSized { }
|
||||||
//~^ ERROR `?Trait` is not permitted in supertraits
|
//~^ ERROR relaxed bounds are not permitted in supertrait bounds
|
||||||
|
|
||||||
trait Bare {}
|
trait Bare {}
|
||||||
|
|
||||||
|
|||||||
@@ -1,30 +1,22 @@
|
|||||||
error[E0658]: `?Trait` is not permitted in supertraits
|
error: relaxed bounds are not permitted in supertrait bounds
|
||||||
--> $DIR/default-supertrait.rs:8:17
|
--> $DIR/default-supertrait.rs:8:17
|
||||||
|
|
|
|
||||||
LL | trait NegSized: ?Sized { }
|
LL | trait NegSized: ?Sized { }
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
|
|
||||||
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
|
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
= note: traits are `?Sized` by default
|
= note: traits are `?Sized` by default
|
||||||
|
|
||||||
error[E0658]: `?Trait` is not permitted in supertraits
|
error: relaxed bounds are not permitted in supertrait bounds
|
||||||
--> $DIR/default-supertrait.rs:13:21
|
--> $DIR/default-supertrait.rs:13:21
|
||||||
|
|
|
|
||||||
LL | trait NegMetaSized: ?MetaSized { }
|
LL | trait NegMetaSized: ?MetaSized { }
|
||||||
| ^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
|
|
|
||||||
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
|
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
|
|
||||||
error[E0658]: `?Trait` is not permitted in supertraits
|
error: relaxed bounds are not permitted in supertrait bounds
|
||||||
--> $DIR/default-supertrait.rs:19:24
|
--> $DIR/default-supertrait.rs:19:24
|
||||||
|
|
|
|
||||||
LL | trait NegPointeeSized: ?PointeeSized { }
|
LL | trait NegPointeeSized: ?PointeeSized { }
|
||||||
| ^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
|
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
|
|
||||||
error[E0277]: the size for values of type `T` cannot be known
|
error[E0277]: the size for values of type `T` cannot be known
|
||||||
--> $DIR/default-supertrait.rs:52:38
|
--> $DIR/default-supertrait.rs:52:38
|
||||||
@@ -119,5 +111,4 @@ LL | fn with_bare_trait<T: PointeeSized + Bare + std::marker::MetaSized>() {
|
|||||||
|
|
||||||
error: aborting due to 9 previous errors
|
error: aborting due to 9 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0277, E0658.
|
For more information about this error, try `rustc --explain E0277`.
|
||||||
For more information about an error, try `rustc --explain E0277`.
|
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
//! Test that ?Trait bounds are forbidden in supertraits and trait object types.
|
|
||||||
//!
|
|
||||||
//! While `?Sized` and other maybe bounds are allowed in type parameter bounds and where clauses,
|
|
||||||
//! they are explicitly forbidden in certain syntactic positions:
|
|
||||||
//! - As supertraits in trait definitions
|
|
||||||
//! - In trait object type expressions
|
|
||||||
//!
|
|
||||||
//! See https://github.com/rust-lang/rust/issues/20503
|
|
||||||
|
|
||||||
trait Tr: ?Sized {}
|
|
||||||
//~^ ERROR `?Trait` is not permitted in supertraits
|
|
||||||
|
|
||||||
type A1 = dyn Tr + (?Sized);
|
|
||||||
//~^ ERROR `?Trait` is not permitted in trait object types
|
|
||||||
type A2 = dyn for<'a> Tr + (?Sized);
|
|
||||||
//~^ ERROR `?Trait` is not permitted in trait object types
|
|
||||||
|
|
||||||
fn main() {}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
error[E0658]: `?Trait` is not permitted in supertraits
|
|
||||||
--> $DIR/maybe-trait-bounds-forbidden-locations.rs:10:11
|
|
||||||
|
|
|
||||||
LL | trait Tr: ?Sized {}
|
|
||||||
| ^^^^^^
|
|
||||||
|
|
|
||||||
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
|
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
= note: traits are `?Sized` by default
|
|
||||||
|
|
||||||
error[E0658]: `?Trait` is not permitted in trait object types
|
|
||||||
--> $DIR/maybe-trait-bounds-forbidden-locations.rs:13:20
|
|
||||||
|
|
|
||||||
LL | type A1 = dyn Tr + (?Sized);
|
|
||||||
| ^^^^^^^^
|
|
||||||
|
|
|
||||||
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
|
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
|
|
||||||
error[E0658]: `?Trait` is not permitted in trait object types
|
|
||||||
--> $DIR/maybe-trait-bounds-forbidden-locations.rs:15:28
|
|
||||||
|
|
|
||||||
LL | type A2 = dyn for<'a> Tr + (?Sized);
|
|
||||||
| ^^^^^^^^
|
|
||||||
|
|
|
||||||
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
|
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0658`.
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
// Test that `dyn ... + ?Sized + ...` is okay (though `?Sized` has no effect in trait objects).
|
|
||||||
|
|
||||||
trait Foo {}
|
|
||||||
|
|
||||||
type _0 = dyn ?Sized + Foo;
|
|
||||||
//~^ ERROR `?Trait` is not permitted in trait object types
|
|
||||||
|
|
||||||
type _1 = dyn Foo + ?Sized;
|
|
||||||
//~^ ERROR `?Trait` is not permitted in trait object types
|
|
||||||
|
|
||||||
type _2 = dyn Foo + ?Sized + ?Sized;
|
|
||||||
//~^ ERROR `?Trait` is not permitted in trait object types
|
|
||||||
//~| ERROR `?Trait` is not permitted in trait object types
|
|
||||||
|
|
||||||
type _3 = dyn ?Sized + Foo;
|
|
||||||
//~^ ERROR `?Trait` is not permitted in trait object types
|
|
||||||
|
|
||||||
fn main() {}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
error[E0658]: `?Trait` is not permitted in trait object types
|
|
||||||
--> $DIR/maybe-bound.rs:5:15
|
|
||||||
|
|
|
||||||
LL | type _0 = dyn ?Sized + Foo;
|
|
||||||
| ^^^^^^
|
|
||||||
|
|
|
||||||
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
|
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
|
|
||||||
error[E0658]: `?Trait` is not permitted in trait object types
|
|
||||||
--> $DIR/maybe-bound.rs:8:21
|
|
||||||
|
|
|
||||||
LL | type _1 = dyn Foo + ?Sized;
|
|
||||||
| ^^^^^^
|
|
||||||
|
|
|
||||||
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
|
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
|
|
||||||
error[E0658]: `?Trait` is not permitted in trait object types
|
|
||||||
--> $DIR/maybe-bound.rs:11:21
|
|
||||||
|
|
|
||||||
LL | type _2 = dyn Foo + ?Sized + ?Sized;
|
|
||||||
| ^^^^^^
|
|
||||||
|
|
|
||||||
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
|
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
|
|
||||||
error[E0658]: `?Trait` is not permitted in trait object types
|
|
||||||
--> $DIR/maybe-bound.rs:11:30
|
|
||||||
|
|
|
||||||
LL | type _2 = dyn Foo + ?Sized + ?Sized;
|
|
||||||
| ^^^^^^
|
|
||||||
|
|
|
||||||
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
|
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
|
|
||||||
error[E0658]: `?Trait` is not permitted in trait object types
|
|
||||||
--> $DIR/maybe-bound.rs:15:15
|
|
||||||
|
|
|
||||||
LL | type _3 = dyn ?Sized + Foo;
|
|
||||||
| ^^^^^^
|
|
||||||
|
|
|
||||||
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
|
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
|
|
||||||
error: aborting due to 5 previous errors
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0658`.
|
|
||||||
@@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
type _0 = dyn ?Sized;
|
type _0 = dyn ?Sized;
|
||||||
//~^ ERROR at least one trait is required for an object type [E0224]
|
//~^ ERROR at least one trait is required for an object type [E0224]
|
||||||
//~| ERROR ?Trait` is not permitted in trait object types
|
//~| ERROR relaxed bounds are not permitted in trait object types
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
error[E0658]: `?Trait` is not permitted in trait object types
|
error: relaxed bounds are not permitted in trait object types
|
||||||
--> $DIR/only-maybe-bound.rs:3:15
|
--> $DIR/only-maybe-bound.rs:3:15
|
||||||
|
|
|
|
||||||
LL | type _0 = dyn ?Sized;
|
LL | type _0 = dyn ?Sized;
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
|
||||||
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
|
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
|
|
||||||
error[E0224]: at least one trait is required for an object type
|
error[E0224]: at least one trait is required for an object type
|
||||||
--> $DIR/only-maybe-bound.rs:3:11
|
--> $DIR/only-maybe-bound.rs:3:11
|
||||||
@@ -15,5 +12,4 @@ LL | type _0 = dyn ?Sized;
|
|||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0224, E0658.
|
For more information about this error, try `rustc --explain E0224`.
|
||||||
For more information about an error, try `rustc --explain E0224`.
|
|
||||||
|
|||||||
@@ -1,19 +1,18 @@
|
|||||||
// Test that relaxed bounds can only be placed on type parameters defined by the closest item
|
// Test various places where relaxed bounds are not permitted.
|
||||||
// (ignoring relaxed bounds inside `impl Trait` and in associated type defs here).
|
//
|
||||||
|
// Relaxed bounds are only permitted inside impl-Trait, assoc ty item bounds and
|
||||||
|
// on type params defined by the closest item.
|
||||||
|
|
||||||
struct S1<T>(T) where (T): ?Sized;
|
struct S1<T>(T) where (T): ?Sized; //~ ERROR this relaxed bound is not permitted here
|
||||||
//~^ ERROR `?Trait` bounds are only permitted at the point where a type parameter is declared
|
|
||||||
|
|
||||||
struct S2<T>(T) where u8: ?Sized;
|
struct S2<T>(T) where u8: ?Sized; //~ ERROR this relaxed bound is not permitted here
|
||||||
//~^ ERROR `?Trait` bounds are only permitted at the point where a type parameter is declared
|
|
||||||
|
|
||||||
struct S3<T>(T) where &'static T: ?Sized;
|
struct S3<T>(T) where &'static T: ?Sized; //~ ERROR this relaxed bound is not permitted here
|
||||||
//~^ ERROR `?Trait` bounds are only permitted at the point where a type parameter is declared
|
|
||||||
|
|
||||||
trait Trait<'a> {}
|
trait Trait<'a> {}
|
||||||
|
|
||||||
struct S4<T>(T) where for<'a> T: ?Trait<'a>;
|
struct S4<T>(T) where for<'a> T: ?Trait<'a>;
|
||||||
//~^ ERROR `?Trait` bounds are only permitted at the point where a type parameter is declared
|
//~^ ERROR this relaxed bound is not permitted here
|
||||||
//~| ERROR relaxing a default bound only does something for `?Sized`
|
//~| ERROR relaxing a default bound only does something for `?Sized`
|
||||||
|
|
||||||
struct S5<T>(*const T) where T: ?Trait<'static> + ?Sized;
|
struct S5<T>(*const T) where T: ?Trait<'static> + ?Sized;
|
||||||
@@ -21,11 +20,17 @@ struct S5<T>(*const T) where T: ?Trait<'static> + ?Sized;
|
|||||||
//~| ERROR relaxing a default bound only does something for `?Sized`
|
//~| ERROR relaxing a default bound only does something for `?Sized`
|
||||||
|
|
||||||
impl<T> S1<T> {
|
impl<T> S1<T> {
|
||||||
fn f() where T: ?Sized {}
|
fn f() where T: ?Sized {} //~ ERROR this relaxed bound is not permitted here
|
||||||
//~^ ERROR `?Trait` bounds are only permitted at the point where a type parameter is declared
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
trait Tr: ?Sized {} //~ ERROR relaxed bounds are not permitted in supertrait bounds
|
||||||
let u = vec![1, 2, 3];
|
|
||||||
let _s: S5<[u8]> = S5(&u[..]); // OK
|
// Test that relaxed `Sized` bounds are rejected in trait object types:
|
||||||
}
|
|
||||||
|
type O1 = dyn Tr + ?Sized; //~ ERROR relaxed bounds are not permitted in trait object types
|
||||||
|
type O2 = dyn ?Sized + ?Sized + Tr;
|
||||||
|
//~^ ERROR relaxed bounds are not permitted in trait object types
|
||||||
|
//~| ERROR relaxed bounds are not permitted in trait object types
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
|
|
||||||
|
|||||||
@@ -1,56 +1,77 @@
|
|||||||
error[E0658]: `?Trait` bounds are only permitted at the point where a type parameter is declared
|
error: this relaxed bound is not permitted here
|
||||||
--> $DIR/relaxed-bounds-invalid-places.rs:4:28
|
--> $DIR/relaxed-bounds-invalid-places.rs:6:28
|
||||||
|
|
|
|
||||||
LL | struct S1<T>(T) where (T): ?Sized;
|
LL | struct S1<T>(T) where (T): ?Sized;
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
|
|
||||||
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
|
= note: in this context, relaxed bounds are only allowed on type parameters defined by the closest item
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
|
|
||||||
error[E0658]: `?Trait` bounds are only permitted at the point where a type parameter is declared
|
error: this relaxed bound is not permitted here
|
||||||
--> $DIR/relaxed-bounds-invalid-places.rs:7:27
|
--> $DIR/relaxed-bounds-invalid-places.rs:8:27
|
||||||
|
|
|
|
||||||
LL | struct S2<T>(T) where u8: ?Sized;
|
LL | struct S2<T>(T) where u8: ?Sized;
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
|
|
||||||
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
|
= note: in this context, relaxed bounds are only allowed on type parameters defined by the closest item
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
|
|
||||||
error[E0658]: `?Trait` bounds are only permitted at the point where a type parameter is declared
|
error: this relaxed bound is not permitted here
|
||||||
--> $DIR/relaxed-bounds-invalid-places.rs:10:35
|
--> $DIR/relaxed-bounds-invalid-places.rs:10:35
|
||||||
|
|
|
|
||||||
LL | struct S3<T>(T) where &'static T: ?Sized;
|
LL | struct S3<T>(T) where &'static T: ?Sized;
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
|
|
||||||
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
|
= note: in this context, relaxed bounds are only allowed on type parameters defined by the closest item
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
|
|
||||||
error[E0658]: `?Trait` bounds are only permitted at the point where a type parameter is declared
|
error: this relaxed bound is not permitted here
|
||||||
--> $DIR/relaxed-bounds-invalid-places.rs:15:34
|
--> $DIR/relaxed-bounds-invalid-places.rs:14:34
|
||||||
|
|
|
|
||||||
LL | struct S4<T>(T) where for<'a> T: ?Trait<'a>;
|
LL | struct S4<T>(T) where for<'a> T: ?Trait<'a>;
|
||||||
| ^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
|
= note: in this context, relaxed bounds are only allowed on type parameters defined by the closest item
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
|
|
||||||
error[E0658]: `?Trait` bounds are only permitted at the point where a type parameter is declared
|
error: this relaxed bound is not permitted here
|
||||||
--> $DIR/relaxed-bounds-invalid-places.rs:24:21
|
--> $DIR/relaxed-bounds-invalid-places.rs:23:21
|
||||||
|
|
|
|
||||||
LL | fn f() where T: ?Sized {}
|
LL | fn f() where T: ?Sized {}
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
|
|
||||||
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
|
= note: in this context, relaxed bounds are only allowed on type parameters defined by the closest item
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
|
error: relaxed bounds are not permitted in supertrait bounds
|
||||||
|
--> $DIR/relaxed-bounds-invalid-places.rs:26:11
|
||||||
|
|
|
||||||
|
LL | trait Tr: ?Sized {}
|
||||||
|
| ^^^^^^
|
||||||
|
|
|
||||||
|
= note: traits are `?Sized` by default
|
||||||
|
|
||||||
|
error: relaxed bounds are not permitted in trait object types
|
||||||
|
--> $DIR/relaxed-bounds-invalid-places.rs:30:20
|
||||||
|
|
|
||||||
|
LL | type O1 = dyn Tr + ?Sized;
|
||||||
|
| ^^^^^^
|
||||||
|
|
||||||
|
error: relaxed bounds are not permitted in trait object types
|
||||||
|
--> $DIR/relaxed-bounds-invalid-places.rs:31:15
|
||||||
|
|
|
||||||
|
LL | type O2 = dyn ?Sized + ?Sized + Tr;
|
||||||
|
| ^^^^^^
|
||||||
|
|
||||||
|
error: relaxed bounds are not permitted in trait object types
|
||||||
|
--> $DIR/relaxed-bounds-invalid-places.rs:31:24
|
||||||
|
|
|
||||||
|
LL | type O2 = dyn ?Sized + ?Sized + Tr;
|
||||||
|
| ^^^^^^
|
||||||
|
|
||||||
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
||||||
--> $DIR/relaxed-bounds-invalid-places.rs:15:34
|
--> $DIR/relaxed-bounds-invalid-places.rs:14:34
|
||||||
|
|
|
|
||||||
LL | struct S4<T>(T) where for<'a> T: ?Trait<'a>;
|
LL | struct S4<T>(T) where for<'a> T: ?Trait<'a>;
|
||||||
| ^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
|
|
||||||
error[E0203]: type parameter has more than one relaxed default bound, only one is supported
|
error[E0203]: type parameter has more than one relaxed default bound, only one is supported
|
||||||
--> $DIR/relaxed-bounds-invalid-places.rs:19:33
|
--> $DIR/relaxed-bounds-invalid-places.rs:18:33
|
||||||
|
|
|
|
||||||
LL | struct S5<T>(*const T) where T: ?Trait<'static> + ?Sized;
|
LL | struct S5<T>(*const T) where T: ?Trait<'static> + ?Sized;
|
||||||
| ^^^^^^^^^^^^^^^ ^^^^^^
|
| ^^^^^^^^^^^^^^^ ^^^^^^
|
||||||
@@ -59,12 +80,11 @@ LL | struct S5<T>(*const T) where T: ?Trait<'static> + ?Sized;
|
|||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||||
|
|
||||||
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
||||||
--> $DIR/relaxed-bounds-invalid-places.rs:19:33
|
--> $DIR/relaxed-bounds-invalid-places.rs:18:33
|
||||||
|
|
|
|
||||||
LL | struct S5<T>(*const T) where T: ?Trait<'static> + ?Sized;
|
LL | struct S5<T>(*const T) where T: ?Trait<'static> + ?Sized;
|
||||||
| ^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to 8 previous errors
|
error: aborting due to 12 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0203, E0658.
|
For more information about this error, try `rustc --explain E0203`.
|
||||||
For more information about an error, try `rustc --explain E0203`.
|
|
||||||
|
|||||||
Reference in New Issue
Block a user