Skip to content

Commit b080a1a

Browse files
authored
Rollup merge of #107815 - compiler-errors:new-solver-no-auto-if-impl, r=lcnr
Disqualify `auto trait` built-in impl in new solver if explicit `impl` exists
2 parents 16a4138 + 68e27b3 commit b080a1a

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

compiler/rustc_trait_selection/src/solve/trait_goals.rs

+14
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
8989
ecx: &mut EvalCtxt<'_, 'tcx>,
9090
goal: Goal<'tcx, Self>,
9191
) -> QueryResult<'tcx> {
92+
// This differs from the current stable behavior and
93+
// fixes #84857. Due to breakage found via crater, we
94+
// currently instead lint patterns which can be used to
95+
// exploit this unsoundness on stable, see #93367 for
96+
// more details.
97+
if let Some(def_id) = ecx.tcx().find_map_relevant_impl(
98+
goal.predicate.def_id(),
99+
goal.predicate.self_ty(),
100+
Some,
101+
) {
102+
debug!(?def_id, ?goal, "disqualified auto-trait implementation");
103+
return Err(NoSolution);
104+
}
105+
92106
ecx.probe_and_evaluate_goal_for_constituent_tys(
93107
goal,
94108
structural_traits::instantiate_constituent_tys_for_auto_trait,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// compile-flags: -Ztrait-solver=next
2+
// check-pass
3+
4+
struct Foo(*mut ());
5+
6+
unsafe impl Sync for Foo {}
7+
8+
fn main() {}

0 commit comments

Comments
 (0)