Stream: t-compiler/rust-analyzer

Topic: `BuiltinType` -> `hir::Type`


Jonas Schievink [he/him] (Feb 11 2021 at 17:43, on Zulip):

Is there a way to go from a BuiltinType to an hir::Type in the IDE crates? I can't seem to find any

matklad (Feb 11 2021 at 17:44, on Zulip):

I wonder if there should be a way? Maybe whiever thing gave you BuiltinType should have handed Type in the first place?

matklad (Feb 11 2021 at 17:44, on Zulip):

Seems easier if ther's only one type

Jonas Schievink [he/him] (Feb 11 2021 at 17:48, on Zulip):

So it'd be ModuleDef::BuiltinType(Type)?

Florian Diebold (Feb 11 2021 at 17:49, on Zulip):

hm no... it might make sense to have a ModuleDef::ty()

Jonas Schievink [he/him] (Feb 11 2021 at 17:50, on Zulip):

hmm, how does Type currently represent builtin types? they have no defining crate, but Type requires one

matklad (Feb 11 2021 at 17:51, on Zulip):

Yeah, I feel it should be ModuleDef::BuildinType(code_model::something)

Florian Diebold (Feb 11 2021 at 17:52, on Zulip):

the krate doesn't need to be the defining one I think, rather the one where the type currently 'lives'

matklad (Feb 11 2021 at 17:52, on Zulip):

where something can be either Adt (i32 is structy) or a dedicated BuildInType with a .ty() method

Florian Diebold (Feb 11 2021 at 17:54, on Zulip):

I'm pretty sure the current Type isn't the ideal abstraction, but I'm not sure how to do it better :grimacing:

Jonas Schievink [he/him] (Feb 11 2021 at 17:59, on Zulip):

"where the type currently 'lives'"? so the crate from which the type is used?

Florian Diebold (Feb 11 2021 at 17:59, on Zulip):

assuming this is about the completion issue, it should be the crate and trait environment from the place where we're completing

Florian Diebold (Feb 11 2021 at 18:00, on Zulip):

i.e. you'd use Type::new_with_resolver to create it with the resolver from there

Jonas Schievink [he/him] (Feb 11 2021 at 18:02, on Zulip):

the other code paths seem to use the defining crate

Florian Diebold (Feb 11 2021 at 18:03, on Zulip):

the other code paths are "give me the type in the environment of its definition"

Jonas Schievink [he/him] (Feb 11 2021 at 18:04, on Zulip):

hmm, only for obtaining the initial Type though

Jonas Schievink [he/him] (Feb 11 2021 at 18:04, on Zulip):

and then the current crate is passed later

Florian Diebold (Feb 11 2021 at 18:05, on Zulip):

it probably doesn't really matter much what you use in this case

Florian Diebold (Feb 11 2021 at 18:07, on Zulip):

although, we do need the crate to find impls, so it does matter somewhat

Jonas Schievink [he/him] (Feb 11 2021 at 18:53, on Zulip):

not terribly happy with this but it seems to work https://github.com/rust-analyzer/rust-analyzer/pull/7644

Last update: Jul 26 2021 at 14:00UTC