Skip to content

upgrade to rustc-ap* v642 #1091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
326 changes: 218 additions & 108 deletions Cargo.lock

Large diffs are not rendered by default.

26 changes: 25 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,33 @@ version = "0.1"
optional = true
path = "metadata"

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

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

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

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

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

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

[dependencies.syntax]
package = "rustc-ap-syntax"
version = "610.0.0"
version = "642.0.0"

[dev-dependencies.racer-testutils]
version = "0.1"
Expand Down
41 changes: 27 additions & 14 deletions src/racer/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,25 @@ use crate::typeinf;
use std::path::Path;
use std::rc::Rc;

use rustc_data_structures::sync::Lrc;
use rustc_errors::emitter::Emitter;
use rustc_errors::{Diagnostic, Handler};
use rustc_parse::new_parser_from_source_str;
use rustc_parse::parser::Parser;
use rustc_session::parse::ParseSess;
use rustc_span::edition::Edition;
use rustc_span::Span;
use rustc_span::source_map::{self, FileName, SourceMap};
use syntax::ast::{self, ExprKind, FunctionRetTy, ItemKind, PatKind, UseTree, UseTreeKind};
use syntax::edition::Edition;
use syntax::errors::{emitter::Emitter, Diagnostic, Handler};
use syntax::parse::parser::Parser;
use syntax::parse::{self, ParseSess};
use syntax::source_map::{self, FileName, SourceMap, Span};
use syntax::{self, visit};

struct DummyEmitter;

impl Emitter for DummyEmitter {
fn emit_diagnostic(&mut self, _db: &Diagnostic) {}
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
None
}
fn should_show_explain(&self) -> bool {
false
}
Expand All @@ -29,7 +36,7 @@ impl Emitter for DummyEmitter {
/// construct parser from string
// From syntax/util/parser_testing.rs
pub fn string_to_parser(ps: &ParseSess, source_str: String) -> Parser<'_> {
parse::new_parser_from_source_str(ps, FileName::Custom("racer-file".to_owned()), source_str)
new_parser_from_source_str(ps, FileName::Custom("racer-file".to_owned()), source_str)
}

/// Get parser from string s and then apply closure f to it
Expand Down Expand Up @@ -217,11 +224,14 @@ pub struct FnArgVisitor {
impl<'ast> visit::Visitor<'ast> for FnArgVisitor {
fn visit_fn(
&mut self,
_fk: visit::FnKind<'_>,
fd: &ast::FnDecl,
fk: visit::FnKind<'_>,
_: source_map::Span,
_: ast::NodeId,
) {
let fd = match fk {
visit::FnKind::Fn(_, _, ref fn_sig, _, _) => &*fn_sig.decl,
visit::FnKind::Closure(ref fn_decl, _) => fn_decl,
};
debug!("[FnArgVisitor::visit_fn] inputs: {:?}", fd.inputs);
self.idents = fd
.inputs
Expand Down Expand Up @@ -495,7 +505,7 @@ impl<'c, 's, 'ast> visit::Visitor<'ast> for ExprTypeVisitor<'c, 's> {
);
//walk_expr(self, ex, e)
match expr.kind {
ExprKind::Unary(_, ref expr) | ExprKind::AddrOf(_, ref expr) => {
ExprKind::Unary(_, ref expr) | ExprKind::AddrOf(_, _, ref expr) => {
self.visit_expr(expr);
}
ExprKind::Path(_, ref path) => {
Expand Down Expand Up @@ -924,13 +934,13 @@ 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 generics, ref otrait, ref self_typ, _) = item.kind {
if let ItemKind::Impl { ref generics, ref of_trait, ref self_ty, .. } = item.kind {
let impl_start = self.offset + get_span_start(item.span).into();
self.result = ImplHeader::new(
generics,
self.filepath,
otrait,
self_typ,
of_trait,
self_ty,
self.offset,
self.local,
impl_start,
Expand Down Expand Up @@ -1015,7 +1025,7 @@ impl<'ast> visit::Visitor<'ast> for StaticVisitor {
match i.kind {
ItemKind::Const(ref ty, ref _expr) => self.ty = Ty::from_ast(ty, &self.scope),
ItemKind::Static(ref ty, m, ref _expr) => {
self.is_mutable = m == ast::Mutability::Mutable;
self.is_mutable = m == ast::Mutability::Mut;
self.ty = Ty::from_ast(ty, &self.scope);
}
_ => {}
Expand Down Expand Up @@ -1229,10 +1239,13 @@ impl<'ast> visit::Visitor<'ast> for FnOutputVisitor {
fn visit_fn(
&mut self,
kind: visit::FnKind<'_>,
fd: &ast::FnDecl,
_: source_map::Span,
_: ast::NodeId,
) {
let fd = match kind {
visit::FnKind::Fn(_, _, ref fn_sig, _, _) => &*fn_sig.decl,
visit::FnKind::Closure(ref fn_decl, _) => fn_decl,
};
self.is_async = kind
.header()
.map(|header| header.asyncness.node.is_async())
Expand Down
22 changes: 11 additions & 11 deletions src/racer/ast_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ use syntax::ast::{
self, GenericBound, GenericBounds, GenericParamKind, LitKind, PatKind, TraitRef, TyKind,
WherePredicate,
};
use rustc_span::source_map;
use rustc_ast_pretty::pprust;
// we can only re-export types without thread-local interned string
pub use syntax::ast::{BindingMode, Mutability};
use syntax::print::pprust;
use syntax::source_map;

/// The leaf of a `use` statement.
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -102,7 +102,7 @@ impl Ty {
let mut ty = self;
// TODO: it's incorrect
for _ in 0..count {
ty = Ty::RefPtr(Box::new(ty), Mutability::Immutable);
ty = Ty::RefPtr(Box::new(ty), Mutability::Not);
}
ty
}
Expand Down Expand Up @@ -159,11 +159,11 @@ impl Ty {
LitKind::Byte(_) => make_match(PrimKind::U8),
LitKind::Char(_) => make_match(PrimKind::Char),
LitKind::Int(_, int_ty) => make_match(PrimKind::from_litint(int_ty)),
LitKind::Float(_, float_ty) => match float_ty {
LitKind::Float(_, ast::LitFloatType::Unsuffixed) => make_match(PrimKind::F32),
LitKind::Float(_, ast::LitFloatType::Suffixed(float_ty)) => match float_ty {
ast::FloatTy::F32 => make_match(PrimKind::F32),
ast::FloatTy::F64 => make_match(PrimKind::F64),
},
LitKind::FloatUnsuffixed(_) => make_match(PrimKind::F32),
LitKind::Bool(_) => make_match(PrimKind::Bool),
LitKind::Err(_) => None,
}
Expand Down Expand Up @@ -232,12 +232,12 @@ impl fmt::Display for Ty {
write!(f, "]")
}
Ty::RefPtr(ref ty, mutab) => match mutab {
Mutability::Immutable => write!(f, "&{}", ty),
Mutability::Mutable => write!(f, "&mut {}", ty),
Mutability::Not => write!(f, "&{}", ty),
Mutability::Mut => write!(f, "&mut {}", ty),
},
Ty::Ptr(ref ty, mutab) => match mutab {
Mutability::Immutable => write!(f, "*const {}", ty),
Mutability::Mutable => write!(f, "*mut {}", ty),
Mutability::Not => write!(f, "*const {}", ty),
Mutability::Mut => write!(f, "*mut {}", ty),
},
Ty::TraitObject(ref bounds) => {
write!(f, "<")?;
Expand Down Expand Up @@ -449,7 +449,7 @@ impl Path {
}
// TODO: support inputs in GenericArgs::Parenthesized (A path like `Foo(A,B) -> C`)
if let ast::GenericArgs::Parenthesized(ref paren_args) = **params {
if let Some(ref ty) = paren_args.output {
if let ast::FunctionRetTy::Ty(ref ty) = paren_args.output {
output = Ty::from_ast(&*ty, scope);
}
}
Expand Down Expand Up @@ -867,7 +867,7 @@ impl GenericsArgs {
WherePredicate::BoundPredicate(bound) => match bound.bounded_ty.kind {
TyKind::Path(ref _qself, ref path) => {
if let Some(seg) = path.segments.get(0) {
let name = seg.ident.name.as_str();
let name = pprust::path_segment_to_string(&seg);
let bound =
TraitBounds::from_generic_bounds(&bound.bounds, &filepath, offset);
if let Some(tp) = args.iter_mut().find(|tp| tp.name == name) {
Expand Down
2 changes: 1 addition & 1 deletion src/racer/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::ops::{Deref, Range};
use std::rc::Rc;
use std::{fmt, vec};
use std::{path, str};
use syntax::source_map;
use rustc_span::source_map;

use crate::ast;
use crate::fileres;
Expand Down
4 changes: 2 additions & 2 deletions src/racer/snippets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::ast::with_error_checking_parse;
use crate::core::{Match, Session};
use crate::typeinf::get_function_declaration;

use syntax::ast::ImplItemKind;
use syntax::ast::AssocItemKind;

/// Returns completion snippets usable by some editors
///
Expand Down Expand Up @@ -58,7 +58,7 @@ impl MethodInfo {
with_error_checking_parse(decorated, |p| {
let mut at_end = false;
if let Ok(method) = p.parse_impl_item(&mut at_end) {
if let ImplItemKind::Method(ref msig, _) = method.kind {
if let AssocItemKind::Fn(ref msig, _) = method.kind {
let decl = &msig.decl;
return Some(MethodInfo {
// ident.as_str calls Ident.name.as_str
Expand Down