mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-02 04:48:13 +00:00
Pass the target crate in HirFormatter
This is required to format evaluated consts, because we need trait env, and it needs the crate (currently it uses the last crate in topological order, which is wrong, the next commit will fix that).
This commit is contained in:
parent
1cd9e683e8
commit
2fc0dc0f13
62 changed files with 842 additions and 517 deletions
|
|
@ -12,7 +12,7 @@ pub(crate) fn expected_function(
|
|||
Diagnostic::new_with_syntax_node_ptr(
|
||||
ctx,
|
||||
DiagnosticCode::RustcHardError("E0618"),
|
||||
format!("expected function, found {}", d.found.display(ctx.sema.db, ctx.edition)),
|
||||
format!("expected function, found {}", d.found.display(ctx.sema.db, ctx.display_target)),
|
||||
d.call.map(|it| it.into()),
|
||||
)
|
||||
.experimental()
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ macro_rules! format_ty {
|
|||
$fmt,
|
||||
$(
|
||||
$arg
|
||||
.display($ctx.sema.db, $ctx.edition)
|
||||
.display($ctx.sema.db, $ctx.display_target)
|
||||
.with_closure_style(ClosureStyle::ClosureWithId)
|
||||
),*
|
||||
)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ pub(crate) fn moved_out_of_ref(ctx: &DiagnosticsContext<'_>, d: &hir::MovedOutOf
|
|||
Diagnostic::new_with_syntax_node_ptr(
|
||||
ctx,
|
||||
DiagnosticCode::RustcHardError("E0507"),
|
||||
format!("cannot move `{}` out of reference", d.ty.display(ctx.sema.db, ctx.edition)),
|
||||
format!("cannot move `{}` out of reference", d.ty.display(ctx.sema.db, ctx.display_target)),
|
||||
d.span,
|
||||
)
|
||||
.experimental() // spans are broken, and I'm not sure how precise we can detect copy types
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ pub(crate) fn trait_impl_redundant_assoc_item(
|
|||
(
|
||||
format!("`fn {redundant_assoc_item_name}`"),
|
||||
function.source(db).map(|it| it.syntax().text_range()).unwrap_or(default_range),
|
||||
format!("\n {};", function.display(db, ctx.edition)),
|
||||
format!("\n {};", function.display(db, ctx.display_target)),
|
||||
)
|
||||
}
|
||||
hir::AssocItem::Const(id) => {
|
||||
|
|
@ -38,7 +38,7 @@ pub(crate) fn trait_impl_redundant_assoc_item(
|
|||
(
|
||||
format!("`const {redundant_assoc_item_name}`"),
|
||||
constant.source(db).map(|it| it.syntax().text_range()).unwrap_or(default_range),
|
||||
format!("\n {};", constant.display(db, ctx.edition)),
|
||||
format!("\n {};", constant.display(db, ctx.display_target)),
|
||||
)
|
||||
}
|
||||
hir::AssocItem::TypeAlias(id) => {
|
||||
|
|
|
|||
|
|
@ -45,10 +45,10 @@ pub(crate) fn type_mismatch(ctx: &DiagnosticsContext<'_>, d: &hir::TypeMismatch)
|
|||
format!(
|
||||
"expected {}, found {}",
|
||||
d.expected
|
||||
.display(ctx.sema.db, ctx.edition)
|
||||
.display(ctx.sema.db, ctx.display_target)
|
||||
.with_closure_style(ClosureStyle::ClosureWithId),
|
||||
d.actual
|
||||
.display(ctx.sema.db, ctx.edition)
|
||||
.display(ctx.sema.db, ctx.display_target)
|
||||
.with_closure_style(ClosureStyle::ClosureWithId),
|
||||
),
|
||||
display_range,
|
||||
|
|
@ -306,8 +306,8 @@ fn str_ref_to_owned(
|
|||
expr_ptr: &InFile<AstPtr<ast::Expr>>,
|
||||
acc: &mut Vec<Assist>,
|
||||
) -> Option<()> {
|
||||
let expected = d.expected.display(ctx.sema.db, ctx.edition);
|
||||
let actual = d.actual.display(ctx.sema.db, ctx.edition);
|
||||
let expected = d.expected.display(ctx.sema.db, ctx.display_target);
|
||||
let actual = d.actual.display(ctx.sema.db, ctx.display_target);
|
||||
|
||||
// FIXME do this properly
|
||||
if expected.to_string() != "String" || actual.to_string() != "&str" {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ pub(crate) fn typed_hole(ctx: &DiagnosticsContext<'_>, d: &hir::TypedHole) -> Di
|
|||
format!(
|
||||
"invalid `_` expression, expected type `{}`",
|
||||
d.expected
|
||||
.display(ctx.sema.db, ctx.edition)
|
||||
.display(ctx.sema.db, ctx.display_target)
|
||||
.with_closure_style(ClosureStyle::ClosureWithId),
|
||||
),
|
||||
fixes(ctx, d),
|
||||
|
|
@ -72,7 +72,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::TypedHole) -> Option<Vec<Assist>
|
|||
prefer_absolute: ctx.config.prefer_absolute,
|
||||
allow_unstable: ctx.is_nightly,
|
||||
},
|
||||
ctx.edition,
|
||||
ctx.display_target,
|
||||
)
|
||||
.ok()
|
||||
})
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ pub(crate) fn unresolved_field(
|
|||
format!(
|
||||
"no field `{}` on type `{}`{method_suffix}",
|
||||
d.name.display(ctx.sema.db, ctx.edition),
|
||||
d.receiver.display(ctx.sema.db, ctx.edition)
|
||||
d.receiver.display(ctx.sema.db, ctx.display_target)
|
||||
),
|
||||
adjusted_display_range(ctx, d.expr, &|expr| {
|
||||
Some(
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ pub(crate) fn unresolved_method(
|
|||
format!(
|
||||
"no method `{}` on type `{}`{suffix}",
|
||||
d.name.display(ctx.sema.db, ctx.edition),
|
||||
d.receiver.display(ctx.sema.db, ctx.edition)
|
||||
d.receiver.display(ctx.sema.db, ctx.display_target)
|
||||
),
|
||||
adjusted_display_range(ctx, d.expr, &|expr| {
|
||||
Some(
|
||||
|
|
@ -152,7 +152,7 @@ fn assoc_func_fix(ctx: &DiagnosticsContext<'_>, d: &hir::UnresolvedMethodCall) -
|
|||
receiver_type.as_adt()?.name(db).display_no_db(ctx.edition).to_smolstr();
|
||||
|
||||
let generic_parameters: Vec<SmolStr> =
|
||||
receiver_type.generic_parameters(db, ctx.edition).collect();
|
||||
receiver_type.generic_parameters(db, ctx.display_target).collect();
|
||||
// if receiver should be pass as first arg in the assoc func,
|
||||
// we could omit generic parameters cause compiler can deduce it automatically
|
||||
if !need_to_take_receiver_as_first_arg && !generic_parameters.is_empty() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue