Skip to content

Commit cbc3598

Browse files
committed
turn new resolving behavior on unconditionally
1 parent aa1bc90 commit cbc3598

5 files changed

Lines changed: 17 additions & 36 deletions

File tree

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,10 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
370370
trace!("resolve: {:?}, {:#?}", def, args);
371371
trace!("typing_env: {:#?}", self.typing_env);
372372
trace!("args: {:#?}", args);
373-
let resolve = if M::SHOULD_RESPECT_CONST_BOUNDS_WHEN_RESOLVING_INSTANCES {
373+
374+
let resolve = if M::SHOULD_RESPECT_CONST_BOUNDS_WHEN_RESOLVING_INSTANCES
375+
&& !self.tcx.sess.opts.unstable_opts.unleash_the_miri_inside_of_you
376+
{
374377
ty::Instance::try_resolve_for_ctfe
375378
} else {
376379
ty::Instance::try_resolve

compiler/rustc_traits/src/codegen.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use tracing::debug;
2323
///
2424
/// This also expects that `trait_ref` is fully normalized.
2525
///
26-
/// When `use_const` is set, we assume the new trait solver is enabled and use
26+
/// When `use_const` is set, we use the new trait solver to prove
2727
/// `HostEffectPredicate` with `constness` set to `Const`.
2828
pub(crate) fn codegen_select_candidate_inner<'tcx>(
2929
tcx: TyCtxt<'tcx>,
@@ -36,7 +36,13 @@ pub(crate) fn codegen_select_candidate_inner<'tcx>(
3636

3737
// Do the initial selection for the obligation. This yields the
3838
// shallow result we are looking for -- that is, what specific impl.
39-
let (infcx, param_env) = tcx.infer_ctxt().ignoring_regions().build_with_typing_env(typing_env);
39+
let mut infcx_builder = tcx.infer_ctxt().ignoring_regions();
40+
if use_const {
41+
// next trait solver is used unconditionally here, because only const code that use trait methods
42+
// are effected (nightly code)
43+
infcx_builder = infcx_builder.with_next_trait_solver(true);
44+
}
45+
let (infcx, param_env) = infcx_builder.build_with_typing_env(typing_env);
4046
let mut selcx = SelectionContext::new(&infcx);
4147

4248
let obligation_cause = ObligationCause::dummy();
@@ -45,7 +51,6 @@ pub(crate) fn codegen_select_candidate_inner<'tcx>(
4551
let host_predicate =
4652
ty::HostEffectPredicate { trait_ref, constness: ty::BoundConstness::Const };
4753
let obligation = Obligation::new(tcx, obligation_cause, param_env, host_predicate);
48-
4954
infcx.select_host_effect_predicate_in_new_trait_solver(&obligation)
5055
} else {
5156
let obligation = Obligation::new(tcx, obligation_cause, param_env, trait_ref);

compiler/rustc_ty_utils/src/instance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn resolve_associated_item<'tcx>(
114114
let trait_ref = ty::TraitRef::from_assoc(tcx, trait_id, rcvr_args);
115115

116116
let input = typing_env.as_query_input(trait_ref);
117-
let candidate = if constness == Constness::Const && tcx.next_trait_solver_globally() {
117+
let candidate = if constness == Constness::Const {
118118
tcx.codegen_select_candidate_for_ctfe(input)
119119
} else {
120120
tcx.codegen_select_candidate(input)

tests/ui/consts/qualif-indirect-mutation-fail.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub const A1: () = {
1515
let b = &mut y;
1616
std::mem::swap(a, b);
1717
std::mem::forget(y);
18-
}; //~ ERROR calling non-const function `<Vec<u8> as Drop>::drop`
18+
};
1919

2020
// Mutable borrow of a type with drop impl.
2121
pub const A2: () = {
@@ -26,7 +26,7 @@ pub const A2: () = {
2626
std::mem::swap(a, b);
2727
std::mem::forget(y);
2828
let _z = x; //~ ERROR destructor of
29-
}; //~ ERROR calling non-const function `<Vec<u8> as Drop>::drop`
29+
};
3030

3131
// Shared borrow of a type that might be !Freeze and Drop.
3232
pub const fn g1<T>() {

tests/ui/consts/qualif-indirect-mutation-fail.stderr

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,6 @@ LL | let mut x = None;
77
LL | };
88
| - value is dropped here
99

10-
error[E0080]: calling non-const function `<Vec<u8> as Drop>::drop`
11-
--> $DIR/qualif-indirect-mutation-fail.rs:18:1
12-
|
13-
LL | };
14-
| ^ evaluation of `A1` failed inside this call
15-
|
16-
note: inside `std::ptr::drop_glue::<Option<String>> - shim(Some(Option<String>))`
17-
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
18-
note: inside `std::ptr::drop_glue::<String> - shim(Some(String))`
19-
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
20-
note: inside `std::ptr::drop_glue::<Vec<u8>> - shim(Some(Vec<u8>))`
21-
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
22-
2310
error[E0493]: destructor of `Option<String>` cannot be evaluated at compile-time
2411
--> $DIR/qualif-indirect-mutation-fail.rs:28:9
2512
|
@@ -28,19 +15,6 @@ LL | let _z = x;
2815
LL | };
2916
| - value is dropped here
3017

31-
error[E0080]: calling non-const function `<Vec<u8> as Drop>::drop`
32-
--> $DIR/qualif-indirect-mutation-fail.rs:29:1
33-
|
34-
LL | };
35-
| ^ evaluation of `A2` failed inside this call
36-
|
37-
note: inside `std::ptr::drop_glue::<Option<String>> - shim(Some(Option<String>))`
38-
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
39-
note: inside `std::ptr::drop_glue::<String> - shim(Some(String))`
40-
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
41-
note: inside `std::ptr::drop_glue::<Vec<u8>> - shim(Some(Vec<u8>))`
42-
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
43-
4418
error[E0493]: destructor of `(u32, Option<String>)` cannot be evaluated at compile-time
4519
--> $DIR/qualif-indirect-mutation-fail.rs:6:9
4620
|
@@ -103,7 +77,6 @@ LL | let x: Option<String> = None;
10377
LL | }
10478
| - value is dropped here
10579

106-
error: aborting due to 11 previous errors
80+
error: aborting due to 9 previous errors
10781

108-
Some errors have detailed explanations: E0080, E0493.
109-
For more information about an error, try `rustc --explain E0080`.
82+
For more information about this error, try `rustc --explain E0493`.

0 commit comments

Comments
 (0)