Skip to content

Commit 0b33563

Browse files
Add ./x.py test rust-analyzer
This adds support for testing `rust-analyzer` in-tree. Test rust-analyzer in CI Set CARGO_WORKSPACE_DIR directly in `prepare_tool_cargo` cf. rust-lang#99444 (comment) cf. rust-analyzer/expect-test#33 Various x.py changes for Submodule => InTree, and removing toolstate Introduce `rust-analyzer/in-rust-tree` cargo feature This allows skipping ra's "check_merge_commits" test for now. Later, it might be used to link against `extern proc_macro` directly, cf. rust-lang/rust-analyzer#12803 More cleanups around the RustAnalyzer tool in bootstrap Start fixing lints Deny the same warnings x.py does in all RA crates Warn on x.py warnings, don't deny cf. https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/rust-analyzer.20as.20a.20subtree.3A.20experimental.20PR.20status/near/290114101 Fix rust_2018_idioms with cargo fix Add warning groups for more RA crates Fix more 2015 idioms (with 2018_idioms, naming is fun) RA passes all x.py warnings Fix formatting after fixing idioms/additional warnings Enable in-rust-tree feature, RA tests pass Print stdout+stderr when nested cargo invocation fails
1 parent 7a03bf4 commit 0b33563

File tree

266 files changed

+1140
-900
lines changed

Some content is hidden

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

266 files changed

+1140
-900
lines changed

src/bootstrap/builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ impl<'a> Builder<'a> {
648648
test::Cargotest,
649649
test::Cargo,
650650
test::Rls,
651+
test::RustAnalyzer,
651652
test::ErrorIndex,
652653
test::Distcheck,
653654
test::RunMakeFullDeps,

src/bootstrap/test.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,53 @@ impl Step for Rls {
352352
}
353353
}
354354

355+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
356+
pub struct RustAnalyzer {
357+
stage: u32,
358+
host: TargetSelection,
359+
}
360+
361+
impl Step for RustAnalyzer {
362+
type Output = ();
363+
const ONLY_HOSTS: bool = true;
364+
const DEFAULT: bool = true;
365+
366+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
367+
run.path("src/tools/rust-analyzer")
368+
}
369+
370+
fn make_run(run: RunConfig<'_>) {
371+
run.builder.ensure(Self { stage: run.builder.top_stage, host: run.target });
372+
}
373+
374+
/// Runs `cargo test` for rust-analyzer.
375+
fn run(self, builder: &Builder<'_>) {
376+
let stage = self.stage;
377+
let host = self.host;
378+
let compiler = builder.compiler(stage, host);
379+
380+
builder
381+
.ensure(tool::RustAnalyzer { compiler, target: self.host, extra_features: Vec::new() })
382+
.expect("in-tree tool");
383+
384+
let mut cargo = tool::prepare_tool_cargo(
385+
builder,
386+
compiler,
387+
Mode::ToolStd,
388+
host,
389+
"test",
390+
"src/tools/rust-analyzer",
391+
SourceType::InTree,
392+
&["rust-analyzer/in-rust-tree".to_owned()],
393+
);
394+
395+
cargo.add_rustc_lib_path(builder, compiler);
396+
cargo.arg("--").args(builder.config.cmd.test_args());
397+
398+
builder.run(&mut cargo.into());
399+
}
400+
}
401+
355402
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
356403
pub struct Rustfmt {
357404
stage: u32,

src/bootstrap/tool.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::HashSet;
22
use std::env;
33
use std::fs;
4-
use std::path::{Path, PathBuf};
4+
use std::path::PathBuf;
55
use std::process::Command;
66

77
use crate::builder::{Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step};
@@ -250,6 +250,10 @@ pub fn prepare_tool_cargo(
250250
}
251251
}
252252

253+
// cargo doesn't set this env var yet, but it's needed by expect-test
254+
// to build correct absolute paths for test_data files
255+
cargo.env("CARGO_WORKSPACE_DIR", &dir);
256+
253257
// clippy tests need to know about the stage sysroot. Set them consistently while building to
254258
// avoid rebuilding when running tests.
255259
cargo.env("SYSROOT", builder.sysroot(compiler));
@@ -780,7 +784,9 @@ tool_extended!((self, builder),
780784
// and this is close enough for now.
781785
RustDemangler, rust_demangler, "src/tools/rust-demangler", "rust-demangler", stable=false, in_tree=true, tool_std=true, {};
782786
Rustfmt, rustfmt, "src/tools/rustfmt", "rustfmt", stable=true, in_tree=true, {};
783-
RustAnalyzer, rust_analyzer, "src/tools/rust-analyzer/crates/rust-analyzer", "rust-analyzer", stable=true, submodule="rust-analyzer", {};
787+
RustAnalyzer, rust_analyzer, "src/tools/rust-analyzer/crates/rust-analyzer", "rust-analyzer", stable=true, in_tree=true, tool_std=true, {
788+
self.extra_features.push("in-rust-tree".to_owned());
789+
};
784790
);
785791

786792
impl<'a> Builder<'a> {

src/tools/rust-analyzer/crates/base-db/src/change.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub struct Change {
1717
}
1818

1919
impl fmt::Debug for Change {
20-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
20+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
2121
let mut d = fmt.debug_struct("Change");
2222
if let Some(roots) = &self.roots {
2323
d.field("roots", roots);

src/tools/rust-analyzer/crates/base-db/src/input.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl CrateName {
104104
}
105105

106106
impl fmt::Display for CrateName {
107-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
107+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
108108
self.0.fmt(f)
109109
}
110110
}
@@ -187,7 +187,7 @@ impl From<CrateName> for CrateDisplayName {
187187
}
188188

189189
impl fmt::Display for CrateDisplayName {
190-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
190+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
191191
self.crate_name.fmt(f)
192192
}
193193
}

src/tools/rust-analyzer/crates/base-db/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! base_db defines basic database traits. The concrete DB is defined by ide.
2+
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
23
mod input;
34
mod change;
45
pub mod fixture;
@@ -54,7 +55,7 @@ pub const DEFAULT_LRU_CAP: usize = 128;
5455
pub trait FileLoader {
5556
/// Text of the file.
5657
fn file_text(&self, file_id: FileId) -> Arc<String>;
57-
fn resolve_path(&self, path: AnchoredPath) -> Option<FileId>;
58+
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId>;
5859
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>>;
5960
}
6061

@@ -113,7 +114,7 @@ impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> {
113114
fn file_text(&self, file_id: FileId) -> Arc<String> {
114115
SourceDatabaseExt::file_text(self.0, file_id)
115116
}
116-
fn resolve_path(&self, path: AnchoredPath) -> Option<FileId> {
117+
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId> {
117118
// FIXME: this *somehow* should be platform agnostic...
118119
let source_root = self.0.file_source_root(path.anchor);
119120
let source_root = self.0.source_root(source_root);

src/tools/rust-analyzer/crates/cfg/src/cfg_expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl CfgExpr {
8585
}
8686
}
8787

88-
fn next_cfg_expr(it: &mut SliceIter<tt::TokenTree>) -> Option<CfgExpr> {
88+
fn next_cfg_expr(it: &mut SliceIter<'_, tt::TokenTree>) -> Option<CfgExpr> {
8989
let name = match it.next() {
9090
None => return None,
9191
Some(tt::TokenTree::Leaf(tt::Leaf::Ident(ident))) => ident.text.clone(),

src/tools/rust-analyzer/crates/cfg/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! cfg defines conditional compiling options, `cfg` attribute parser and evaluator
2+
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
23

34
mod cfg_expr;
45
mod dnf;

src/tools/rust-analyzer/crates/flycheck/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Flycheck provides the functionality needed to run `cargo check` or
22
//! another compatible command (f.x. clippy) in a background thread and provide
33
//! LSP diagnostics based on the output of the command.
4+
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
45

56
use std::{
67
fmt, io,

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl GenericParams {
195195
}
196196
}
197197

198-
pub(crate) fn fill(&mut self, lower_ctx: &LowerCtx, node: &dyn HasGenericParams) {
198+
pub(crate) fn fill(&mut self, lower_ctx: &LowerCtx<'_>, node: &dyn HasGenericParams) {
199199
if let Some(params) = node.generic_param_list() {
200200
self.fill_params(lower_ctx, params)
201201
}
@@ -206,7 +206,7 @@ impl GenericParams {
206206

207207
pub(crate) fn fill_bounds(
208208
&mut self,
209-
lower_ctx: &LowerCtx,
209+
lower_ctx: &LowerCtx<'_>,
210210
node: &dyn ast::HasTypeBounds,
211211
target: Either<TypeRef, LifetimeRef>,
212212
) {
@@ -217,7 +217,7 @@ impl GenericParams {
217217
}
218218
}
219219

220-
fn fill_params(&mut self, lower_ctx: &LowerCtx, params: ast::GenericParamList) {
220+
fn fill_params(&mut self, lower_ctx: &LowerCtx<'_>, params: ast::GenericParamList) {
221221
for type_or_const_param in params.type_or_const_params() {
222222
match type_or_const_param {
223223
ast::TypeOrConstParam::Type(type_param) => {
@@ -259,7 +259,7 @@ impl GenericParams {
259259
}
260260
}
261261

262-
fn fill_where_predicates(&mut self, lower_ctx: &LowerCtx, where_clause: ast::WhereClause) {
262+
fn fill_where_predicates(&mut self, lower_ctx: &LowerCtx<'_>, where_clause: ast::WhereClause) {
263263
for pred in where_clause.predicates() {
264264
let target = if let Some(type_ref) = pred.ty() {
265265
Either::Left(TypeRef::from_ast(lower_ctx, type_ref))
@@ -293,7 +293,7 @@ impl GenericParams {
293293

294294
fn add_where_predicate_from_bound(
295295
&mut self,
296-
lower_ctx: &LowerCtx,
296+
lower_ctx: &LowerCtx<'_>,
297297
bound: ast::TypeBound,
298298
hrtb_lifetimes: Option<&Box<[Name]>>,
299299
target: Either<TypeRef, LifetimeRef>,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//!
77
//! Note that `hir_def` is a work in progress, so not all of the above is
88
//! actually true.
9+
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
910

1011
#[allow(unused)]
1112
macro_rules! eprintln {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,7 @@ impl ModCollector<'_, '_> {
15091509
let module = self.def_collector.def_map.module_id(self.module_id);
15101510
let def_map = &mut self.def_collector.def_map;
15111511
let update_def =
1512-
|def_collector: &mut DefCollector, id, name: &Name, vis, has_constructor| {
1512+
|def_collector: &mut DefCollector<'_>, id, name: &Name, vis, has_constructor| {
15131513
def_collector.def_map.modules[self.module_id].scope.declare(id);
15141514
def_collector.update(
15151515
self.module_id,

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub enum GenericArg {
8888
impl Path {
8989
/// Converts an `ast::Path` to `Path`. Works with use trees.
9090
/// It correctly handles `$crate` based path from macro call.
91-
pub fn from_src(path: ast::Path, ctx: &LowerCtx) -> Option<Path> {
91+
pub fn from_src(path: ast::Path, ctx: &LowerCtx<'_>) -> Option<Path> {
9292
lower::lower_path(path, ctx)
9393
}
9494

@@ -188,7 +188,10 @@ impl<'a> PathSegments<'a> {
188188
}
189189

190190
impl GenericArgs {
191-
pub(crate) fn from_ast(lower_ctx: &LowerCtx, node: ast::GenericArgList) -> Option<GenericArgs> {
191+
pub(crate) fn from_ast(
192+
lower_ctx: &LowerCtx<'_>,
193+
node: ast::GenericArgList,
194+
) -> Option<GenericArgs> {
192195
lower::lower_generic_args(lower_ctx, node)
193196
}
194197

src/tools/rust-analyzer/crates/hir-def/src/path/lower.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515

1616
/// Converts an `ast::Path` to `Path`. Works with use trees.
1717
/// It correctly handles `$crate` based path from macro call.
18-
pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option<Path> {
18+
pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx<'_>) -> Option<Path> {
1919
let mut kind = PathKind::Plain;
2020
let mut type_anchor = None;
2121
let mut segments = Vec::new();
@@ -149,7 +149,7 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option<Path> {
149149
}
150150

151151
pub(super) fn lower_generic_args(
152-
lower_ctx: &LowerCtx,
152+
lower_ctx: &LowerCtx<'_>,
153153
node: ast::GenericArgList,
154154
) -> Option<GenericArgs> {
155155
let mut args = Vec::new();
@@ -196,7 +196,7 @@ pub(super) fn lower_generic_args(
196196
/// Collect `GenericArgs` from the parts of a fn-like path, i.e. `Fn(X, Y)
197197
/// -> Z` (which desugars to `Fn<(X, Y), Output=Z>`).
198198
fn lower_generic_args_from_fn_path(
199-
ctx: &LowerCtx,
199+
ctx: &LowerCtx<'_>,
200200
params: Option<ast::ParamList>,
201201
ret_type: Option<ast::RetType>,
202202
) -> Option<GenericArgs> {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl FileLoader for TestDB {
7373
fn file_text(&self, file_id: FileId) -> Arc<String> {
7474
FileLoaderDelegate(self).file_text(file_id)
7575
}
76-
fn resolve_path(&self, path: AnchoredPath) -> Option<FileId> {
76+
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId> {
7777
FileLoaderDelegate(self).resolve_path(path)
7878
}
7979
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub struct TraitRef {
8686

8787
impl TraitRef {
8888
/// Converts an `ast::PathType` to a `hir::TraitRef`.
89-
pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::Type) -> Option<Self> {
89+
pub(crate) fn from_ast(ctx: &LowerCtx<'_>, node: ast::Type) -> Option<Self> {
9090
// FIXME: Use `Path::from_src`
9191
match node {
9292
ast::Type::PathType(path) => {
@@ -159,7 +159,7 @@ pub enum TraitBoundModifier {
159159

160160
impl TypeRef {
161161
/// Converts an `ast::TypeRef` to a `hir::TypeRef`.
162-
pub fn from_ast(ctx: &LowerCtx, node: ast::Type) -> Self {
162+
pub fn from_ast(ctx: &LowerCtx<'_>, node: ast::Type) -> Self {
163163
match node {
164164
ast::Type::ParenType(inner) => TypeRef::from_ast_opt(ctx, inner.ty()),
165165
ast::Type::TupleType(inner) => {
@@ -245,7 +245,7 @@ impl TypeRef {
245245
}
246246
}
247247

248-
pub(crate) fn from_ast_opt(ctx: &LowerCtx, node: Option<ast::Type>) -> Self {
248+
pub(crate) fn from_ast_opt(ctx: &LowerCtx<'_>, node: Option<ast::Type>) -> Self {
249249
match node {
250250
Some(node) => TypeRef::from_ast(ctx, node),
251251
None => TypeRef::Error,
@@ -320,7 +320,7 @@ impl TypeRef {
320320
}
321321

322322
pub(crate) fn type_bounds_from_ast(
323-
lower_ctx: &LowerCtx,
323+
lower_ctx: &LowerCtx<'_>,
324324
type_bounds_opt: Option<ast::TypeBoundList>,
325325
) -> Vec<Interned<TypeBound>> {
326326
if let Some(type_bounds) = type_bounds_opt {
@@ -331,7 +331,7 @@ pub(crate) fn type_bounds_from_ast(
331331
}
332332

333333
impl TypeBound {
334-
pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::TypeBound) -> Self {
334+
pub(crate) fn from_ast(ctx: &LowerCtx<'_>, node: ast::TypeBound) -> Self {
335335
let lower_path_type = |path_type: ast::PathType| ctx.lower_path(path_type.path()?);
336336

337337
match node.kind() {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! Specifically, it implements a concept of `MacroFile` -- a file whose syntax
44
//! tree originates not from the text of some `FileId`, but from some macro
55
//! expansion.
6+
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
67

78
pub mod db;
89
pub mod ast_id_map;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl ModPath {
102102
}
103103
}
104104

105-
pub fn escaped(&self) -> EscapedModPath {
105+
pub fn escaped(&self) -> EscapedModPath<'_> {
106106
EscapedModPath(self)
107107
}
108108

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ enum Repr {
2121
}
2222

2323
impl fmt::Display for Name {
24-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
24+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2525
match &self.0 {
2626
Repr::Text(text) => fmt::Display::fmt(&text, f),
2727
Repr::TupleField(idx) => fmt::Display::fmt(&idx, f),
@@ -35,7 +35,7 @@ fn is_raw_identifier(name: &str) -> bool {
3535
}
3636

3737
impl<'a> fmt::Display for EscapedName<'a> {
38-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
38+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3939
match &self.0 .0 {
4040
Repr::Text(text) => {
4141
if is_raw_identifier(text) {
@@ -142,7 +142,7 @@ impl Name {
142142
}
143143
}
144144

145-
pub fn escaped(&self) -> EscapedName {
145+
pub fn escaped(&self) -> EscapedName<'_> {
146146
EscapedName(self)
147147
}
148148
}

0 commit comments

Comments
 (0)