Handle parenthesised infer args
This commit is contained in:
parent
1983c437ce
commit
c58fe21cb9
3 changed files with 32 additions and 6 deletions
|
@ -288,6 +288,7 @@ impl ParenthesizedArgs {
|
|||
}
|
||||
}
|
||||
|
||||
use crate::AstDeref;
|
||||
pub use crate::node_id::{CRATE_NODE_ID, DUMMY_NODE_ID, NodeId};
|
||||
|
||||
/// Modifiers on a trait bound like `~const`, `?` and `!`.
|
||||
|
@ -2166,6 +2167,14 @@ impl Ty {
|
|||
}
|
||||
final_ty
|
||||
}
|
||||
|
||||
pub fn is_maybe_parenthesised_infer(&self) -> bool {
|
||||
match &self.kind {
|
||||
TyKind::Infer => true,
|
||||
TyKind::Paren(inner) => inner.ast_deref().is_maybe_parenthesised_infer(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
|
|
|
@ -1084,17 +1084,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
match arg {
|
||||
ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(lt)),
|
||||
ast::GenericArg::Type(ty) => {
|
||||
match &ty.kind {
|
||||
TyKind::Infer => {
|
||||
// We cannot just match on `TyKind::Infer` as `(_)` is represented as
|
||||
// `TyKind::Paren(TyKind::Infer)` and should also be lowered to `GenericArg::Infer`
|
||||
if ty.is_maybe_parenthesised_infer() {
|
||||
return GenericArg::Infer(hir::InferArg {
|
||||
hir_id: self.lower_node_id(ty.id),
|
||||
span: self.lower_span(ty.span),
|
||||
});
|
||||
}
|
||||
|
||||
match &ty.kind {
|
||||
// We parse const arguments as path types as we cannot distinguish them during
|
||||
// parsing. We try to resolve that ambiguity by attempting resolution in both the
|
||||
// type and value namespaces. If we resolved the path in the value namespace, we
|
||||
// transform it into a generic const argument.
|
||||
//
|
||||
// FIXME: Should we be handling `(PATH_TO_CONST)`?
|
||||
TyKind::Path(None, path) => {
|
||||
if let Some(res) = self
|
||||
.resolver
|
||||
|
|
12
tests/ui/const-generics/generic_arg_infer/parend_infer.rs
Normal file
12
tests/ui/const-generics/generic_arg_infer/parend_infer.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
//@ check-pass
|
||||
//@ revisions: gate nogate
|
||||
#![cfg_attr(gate, feature(generic_arg_infer))]
|
||||
|
||||
fn main() {
|
||||
// AST Types preserve parens for pretty printing reasons. This means
|
||||
// that this is parsed as a `TyKind::Paren(TyKind::Infer)`. Generic
|
||||
// arg lowering therefore needs to take into account not just `TyKind::Infer`
|
||||
// but `TyKind::Infer` wrapped in arbitrarily many `TyKind::Paren`.
|
||||
let a: Vec<(_)> = vec![1_u8];
|
||||
let a: Vec<(((((_)))))> = vec![1_u8];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue