about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2025-05-17 14:11:51 +0000
committerMichael Goulet <michael@errs.io>2025-05-18 12:18:44 +0000
commit407fac54798cf225b81b67cad2525a0acbda9b03 (patch)
tree14a68371e265f8ab05f8225e7db5da0a0b60ea11
parent1d0d258a8635822b49d6cc937d895947523372fd (diff)
downloadrust-407fac54798cf225b81b67cad2525a0acbda9b03.tar.gz
rust-407fac54798cf225b81b67cad2525a0acbda9b03.zip
Fast path for sized pred
-rw-r--r--compiler/rustc_middle/src/ty/sty.rs4
-rw-r--r--compiler/rustc_trait_selection/src/solve/delegate.rs16
2 files changed, 18 insertions, 2 deletions
diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs
index ab1f3d6099f..77b9becba57 100644
--- a/compiler/rustc_middle/src/ty/sty.rs
+++ b/compiler/rustc_middle/src/ty/sty.rs
@@ -1882,9 +1882,9 @@ impl<'tcx> Ty<'tcx> {
             // Needs normalization or revealing to determine, so no is the safe answer.
             ty::Alias(..) => false,
 
-            ty::Param(..) | ty::Infer(..) | ty::Error(..) => false,
+            ty::Param(..) | ty::Placeholder(..) | ty::Infer(..) | ty::Error(..) => false,
 
-            ty::Bound(..) | ty::Placeholder(..) => {
+            ty::Bound(..) => {
                 bug!("`is_trivially_pure_clone_copy` applied to unexpected type: {:?}", self);
             }
         }
diff --git a/compiler/rustc_trait_selection/src/solve/delegate.rs b/compiler/rustc_trait_selection/src/solve/delegate.rs
index b6351e5e604..a60642b953c 100644
--- a/compiler/rustc_trait_selection/src/solve/delegate.rs
+++ b/compiler/rustc_trait_selection/src/solve/delegate.rs
@@ -1,6 +1,7 @@
 use std::ops::Deref;
 
 use rustc_data_structures::fx::FxHashSet;
+use rustc_hir::LangItem;
 use rustc_hir::def_id::{CRATE_DEF_ID, DefId};
 use rustc_infer::infer::canonical::query_response::make_query_region_constraints;
 use rustc_infer::infer::canonical::{
@@ -83,6 +84,21 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
 
                 Some(HasChanged::No)
             }
+            ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_pred)) => {
+                match self.0.tcx.as_lang_item(trait_pred.def_id()) {
+                    Some(LangItem::Sized)
+                        if trait_pred.self_ty().is_trivially_sized(self.0.tcx) =>
+                    {
+                        Some(HasChanged::No)
+                    }
+                    Some(LangItem::Copy | LangItem::Clone)
+                        if trait_pred.self_ty().is_trivially_pure_clone_copy() =>
+                    {
+                        Some(HasChanged::No)
+                    }
+                    _ => None,
+                }
+            }
             _ => None,
         }
     }