Skip to content

Commit 556beb9

Browse files
committed
Auto merge of #149602 - lnicola:sync-from-ra, r=lnicola
`rust-analyzer` subtree update Subtree update of `rust-analyzer` to rust-lang/rust-analyzer@633cff2. Created using https://github.com/rust-lang/josh-sync. r? `@ghost`
2 parents 5325015 + 0e706a5 commit 556beb9

Some content is hidden

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

87 files changed

+920
-770
lines changed

src/tools/rust-analyzer/.github/workflows/rustdoc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ env:
88
CARGO_INCREMENTAL: 0
99
CARGO_NET_RETRY: 10
1010
RUSTFLAGS: "-D warnings -W unreachable-pub"
11+
RUSTDOCFLAGS: "-D warnings"
1112
RUSTUP_MAX_RETRIES: 10
1213

1314
jobs:

src/tools/rust-analyzer/crates/hir-def/src/expr_store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub use self::lower::{
4343
hir_assoc_type_binding_to_ast, hir_generic_arg_to_ast, hir_segment_to_ast_segment,
4444
};
4545

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

src/tools/rust-analyzer/crates/hir-def/src/hir/generics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub type LocalLifetimeParamId = Idx<LifetimeParamData>;
2020
/// Data about a generic type parameter (to a function, struct, impl, ...).
2121
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
2222
pub struct TypeParamData {
23-
/// [`None`] only if the type ref is an [`TypeRef::ImplTrait`]. FIXME: Might be better to just
23+
/// [`None`] only if the type ref is an [`crate::type_ref::TypeRef::ImplTrait`]. FIXME: Might be better to just
2424
/// make it always be a value, giving impl trait a special name.
2525
pub name: Option<Name>,
2626
pub default: Option<TypeRefId>,

src/tools/rust-analyzer/crates/hir-def/src/lang_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ language_item_table! { LangItems =>
238238
Clone, sym::clone, clone_trait, TraitId, GenericRequirement::None;
239239
Sync, sym::sync, sync_trait, TraitId, GenericRequirement::Exact(0);
240240
DiscriminantKind, sym::discriminant_kind, discriminant_kind_trait, TraitId, GenericRequirement::None;
241-
/// The associated item of the [`DiscriminantKind`] trait.
241+
/// The associated item of the `DiscriminantKind` trait.
242242
Discriminant, sym::discriminant_type, discriminant_type, TypeAliasId, GenericRequirement::None;
243243

244244
PointeeTrait, sym::pointee_trait, pointee_trait, TraitId, GenericRequirement::None;

src/tools/rust-analyzer/crates/hir-def/src/nameres.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ impl ModuleData {
739739
self.origin.definition_source(db)
740740
}
741741

742-
/// Same as [`definition_source`] but only returns the file id to prevent parsing the ASt.
742+
/// Same as [`ModuleData::definition_source`] but only returns the file id to prevent parsing the ASt.
743743
pub fn definition_source_file_id(&self) -> HirFileId {
744744
match self.origin {
745745
ModuleOrigin::File { definition, .. } | ModuleOrigin::CrateRoot { definition } => {

src/tools/rust-analyzer/crates/hir-expand/src/files.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ impl<SN: Borrow<SyntaxNode>> InFile<SN> {
295295
/// Falls back to the macro call range if the node cannot be mapped up fully.
296296
///
297297
/// For attributes and derives, this will point back to the attribute only.
298-
/// For the entire item use [`InFile::original_file_range_full`].
298+
/// For the entire item use `InFile::original_file_range_full`.
299299
pub fn original_file_range_rooted(self, db: &dyn db::ExpandDatabase) -> FileRange {
300300
self.borrow().map(SyntaxNode::text_range).original_node_file_range_rooted(db)
301301
}

src/tools/rust-analyzer/crates/hir-expand/src/hygiene.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
//!
99
//! # The Expansion Order Hierarchy
1010
//!
11-
//! `ExpnData` in rustc, rust-analyzer's version is [`MacroCallLoc`]. Traversing the hierarchy
12-
//! upwards can be achieved by walking up [`MacroCallLoc::kind`]'s contained file id, as
13-
//! [`MacroFile`]s are interned [`MacroCallLoc`]s.
11+
//! `ExpnData` in rustc, rust-analyzer's version is `MacroCallLoc`. Traversing the hierarchy
12+
//! upwards can be achieved by walking up `MacroCallLoc::kind`'s contained file id, as
13+
//! `MacroFile`s are interned `MacroCallLoc`s.
1414
//!
1515
//! # The Macro Definition Hierarchy
1616
//!
1717
//! `SyntaxContextData` in rustc and rust-analyzer. Basically the same in both.
1818
//!
1919
//! # The Call-site Hierarchy
2020
//!
21-
//! `ExpnData::call_site` in rustc, [`MacroCallLoc::call_site`] in rust-analyzer.
21+
//! `ExpnData::call_site` in rustc, `MacroCallLoc::call_site` in rust-analyzer.
2222
// FIXME: Move this into the span crate? Not quite possible today as that depends on `MacroCallLoc`
2323
// which contains a bunch of unrelated things
2424

src/tools/rust-analyzer/crates/hir-expand/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//! tree originates not from the text of some `FileId`, but from some macro
55
//! expansion.
66
#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
7+
// It's useful to refer to code that is private in doc comments.
8+
#![allow(rustdoc::private_intra_doc_links)]
79

810
pub use intern;
911

@@ -860,7 +862,7 @@ impl ExpansionInfo {
860862
}
861863

862864
/// Maps the passed in file range down into a macro expansion if it is the input to a macro call.
863-
/// Unlike [`map_range_down_exact`], this will consider spans that contain the given span.
865+
/// Unlike [`ExpansionInfo::map_range_down_exact`], this will consider spans that contain the given span.
864866
///
865867
/// Note this does a linear search through the entire backing vector of the spanmap.
866868
pub fn map_range_down(

src/tools/rust-analyzer/crates/hir-ty/src/autoderef.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ use std::fmt;
88
use hir_def::{TraitId, TypeAliasId};
99
use rustc_type_ir::inherent::{IntoKind, Ty as _};
1010
use tracing::debug;
11-
use triomphe::Arc;
1211

1312
use crate::{
14-
TraitEnvironment,
13+
ParamEnvAndCrate,
1514
db::HirDatabase,
1615
infer::InferenceContext,
1716
next_solver::{
@@ -35,13 +34,13 @@ const AUTODEREF_RECURSION_LIMIT: usize = 20;
3534
/// detects a cycle in the deref chain.
3635
pub fn autoderef<'db>(
3736
db: &'db dyn HirDatabase,
38-
env: Arc<TraitEnvironment<'db>>,
37+
env: ParamEnvAndCrate<'db>,
3938
ty: Canonical<'db, Ty<'db>>,
4039
) -> impl Iterator<Item = Ty<'db>> + use<'db> {
4140
let interner = DbInterner::new_with(db, env.krate);
4241
let infcx = interner.infer_ctxt().build(TypingMode::PostAnalysis);
4342
let (ty, _) = infcx.instantiate_canonical(&ty);
44-
let autoderef = Autoderef::new(&infcx, &env, ty);
43+
let autoderef = Autoderef::new(&infcx, env.param_env, ty);
4544
let mut v = Vec::new();
4645
for (ty, _steps) in autoderef {
4746
// `ty` may contain unresolved inference variables. Since there's no chance they would be
@@ -111,21 +110,21 @@ struct AutoderefTraits {
111110
// borrows it.
112111
pub(crate) trait AutoderefCtx<'db> {
113112
fn infcx(&self) -> &InferCtxt<'db>;
114-
fn env(&self) -> &TraitEnvironment<'db>;
113+
fn param_env(&self) -> ParamEnv<'db>;
115114
}
116115

117116
pub(crate) struct DefaultAutoderefCtx<'a, 'db> {
118117
infcx: &'a InferCtxt<'db>,
119-
env: &'a TraitEnvironment<'db>,
118+
param_env: ParamEnv<'db>,
120119
}
121120
impl<'db> AutoderefCtx<'db> for DefaultAutoderefCtx<'_, 'db> {
122121
#[inline]
123122
fn infcx(&self) -> &InferCtxt<'db> {
124123
self.infcx
125124
}
126125
#[inline]
127-
fn env(&self) -> &TraitEnvironment<'db> {
128-
self.env
126+
fn param_env(&self) -> ParamEnv<'db> {
127+
self.param_env
129128
}
130129
}
131130

@@ -136,8 +135,8 @@ impl<'db> AutoderefCtx<'db> for InferenceContextAutoderefCtx<'_, '_, 'db> {
136135
&self.0.table.infer_ctxt
137136
}
138137
#[inline]
139-
fn env(&self) -> &TraitEnvironment<'db> {
140-
&self.0.table.trait_env
138+
fn param_env(&self) -> ParamEnv<'db> {
139+
self.0.table.param_env
141140
}
142141
}
143142

@@ -201,7 +200,7 @@ where
201200
// autoderef expect this type to have been structurally normalized.
202201
if let TyKind::Alias(..) = ty.kind() {
203202
let (normalized_ty, obligations) =
204-
structurally_normalize_ty(self.infcx(), self.env().env, ty)?;
203+
structurally_normalize_ty(self.infcx(), self.param_env(), ty)?;
205204
self.state.obligations.extend(obligations);
206205
(AutoderefKind::Builtin, normalized_ty)
207206
} else {
@@ -231,10 +230,10 @@ impl<'a, 'db> Autoderef<'a, 'db> {
231230
#[inline]
232231
pub(crate) fn new_with_tracking(
233232
infcx: &'a InferCtxt<'db>,
234-
env: &'a TraitEnvironment<'db>,
233+
param_env: ParamEnv<'db>,
235234
base_ty: Ty<'db>,
236235
) -> Self {
237-
Self::new_impl(DefaultAutoderefCtx { infcx, env }, base_ty)
236+
Self::new_impl(DefaultAutoderefCtx { infcx, param_env }, base_ty)
238237
}
239238
}
240239

@@ -257,10 +256,10 @@ impl<'a, 'db> Autoderef<'a, 'db, usize> {
257256
#[inline]
258257
pub(crate) fn new(
259258
infcx: &'a InferCtxt<'db>,
260-
env: &'a TraitEnvironment<'db>,
259+
param_env: ParamEnv<'db>,
261260
base_ty: Ty<'db>,
262261
) -> Self {
263-
Self::new_impl(DefaultAutoderefCtx { infcx, env }, base_ty)
262+
Self::new_impl(DefaultAutoderefCtx { infcx, param_env }, base_ty)
264263
}
265264
}
266265

@@ -292,8 +291,8 @@ where
292291
}
293292

294293
#[inline]
295-
fn env(&self) -> &TraitEnvironment<'db> {
296-
self.ctx.env()
294+
fn param_env(&self) -> ParamEnv<'db> {
295+
self.ctx.param_env()
297296
}
298297

299298
#[inline]
@@ -339,7 +338,7 @@ where
339338

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

352351
let (normalized_ty, obligations) = structurally_normalize_ty(
353352
self.infcx(),
354-
self.env().env,
353+
self.param_env(),
355354
Ty::new_projection(interner, trait_target.into(), [ty]),
356355
)?;
357356
debug!("overloaded_deref_ty({:?}) = ({:?}, {:?})", ty, normalized_ty, obligations);

src/tools/rust-analyzer/crates/hir-ty/src/consteval.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod tests;
55

66
use base_db::Crate;
77
use hir_def::{
8-
ConstId, EnumVariantId, GeneralConstId, StaticId,
8+
ConstId, EnumVariantId, GeneralConstId, HasModule, StaticId,
99
attrs::AttrFlags,
1010
expr_store::Body,
1111
hir::{Expr, ExprId},
@@ -16,14 +16,14 @@ use rustc_type_ir::inherent::IntoKind;
1616
use triomphe::Arc;
1717

1818
use crate::{
19-
LifetimeElisionKind, MemoryMap, TraitEnvironment, TyLoweringContext,
19+
LifetimeElisionKind, MemoryMap, ParamEnvAndCrate, TyLoweringContext,
2020
db::HirDatabase,
2121
display::DisplayTarget,
2222
infer::InferenceContext,
2323
mir::{MirEvalError, MirLowerError},
2424
next_solver::{
25-
Const, ConstBytes, ConstKind, DbInterner, ErrorGuaranteed, GenericArg, GenericArgs, Ty,
26-
ValueConst,
25+
Const, ConstBytes, ConstKind, DbInterner, ErrorGuaranteed, GenericArg, GenericArgs,
26+
ParamEnv, Ty, ValueConst,
2727
},
2828
};
2929

@@ -85,7 +85,7 @@ pub fn intern_const_ref<'a>(
8585
krate: Crate,
8686
) -> Const<'a> {
8787
let interner = DbInterner::new_no_crate(db);
88-
let layout = db.layout_of_ty(ty, TraitEnvironment::empty(krate));
88+
let layout = db.layout_of_ty(ty, ParamEnvAndCrate { param_env: ParamEnv::empty(), krate });
8989
let kind = match value {
9090
LiteralConstRef::Int(i) => {
9191
// FIXME: We should handle failure of layout better.
@@ -207,7 +207,7 @@ pub(crate) fn const_eval_discriminant_variant<'db>(
207207
let mir_body = db.monomorphized_mir_body(
208208
def,
209209
GenericArgs::new_from_iter(interner, []),
210-
db.trait_environment_for_body(def),
210+
ParamEnvAndCrate { param_env: db.trait_environment_for_body(def), krate: def.krate(db) },
211211
)?;
212212
let c = interpret_mir(db, mir_body, false, None)?.0?;
213213
let c = if is_signed {
@@ -259,7 +259,7 @@ pub(crate) fn const_eval_cycle_result<'db>(
259259
_: &'db dyn HirDatabase,
260260
_: ConstId,
261261
_: GenericArgs<'db>,
262-
_: Option<Arc<TraitEnvironment<'db>>>,
262+
_: Option<ParamEnvAndCrate<'db>>,
263263
) -> Result<Const<'db>, ConstEvalError<'db>> {
264264
Err(ConstEvalError::MirLowerError(MirLowerError::Loop))
265265
}
@@ -282,9 +282,13 @@ pub(crate) fn const_eval_query<'db>(
282282
db: &'db dyn HirDatabase,
283283
def: ConstId,
284284
subst: GenericArgs<'db>,
285-
trait_env: Option<Arc<TraitEnvironment<'db>>>,
285+
trait_env: Option<ParamEnvAndCrate<'db>>,
286286
) -> Result<Const<'db>, ConstEvalError<'db>> {
287-
let body = db.monomorphized_mir_body(def.into(), subst, db.trait_environment(def.into()))?;
287+
let body = db.monomorphized_mir_body(
288+
def.into(),
289+
subst,
290+
ParamEnvAndCrate { param_env: db.trait_environment(def.into()), krate: def.krate(db) },
291+
)?;
288292
let c = interpret_mir(db, body, false, trait_env)?.0?;
289293
Ok(c)
290294
}
@@ -297,7 +301,10 @@ pub(crate) fn const_eval_static_query<'db>(
297301
let body = db.monomorphized_mir_body(
298302
def.into(),
299303
GenericArgs::new_from_iter(interner, []),
300-
db.trait_environment_for_body(def.into()),
304+
ParamEnvAndCrate {
305+
param_env: db.trait_environment_for_body(def.into()),
306+
krate: def.krate(db),
307+
},
301308
)?;
302309
let c = interpret_mir(db, body, false, None)?.0?;
303310
Ok(c)

0 commit comments

Comments
 (0)