Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rust-lang/rust
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 743d2e54f7c04063c749480602da2586e6da6e59
Choose a base ref
..
head repository: rust-lang/rust
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8a57aea25c0f13f17af646f9889e5afe1ad4852f
Choose a head ref
6 changes: 4 additions & 2 deletions compiler/rustc_error_codes/src/error_codes/E0203.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#### Note: this error code is no longer emitted by the compiler.

Having multiple relaxed default bounds is unsupported.

Erroneous code example:
Previously erroneous code example:

```compile_fail,E0203
```compile_fail
struct Bad<T: ?Sized + ?Send>{
inner: T
}
1 change: 1 addition & 0 deletions compiler/rustc_error_codes/src/lib.rs
Original file line number Diff line number Diff line change
@@ -575,6 +575,7 @@ E0797: 0797,
// E0190, // deprecated: can only cast a &-pointer to an &-object
// E0194, // merged into E0403
// E0196, // cannot determine a type for this closure
// E0203 // replaced with a `allow_maybe_polarity` feature gate
// E0209, // builtin traits can only be implemented on structs or enums
// E0213, // associated types are not accepted in this context
// E0215, // angle-bracket notation is not stable with `Fn`
13 changes: 9 additions & 4 deletions compiler/rustc_hir_analysis/src/astconv/bounds.rs
Original file line number Diff line number Diff line change
@@ -4,8 +4,9 @@ use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_middle::ty::{self as ty, Ty};
use rustc_session::parse::feature_err;
use rustc_span::symbol::Ident;
use rustc_span::{ErrorGuaranteed, Span};
use rustc_span::{sym, ErrorGuaranteed, Span};
use rustc_trait_selection::traits;
use smallvec::SmallVec;

@@ -67,9 +68,13 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
}

if unbounds.len() > 1 && !tcx.features().allow_maybe_polarity {
tcx.dcx().emit_err(errors::MultipleRelaxedDefaultBounds {
spans: unbounds.iter().map(|ptr| ptr.span).collect(),
});
feature_err(
tcx.sess,
sym::allow_maybe_polarity,
unbounds.iter().map(|ptr| ptr.span).collect::<Vec<Span>>(),
"type parameter has more than one relaxed default bound, only one is supported",
)
.emit();
}

let mut seen_sized_unbound = false;
2 changes: 1 addition & 1 deletion tests/ui/traits/maybe-polarity-pass.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//@ check-pass

#![feature(allow_maybe_polarity)]
#![feature(auto_traits)]
#![feature(negative_impls)]
#![feature(allow_maybe_polarity)]

trait Trait1 {}
auto trait Trait2 {}
7 changes: 5 additions & 2 deletions tests/ui/unsized/maybe-bounds-where.stderr
Original file line number Diff line number Diff line change
@@ -34,11 +34,14 @@ warning: relaxing a default bound only does something for `?Sized`; all other tr
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[E0658]: type parameter has more than one relaxed default bound, only one is supported
--> $DIR/maybe-bounds-where.rs:16:33
|
LL | struct S5<T>(*const T) where T: ?Trait<'static> + ?Sized;
| ^^^^^^^^^^^^^^^ ^^^^^^
|
= help: add `#![feature(allow_maybe_polarity)]` 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: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
--> $DIR/maybe-bounds-where.rs:16:33
@@ -48,4 +51,4 @@ LL | struct S5<T>(*const T) where T: ?Trait<'static> + ?Sized;

error: aborting due to 6 previous errors; 2 warnings emitted

For more information about this error, try `rustc --explain E0203`.
For more information about this error, try `rustc --explain E0658`.