-
-
Notifications
You must be signed in to change notification settings - Fork 15.9k
yeet AliasConstKind::opt_def_id #162797
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
base: main
Are you sure you want to change the base?
yeet AliasConstKind::opt_def_id #162797
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1481,9 +1481,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | |
| )? { | ||
| TypeRelativePath::AssocItem(alias_term) => { | ||
| let alias_ct = alias_term.expect_ct(); | ||
| if let Some(def_id) = alias_ct.kind.opt_def_id() { | ||
| self.check_const_item_in_type_system(def_id, span)?; | ||
| } | ||
| self.check_const_item_in_type_system(alias_ct.kind, span)?; | ||
| let ct = Const::new_alias(tcx, ty::IsRigid::No, alias_ct); | ||
| let ct = self.check_param_uses_if_mcg(ct, span, false); | ||
| Ok(ct) | ||
|
|
@@ -1945,7 +1943,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | |
| item_segment, | ||
| ty::AssocTag::Const, | ||
| )?; | ||
| self.check_const_item_in_type_system(item_def_id, span)?; | ||
| let alias_const = ty::AliasConst::new( | ||
| tcx, | ||
| ty::AliasConstKind::new_from_def_id( | ||
|
|
@@ -1955,6 +1952,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | |
| ), | ||
| item_args, | ||
| ); | ||
| self.check_const_item_in_type_system(alias_const.kind, span)?; | ||
| Ok(Const::new_alias(tcx, ty::IsRigid::No, alias_const)) | ||
| } | ||
|
|
||
|
|
@@ -2900,7 +2898,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | |
| self.lower_const_param(def_id, hir_id) | ||
| } | ||
| Res::Def(DefKind::Const, did) => { | ||
| if let Err(guar) = self.check_const_item_in_type_system(did, span) { | ||
| let alias_const_kind = ty::AliasConstKind::new_from_def_id( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. given that this is never an inherent const it would be nice to use a different constructor here that doesnt take
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #162760 I suppose
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exactly:
(this is one of the kludgey spots) |
||
| tcx, | ||
| did, | ||
| ty::AliasConstInherentArgsKind::WithSelf, | ||
| ); | ||
| if let Err(guar) = self.check_const_item_in_type_system(alias_const_kind, span) { | ||
| return Const::new_error(self.tcx(), guar); | ||
| } | ||
|
|
||
|
|
@@ -2912,15 +2915,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | |
| ty::Const::new_alias( | ||
| tcx, | ||
| ty::IsRigid::No, | ||
| ty::AliasConst::new( | ||
| tcx, | ||
| ty::AliasConstKind::new_from_def_id( | ||
| tcx, | ||
| did, | ||
| ty::AliasConstInherentArgsKind::WithSelf, | ||
| ), | ||
| args, | ||
| ), | ||
| ty::AliasConst::new(tcx, alias_const_kind, args), | ||
| ) | ||
| } | ||
| Res::Def(kind @ DefKind::Ctor(ctor_of, CtorKind::Const), did) => { | ||
|
|
@@ -3155,18 +3150,27 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | |
| /// `def_id` is a const item used in the type system. Checks if that's OK. | ||
| fn check_const_item_in_type_system( | ||
| &self, | ||
| def_id: DefId, | ||
| alias_const: ty::AliasConstKind<'tcx>, | ||
| span: Span, | ||
| ) -> Result<(), ErrorGuaranteed> { | ||
| let tcx = self.tcx(); | ||
| if tcx.features().generic_const_args() || tcx.is_direct_const(def_id) { | ||
| if tcx.features().generic_const_args() || alias_const.is_direct_const(tcx) { | ||
| Ok(()) | ||
| } else { | ||
| let mut err = self | ||
| .dcx() | ||
| .struct_span_err(span, "use of `const` in the type system not marked as direct"); | ||
| if let Some(local_def_id) = def_id.as_local() { | ||
| if let Some(body_id) = tcx.hir_node_by_def_id(local_def_id).body_id() { | ||
| let hir_node = match alias_const { | ||
| ty::AliasConstKind::Projection { def_id } | ||
| | ty::AliasConstKind::InherentSelf { def_id } | ||
| | ty::AliasConstKind::InherentImpl { def_id } | ||
| | ty::AliasConstKind::Free { def_id } | ||
| | ty::AliasConstKind::Anon { def_id } => { | ||
| def_id.as_local().map(|id| tcx.hir_node_by_def_id(id)) | ||
| } | ||
| }; | ||
| if let Some(hir_node) = hir_node { | ||
| if let Some(body_id) = hir_node.body_id() { | ||
| let body_span = tcx.hir_body(body_id).value.span; | ||
|
|
||
| err.multipart_suggestion( | ||
|
|
@@ -3177,10 +3181,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | |
| ], | ||
| Applicability::MaybeIncorrect, | ||
| ); | ||
| } else if let DefKind::AssocConst = tcx.def_kind(def_id) | ||
| && let DefKind::Trait = tcx.def_kind(tcx.parent(def_id)) | ||
| { | ||
| let node = tcx.hir_node_by_def_id(local_def_id).expect_trait_item(); | ||
| } else if let ty::AliasConstKind::Projection { .. } = alias_const { | ||
| let node = hir_node.expect_trait_item(); | ||
| let sp = node.span.shrink_to_lo(); | ||
| err.span_suggestion_verbose( | ||
| sp, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| //@ check-pass | ||
| //! rustc_hir_analysis::check_item_type does type_of() on the default value. This is wonky, because | ||
| //! the generic args are in Self format at that point, not in impl format, so the result can't be | ||
| //! used with the Self-format args. However, it does not instantiate the result, it just does | ||
| //! ensure_ok(). This test just makes sure that codepath is hit in tests. | ||
| #![feature(min_generic_const_args, inherent_associated_types)] | ||
|
|
||
| struct Struct<T1, T2, T3>(T1, T2, T3); | ||
| impl<T1, T2, T3> Struct<T1, T2, T3> { | ||
| const INHERENT: usize = core::direct_const_arg!(2); | ||
| } | ||
|
|
||
| struct WithDefault<const N: usize = { core::direct_const_arg!(Struct::<u8, u16, u32>::INHERENT) }>; | ||
|
|
||
| fn main() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is inherent impl reachable here? the type from
const_param_defaultought to be unnormalized and so inInherentSelfformUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is unreachable. it is from
const_param_default->lower_const_arg->lower_type_relative_const_path->blah blah unnormalized. the rest are reachable though (at first I was like "can't it only be anons?" but no it can be directly represented paths too)