mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Treat str
as containing [u8]
for auto trait purposes
This commit is contained in:
parent
31448badfd
commit
3560e65c44
@ -20,12 +20,14 @@ pub(super) fn instantiate_constituent_tys_for_auto_trait<'tcx>(
|
||||
| ty::Float(_)
|
||||
| ty::FnDef(..)
|
||||
| ty::FnPtr(_)
|
||||
| ty::Str
|
||||
| ty::Error(_)
|
||||
| ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
|
||||
| ty::Never
|
||||
| ty::Char => Ok(vec![]),
|
||||
|
||||
// Treat this like `struct str([u8]);`
|
||||
ty::Str => Ok(vec![tcx.mk_slice(tcx.types.u8)]),
|
||||
|
||||
ty::Dynamic(..)
|
||||
| ty::Param(..)
|
||||
| ty::Foreign(..)
|
||||
|
@ -2300,12 +2300,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
| ty::Float(_)
|
||||
| ty::FnDef(..)
|
||||
| ty::FnPtr(_)
|
||||
| ty::Str
|
||||
| ty::Error(_)
|
||||
| ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
|
||||
| ty::Never
|
||||
| ty::Char => ty::Binder::dummy(Vec::new()),
|
||||
|
||||
// Treat this like `struct str([u8]);`
|
||||
ty::Str => ty::Binder::dummy(vec![self.tcx().mk_slice(self.tcx().types.u8)]),
|
||||
|
||||
ty::Placeholder(..)
|
||||
| ty::Dynamic(..)
|
||||
| ty::Param(..)
|
||||
|
13
tests/ui/auto-traits/str-contains-slice-conceptually.rs
Normal file
13
tests/ui/auto-traits/str-contains-slice-conceptually.rs
Normal file
@ -0,0 +1,13 @@
|
||||
#![feature(negative_impls)]
|
||||
#![feature(auto_traits)]
|
||||
|
||||
auto trait AutoTrait {}
|
||||
|
||||
impl<T> !AutoTrait for [T] {}
|
||||
|
||||
fn needs_auto_trait<T: AutoTrait + ?Sized>() {}
|
||||
|
||||
fn main() {
|
||||
needs_auto_trait::<str>();
|
||||
//~^ ERROR the trait bound `[u8]: AutoTrait` is not satisfied in `str`
|
||||
}
|
16
tests/ui/auto-traits/str-contains-slice-conceptually.stderr
Normal file
16
tests/ui/auto-traits/str-contains-slice-conceptually.stderr
Normal file
@ -0,0 +1,16 @@
|
||||
error[E0277]: the trait bound `[u8]: AutoTrait` is not satisfied in `str`
|
||||
--> $DIR/str-contains-slice-conceptually.rs:11:22
|
||||
|
|
||||
LL | needs_auto_trait::<str>();
|
||||
| ^^^ within `str`, the trait `AutoTrait` is not implemented for `[u8]`
|
||||
|
|
||||
= note: required because it appears within the type `str`
|
||||
note: required by a bound in `needs_auto_trait`
|
||||
--> $DIR/str-contains-slice-conceptually.rs:8:24
|
||||
|
|
||||
LL | fn needs_auto_trait<T: AutoTrait + ?Sized>() {}
|
||||
| ^^^^^^^^^ required by this bound in `needs_auto_trait`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
Loading…
Reference in New Issue
Block a user