Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/tools/rust-analyzer/.github/workflows/rustdoc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ env:
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
RUSTFLAGS: "-D warnings -W unreachable-pub"
RUSTDOCFLAGS: "-D warnings"
RUSTUP_MAX_RETRIES: 10

jobs:
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-def/src/expr_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub use self::lower::{
hir_assoc_type_binding_to_ast, hir_generic_arg_to_ast, hir_segment_to_ast_segment,
};

/// A wrapper around [`span::SyntaxContextId`] that is intended only for comparisons.
/// A wrapper around [`span::SyntaxContext`] that is intended only for comparisons.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct HygieneId(span::SyntaxContext);

Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-def/src/hir/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub type LocalLifetimeParamId = Idx<LifetimeParamData>;
/// Data about a generic type parameter (to a function, struct, impl, ...).
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub struct TypeParamData {
/// [`None`] only if the type ref is an [`TypeRef::ImplTrait`]. FIXME: Might be better to just
/// [`None`] only if the type ref is an [`crate::type_ref::TypeRef::ImplTrait`]. FIXME: Might be better to just
/// make it always be a value, giving impl trait a special name.
pub name: Option<Name>,
pub default: Option<TypeRefId>,
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-def/src/lang_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ language_item_table! { LangItems =>
Clone, sym::clone, clone_trait, TraitId, GenericRequirement::None;
Sync, sym::sync, sync_trait, TraitId, GenericRequirement::Exact(0);
DiscriminantKind, sym::discriminant_kind, discriminant_kind_trait, TraitId, GenericRequirement::None;
/// The associated item of the [`DiscriminantKind`] trait.
/// The associated item of the `DiscriminantKind` trait.
Discriminant, sym::discriminant_type, discriminant_type, TypeAliasId, GenericRequirement::None;

PointeeTrait, sym::pointee_trait, pointee_trait, TraitId, GenericRequirement::None;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-def/src/nameres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ impl ModuleData {
self.origin.definition_source(db)
}

/// Same as [`definition_source`] but only returns the file id to prevent parsing the ASt.
/// Same as [`ModuleData::definition_source`] but only returns the file id to prevent parsing the ASt.
pub fn definition_source_file_id(&self) -> HirFileId {
match self.origin {
ModuleOrigin::File { definition, .. } | ModuleOrigin::CrateRoot { definition } => {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-expand/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ impl<SN: Borrow<SyntaxNode>> InFile<SN> {
/// Falls back to the macro call range if the node cannot be mapped up fully.
///
/// For attributes and derives, this will point back to the attribute only.
/// For the entire item use [`InFile::original_file_range_full`].
/// For the entire item use `InFile::original_file_range_full`.
pub fn original_file_range_rooted(self, db: &dyn db::ExpandDatabase) -> FileRange {
self.borrow().map(SyntaxNode::text_range).original_node_file_range_rooted(db)
}
Expand Down
8 changes: 4 additions & 4 deletions src/tools/rust-analyzer/crates/hir-expand/src/hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
//!
//! # The Expansion Order Hierarchy
//!
//! `ExpnData` in rustc, rust-analyzer's version is [`MacroCallLoc`]. Traversing the hierarchy
//! upwards can be achieved by walking up [`MacroCallLoc::kind`]'s contained file id, as
//! [`MacroFile`]s are interned [`MacroCallLoc`]s.
//! `ExpnData` in rustc, rust-analyzer's version is `MacroCallLoc`. Traversing the hierarchy
//! upwards can be achieved by walking up `MacroCallLoc::kind`'s contained file id, as
//! `MacroFile`s are interned `MacroCallLoc`s.
//!
//! # The Macro Definition Hierarchy
//!
//! `SyntaxContextData` in rustc and rust-analyzer. Basically the same in both.
//!
//! # The Call-site Hierarchy
//!
//! `ExpnData::call_site` in rustc, [`MacroCallLoc::call_site`] in rust-analyzer.
//! `ExpnData::call_site` in rustc, `MacroCallLoc::call_site` in rust-analyzer.
// FIXME: Move this into the span crate? Not quite possible today as that depends on `MacroCallLoc`
// which contains a bunch of unrelated things

Expand Down
4 changes: 3 additions & 1 deletion src/tools/rust-analyzer/crates/hir-expand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//! tree originates not from the text of some `FileId`, but from some macro
//! expansion.
#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
// It's useful to refer to code that is private in doc comments.
#![allow(rustdoc::private_intra_doc_links)]

pub use intern;

Expand Down Expand Up @@ -860,7 +862,7 @@ impl ExpansionInfo {
}

/// Maps the passed in file range down into a macro expansion if it is the input to a macro call.
/// Unlike [`map_range_down_exact`], this will consider spans that contain the given span.
/// Unlike [`ExpansionInfo::map_range_down_exact`], this will consider spans that contain the given span.
///
/// Note this does a linear search through the entire backing vector of the spanmap.
pub fn map_range_down(
Expand Down
37 changes: 18 additions & 19 deletions src/tools/rust-analyzer/crates/hir-ty/src/autoderef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ use std::fmt;
use hir_def::{TraitId, TypeAliasId};
use rustc_type_ir::inherent::{IntoKind, Ty as _};
use tracing::debug;
use triomphe::Arc;

use crate::{
TraitEnvironment,
ParamEnvAndCrate,
db::HirDatabase,
infer::InferenceContext,
next_solver::{
Expand All @@ -35,13 +34,13 @@ const AUTODEREF_RECURSION_LIMIT: usize = 20;
/// detects a cycle in the deref chain.
pub fn autoderef<'db>(
db: &'db dyn HirDatabase,
env: Arc<TraitEnvironment<'db>>,
env: ParamEnvAndCrate<'db>,
ty: Canonical<'db, Ty<'db>>,
) -> impl Iterator<Item = Ty<'db>> + use<'db> {
let interner = DbInterner::new_with(db, env.krate);
let infcx = interner.infer_ctxt().build(TypingMode::PostAnalysis);
let (ty, _) = infcx.instantiate_canonical(&ty);
let autoderef = Autoderef::new(&infcx, &env, ty);
let autoderef = Autoderef::new(&infcx, env.param_env, ty);
let mut v = Vec::new();
for (ty, _steps) in autoderef {
// `ty` may contain unresolved inference variables. Since there's no chance they would be
Expand Down Expand Up @@ -111,21 +110,21 @@ struct AutoderefTraits {
// borrows it.
pub(crate) trait AutoderefCtx<'db> {
fn infcx(&self) -> &InferCtxt<'db>;
fn env(&self) -> &TraitEnvironment<'db>;
fn param_env(&self) -> ParamEnv<'db>;
}

pub(crate) struct DefaultAutoderefCtx<'a, 'db> {
infcx: &'a InferCtxt<'db>,
env: &'a TraitEnvironment<'db>,
param_env: ParamEnv<'db>,
}
impl<'db> AutoderefCtx<'db> for DefaultAutoderefCtx<'_, 'db> {
#[inline]
fn infcx(&self) -> &InferCtxt<'db> {
self.infcx
}
#[inline]
fn env(&self) -> &TraitEnvironment<'db> {
self.env
fn param_env(&self) -> ParamEnv<'db> {
self.param_env
}
}

Expand All @@ -136,8 +135,8 @@ impl<'db> AutoderefCtx<'db> for InferenceContextAutoderefCtx<'_, '_, 'db> {
&self.0.table.infer_ctxt
}
#[inline]
fn env(&self) -> &TraitEnvironment<'db> {
&self.0.table.trait_env
fn param_env(&self) -> ParamEnv<'db> {
self.0.table.param_env
}
}

Expand Down Expand Up @@ -201,7 +200,7 @@ where
// autoderef expect this type to have been structurally normalized.
if let TyKind::Alias(..) = ty.kind() {
let (normalized_ty, obligations) =
structurally_normalize_ty(self.infcx(), self.env().env, ty)?;
structurally_normalize_ty(self.infcx(), self.param_env(), ty)?;
self.state.obligations.extend(obligations);
(AutoderefKind::Builtin, normalized_ty)
} else {
Expand Down Expand Up @@ -231,10 +230,10 @@ impl<'a, 'db> Autoderef<'a, 'db> {
#[inline]
pub(crate) fn new_with_tracking(
infcx: &'a InferCtxt<'db>,
env: &'a TraitEnvironment<'db>,
param_env: ParamEnv<'db>,
base_ty: Ty<'db>,
) -> Self {
Self::new_impl(DefaultAutoderefCtx { infcx, env }, base_ty)
Self::new_impl(DefaultAutoderefCtx { infcx, param_env }, base_ty)
}
}

Expand All @@ -257,10 +256,10 @@ impl<'a, 'db> Autoderef<'a, 'db, usize> {
#[inline]
pub(crate) fn new(
infcx: &'a InferCtxt<'db>,
env: &'a TraitEnvironment<'db>,
param_env: ParamEnv<'db>,
base_ty: Ty<'db>,
) -> Self {
Self::new_impl(DefaultAutoderefCtx { infcx, env }, base_ty)
Self::new_impl(DefaultAutoderefCtx { infcx, param_env }, base_ty)
}
}

Expand Down Expand Up @@ -292,8 +291,8 @@ where
}

#[inline]
fn env(&self) -> &TraitEnvironment<'db> {
self.ctx.env()
fn param_env(&self) -> ParamEnv<'db> {
self.ctx.param_env()
}

#[inline]
Expand Down Expand Up @@ -339,7 +338,7 @@ where

let trait_ref = TraitRef::new(interner, trait_.into(), [ty]);
let obligation =
Obligation::new(interner, ObligationCause::new(), self.env().env, trait_ref);
Obligation::new(interner, ObligationCause::new(), self.param_env(), trait_ref);
// We detect whether the self type implements `Deref` before trying to
// structurally normalize. We use `predicate_may_hold_opaque_types_jank`
// to support not-yet-defined opaque types. It will succeed for `impl Deref`
Expand All @@ -351,7 +350,7 @@ where

let (normalized_ty, obligations) = structurally_normalize_ty(
self.infcx(),
self.env().env,
self.param_env(),
Ty::new_projection(interner, trait_target.into(), [ty]),
)?;
debug!("overloaded_deref_ty({:?}) = ({:?}, {:?})", ty, normalized_ty, obligations);
Expand Down
27 changes: 17 additions & 10 deletions src/tools/rust-analyzer/crates/hir-ty/src/consteval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod tests;

use base_db::Crate;
use hir_def::{
ConstId, EnumVariantId, GeneralConstId, StaticId,
ConstId, EnumVariantId, GeneralConstId, HasModule, StaticId,
attrs::AttrFlags,
expr_store::Body,
hir::{Expr, ExprId},
Expand All @@ -16,14 +16,14 @@ use rustc_type_ir::inherent::IntoKind;
use triomphe::Arc;

use crate::{
LifetimeElisionKind, MemoryMap, TraitEnvironment, TyLoweringContext,
LifetimeElisionKind, MemoryMap, ParamEnvAndCrate, TyLoweringContext,
db::HirDatabase,
display::DisplayTarget,
infer::InferenceContext,
mir::{MirEvalError, MirLowerError},
next_solver::{
Const, ConstBytes, ConstKind, DbInterner, ErrorGuaranteed, GenericArg, GenericArgs, Ty,
ValueConst,
Const, ConstBytes, ConstKind, DbInterner, ErrorGuaranteed, GenericArg, GenericArgs,
ParamEnv, Ty, ValueConst,
},
};

Expand Down Expand Up @@ -85,7 +85,7 @@ pub fn intern_const_ref<'a>(
krate: Crate,
) -> Const<'a> {
let interner = DbInterner::new_no_crate(db);
let layout = db.layout_of_ty(ty, TraitEnvironment::empty(krate));
let layout = db.layout_of_ty(ty, ParamEnvAndCrate { param_env: ParamEnv::empty(), krate });
let kind = match value {
LiteralConstRef::Int(i) => {
// FIXME: We should handle failure of layout better.
Expand Down Expand Up @@ -207,7 +207,7 @@ pub(crate) fn const_eval_discriminant_variant<'db>(
let mir_body = db.monomorphized_mir_body(
def,
GenericArgs::new_from_iter(interner, []),
db.trait_environment_for_body(def),
ParamEnvAndCrate { param_env: db.trait_environment_for_body(def), krate: def.krate(db) },
)?;
let c = interpret_mir(db, mir_body, false, None)?.0?;
let c = if is_signed {
Expand Down Expand Up @@ -259,7 +259,7 @@ pub(crate) fn const_eval_cycle_result<'db>(
_: &'db dyn HirDatabase,
_: ConstId,
_: GenericArgs<'db>,
_: Option<Arc<TraitEnvironment<'db>>>,
_: Option<ParamEnvAndCrate<'db>>,
) -> Result<Const<'db>, ConstEvalError<'db>> {
Err(ConstEvalError::MirLowerError(MirLowerError::Loop))
}
Expand All @@ -282,9 +282,13 @@ pub(crate) fn const_eval_query<'db>(
db: &'db dyn HirDatabase,
def: ConstId,
subst: GenericArgs<'db>,
trait_env: Option<Arc<TraitEnvironment<'db>>>,
trait_env: Option<ParamEnvAndCrate<'db>>,
) -> Result<Const<'db>, ConstEvalError<'db>> {
let body = db.monomorphized_mir_body(def.into(), subst, db.trait_environment(def.into()))?;
let body = db.monomorphized_mir_body(
def.into(),
subst,
ParamEnvAndCrate { param_env: db.trait_environment(def.into()), krate: def.krate(db) },
)?;
let c = interpret_mir(db, body, false, trait_env)?.0?;
Ok(c)
}
Expand All @@ -297,7 +301,10 @@ pub(crate) fn const_eval_static_query<'db>(
let body = db.monomorphized_mir_body(
def.into(),
GenericArgs::new_from_iter(interner, []),
db.trait_environment_for_body(def.into()),
ParamEnvAndCrate {
param_env: db.trait_environment_for_body(def.into()),
krate: def.krate(db),
},
)?;
let c = interpret_mir(db, body, false, None)?.0?;
Ok(c)
Expand Down
24 changes: 13 additions & 11 deletions src/tools/rust-analyzer/crates/hir-ty/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ use salsa::plumbing::AsId;
use triomphe::Arc;

use crate::{
ImplTraitId, TraitEnvironment, TyDefId, ValueTyDefId,
ImplTraitId, TyDefId, ValueTyDefId,
consteval::ConstEvalError,
dyn_compatibility::DynCompatibilityViolation,
layout::{Layout, LayoutError},
lower::{Diagnostics, GenericDefaults},
mir::{BorrowckResult, MirBody, MirLowerError},
next_solver::{Const, EarlyBinder, GenericArgs, PolyFnSig, TraitRef, Ty, VariancesOf},
next_solver::{
Const, EarlyBinder, GenericArgs, ParamEnv, PolyFnSig, TraitRef, Ty, VariancesOf,
},
traits::ParamEnvAndCrate,
};

#[query_group::query_group]
Expand Down Expand Up @@ -46,15 +49,15 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
&'db self,
def: DefWithBodyId,
subst: GenericArgs<'db>,
env: Arc<TraitEnvironment<'db>>,
env: ParamEnvAndCrate<'db>,
) -> Result<Arc<MirBody<'db>>, MirLowerError<'db>>;

#[salsa::invoke(crate::mir::monomorphized_mir_body_for_closure_query)]
fn monomorphized_mir_body_for_closure<'db>(
&'db self,
def: InternedClosureId,
subst: GenericArgs<'db>,
env: Arc<TraitEnvironment<'db>>,
env: ParamEnvAndCrate<'db>,
) -> Result<Arc<MirBody<'db>>, MirLowerError<'db>>;

#[salsa::invoke(crate::mir::borrowck_query)]
Expand All @@ -70,7 +73,7 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
&'db self,
def: ConstId,
subst: GenericArgs<'db>,
trait_env: Option<Arc<TraitEnvironment<'db>>>,
trait_env: Option<ParamEnvAndCrate<'db>>,
) -> Result<Const<'db>, ConstEvalError<'db>>;

#[salsa::invoke(crate::consteval::const_eval_static_query)]
Expand All @@ -88,7 +91,7 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
#[salsa::transparent]
fn lookup_impl_method<'db>(
&'db self,
env: Arc<TraitEnvironment<'db>>,
env: ParamEnvAndCrate<'db>,
func: FunctionId,
fn_subst: GenericArgs<'db>,
) -> (FunctionId, GenericArgs<'db>);
Expand All @@ -101,15 +104,15 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
&'db self,
def: AdtId,
args: GenericArgs<'db>,
trait_env: Arc<TraitEnvironment<'db>>,
trait_env: ParamEnvAndCrate<'db>,
) -> Result<Arc<Layout>, LayoutError>;

#[salsa::invoke(crate::layout::layout_of_ty_query)]
#[salsa::cycle(cycle_result = crate::layout::layout_of_ty_cycle_result)]
fn layout_of_ty<'db>(
&'db self,
ty: Ty<'db>,
env: Arc<TraitEnvironment<'db>>,
env: ParamEnvAndCrate<'db>,
) -> Result<Arc<Layout>, LayoutError>;

#[salsa::invoke(crate::layout::target_data_layout_query)]
Expand Down Expand Up @@ -186,11 +189,10 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {

#[salsa::invoke(crate::lower::trait_environment_for_body_query)]
#[salsa::transparent]
fn trait_environment_for_body<'db>(&'db self, def: DefWithBodyId)
-> Arc<TraitEnvironment<'db>>;
fn trait_environment_for_body<'db>(&'db self, def: DefWithBodyId) -> ParamEnv<'db>;

#[salsa::invoke(crate::lower::trait_environment_query)]
fn trait_environment<'db>(&'db self, def: GenericDefId) -> Arc<TraitEnvironment<'db>>;
fn trait_environment<'db>(&'db self, def: GenericDefId) -> ParamEnv<'db>;

#[salsa::invoke(crate::lower::generic_defaults_with_diagnostics_query)]
#[salsa::cycle(cycle_result = crate::lower::generic_defaults_with_diagnostics_cycle_result)]
Expand Down
Loading
Loading