) -> Result<ResolvedRule, SsrError> {
let resolver =
Resolver { resolution_scope, placeholders_by_stand_in: rule.placeholders_by_stand_in };
- let resolved_template = if let Some(template) = rule.template {
- Some(resolver.resolve_pattern_tree(template)?)
- } else {
- None
+ let resolved_template = match rule.template {
+ Some(template) => Some(resolver.resolve_pattern_tree(template)?),
+ None => None,
};
Ok(ResolvedRule {
pattern: resolver.resolve_pattern_tree(rule.pattern)?,
fn path_contains_placeholder(&self, path: &ast::Path) -> bool {
if let Some(segment) = path.segment() {
if let Some(name_ref) = segment.name_ref() {
- if self.placeholders_by_stand_in.contains_key(name_ref.text()) {
+ if self.placeholders_by_stand_in.contains_key(name_ref.text().as_str()) {
return true;
}
}
.syntax()
.token_at_offset(resolve_context.offset)
.left_biased()
- .map(|token| token.parent())
+ .and_then(|token| token.parent())
.unwrap_or_else(|| file.syntax().clone());
let node = pick_node_for_resolution(node);
let scope = sema.scope(&node);
// First try resolving the whole path. This will work for things like
// `std::collections::HashMap`, but will fail for things like
// `std::collections::HashMap::new`.
- if let Some(resolution) = self.scope.speculative_resolve(&path) {
+ if let Some(resolution) = self.scope.speculative_resolve(path) {
return Some(resolution);
}
// Resolution failed, try resolving the qualifier (e.g. `std::collections::HashMap` and if
let resolved_qualifier = self.scope.speculative_resolve(&path.qualifier()?)?;
if let hir::PathResolution::Def(hir::ModuleDef::Adt(adt)) = resolved_qualifier {
let name = path.segment()?.name_ref()?;
+ let module = self.scope.module()?;
adt.ty(self.scope.db).iterate_path_candidates(
self.scope.db,
- self.scope.module()?.krate(),
- &self.scope.traits_in_scope(),
+ module.krate(),
+ &self.scope.visible_traits(),
+ Some(module),
None,
|_ty, assoc_item| {
let item_name = assoc_item.name(self.scope.db)?;
- if item_name.to_string().as_str() == name.text() {
+ if item_name.to_smol_str().as_str() == name.text() {
Some(hir::PathResolution::AssocItem(assoc_item))
} else {
None
use syntax::ast::AstNode;
if let Some(path) = ast::Path::cast(path.clone()) {
if let Some(qualifier) = path.qualifier() {
- if let Some(resolved_qualifier) = self.resolve_path(&qualifier) {
- if let hir::PathResolution::Def(hir::ModuleDef::Adt(adt)) = resolved_qualifier {
- return Some(adt.ty(self.scope.db));
- }
+ if let Some(hir::PathResolution::Def(hir::ModuleDef::Adt(adt))) =
+ self.resolve_path(&qualifier)
+ {
+ return Some(adt.ty(self.scope.db));
}
}
}