Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 363d158

Browse files
authoredMay 9, 2023
Rollup merge of #111215 - BoxyUwU:resolve_anon_consts_differently, r=cjgillot
Various changes to name resolution of anon consts Sorry this PR is kind of all over the place ^^' Fixes #111012 - Rewrites anon const nameres to all go through `fn resolve_anon_const` explicitly instead of `visit_anon_const` to ensure that we do not accidentally resolve anon consts as if they are allowed to use generics when they aren't. Also means that we dont have bits of code for resolving anon consts that will get out of sync (i.e. legacy const generics and resolving path consts that were parsed as type arguments) - Renames two of the `LifetimeRibKind`, `AnonConst -> ConcreteAnonConst` and `ConstGeneric -> ConstParamTy` - Noticed while doing this that under `generic_const_exprs` all lifetimes currently get resolved to errors without any error being emitted which was causing a bunch of tests to pass without their bugs having been fixed, incidentally fixed that in this PR and marked those tests as `// known-bug:`. I'm fine to break those since `generic_const_exprs` is a very unstable incomplete feature and this PR _does_ make generic_const_exprs "less broken" as a whole, also I can't be assed to figure out what the underlying causes of all of them are. This PR reopens #77357 #83993 - Changed `generics_of` to stop providing generics and predicates to enum variant discriminant anon consts since those are not allowed to use generic parameters - Updated the error for non 'static lifetime in const arguments and the error for non 'static lifetime in const param tys to use `derive(Diagnostic)` I have a vague idea why const-arg-in-const-arg.rs, in-closure.rs and simple.rs have started failing which is unfortunate since these were deliberately made to work, I think lifetime resolution being broken just means this regressed at some point and nobody noticed because the tests were not testing anything :( I'm fine breaking these too for the same reason as the tests for #77357 #83993. I couldn't get `// known-bug` to work for these ICEs and just kept getting different stderr between CI and local `--bless` so I just removed them and will create an issue to track re-adding (and fixing) the bugs if this PR lands. r? `@cjgillot` cc `@compiler-errors`
2 parents 985ea22 + 73b3ce2 commit 363d158

File tree

70 files changed

+846
-614
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+846
-614
lines changed
 

‎compiler/rustc_ast/src/ast.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ impl Path {
120120
pub fn is_global(&self) -> bool {
121121
!self.segments.is_empty() && self.segments[0].ident.name == kw::PathRoot
122122
}
123+
124+
/// If this path is a single identifier with no arguments, does not ensure
125+
/// that the path resolves to a const param, the caller should check this.
126+
pub fn is_potential_trivial_const_arg(&self) -> bool {
127+
self.segments.len() == 1 && self.segments[0].args.is_none()
128+
}
123129
}
124130

125131
/// A segment of a path: an identifier, an optional lifetime, and a set of types.
@@ -1154,7 +1160,9 @@ impl Expr {
11541160
///
11551161
/// If this is not the case, name resolution does not resolve `N` when using
11561162
/// `min_const_generics` as more complex expressions are not supported.
1157-
pub fn is_potential_trivial_const_param(&self) -> bool {
1163+
///
1164+
/// Does not ensure that the path resolves to a const param, the caller should check this.
1165+
pub fn is_potential_trivial_const_arg(&self) -> bool {
11581166
let this = if let ExprKind::Block(block, None) = &self.kind
11591167
&& block.stmts.len() == 1
11601168
&& let StmtKind::Expr(expr) = &block.stmts[0].kind
@@ -1165,8 +1173,7 @@ impl Expr {
11651173
};
11661174

11671175
if let ExprKind::Path(None, path) = &this.kind
1168-
&& path.segments.len() == 1
1169-
&& path.segments[0].args.is_none()
1176+
&& path.is_potential_trivial_const_arg()
11701177
{
11711178
true
11721179
} else {

‎compiler/rustc_ast/src/visit.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ pub trait Visitor<'ast>: Sized {
188188
fn visit_variant(&mut self, v: &'ast Variant) {
189189
walk_variant(self, v)
190190
}
191+
fn visit_variant_discr(&mut self, discr: &'ast AnonConst) {
192+
self.visit_anon_const(discr);
193+
}
191194
fn visit_label(&mut self, label: &'ast Label) {
192195
walk_label(self, label)
193196
}
@@ -380,7 +383,7 @@ where
380383
visitor.visit_ident(variant.ident);
381384
visitor.visit_vis(&variant.vis);
382385
visitor.visit_variant_data(&variant.data);
383-
walk_list!(visitor, visit_anon_const, &variant.disr_expr);
386+
walk_list!(visitor, visit_variant_discr, &variant.disr_expr);
384387
walk_list!(visitor, visit_attribute, &variant.attrs);
385388
}
386389

0 commit comments

Comments
 (0)
Please sign in to comment.