Skip to content

Commit 3b96f07

Browse files
authored
Unrolled build for #143307
Rollup merge of #143307 - compiler-errors:fast-path-nitpicks, r=lcnr Fast path nitpicks Miscellaneous commits that I didn't really want to fold into anything else. Fixes one theoretical bug with the fast path not considering polarity for `T: !Sized` bounds.
2 parents 837c5dd + 91c53c9 commit 3b96f07

File tree

5 files changed

+31
-24
lines changed

5 files changed

+31
-24
lines changed

compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,9 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> {
2121

2222
if let ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(term)) =
2323
key.value.predicate.kind().skip_binder()
24+
&& term.is_trivially_wf(tcx)
2425
{
25-
match term.as_type()?.kind() {
26-
ty::Param(_)
27-
| ty::Bool
28-
| ty::Char
29-
| ty::Int(_)
30-
| ty::Float(_)
31-
| ty::Str
32-
| ty::Uint(_) => {
33-
return Some(());
34-
}
35-
_ => {}
36-
}
26+
return Some(());
3727
}
3828

3929
None

compiler/rustc_trait_selection/src/traits/util.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,16 +368,17 @@ pub fn sizedness_fast_path<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tc
368368
// Proving `Sized`/`MetaSized`, very often on "obviously sized" types like
369369
// `&T`, accounts for about 60% percentage of the predicates we have to prove. No need to
370370
// canonicalize and all that for such cases.
371-
if let ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_ref)) =
371+
if let ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_pred)) =
372372
predicate.kind().skip_binder()
373+
&& trait_pred.polarity == ty::PredicatePolarity::Positive
373374
{
374-
let sizedness = match tcx.as_lang_item(trait_ref.def_id()) {
375+
let sizedness = match tcx.as_lang_item(trait_pred.def_id()) {
375376
Some(LangItem::Sized) => SizedTraitKind::Sized,
376377
Some(LangItem::MetaSized) => SizedTraitKind::MetaSized,
377378
_ => return false,
378379
};
379380

380-
if trait_ref.self_ty().has_trivial_sizedness(tcx, sizedness) {
381+
if trait_pred.self_ty().has_trivial_sizedness(tcx, sizedness) {
381382
debug!("fast path -- trivial sizedness");
382383
return true;
383384
}

compiler/rustc_traits/src/codegen.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
use rustc_infer::infer::TyCtxtInferExt;
77
use rustc_middle::bug;
88
use rustc_middle::traits::CodegenObligationError;
9-
use rustc_middle::ty::{self, PseudoCanonicalInput, TyCtxt, TypeVisitableExt, Upcast};
9+
use rustc_middle::ty::{self, PseudoCanonicalInput, TyCtxt, TypeVisitableExt};
1010
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
1111
use rustc_trait_selection::traits::{
1212
ImplSource, Obligation, ObligationCause, ObligationCtxt, ScrubbedTraitError, SelectionContext,
13-
SelectionError, sizedness_fast_path,
13+
SelectionError,
1414
};
1515
use tracing::debug;
1616

@@ -34,13 +34,6 @@ pub(crate) fn codegen_select_candidate<'tcx>(
3434
let (infcx, param_env) = tcx.infer_ctxt().ignoring_regions().build_with_typing_env(typing_env);
3535
let mut selcx = SelectionContext::new(&infcx);
3636

37-
if sizedness_fast_path(tcx, trait_ref.upcast(tcx)) {
38-
return Ok(&*tcx.arena.alloc(ImplSource::Builtin(
39-
ty::solve::BuiltinImplSource::Trivial,
40-
Default::default(),
41-
)));
42-
}
43-
4437
let obligation_cause = ObligationCause::dummy();
4538
let obligation = Obligation::new(tcx, obligation_cause, param_env, trait_ref);
4639

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![feature(negative_bounds)]
2+
3+
fn foo<T: !Sized>() {}
4+
5+
fn main() {
6+
foo::<()>();
7+
//~^ ERROR the trait bound `(): !Sized` is not satisfied
8+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0277]: the trait bound `(): !Sized` is not satisfied
2+
--> $DIR/negative-sized.rs:6:11
3+
|
4+
LL | foo::<()>();
5+
| ^^ the trait bound `(): !Sized` is not satisfied
6+
|
7+
note: required by a bound in `foo`
8+
--> $DIR/negative-sized.rs:3:11
9+
|
10+
LL | fn foo<T: !Sized>() {}
11+
| ^^^^^^ required by this bound in `foo`
12+
13+
error: aborting due to 1 previous error
14+
15+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)