From 1635d22a355b08309661e3d54d22c6bc2b53e5e1 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Thu, 30 Apr 2020 18:12:52 +0800 Subject: Add test --- crates/ra_hir_ty/src/tests/macros.rs | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'crates') diff --git a/crates/ra_hir_ty/src/tests/macros.rs b/crates/ra_hir_ty/src/tests/macros.rs index 5ddecbdc6..1f796876d 100644 --- a/crates/ra_hir_ty/src/tests/macros.rs +++ b/crates/ra_hir_ty/src/tests/macros.rs @@ -338,6 +338,46 @@ pub fn baz() -> usize { 31usize } assert_eq!("(i32, usize)", type_at_pos(&db, pos)); } +#[test] +fn infer_macro_with_dollar_crate_is_correct_in_trait_associate_type() { + let (db, pos) = TestDB::with_position( + r#" +//- /main.rs crate:main deps:foo +use foo::Trait; + +fn test() { + let msg = foo::Message(foo::MessageRef); + let r = msg.deref(); + r<|>; +} + +//- /lib.rs crate:foo +pub struct MessageRef; +pub struct Message(MessageRef); + +pub trait Trait { + type Target; + fn deref(&self) -> &Self::Target; +} + +#[macro_export] +macro_rules! expand { + () => { + impl Trait for Message { + type Target = $crate::MessageRef; + fn deref(&self) -> &Self::Target { + &self.0 + } + } + } +} + +expand!(); +"#, + ); + assert_eq!("&MessageRef", type_at_pos(&db, pos)); +} + #[test] fn infer_type_value_non_legacy_macro_use_as() { assert_snapshot!( -- cgit v1.2.3 From bdcf6f56589f8367c8cc82f3f4f045dcaf53748d Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Thu, 30 Apr 2020 18:20:13 +0800 Subject: Introduce LowerCtx for path lowering --- crates/ra_assists/src/assist_ctx.rs | 9 ++- crates/ra_assists/src/ast_transform.rs | 2 + .../handlers/replace_qualified_name_with_use.rs | 2 +- crates/ra_hir/src/lib.rs | 3 +- crates/ra_hir/src/source_analyzer.rs | 3 +- crates/ra_hir_def/src/adt.rs | 18 ++++-- crates/ra_hir_def/src/body.rs | 2 + crates/ra_hir_def/src/body/lower.rs | 42 ++++++++++--- crates/ra_hir_def/src/data.rs | 21 ++++--- crates/ra_hir_def/src/generics.rs | 68 +++++++++++++++------- crates/ra_hir_def/src/path.rs | 5 +- crates/ra_hir_def/src/path/lower.rs | 23 +++++--- crates/ra_hir_def/src/type_ref.rs | 52 ++++++++++------- crates/ra_hir_expand/src/hygiene.rs | 2 +- 14 files changed, 172 insertions(+), 80 deletions(-) (limited to 'crates') diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs index 2fe7c3de3..3155a469b 100644 --- a/crates/ra_assists/src/assist_ctx.rs +++ b/crates/ra_assists/src/assist_ctx.rs @@ -1,12 +1,12 @@ //! This module defines `AssistCtx` -- the API surface that is exposed to assists. use hir::Semantics; -use ra_db::FileRange; +use ra_db::{FileRange, Upcast}; use ra_fmt::{leading_indent, reindent}; use ra_ide_db::RootDatabase; use ra_syntax::{ algo::{self, find_covering_element, find_node_at_offset}, - AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize, - TokenAtOffset, + ast, AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, + TextSize, TokenAtOffset, }; use ra_text_edit::TextEditBuilder; @@ -136,6 +136,9 @@ impl<'a> AssistCtx<'a> { pub(crate) fn covering_node_for_range(&self, range: TextRange) -> SyntaxElement { find_covering_element(self.source_file.syntax(), range) } + pub(crate) fn lower_path(&self, path: ast::Path) -> Option { + hir::Path::from_src(path, &hir::Hygiene::new(self.db.upcast(), self.frange.file_id.into())) + } } pub(crate) struct AssistGroup<'a> { diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs index 52b4c82db..9ac65ab39 100644 --- a/crates/ra_assists/src/ast_transform.rs +++ b/crates/ra_assists/src/ast_transform.rs @@ -85,6 +85,7 @@ impl<'a> SubstituteTypeParams<'a> { ast::TypeRef::PathType(path_type) => path_type.path()?, _ => return None, }; + // FIXME: use `hir::Path::from_src` instead. let path = hir::Path::from_ast(path)?; let resolution = self.source_scope.resolve_hir_path(&path)?; match resolution { @@ -128,6 +129,7 @@ impl<'a> QualifyPaths<'a> { // don't try to qualify `Fn(Foo) -> Bar` paths, they are in prelude anyway return None; } + // FIXME: use `hir::Path::from_src` instead. let hir_path = hir::Path::from_ast(p.clone()); let resolution = self.source_scope.resolve_hir_path(&hir_path?)?; match resolution { diff --git a/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs b/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs index 2f02df303..ad59db392 100644 --- a/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs +++ b/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs @@ -27,7 +27,7 @@ pub(crate) fn replace_qualified_name_with_use(ctx: AssistCtx) -> Option return None; } - let hir_path = hir::Path::from_ast(path.clone())?; + let hir_path = ctx.lower_path(path.clone())?; let segments = collect_hir_path_segments(&hir_path)?; if segments.len() < 2 { return None; diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 312ef3814..c5df4ac24 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -70,6 +70,7 @@ pub use hir_def::{ type_ref::Mutability, }; pub use hir_expand::{ - name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, Origin, + hygiene::Hygiene, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, + MacroFile, Origin, }; pub use hir_ty::{display::HirDisplay, CallableDef}; diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs index 74d64c97d..c63d1b847 100644 --- a/crates/ra_hir/src/source_analyzer.rs +++ b/crates/ra_hir/src/source_analyzer.rs @@ -224,7 +224,8 @@ impl SourceAnalyzer { } } // This must be a normal source file rather than macro file. - let hir_path = crate::Path::from_ast(path.clone())?; + let hir_path = + crate::Path::from_src(path.clone(), &Hygiene::new(db.upcast(), self.file_id))?; resolve_hir_path(db, &self.resolver, &hir_path) } diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs index 753becc3d..8eef51828 100644 --- a/crates/ra_hir_def/src/adt.rs +++ b/crates/ra_hir_def/src/adt.rs @@ -12,9 +12,15 @@ use ra_prof::profile; use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner, VisibilityOwner}; use crate::{ - body::CfgExpander, db::DefDatabase, src::HasChildSource, src::HasSource, trace::Trace, - type_ref::TypeRef, visibility::RawVisibility, EnumId, HasModule, LocalEnumVariantId, - LocalFieldId, Lookup, ModuleId, StructId, UnionId, VariantId, + body::{CfgExpander, LowerCtx}, + db::DefDatabase, + src::HasChildSource, + src::HasSource, + trace::Trace, + type_ref::TypeRef, + visibility::RawVisibility, + EnumId, HasModule, LocalEnumVariantId, LocalFieldId, Lookup, ModuleId, StructId, UnionId, + VariantId, }; /// Note that we use `StructData` for unions as well! @@ -198,6 +204,8 @@ fn lower_struct( trace: &mut Trace>, ast: &InFile, ) -> StructKind { + let ctx = LowerCtx::new(db, ast.file_id); + match &ast.value { ast::StructKind::Tuple(fl) => { for (i, fd) in fl.fields().enumerate() { @@ -210,7 +218,7 @@ fn lower_struct( || Either::Left(fd.clone()), || FieldData { name: Name::new_tuple_field(i), - type_ref: TypeRef::from_ast_opt(fd.type_ref()), + type_ref: TypeRef::from_ast_opt(&ctx, fd.type_ref()), visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())), }, ); @@ -228,7 +236,7 @@ fn lower_struct( || Either::Right(fd.clone()), || FieldData { name: fd.name().map(|n| n.as_name()).unwrap_or_else(Name::missing), - type_ref: TypeRef::from_ast_opt(fd.ascribed_type()), + type_ref: TypeRef::from_ast_opt(&ctx, fd.ascribed_type()), visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())), }, ); diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index 890cefcaf..4edaad960 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs @@ -15,6 +15,8 @@ use ra_prof::profile; use ra_syntax::{ast, AstNode, AstPtr}; use rustc_hash::FxHashMap; +pub(crate) use lower::LowerCtx; + use crate::{ attr::Attrs, db::DefDatabase, diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index f467ed3fe..e9dd65b0a 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -3,8 +3,9 @@ use either::Either; use hir_expand::{ + hygiene::Hygiene, name::{name, AsName, Name}, - MacroDefId, MacroDefKind, + HirFileId, MacroDefId, MacroDefKind, }; use ra_arena::Arena; use ra_syntax::{ @@ -26,7 +27,7 @@ use crate::{ LogicOp, MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, Statement, }, item_scope::BuiltinShadowMode, - path::GenericArgs, + path::{GenericArgs, Path}, type_ref::{Mutability, TypeRef}, AdtId, ConstLoc, ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc, @@ -35,6 +36,23 @@ use crate::{ use super::{ExprSource, PatSource}; use ast::AstChildren; +pub(crate) struct LowerCtx { + hygiene: Hygiene, +} + +impl LowerCtx { + pub fn new(db: &dyn DefDatabase, file_id: HirFileId) -> Self { + LowerCtx { hygiene: Hygiene::new(db.upcast(), file_id) } + } + pub fn with_hygiene(hygiene: &Hygiene) -> Self { + LowerCtx { hygiene: hygiene.clone() } + } + + pub fn lower_path(&self, ast: ast::Path) -> Option { + Path::from_src(ast, &self.hygiene) + } +} + pub(super) fn lower( db: &dyn DefDatabase, def: DefWithBodyId, @@ -42,10 +60,13 @@ pub(super) fn lower( params: Option, body: Option, ) -> (Body, BodySourceMap) { + let ctx = LowerCtx::new(db, expander.current_file_id.clone()); + ExprCollector { db, def, expander, + ctx, source_map: BodySourceMap::default(), body: Body { exprs: Arena::default(), @@ -62,7 +83,7 @@ struct ExprCollector<'a> { db: &'a dyn DefDatabase, def: DefWithBodyId, expander: Expander, - + ctx: LowerCtx, body: Body, source_map: BodySourceMap, } @@ -237,7 +258,8 @@ impl ExprCollector<'_> { Vec::new() }; let method_name = e.name_ref().map(|nr| nr.as_name()).unwrap_or_else(Name::missing); - let generic_args = e.type_arg_list().and_then(GenericArgs::from_ast); + let generic_args = + e.type_arg_list().and_then(|it| GenericArgs::from_ast(&self.ctx, it)); self.alloc_expr( Expr::MethodCall { receiver, method_name, args, generic_args }, syntax_ptr, @@ -343,7 +365,7 @@ impl ExprCollector<'_> { } ast::Expr::CastExpr(e) => { let expr = self.collect_expr_opt(e.expr()); - let type_ref = TypeRef::from_ast_opt(e.type_ref()); + let type_ref = TypeRef::from_ast_opt(&self.ctx, e.type_ref()); self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr) } ast::Expr::RefExpr(e) => { @@ -365,12 +387,16 @@ impl ExprCollector<'_> { if let Some(pl) = e.param_list() { for param in pl.params() { let pat = self.collect_pat_opt(param.pat()); - let type_ref = param.ascribed_type().map(TypeRef::from_ast); + let type_ref = + param.ascribed_type().map(|it| TypeRef::from_ast(&self.ctx, it)); args.push(pat); arg_types.push(type_ref); } } - let ret_type = e.ret_type().and_then(|r| r.type_ref()).map(TypeRef::from_ast); + let ret_type = e + .ret_type() + .and_then(|r| r.type_ref()) + .map(|it| TypeRef::from_ast(&self.ctx, it)); let body = self.collect_expr_opt(e.body()); self.alloc_expr(Expr::Lambda { args, arg_types, ret_type, body }, syntax_ptr) } @@ -476,7 +502,7 @@ impl ExprCollector<'_> { .map(|s| match s { ast::Stmt::LetStmt(stmt) => { let pat = self.collect_pat_opt(stmt.pat()); - let type_ref = stmt.ascribed_type().map(TypeRef::from_ast); + let type_ref = stmt.ascribed_type().map(|it| TypeRef::from_ast(&self.ctx, it)); let initializer = stmt.initializer().map(|e| self.collect_expr(e)); Statement::Let { pat, type_ref, initializer } } diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index ccb682f9a..7a2067e49 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs @@ -15,6 +15,7 @@ use ra_syntax::ast::{ use crate::{ attr::Attrs, + body::LowerCtx, db::DefDatabase, path::{path, AssociatedTypeBinding, GenericArgs, Path}, src::HasSource, @@ -40,13 +41,14 @@ impl FunctionData { pub(crate) fn fn_data_query(db: &impl DefDatabase, func: FunctionId) -> Arc { let loc = func.lookup(db); let src = loc.source(db); + let ctx = LowerCtx::new(db, src.file_id); let name = src.value.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); let mut params = Vec::new(); let mut has_self_param = false; if let Some(param_list) = src.value.param_list() { if let Some(self_param) = param_list.self_param() { let self_type = if let Some(type_ref) = self_param.ascribed_type() { - TypeRef::from_ast(type_ref) + TypeRef::from_ast(&ctx, type_ref) } else { let self_type = TypeRef::Path(name![Self].into()); match self_param.kind() { @@ -63,14 +65,14 @@ impl FunctionData { has_self_param = true; } for param in param_list.params() { - let type_ref = TypeRef::from_ast_opt(param.ascribed_type()); + let type_ref = TypeRef::from_ast_opt(&ctx, param.ascribed_type()); params.push(type_ref); } } let attrs = Attrs::new(&src.value, &Hygiene::new(db.upcast(), src.file_id)); let ret_type = if let Some(type_ref) = src.value.ret_type().and_then(|rt| rt.type_ref()) { - TypeRef::from_ast(type_ref) + TypeRef::from_ast(&ctx, type_ref) } else { TypeRef::unit() }; @@ -122,7 +124,8 @@ impl TypeAliasData { let loc = typ.lookup(db); let node = loc.source(db); let name = node.value.name().map_or_else(Name::missing, |n| n.as_name()); - let type_ref = node.value.type_ref().map(TypeRef::from_ast); + let lower_ctx = LowerCtx::new(db, node.file_id); + let type_ref = node.value.type_ref().map(|it| TypeRef::from_ast(&lower_ctx, it)); let vis_default = RawVisibility::default_for_container(loc.container); let visibility = RawVisibility::from_ast_with_default( db, @@ -130,7 +133,7 @@ impl TypeAliasData { node.as_ref().map(|n| n.visibility()), ); let bounds = if let Some(bound_list) = node.value.type_bound_list() { - bound_list.bounds().map(TypeBound::from_ast).collect() + bound_list.bounds().map(|it| TypeBound::from_ast(&lower_ctx, it)).collect() } else { Vec::new() }; @@ -223,9 +226,10 @@ impl ImplData { let _p = profile("impl_data_query"); let impl_loc = id.lookup(db); let src = impl_loc.source(db); + let lower_ctx = LowerCtx::new(db, src.file_id); - let target_trait = src.value.target_trait().map(TypeRef::from_ast); - let target_type = TypeRef::from_ast_opt(src.value.target_type()); + let target_trait = src.value.target_trait().map(|it| TypeRef::from_ast(&lower_ctx, it)); + let target_type = TypeRef::from_ast_opt(&lower_ctx, src.value.target_type()); let is_negative = src.value.excl_token().is_some(); let module_id = impl_loc.container.module(db); @@ -279,8 +283,9 @@ impl ConstData { vis_default: RawVisibility, node: InFile, ) -> ConstData { + let ctx = LowerCtx::new(db, node.file_id); let name = node.value.name().map(|n| n.as_name()); - let type_ref = TypeRef::from_ast_opt(node.value.ascribed_type()); + let type_ref = TypeRef::from_ast_opt(&ctx, node.value.ascribed_type()); let visibility = RawVisibility::from_ast_with_default(db, vis_default, node.map(|n| n.visibility())); ConstData { name, type_ref, visibility } diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs index d850244c4..09a5241f7 100644 --- a/crates/ra_hir_def/src/generics.rs +++ b/crates/ra_hir_def/src/generics.rs @@ -15,6 +15,7 @@ use ra_prof::profile; use ra_syntax::ast::{self, NameOwner, TypeBoundsOwner, TypeParamsOwner}; use crate::{ + body::LowerCtx, child_by_source::ChildBySource, db::DefDatabase, dyn_map::DynMap, @@ -80,11 +81,13 @@ impl GenericParams { fn new(db: &dyn DefDatabase, def: GenericDefId) -> (GenericParams, InFile) { let mut generics = GenericParams { types: Arena::default(), where_predicates: Vec::new() }; let mut sm = ArenaMap::default(); + // FIXME: add `: Sized` bound for everything except for `Self` in traits let file_id = match def { GenericDefId::FunctionId(it) => { let src = it.lookup(db).source(db); - generics.fill(&mut sm, &src.value); + let lower_ctx = LowerCtx::new(db, src.file_id); + generics.fill(&lower_ctx, &mut sm, &src.value); // lower `impl Trait` in arguments let data = db.function_data(it); for param in &data.params { @@ -94,21 +97,25 @@ impl GenericParams { } GenericDefId::AdtId(AdtId::StructId(it)) => { let src = it.lookup(db).source(db); - generics.fill(&mut sm, &src.value); + let lower_ctx = LowerCtx::new(db, src.file_id); + generics.fill(&lower_ctx, &mut sm, &src.value); src.file_id } GenericDefId::AdtId(AdtId::UnionId(it)) => { let src = it.lookup(db).source(db); - generics.fill(&mut sm, &src.value); + let lower_ctx = LowerCtx::new(db, src.file_id); + generics.fill(&lower_ctx, &mut sm, &src.value); src.file_id } GenericDefId::AdtId(AdtId::EnumId(it)) => { let src = it.lookup(db).source(db); - generics.fill(&mut sm, &src.value); + let lower_ctx = LowerCtx::new(db, src.file_id); + generics.fill(&lower_ctx, &mut sm, &src.value); src.file_id } GenericDefId::TraitId(it) => { let src = it.lookup(db).source(db); + let lower_ctx = LowerCtx::new(db, src.file_id); // traits get the Self type as an implicit first type parameter let self_param_id = generics.types.alloc(TypeParamData { @@ -120,14 +127,16 @@ impl GenericParams { // add super traits as bounds on Self // i.e., trait Foo: Bar is equivalent to trait Foo where Self: Bar let self_param = TypeRef::Path(name![Self].into()); - generics.fill_bounds(&src.value, self_param); + generics.fill_bounds(&lower_ctx, &src.value, self_param); - generics.fill(&mut sm, &src.value); + generics.fill(&lower_ctx, &mut sm, &src.value); src.file_id } GenericDefId::TypeAliasId(it) => { let src = it.lookup(db).source(db); - generics.fill(&mut sm, &src.value); + let lower_ctx = LowerCtx::new(db, src.file_id); + + generics.fill(&lower_ctx, &mut sm, &src.value); src.file_id } // Note that we don't add `Self` here: in `impl`s, `Self` is not a @@ -135,7 +144,9 @@ impl GenericParams { // type, so this is handled by the resolver. GenericDefId::ImplId(it) => { let src = it.lookup(db).source(db); - generics.fill(&mut sm, &src.value); + let lower_ctx = LowerCtx::new(db, src.file_id); + + generics.fill(&lower_ctx, &mut sm, &src.value); src.file_id } // We won't be using this ID anyway @@ -145,28 +156,38 @@ impl GenericParams { (generics, InFile::new(file_id, sm)) } - fn fill(&mut self, sm: &mut SourceMap, node: &dyn TypeParamsOwner) { + fn fill(&mut self, lower_ctx: &LowerCtx, sm: &mut SourceMap, node: &dyn TypeParamsOwner) { if let Some(params) = node.type_param_list() { - self.fill_params(sm, params) + self.fill_params(lower_ctx, sm, params) } if let Some(where_clause) = node.where_clause() { - self.fill_where_predicates(where_clause); + self.fill_where_predicates(lower_ctx, where_clause); } } - fn fill_bounds(&mut self, node: &dyn ast::TypeBoundsOwner, type_ref: TypeRef) { + fn fill_bounds( + &mut self, + lower_ctx: &LowerCtx, + node: &dyn ast::TypeBoundsOwner, + type_ref: TypeRef, + ) { for bound in node.type_bound_list().iter().flat_map(|type_bound_list| type_bound_list.bounds()) { - self.add_where_predicate_from_bound(bound, type_ref.clone()); + self.add_where_predicate_from_bound(lower_ctx, bound, type_ref.clone()); } } - fn fill_params(&mut self, sm: &mut SourceMap, params: ast::TypeParamList) { + fn fill_params( + &mut self, + lower_ctx: &LowerCtx, + sm: &mut SourceMap, + params: ast::TypeParamList, + ) { for type_param in params.type_params() { let name = type_param.name().map_or_else(Name::missing, |it| it.as_name()); // FIXME: Use `Path::from_src` - let default = type_param.default_type().map(TypeRef::from_ast); + let default = type_param.default_type().map(|it| TypeRef::from_ast(lower_ctx, it)); let param = TypeParamData { name: Some(name.clone()), default, @@ -176,29 +197,34 @@ impl GenericParams { sm.insert(param_id, Either::Right(type_param.clone())); let type_ref = TypeRef::Path(name.into()); - self.fill_bounds(&type_param, type_ref); + self.fill_bounds(&lower_ctx, &type_param, type_ref); } } - fn fill_where_predicates(&mut self, where_clause: ast::WhereClause) { + fn fill_where_predicates(&mut self, lower_ctx: &LowerCtx, where_clause: ast::WhereClause) { for pred in where_clause.predicates() { let type_ref = match pred.type_ref() { Some(type_ref) => type_ref, None => continue, }; - let type_ref = TypeRef::from_ast(type_ref); + let type_ref = TypeRef::from_ast(lower_ctx, type_ref); for bound in pred.type_bound_list().iter().flat_map(|l| l.bounds()) { - self.add_where_predicate_from_bound(bound, type_ref.clone()); + self.add_where_predicate_from_bound(lower_ctx, bound, type_ref.clone()); } } } - fn add_where_predicate_from_bound(&mut self, bound: ast::TypeBound, type_ref: TypeRef) { + fn add_where_predicate_from_bound( + &mut self, + lower_ctx: &LowerCtx, + bound: ast::TypeBound, + type_ref: TypeRef, + ) { if bound.question_token().is_some() { // FIXME: remove this bound return; } - let bound = TypeBound::from_ast(bound); + let bound = TypeBound::from_ast(lower_ctx, bound); self.where_predicates .push(WherePredicate { target: WherePredicateTarget::TypeRef(type_ref), bound }); } diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs index 162b3c8c7..e84efe2ab 100644 --- a/crates/ra_hir_def/src/path.rs +++ b/crates/ra_hir_def/src/path.rs @@ -7,6 +7,7 @@ use std::{ sync::Arc, }; +use crate::body::LowerCtx; use hir_expand::{ hygiene::Hygiene, name::{AsName, Name}, @@ -244,8 +245,8 @@ impl<'a> PathSegments<'a> { } impl GenericArgs { - pub(crate) fn from_ast(node: ast::TypeArgList) -> Option { - lower::lower_generic_args(node) + pub(crate) fn from_ast(lower_ctx: &LowerCtx, node: ast::TypeArgList) -> Option { + lower::lower_generic_args(lower_ctx, node) } pub(crate) fn empty() -> GenericArgs { diff --git a/crates/ra_hir_def/src/path/lower.rs b/crates/ra_hir_def/src/path/lower.rs index 9ec2e0dcd..e3d237a0a 100644 --- a/crates/ra_hir_def/src/path/lower.rs +++ b/crates/ra_hir_def/src/path/lower.rs @@ -13,6 +13,7 @@ use ra_syntax::ast::{self, AstNode, TypeAscriptionOwner, TypeBoundsOwner}; use super::AssociatedTypeBinding; use crate::{ + body::LowerCtx, path::{GenericArg, GenericArgs, ModPath, Path, PathKind}, type_ref::{TypeBound, TypeRef}, }; @@ -26,6 +27,7 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option let mut type_anchor = None; let mut segments = Vec::new(); let mut generic_args = Vec::new(); + let ctx = LowerCtx::with_hygiene(hygiene); loop { let segment = path.segment()?; @@ -40,9 +42,10 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option Either::Left(name) => { let args = segment .type_arg_list() - .and_then(lower_generic_args) + .and_then(|it| lower_generic_args(&ctx, it)) .or_else(|| { lower_generic_args_from_fn_path( + &ctx, segment.param_list(), segment.ret_type(), ) @@ -60,7 +63,7 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option ast::PathSegmentKind::Type { type_ref, trait_ref } => { assert!(path.qualifier().is_none()); // this can only occur at the first segment - let self_type = TypeRef::from_ast(type_ref?); + let self_type = TypeRef::from_ast(&ctx, type_ref?); match trait_ref { // ::foo @@ -128,10 +131,13 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option } } -pub(super) fn lower_generic_args(node: ast::TypeArgList) -> Option { +pub(super) fn lower_generic_args( + lower_ctx: &LowerCtx, + node: ast::TypeArgList, +) -> Option { let mut args = Vec::new(); for type_arg in node.type_args() { - let type_ref = TypeRef::from_ast_opt(type_arg.type_ref()); + let type_ref = TypeRef::from_ast_opt(lower_ctx, type_arg.type_ref()); args.push(GenericArg::Type(type_ref)); } // lifetimes ignored for now @@ -140,9 +146,9 @@ pub(super) fn lower_generic_args(node: ast::TypeArgList) -> Option let assoc_type_arg: ast::AssocTypeArg = assoc_type_arg; if let Some(name_ref) = assoc_type_arg.name_ref() { let name = name_ref.as_name(); - let type_ref = assoc_type_arg.type_ref().map(TypeRef::from_ast); + let type_ref = assoc_type_arg.type_ref().map(|it| TypeRef::from_ast(lower_ctx, it)); let bounds = if let Some(l) = assoc_type_arg.type_bound_list() { - l.bounds().map(TypeBound::from_ast).collect() + l.bounds().map(|it| TypeBound::from_ast(lower_ctx, it)).collect() } else { Vec::new() }; @@ -159,6 +165,7 @@ pub(super) fn lower_generic_args(node: ast::TypeArgList) -> Option /// 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, params: Option, ret_type: Option, ) -> Option { @@ -167,14 +174,14 @@ fn lower_generic_args_from_fn_path( if let Some(params) = params { let mut param_types = Vec::new(); for param in params.params() { - let type_ref = TypeRef::from_ast_opt(param.ascribed_type()); + let type_ref = TypeRef::from_ast_opt(&ctx, param.ascribed_type()); param_types.push(type_ref); } let arg = GenericArg::Type(TypeRef::Tuple(param_types)); args.push(arg); } if let Some(ret_type) = ret_type { - let type_ref = TypeRef::from_ast_opt(ret_type.type_ref()); + let type_ref = TypeRef::from_ast_opt(&ctx, ret_type.type_ref()); bindings.push(AssociatedTypeBinding { name: name![Output], type_ref: Some(type_ref), diff --git a/crates/ra_hir_def/src/type_ref.rs b/crates/ra_hir_def/src/type_ref.rs index f308c6bdf..5bdad9efd 100644 --- a/crates/ra_hir_def/src/type_ref.rs +++ b/crates/ra_hir_def/src/type_ref.rs @@ -3,7 +3,7 @@ use ra_syntax::ast::{self, TypeAscriptionOwner, TypeBoundsOwner}; -use crate::path::Path; +use crate::{body::LowerCtx, path::Path}; #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] pub enum Mutability { @@ -64,30 +64,34 @@ pub enum TypeBound { impl TypeRef { /// Converts an `ast::TypeRef` to a `hir::TypeRef`. - pub(crate) fn from_ast(node: ast::TypeRef) -> Self { + pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::TypeRef) -> Self { match node { - ast::TypeRef::ParenType(inner) => TypeRef::from_ast_opt(inner.type_ref()), + ast::TypeRef::ParenType(inner) => TypeRef::from_ast_opt(&ctx, inner.type_ref()), ast::TypeRef::TupleType(inner) => { - TypeRef::Tuple(inner.fields().map(TypeRef::from_ast).collect()) + TypeRef::Tuple(inner.fields().map(|it| TypeRef::from_ast(ctx, it)).collect()) } ast::TypeRef::NeverType(..) => TypeRef::Never, ast::TypeRef::PathType(inner) => { // FIXME: Use `Path::from_src` - inner.path().and_then(Path::from_ast).map(TypeRef::Path).unwrap_or(TypeRef::Error) + inner + .path() + .and_then(|it| ctx.lower_path(it)) + .map(TypeRef::Path) + .unwrap_or(TypeRef::Error) } ast::TypeRef::PointerType(inner) => { - let inner_ty = TypeRef::from_ast_opt(inner.type_ref()); + let inner_ty = TypeRef::from_ast_opt(&ctx, inner.type_ref()); let mutability = Mutability::from_mutable(inner.mut_token().is_some()); TypeRef::RawPtr(Box::new(inner_ty), mutability) } ast::TypeRef::ArrayType(inner) => { - TypeRef::Array(Box::new(TypeRef::from_ast_opt(inner.type_ref()))) + TypeRef::Array(Box::new(TypeRef::from_ast_opt(&ctx, inner.type_ref()))) } ast::TypeRef::SliceType(inner) => { - TypeRef::Slice(Box::new(TypeRef::from_ast_opt(inner.type_ref()))) + TypeRef::Slice(Box::new(TypeRef::from_ast_opt(&ctx, inner.type_ref()))) } ast::TypeRef::ReferenceType(inner) => { - let inner_ty = TypeRef::from_ast_opt(inner.type_ref()); + let inner_ty = TypeRef::from_ast_opt(&ctx, inner.type_ref()); let mutability = Mutability::from_mutable(inner.mut_token().is_some()); TypeRef::Reference(Box::new(inner_ty), mutability) } @@ -96,10 +100,13 @@ impl TypeRef { let ret_ty = inner .ret_type() .and_then(|rt| rt.type_ref()) - .map(TypeRef::from_ast) + .map(|it| TypeRef::from_ast(ctx, it)) .unwrap_or_else(|| TypeRef::Tuple(Vec::new())); let mut params = if let Some(pl) = inner.param_list() { - pl.params().map(|p| p.ascribed_type()).map(TypeRef::from_ast_opt).collect() + pl.params() + .map(|p| p.ascribed_type()) + .map(|it| TypeRef::from_ast_opt(&ctx, it)) + .collect() } else { Vec::new() }; @@ -107,19 +114,19 @@ impl TypeRef { TypeRef::Fn(params) } // for types are close enough for our purposes to the inner type for now... - ast::TypeRef::ForType(inner) => TypeRef::from_ast_opt(inner.type_ref()), + ast::TypeRef::ForType(inner) => TypeRef::from_ast_opt(&ctx, inner.type_ref()), ast::TypeRef::ImplTraitType(inner) => { - TypeRef::ImplTrait(type_bounds_from_ast(inner.type_bound_list())) + TypeRef::ImplTrait(type_bounds_from_ast(ctx, inner.type_bound_list())) } ast::TypeRef::DynTraitType(inner) => { - TypeRef::DynTrait(type_bounds_from_ast(inner.type_bound_list())) + TypeRef::DynTrait(type_bounds_from_ast(ctx, inner.type_bound_list())) } } } - pub(crate) fn from_ast_opt(node: Option) -> Self { + pub(crate) fn from_ast_opt(ctx: &LowerCtx, node: Option) -> Self { if let Some(node) = node { - TypeRef::from_ast(node) + TypeRef::from_ast(ctx, node) } else { TypeRef::Error } @@ -180,24 +187,27 @@ impl TypeRef { } } -pub(crate) fn type_bounds_from_ast(type_bounds_opt: Option) -> Vec { +pub(crate) fn type_bounds_from_ast( + lower_ctx: &LowerCtx, + type_bounds_opt: Option, +) -> Vec { if let Some(type_bounds) = type_bounds_opt { - type_bounds.bounds().map(TypeBound::from_ast).collect() + type_bounds.bounds().map(|it| TypeBound::from_ast(lower_ctx, it)).collect() } else { vec![] } } impl TypeBound { - pub(crate) fn from_ast(node: ast::TypeBound) -> Self { + pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::TypeBound) -> Self { match node.kind() { ast::TypeBoundKind::PathType(path_type) => { let path = match path_type.path() { Some(p) => p, None => return TypeBound::Error, }; - // FIXME: Use `Path::from_src` - let path = match Path::from_ast(path) { + + let path = match ctx.lower_path(path) { Some(p) => p, None => return TypeBound::Error, }; diff --git a/crates/ra_hir_expand/src/hygiene.rs b/crates/ra_hir_expand/src/hygiene.rs index 0b41d0e95..53866bbcb 100644 --- a/crates/ra_hir_expand/src/hygiene.rs +++ b/crates/ra_hir_expand/src/hygiene.rs @@ -12,7 +12,7 @@ use crate::{ HirFileId, HirFileIdRepr, MacroCallId, MacroDefKind, }; -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct Hygiene { // This is what `$crate` expands to def_crate: Option, -- cgit v1.2.3 From 44f5e2048ce00b0b417be95c16bae9a9ced1a5e8 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 1 May 2020 19:58:47 +0800 Subject: Remove lower_path from AssistCtx to Semantic --- crates/ra_assists/src/assist_ctx.rs | 9 +++------ .../ra_assists/src/handlers/replace_qualified_name_with_use.rs | 2 +- crates/ra_hir/src/semantics.rs | 7 ++++++- 3 files changed, 10 insertions(+), 8 deletions(-) (limited to 'crates') diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs index 3155a469b..2fe7c3de3 100644 --- a/crates/ra_assists/src/assist_ctx.rs +++ b/crates/ra_assists/src/assist_ctx.rs @@ -1,12 +1,12 @@ //! This module defines `AssistCtx` -- the API surface that is exposed to assists. use hir::Semantics; -use ra_db::{FileRange, Upcast}; +use ra_db::FileRange; use ra_fmt::{leading_indent, reindent}; use ra_ide_db::RootDatabase; use ra_syntax::{ algo::{self, find_covering_element, find_node_at_offset}, - ast, AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, - TextSize, TokenAtOffset, + AstNode, SourceFile, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize, + TokenAtOffset, }; use ra_text_edit::TextEditBuilder; @@ -136,9 +136,6 @@ impl<'a> AssistCtx<'a> { pub(crate) fn covering_node_for_range(&self, range: TextRange) -> SyntaxElement { find_covering_element(self.source_file.syntax(), range) } - pub(crate) fn lower_path(&self, path: ast::Path) -> Option { - hir::Path::from_src(path, &hir::Hygiene::new(self.db.upcast(), self.frange.file_id.into())) - } } pub(crate) struct AssistGroup<'a> { diff --git a/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs b/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs index ad59db392..918e8dd8d 100644 --- a/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs +++ b/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs @@ -27,7 +27,7 @@ pub(crate) fn replace_qualified_name_with_use(ctx: AssistCtx) -> Option return None; } - let hir_path = ctx.lower_path(path.clone())?; + let hir_path = ctx.sema.lower_path(&path)?; let segments = collect_hir_path_segments(&hir_path)?; if segments.len() < 2 { return None; diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs index a0a0f234b..515e5eb17 100644 --- a/crates/ra_hir/src/semantics.rs +++ b/crates/ra_hir/src/semantics.rs @@ -8,7 +8,7 @@ use hir_def::{ resolver::{self, HasResolver, Resolver}, AsMacroCall, TraitId, }; -use hir_expand::ExpansionInfo; +use hir_expand::{hygiene::Hygiene, ExpansionInfo}; use hir_ty::associated_type_shorthand_candidates; use itertools::Itertools; use ra_db::{FileId, FileRange}; @@ -246,6 +246,11 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { self.analyze(path.syntax()).resolve_path(self.db, path) } + pub fn lower_path(&self, path: &ast::Path) -> Option { + let src = self.find_file(path.syntax().clone()); + Path::from_src(path.clone(), &Hygiene::new(self.db.upcast(), src.file_id.into())) + } + pub fn resolve_bind_pat_to_const(&self, pat: &ast::BindPat) -> Option { self.analyze(pat.syntax()).resolve_bind_pat_to_const(self.db, pat) } -- cgit v1.2.3 From 1e20467c3a62f0b8a65605938a2ddb7babcfd8bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Fri, 1 May 2020 15:29:03 +0300 Subject: Bump deps --- crates/ra_hir_ty/Cargo.toml | 2 +- crates/ra_proc_macro_srv/Cargo.toml | 2 +- .../tests/fixtures/test_serialize_proc_macro.txt | 7 +++- crates/ra_proc_macro_srv/src/tests/mod.rs | 6 ++-- crates/ra_project_model/Cargo.toml | 2 +- crates/ra_syntax/Cargo.toml | 4 +-- crates/ra_syntax/src/parsing/lexer.rs | 37 +++++++++++++--------- crates/rust-analyzer/Cargo.toml | 2 +- 8 files changed, 37 insertions(+), 25 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir_ty/Cargo.toml b/crates/ra_hir_ty/Cargo.toml index 04d3cd6a2..65db6d1b0 100644 --- a/crates/ra_hir_ty/Cargo.toml +++ b/crates/ra_hir_ty/Cargo.toml @@ -11,7 +11,7 @@ doctest = false itertools = "0.9.0" arrayvec = "0.5.1" smallvec = "1.2.0" -ena = "0.13.1" +ena = "0.14.0" log = "0.4.8" rustc-hash = "1.1.0" diff --git a/crates/ra_proc_macro_srv/Cargo.toml b/crates/ra_proc_macro_srv/Cargo.toml index ac2d156dc..886e14870 100644 --- a/crates/ra_proc_macro_srv/Cargo.toml +++ b/crates/ra_proc_macro_srv/Cargo.toml @@ -21,4 +21,4 @@ test_utils = { path = "../test_utils" } cargo_metadata = "0.9.1" difference = "2.0.0" # used as proc macro test target -serde_derive = "=1.0.104" +serde_derive = "=1.0.106" diff --git a/crates/ra_proc_macro_srv/src/tests/fixtures/test_serialize_proc_macro.txt b/crates/ra_proc_macro_srv/src/tests/fixtures/test_serialize_proc_macro.txt index 1f5d940fa..6776f5231 100644 --- a/crates/ra_proc_macro_srv/src/tests/fixtures/test_serialize_proc_macro.txt +++ b/crates/ra_proc_macro_srv/src/tests/fixtures/test_serialize_proc_macro.txt @@ -1,5 +1,10 @@ SUBTREE $ PUNCH # [alone] 4294967295 + SUBTREE [] 4294967295 + IDENT doc 4294967295 + SUBTREE () 4294967295 + IDENT hidden 4294967295 + PUNCH # [alone] 4294967295 SUBTREE [] 4294967295 IDENT allow 4294967295 SUBTREE () 4294967295 @@ -184,4 +189,4 @@ SUBTREE $ IDENT end 4294967295 SUBTREE () 4294967295 IDENT __serde_state 4294967295 - PUNCH ; [alone] 4294967295 \ No newline at end of file + PUNCH ; [alone] 4294967295 diff --git a/crates/ra_proc_macro_srv/src/tests/mod.rs b/crates/ra_proc_macro_srv/src/tests/mod.rs index 03f79bc5d..9cf58511c 100644 --- a/crates/ra_proc_macro_srv/src/tests/mod.rs +++ b/crates/ra_proc_macro_srv/src/tests/mod.rs @@ -10,7 +10,7 @@ fn test_derive_serialize_proc_macro() { assert_expand( "serde_derive", "Serialize", - "1.0.104", + "1.0.106", r##"struct Foo {}"##, include_str!("fixtures/test_serialize_proc_macro.txt"), ); @@ -21,7 +21,7 @@ fn test_derive_serialize_proc_macro_failed() { assert_expand( "serde_derive", "Serialize", - "1.0.104", + "1.0.106", r##" struct {} "##, @@ -37,7 +37,7 @@ SUBTREE $ #[test] fn test_derive_proc_macro_list() { - let res = list("serde_derive", "1.0.104").join("\n"); + let res = list("serde_derive", "1.0.106").join("\n"); assert_eq_text!( &res, diff --git a/crates/ra_project_model/Cargo.toml b/crates/ra_project_model/Cargo.toml index b10644b4b..5e651fe70 100644 --- a/crates/ra_project_model/Cargo.toml +++ b/crates/ra_project_model/Cargo.toml @@ -18,7 +18,7 @@ ra_db = { path = "../ra_db" } ra_cfg = { path = "../ra_cfg" } ra_proc_macro = { path = "../ra_proc_macro" } -serde = { version = "1.0.104", features = ["derive"] } +serde = { version = "1.0.106", features = ["derive"] } serde_json = "1.0.48" anyhow = "1.0.26" diff --git a/crates/ra_syntax/Cargo.toml b/crates/ra_syntax/Cargo.toml index 7ffe46c69..c07ff488e 100644 --- a/crates/ra_syntax/Cargo.toml +++ b/crates/ra_syntax/Cargo.toml @@ -13,7 +13,7 @@ doctest = false [dependencies] itertools = "0.9.0" rowan = "0.10.0" -rustc_lexer = { version = "652.0.0", package = "rustc-ap-rustc_lexer" } +rustc_lexer = { version = "656.0.0", package = "rustc-ap-rustc_lexer" } rustc-hash = "1.1.0" arrayvec = "0.5.1" once_cell = "1.3.1" @@ -27,7 +27,7 @@ ra_parser = { path = "../ra_parser" } # ideally, `serde` should be enabled by `rust-analyzer`, but we enable it here # to reduce number of compilations smol_str = { version = "0.1.15", features = ["serde"] } -serde = { version = "1.0.104", features = ["derive"] } +serde = { version = "1.0.106", features = ["derive"] } [dev-dependencies] test_utils = { path = "../test_utils" } diff --git a/crates/ra_syntax/src/parsing/lexer.rs b/crates/ra_syntax/src/parsing/lexer.rs index f450ef4a2..1a5a6dc06 100644 --- a/crates/ra_syntax/src/parsing/lexer.rs +++ b/crates/ra_syntax/src/parsing/lexer.rs @@ -180,7 +180,7 @@ fn rustc_token_kind_to_syntax_kind( return (syntax_kind, None); fn match_literal_kind(kind: &rustc_lexer::LiteralKind) -> (SyntaxKind, Option<&'static str>) { - use rustc_lexer::LiteralKind as LK; + use rustc_lexer::{LexRawStrError, LiteralKind as LK}; #[rustfmt::skip] let syntax_kind = match *kind { @@ -215,21 +215,28 @@ fn rustc_token_kind_to_syntax_kind( return (BYTE_STRING, Some("Missing trailing `\"` symbol to terminate the byte string literal")) } - LK::RawStr { started: true, terminated: true, .. } => RAW_STRING, - LK::RawStr { started: true, terminated: false, .. } => { - return (RAW_STRING, Some("Missing trailing `\"` with `#` symbols to terminate the raw string literal")) - } - LK::RawStr { started: false, .. } => { - return (RAW_STRING, Some("Missing `\"` symbol after `#` symbols to begin the raw string literal")) - } + LK::RawStr(str) => match str.validate() { + Ok(_) => RAW_STRING, + Err(LexRawStrError::InvalidStarter) => return (RAW_STRING, Some("Missing `\"` symbol after `#` symbols to begin the raw string literal")), + Err(LexRawStrError::NoTerminator { expected, found, .. }) => if expected == found { + return (RAW_STRING, Some("Missing trailing `\"` to terminate the raw string literal")) + } else { + return (RAW_STRING, Some("Missing trailing `\"` with `#` symbols to terminate the raw string literal")) + + }, + Err(LexRawStrError::TooManyDelimiters { .. }) => return (RAW_STRING, Some("Too many `#` symbols: raw strings may be delimited by up to 65535 `#` symbols")), + }, + LK::RawByteStr(str) => match str.validate() { + Ok(_) => RAW_BYTE_STRING, + Err(LexRawStrError::InvalidStarter) => return (RAW_BYTE_STRING, Some("Missing `\"` symbol after `#` symbols to begin the raw byte string literal")), + Err(LexRawStrError::NoTerminator { expected, found, .. }) => if expected == found { + return (RAW_BYTE_STRING, Some("Missing trailing `\"` to terminate the raw byte string literal")) + } else { + return (RAW_BYTE_STRING, Some("Missing trailing `\"` with `#` symbols to terminate the raw byte string literal")) - LK::RawByteStr { started: true, terminated: true, .. } => RAW_BYTE_STRING, - LK::RawByteStr { started: true, terminated: false, .. } => { - return (RAW_BYTE_STRING, Some("Missing trailing `\"` with `#` symbols to terminate the raw byte string literal")) - } - LK::RawByteStr { started: false, .. } => { - return (RAW_BYTE_STRING, Some("Missing `\"` symbol after `#` symbols to begin the raw byte string literal")) - } + }, + Err(LexRawStrError::TooManyDelimiters { .. }) => return (RAW_BYTE_STRING, Some("Too many `#` symbols: raw byte strings may be delimited by up to 65535 `#` symbols")), + }, }; (syntax_kind, None) diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml index 0459807fc..8c94f430a 100644 --- a/crates/rust-analyzer/Cargo.toml +++ b/crates/rust-analyzer/Cargo.toml @@ -26,7 +26,7 @@ pico-args = "0.3.1" rand = { version = "0.7.3", features = ["small_rng"] } relative-path = "1.0.0" rustc-hash = "1.1.0" -serde = { version = "1.0.104", features = ["derive"] } +serde = { version = "1.0.106", features = ["derive"] } serde_json = "1.0.48" threadpool = "1.7.1" -- cgit v1.2.3