From bb6e1bf811bce09fdab115a4257e47cc0d5ddc82 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 24 Mar 2021 17:00:29 +0100 Subject: Lower traits to TraitRef instead of TypeRef --- crates/hir_def/src/type_ref.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'crates/hir_def/src/type_ref.rs') diff --git a/crates/hir_def/src/type_ref.rs b/crates/hir_def/src/type_ref.rs index 049b2e462..b7484ed0d 100644 --- a/crates/hir_def/src/type_ref.rs +++ b/crates/hir_def/src/type_ref.rs @@ -51,6 +51,25 @@ impl Rawness { } } +#[derive(Clone, PartialEq, Eq, Hash, Debug)] +pub enum TraitRef { + Path(Path), + Error, +} + +impl TraitRef { + /// Converts an `ast::PathType` to a `hir::TraitRef`. + pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::Type) -> Self { + // FIXME: Use `Path::from_src` + match node { + ast::Type::PathType(path) => path + .path() + .and_then(|it| ctx.lower_path(it)) + .map_or(TraitRef::Error, TraitRef::Path), + _ => TraitRef::Error, + } + } +} /// Compare ty::Ty #[derive(Clone, PartialEq, Eq, Hash, Debug)] pub enum TypeRef { -- cgit v1.2.3