Skip to content

Commit

Permalink
Use rustc_private and bump nightly
Browse files Browse the repository at this point in the history
This moves away from the rustc-ap crates and uses rustc-dev instead. It
also bumps this crate to use the latest nightly.
  • Loading branch information
flip1995 committed Dec 13, 2021
1 parent 48ed93d commit c057f55
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 865 deletions.
912 changes: 89 additions & 823 deletions Cargo.lock

Large diffs are not rendered by default.

32 changes: 4 additions & 28 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,6 @@ version = "0.1"
optional = true
path = "metadata"

[dependencies.rustc_ast_pretty]
package = "rustc-ap-rustc_ast_pretty"
version = "722.0.0"

[dependencies.rustc_data_structures]
package = "rustc-ap-rustc_data_structures"
version = "722.0.0"

[dependencies.rustc_errors]
package = "rustc-ap-rustc_errors"
version = "722.0.0"

[dependencies.rustc_parse]
package = "rustc-ap-rustc_parse"
version = "722.0.0"

[dependencies.rustc_session]
package = "rustc-ap-rustc_session"
version = "722.0.0"

[dependencies.rustc_span]
package = "rustc-ap-rustc_span"
version = "722.0.0"

[dependencies.rustc_ast]
package = "rustc-ap-rustc_ast"
version = "722.0.0"

[dev-dependencies.racer-testutils]
version = "0.1"
path = "testutils"
Expand All @@ -77,3 +49,7 @@ nightly = []

[workspace]
members = ["interner", "metadata", "testutils"]

[package.metadata.rust-analyzer]
# This package uses #[feature(rustc_private)]
rustc_private = true
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ From 2.1, racer needs **nightly rust**

If you're using rustup, run
```
rustup toolchain add nightly
rustup toolchain install nightly
rustup component add rustc-dev --toolchain=nightly
```

_Note: The second command adds the `rustc-dev` component to the nightly
toolchain, which is necessary to compile Racer._

#### Cargo
Internally, racer calls cargo as a CLI tool, so please make sure cargo is installed

Expand Down
4 changes: 2 additions & 2 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2021-06-06"
components = ["rust-src"]
channel = "nightly-2021-12-13"
components = ["rust-src", "rustc-dev"]
16 changes: 8 additions & 8 deletions src/racer/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ where
F: FnOnce(&mut Parser<'_>) -> Option<T>,
{
// FIXME: Set correct edition based on the edition of the target crate.
rustc_span::with_session_globals(Edition::Edition2018, || {
rustc_span::create_session_if_not_set_then(Edition::Edition2018, |_| {
let codemap = Rc::new(SourceMap::new(source_map::FilePathMapping::empty()));
// We use DummyEmitter here not to print error messages to stderr
let handler = Handler::with_emitter(false, None, Box::new(DummyEmitter {}));
Expand Down Expand Up @@ -291,7 +291,7 @@ fn destructure_pattern_to_ty(
}
_ => panic!("Expecting TyTuple"),
},
PatKind::TupleStruct(ref path, ref children) => {
PatKind::TupleStruct(_, ref path, ref children) => {
let m = resolve_ast_path(path, &scope.filepath, scope.point, session)?;
let contextty = path_to_match(ty.clone(), session);
for (i, p) in children.iter().enumerate() {
Expand All @@ -314,7 +314,7 @@ fn destructure_pattern_to_ty(
}
None
}
PatKind::Struct(ref path, ref children, _) => {
PatKind::Struct(_, ref path, ref children, _) => {
let m = resolve_ast_path(path, &scope.filepath, scope.point, session)?;
let contextty = path_to_match(ty.clone(), session);
for child in children {
Expand Down Expand Up @@ -356,7 +356,7 @@ impl<'c, 's, 'ast> visit::Visitor<'ast> for LetTypeVisitor<'c, 's> {
fn visit_local(&mut self, local: &ast::Local) {
let ty = match &local.ty {
Some(annon) => Ty::from_ast(&*annon, &self.scope),
None => local.init.as_ref().and_then(|initexpr| {
None => local.kind.init().as_ref().and_then(|initexpr| {
debug!("[LetTypeVisitor] initexpr is {:?}", initexpr.kind);
let mut v = ExprTypeVisitor::new(self.scope.clone(), self.session);
v.visit_expr(initexpr);
Expand Down Expand Up @@ -898,7 +898,7 @@ pub struct TypeVisitor<'s> {
impl<'ast, 's> visit::Visitor<'ast> for TypeVisitor<'s> {
fn visit_item(&mut self, item: &ast::Item) {
if let ItemKind::TyAlias(ref ty_kind) = item.kind {
if let Some(ref ty) = ty_kind.3 {
if let Some(ref ty) = ty_kind.ty {
self.name = Some(item.ident.name.to_string());
self.type_ = Ty::from_ast(&ty, self.scope);
debug!("typevisitor type is {:?}", self.type_);
Expand Down Expand Up @@ -943,7 +943,7 @@ impl<'p> ImplVisitor<'p> {
impl<'ast, 'p> visit::Visitor<'ast> for ImplVisitor<'p> {
fn visit_item(&mut self, item: &ast::Item) {
if let ItemKind::Impl(ref impl_kind) = item.kind {
let ast::ImplKind {
let ast::Impl {
ref generics,
ref of_trait,
ref self_ty,
Expand Down Expand Up @@ -1283,7 +1283,7 @@ where
fn visit_item(&mut self, item: &ast::Item) {
if let ItemKind::Trait(ref trait_kind) = item.kind {
self.result = Some(TraitBounds::from_generic_bounds(
&trait_kind.3,
&trait_kind.bounds,
&self.file_path,
self.offset,
));
Expand Down Expand Up @@ -1338,7 +1338,7 @@ impl<'ast, 'r, 's> visit::Visitor<'ast> for IfLetVisitor<'r, 's> {
fn visit_expr(&mut self, ex: &'ast ast::Expr) {
match &ex.kind {
ExprKind::If(let_stmt, ..) | ExprKind::While(let_stmt, ..) => {
if let ExprKind::Let(pat, expr) = &let_stmt.kind {
if let ExprKind::Let(pat, expr, _span) = &let_stmt.kind {
self.let_pat = Some(Pat::from_ast(&pat.kind, &self.scope));
let mut expr_visitor = ExprTypeVisitor::new(self.scope.clone(), self.session);
expr_visitor.visit_expr(expr);
Expand Down
4 changes: 2 additions & 2 deletions src/racer/ast_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,15 @@ impl Pat {
match pat {
PatKind::Wild => Pat::Wild,
PatKind::Ident(bi, ident, _) => Pat::Ident(*bi, ident.to_string()),
PatKind::Struct(path, fields, _) => {
PatKind::Struct(_, path, fields, _) => {
let path = Path::from_ast(path, scope);
let fields = fields
.iter()
.map(|fld| FieldPat::from_ast(&fld, scope))
.collect();
Pat::Struct(path, fields)
}
PatKind::TupleStruct(path, pats) => {
PatKind::TupleStruct(_, path, pats) => {
let path = Path::from_ast(path, scope);
let pats = pats
.iter()
Expand Down
9 changes: 9 additions & 0 deletions src/racer/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![cfg_attr(feature = "nightly", feature(test))]
#![feature(control_flow_enum)]
#![feature(try_trait_v2)]
#![feature(rustc_private)]

#[macro_use]
extern crate log;
Expand All @@ -12,6 +13,14 @@ extern crate bitflags;
#[macro_use]
extern crate derive_more;

extern crate rustc_ast;
extern crate rustc_ast_pretty;
extern crate rustc_data_structures;
extern crate rustc_errors;
extern crate rustc_parse;
extern crate rustc_session;
extern crate rustc_span;

#[macro_use]
mod testutils;
#[macro_use]
Expand Down
2 changes: 1 addition & 1 deletion src/racer/snippets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl MethodInfo {
with_error_checking_parse(decorated, |p| {
if let Ok(Some(Some(method))) = p.parse_impl_item(ForceCollect::No) {
if let AssocItemKind::Fn(ref fn_kind) = method.kind {
let decl = &fn_kind.1.decl;
let decl = &fn_kind.sig.decl;
return Some(MethodInfo {
// ident.as_str calls Ident.name.as_str
name: method.ident.name.to_string(),
Expand Down

0 comments on commit c057f55

Please sign in to comment.