Skip to content

Commit

Permalink
Add ./x.py test rust-analyzer
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fasterthanlime committed Jul 19, 2022
1 parent 7a03bf4 commit 0b33563
Show file tree
Hide file tree
Showing 266 changed files with 1,140 additions and 900 deletions.
1 change: 1 addition & 0 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ impl<'a> Builder<'a> {
test::Cargotest,
test::Cargo,
test::Rls,
test::RustAnalyzer,
test::ErrorIndex,
test::Distcheck,
test::RunMakeFullDeps,
Expand Down
47 changes: 47 additions & 0 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,53 @@ impl Step for Rls {
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct RustAnalyzer {
stage: u32,
host: TargetSelection,
}

impl Step for RustAnalyzer {
type Output = ();
const ONLY_HOSTS: bool = true;
const DEFAULT: bool = true;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.path("src/tools/rust-analyzer")
}

fn make_run(run: RunConfig<'_>) {
run.builder.ensure(Self { stage: run.builder.top_stage, host: run.target });
}

/// Runs `cargo test` for rust-analyzer.
fn run(self, builder: &Builder<'_>) {
let stage = self.stage;
let host = self.host;
let compiler = builder.compiler(stage, host);

builder
.ensure(tool::RustAnalyzer { compiler, target: self.host, extra_features: Vec::new() })
.expect("in-tree tool");

let mut cargo = tool::prepare_tool_cargo(
builder,
compiler,
Mode::ToolStd,
host,
"test",
"src/tools/rust-analyzer",
SourceType::InTree,
&["rust-analyzer/in-rust-tree".to_owned()],
);

cargo.add_rustc_lib_path(builder, compiler);
cargo.arg("--").args(builder.config.cmd.test_args());

builder.run(&mut cargo.into());
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Rustfmt {
stage: u32,
Expand Down
10 changes: 8 additions & 2 deletions src/bootstrap/tool.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashSet;
use std::env;
use std::fs;
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use std::process::Command;

use crate::builder::{Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step};
Expand Down Expand Up @@ -250,6 +250,10 @@ pub fn prepare_tool_cargo(
}
}

// cargo doesn't set this env var yet, but it's needed by expect-test
// to build correct absolute paths for test_data files
cargo.env("CARGO_WORKSPACE_DIR", &dir);

// clippy tests need to know about the stage sysroot. Set them consistently while building to
// avoid rebuilding when running tests.
cargo.env("SYSROOT", builder.sysroot(compiler));
Expand Down Expand Up @@ -780,7 +784,9 @@ tool_extended!((self, builder),
// and this is close enough for now.
RustDemangler, rust_demangler, "src/tools/rust-demangler", "rust-demangler", stable=false, in_tree=true, tool_std=true, {};
Rustfmt, rustfmt, "src/tools/rustfmt", "rustfmt", stable=true, in_tree=true, {};
RustAnalyzer, rust_analyzer, "src/tools/rust-analyzer/crates/rust-analyzer", "rust-analyzer", stable=true, submodule="rust-analyzer", {};
RustAnalyzer, rust_analyzer, "src/tools/rust-analyzer/crates/rust-analyzer", "rust-analyzer", stable=true, in_tree=true, tool_std=true, {
self.extra_features.push("in-rust-tree".to_owned());
};
);

impl<'a> Builder<'a> {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/base-db/src/change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct Change {
}

impl fmt::Debug for Change {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut d = fmt.debug_struct("Change");
if let Some(roots) = &self.roots {
d.field("roots", roots);
Expand Down
4 changes: 2 additions & 2 deletions src/tools/rust-analyzer/crates/base-db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl CrateName {
}

impl fmt::Display for CrateName {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
Expand Down Expand Up @@ -187,7 +187,7 @@ impl From<CrateName> for CrateDisplayName {
}

impl fmt::Display for CrateDisplayName {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.crate_name.fmt(f)
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/tools/rust-analyzer/crates/base-db/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! base_db defines basic database traits. The concrete DB is defined by ide.
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
mod input;
mod change;
pub mod fixture;
Expand Down Expand Up @@ -54,7 +55,7 @@ pub const DEFAULT_LRU_CAP: usize = 128;
pub trait FileLoader {
/// Text of the file.
fn file_text(&self, file_id: FileId) -> Arc<String>;
fn resolve_path(&self, path: AnchoredPath) -> Option<FileId>;
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId>;
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>>;
}

Expand Down Expand Up @@ -113,7 +114,7 @@ impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> {
fn file_text(&self, file_id: FileId) -> Arc<String> {
SourceDatabaseExt::file_text(self.0, file_id)
}
fn resolve_path(&self, path: AnchoredPath) -> Option<FileId> {
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId> {
// FIXME: this *somehow* should be platform agnostic...
let source_root = self.0.file_source_root(path.anchor);
let source_root = self.0.source_root(source_root);
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/cfg/src/cfg_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl CfgExpr {
}
}

fn next_cfg_expr(it: &mut SliceIter<tt::TokenTree>) -> Option<CfgExpr> {
fn next_cfg_expr(it: &mut SliceIter<'_, tt::TokenTree>) -> Option<CfgExpr> {
let name = match it.next() {
None => return None,
Some(tt::TokenTree::Leaf(tt::Leaf::Ident(ident))) => ident.text.clone(),
Expand Down
1 change: 1 addition & 0 deletions src/tools/rust-analyzer/crates/cfg/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! cfg defines conditional compiling options, `cfg` attribute parser and evaluator
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]

mod cfg_expr;
mod dnf;
Expand Down
1 change: 1 addition & 0 deletions src/tools/rust-analyzer/crates/flycheck/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Flycheck provides the functionality needed to run `cargo check` or
//! another compatible command (f.x. clippy) in a background thread and provide
//! LSP diagnostics based on the output of the command.
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]

use std::{
fmt, io,
Expand Down
10 changes: 5 additions & 5 deletions src/tools/rust-analyzer/crates/hir-def/src/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl GenericParams {
}
}

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

pub(crate) fn fill_bounds(
&mut self,
lower_ctx: &LowerCtx,
lower_ctx: &LowerCtx<'_>,
node: &dyn ast::HasTypeBounds,
target: Either<TypeRef, LifetimeRef>,
) {
Expand All @@ -217,7 +217,7 @@ impl GenericParams {
}
}

fn fill_params(&mut self, lower_ctx: &LowerCtx, params: ast::GenericParamList) {
fn fill_params(&mut self, lower_ctx: &LowerCtx<'_>, params: ast::GenericParamList) {
for type_or_const_param in params.type_or_const_params() {
match type_or_const_param {
ast::TypeOrConstParam::Type(type_param) => {
Expand Down Expand Up @@ -259,7 +259,7 @@ impl GenericParams {
}
}

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

fn add_where_predicate_from_bound(
&mut self,
lower_ctx: &LowerCtx,
lower_ctx: &LowerCtx<'_>,
bound: ast::TypeBound,
hrtb_lifetimes: Option<&Box<[Name]>>,
target: Either<TypeRef, LifetimeRef>,
Expand Down
1 change: 1 addition & 0 deletions src/tools/rust-analyzer/crates/hir-def/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//!
//! Note that `hir_def` is a work in progress, so not all of the above is
//! actually true.
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]

#[allow(unused)]
macro_rules! eprintln {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ impl ModCollector<'_, '_> {
let module = self.def_collector.def_map.module_id(self.module_id);
let def_map = &mut self.def_collector.def_map;
let update_def =
|def_collector: &mut DefCollector, id, name: &Name, vis, has_constructor| {
|def_collector: &mut DefCollector<'_>, id, name: &Name, vis, has_constructor| {
def_collector.def_map.modules[self.module_id].scope.declare(id);
def_collector.update(
self.module_id,
Expand Down
7 changes: 5 additions & 2 deletions src/tools/rust-analyzer/crates/hir-def/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub enum GenericArg {
impl Path {
/// Converts an `ast::Path` to `Path`. Works with use trees.
/// It correctly handles `$crate` based path from macro call.
pub fn from_src(path: ast::Path, ctx: &LowerCtx) -> Option<Path> {
pub fn from_src(path: ast::Path, ctx: &LowerCtx<'_>) -> Option<Path> {
lower::lower_path(path, ctx)
}

Expand Down Expand Up @@ -188,7 +188,10 @@ impl<'a> PathSegments<'a> {
}

impl GenericArgs {
pub(crate) fn from_ast(lower_ctx: &LowerCtx, node: ast::GenericArgList) -> Option<GenericArgs> {
pub(crate) fn from_ast(
lower_ctx: &LowerCtx<'_>,
node: ast::GenericArgList,
) -> Option<GenericArgs> {
lower::lower_generic_args(lower_ctx, node)
}

Expand Down
6 changes: 3 additions & 3 deletions src/tools/rust-analyzer/crates/hir-def/src/path/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{

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

pub(super) fn lower_generic_args(
lower_ctx: &LowerCtx,
lower_ctx: &LowerCtx<'_>,
node: ast::GenericArgList,
) -> Option<GenericArgs> {
let mut args = Vec::new();
Expand Down Expand Up @@ -196,7 +196,7 @@ pub(super) fn lower_generic_args(
/// Collect `GenericArgs` from the parts of a fn-like path, i.e. `Fn(X, Y)
/// -> Z` (which desugars to `Fn<(X, Y), Output=Z>`).
fn lower_generic_args_from_fn_path(
ctx: &LowerCtx,
ctx: &LowerCtx<'_>,
params: Option<ast::ParamList>,
ret_type: Option<ast::RetType>,
) -> Option<GenericArgs> {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-def/src/test_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl FileLoader for TestDB {
fn file_text(&self, file_id: FileId) -> Arc<String> {
FileLoaderDelegate(self).file_text(file_id)
}
fn resolve_path(&self, path: AnchoredPath) -> Option<FileId> {
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId> {
FileLoaderDelegate(self).resolve_path(path)
}
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {
Expand Down
10 changes: 5 additions & 5 deletions src/tools/rust-analyzer/crates/hir-def/src/type_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub struct TraitRef {

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

impl TypeRef {
/// Converts an `ast::TypeRef` to a `hir::TypeRef`.
pub fn from_ast(ctx: &LowerCtx, node: ast::Type) -> Self {
pub fn from_ast(ctx: &LowerCtx<'_>, node: ast::Type) -> Self {
match node {
ast::Type::ParenType(inner) => TypeRef::from_ast_opt(ctx, inner.ty()),
ast::Type::TupleType(inner) => {
Expand Down Expand Up @@ -245,7 +245,7 @@ impl TypeRef {
}
}

pub(crate) fn from_ast_opt(ctx: &LowerCtx, node: Option<ast::Type>) -> Self {
pub(crate) fn from_ast_opt(ctx: &LowerCtx<'_>, node: Option<ast::Type>) -> Self {
match node {
Some(node) => TypeRef::from_ast(ctx, node),
None => TypeRef::Error,
Expand Down Expand Up @@ -320,7 +320,7 @@ impl TypeRef {
}

pub(crate) fn type_bounds_from_ast(
lower_ctx: &LowerCtx,
lower_ctx: &LowerCtx<'_>,
type_bounds_opt: Option<ast::TypeBoundList>,
) -> Vec<Interned<TypeBound>> {
if let Some(type_bounds) = type_bounds_opt {
Expand All @@ -331,7 +331,7 @@ pub(crate) fn type_bounds_from_ast(
}

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

match node.kind() {
Expand Down
1 change: 1 addition & 0 deletions src/tools/rust-analyzer/crates/hir-expand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! Specifically, it implements a concept of `MacroFile` -- a file whose syntax
//! tree originates not from the text of some `FileId`, but from some macro
//! expansion.
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]

pub mod db;
pub mod ast_id_map;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-expand/src/mod_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl ModPath {
}
}

pub fn escaped(&self) -> EscapedModPath {
pub fn escaped(&self) -> EscapedModPath<'_> {
EscapedModPath(self)
}

Expand Down
6 changes: 3 additions & 3 deletions src/tools/rust-analyzer/crates/hir-expand/src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ enum Repr {
}

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

impl<'a> fmt::Display for EscapedName<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.0 .0 {
Repr::Text(text) => {
if is_raw_identifier(text) {
Expand Down Expand Up @@ -142,7 +142,7 @@ impl Name {
}
}

pub fn escaped(&self) -> EscapedName {
pub fn escaped(&self) -> EscapedName<'_> {
EscapedName(self)
}
}
Expand Down
Loading

0 comments on commit 0b33563

Please sign in to comment.