Consider polarity in sizedness fast path
This commit is contained in:
@@ -368,16 +368,17 @@ pub fn sizedness_fast_path<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tc
|
|||||||
// Proving `Sized`/`MetaSized`, very often on "obviously sized" types like
|
// Proving `Sized`/`MetaSized`, very often on "obviously sized" types like
|
||||||
// `&T`, accounts for about 60% percentage of the predicates we have to prove. No need to
|
// `&T`, accounts for about 60% percentage of the predicates we have to prove. No need to
|
||||||
// canonicalize and all that for such cases.
|
// canonicalize and all that for such cases.
|
||||||
if let ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_ref)) =
|
if let ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_pred)) =
|
||||||
predicate.kind().skip_binder()
|
predicate.kind().skip_binder()
|
||||||
|
&& trait_pred.polarity == ty::PredicatePolarity::Positive
|
||||||
{
|
{
|
||||||
let sizedness = match tcx.as_lang_item(trait_ref.def_id()) {
|
let sizedness = match tcx.as_lang_item(trait_pred.def_id()) {
|
||||||
Some(LangItem::Sized) => SizedTraitKind::Sized,
|
Some(LangItem::Sized) => SizedTraitKind::Sized,
|
||||||
Some(LangItem::MetaSized) => SizedTraitKind::MetaSized,
|
Some(LangItem::MetaSized) => SizedTraitKind::MetaSized,
|
||||||
_ => return false,
|
_ => return false,
|
||||||
};
|
};
|
||||||
|
|
||||||
if trait_ref.self_ty().has_trivial_sizedness(tcx, sizedness) {
|
if trait_pred.self_ty().has_trivial_sizedness(tcx, sizedness) {
|
||||||
debug!("fast path -- trivial sizedness");
|
debug!("fast path -- trivial sizedness");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
8
tests/ui/traits/negative-bounds/negative-sized.rs
Normal file
8
tests/ui/traits/negative-bounds/negative-sized.rs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#![feature(negative_bounds)]
|
||||||
|
|
||||||
|
fn foo<T: !Sized>() {}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
foo::<()>();
|
||||||
|
//~^ ERROR the trait bound `(): !Sized` is not satisfied
|
||||||
|
}
|
||||||
15
tests/ui/traits/negative-bounds/negative-sized.stderr
Normal file
15
tests/ui/traits/negative-bounds/negative-sized.stderr
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
error[E0277]: the trait bound `(): !Sized` is not satisfied
|
||||||
|
--> $DIR/negative-sized.rs:6:11
|
||||||
|
|
|
||||||
|
LL | foo::<()>();
|
||||||
|
| ^^ the trait bound `(): !Sized` is not satisfied
|
||||||
|
|
|
||||||
|
note: required by a bound in `foo`
|
||||||
|
--> $DIR/negative-sized.rs:3:11
|
||||||
|
|
|
||||||
|
LL | fn foo<T: !Sized>() {}
|
||||||
|
| ^^^^^^ required by this bound in `foo`
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0277`.
|
||||||
Reference in New Issue
Block a user