Stream: t-compiler/rust-analyzer

Topic: Why isn’t Name optional?


Aramis Razzaghipour (Jan 14 2021 at 00:21, on Zulip):

The name field of items from item_tree.rs is never an Option<Name>. Why is this? When lowering to HIR from AST, the name could be missing from the AST. Take Struct as an example: lower::Ctx::lower_struct returns an Option<FileItemTreeId<Struct>>, and only returns None if the name is not present in the AST. Why not salvage the lowering and make name optional, rather than throwing the entire Struct away?

Jonas Schievink [he/him] (Jan 14 2021 at 01:22, on Zulip):

What could we do with that struct?

Aramis Razzaghipour (Jan 14 2021 at 03:54, on Zulip):

I’m not sure, it just seems better not to throw away data. I guess it isn’t really useful though.

matklad (Jan 15 2021 at 09:31, on Zulip):

yeah, the situation with optionality of names is a mess

matklad (Jan 15 2021 at 09:32, on Zulip):

ther's also Name::missing, so even a non-optional name might not be there

matklad (Jan 15 2021 at 09:33, on Zulip):

I think we should probably keep this simple -- remove the missing and options, and just through the defs away when the ast doesn't have a name

matklad (Jan 15 2021 at 09:35, on Zulip):

the way the parser works, it the name's missing, there's probably little else in the def anyways

matklad (Jan 15 2021 at 09:37, on Zulip):

Hm, @Jonas Schievink , I think I've just found a pile of dead code!

matklad (Jan 15 2021 at 09:38, on Zulip):

Take a look at lower_enum in adt.rs

matklad (Jan 15 2021 at 09:38, on Zulip):

The

matklad (Jan 15 2021 at 09:38, on Zulip):
            || EnumVariantData {
                name: var.name().map_or_else(Name::missing, |it| it.as_name()),
                variant_data: Arc::new(VariantData::new(db, ast.with_value(var.kind()), module_id)),
            },

bit I think is dead -- this is now handled by item tree?

matklad (Jan 15 2021 at 09:39, on Zulip):

I wonder if the whole Trace infra can be removed?

Last update: Jul 26 2021 at 12:30UTC