Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
6630c14
Implement the `+whole-archive` modifier for `wasm-ld`
alexcrichton Sep 24, 2022
c0447b4
fix #103435, unused lint won't produce invalid code
chenyukang Oct 24, 2022
a46af18
fix parentheses surrounding spacing issue in parser
chenyukang Oct 24, 2022
32a2f0d
suggest calling the method of the same name when method not found
chenyukang Oct 25, 2022
2716449
add testcase for suggest self
chenyukang Oct 25, 2022
4f3a988
teach ./miri how to do Josh syncs
RalfJung Oct 29, 2022
39598e4
merge rustup-toolchain into ./miri
RalfJung Oct 29, 2022
2a3a53b
explain how to go back to rustup-managed Miri
RalfJung Oct 29, 2022
18a23a5
Auto merge of #2635 - RalfJung:rustup-managed-miri, r=RalfJung
bors Oct 29, 2022
79a48ce
Auto merge of #2634 - RalfJung:miri-script, r=oli-obk
bors Oct 29, 2022
1470e99
Stacked Borrows: make scalar field retagging the default
RalfJung Oct 29, 2022
c162fd3
Auto merge of #2636 - RalfJung:scalar-field-retag, r=oli-obk
bors Oct 29, 2022
bfe23b9
Merge from rustc
RalfJung Oct 30, 2022
0b49a5d
rustup
RalfJung Oct 30, 2022
962bf63
Auto merge of #2639 - RalfJung:rustup, r=RalfJung
bors Oct 30, 2022
41c368b
fix dupe word typos
Rageking8 Oct 31, 2022
224dff4
add acquire when init once is already complete
beepster4096 Oct 31, 2022
21669d2
Auto merge of #2640 - Rageking8:fix-dupe-word-typos, r=saethlin
bors Oct 31, 2022
a1cd279
followup for pr 2640
Rageking8 Oct 31, 2022
02c5ded
Auto merge of #2642 - Rageking8:followup-for-pr-2640, r=RalfJung
bors Oct 31, 2022
9554907
fix ./miri bench
RalfJung Nov 2, 2022
9d9157e
Auto merge of #2645 - RalfJung:miri-bench, r=RalfJung
bors Nov 2, 2022
fa1b720
refactor into private functions
beepster4096 Nov 4, 2022
cb6f7a6
clarify no_data_race_after_complete test
beepster4096 Nov 4, 2022
4492c02
Auto merge of #2641 - DrMeepster:init_once_acquire, r=RalfJung
bors Nov 4, 2022
83239c2
Merge from rustc
RalfJung Nov 5, 2022
7910caf
Auto merge of #2650 - RalfJung:rustup, r=RalfJung
bors Nov 5, 2022
a1d94d4
impl condvars for windows
beepster4096 Oct 30, 2022
a2f7e84
use enum for condvar locks
beepster4096 Oct 30, 2022
2eb07a0
fix shared behavior and add tests
beepster4096 Oct 31, 2022
f60a2ae
Auto merge of #2638 - DrMeepster:windows-condvars, r=RalfJung
bors Nov 6, 2022
8e0cac1
rustdoc: refactor `notable_traits_decl` to just act on the type directly
notriddle Nov 7, 2022
303653e
rustdoc: use javascript to layout notable traits popups
notriddle Nov 7, 2022
a45151e
rustdoc: fix font color inheritance from body, and test
notriddle Nov 8, 2022
e636af7
lint auto pass
AndyJado Sep 14, 2022
a0cee0a
remove old var_span_path_only
AndyJado Nov 4, 2022
abf259c
var_subdiag refinement
AndyJado Nov 9, 2022
057d8e5
struct error E0505
AndyJado Nov 9, 2022
53e8b49
rustdoc: sort output to make it deterministic
notriddle Nov 9, 2022
5c25d30
Allow specialized const trait impls.
BGR360 Mar 25, 2022
ce03d25
Disallow specializing on const impls with non-const impls.
BGR360 Sep 14, 2022
d492b9b
Add #[const_trait] where needed in tests.
BGR360 Nov 6, 2022
c0ae62e
Require `~const` qualifier on trait bounds in specializing impls if p…
BGR360 Nov 6, 2022
fe53cac
Apply PR feedback.
BGR360 Nov 10, 2022
0f2e45b
make `Sized` coinductive
lcnr Mar 29, 2021
8ec6c84
add some more tests
lcnr Apr 27, 2021
43ad19b
bless tests
compiler-errors Aug 10, 2022
fea8d0e
More nits
compiler-errors Nov 10, 2022
94f67e6
Oops, bless this test.
BGR360 Nov 11, 2022
05824cd
rustdoc: fix HTML validation failure by escaping `data-ty`
notriddle Nov 11, 2022
cd30ccf
Rollup merge of #95292 - BGR360:const-trait-specialize, r=lcnr
Manishearth Nov 11, 2022
76ce198
Rollup merge of #100386 - compiler-errors:sized-coinductive-redux, r=…
Manishearth Nov 11, 2022
9553fea
Rollup merge of #102215 - alexcrichton:wasm-link-whole-archive, r=est…
Manishearth Nov 11, 2022
fd5ff82
Rollup merge of #103468 - chenyukang:yukang/fix-103435-extra-parenthe…
Manishearth Nov 11, 2022
f00897e
Rollup merge of #103531 - chenyukang:yukang/fix-103474, r=estebank
Manishearth Nov 11, 2022
a13809a
Rollup merge of #103960 - AndyJado:var_path_only_diag, r=davidtwco
Manishearth Nov 11, 2022
e8bc6e1
Rollup merge of #104051 - RalfJung:miri, r=RalfJung
Manishearth Nov 11, 2022
b74d042
Rollup merge of #104129 - notriddle:notriddle/102576-js-notable-trait…
Manishearth Nov 11, 2022
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
Prev Previous commit
Next Next commit
Disallow specializing on const impls with non-const impls.
  • Loading branch information
BGR360 committed Nov 10, 2022
commit ce03d259da4a9e47111465353363597868aa2266
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ use crate::constrained_generic_params as cgp;
use crate::errors::SubstsOnOverriddenImpl;

use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
use rustc_infer::infer::TyCtxtInferExt;
Expand Down Expand Up @@ -117,12 +118,33 @@ fn check_always_applicable(tcx: TyCtxt<'_>, impl1_def_id: LocalDefId, impl2_node
};

let span = tcx.def_span(impl1_def_id);
check_constness(tcx, impl1_def_id, impl2_node, span);
check_static_lifetimes(tcx, &parent_substs, span);
check_duplicate_params(tcx, impl1_substs, &parent_substs, span);
check_predicates(tcx, impl1_def_id, impl1_substs, impl2_node, impl2_substs, span);
}
}

/// Check that the specializing impl `impl1` is at least as const as the base
/// impl `impl2`
fn check_constness(tcx: TyCtxt<'_>, impl1_def_id: LocalDefId, impl2_node: Node, span: Span) {
if impl2_node.is_from_trait() {
// This isn't a specialization
return;
}

let impl1_constness = tcx.constness(impl1_def_id.to_def_id());
let impl2_constness = tcx.constness(impl2_node.def_id());

if let hir::Constness::Const = impl2_constness {
if let hir::Constness::NotConst = impl1_constness {
tcx.sess
.struct_span_err(span, "cannot specialize on const impl with non-const impl")
.emit();
}
}
}

/// Given a specializing impl `impl1`, and the base impl `impl2`, returns two
/// substitutions `(S1, S2)` that equate their trait references. The returned
/// types are expressed in terms of the generics of `impl1`.
Expand Down Expand Up @@ -277,7 +299,7 @@ fn check_static_lifetimes<'tcx>(

/// Check whether predicates on the specializing impl (`impl1`) are allowed.
///
/// Each predicate `P` must be:
/// Each predicate `P` must be one of:
///
/// * Global (not reference any parameters).
/// * A `T: Tr` predicate where `Tr` is an always-applicable trait.
Expand Down Expand Up @@ -375,16 +397,19 @@ fn check_predicates<'tcx>(
}
}

/// Checks whether two predicates are the same for the purposes of specialization.
/// Checks if some predicate on the specializing impl (`predicate1`) is the same
/// as some predicate on the base impl (`predicate2`).
///
/// This is slightly more complicated than simple syntactic equivalence, since
/// we want to equate `T: Tr` with `T: ~const Tr` so this can work:
///
/// ```ignore (illustrative)
/// #[rustc_specialization_trait]
/// trait Specialize { }
///
/// impl<T: ~const Bound> const Tr for T { }
/// impl<T: Bound + Specialize> Tr for T { }
/// impl<T: Bound> Tr for T { }
/// impl<T: ~const Bound + Specialize> const Tr for T { }
/// ```
fn trait_predicates_eq<'tcx>(
predicate1: ty::Predicate<'tcx>,
predicate2: ty::Predicate<'tcx>,
Expand All @@ -400,6 +425,8 @@ fn trait_predicates_eq<'tcx>(
_ => kind,
};

// We rely on `check_constness` above to ensure that pred1 is const if pred2
// is const.
let pred1_kind_not_const = predicate1.kind().map_bound(predicate_kind_without_constness);
let pred2_kind_not_const = predicate2.kind().map_bound(predicate_kind_without_constness);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Tests that a const default trait impl can be specialized by a non-const trait
// impl, but that the specializing impl cannot be used in a const context.
// Tests that a const default trait impl cannot be specialized by a non-const
// trait impl.

#![feature(const_trait_impl)]
#![feature(min_specialization)]
Expand All @@ -8,12 +8,6 @@ trait Value {
fn value() -> u32;
}

const fn get_value<T: ~const Value>() -> u32 {
T::value()
//~^ ERROR any use of this value will cause an error [const_err]
//~| WARNING this was previously accepted
}

impl<T> const Value for T {
default fn value() -> u32 {
0
Expand All @@ -22,16 +16,11 @@ impl<T> const Value for T {

struct FortyTwo;

impl Value for FortyTwo {
impl Value for FortyTwo { //~ ERROR cannot specialize on const impl with non-const impl
fn value() -> u32 {
println!("You can't do that (constly)");
42
}
}

const ZERO: u32 = get_value::<()>();

const FORTY_TWO: u32 =
get_value::<FortyTwo>(); // This is the line that causes the error, but it gets reported above

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,37 +1,8 @@
error: any use of this value will cause an error
--> $DIR/const-default-non-const-specialized.rs:12:5
error: cannot specialize on const impl with non-const impl
--> $DIR/const-default-non-const-specialized.rs:19:1
|
LL | T::value()
| ^^^^^^^^^^
| |
| calling non-const function `<FortyTwo as Value>::value`
| inside `get_value::<FortyTwo>` at $DIR/const-default-non-const-specialized.rs:12:5
| inside `FORTY_TWO` at $DIR/const-default-non-const-specialized.rs:35:5
...
LL | const FORTY_TWO: u32 =
| --------------------
|
= note: `#[deny(const_err)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
LL | impl Value for FortyTwo {
| ^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

Future incompatibility report: Future breakage diagnostic:
error: any use of this value will cause an error
--> $DIR/const-default-non-const-specialized.rs:12:5
|
LL | T::value()
| ^^^^^^^^^^
| |
| calling non-const function `<FortyTwo as Value>::value`
| inside `get_value::<FortyTwo>` at $DIR/const-default-non-const-specialized.rs:12:5
| inside `FORTY_TWO` at $DIR/const-default-non-const-specialized.rs:35:5
...
LL | const FORTY_TWO: u32 =
| --------------------
|
= note: `#[deny(const_err)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Tests that `T: ~const Foo` and `T: Foo` are treated as equivalent for the
// Tests that `T: Foo` and `T: ~const Foo` are treated as equivalent for the
// purposes of min_specialization.

// check-pass
Expand All @@ -14,14 +14,14 @@ trait Foo {}

trait Bar {}

impl<T> const Bar for T
impl<T> Bar for T
where
T: ~const Foo,
T: Foo,
{}

impl<T> Bar for T
impl<T> const Bar for T
where
T: Foo,
T: ~const Foo,
T: Specialize,
{}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Tests that a non-const default impl can be specialized by a const trait impl,
// but that the default impl cannot be used in a const context.

// run-pass

#![feature(const_trait_impl)]
#![feature(min_specialization)]

Expand All @@ -27,8 +29,10 @@ impl const Value for FortyTwo {
}
}

const ZERO: u32 = get_value::<()>(); //~ ERROR the trait bound `(): ~const Value` is not satisfied

const FORTY_TWO: u32 = get_value::<FortyTwo>();
fn main() {
let zero = get_value::<()>();
assert_eq!(zero, 0);

fn main() {}
const FORTY_TWO: u32 = get_value::<FortyTwo>();
assert_eq!(FORTY_TWO, 42);
}

This file was deleted.