Skip to content

Commit

Permalink
Auto merge of rust-lang#3363 - RalfJung:rustup, r=RalfJung
Browse files Browse the repository at this point in the history
Rustup

This should finally work again :)
  • Loading branch information
bors committed Mar 6, 2024
2 parents f576d28 + 078ab25 commit 41b1ccb
Show file tree
Hide file tree
Showing 122 changed files with 3,267 additions and 1,269 deletions.
8 changes: 8 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ Otherwise please try to provide information which will help us to fix the issue
**rustc version**: (eg. output of `rustc -V`)

**relevant settings**: (eg. client settings, or environment variables like `CARGO`, `RUSTC`, `RUSTUP_HOME` or `CARGO_HOME`)

**repository link (if public, optional)**: (eg. [rust-analyzer](https://github.com/rust-lang/rust-analyzer))

**code snippet to reproduce**:
```rust
// add your code here

```
44 changes: 22 additions & 22 deletions .typos.toml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
[default.extend-identifiers]
AnserStyle = "AnserStyle"
datas = "datas"
impl_froms = "impl_froms"
selfs = "selfs"
[files]
extend-exclude = [
"*.rast",
"bench_data/",
"crates/parser/test_data/lexer/err/",
"crates/project-model/test_data/",
]
ignore-hidden = false

[default]
extend-ignore-re = [
# ignore string which contains $0, which is used widely in tests
".*\\$0.*",
# ignore generated content like `boxed....nner()`, `Defaul...efault`
"\\w*\\.{3,4}\\w*",
'"flate2"',
"raison d'être",
]

[default.extend-words]
anser = "anser"
ba = "ba"
fo = "fo"
ket = "ket"
makro = "makro"
raison = "raison"
trivias = "trivias"
TOOD = "TOOD"

[default]
extend-ignore-re = [
# ignore string which contains $x (x is a num), which use widely in test
".*\\$\\d.*",
# ignore generated content like `boxed....nner()`, `Defaul...efault`
"\\w*\\.{3,4}\\w*",
]

[files]
extend-exclude = [
"*.json",
"*.rast",
"crates/parser/test_data/lexer/err/*",
"bench_data/*",
]
[default.extend-identifiers]
datas = "datas"
impl_froms = "impl_froms"
selfs = "selfs"
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exclude = ["crates/proc-macro-srv/proc-macro-test/imp"]
resolver = "2"

[workspace.package]
rust-version = "1.74"
rust-version = "1.76"
edition = "2021"
license = "MIT OR Apache-2.0"
authors = ["rust-analyzer team"]
Expand All @@ -28,6 +28,10 @@ incremental = true
# Set this to 1 or 2 to get more useful backtraces in debugger.
debug = 0

[profile.dev-rel]
inherits = "release"
debug = 2

[patch.'crates-io']
# rowan = { path = "../rowan" }

Expand Down
2 changes: 1 addition & 1 deletion crates/base-db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ impl CrateGraph {
.arena
.iter_mut()
.take(m)
.find_map(|(id, data)| merge((id, data), (topo, &crate_data)).then_some(id));
.find_map(|(id, data)| merge((id, data), (topo, crate_data)).then_some(id));

let new_id =
if let Some(res) = res { res } else { self.arena.alloc(crate_data.clone()) };
Expand Down
2 changes: 1 addition & 1 deletion crates/flycheck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ impl CommandHandle {
let (sender, receiver) = unbounded();
let actor = CargoActor::new(sender, stdout, stderr);
let thread = stdx::thread::Builder::new(stdx::thread::ThreadIntent::Worker)
.name("CargoHandle".to_owned())
.name("CommandHandle".to_owned())
.spawn(move || actor.run())
.expect("failed to spawn thread");
Ok(CommandHandle { program, arguments, current_dir, child, thread, receiver })
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/body/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use std::mem;
use base_db::CrateId;
use either::Either;
use hir_expand::{
ast_id_map::AstIdMap,
name::{name, AsName, Name},
ExpandError, InFile,
};
use intern::Interned;
use profile::Count;
use rustc_hash::FxHashMap;
use smallvec::SmallVec;
use span::AstIdMap;
use syntax::{
ast::{
self, ArrayExprKind, AstChildren, BlockExpr, HasArgList, HasAttrs, HasLoopBody, HasName,
Expand Down
34 changes: 34 additions & 0 deletions crates/hir-def/src/body/tests/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,40 @@ pub mod cov_mark {
);
}

#[test]
fn macro_exported_in_block_mod() {
check_at(
r#"
#[macro_export]
macro_rules! foo {
() => { pub struct FooWorks; };
}
macro_rules! bar {
() => { pub struct BarWorks; };
}
fn main() {
mod module {
foo!();
bar!();
$0
}
}
"#,
expect![[r#"
block scope
module: t
block scope::module
BarWorks: t v
FooWorks: t v
crate
foo: m
main: v
"#]],
);
}

#[test]
fn macro_resolve_legacy() {
check_at(
Expand Down
3 changes: 2 additions & 1 deletion crates/hir-def/src/child_by_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,11 @@ impl ChildBySource for DefWithBodyId {
VariantId::EnumVariantId(v).child_by_source_to(db, res, file_id)
}

for (_, def_map) in body.blocks(db) {
for (block, def_map) in body.blocks(db) {
// All block expressions are merged into the same map, because they logically all add
// inner items to the containing `DefWithBodyId`.
def_map[DefMap::ROOT].scope.child_by_source_to(db, res, file_id);
res[keys::BLOCK].insert(block.lookup(db).ast_id.to_node(db.upcast()), block);
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions crates/hir-def/src/dyn_map/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ use syntax::{ast, AstNode, AstPtr};

use crate::{
dyn_map::{DynMap, Policy},
ConstId, EnumId, EnumVariantId, ExternCrateId, FieldId, FunctionId, ImplId, LifetimeParamId,
Macro2Id, MacroRulesId, ProcMacroId, StaticId, StructId, TraitAliasId, TraitId, TypeAliasId,
TypeOrConstParamId, UnionId, UseId,
BlockId, ConstId, EnumId, EnumVariantId, ExternCrateId, FieldId, FunctionId, ImplId,
LifetimeParamId, Macro2Id, MacroRulesId, ProcMacroId, StaticId, StructId, TraitAliasId,
TraitId, TypeAliasId, TypeOrConstParamId, UnionId, UseId,
};

pub type Key<K, V> = crate::dyn_map::Key<K, V, AstPtrPolicy<K, V>>;

pub const BLOCK: Key<ast::BlockExpr, BlockId> = Key::new();
pub const FUNCTION: Key<ast::Fn, FunctionId> = Key::new();
pub const CONST: Key<ast::Const, ConstId> = Key::new();
pub const STATIC: Key<ast::Static, StaticId> = Key::new();
Expand Down
9 changes: 2 additions & 7 deletions crates/hir-def/src/item_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,13 @@ use std::{
use ast::{AstNode, StructKind};
use base_db::CrateId;
use either::Either;
use hir_expand::{
ast_id_map::{AstIdNode, FileAstId},
attrs::RawAttrs,
name::Name,
ExpandTo, HirFileId, InFile,
};
use hir_expand::{attrs::RawAttrs, name::Name, ExpandTo, HirFileId, InFile};
use intern::Interned;
use la_arena::{Arena, Idx, IdxRange, RawIdx};
use profile::Count;
use rustc_hash::FxHashMap;
use smallvec::SmallVec;
use span::Span;
use span::{AstIdNode, FileAstId, Span};
use stdx::never;
use syntax::{ast, match_ast, SyntaxKind};
use triomphe::Arc;
Expand Down
5 changes: 2 additions & 3 deletions crates/hir-def/src/item_tree/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
use std::collections::hash_map::Entry;

use hir_expand::{
ast_id_map::AstIdMap, mod_path::path, name, name::AsName, span_map::SpanMapRef, HirFileId,
};
use hir_expand::{mod_path::path, name, name::AsName, span_map::SpanMapRef, HirFileId};
use la_arena::Arena;
use span::AstIdMap;
use syntax::{
ast::{self, HasModuleItem, HasName, HasTypeBounds, IsString},
AstNode,
Expand Down
3 changes: 1 addition & 2 deletions crates/hir-def/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ use base_db::{
CrateId, Edition,
};
use hir_expand::{
ast_id_map::{AstIdNode, FileAstId},
builtin_attr_macro::BuiltinAttrExpander,
builtin_derive_macro::BuiltinDeriveExpander,
builtin_fn_macro::{BuiltinFnLikeExpander, EagerExpander},
Expand All @@ -91,7 +90,7 @@ use hir_expand::{
use item_tree::ExternBlock;
use la_arena::Idx;
use nameres::DefMap;
use span::{FileId, Span};
use span::{AstIdNode, FileAstId, FileId, Span};
use stdx::impl_from;
use syntax::{ast, AstNode};

Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
use std::cell::OnceCell;

use hir_expand::{
ast_id_map::{AstIdMap, AstIdNode},
span_map::{SpanMap, SpanMapRef},
AstId, HirFileId, InFile,
};
use span::{AstIdMap, AstIdNode};
use syntax::ast;
use triomphe::Arc;

Expand Down
10 changes: 8 additions & 2 deletions crates/hir-def/src/nameres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ use std::ops::Deref;

use base_db::{CrateId, Edition, FileId};
use hir_expand::{
ast_id_map::FileAstId, name::Name, proc_macro::ProcMacroKind, HirFileId, InFile, MacroCallId,
MacroDefId,
name::Name, proc_macro::ProcMacroKind, HirFileId, InFile, MacroCallId, MacroDefId,
};
use itertools::Itertools;
use la_arena::Arena;
use profile::Count;
use rustc_hash::{FxHashMap, FxHashSet};
use span::FileAstId;
use stdx::format_to;
use syntax::{ast, SmolStr};
use triomphe::Arc;
Expand Down Expand Up @@ -469,6 +469,12 @@ impl DefMap {
CrateRootModuleId { krate: self.krate }
}

/// This is the same as [`Self::crate_root`] for crate def maps, but for block def maps, it
/// returns the root block module.
pub fn root_module_id(&self) -> ModuleId {
self.module_id(Self::ROOT)
}

pub(crate) fn resolve_path(
&self,
db: &dyn DefDatabase,
Expand Down
3 changes: 1 addition & 2 deletions crates/hir-def/src/nameres/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use base_db::{CrateId, Dependency, Edition, FileId};
use cfg::{CfgExpr, CfgOptions};
use either::Either;
use hir_expand::{
ast_id_map::FileAstId,
attrs::{Attr, AttrId},
builtin_attr_macro::{find_builtin_attr, BuiltinAttrExpander},
builtin_derive_macro::find_builtin_derive,
Expand All @@ -23,7 +22,7 @@ use itertools::{izip, Itertools};
use la_arena::Idx;
use limit::Limit;
use rustc_hash::{FxHashMap, FxHashSet};
use span::{ErasedFileAstId, Span, SyntaxContextId};
use span::{ErasedFileAstId, FileAstId, Span, SyntaxContextId};
use stdx::always;
use syntax::{ast, SmolStr};
use triomphe::Arc;
Expand Down
29 changes: 19 additions & 10 deletions crates/hir-def/src/resolver.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Name resolution façade.
use std::{fmt, hash::BuildHasherDefault};
use std::{fmt, hash::BuildHasherDefault, mem};

use base_db::CrateId;
use hir_expand::{
Expand Down Expand Up @@ -809,7 +809,7 @@ fn resolver_for_scope_(
for scope in scope_chain.into_iter().rev() {
if let Some(block) = scopes.block(scope) {
let def_map = db.block_def_map(block);
r = r.push_block_scope(def_map, DefMap::ROOT);
r = r.push_block_scope(def_map);
// FIXME: This adds as many module scopes as there are blocks, but resolving in each
// already traverses all parents, so this is O(n²). I think we could only store the
// innermost module scope instead?
Expand All @@ -835,8 +835,9 @@ impl Resolver {
self.push_scope(Scope::ImplDefScope(impl_def))
}

fn push_block_scope(self, def_map: Arc<DefMap>, module_id: LocalModuleId) -> Resolver {
self.push_scope(Scope::BlockScope(ModuleItemMap { def_map, module_id }))
fn push_block_scope(self, def_map: Arc<DefMap>) -> Resolver {
debug_assert!(def_map.block_id().is_some());
self.push_scope(Scope::BlockScope(ModuleItemMap { def_map, module_id: DefMap::ROOT }))
}

fn push_expr_scope(
Expand Down Expand Up @@ -986,19 +987,27 @@ pub trait HasResolver: Copy {
impl HasResolver for ModuleId {
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
let mut def_map = self.def_map(db);
let mut modules: SmallVec<[_; 1]> = smallvec![];
let mut module_id = self.local_id;
let mut modules: SmallVec<[_; 1]> = smallvec![];

if !self.is_block_module() {
return Resolver { scopes: vec![], module_scope: ModuleItemMap { def_map, module_id } };
}

while let Some(parent) = def_map.parent() {
modules.push((def_map, module_id));
def_map = parent.def_map(db);
module_id = parent.local_id;
let block_def_map = mem::replace(&mut def_map, parent.def_map(db));
modules.push(block_def_map);
if !parent.is_block_module() {
module_id = parent.local_id;
break;
}
}
let mut resolver = Resolver {
scopes: Vec::with_capacity(modules.len()),
module_scope: ModuleItemMap { def_map, module_id },
};
for (def_map, module) in modules.into_iter().rev() {
resolver = resolver.push_block_scope(def_map, module);
for def_map in modules.into_iter().rev() {
resolver = resolver.push_block_scope(def_map);
}
resolver
}
Expand Down
Loading

0 comments on commit 41b1ccb

Please sign in to comment.