Skip to content

Rollup of 11 pull requests #135519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3c31861
Don't allow transmuting ZSTs in dispatch_from_dyn impl
compiler-errors Jan 8, 2025
11bc805
Don't allow DispatchFromDyn impls that transmute ZST to non-ZST
compiler-errors Jan 8, 2025
d4057e8
re-add --disable-minification to rustdoc
lolbinarycat Jan 10, 2025
7f743c7
bootstrap: do not rely on LIBRARY_PATH env variable
rhelmot Dec 30, 2024
ebd5ce1
for purely return-type based searches, deprioritize clone-like functions
lolbinarycat Jan 9, 2025
244316f
add disclaimer to --disable-minification
lolbinarycat Jan 14, 2025
f5e23d5
fix typo and unit test
lolbinarycat Jan 14, 2025
516a933
Make sure we can produce ConstArgHasWrongType errors for valtree consts
compiler-errors Jan 11, 2025
3cd7581
Normalize field before checking PhantomData in coerce/dispatch impl v…
compiler-errors Jan 8, 2025
2669f2a
Do not consider traits that have unsatisfied const conditions to be c…
compiler-errors Jan 13, 2025
b89a6e4
Consider more erroneous layouts as LayoutError::ReferencesError to su…
compiler-errors Jan 8, 2025
2743df8
Enforce syntactical stability of const traits in HIR
compiler-errors Jan 12, 2025
5775190
Make sure to scrape region constraints from deeply normalizing type o…
compiler-errors Dec 30, 2024
4f6902d
fix underlining of hovered intra-doc links.
lolbinarycat Jan 14, 2025
62d5562
Fix clippy lints
GuillaumeGomez Jan 14, 2025
8f7e622
Rollup merge of #134913 - rhelmot:master, r=jieyouxu
workingjubilee Jan 15, 2025
aa8bc25
Rollup merge of #134940 - compiler-errors:scrape, r=lcnr
workingjubilee Jan 15, 2025
f256f9e
Rollup merge of #135228 - compiler-errors:normalizes-ur-dispatch, r=B…
workingjubilee Jan 15, 2025
55247be
Rollup merge of #135264 - compiler-errors:layout-propagate-errors, r=…
workingjubilee Jan 15, 2025
0a5a8c4
Rollup merge of #135302 - lolbinarycat:rustdoc-search-return-sort-134…
workingjubilee Jan 15, 2025
b998c29
Rollup merge of #135353 - lolbinarycat:rustdoc-disable-minification, …
workingjubilee Jan 15, 2025
7c85da9
Rollup merge of #135380 - compiler-errors:mismatch-valtree, r=lcnr
workingjubilee Jan 15, 2025
11ac57a
Rollup merge of #135423 - compiler-errors:enforce-const-trait-syntact…
workingjubilee Jan 15, 2025
0a1b9db
Rollup merge of #135425 - compiler-errors:not-conditionally-const, r=…
workingjubilee Jan 15, 2025
b52f2fa
Rollup merge of #135499 - lolbinarycat:rustdoc-link-underline-133484,…
workingjubilee Jan 15, 2025
4f25a31
Rollup merge of #135505 - GuillaumeGomez:clippy, r=notriddle
workingjubilee Jan 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions compiler/rustc_const_eval/src/check_consts/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ use crate::errors;
type QualifResults<'mir, 'tcx, Q> =
rustc_mir_dataflow::ResultsCursor<'mir, 'tcx, FlowSensitiveAnalysis<'mir, 'mir, 'tcx, Q>>;

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
enum ConstConditionsHold {
Yes,
No,
}

#[derive(Default)]
pub(crate) struct Qualifs<'mir, 'tcx> {
has_mut_interior: Option<QualifResults<'mir, 'tcx, HasMutInterior>>,
Expand Down Expand Up @@ -376,15 +382,15 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
callee: DefId,
callee_args: ty::GenericArgsRef<'tcx>,
call_span: Span,
) -> bool {
) -> Option<ConstConditionsHold> {
let tcx = self.tcx;
if !tcx.is_conditionally_const(callee) {
return false;
return None;
}

let const_conditions = tcx.const_conditions(callee).instantiate(tcx, callee_args);
if const_conditions.is_empty() {
return false;
return None;
}

let (infcx, param_env) = tcx.infer_ctxt().build_with_typing_env(self.body.typing_env(tcx));
Expand Down Expand Up @@ -413,12 +419,13 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
}));

let errors = ocx.select_all_or_error();
if !errors.is_empty() {
if errors.is_empty() {
Some(ConstConditionsHold::Yes)
} else {
tcx.dcx()
.span_delayed_bug(call_span, "this should have reported a ~const error in HIR");
Some(ConstConditionsHold::No)
}

true
}

pub fn check_drop_terminator(
Expand Down Expand Up @@ -706,7 +713,10 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
trace!("attempting to call a trait method");
let trait_is_const = tcx.is_const_trait(trait_did);

if trait_is_const {
// Only consider a trait to be const if the const conditions hold.
// Otherwise, it's really misleading to call something "conditionally"
// const when it's very obviously not conditionally const.
if trait_is_const && has_const_conditions == Some(ConstConditionsHold::Yes) {
// Trait calls are always conditionally-const.
self.check_op(ops::ConditionallyConstCall {
callee,
Expand All @@ -730,7 +740,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
}

// Even if we know the callee, ensure we can use conditionally-const calls.
if has_const_conditions {
if has_const_conditions.is_some() {
self.check_op(ops::ConditionallyConstCall {
callee,
args: fn_args,
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/issues/issue-25901.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ struct A;
struct B;

static S: &'static B = &A;
//~^ ERROR cannot perform conditionally-const deref coercion
//~^ ERROR cannot perform non-const deref coercion

use std::ops::Deref;

Expand Down
13 changes: 8 additions & 5 deletions tests/ui/issues/issue-25901.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0658]: cannot perform conditionally-const deref coercion on `A` in statics
error[E0015]: cannot perform non-const deref coercion on `A` in statics
--> $DIR/issue-25901.rs:4:24
|
LL | static S: &'static B = &A;
Expand All @@ -10,11 +10,14 @@ note: deref defined here
|
LL | type Target = B;
| ^^^^^^^^^^^
note: impl defined here, but it is not `const`
--> $DIR/issue-25901.rs:9:1
|
LL | impl Deref for A {
| ^^^^^^^^^^^^^^^^
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0658`.
For more information about this error, try `rustc --explain E0015`.
2 changes: 1 addition & 1 deletion tests/ui/self/arbitrary-self-from-method-substs-ice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl Foo {
//~^ ERROR invalid generic `self` parameter type
//~| ERROR destructor of `R` cannot be evaluated at compile-time
self.0
//~^ ERROR cannot perform conditionally-const deref coercion on `R` in constant functions
//~^ ERROR cannot perform non-const deref coercion on `R` in constant functions
}
}

Expand Down
9 changes: 3 additions & 6 deletions tests/ui/self/arbitrary-self-from-method-substs-ice.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
error[E0658]: cannot perform conditionally-const deref coercion on `R` in constant functions
error[E0015]: cannot perform non-const deref coercion on `R` in constant functions
--> $DIR/arbitrary-self-from-method-substs-ice.rs:13:9
|
LL | self.0
| ^^^^^^
|
= note: attempting to deref into `Foo`
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0493]: destructor of `R` cannot be evaluated at compile-time
--> $DIR/arbitrary-self-from-method-substs-ice.rs:10:43
Expand All @@ -30,5 +27,5 @@ LL | const fn get<R: Deref<Target = Self>>(self: R) -> u32 {

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0493, E0658, E0801.
For more information about an error, try `rustc --explain E0493`.
Some errors have detailed explanations: E0015, E0493, E0801.
For more information about an error, try `rustc --explain E0015`.
8 changes: 3 additions & 5 deletions tests/ui/traits/const-traits/cross-crate.stocknc.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
error[E0658]: cannot call conditionally-const method `<cross_crate::NonConst as cross_crate::MyTrait>::func` in constant functions
error[E0015]: cannot call non-const method `<cross_crate::NonConst as cross_crate::MyTrait>::func` in constant functions
--> $DIR/cross-crate.rs:19:14
|
LL | NonConst.func();
| ^^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0658]: cannot call conditionally-const method `<cross_crate::Const as cross_crate::MyTrait>::func` in constant functions
--> $DIR/cross-crate.rs:22:11
Expand All @@ -22,4 +19,5 @@ LL | Const.func();

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0658`.
Some errors have detailed explanations: E0015, E0658.
For more information about an error, try `rustc --explain E0015`.