Skip to content

Rollup of 6 pull requests #133273

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

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b071f64
Emscripten: link with -sWASM_BIGINT
hoodmane Oct 15, 2024
f2f7d32
FieldDef
maxcabrajac Nov 17, 2024
b96758b
Arm
maxcabrajac Nov 17, 2024
e52cef1
Variant
maxcabrajac Nov 17, 2024
f4fbe88
Param
maxcabrajac Nov 17, 2024
8b0284a
GenericParam
maxcabrajac Nov 17, 2024
eb2f1c8
ExprField
maxcabrajac Nov 17, 2024
5c2de73
PatField
maxcabrajac Nov 17, 2024
588c4c4
Rename implied_const_bounds to explicit_implied_const_bounds
compiler-errors Nov 19, 2024
5eeaf2e
Implement ~const opaques
compiler-errors Nov 19, 2024
19b528b
Store resolution for self and crate root module segments
compiler-errors Oct 27, 2024
b33a0d3
we should not be reporting generic error if there is not a segment to…
compiler-errors Oct 26, 2024
1dc1236
Items
maxcabrajac Nov 17, 2024
01b26e6
Use visit_item instead of flat_map_item in test_harness.rs
maxcabrajac Nov 18, 2024
15528b2
Fix `catbat` pager typo.
nnethercote Nov 19, 2024
9116495
Remove redundant `is_terminal` check.
nnethercote Nov 20, 2024
525e191
Rewrite `show_md_content_with_pager`.
nnethercote Nov 20, 2024
a991f25
Reduce integer `Display` implementation size
GuillaumeGomez Nov 20, 2024
91d743c
Rollup merge of #131736 - hoodmane:emscripten-wasm-bigint, r=workingj…
matthiaskrgr Nov 21, 2024
6869b40
Rollup merge of #132207 - compiler-errors:tweak-res-mod-segment, r=pe…
matthiaskrgr Nov 21, 2024
af6711d
Rollup merge of #133153 - maxcabrajac:flat_maps, r=petrochenkov
matthiaskrgr Nov 21, 2024
9937d8b
Rollup merge of #133218 - compiler-errors:const-opaque, r=fee1-dead
matthiaskrgr Nov 21, 2024
f14c424
Rollup merge of #133228 - nnethercote:rewrite-show_md_content_with_pa…
matthiaskrgr Nov 21, 2024
e342ea8
Rollup merge of #133247 - GuillaumeGomez:reduce-integer-display-impl,…
matthiaskrgr Nov 21, 2024
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
Implement ~const opaques
  • Loading branch information
compiler-errors committed Nov 19, 2024
commit 5eeaf2ec3310b6b10d0567890a52eb0293585e7a
2 changes: 2 additions & 0 deletions compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ fn check_opaque_meets_bounds<'tcx>(

let misc_cause = ObligationCause::misc(span, def_id);
// FIXME: We should just register the item bounds here, rather than equating.
// FIXME(const_trait_impl): When we do that, please make sure to also register
// the `~const` bounds.
match ocx.eq(&misc_cause, param_env, opaque_ty, hidden_ty) {
Ok(()) => {}
Err(ty_err) => {
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
self.tcx.ensure().explicit_item_super_predicates(def_id);
self.tcx.ensure().item_bounds(def_id);
self.tcx.ensure().item_super_predicates(def_id);
if self.tcx.is_conditionally_const(def_id) {
self.tcx.ensure().explicit_implied_const_bounds(def_id);
self.tcx.ensure().const_conditions(def_id);
}
intravisit::walk_opaque_ty(self, opaque);
}

Expand Down Expand Up @@ -681,6 +685,10 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
tcx.ensure().generics_of(item.owner_id);
tcx.ensure().type_of(item.owner_id);
tcx.ensure().predicates_of(item.owner_id);
if tcx.is_conditionally_const(def_id) {
tcx.ensure().explicit_implied_const_bounds(def_id);
tcx.ensure().const_conditions(def_id);
}
match item.kind {
hir::ForeignItemKind::Fn(..) => {
tcx.ensure().codegen_fn_attrs(item.owner_id);
Expand Down
9 changes: 8 additions & 1 deletion compiler/rustc_hir_analysis/src/collect/predicates_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,12 @@ pub(super) fn const_conditions<'tcx>(
hir::ForeignItemKind::Fn(_, _, generics) => (generics, None, false),
_ => bug!("const_conditions called on wrong item: {def_id:?}"),
},
Node::OpaqueTy(opaque) => match opaque.origin {
hir::OpaqueTyOrigin::FnReturn { parent, .. } => return tcx.const_conditions(parent),
hir::OpaqueTyOrigin::AsyncFn { .. } | hir::OpaqueTyOrigin::TyAlias { .. } => {
unreachable!()
}
},
// N.B. Tuple ctors are unconditionally constant.
Node::Ctor(hir::VariantData::Tuple { .. }) => return Default::default(),
_ => bug!("const_conditions called on wrong item: {def_id:?}"),
Expand Down Expand Up @@ -1033,7 +1039,8 @@ pub(super) fn explicit_implied_const_bounds<'tcx>(
PredicateFilter::SelfConstIfConst,
)
}
Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Type(..), .. }) => {
Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Type(..), .. })
| Node::OpaqueTy(_) => {
explicit_item_bounds_with_filter(tcx, def_id, PredicateFilter::ConstIfConst)
}
_ => bug!("explicit_implied_const_bounds called on wrong item: {def_id:?}"),
Expand Down
27 changes: 23 additions & 4 deletions compiler/rustc_infer/src/infer/opaque_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,8 @@ impl<'tcx> InferCtxt<'tcx> {
// unexpected region errors.
goals.push(Goal::new(tcx, param_env, ty::ClauseKind::WellFormed(hidden_ty.into())));

let item_bounds = tcx.explicit_item_bounds(def_id);
for (predicate, _) in item_bounds.iter_instantiated_copied(tcx, args) {
let predicate = predicate.fold_with(&mut BottomUpFolder {
let replace_opaques_in = |clause: ty::Clause<'tcx>, goals: &mut Vec<_>| {
clause.fold_with(&mut BottomUpFolder {
tcx,
ty_op: |ty| match *ty.kind() {
// We can't normalize associated types from `rustc_infer`,
Expand Down Expand Up @@ -612,11 +611,31 @@ impl<'tcx> InferCtxt<'tcx> {
},
lt_op: |lt| lt,
ct_op: |ct| ct,
});
})
};

let item_bounds = tcx.explicit_item_bounds(def_id);
for (predicate, _) in item_bounds.iter_instantiated_copied(tcx, args) {
let predicate = replace_opaques_in(predicate, goals);

// Require that the predicate holds for the concrete type.
debug!(?predicate);
goals.push(Goal::new(self.tcx, param_env, predicate));
}

// If this opaque is being defined and it's conditionally const,
if self.tcx.is_conditionally_const(def_id) {
let item_bounds = tcx.explicit_implied_const_bounds(def_id);
for (predicate, _) in item_bounds.iter_instantiated_copied(tcx, args) {
let predicate = replace_opaques_in(
predicate.to_host_effect_clause(self.tcx, ty::BoundConstness::Maybe),
goals,
);

// Require that the predicate holds for the concrete type.
debug!(?predicate);
goals.push(Goal::new(self.tcx, param_env, predicate));
}
}
}
}
4 changes: 4 additions & 0 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1532,6 +1532,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
self.encode_explicit_item_super_predicates(def_id);
record!(self.tables.opaque_ty_origin[def_id] <- self.tcx.opaque_ty_origin(def_id));
self.encode_precise_capturing_args(def_id);
if tcx.is_conditionally_const(def_id) {
record_defaulted_array!(self.tables.explicit_implied_const_bounds[def_id]
<- tcx.explicit_implied_const_bounds(def_id).skip_binder());
}
}
if tcx.impl_method_has_trait_impl_trait_tys(def_id)
&& let Ok(table) = self.tcx.collect_return_position_impl_trait_in_trait_tys(def_id)
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2117,7 +2117,13 @@ impl<'tcx> TyCtxt<'tcx> {
_ => bug!("unexpected parent item of associated item: {parent_def_id:?}"),
}
}
DefKind::Closure | DefKind::OpaqueTy => {
DefKind::OpaqueTy => match self.opaque_ty_origin(def_id) {
hir::OpaqueTyOrigin::FnReturn { parent, .. } => self.is_conditionally_const(parent),
hir::OpaqueTyOrigin::AsyncFn { .. } => false,
// FIXME(const_trait_impl): ATPITs could be conditionally const?
hir::OpaqueTyOrigin::TyAlias { .. } => false,
},
DefKind::Closure => {
// Closures and RPITs will eventually have const conditions
// for `~const` bounds.
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,13 @@ LL | const fn test() -> impl ~const Fn() {
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 2 previous errors
error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/const-closure-parse-not-item.rs:7:25
|
LL | const fn test() -> impl ~const Fn() {
| ^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 3 previous errors

15 changes: 15 additions & 0 deletions tests/ui/traits/const-traits/const-opaque.no.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0277]: the trait bound `(): const Foo` is not satisfied
--> $DIR/const-opaque.rs:31:18
|
LL | let opaque = bar(());
| ^^^^^^^

error[E0277]: the trait bound `(): const Foo` is not satisfied
--> $DIR/const-opaque.rs:33:5
|
LL | opaque.method();
| ^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.
38 changes: 38 additions & 0 deletions tests/ui/traits/const-traits/const-opaque.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//@ revisions: yes no
//@ compile-flags: -Znext-solver
//@[yes] check-pass

#![feature(const_trait_impl)]

#[const_trait]
trait Foo {
fn method(&self);
}

impl<T: ~const Foo> const Foo for (T,) {
fn method(&self) {}
}

#[cfg(yes)]
impl const Foo for () {
fn method(&self) {}
}

#[cfg(no)]
impl Foo for () {
fn method(&self) {}
}

const fn bar<T: ~const Foo>(t: T) -> impl ~const Foo {
(t,)
}

const _: () = {
let opaque = bar(());
//[no]~^ ERROR the trait bound `(): const Foo` is not satisfied
opaque.method();
//[no]~^ ERROR the trait bound `(): const Foo` is not satisfied
std::mem::forget(opaque);
};

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const fn test() -> impl ~const Fn() {
//~^ ERROR `~const` can only be applied to `#[const_trait]` traits
//~| ERROR `~const` can only be applied to `#[const_trait]` traits
//~| ERROR `~const` can only be applied to `#[const_trait]` traits
const move || { //~ ERROR const closures are experimental
let sl: &[u8] = b"foo";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0658]: const closures are experimental
--> $DIR/ice-112822-expected-type-for-param.rs:6:5
--> $DIR/ice-112822-expected-type-for-param.rs:7:5
|
LL | const move || {
| ^^^^^
Expand All @@ -22,8 +22,16 @@ LL | const fn test() -> impl ~const Fn() {
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/ice-112822-expected-type-for-param.rs:3:25
|
LL | const fn test() -> impl ~const Fn() {
| ^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0015]: cannot call non-const operator in constant functions
--> $DIR/ice-112822-expected-type-for-param.rs:11:17
--> $DIR/ice-112822-expected-type-for-param.rs:12:17
|
LL | assert_eq!(first, &b'f');
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -32,15 +40,15 @@ LL | assert_eq!(first, &b'f');
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0015]: cannot call non-const fn `core::panicking::assert_failed::<&u8, &u8>` in constant functions
--> $DIR/ice-112822-expected-type-for-param.rs:11:17
--> $DIR/ice-112822-expected-type-for-param.rs:12:17
|
LL | assert_eq!(first, &b'f');
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 5 previous errors
error: aborting due to 6 previous errors

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