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>,

0 commit comments

Comments
 (0)