Skip to content

Commit 8a9a1e3

Browse files
Remove all upcasts!
It turns out there were a lot redundant too.
1 parent a775d21 commit 8a9a1e3

Some content is hidden

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

80 files changed

+1009
-1257
lines changed

crates/base-db/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ macro_rules! impl_intern_key {
4343
};
4444
}
4545

46-
pub trait Upcast<T: ?Sized> {
47-
fn upcast(&self) -> &T;
48-
}
49-
5046
pub const DEFAULT_FILE_TEXT_LRU_CAP: u16 = 16;
5147
pub const DEFAULT_PARSE_LRU_CAP: u16 = 128;
5248
pub const DEFAULT_BORROWCK_LRU_CAP: u16 = 2024;

crates/hir-def/src/attr.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl Attrs {
4646
}
4747

4848
pub(crate) fn filter(db: &dyn DefDatabase, krate: Crate, raw_attrs: RawAttrs) -> Attrs {
49-
Attrs(raw_attrs.filter(db.upcast(), krate))
49+
Attrs(raw_attrs.filter(db, krate))
5050
}
5151
}
5252

@@ -507,7 +507,7 @@ impl AttrsWithOwner {
507507
// FIXME: We should be never getting `None` here.
508508
match src.value.get(it.local_id()) {
509509
Some(val) => RawAttrs::from_attrs_owner(
510-
db.upcast(),
510+
db,
511511
src.with_value(val),
512512
db.span_map(src.file_id).as_ref(),
513513
),
@@ -519,7 +519,7 @@ impl AttrsWithOwner {
519519
// FIXME: We should be never getting `None` here.
520520
match src.value.get(it.local_id()) {
521521
Some(val) => RawAttrs::from_attrs_owner(
522-
db.upcast(),
522+
db,
523523
src.with_value(val),
524524
db.span_map(src.file_id).as_ref(),
525525
),
@@ -531,7 +531,7 @@ impl AttrsWithOwner {
531531
// FIXME: We should be never getting `None` here.
532532
match src.value.get(it.local_id) {
533533
Some(val) => RawAttrs::from_attrs_owner(
534-
db.upcast(),
534+
db,
535535
src.with_value(val),
536536
db.span_map(src.file_id).as_ref(),
537537
),
@@ -544,7 +544,7 @@ impl AttrsWithOwner {
544544
AttrDefId::UseId(it) => attrs_from_item_tree_loc(db, it),
545545
};
546546

547-
let attrs = raw_attrs.filter(db.upcast(), def.krate(db));
547+
let attrs = raw_attrs.filter(db, def.krate(db));
548548
Attrs(attrs)
549549
}
550550

crates/hir-def/src/db.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Defines database & queries for name resolution.
2-
use base_db::{Crate, RootQueryDb, SourceDatabase, Upcast};
2+
use base_db::{Crate, RootQueryDb, SourceDatabase};
33
use either::Either;
44
use hir_expand::{HirFileId, MacroDefId, db::ExpandDatabase};
55
use intern::sym;
@@ -100,13 +100,7 @@ pub trait InternDatabase: RootQueryDb {
100100
}
101101

102102
#[query_group::query_group]
103-
pub trait DefDatabase:
104-
InternDatabase
105-
+ ExpandDatabase
106-
+ SourceDatabase
107-
+ Upcast<dyn ExpandDatabase>
108-
+ Upcast<dyn RootQueryDb>
109-
{
103+
pub trait DefDatabase: InternDatabase + ExpandDatabase + SourceDatabase {
110104
/// Whether to expand procedural macros during name resolution.
111105
#[salsa::input]
112106
fn expand_proc_attr_macros(&self) -> bool;
@@ -381,7 +375,7 @@ fn include_macro_invoc(
381375
.flat_map(|m| m.scope.iter_macro_invoc())
382376
.filter_map(|invoc| {
383377
db.lookup_intern_macro_call(*invoc.1)
384-
.include_file_id(db.upcast(), *invoc.1)
378+
.include_file_id(db, *invoc.1)
385379
.map(|x| (*invoc.1, x))
386380
})
387381
.collect()

crates/hir-def/src/expr_store/expander.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl Expander {
7272
krate: Crate,
7373
has_attrs: &dyn HasAttrs,
7474
) -> Attrs {
75-
Attrs::filter(db, krate, RawAttrs::new(db.upcast(), has_attrs, self.span_map.as_ref()))
75+
Attrs::filter(db, krate, RawAttrs::new(db, has_attrs, self.span_map.as_ref()))
7676
}
7777

7878
pub(super) fn is_cfg_enabled(
@@ -103,7 +103,7 @@ impl Expander {
103103
let result = self.within_limit(db, |this| {
104104
let macro_call = this.in_file(&macro_call);
105105
match macro_call.as_call_id_with_errors(
106-
db.upcast(),
106+
db,
107107
krate,
108108
|path| resolver(path).map(|it| db.macro_def(it)),
109109
eager_callback,
@@ -178,7 +178,7 @@ impl Expander {
178178
self.recursion_depth = u32::MAX;
179179
cov_mark::hit!(your_stack_belongs_to_me);
180180
return ExpandResult::only_err(ExpandError::new(
181-
db.macro_arg_considering_derives(call_id, &call_id.lookup(db.upcast()).kind).2,
181+
db.macro_arg_considering_derives(call_id, &call_id.lookup(db).kind).2,
182182
ExpandErrorKind::RecursionOverflow,
183183
));
184184
}

crates/hir-def/src/expr_store/lower/path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub(super) fn lower_path(
7878
return None;
7979
}
8080
break kind = resolve_crate_root(
81-
collector.db.upcast(),
81+
collector.db,
8282
collector.expander.ctx_for_range(name_ref.syntax().text_range()),
8383
)
8484
.map(PathKind::DollarCrate)
@@ -216,7 +216,7 @@ pub(super) fn lower_path(
216216
let syn_ctxt = collector.expander.ctx_for_range(path.segment()?.syntax().text_range());
217217
if let Some(macro_call_id) = syn_ctxt.outer_expn(collector.db) {
218218
if collector.db.lookup_intern_macro_call(macro_call_id).def.local_inner {
219-
kind = match resolve_crate_root(collector.db.upcast(), syn_ctxt) {
219+
kind = match resolve_crate_root(collector.db, syn_ctxt) {
220220
Some(crate_root) => PathKind::DollarCrate(crate_root),
221221
None => PathKind::Crate,
222222
}

crates/hir-def/src/expr_store/pretty.rs

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,18 @@ pub(crate) fn print_body_hir(
5353
edition: Edition,
5454
) -> String {
5555
let header = match owner {
56-
DefWithBodyId::FunctionId(it) => it
57-
.lookup(db)
58-
.id
59-
.resolved(db, |it| format!("fn {}", it.name.display(db.upcast(), edition))),
56+
DefWithBodyId::FunctionId(it) => {
57+
it.lookup(db).id.resolved(db, |it| format!("fn {}", it.name.display(db, edition)))
58+
}
6059
DefWithBodyId::StaticId(it) => it
6160
.lookup(db)
6261
.id
63-
.resolved(db, |it| format!("static {} = ", it.name.display(db.upcast(), edition))),
62+
.resolved(db, |it| format!("static {} = ", it.name.display(db, edition))),
6463
DefWithBodyId::ConstId(it) => it.lookup(db).id.resolved(db, |it| {
6564
format!(
6665
"const {} = ",
6766
match &it.name {
68-
Some(name) => name.display(db.upcast(), edition).to_string(),
67+
Some(name) => name.display(db, edition).to_string(),
6968
None => "_".to_owned(),
7069
}
7170
)
@@ -75,8 +74,8 @@ pub(crate) fn print_body_hir(
7574
let enum_loc = loc.parent.lookup(db);
7675
format!(
7776
"enum {}::{}",
78-
enum_loc.id.item_tree(db)[enum_loc.id.value].name.display(db.upcast(), edition),
79-
loc.id.item_tree(db)[loc.id.value].name.display(db.upcast(), edition),
77+
enum_loc.id.item_tree(db)[enum_loc.id.value].name.display(db, edition),
78+
loc.id.item_tree(db)[loc.id.value].name.display(db, edition),
8079
)
8180
}
8281
};
@@ -162,7 +161,7 @@ pub(crate) fn print_struct(
162161
wln!(p, "#[fundamental]");
163162
}
164163
w!(p, "struct ");
165-
w!(p, "{}", name.display(db.upcast(), edition));
164+
w!(p, "{}", name.display(db, edition));
166165
print_generic_params(db, generic_params, &mut p);
167166
match shape {
168167
FieldsShape::Record => wln!(p, " {{...}}"),
@@ -219,7 +218,7 @@ pub(crate) fn print_function(
219218
w!(p, "extern \"{}\" ", abi.as_str());
220219
}
221220
w!(p, "fn ");
222-
w!(p, "{}", name.display(db.upcast(), edition));
221+
w!(p, "{}", name.display(db, edition));
223222
print_generic_params(db, generic_params, &mut p);
224223
w!(p, "(");
225224
for (i, param) in params.iter().enumerate() {
@@ -260,7 +259,7 @@ fn print_where_clauses(db: &dyn DefDatabase, generic_params: &GenericParams, p:
260259
}
261260
WherePredicateTypeTarget::TypeOrConstParam(idx) => {
262261
match generic_params[*idx].name() {
263-
Some(name) => w!(p, "{}", name.display(db.upcast(), p.edition)),
262+
Some(name) => w!(p, "{}", name.display(db, p.edition)),
264263
None => w!(p, "Param[{}]", idx.into_raw()),
265264
}
266265
w!(p, ": ");
@@ -278,7 +277,7 @@ fn print_where_clauses(db: &dyn DefDatabase, generic_params: &GenericParams, p:
278277
if i != 0 {
279278
w!(p, ", ");
280279
}
281-
w!(p, "{}", lifetime.display(db.upcast(), p.edition));
280+
w!(p, "{}", lifetime.display(db, p.edition));
282281
}
283282
w!(p, "> ");
284283
match target {
@@ -289,7 +288,7 @@ fn print_where_clauses(db: &dyn DefDatabase, generic_params: &GenericParams, p:
289288
}
290289
WherePredicateTypeTarget::TypeOrConstParam(idx) => {
291290
match generic_params[*idx].name() {
292-
Some(name) => w!(p, "{}", name.display(db.upcast(), p.edition)),
291+
Some(name) => w!(p, "{}", name.display(db, p.edition)),
293292
None => w!(p, "Param[{}]", idx.into_raw()),
294293
}
295294
w!(p, ": ");
@@ -313,15 +312,15 @@ fn print_generic_params(db: &dyn DefDatabase, generic_params: &GenericParams, p:
313312
w!(p, ", ");
314313
}
315314
first = false;
316-
w!(p, "{}", param.name.display(db.upcast(), p.edition));
315+
w!(p, "{}", param.name.display(db, p.edition));
317316
}
318317
for (i, param) in generic_params.iter_type_or_consts() {
319318
if !first {
320319
w!(p, ", ");
321320
}
322321
first = false;
323322
if let Some(const_param) = param.const_param() {
324-
w!(p, "const {}: ", const_param.name.display(db.upcast(), p.edition));
323+
w!(p, "const {}: ", const_param.name.display(db, p.edition));
325324
p.print_type_ref(const_param.ty);
326325
if let Some(default) = const_param.default {
327326
w!(p, " = ");
@@ -330,7 +329,7 @@ fn print_generic_params(db: &dyn DefDatabase, generic_params: &GenericParams, p:
330329
}
331330
if let Some(type_param) = param.type_param() {
332331
match &type_param.name {
333-
Some(name) => w!(p, "{}", name.display(db.upcast(), p.edition)),
332+
Some(name) => w!(p, "{}", name.display(db, p.edition)),
334333
None => w!(p, "Param[{}]", i.into_raw()),
335334
}
336335
if let Some(default) = type_param.default {
@@ -476,7 +475,7 @@ impl Printer<'_> {
476475
offset_of
477476
.fields
478477
.iter()
479-
.format_with(".", |field, f| f(&field.display(self.db.upcast(), edition)))
478+
.format_with(".", |field, f| f(&field.display(self.db, edition)))
480479
);
481480
}
482481
Expr::Path(path) => self.print_path(path),
@@ -498,7 +497,7 @@ impl Printer<'_> {
498497
}
499498
Expr::Loop { body, label } => {
500499
if let Some(lbl) = label {
501-
w!(self, "{}: ", self.store[*lbl].name.display(self.db.upcast(), self.edition));
500+
w!(self, "{}: ", self.store[*lbl].name.display(self.db, self.edition));
502501
}
503502
w!(self, "loop ");
504503
self.print_expr(*body);
@@ -518,7 +517,7 @@ impl Printer<'_> {
518517
}
519518
Expr::MethodCall { receiver, method_name, args, generic_args } => {
520519
self.print_expr(*receiver);
521-
w!(self, ".{}", method_name.display(self.db.upcast(), self.edition));
520+
w!(self, ".{}", method_name.display(self.db, self.edition));
522521
if let Some(args) = generic_args {
523522
w!(self, "::<");
524523
self.print_generic_args(args);
@@ -556,13 +555,13 @@ impl Printer<'_> {
556555
Expr::Continue { label } => {
557556
w!(self, "continue");
558557
if let Some(lbl) = label {
559-
w!(self, " {}", self.store[*lbl].name.display(self.db.upcast(), self.edition));
558+
w!(self, " {}", self.store[*lbl].name.display(self.db, self.edition));
560559
}
561560
}
562561
Expr::Break { expr, label } => {
563562
w!(self, "break");
564563
if let Some(lbl) = label {
565-
w!(self, " {}", self.store[*lbl].name.display(self.db.upcast(), self.edition));
564+
w!(self, " {}", self.store[*lbl].name.display(self.db, self.edition));
566565
}
567566
if let Some(expr) = expr {
568567
self.whitespace();
@@ -607,7 +606,7 @@ impl Printer<'_> {
607606
let edition = self.edition;
608607
self.indented(|p| {
609608
for field in &**fields {
610-
w!(p, "{}: ", field.name.display(self.db.upcast(), edition));
609+
w!(p, "{}: ", field.name.display(self.db, edition));
611610
p.print_expr(field.expr);
612611
wln!(p, ",");
613612
}
@@ -621,7 +620,7 @@ impl Printer<'_> {
621620
}
622621
Expr::Field { expr, name } => {
623622
self.print_expr(*expr);
624-
w!(self, ".{}", name.display(self.db.upcast(), self.edition));
623+
w!(self, ".{}", name.display(self.db, self.edition));
625624
}
626625
Expr::Await { expr } => {
627626
self.print_expr(*expr);
@@ -760,7 +759,7 @@ impl Printer<'_> {
760759
Expr::Literal(lit) => self.print_literal(lit),
761760
Expr::Block { id: _, statements, tail, label } => {
762761
let label = label.map(|lbl| {
763-
format!("{}: ", self.store[lbl].name.display(self.db.upcast(), self.edition))
762+
format!("{}: ", self.store[lbl].name.display(self.db, self.edition))
764763
});
765764
self.print_block(label.as_deref(), statements, tail);
766765
}
@@ -846,7 +845,7 @@ impl Printer<'_> {
846845
let oneline = matches!(self.line_format, LineFormat::Oneline);
847846
self.indented(|p| {
848847
for (idx, arg) in args.iter().enumerate() {
849-
let field_name = arg.name.display(self.db.upcast(), edition).to_string();
848+
let field_name = arg.name.display(self.db, edition).to_string();
850849

851850
let mut same_name = false;
852851
if let Pat::Bind { id, subpat: None } = &self.store[arg.pat] {
@@ -1019,7 +1018,7 @@ impl Printer<'_> {
10191018
BindingAnnotation::Ref => "ref ",
10201019
BindingAnnotation::RefMut => "ref mut ",
10211020
};
1022-
w!(self, "{}{}", mode, name.display(self.db.upcast(), self.edition));
1021+
w!(self, "{}{}", mode, name.display(self.db, self.edition));
10231022
}
10241023

10251024
fn print_path(&mut self, path: &Path) {
@@ -1030,7 +1029,7 @@ impl Printer<'_> {
10301029
let loc = $it.lookup(self.db);
10311030
let tree = loc.item_tree_id().item_tree(self.db);
10321031
let name = &tree[loc.id.value].name;
1033-
w!(self, "{}", name.display(self.db.upcast(), self.edition));
1032+
w!(self, "{}", name.display(self.db, self.edition));
10341033
}};
10351034
}
10361035
match *it {
@@ -1046,7 +1045,7 @@ impl Printer<'_> {
10461045
}
10471046

10481047
if let Some(s) = s {
1049-
w!(self, "::{}", s.display(self.db.upcast(), self.edition));
1048+
w!(self, "::{}", s.display(self.db, self.edition));
10501049
}
10511050
return w!(self, ")");
10521051
}
@@ -1088,7 +1087,7 @@ impl Printer<'_> {
10881087
w!(self, "::");
10891088
}
10901089

1091-
w!(self, "{}", segment.name.display(self.db.upcast(), self.edition));
1090+
w!(self, "{}", segment.name.display(self.db, self.edition));
10921091
if let Some(generics) = segment.args_and_bindings {
10931092
w!(self, "::<");
10941093
self.print_generic_args(generics);
@@ -1121,7 +1120,7 @@ impl Printer<'_> {
11211120
w!(self, ", ");
11221121
}
11231122
first = false;
1124-
w!(self, "{}", binding.name.display(self.db.upcast(), self.edition));
1123+
w!(self, "{}", binding.name.display(self.db, self.edition));
11251124
if !binding.bounds.is_empty() {
11261125
w!(self, ": ");
11271126
self.print_type_bounds(&binding.bounds);
@@ -1145,7 +1144,7 @@ impl Printer<'_> {
11451144
let generic_params = self.db.generic_params(param.parent());
11461145

11471146
match generic_params[param.local_id()].name() {
1148-
Some(name) => w!(self, "{}", name.display(self.db.upcast(), self.edition)),
1147+
Some(name) => w!(self, "{}", name.display(self.db, self.edition)),
11491148
None => w!(self, "Param[{}]", param.local_id().into_raw()),
11501149
}
11511150
}
@@ -1154,7 +1153,7 @@ impl Printer<'_> {
11541153
match lt_ref {
11551154
LifetimeRef::Static => w!(self, "'static"),
11561155
LifetimeRef::Named(lt) => {
1157-
w!(self, "{}", lt.display(self.db.upcast(), self.edition))
1156+
w!(self, "{}", lt.display(self.db, self.edition))
11581157
}
11591158
LifetimeRef::Placeholder => w!(self, "'_"),
11601159
LifetimeRef::Error => w!(self, "'{{error}}"),
@@ -1270,7 +1269,7 @@ impl Printer<'_> {
12701269
"for<{}> ",
12711270
lifetimes
12721271
.iter()
1273-
.map(|it| it.display(self.db.upcast(), self.edition))
1272+
.map(|it| it.display(self.db, self.edition))
12741273
.format(", ")
12751274
.to_string()
12761275
);
@@ -1286,7 +1285,7 @@ impl Printer<'_> {
12861285
}
12871286
match arg {
12881287
UseArgRef::Name(it) => {
1289-
w!(self, "{}", it.display(self.db.upcast(), self.edition))
1288+
w!(self, "{}", it.display(self.db, self.edition))
12901289
}
12911290
UseArgRef::Lifetime(it) => self.print_lifetime_ref(it),
12921291
}

0 commit comments

Comments
 (0)