Skip to content

Commit 3e4e2d3

Browse files
authored
Unrolled build for #145713
Rollup merge of #145713 - lcnr:const-trait-bootstrap, r=compiler-errors next-solver: fix `feature(const_trait_impl)` bootstrap rarw r? ``@compiler-errors`` ``@fee1-dead``
2 parents 69b76df + e8ae1da commit 3e4e2d3

File tree

5 files changed

+69
-9
lines changed

5 files changed

+69
-9
lines changed

compiler/rustc_middle/src/ty/context.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use rustc_errors::{
3333
Applicability, Diag, DiagCtxtHandle, ErrorGuaranteed, LintDiagnostic, LintEmitter, MultiSpan,
3434
};
3535
use rustc_hir::attrs::AttributeKind;
36-
use rustc_hir::def::{CtorKind, DefKind};
36+
use rustc_hir::def::{CtorKind, CtorOf, DefKind};
3737
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId};
3838
use rustc_hir::definitions::{DefPathData, Definitions, DisambiguatorState};
3939
use rustc_hir::intravisit::VisitorExt;
@@ -445,7 +445,10 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
445445
}
446446

447447
fn fn_is_const(self, def_id: DefId) -> bool {
448-
debug_assert_matches!(self.def_kind(def_id), DefKind::Fn | DefKind::AssocFn);
448+
debug_assert_matches!(
449+
self.def_kind(def_id),
450+
DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(CtorOf::Struct, CtorKind::Fn)
451+
);
449452
self.is_conditionally_const(def_id)
450453
}
451454

compiler/rustc_next_trait_solver/src/solve/effect_goals.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_type_ir::inherent::*;
66
use rustc_type_ir::lang_items::TraitSolverLangItem;
77
use rustc_type_ir::solve::SizedTraitKind;
88
use rustc_type_ir::solve::inspect::ProbeKind;
9-
use rustc_type_ir::{self as ty, Interner, elaborate};
9+
use rustc_type_ir::{self as ty, Interner, TypingMode, elaborate};
1010
use tracing::instrument;
1111

1212
use super::assembly::{Candidate, structural_traits};
@@ -135,12 +135,16 @@ where
135135
}
136136

137137
let impl_polarity = cx.impl_polarity(impl_def_id);
138-
match impl_polarity {
138+
let certainty = match impl_polarity {
139139
ty::ImplPolarity::Negative => return Err(NoSolution),
140-
ty::ImplPolarity::Reservation => {
141-
unimplemented!("reservation impl for const trait: {:?}", goal)
142-
}
143-
ty::ImplPolarity::Positive => {}
140+
ty::ImplPolarity::Reservation => match ecx.typing_mode() {
141+
TypingMode::Coherence => Certainty::AMBIGUOUS,
142+
TypingMode::Analysis { .. }
143+
| TypingMode::Borrowck { .. }
144+
| TypingMode::PostBorrowckAnalysis { .. }
145+
| TypingMode::PostAnalysis => return Err(NoSolution),
146+
},
147+
ty::ImplPolarity::Positive => Certainty::Yes,
144148
};
145149

146150
if !cx.impl_is_const(impl_def_id) {
@@ -171,7 +175,7 @@ where
171175
});
172176
ecx.add_goals(GoalSource::ImplWhereBound, const_conditions);
173177

174-
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
178+
ecx.evaluate_added_goals_and_make_canonical_response(certainty)
175179
})
176180
}
177181

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ check-pass
2+
//@ compile-flags: -Znext-solver
3+
#![feature(const_trait_impl)]
4+
const fn impls_fn<F: ~const Fn(u32) -> Foo>(_: &F) {}
5+
6+
struct Foo(u32);
7+
8+
const fn foo() {
9+
// This previously triggered an incorrect assert
10+
// when checking whether the constructor of `Foo`
11+
// is const.
12+
impls_fn(&Foo)
13+
}
14+
15+
fn main() {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ compile-flags: -Znext-solver
2+
#![feature(const_from, never_type, const_trait_impl)]
3+
4+
const fn impls_from<T: ~const From<!>>() {}
5+
6+
const fn foo() {
7+
// This previously ICE'd when encountering the reservation impl
8+
// from the standard library.
9+
impls_from::<()>();
10+
//~^ ERROR the trait bound `(): From<!>` is not satisfied
11+
}
12+
13+
fn main() {}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0277]: the trait bound `(): From<!>` is not satisfied
2+
--> $DIR/reservation-impl-ice.rs:9:18
3+
|
4+
LL | impls_from::<()>();
5+
| ^^ the trait `From<!>` is not implemented for `()`
6+
|
7+
= help: the following other types implement trait `From<T>`:
8+
`(T, T)` implements `From<[T; 2]>`
9+
`(T, T, T)` implements `From<[T; 3]>`
10+
`(T, T, T, T)` implements `From<[T; 4]>`
11+
`(T, T, T, T, T)` implements `From<[T; 5]>`
12+
`(T, T, T, T, T, T)` implements `From<[T; 6]>`
13+
`(T, T, T, T, T, T, T)` implements `From<[T; 7]>`
14+
`(T, T, T, T, T, T, T, T)` implements `From<[T; 8]>`
15+
`(T, T, T, T, T, T, T, T, T)` implements `From<[T; 9]>`
16+
and 4 others
17+
note: required by a bound in `impls_from`
18+
--> $DIR/reservation-impl-ice.rs:4:24
19+
|
20+
LL | const fn impls_from<T: ~const From<!>>() {}
21+
| ^^^^^^^^^^^^^^ required by this bound in `impls_from`
22+
23+
error: aborting due to 1 previous error
24+
25+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)