Auto merge of #12826 - fasterthanlime:in-tree-warnings, r=Veykril

Enable (and fix) extra lint groups required for in-tree build

This enables 3 lint groups that are required to build rust-analyzer as an "in-tree" (git subtree) tool in `rust-lang/rust`, and fixes all relevant diagnostics.

This change is tracked in:

  * https://github.com/rust-lang/rust-analyzer/issues/12818

Maintainer impact: more warnings, should be easy enough to fix them (it's mostly looking out for "rust-2015-isms", the lint group is poorly named). If you forget some, they'll show up during a `ra=>rust` sync.
This commit is contained in:
bors 2022-07-20 13:14:36 +00:00
commit 28bab681e9
262 changed files with 1125 additions and 896 deletions

View file

@ -17,7 +17,7 @@ pub struct Change {
} }
impl fmt::Debug for 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"); let mut d = fmt.debug_struct("Change");
if let Some(roots) = &self.roots { if let Some(roots) = &self.roots {
d.field("roots", roots); d.field("roots", roots);

View file

@ -104,7 +104,7 @@ impl CrateName {
} }
impl fmt::Display for 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) self.0.fmt(f)
} }
} }
@ -187,7 +187,7 @@ impl From<CrateName> for CrateDisplayName {
} }
impl fmt::Display 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) self.crate_name.fmt(f)
} }
} }

View file

@ -1,4 +1,7 @@
//! base_db defines basic database traits. The concrete DB is defined by ide. //! 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 input;
mod change; mod change;
pub mod fixture; pub mod fixture;
@ -54,7 +57,7 @@ pub const DEFAULT_LRU_CAP: usize = 128;
pub trait FileLoader { pub trait FileLoader {
/// Text of the file. /// Text of the file.
fn file_text(&self, file_id: FileId) -> Arc<String>; 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>>; fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>>;
} }
@ -113,7 +116,7 @@ impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> {
fn file_text(&self, file_id: FileId) -> Arc<String> { fn file_text(&self, file_id: FileId) -> Arc<String> {
SourceDatabaseExt::file_text(self.0, file_id) 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... // FIXME: this *somehow* should be platform agnostic...
let source_root = self.0.file_source_root(path.anchor); let source_root = self.0.file_source_root(path.anchor);
let source_root = self.0.source_root(source_root); let source_root = self.0.source_root(source_root);

View file

@ -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() { let name = match it.next() {
None => return None, None => return None,
Some(tt::TokenTree::Leaf(tt::Leaf::Ident(ident))) => ident.text.clone(), Some(tt::TokenTree::Leaf(tt::Leaf::Ident(ident))) => ident.text.clone(),

View file

@ -1,5 +1,7 @@
//! cfg defines conditional compiling options, `cfg` attribute parser and evaluator //! 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 cfg_expr;
mod dnf; mod dnf;
#[cfg(test)] #[cfg(test)]

View file

@ -2,6 +2,8 @@
//! another compatible command (f.x. clippy) in a background thread and provide //! another compatible command (f.x. clippy) in a background thread and provide
//! LSP diagnostics based on the output of the command. //! LSP diagnostics based on the output of the command.
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
use std::{ use std::{
fmt, io, fmt, io,
process::{ChildStderr, ChildStdout, Command, Stdio}, process::{ChildStderr, ChildStdout, Command, Stdio},

View file

@ -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() { if let Some(params) = node.generic_param_list() {
self.fill_params(lower_ctx, params) self.fill_params(lower_ctx, params)
} }
@ -206,7 +206,7 @@ impl GenericParams {
pub(crate) fn fill_bounds( pub(crate) fn fill_bounds(
&mut self, &mut self,
lower_ctx: &LowerCtx, lower_ctx: &LowerCtx<'_>,
node: &dyn ast::HasTypeBounds, node: &dyn ast::HasTypeBounds,
target: Either<TypeRef, LifetimeRef>, target: Either<TypeRef, LifetimeRef>,
) { ) {
@ -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() { for type_or_const_param in params.type_or_const_params() {
match type_or_const_param { match type_or_const_param {
ast::TypeOrConstParam::Type(type_param) => { ast::TypeOrConstParam::Type(type_param) => {
@ -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() { for pred in where_clause.predicates() {
let target = if let Some(type_ref) = pred.ty() { let target = if let Some(type_ref) = pred.ty() {
Either::Left(TypeRef::from_ast(lower_ctx, type_ref)) Either::Left(TypeRef::from_ast(lower_ctx, type_ref))
@ -293,7 +293,7 @@ impl GenericParams {
fn add_where_predicate_from_bound( fn add_where_predicate_from_bound(
&mut self, &mut self,
lower_ctx: &LowerCtx, lower_ctx: &LowerCtx<'_>,
bound: ast::TypeBound, bound: ast::TypeBound,
hrtb_lifetimes: Option<&Box<[Name]>>, hrtb_lifetimes: Option<&Box<[Name]>>,
target: Either<TypeRef, LifetimeRef>, target: Either<TypeRef, LifetimeRef>,

View file

@ -7,6 +7,8 @@
//! Note that `hir_def` is a work in progress, so not all of the above is //! Note that `hir_def` is a work in progress, so not all of the above is
//! actually true. //! actually true.
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
#[allow(unused)] #[allow(unused)]
macro_rules! eprintln { macro_rules! eprintln {
($($tt:tt)*) => { stdx::eprintln!($($tt)*) }; ($($tt:tt)*) => { stdx::eprintln!($($tt)*) };

View file

@ -1509,7 +1509,7 @@ impl ModCollector<'_, '_> {
let module = self.def_collector.def_map.module_id(self.module_id); let module = self.def_collector.def_map.module_id(self.module_id);
let def_map = &mut self.def_collector.def_map; let def_map = &mut self.def_collector.def_map;
let update_def = 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.def_map.modules[self.module_id].scope.declare(id);
def_collector.update( def_collector.update(
self.module_id, self.module_id,

View file

@ -88,7 +88,7 @@ pub enum GenericArg {
impl Path { impl Path {
/// Converts an `ast::Path` to `Path`. Works with use trees. /// Converts an `ast::Path` to `Path`. Works with use trees.
/// It correctly handles `$crate` based path from macro call. /// 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) lower::lower_path(path, ctx)
} }
@ -188,7 +188,10 @@ impl<'a> PathSegments<'a> {
} }
impl GenericArgs { 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) lower::lower_generic_args(lower_ctx, node)
} }

View file

@ -15,7 +15,7 @@ use crate::{
/// Converts an `ast::Path` to `Path`. Works with use trees. /// Converts an `ast::Path` to `Path`. Works with use trees.
/// It correctly handles `$crate` based path from macro call. /// 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 kind = PathKind::Plain;
let mut type_anchor = None; let mut type_anchor = None;
let mut segments = Vec::new(); let mut segments = Vec::new();
@ -149,7 +149,7 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option<Path> {
} }
pub(super) fn lower_generic_args( pub(super) fn lower_generic_args(
lower_ctx: &LowerCtx, lower_ctx: &LowerCtx<'_>,
node: ast::GenericArgList, node: ast::GenericArgList,
) -> Option<GenericArgs> { ) -> Option<GenericArgs> {
let mut args = Vec::new(); let mut args = Vec::new();
@ -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) /// Collect `GenericArgs` from the parts of a fn-like path, i.e. `Fn(X, Y)
/// -> Z` (which desugars to `Fn<(X, Y), Output=Z>`). /// -> Z` (which desugars to `Fn<(X, Y), Output=Z>`).
fn lower_generic_args_from_fn_path( fn lower_generic_args_from_fn_path(
ctx: &LowerCtx, ctx: &LowerCtx<'_>,
params: Option<ast::ParamList>, params: Option<ast::ParamList>,
ret_type: Option<ast::RetType>, ret_type: Option<ast::RetType>,
) -> Option<GenericArgs> { ) -> Option<GenericArgs> {

View file

@ -73,7 +73,7 @@ impl FileLoader for TestDB {
fn file_text(&self, file_id: FileId) -> Arc<String> { fn file_text(&self, file_id: FileId) -> Arc<String> {
FileLoaderDelegate(self).file_text(file_id) 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) FileLoaderDelegate(self).resolve_path(path)
} }
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> { fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {

View file

@ -86,7 +86,7 @@ pub struct TraitRef {
impl TraitRef { impl TraitRef {
/// Converts an `ast::PathType` to a `hir::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` // FIXME: Use `Path::from_src`
match node { match node {
ast::Type::PathType(path) => { ast::Type::PathType(path) => {
@ -159,7 +159,7 @@ pub enum TraitBoundModifier {
impl TypeRef { impl TypeRef {
/// Converts an `ast::TypeRef` to a `hir::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 { match node {
ast::Type::ParenType(inner) => TypeRef::from_ast_opt(ctx, inner.ty()), ast::Type::ParenType(inner) => TypeRef::from_ast_opt(ctx, inner.ty()),
ast::Type::TupleType(inner) => { ast::Type::TupleType(inner) => {
@ -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 { match node {
Some(node) => TypeRef::from_ast(ctx, node), Some(node) => TypeRef::from_ast(ctx, node),
None => TypeRef::Error, None => TypeRef::Error,
@ -320,7 +320,7 @@ impl TypeRef {
} }
pub(crate) fn type_bounds_from_ast( pub(crate) fn type_bounds_from_ast(
lower_ctx: &LowerCtx, lower_ctx: &LowerCtx<'_>,
type_bounds_opt: Option<ast::TypeBoundList>, type_bounds_opt: Option<ast::TypeBoundList>,
) -> Vec<Interned<TypeBound>> { ) -> Vec<Interned<TypeBound>> {
if let Some(type_bounds) = type_bounds_opt { if let Some(type_bounds) = type_bounds_opt {
@ -331,7 +331,7 @@ pub(crate) fn type_bounds_from_ast(
} }
impl TypeBound { 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()?); let lower_path_type = |path_type: ast::PathType| ctx.lower_path(path_type.path()?);
match node.kind() { match node.kind() {

View file

@ -4,6 +4,8 @@
//! tree originates not from the text of some `FileId`, but from some macro //! tree originates not from the text of some `FileId`, but from some macro
//! expansion. //! expansion.
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
pub mod db; pub mod db;
pub mod ast_id_map; pub mod ast_id_map;
pub mod name; pub mod name;

View file

@ -102,7 +102,7 @@ impl ModPath {
} }
} }
pub fn escaped(&self) -> EscapedModPath { pub fn escaped(&self) -> EscapedModPath<'_> {
EscapedModPath(self) EscapedModPath(self)
} }

View file

@ -21,7 +21,7 @@ enum Repr {
} }
impl fmt::Display for Name { 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 { match &self.0 {
Repr::Text(text) => fmt::Display::fmt(&text, f), Repr::Text(text) => fmt::Display::fmt(&text, f),
Repr::TupleField(idx) => fmt::Display::fmt(&idx, f), Repr::TupleField(idx) => fmt::Display::fmt(&idx, f),
@ -35,7 +35,7 @@ fn is_raw_identifier(name: &str) -> bool {
} }
impl<'a> fmt::Display for EscapedName<'a> { 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 { match &self.0 .0 {
Repr::Text(text) => { Repr::Text(text) => {
if is_raw_identifier(text) { if is_raw_identifier(text) {
@ -142,7 +142,7 @@ impl Name {
} }
} }
pub fn escaped(&self) -> EscapedName { pub fn escaped(&self) -> EscapedName<'_> {
EscapedName(self) EscapedName(self)
} }
} }

View file

@ -70,7 +70,10 @@ impl Iterator for Autoderef<'_, '_> {
} }
} }
pub(crate) fn autoderef_step(table: &mut InferenceTable, ty: Ty) -> Option<(AutoderefKind, Ty)> { pub(crate) fn autoderef_step(
table: &mut InferenceTable<'_>,
ty: Ty,
) -> Option<(AutoderefKind, Ty)> {
if let Some(derefed) = builtin_deref(&ty) { if let Some(derefed) = builtin_deref(&ty) {
Some((AutoderefKind::Builtin, table.resolve_ty_shallow(derefed))) Some((AutoderefKind::Builtin, table.resolve_ty_shallow(derefed)))
} else { } else {
@ -94,7 +97,7 @@ pub fn autoderef<'a>(
v.into_iter() v.into_iter()
} }
pub(crate) fn deref(table: &mut InferenceTable, ty: Ty) -> Option<Ty> { pub(crate) fn deref(table: &mut InferenceTable<'_>, ty: Ty) -> Option<Ty> {
let _p = profile::span("deref"); let _p = profile::span("deref");
autoderef_step(table, ty).map(|(_, ty)| ty) autoderef_step(table, ty).map(|(_, ty)| ty)
} }
@ -107,7 +110,7 @@ fn builtin_deref(ty: &Ty) -> Option<&Ty> {
} }
} }
fn deref_by_trait(table: &mut InferenceTable, ty: Ty) -> Option<Ty> { fn deref_by_trait(table: &mut InferenceTable<'_>, ty: Ty) -> Option<Ty> {
let _p = profile::span("deref_by_trait"); let _p = profile::span("deref_by_trait");
if table.resolve_ty_shallow(&ty).inference_var(Interner).is_some() { if table.resolve_ty_shallow(&ty).inference_var(Interner).is_some() {
// don't try to deref unknown variables // don't try to deref unknown variables

View file

@ -111,7 +111,7 @@ impl<D> TyBuilder<D> {
this this
} }
pub(crate) fn fill_with_inference_vars(self, table: &mut InferenceTable) -> Self { pub(crate) fn fill_with_inference_vars(self, table: &mut InferenceTable<'_>) -> Self {
self.fill(|x| match x { self.fill(|x| match x {
ParamKind::Type => GenericArgData::Ty(table.new_type_var()).intern(Interner), ParamKind::Type => GenericArgData::Ty(table.new_type_var()).intern(Interner),
ParamKind::Const(ty) => { ParamKind::Const(ty) => {

View file

@ -292,7 +292,7 @@ impl<'a> PatCtxt<'a> {
} }
impl HirDisplay for Pat { impl HirDisplay for Pat {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
match &*self.kind { match &*self.kind {
PatKind::Wild => write!(f, "_"), PatKind::Wild => write!(f, "_"),
PatKind::Binding { name, subpattern } => { PatKind::Binding { name, subpattern } => {
@ -394,11 +394,11 @@ impl HirDisplay for Pat {
struct WriteWith<F>(F) struct WriteWith<F>(F)
where where
F: Fn(&mut HirFormatter) -> Result<(), HirDisplayError>; F: Fn(&mut HirFormatter<'_>) -> Result<(), HirDisplayError>;
impl<F> HirDisplay for WriteWith<F> impl<F> HirDisplay for WriteWith<F>
where where
F: Fn(&mut HirFormatter) -> Result<(), HirDisplayError>, F: Fn(&mut HirFormatter<'_>) -> Result<(), HirDisplayError>,
{ {
fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
(self.0)(f) (self.0)(f)

View file

@ -144,7 +144,7 @@ impl IntRange {
} }
} }
fn to_pat(&self, _cx: &MatchCheckCtx, ty: Ty) -> Pat { fn to_pat(&self, _cx: &MatchCheckCtx<'_, '_>, ty: Ty) -> Pat {
match ty.kind(Interner) { match ty.kind(Interner) {
TyKind::Scalar(Scalar::Bool) => { TyKind::Scalar(Scalar::Bool) => {
let kind = match self.boundaries() { let kind = match self.boundaries() {

View file

@ -45,7 +45,7 @@ pub struct HirFormatter<'a> {
} }
pub trait HirDisplay { pub trait HirDisplay {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError>; fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError>;
/// Returns a `Display`able type that is human-readable. /// Returns a `Display`able type that is human-readable.
fn into_displayable<'a>( fn into_displayable<'a>(
@ -162,7 +162,7 @@ impl<'a> HirFormatter<'a> {
} }
/// This allows using the `write!` macro directly with a `HirFormatter`. /// This allows using the `write!` macro directly with a `HirFormatter`.
pub fn write_fmt(&mut self, args: fmt::Arguments) -> Result<(), HirDisplayError> { pub fn write_fmt(&mut self, args: fmt::Arguments<'_>) -> Result<(), HirDisplayError> {
// We write to a buffer first to track output size // We write to a buffer first to track output size
self.buf.clear(); self.buf.clear();
fmt::write(&mut self.buf, args)?; fmt::write(&mut self.buf, args)?;
@ -247,7 +247,7 @@ impl<'a, T> fmt::Display for HirDisplayWrapper<'a, T>
where where
T: HirDisplay, T: HirDisplay,
{ {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.t.hir_fmt(&mut HirFormatter { match self.t.hir_fmt(&mut HirFormatter {
db: self.db, db: self.db,
fmt: f, fmt: f,
@ -270,19 +270,19 @@ where
const TYPE_HINT_TRUNCATION: &str = ""; const TYPE_HINT_TRUNCATION: &str = "";
impl<T: HirDisplay> HirDisplay for &'_ T { impl<T: HirDisplay> HirDisplay for &'_ T {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
HirDisplay::hir_fmt(*self, f) HirDisplay::hir_fmt(*self, f)
} }
} }
impl<T: HirDisplay + Internable> HirDisplay for Interned<T> { impl<T: HirDisplay + Internable> HirDisplay for Interned<T> {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
HirDisplay::hir_fmt(self.as_ref(), f) HirDisplay::hir_fmt(self.as_ref(), f)
} }
} }
impl HirDisplay for ProjectionTy { impl HirDisplay for ProjectionTy {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
if f.should_truncate() { if f.should_truncate() {
return write!(f, "{}", TYPE_HINT_TRUNCATION); return write!(f, "{}", TYPE_HINT_TRUNCATION);
} }
@ -302,7 +302,7 @@ impl HirDisplay for ProjectionTy {
} }
impl HirDisplay for OpaqueTy { impl HirDisplay for OpaqueTy {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
if f.should_truncate() { if f.should_truncate() {
return write!(f, "{}", TYPE_HINT_TRUNCATION); return write!(f, "{}", TYPE_HINT_TRUNCATION);
} }
@ -312,7 +312,7 @@ impl HirDisplay for OpaqueTy {
} }
impl HirDisplay for GenericArg { impl HirDisplay for GenericArg {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
match self.interned() { match self.interned() {
crate::GenericArgData::Ty(ty) => ty.hir_fmt(f), crate::GenericArgData::Ty(ty) => ty.hir_fmt(f),
crate::GenericArgData::Lifetime(lt) => lt.hir_fmt(f), crate::GenericArgData::Lifetime(lt) => lt.hir_fmt(f),
@ -322,7 +322,7 @@ impl HirDisplay for GenericArg {
} }
impl HirDisplay for Const { impl HirDisplay for Const {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
let data = self.interned(); let data = self.interned();
match data.value { match data.value {
ConstValue::BoundVar(idx) => idx.hir_fmt(f), ConstValue::BoundVar(idx) => idx.hir_fmt(f),
@ -339,13 +339,13 @@ impl HirDisplay for Const {
} }
impl HirDisplay for BoundVar { impl HirDisplay for BoundVar {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
write!(f, "?{}.{}", self.debruijn.depth(), self.index) write!(f, "?{}.{}", self.debruijn.depth(), self.index)
} }
} }
impl HirDisplay for Ty { impl HirDisplay for Ty {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
if f.should_truncate() { if f.should_truncate() {
return write!(f, "{}", TYPE_HINT_TRUNCATION); return write!(f, "{}", TYPE_HINT_TRUNCATION);
} }
@ -790,7 +790,7 @@ impl HirDisplay for Ty {
} }
impl HirDisplay for CallableSig { impl HirDisplay for CallableSig {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
write!(f, "fn(")?; write!(f, "fn(")?;
f.write_joined(self.params(), ", ")?; f.write_joined(self.params(), ", ")?;
if self.is_varargs { if self.is_varargs {
@ -839,7 +839,7 @@ pub fn write_bounds_like_dyn_trait_with_prefix(
prefix: &str, prefix: &str,
predicates: &[QuantifiedWhereClause], predicates: &[QuantifiedWhereClause],
default_sized: SizedByDefault, default_sized: SizedByDefault,
f: &mut HirFormatter, f: &mut HirFormatter<'_>,
) -> Result<(), HirDisplayError> { ) -> Result<(), HirDisplayError> {
write!(f, "{}", prefix)?; write!(f, "{}", prefix)?;
if !predicates.is_empty() if !predicates.is_empty()
@ -855,7 +855,7 @@ pub fn write_bounds_like_dyn_trait_with_prefix(
fn write_bounds_like_dyn_trait( fn write_bounds_like_dyn_trait(
predicates: &[QuantifiedWhereClause], predicates: &[QuantifiedWhereClause],
default_sized: SizedByDefault, default_sized: SizedByDefault,
f: &mut HirFormatter, f: &mut HirFormatter<'_>,
) -> Result<(), HirDisplayError> { ) -> Result<(), HirDisplayError> {
// Note: This code is written to produce nice results (i.e. // Note: This code is written to produce nice results (i.e.
// corresponding to surface Rust) for types that can occur in // corresponding to surface Rust) for types that can occur in
@ -952,7 +952,11 @@ fn write_bounds_like_dyn_trait(
Ok(()) Ok(())
} }
fn fmt_trait_ref(tr: &TraitRef, f: &mut HirFormatter, use_as: bool) -> Result<(), HirDisplayError> { fn fmt_trait_ref(
tr: &TraitRef,
f: &mut HirFormatter<'_>,
use_as: bool,
) -> Result<(), HirDisplayError> {
if f.should_truncate() { if f.should_truncate() {
return write!(f, "{}", TYPE_HINT_TRUNCATION); return write!(f, "{}", TYPE_HINT_TRUNCATION);
} }
@ -973,13 +977,13 @@ fn fmt_trait_ref(tr: &TraitRef, f: &mut HirFormatter, use_as: bool) -> Result<()
} }
impl HirDisplay for TraitRef { impl HirDisplay for TraitRef {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
fmt_trait_ref(self, f, false) fmt_trait_ref(self, f, false)
} }
} }
impl HirDisplay for WhereClause { impl HirDisplay for WhereClause {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
if f.should_truncate() { if f.should_truncate() {
return write!(f, "{}", TYPE_HINT_TRUNCATION); return write!(f, "{}", TYPE_HINT_TRUNCATION);
} }
@ -1007,7 +1011,7 @@ impl HirDisplay for WhereClause {
} }
impl HirDisplay for LifetimeOutlives { impl HirDisplay for LifetimeOutlives {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
self.a.hir_fmt(f)?; self.a.hir_fmt(f)?;
write!(f, ": ")?; write!(f, ": ")?;
self.b.hir_fmt(f) self.b.hir_fmt(f)
@ -1015,13 +1019,13 @@ impl HirDisplay for LifetimeOutlives {
} }
impl HirDisplay for Lifetime { impl HirDisplay for Lifetime {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
self.interned().hir_fmt(f) self.interned().hir_fmt(f)
} }
} }
impl HirDisplay for LifetimeData { impl HirDisplay for LifetimeData {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
match self { match self {
LifetimeData::BoundVar(idx) => idx.hir_fmt(f), LifetimeData::BoundVar(idx) => idx.hir_fmt(f),
LifetimeData::InferenceVar(_) => write!(f, "_"), LifetimeData::InferenceVar(_) => write!(f, "_"),
@ -1040,7 +1044,7 @@ impl HirDisplay for LifetimeData {
} }
impl HirDisplay for DomainGoal { impl HirDisplay for DomainGoal {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
match self { match self {
DomainGoal::Holds(wc) => { DomainGoal::Holds(wc) => {
write!(f, "Holds(")?; write!(f, "Holds(")?;
@ -1056,7 +1060,7 @@ impl HirDisplay for DomainGoal {
pub fn write_visibility( pub fn write_visibility(
module_id: ModuleId, module_id: ModuleId,
vis: Visibility, vis: Visibility,
f: &mut HirFormatter, f: &mut HirFormatter<'_>,
) -> Result<(), HirDisplayError> { ) -> Result<(), HirDisplayError> {
match vis { match vis {
Visibility::Public => write!(f, "pub "), Visibility::Public => write!(f, "pub "),
@ -1078,7 +1082,7 @@ pub fn write_visibility(
} }
impl HirDisplay for TypeRef { impl HirDisplay for TypeRef {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
match self { match self {
TypeRef::Never => write!(f, "!")?, TypeRef::Never => write!(f, "!")?,
TypeRef::Placeholder => write!(f, "_")?, TypeRef::Placeholder => write!(f, "_")?,
@ -1177,7 +1181,7 @@ impl HirDisplay for TypeRef {
} }
impl HirDisplay for TypeBound { impl HirDisplay for TypeBound {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
match self { match self {
TypeBound::Path(path, modifier) => { TypeBound::Path(path, modifier) => {
match modifier { match modifier {
@ -1197,7 +1201,7 @@ impl HirDisplay for TypeBound {
} }
impl HirDisplay for Path { impl HirDisplay for Path {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
match (self.type_anchor(), self.kind()) { match (self.type_anchor(), self.kind()) {
(Some(anchor), _) => { (Some(anchor), _) => {
write!(f, "<")?; write!(f, "<")?;
@ -1301,7 +1305,7 @@ impl HirDisplay for Path {
} }
impl HirDisplay for hir_def::path::GenericArg { impl HirDisplay for hir_def::path::GenericArg {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
match self { match self {
hir_def::path::GenericArg::Type(ty) => ty.hir_fmt(f), hir_def::path::GenericArg::Type(ty) => ty.hir_fmt(f),
hir_def::path::GenericArg::Const(c) => write!(f, "{}", c), hir_def::path::GenericArg::Const(c) => write!(f, "{}", c),

View file

@ -130,7 +130,7 @@ trait PatLike: Into<ExprOrPatId> + Copy {
type BindingMode: Copy; type BindingMode: Copy;
fn infer( fn infer(
this: &mut InferenceContext, this: &mut InferenceContext<'_>,
id: Self, id: Self,
expected_ty: &Ty, expected_ty: &Ty,
default_bm: Self::BindingMode, default_bm: Self::BindingMode,
@ -140,7 +140,12 @@ trait PatLike: Into<ExprOrPatId> + Copy {
impl PatLike for ExprId { impl PatLike for ExprId {
type BindingMode = (); type BindingMode = ();
fn infer(this: &mut InferenceContext, id: Self, expected_ty: &Ty, _: Self::BindingMode) -> Ty { fn infer(
this: &mut InferenceContext<'_>,
id: Self,
expected_ty: &Ty,
_: Self::BindingMode,
) -> Ty {
this.infer_assignee_expr(id, expected_ty) this.infer_assignee_expr(id, expected_ty)
} }
} }
@ -149,7 +154,7 @@ impl PatLike for PatId {
type BindingMode = BindingMode; type BindingMode = BindingMode;
fn infer( fn infer(
this: &mut InferenceContext, this: &mut InferenceContext<'_>,
id: Self, id: Self,
expected_ty: &Ty, expected_ty: &Ty,
default_bm: Self::BindingMode, default_bm: Self::BindingMode,
@ -971,7 +976,7 @@ impl Expectation {
/// which still is useful, because it informs integer literals and the like. /// which still is useful, because it informs integer literals and the like.
/// See the test case `test/ui/coerce-expect-unsized.rs` and #20169 /// See the test case `test/ui/coerce-expect-unsized.rs` and #20169
/// for examples of where this comes up,. /// for examples of where this comes up,.
fn rvalue_hint(table: &mut unify::InferenceTable, ty: Ty) -> Self { fn rvalue_hint(table: &mut unify::InferenceTable<'_>, ty: Ty) -> Self {
// FIXME: do struct_tail_without_normalization // FIXME: do struct_tail_without_normalization
match table.resolve_ty_shallow(&ty).kind(Interner) { match table.resolve_ty_shallow(&ty).kind(Interner) {
TyKind::Slice(_) | TyKind::Str | TyKind::Dyn(_) => Expectation::RValueLikeUnsized(ty), TyKind::Slice(_) | TyKind::Str | TyKind::Dyn(_) => Expectation::RValueLikeUnsized(ty),
@ -984,7 +989,7 @@ impl Expectation {
Expectation::None Expectation::None
} }
fn resolve(&self, table: &mut unify::InferenceTable) -> Expectation { fn resolve(&self, table: &mut unify::InferenceTable<'_>) -> Expectation {
match self { match self {
Expectation::None => Expectation::None, Expectation::None => Expectation::None,
Expectation::HasType(t) => Expectation::HasType(table.resolve_ty_shallow(t)), Expectation::HasType(t) => Expectation::HasType(table.resolve_ty_shallow(t)),
@ -994,7 +999,7 @@ impl Expectation {
} }
} }
fn to_option(&self, table: &mut unify::InferenceTable) -> Option<Ty> { fn to_option(&self, table: &mut unify::InferenceTable<'_>) -> Option<Ty> {
match self.resolve(table) { match self.resolve(table) {
Expectation::None => None, Expectation::None => None,
Expectation::HasType(t) | Expectation::HasType(t) |
@ -1003,7 +1008,7 @@ impl Expectation {
} }
} }
fn only_has_type(&self, table: &mut unify::InferenceTable) -> Option<Ty> { fn only_has_type(&self, table: &mut unify::InferenceTable<'_>) -> Option<Ty> {
match self { match self {
Expectation::HasType(t) => Some(table.resolve_ty_shallow(t)), Expectation::HasType(t) => Some(table.resolve_ty_shallow(t)),
// Expectation::Castable(_) | // Expectation::Castable(_) |
@ -1028,7 +1033,7 @@ impl Expectation {
/// an expected type. Otherwise, we might write parts of the type /// an expected type. Otherwise, we might write parts of the type
/// when checking the 'then' block which are incompatible with the /// when checking the 'then' block which are incompatible with the
/// 'else' branch. /// 'else' branch.
fn adjust_for_branches(&self, table: &mut unify::InferenceTable) -> Expectation { fn adjust_for_branches(&self, table: &mut unify::InferenceTable<'_>) -> Expectation {
match self { match self {
Expectation::HasType(ety) => { Expectation::HasType(ety) => {
let ety = table.resolve_ty_shallow(ety); let ety = table.resolve_ty_shallow(ety);

View file

@ -43,7 +43,7 @@ where
impl<T: HasInterner<Interner = Interner>> Canonicalized<T> { impl<T: HasInterner<Interner = Interner>> Canonicalized<T> {
pub(super) fn apply_solution( pub(super) fn apply_solution(
&self, &self,
ctx: &mut InferenceTable, ctx: &mut InferenceTable<'_>,
solution: Canonical<Substitution>, solution: Canonical<Substitution>,
) { ) {
// the solution may contain new variables, which we need to convert to new inference vars // the solution may contain new variables, which we need to convert to new inference vars
@ -391,7 +391,7 @@ impl<'a> InferenceTable<'a> {
self.pending_obligations = snapshot.pending_obligations; self.pending_obligations = snapshot.pending_obligations;
} }
pub(crate) fn run_in_snapshot<T>(&mut self, f: impl FnOnce(&mut InferenceTable) -> T) -> T { pub(crate) fn run_in_snapshot<T>(&mut self, f: impl FnOnce(&mut InferenceTable<'_>) -> T) -> T {
let snapshot = self.snapshot(); let snapshot = self.snapshot();
let result = f(self); let result = f(self);
self.rollback_to(snapshot); self.rollback_to(snapshot);

View file

@ -168,7 +168,7 @@ impl chalk_ir::interner::Interner for Interner {
} }
fn debug_separator_trait_ref( fn debug_separator_trait_ref(
separator_trait_ref: &chalk_ir::SeparatorTraitRef<Interner>, separator_trait_ref: &chalk_ir::SeparatorTraitRef<'_, Interner>,
fmt: &mut fmt::Formatter<'_>, fmt: &mut fmt::Formatter<'_>,
) -> Option<fmt::Result> { ) -> Option<fmt::Result> {
Some(write!(fmt, "{:?}", separator_trait_ref.debug(Interner))) Some(write!(fmt, "{:?}", separator_trait_ref.debug(Interner)))

View file

@ -1,6 +1,8 @@
//! The type system. We currently use this to infer types for completion, hover //! The type system. We currently use this to infer types for completion, hover
//! information and various assists. //! information and various assists.
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
#[allow(unused)] #[allow(unused)]
macro_rules! eprintln { macro_rules! eprintln {
($($tt:tt)*) => { stdx::eprintln!($($tt)*) }; ($($tt:tt)*) => { stdx::eprintln!($($tt)*) };

View file

@ -106,7 +106,7 @@ impl<'a> TyLoweringContext<'a> {
pub fn with_debruijn<T>( pub fn with_debruijn<T>(
&self, &self,
debruijn: DebruijnIndex, debruijn: DebruijnIndex,
f: impl FnOnce(&TyLoweringContext) -> T, f: impl FnOnce(&TyLoweringContext<'_>) -> T,
) -> T { ) -> T {
let opaque_ty_data_vec = self.opaque_type_data.take(); let opaque_ty_data_vec = self.opaque_type_data.take();
let expander = self.expander.take(); let expander = self.expander.take();
@ -130,7 +130,7 @@ impl<'a> TyLoweringContext<'a> {
pub fn with_shifted_in<T>( pub fn with_shifted_in<T>(
&self, &self,
debruijn: DebruijnIndex, debruijn: DebruijnIndex,
f: impl FnOnce(&TyLoweringContext) -> T, f: impl FnOnce(&TyLoweringContext<'_>) -> T,
) -> T { ) -> T {
self.with_debruijn(self.in_binders.shifted_in_from(debruijn), f) self.with_debruijn(self.in_binders.shifted_in_from(debruijn), f)
} }

View file

@ -492,7 +492,7 @@ pub struct ReceiverAdjustments {
} }
impl ReceiverAdjustments { impl ReceiverAdjustments {
pub(crate) fn apply(&self, table: &mut InferenceTable, ty: Ty) -> (Ty, Vec<Adjustment>) { pub(crate) fn apply(&self, table: &mut InferenceTable<'_>, ty: Ty) -> (Ty, Vec<Adjustment>) {
let mut ty = ty; let mut ty = ty;
let mut adjust = Vec::new(); let mut adjust = Vec::new();
for _ in 0..self.autoderefs { for _ in 0..self.autoderefs {
@ -597,7 +597,7 @@ pub fn lookup_impl_method(
fn find_matching_impl( fn find_matching_impl(
mut impls: impl Iterator<Item = ImplId>, mut impls: impl Iterator<Item = ImplId>,
table: &mut InferenceTable, table: &mut InferenceTable<'_>,
self_ty: &Ty, self_ty: &Ty,
) -> Option<Arc<ImplData>> { ) -> Option<Arc<ImplData>> {
let db = table.db; let db = table.db;
@ -856,7 +856,7 @@ fn iterate_method_candidates_for_self_ty(
fn iterate_trait_method_candidates( fn iterate_trait_method_candidates(
self_ty: &Ty, self_ty: &Ty,
table: &mut InferenceTable, table: &mut InferenceTable<'_>,
traits_in_scope: &FxHashSet<TraitId>, traits_in_scope: &FxHashSet<TraitId>,
name: Option<&Name>, name: Option<&Name>,
receiver_ty: Option<&Ty>, receiver_ty: Option<&Ty>,
@ -922,7 +922,7 @@ fn iterate_trait_method_candidates(
fn iterate_inherent_methods( fn iterate_inherent_methods(
self_ty: &Ty, self_ty: &Ty,
table: &mut InferenceTable, table: &mut InferenceTable<'_>,
name: Option<&Name>, name: Option<&Name>,
receiver_ty: Option<&Ty>, receiver_ty: Option<&Ty>,
receiver_adjustments: Option<ReceiverAdjustments>, receiver_adjustments: Option<ReceiverAdjustments>,
@ -975,7 +975,7 @@ fn iterate_inherent_methods(
fn impls_for_self_ty( fn impls_for_self_ty(
impls: &InherentImpls, impls: &InherentImpls,
self_ty: &Ty, self_ty: &Ty,
table: &mut InferenceTable, table: &mut InferenceTable<'_>,
name: Option<&Name>, name: Option<&Name>,
receiver_ty: Option<&Ty>, receiver_ty: Option<&Ty>,
receiver_adjustments: Option<ReceiverAdjustments>, receiver_adjustments: Option<ReceiverAdjustments>,
@ -1017,7 +1017,7 @@ pub fn resolve_indexing_op(
} }
fn is_valid_candidate( fn is_valid_candidate(
table: &mut InferenceTable, table: &mut InferenceTable<'_>,
name: Option<&Name>, name: Option<&Name>,
receiver_ty: Option<&Ty>, receiver_ty: Option<&Ty>,
item: AssocItemId, item: AssocItemId,
@ -1161,7 +1161,7 @@ fn generic_implements_goal(
} }
fn autoderef_method_receiver( fn autoderef_method_receiver(
table: &mut InferenceTable, table: &mut InferenceTable<'_>,
ty: Ty, ty: Ty,
) -> (Vec<Canonical<Ty>>, Vec<ReceiverAdjustments>) { ) -> (Vec<Canonical<Ty>>, Vec<ReceiverAdjustments>) {
let (mut deref_chain, mut adjustments): (Vec<_>, Vec<_>) = (Vec::new(), Vec::new()); let (mut deref_chain, mut adjustments): (Vec<_>, Vec<_>) = (Vec::new(), Vec::new());

View file

@ -77,7 +77,7 @@ impl FileLoader for TestDB {
fn file_text(&self, file_id: FileId) -> Arc<String> { fn file_text(&self, file_id: FileId) -> Arc<String> {
FileLoaderDelegate(self).file_text(file_id) 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) FileLoaderDelegate(self).resolve_path(path)
} }
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> { fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> {

View file

@ -104,7 +104,7 @@ mod unsafe_tls {
use crate::db::HirDatabase; use crate::db::HirDatabase;
use scoped_tls::scoped_thread_local; use scoped_tls::scoped_thread_local;
scoped_thread_local!(static PROGRAM: DebugContext); scoped_thread_local!(static PROGRAM: DebugContext<'_>);
pub(crate) fn with_current_program<R>( pub(crate) fn with_current_program<R>(
op: impl for<'a> FnOnce(Option<&'a DebugContext<'a>>) -> R, op: impl for<'a> FnOnce(Option<&'a DebugContext<'a>>) -> R,
@ -127,7 +127,7 @@ mod unsafe_tls {
// `with_current_program`, which hides the lifetime through the `for` // `with_current_program`, which hides the lifetime through the `for`
// type. // type.
let static_p: &DebugContext<'static> = let static_p: &DebugContext<'static> =
unsafe { std::mem::transmute::<&DebugContext, &DebugContext<'static>>(&ctx) }; unsafe { std::mem::transmute::<&DebugContext<'_>, &DebugContext<'static>>(&ctx) };
PROGRAM.set(static_p, op) PROGRAM.set(static_p, op)
} }
} }

View file

@ -130,7 +130,7 @@ pub fn all_super_traits(db: &dyn DefDatabase, trait_: TraitId) -> SmallVec<[Trai
/// `all_super_traits` is that we keep track of type parameters; for example if /// `all_super_traits` is that we keep track of type parameters; for example if
/// we have `Self: Trait<u32, i32>` and `Trait<T, U>: OtherTrait<U>` we'll get /// we have `Self: Trait<u32, i32>` and `Trait<T, U>: OtherTrait<U>` we'll get
/// `Self: OtherTrait<i32>`. /// `Self: OtherTrait<i32>`.
pub(super) fn all_super_trait_refs(db: &dyn HirDatabase, trait_ref: TraitRef) -> SuperTraits { pub(super) fn all_super_trait_refs(db: &dyn HirDatabase, trait_ref: TraitRef) -> SuperTraits<'_> {
SuperTraits { db, seen: iter::once(trait_ref.trait_id).collect(), stack: vec![trait_ref] } SuperTraits { db, seen: iter::once(trait_ref.trait_id).collect(), stack: vec![trait_ref] }
} }

View file

@ -23,7 +23,7 @@ use crate::{
}; };
impl HirDisplay for Function { impl HirDisplay for Function {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
let data = f.db.function_data(self.id); let data = f.db.function_data(self.id);
write_visibility(self.module(f.db).id, self.visibility(f.db), f)?; write_visibility(self.module(f.db).id, self.visibility(f.db), f)?;
if data.has_default_kw() { if data.has_default_kw() {
@ -48,7 +48,7 @@ impl HirDisplay for Function {
f.write_char('(')?; f.write_char('(')?;
let write_self_param = |ty: &TypeRef, f: &mut HirFormatter| match ty { let write_self_param = |ty: &TypeRef, f: &mut HirFormatter<'_>| match ty {
TypeRef::Path(p) if p.is_self_type() => f.write_str("self"), TypeRef::Path(p) if p.is_self_type() => f.write_str("self"),
TypeRef::Reference(inner, lifetime, mut_) if matches!(&**inner,TypeRef::Path(p) if p.is_self_type()) => TypeRef::Reference(inner, lifetime, mut_) if matches!(&**inner,TypeRef::Path(p) if p.is_self_type()) =>
{ {
@ -129,7 +129,7 @@ impl HirDisplay for Function {
} }
impl HirDisplay for Adt { impl HirDisplay for Adt {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
match self { match self {
Adt::Struct(it) => it.hir_fmt(f), Adt::Struct(it) => it.hir_fmt(f),
Adt::Union(it) => it.hir_fmt(f), Adt::Union(it) => it.hir_fmt(f),
@ -139,7 +139,7 @@ impl HirDisplay for Adt {
} }
impl HirDisplay for Struct { impl HirDisplay for Struct {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
write_visibility(self.module(f.db).id, self.visibility(f.db), f)?; write_visibility(self.module(f.db).id, self.visibility(f.db), f)?;
f.write_str("struct ")?; f.write_str("struct ")?;
write!(f, "{}", self.name(f.db))?; write!(f, "{}", self.name(f.db))?;
@ -151,7 +151,7 @@ impl HirDisplay for Struct {
} }
impl HirDisplay for Enum { impl HirDisplay for Enum {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
write_visibility(self.module(f.db).id, self.visibility(f.db), f)?; write_visibility(self.module(f.db).id, self.visibility(f.db), f)?;
f.write_str("enum ")?; f.write_str("enum ")?;
write!(f, "{}", self.name(f.db))?; write!(f, "{}", self.name(f.db))?;
@ -163,7 +163,7 @@ impl HirDisplay for Enum {
} }
impl HirDisplay for Union { impl HirDisplay for Union {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
write_visibility(self.module(f.db).id, self.visibility(f.db), f)?; write_visibility(self.module(f.db).id, self.visibility(f.db), f)?;
f.write_str("union ")?; f.write_str("union ")?;
write!(f, "{}", self.name(f.db))?; write!(f, "{}", self.name(f.db))?;
@ -175,7 +175,7 @@ impl HirDisplay for Union {
} }
impl HirDisplay for Field { impl HirDisplay for Field {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
write_visibility(self.parent.module(f.db).id, self.visibility(f.db), f)?; write_visibility(self.parent.module(f.db).id, self.visibility(f.db), f)?;
write!(f, "{}: ", self.name(f.db))?; write!(f, "{}: ", self.name(f.db))?;
self.ty(f.db).hir_fmt(f) self.ty(f.db).hir_fmt(f)
@ -183,7 +183,7 @@ impl HirDisplay for Field {
} }
impl HirDisplay for Variant { impl HirDisplay for Variant {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
write!(f, "{}", self.name(f.db))?; write!(f, "{}", self.name(f.db))?;
let data = self.variant_data(f.db); let data = self.variant_data(f.db);
match &*data { match &*data {
@ -224,13 +224,13 @@ impl HirDisplay for Variant {
} }
impl HirDisplay for Type { impl HirDisplay for Type {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
self.ty.hir_fmt(f) self.ty.hir_fmt(f)
} }
} }
impl HirDisplay for GenericParam { impl HirDisplay for GenericParam {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
match self { match self {
GenericParam::TypeParam(it) => it.hir_fmt(f), GenericParam::TypeParam(it) => it.hir_fmt(f),
GenericParam::ConstParam(it) => it.hir_fmt(f), GenericParam::ConstParam(it) => it.hir_fmt(f),
@ -240,7 +240,7 @@ impl HirDisplay for GenericParam {
} }
impl HirDisplay for TypeOrConstParam { impl HirDisplay for TypeOrConstParam {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
match self.split(f.db) { match self.split(f.db) {
either::Either::Left(x) => x.hir_fmt(f), either::Either::Left(x) => x.hir_fmt(f),
either::Either::Right(x) => x.hir_fmt(f), either::Either::Right(x) => x.hir_fmt(f),
@ -249,7 +249,7 @@ impl HirDisplay for TypeOrConstParam {
} }
impl HirDisplay for TypeParam { impl HirDisplay for TypeParam {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
write!(f, "{}", self.name(f.db))?; write!(f, "{}", self.name(f.db))?;
if f.omit_verbose_types() { if f.omit_verbose_types() {
return Ok(()); return Ok(());
@ -277,19 +277,22 @@ impl HirDisplay for TypeParam {
} }
impl HirDisplay for LifetimeParam { impl HirDisplay for LifetimeParam {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
write!(f, "{}", self.name(f.db)) write!(f, "{}", self.name(f.db))
} }
} }
impl HirDisplay for ConstParam { impl HirDisplay for ConstParam {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
write!(f, "const {}: ", self.name(f.db))?; write!(f, "const {}: ", self.name(f.db))?;
self.ty(f.db).hir_fmt(f) self.ty(f.db).hir_fmt(f)
} }
} }
fn write_generic_params(def: GenericDefId, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn write_generic_params(
def: GenericDefId,
f: &mut HirFormatter<'_>,
) -> Result<(), HirDisplayError> {
let params = f.db.generic_params(def); let params = f.db.generic_params(def);
if params.lifetimes.is_empty() if params.lifetimes.is_empty()
&& params.type_or_consts.iter().all(|x| x.1.const_param().is_none()) && params.type_or_consts.iter().all(|x| x.1.const_param().is_none())
@ -304,7 +307,7 @@ fn write_generic_params(def: GenericDefId, f: &mut HirFormatter) -> Result<(), H
f.write_char('<')?; f.write_char('<')?;
let mut first = true; let mut first = true;
let mut delim = |f: &mut HirFormatter| { let mut delim = |f: &mut HirFormatter<'_>| {
if first { if first {
first = false; first = false;
Ok(()) Ok(())
@ -343,7 +346,7 @@ fn write_generic_params(def: GenericDefId, f: &mut HirFormatter) -> Result<(), H
Ok(()) Ok(())
} }
fn write_where_clause(def: GenericDefId, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn write_where_clause(def: GenericDefId, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
let params = f.db.generic_params(def); let params = f.db.generic_params(def);
// unnamed type targets are displayed inline with the argument itself, e.g. `f: impl Y`. // unnamed type targets are displayed inline with the argument itself, e.g. `f: impl Y`.
@ -365,7 +368,7 @@ fn write_where_clause(def: GenericDefId, f: &mut HirFormatter) -> Result<(), Hir
return Ok(()); return Ok(());
} }
let write_target = |target: &WherePredicateTypeTarget, f: &mut HirFormatter| match target { let write_target = |target: &WherePredicateTypeTarget, f: &mut HirFormatter<'_>| match target {
WherePredicateTypeTarget::TypeRef(ty) => ty.hir_fmt(f), WherePredicateTypeTarget::TypeRef(ty) => ty.hir_fmt(f),
WherePredicateTypeTarget::TypeOrConstParam(id) => { WherePredicateTypeTarget::TypeOrConstParam(id) => {
match &params.type_or_consts[*id].name() { match &params.type_or_consts[*id].name() {
@ -381,8 +384,9 @@ fn write_where_clause(def: GenericDefId, f: &mut HirFormatter) -> Result<(), Hir
let prev_pred = let prev_pred =
if pred_idx == 0 { None } else { Some(&params.where_predicates[pred_idx - 1]) }; if pred_idx == 0 { None } else { Some(&params.where_predicates[pred_idx - 1]) };
let new_predicate = let new_predicate = |f: &mut HirFormatter<'_>| {
|f: &mut HirFormatter| f.write_str(if pred_idx == 0 { "\n " } else { ",\n " }); f.write_str(if pred_idx == 0 { "\n " } else { ",\n " })
};
match pred { match pred {
WherePredicate::TypeBound { target, .. } if is_unnamed_type_target(target) => {} WherePredicate::TypeBound { target, .. } if is_unnamed_type_target(target) => {}
@ -438,7 +442,7 @@ fn write_where_clause(def: GenericDefId, f: &mut HirFormatter) -> Result<(), Hir
} }
impl HirDisplay for Const { impl HirDisplay for Const {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
write_visibility(self.module(f.db).id, self.visibility(f.db), f)?; write_visibility(self.module(f.db).id, self.visibility(f.db), f)?;
let data = f.db.const_data(self.id); let data = f.db.const_data(self.id);
f.write_str("const ")?; f.write_str("const ")?;
@ -452,7 +456,7 @@ impl HirDisplay for Const {
} }
impl HirDisplay for Static { impl HirDisplay for Static {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
write_visibility(self.module(f.db).id, self.visibility(f.db), f)?; write_visibility(self.module(f.db).id, self.visibility(f.db), f)?;
let data = f.db.static_data(self.id); let data = f.db.static_data(self.id);
f.write_str("static ")?; f.write_str("static ")?;
@ -466,7 +470,7 @@ impl HirDisplay for Static {
} }
impl HirDisplay for Trait { impl HirDisplay for Trait {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
write_visibility(self.module(f.db).id, self.visibility(f.db), f)?; write_visibility(self.module(f.db).id, self.visibility(f.db), f)?;
let data = f.db.trait_data(self.id); let data = f.db.trait_data(self.id);
if data.is_unsafe { if data.is_unsafe {
@ -484,7 +488,7 @@ impl HirDisplay for Trait {
} }
impl HirDisplay for TypeAlias { impl HirDisplay for TypeAlias {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
write_visibility(self.module(f.db).id, self.visibility(f.db), f)?; write_visibility(self.module(f.db).id, self.visibility(f.db), f)?;
let data = f.db.type_alias_data(self.id); let data = f.db.type_alias_data(self.id);
write!(f, "type {}", data.name)?; write!(f, "type {}", data.name)?;
@ -501,7 +505,7 @@ impl HirDisplay for TypeAlias {
} }
impl HirDisplay for Module { impl HirDisplay for Module {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
// FIXME: Module doesn't have visibility saved in data. // FIXME: Module doesn't have visibility saved in data.
match self.name(f.db) { match self.name(f.db) {
Some(name) => write!(f, "mod {}", name), Some(name) => write!(f, "mod {}", name),
@ -515,7 +519,7 @@ impl HirDisplay for Module {
} }
impl HirDisplay for Macro { impl HirDisplay for Macro {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
match self.id { match self.id {
hir_def::MacroId::Macro2Id(_) => f.write_str("macro"), hir_def::MacroId::Macro2Id(_) => f.write_str("macro"),
hir_def::MacroId::MacroRulesId(_) => f.write_str("macro_rules!"), hir_def::MacroId::MacroRulesId(_) => f.write_str("macro_rules!"),

View file

@ -17,6 +17,7 @@
//! from the ide with completions, hovers, etc. It is a (soft, internal) boundary: //! from the ide with completions, hovers, etc. It is a (soft, internal) boundary:
//! <https://www.tedinski.com/2018/02/06/system-boundaries.html>. //! <https://www.tedinski.com/2018/02/06/system-boundaries.html>.
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
#![recursion_limit = "512"] #![recursion_limit = "512"]
mod semantics; mod semantics;
@ -3027,7 +3028,7 @@ impl Type {
pub fn iterate_method_candidates<T>( pub fn iterate_method_candidates<T>(
&self, &self,
db: &dyn HirDatabase, db: &dyn HirDatabase,
scope: &SemanticsScope, scope: &SemanticsScope<'_>,
// FIXME this can be retrieved from `scope`, except autoimport uses this // FIXME this can be retrieved from `scope`, except autoimport uses this
// to specify a different set, so the method needs to be split // to specify a different set, so the method needs to be split
traits_in_scope: &FxHashSet<TraitId>, traits_in_scope: &FxHashSet<TraitId>,
@ -3060,7 +3061,7 @@ impl Type {
fn iterate_method_candidates_dyn( fn iterate_method_candidates_dyn(
&self, &self,
db: &dyn HirDatabase, db: &dyn HirDatabase,
scope: &SemanticsScope, scope: &SemanticsScope<'_>,
traits_in_scope: &FxHashSet<TraitId>, traits_in_scope: &FxHashSet<TraitId>,
with_local_impls: Option<Module>, with_local_impls: Option<Module>,
name: Option<&Name>, name: Option<&Name>,
@ -3090,7 +3091,7 @@ impl Type {
pub fn iterate_path_candidates<T>( pub fn iterate_path_candidates<T>(
&self, &self,
db: &dyn HirDatabase, db: &dyn HirDatabase,
scope: &SemanticsScope, scope: &SemanticsScope<'_>,
traits_in_scope: &FxHashSet<TraitId>, traits_in_scope: &FxHashSet<TraitId>,
with_local_impls: Option<Module>, with_local_impls: Option<Module>,
name: Option<&Name>, name: Option<&Name>,
@ -3118,7 +3119,7 @@ impl Type {
fn iterate_path_candidates_dyn( fn iterate_path_candidates_dyn(
&self, &self,
db: &dyn HirDatabase, db: &dyn HirDatabase,
scope: &SemanticsScope, scope: &SemanticsScope<'_>,
traits_in_scope: &FxHashSet<TraitId>, traits_in_scope: &FxHashSet<TraitId>,
with_local_impls: Option<Module>, with_local_impls: Option<Module>,
name: Option<&Name>, name: Option<&Name>,

View file

@ -124,7 +124,7 @@ impl<DB> fmt::Debug for Semantics<'_, DB> {
} }
impl<'db, DB: HirDatabase> Semantics<'db, DB> { impl<'db, DB: HirDatabase> Semantics<'db, DB> {
pub fn new(db: &DB) -> Semantics<DB> { pub fn new(db: &DB) -> Semantics<'_, DB> {
let impl_ = SemanticsImpl::new(db); let impl_ = SemanticsImpl::new(db);
Semantics { db, imp: impl_ } Semantics { db, imp: impl_ }
} }
@ -1056,7 +1056,7 @@ impl<'db> SemanticsImpl<'db> {
.unwrap_or_default() .unwrap_or_default()
} }
fn with_ctx<F: FnOnce(&mut SourceToDefCtx) -> T, T>(&self, f: F) -> T { fn with_ctx<F: FnOnce(&mut SourceToDefCtx<'_, '_>) -> T, T>(&self, f: F) -> T {
let mut cache = self.s2d_cache.borrow_mut(); let mut cache = self.s2d_cache.borrow_mut();
let mut ctx = SourceToDefCtx { db: self.db, cache: &mut *cache }; let mut ctx = SourceToDefCtx { db: self.db, cache: &mut *cache };
f(&mut ctx) f(&mut ctx)
@ -1280,7 +1280,7 @@ impl<'db> SemanticsImpl<'db> {
} }
fn macro_call_to_macro_id( fn macro_call_to_macro_id(
ctx: &mut SourceToDefCtx, ctx: &mut SourceToDefCtx<'_, '_>,
db: &dyn AstDatabase, db: &dyn AstDatabase,
macro_call_id: MacroCallId, macro_call_id: MacroCallId,
) -> Option<MacroId> { ) -> Option<MacroId> {
@ -1302,14 +1302,14 @@ fn macro_call_to_macro_id(
pub trait ToDef: AstNode + Clone { pub trait ToDef: AstNode + Clone {
type Def; type Def;
fn to_def(sema: &SemanticsImpl, src: InFile<Self>) -> Option<Self::Def>; fn to_def(sema: &SemanticsImpl<'_>, src: InFile<Self>) -> Option<Self::Def>;
} }
macro_rules! to_def_impls { macro_rules! to_def_impls {
($(($def:path, $ast:path, $meth:ident)),* ,) => {$( ($(($def:path, $ast:path, $meth:ident)),* ,) => {$(
impl ToDef for $ast { impl ToDef for $ast {
type Def = $def; type Def = $def;
fn to_def(sema: &SemanticsImpl, src: InFile<Self>) -> Option<Self::Def> { fn to_def(sema: &SemanticsImpl<'_>, src: InFile<Self>) -> Option<Self::Def> {
sema.with_ctx(|ctx| ctx.$meth(src)).map(<$def>::from) sema.with_ctx(|ctx| ctx.$meth(src)).map(<$def>::from)
} }
} }

View file

@ -32,7 +32,7 @@ pub struct DeclarationLocation {
} }
impl DeclarationLocation { impl DeclarationLocation {
pub fn syntax<DB: HirDatabase>(&self, sema: &Semantics<DB>) -> Option<SyntaxNode> { pub fn syntax<DB: HirDatabase>(&self, sema: &Semantics<'_, DB>) -> Option<SyntaxNode> {
let root = sema.parse_or_expand(self.hir_file_id)?; let root = sema.parse_or_expand(self.hir_file_id)?;
Some(self.ptr.to_node(&root)) Some(self.ptr.to_node(&root))
} }

View file

@ -144,7 +144,7 @@ pub(crate) struct Assists {
} }
impl Assists { impl Assists {
pub(crate) fn new(ctx: &AssistContext, resolve: AssistResolveStrategy) -> Assists { pub(crate) fn new(ctx: &AssistContext<'_>, resolve: AssistResolveStrategy) -> Assists {
Assists { Assists {
resolve, resolve,
file: ctx.frange.file_id, file: ctx.frange.file_id,

View file

@ -19,7 +19,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// let x: i32 = 92; // let x: i32 = 92;
// } // }
// ``` // ```
pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let (ascribed_ty, expr, pat) = if let Some(let_stmt) = ctx.find_node_at_offset::<LetStmt>() { let (ascribed_ty, expr, pat) = if let Some(let_stmt) = ctx.find_node_at_offset::<LetStmt>() {
let cursor_in_range = { let cursor_in_range = {
let eq_range = let_stmt.eq_token()?.text_range(); let eq_range = let_stmt.eq_token()?.text_range();

View file

@ -27,7 +27,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// } // }
// } // }
// ``` // ```
pub(crate) fn add_label_to_loop(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn add_label_to_loop(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let loop_kw = ctx.find_token_syntax_at_offset(T![loop])?; let loop_kw = ctx.find_token_syntax_at_offset(T![loop])?;
let loop_expr = loop_kw.parent().and_then(ast::LoopExpr::cast)?; let loop_expr = loop_kw.parent().and_then(ast::LoopExpr::cast)?;
if loop_expr.label().is_some() { if loop_expr.label().is_some() {

View file

@ -19,7 +19,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// y: u32, // y: u32,
// } // }
// ``` // ```
pub(crate) fn add_lifetime_to_type(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn add_lifetime_to_type(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let ref_type_focused = ctx.find_node_at_offset::<ast::RefType>()?; let ref_type_focused = ctx.find_node_at_offset::<ast::RefType>()?;
if ref_type_focused.lifetime().is_some() { if ref_type_focused.lifetime().is_some() {
return None; return None;

View file

@ -44,7 +44,7 @@ use crate::{
// } // }
// } // }
// ``` // ```
pub(crate) fn add_missing_impl_members(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn add_missing_impl_members(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
add_missing_impl_members_inner( add_missing_impl_members_inner(
acc, acc,
ctx, ctx,
@ -85,7 +85,10 @@ pub(crate) fn add_missing_impl_members(acc: &mut Assists, ctx: &AssistContext) -
// $0fn bar(&self) {} // $0fn bar(&self) {}
// } // }
// ``` // ```
pub(crate) fn add_missing_default_members(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn add_missing_default_members(
acc: &mut Assists,
ctx: &AssistContext<'_>,
) -> Option<()> {
add_missing_impl_members_inner( add_missing_impl_members_inner(
acc, acc,
ctx, ctx,
@ -97,7 +100,7 @@ pub(crate) fn add_missing_default_members(acc: &mut Assists, ctx: &AssistContext
fn add_missing_impl_members_inner( fn add_missing_impl_members_inner(
acc: &mut Assists, acc: &mut Assists,
ctx: &AssistContext, ctx: &AssistContext<'_>,
mode: DefaultMethods, mode: DefaultMethods,
assist_id: &'static str, assist_id: &'static str,
label: &'static str, label: &'static str,
@ -164,7 +167,7 @@ fn add_missing_impl_members_inner(
} }
fn try_gen_trait_body( fn try_gen_trait_body(
ctx: &AssistContext, ctx: &AssistContext<'_>,
func: &ast::Fn, func: &ast::Fn,
trait_: &hir::Trait, trait_: &hir::Trait,
impl_def: &ast::Impl, impl_def: &ast::Impl,

View file

@ -36,7 +36,7 @@ use crate::{
// } // }
// } // }
// ``` // ```
pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let match_expr = ctx.find_node_at_offset_with_descend::<ast::MatchExpr>()?; let match_expr = ctx.find_node_at_offset_with_descend::<ast::MatchExpr>()?;
let match_arm_list = match_expr.match_arm_list()?; let match_arm_list = match_expr.match_arm_list()?;
let target_range = ctx.sema.original_range(match_expr.syntax()).range; let target_range = ctx.sema.original_range(match_expr.syntax()).range;
@ -221,7 +221,7 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext) ->
} }
fn cursor_at_trivial_match_arm_list( fn cursor_at_trivial_match_arm_list(
ctx: &AssistContext, ctx: &AssistContext<'_>,
match_expr: &MatchExpr, match_expr: &MatchExpr,
match_arm_list: &MatchArmList, match_arm_list: &MatchArmList,
) -> Option<()> { ) -> Option<()> {
@ -321,7 +321,7 @@ impl ExtendedEnum {
} }
} }
fn resolve_enum_def(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> Option<ExtendedEnum> { fn resolve_enum_def(sema: &Semantics<'_, RootDatabase>, expr: &ast::Expr) -> Option<ExtendedEnum> {
sema.type_of_expr(expr)?.adjusted().autoderef(sema.db).find_map(|ty| match ty.as_adt() { sema.type_of_expr(expr)?.adjusted().autoderef(sema.db).find_map(|ty| match ty.as_adt() {
Some(Adt::Enum(e)) => Some(ExtendedEnum::Enum(e)), Some(Adt::Enum(e)) => Some(ExtendedEnum::Enum(e)),
_ => ty.is_bool().then(|| ExtendedEnum::Bool), _ => ty.is_bool().then(|| ExtendedEnum::Bool),
@ -329,7 +329,7 @@ fn resolve_enum_def(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> Option<
} }
fn resolve_tuple_of_enum_def( fn resolve_tuple_of_enum_def(
sema: &Semantics<RootDatabase>, sema: &Semantics<'_, RootDatabase>,
expr: &ast::Expr, expr: &ast::Expr,
) -> Option<Vec<ExtendedEnum>> { ) -> Option<Vec<ExtendedEnum>> {
sema.type_of_expr(expr)? sema.type_of_expr(expr)?

View file

@ -15,7 +15,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// ``` // ```
// fn foo() -> i32 { 42i32 } // fn foo() -> i32 { 42i32 }
// ``` // ```
pub(crate) fn add_return_type(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn add_return_type(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let (fn_type, tail_expr, builder_edit_pos) = extract_tail(ctx)?; let (fn_type, tail_expr, builder_edit_pos) = extract_tail(ctx)?;
let module = ctx.sema.scope(tail_expr.syntax())?.module(); let module = ctx.sema.scope(tail_expr.syntax())?.module();
let ty = ctx.sema.type_of_expr(&peel_blocks(tail_expr.clone()))?.original(); let ty = ctx.sema.type_of_expr(&peel_blocks(tail_expr.clone()))?.original();
@ -132,7 +132,7 @@ fn peel_blocks(mut expr: ast::Expr) -> ast::Expr {
expr expr
} }
fn extract_tail(ctx: &AssistContext) -> Option<(FnType, ast::Expr, InsertOrReplace)> { fn extract_tail(ctx: &AssistContext<'_>) -> Option<(FnType, ast::Expr, InsertOrReplace)> {
let (fn_type, tail_expr, return_type_range, action) = let (fn_type, tail_expr, return_type_range, action) =
if let Some(closure) = ctx.find_node_at_offset::<ast::ClosureExpr>() { if let Some(closure) = ctx.find_node_at_offset::<ast::ClosureExpr>() {
let rpipe = closure.param_list()?.syntax().last_token()?; let rpipe = closure.param_list()?.syntax().last_token()?;

View file

@ -24,7 +24,7 @@ use crate::{
// let x = make::<${0:_}>(); // let x = make::<${0:_}>();
// } // }
// ``` // ```
pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let ident = ctx.find_token_syntax_at_offset(SyntaxKind::IDENT).or_else(|| { let ident = ctx.find_token_syntax_at_offset(SyntaxKind::IDENT).or_else(|| {
let arg_list = ctx.find_node_at_offset::<ast::ArgList>()?; let arg_list = ctx.find_node_at_offset::<ast::ArgList>()?;
if arg_list.args().next().is_some() { if arg_list.args().next().is_some() {

View file

@ -22,7 +22,7 @@ use crate::{utils::invert_boolean_expression, AssistContext, AssistId, AssistKin
// if !(x == 4 && y >= 3.14) {} // if !(x == 4 && y >= 3.14) {}
// } // }
// ``` // ```
pub(crate) fn apply_demorgan(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn apply_demorgan(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let expr = ctx.find_node_at_offset::<ast::BinExpr>()?; let expr = ctx.find_node_at_offset::<ast::BinExpr>()?;
let op = expr.op_kind()?; let op = expr.op_kind()?;
let op_range = expr.op_token()?.text_range(); let op_range = expr.op_token()?.text_range();

View file

@ -87,7 +87,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists, GroupLabel};
// } // }
// # pub mod std { pub mod collections { pub struct HashMap { } } } // # pub mod std { pub mod collections { pub struct HashMap { } } }
// ``` // ```
pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let (import_assets, syntax_under_caret) = find_importable_node(ctx)?; let (import_assets, syntax_under_caret) = find_importable_node(ctx)?;
let mut proposed_imports = let mut proposed_imports =
import_assets.search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind); import_assets.search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind);
@ -142,7 +142,9 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
Some(()) Some(())
} }
pub(super) fn find_importable_node(ctx: &AssistContext) -> Option<(ImportAssets, SyntaxElement)> { pub(super) fn find_importable_node(
ctx: &AssistContext<'_>,
) -> Option<(ImportAssets, SyntaxElement)> {
if let Some(path_under_caret) = ctx.find_node_at_offset_with_descend::<ast::Path>() { if let Some(path_under_caret) = ctx.find_node_at_offset_with_descend::<ast::Path>() {
ImportAssets::for_exact_path(&path_under_caret, &ctx.sema) ImportAssets::for_exact_path(&path_under_caret, &ctx.sema)
.zip(Some(path_under_caret.syntax().clone().into())) .zip(Some(path_under_caret.syntax().clone().into()))
@ -177,7 +179,7 @@ fn group_label(import_candidate: &ImportCandidate) -> GroupLabel {
/// Determine how relevant a given import is in the current context. Higher scores are more /// Determine how relevant a given import is in the current context. Higher scores are more
/// relevant. /// relevant.
fn relevance_score( fn relevance_score(
ctx: &AssistContext, ctx: &AssistContext<'_>,
import: &LocatedImport, import: &LocatedImport,
current_module: Option<&Module>, current_module: Option<&Module>,
) -> i32 { ) -> i32 {

View file

@ -20,14 +20,14 @@ use crate::{utils::vis_offset, AssistContext, AssistId, AssistKind, Assists};
// ``` // ```
// pub(crate) fn frobnicate() {} // pub(crate) fn frobnicate() {}
// ``` // ```
pub(crate) fn change_visibility(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn change_visibility(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
if let Some(vis) = ctx.find_node_at_offset::<ast::Visibility>() { if let Some(vis) = ctx.find_node_at_offset::<ast::Visibility>() {
return change_vis(acc, vis); return change_vis(acc, vis);
} }
add_vis(acc, ctx) add_vis(acc, ctx)
} }
fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { fn add_vis(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let item_keyword = ctx.token_at_offset().find(|leaf| { let item_keyword = ctx.token_at_offset().find(|leaf| {
matches!( matches!(
leaf.kind(), leaf.kind(),

View file

@ -37,7 +37,7 @@ use crate::{
// cond.then(|| val) // cond.then(|| val)
// } // }
// ``` // ```
pub(crate) fn convert_if_to_bool_then(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn convert_if_to_bool_then(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
// FIXME applies to match as well // FIXME applies to match as well
let expr = ctx.find_node_at_offset::<ast::IfExpr>()?; let expr = ctx.find_node_at_offset::<ast::IfExpr>()?;
if !expr.if_token()?.text_range().contains_inclusive(ctx.offset()) { if !expr.if_token()?.text_range().contains_inclusive(ctx.offset()) {
@ -149,7 +149,7 @@ pub(crate) fn convert_if_to_bool_then(acc: &mut Assists, ctx: &AssistContext) ->
// } // }
// } // }
// ``` // ```
pub(crate) fn convert_bool_then_to_if(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn convert_bool_then_to_if(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let name_ref = ctx.find_node_at_offset::<ast::NameRef>()?; let name_ref = ctx.find_node_at_offset::<ast::NameRef>()?;
let mcall = name_ref.syntax().parent().and_then(ast::MethodCallExpr::cast)?; let mcall = name_ref.syntax().parent().and_then(ast::MethodCallExpr::cast)?;
let receiver = mcall.receiver()?; let receiver = mcall.receiver()?;
@ -219,7 +219,7 @@ pub(crate) fn convert_bool_then_to_if(acc: &mut Assists, ctx: &AssistContext) ->
} }
fn option_variants( fn option_variants(
sema: &Semantics<RootDatabase>, sema: &Semantics<'_, RootDatabase>,
expr: &SyntaxNode, expr: &SyntaxNode,
) -> Option<(hir::Variant, hir::Variant)> { ) -> Option<(hir::Variant, hir::Variant)> {
let fam = FamousDefs(sema, sema.scope(expr)?.krate()); let fam = FamousDefs(sema, sema.scope(expr)?.krate());
@ -237,7 +237,7 @@ fn option_variants(
/// Traverses the expression checking if it contains `return` or `?` expressions or if any tail is not a `Some(expr)` expression. /// Traverses the expression checking if it contains `return` or `?` expressions or if any tail is not a `Some(expr)` expression.
/// If any of these conditions are met it is impossible to rewrite this as a `bool::then` call. /// If any of these conditions are met it is impossible to rewrite this as a `bool::then` call.
fn is_invalid_body( fn is_invalid_body(
sema: &Semantics<RootDatabase>, sema: &Semantics<'_, RootDatabase>,
some_variant: hir::Variant, some_variant: hir::Variant,
expr: &ast::Expr, expr: &ast::Expr,
) -> bool { ) -> bool {
@ -272,7 +272,7 @@ fn is_invalid_body(
} }
fn block_is_none_variant( fn block_is_none_variant(
sema: &Semantics<RootDatabase>, sema: &Semantics<'_, RootDatabase>,
block: &ast::BlockExpr, block: &ast::BlockExpr,
none_variant: hir::Variant, none_variant: hir::Variant,
) -> bool { ) -> bool {

View file

@ -21,7 +21,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// comment // comment
// */ // */
// ``` // ```
pub(crate) fn convert_comment_block(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn convert_comment_block(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let comment = ctx.find_token_at_offset::<ast::Comment>()?; let comment = ctx.find_token_at_offset::<ast::Comment>()?;
// Only allow comments which are alone on their line // Only allow comments which are alone on their line
if let Some(prev) = comment.syntax().prev_token() { if let Some(prev) = comment.syntax().prev_token() {

View file

@ -13,7 +13,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists, GroupLabel};
// ``` // ```
// const _: i32 = 0b1010; // const _: i32 = 0b1010;
// ``` // ```
pub(crate) fn convert_integer_literal(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn convert_integer_literal(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let literal = ctx.find_node_at_offset::<ast::Literal>()?; let literal = ctx.find_node_at_offset::<ast::Literal>()?;
let literal = match literal.kind() { let literal = match literal.kind() {
ast::LiteralKind::IntNumber(it) => it, ast::LiteralKind::IntNumber(it) => it,

View file

@ -31,7 +31,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// } // }
// } // }
// ``` // ```
pub(crate) fn convert_into_to_from(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn convert_into_to_from(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let impl_ = ctx.find_node_at_offset::<ast::Impl>()?; let impl_ = ctx.find_node_at_offset::<ast::Impl>()?;
let src_type = impl_.self_ty()?; let src_type = impl_.self_ty()?;
let ast_trait = impl_.trait_()?; let ast_trait = impl_.trait_()?;

View file

@ -32,7 +32,10 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// } // }
// } // }
// ``` // ```
pub(crate) fn convert_iter_for_each_to_for(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn convert_iter_for_each_to_for(
acc: &mut Assists,
ctx: &AssistContext<'_>,
) -> Option<()> {
let method = ctx.find_node_at_offset::<ast::MethodCallExpr>()?; let method = ctx.find_node_at_offset::<ast::MethodCallExpr>()?;
let closure = match method.arg_list()?.args().next()? { let closure = match method.arg_list()?.args().next()? {
@ -91,7 +94,10 @@ pub(crate) fn convert_iter_for_each_to_for(acc: &mut Assists, ctx: &AssistContex
// }); // });
// } // }
// ``` // ```
pub(crate) fn convert_for_loop_with_for_each(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn convert_for_loop_with_for_each(
acc: &mut Assists,
ctx: &AssistContext<'_>,
) -> Option<()> {
let for_loop = ctx.find_node_at_offset::<ast::ForExpr>()?; let for_loop = ctx.find_node_at_offset::<ast::ForExpr>()?;
let iterable = for_loop.iterable()?; let iterable = for_loop.iterable()?;
let pat = for_loop.pat()?; let pat = for_loop.pat()?;
@ -136,7 +142,7 @@ pub(crate) fn convert_for_loop_with_for_each(acc: &mut Assists, ctx: &AssistCont
/// returning an Iterator called iter or iter_mut (depending on the type of reference) then return /// returning an Iterator called iter or iter_mut (depending on the type of reference) then return
/// the expression behind the reference and the method name /// the expression behind the reference and the method name
fn is_ref_and_impls_iter_method( fn is_ref_and_impls_iter_method(
sema: &hir::Semantics<ide_db::RootDatabase>, sema: &hir::Semantics<'_, ide_db::RootDatabase>,
iterable: &ast::Expr, iterable: &ast::Expr,
) -> Option<(ast::Expr, hir::Name)> { ) -> Option<(ast::Expr, hir::Name)> {
let ref_expr = match iterable { let ref_expr = match iterable {
@ -173,7 +179,7 @@ fn is_ref_and_impls_iter_method(
} }
/// Whether iterable implements core::Iterator /// Whether iterable implements core::Iterator
fn impls_core_iter(sema: &hir::Semantics<ide_db::RootDatabase>, iterable: &ast::Expr) -> bool { fn impls_core_iter(sema: &hir::Semantics<'_, ide_db::RootDatabase>, iterable: &ast::Expr) -> bool {
(|| { (|| {
let it_typ = sema.type_of_expr(iterable)?.adjusted(); let it_typ = sema.type_of_expr(iterable)?.adjusted();
@ -188,7 +194,7 @@ fn impls_core_iter(sema: &hir::Semantics<ide_db::RootDatabase>, iterable: &ast::
} }
fn validate_method_call_expr( fn validate_method_call_expr(
ctx: &AssistContext, ctx: &AssistContext<'_>,
expr: ast::MethodCallExpr, expr: ast::MethodCallExpr,
) -> Option<(ast::Expr, ast::Expr)> { ) -> Option<(ast::Expr, ast::Expr)> {
let name_ref = expr.name_ref()?; let name_ref = expr.name_ref()?;

View file

@ -9,7 +9,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
fn binders_in_pat( fn binders_in_pat(
acc: &mut Vec<(Name, bool)>, acc: &mut Vec<(Name, bool)>,
pat: &Pat, pat: &Pat,
sem: &Semantics<RootDatabase>, sem: &Semantics<'_, RootDatabase>,
) -> Option<()> { ) -> Option<()> {
use Pat::*; use Pat::*;
match pat { match pat {
@ -115,7 +115,7 @@ fn binders_to_str(binders: &[(Name, bool)], addmut: bool) -> String {
// }; // };
// } // }
// ``` // ```
pub(crate) fn convert_let_else_to_match(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn convert_let_else_to_match(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
// should focus on else token to trigger // should focus on else token to trigger
let else_token = ctx.find_token_syntax_at_offset(T![else])?; let else_token = ctx.find_token_syntax_at_offset(T![else])?;
let let_stmt = LetStmt::cast(else_token.parent()?.parent()?)?; let let_stmt = LetStmt::cast(else_token.parent()?.parent()?)?;

View file

@ -40,7 +40,7 @@ use crate::{
// bar(); // bar();
// } // }
// ``` // ```
pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let if_expr: ast::IfExpr = ctx.find_node_at_offset()?; let if_expr: ast::IfExpr = ctx.find_node_at_offset()?;
if if_expr.else_branch().is_some() { if if_expr.else_branch().is_some() {
return None; return None;

View file

@ -48,7 +48,7 @@ use crate::{assist_context::AssistBuilder, AssistContext, AssistId, AssistKind,
// ``` // ```
pub(crate) fn convert_tuple_struct_to_named_struct( pub(crate) fn convert_tuple_struct_to_named_struct(
acc: &mut Assists, acc: &mut Assists,
ctx: &AssistContext, ctx: &AssistContext<'_>,
) -> Option<()> { ) -> Option<()> {
let strukt = ctx let strukt = ctx
.find_node_at_offset::<ast::Struct>() .find_node_at_offset::<ast::Struct>()
@ -79,7 +79,7 @@ pub(crate) fn convert_tuple_struct_to_named_struct(
} }
fn edit_struct_def( fn edit_struct_def(
ctx: &AssistContext, ctx: &AssistContext<'_>,
edit: &mut AssistBuilder, edit: &mut AssistBuilder,
strukt: &Either<ast::Struct, ast::Variant>, strukt: &Either<ast::Struct, ast::Variant>,
tuple_fields: ast::TupleFieldList, tuple_fields: ast::TupleFieldList,
@ -121,7 +121,7 @@ fn edit_struct_def(
} }
fn edit_struct_references( fn edit_struct_references(
ctx: &AssistContext, ctx: &AssistContext<'_>,
edit: &mut AssistBuilder, edit: &mut AssistBuilder,
strukt: Either<hir::Struct, hir::Variant>, strukt: Either<hir::Struct, hir::Variant>,
names: &[ast::Name], names: &[ast::Name],
@ -202,7 +202,7 @@ fn edit_struct_references(
} }
fn edit_field_references( fn edit_field_references(
ctx: &AssistContext, ctx: &AssistContext<'_>,
edit: &mut AssistBuilder, edit: &mut AssistBuilder,
fields: impl Iterator<Item = ast::TupleField>, fields: impl Iterator<Item = ast::TupleField>,
names: &[ast::Name], names: &[ast::Name],

View file

@ -38,7 +38,7 @@ use crate::{
// } // }
// } // }
// ``` // ```
pub(crate) fn convert_while_to_loop(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn convert_while_to_loop(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let while_kw = ctx.find_token_syntax_at_offset(T![while])?; let while_kw = ctx.find_token_syntax_at_offset(T![while])?;
let while_expr = while_kw.parent().and_then(ast::WhileExpr::cast)?; let while_expr = while_kw.parent().and_then(ast::WhileExpr::cast)?;
let while_body = while_expr.loop_body()?; let while_body = while_expr.loop_body()?;

View file

@ -27,7 +27,7 @@ use crate::assist_context::{AssistBuilder, AssistContext, Assists};
// let v = _0; // let v = _0;
// } // }
// ``` // ```
pub(crate) fn destructure_tuple_binding(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn destructure_tuple_binding(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
destructure_tuple_binding_impl(acc, ctx, false) destructure_tuple_binding_impl(acc, ctx, false)
} }
@ -51,7 +51,7 @@ pub(crate) fn destructure_tuple_binding(acc: &mut Assists, ctx: &AssistContext)
// ``` // ```
pub(crate) fn destructure_tuple_binding_impl( pub(crate) fn destructure_tuple_binding_impl(
acc: &mut Assists, acc: &mut Assists,
ctx: &AssistContext, ctx: &AssistContext<'_>,
with_sub_pattern: bool, with_sub_pattern: bool,
) -> Option<()> { ) -> Option<()> {
let ident_pat = ctx.find_node_at_offset::<ast::IdentPat>()?; let ident_pat = ctx.find_node_at_offset::<ast::IdentPat>()?;
@ -82,7 +82,7 @@ pub(crate) fn destructure_tuple_binding_impl(
Some(()) Some(())
} }
fn collect_data(ident_pat: IdentPat, ctx: &AssistContext) -> Option<TupleData> { fn collect_data(ident_pat: IdentPat, ctx: &AssistContext<'_>) -> Option<TupleData> {
if ident_pat.at_token().is_some() { if ident_pat.at_token().is_some() {
// Cannot destructure pattern with sub-pattern: // Cannot destructure pattern with sub-pattern:
// Only IdentPat can have sub-pattern, // Only IdentPat can have sub-pattern,
@ -126,7 +126,7 @@ fn collect_data(ident_pat: IdentPat, ctx: &AssistContext) -> Option<TupleData> {
} }
fn generate_name( fn generate_name(
_ctx: &AssistContext, _ctx: &AssistContext<'_>,
index: usize, index: usize,
_tuple_name: &str, _tuple_name: &str,
_ident_pat: &IdentPat, _ident_pat: &IdentPat,
@ -150,7 +150,7 @@ struct TupleData {
usages: Option<UsageSearchResult>, usages: Option<UsageSearchResult>,
} }
fn edit_tuple_assignment( fn edit_tuple_assignment(
ctx: &AssistContext, ctx: &AssistContext<'_>,
builder: &mut AssistBuilder, builder: &mut AssistBuilder,
data: &TupleData, data: &TupleData,
in_sub_pattern: bool, in_sub_pattern: bool,
@ -196,7 +196,7 @@ fn edit_tuple_assignment(
fn edit_tuple_usages( fn edit_tuple_usages(
data: &TupleData, data: &TupleData,
builder: &mut AssistBuilder, builder: &mut AssistBuilder,
ctx: &AssistContext, ctx: &AssistContext<'_>,
in_sub_pattern: bool, in_sub_pattern: bool,
) { ) {
if let Some(usages) = data.usages.as_ref() { if let Some(usages) = data.usages.as_ref() {
@ -210,7 +210,7 @@ fn edit_tuple_usages(
} }
} }
fn edit_tuple_usage( fn edit_tuple_usage(
ctx: &AssistContext, ctx: &AssistContext<'_>,
builder: &mut AssistBuilder, builder: &mut AssistBuilder,
usage: &FileReference, usage: &FileReference,
data: &TupleData, data: &TupleData,
@ -238,7 +238,7 @@ fn edit_tuple_usage(
} }
fn edit_tuple_field_usage( fn edit_tuple_field_usage(
ctx: &AssistContext, ctx: &AssistContext<'_>,
builder: &mut AssistBuilder, builder: &mut AssistBuilder,
data: &TupleData, data: &TupleData,
index: TupleIndex, index: TupleIndex,
@ -321,7 +321,7 @@ impl RefData {
} }
} }
} }
fn handle_ref_field_usage(ctx: &AssistContext, field_expr: &FieldExpr) -> RefData { fn handle_ref_field_usage(ctx: &AssistContext<'_>, field_expr: &FieldExpr) -> RefData {
let s = field_expr.syntax(); let s = field_expr.syntax();
let mut ref_data = let mut ref_data =
RefData { range: s.text_range(), needs_deref: true, needs_parentheses: true }; RefData { range: s.text_range(), needs_deref: true, needs_parentheses: true };
@ -368,8 +368,8 @@ fn handle_ref_field_usage(ctx: &AssistContext, field_expr: &FieldExpr) -> RefDat
// other combinations (`&value` -> `value`, `&&value` -> `&value`, `&value` -> `&&value`) might or might not be able to auto-ref/deref, // other combinations (`&value` -> `value`, `&&value` -> `&value`, `&value` -> `&&value`) might or might not be able to auto-ref/deref,
// but there might be trait implementations an added `&` might resolve to // but there might be trait implementations an added `&` might resolve to
// -> ONLY handle auto-ref from `value` to `&value` // -> ONLY handle auto-ref from `value` to `&value`
fn is_auto_ref(ctx: &AssistContext, call_expr: &MethodCallExpr) -> bool { fn is_auto_ref(ctx: &AssistContext<'_>, call_expr: &MethodCallExpr) -> bool {
fn impl_(ctx: &AssistContext, call_expr: &MethodCallExpr) -> Option<bool> { fn impl_(ctx: &AssistContext<'_>, call_expr: &MethodCallExpr) -> Option<bool> {
let rec = call_expr.receiver()?; let rec = call_expr.receiver()?;
let rec_ty = ctx.sema.type_of_expr(&rec)?.original(); let rec_ty = ctx.sema.type_of_expr(&rec)?.original();
// input must be actual value // input must be actual value
@ -426,7 +426,7 @@ mod tests {
// Tests for direct tuple destructure: // Tests for direct tuple destructure:
// `let $0t = (1,2);` -> `let (_0, _1) = (1,2);` // `let $0t = (1,2);` -> `let (_0, _1) = (1,2);`
fn assist(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { fn assist(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
destructure_tuple_binding_impl(acc, ctx, false) destructure_tuple_binding_impl(acc, ctx, false)
} }
@ -1191,10 +1191,10 @@ fn main {
use super::*; use super::*;
use crate::tests::check_assist_by_label; use crate::tests::check_assist_by_label;
fn assist(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { fn assist(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
destructure_tuple_binding_impl(acc, ctx, true) destructure_tuple_binding_impl(acc, ctx, true)
} }
fn in_place_assist(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { fn in_place_assist(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
destructure_tuple_binding_impl(acc, ctx, false) destructure_tuple_binding_impl(acc, ctx, false)
} }
@ -1256,7 +1256,7 @@ fn main() {
#[test] #[test]
fn trigger_both_destructure_tuple_assists() { fn trigger_both_destructure_tuple_assists() {
fn assist(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { fn assist(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
destructure_tuple_binding_impl(acc, ctx, true) destructure_tuple_binding_impl(acc, ctx, true)
} }
let text = r#" let text = r#"

View file

@ -40,7 +40,7 @@ use crate::{
// //
// fn qux(bar: Bar, baz: Baz) {} // fn qux(bar: Bar, baz: Baz) {}
// ``` // ```
pub(crate) fn expand_glob_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn expand_glob_import(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let star = ctx.find_token_syntax_at_offset(T![*])?; let star = ctx.find_token_syntax_at_offset(T![*])?;
let use_tree = star.parent().and_then(ast::UseTree::cast)?; let use_tree = star.parent().and_then(ast::UseTree::cast)?;
let (parent, mod_path) = find_parent_and_path(&star)?; let (parent, mod_path) = find_parent_and_path(&star)?;
@ -112,7 +112,7 @@ fn find_parent_and_path(
} }
} }
fn def_is_referenced_in(def: Definition, ctx: &AssistContext) -> bool { fn def_is_referenced_in(def: Definition, ctx: &AssistContext<'_>) -> bool {
let search_scope = SearchScope::single_file(ctx.file_id()); let search_scope = SearchScope::single_file(ctx.file_id());
def.usages(&ctx.sema).in_scope(search_scope).at_least_one() def.usages(&ctx.sema).in_scope(search_scope).at_least_one()
} }
@ -139,7 +139,7 @@ impl Ref {
struct Refs(Vec<Ref>); struct Refs(Vec<Ref>);
impl Refs { impl Refs {
fn used_refs(&self, ctx: &AssistContext) -> Refs { fn used_refs(&self, ctx: &AssistContext<'_>) -> Refs {
Refs( Refs(
self.0 self.0
.clone() .clone()
@ -168,7 +168,7 @@ impl Refs {
} }
} }
fn find_refs_in_mod(ctx: &AssistContext, module: Module, visible_from: Module) -> Option<Refs> { fn find_refs_in_mod(ctx: &AssistContext<'_>, module: Module, visible_from: Module) -> Option<Refs> {
if !is_mod_visible_from(ctx, module, visible_from) { if !is_mod_visible_from(ctx, module, visible_from) {
return None; return None;
} }
@ -178,7 +178,7 @@ fn find_refs_in_mod(ctx: &AssistContext, module: Module, visible_from: Module) -
Some(Refs(refs)) Some(Refs(refs))
} }
fn is_mod_visible_from(ctx: &AssistContext, module: Module, from: Module) -> bool { fn is_mod_visible_from(ctx: &AssistContext<'_>, module: Module, from: Module) -> bool {
match module.parent(ctx.db()) { match module.parent(ctx.db()) {
Some(parent) => { Some(parent) => {
module.visibility(ctx.db()).is_visible_from(ctx.db(), from.into()) module.visibility(ctx.db()).is_visible_from(ctx.db(), from.into())
@ -202,7 +202,7 @@ fn is_mod_visible_from(ctx: &AssistContext, module: Module, from: Module) -> boo
// use foo::*$0; // use foo::*$0;
// use baz::Baz; // use baz::Baz;
// ↑ --------------- // ↑ ---------------
fn find_imported_defs(ctx: &AssistContext, star: SyntaxToken) -> Option<Vec<Definition>> { fn find_imported_defs(ctx: &AssistContext<'_>, star: SyntaxToken) -> Option<Vec<Definition>> {
let parent_use_item_syntax = star.parent_ancestors().find_map(|n| { let parent_use_item_syntax = star.parent_ancestors().find_map(|n| {
if ast::Use::can_cast(n.kind()) { if ast::Use::can_cast(n.kind()) {
Some(n) Some(n)
@ -239,7 +239,7 @@ fn find_imported_defs(ctx: &AssistContext, star: SyntaxToken) -> Option<Vec<Defi
} }
fn find_names_to_import( fn find_names_to_import(
ctx: &AssistContext, ctx: &AssistContext<'_>,
refs_in_target: Refs, refs_in_target: Refs,
imported_defs: Vec<Definition>, imported_defs: Vec<Definition>,
) -> Vec<Name> { ) -> Vec<Name> {

View file

@ -60,7 +60,7 @@ use crate::{
// let k = m + n; // let k = m + n;
// } // }
// ``` // ```
pub(crate) fn extract_function(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn extract_function(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let range = ctx.selection_trimmed(); let range = ctx.selection_trimmed();
if range.is_empty() { if range.is_empty() {
return None; return None;
@ -170,7 +170,7 @@ pub(crate) fn extract_function(acc: &mut Assists, ctx: &AssistContext) -> Option
) )
} }
fn make_function_name(semantics_scope: &hir::SemanticsScope) -> ast::NameRef { fn make_function_name(semantics_scope: &hir::SemanticsScope<'_>) -> ast::NameRef {
let mut names_in_scope = vec![]; let mut names_in_scope = vec![];
semantics_scope.process_all_names(&mut |name, _| names_in_scope.push(name.to_string())); semantics_scope.process_all_names(&mut |name, _| names_in_scope.push(name.to_string()));
@ -366,7 +366,7 @@ struct OutlivedLocal {
struct LocalUsages(ide_db::search::UsageSearchResult); struct LocalUsages(ide_db::search::UsageSearchResult);
impl LocalUsages { impl LocalUsages {
fn find_local_usages(ctx: &AssistContext, var: Local) -> Self { fn find_local_usages(ctx: &AssistContext<'_>, var: Local) -> Self {
Self( Self(
Definition::Local(var) Definition::Local(var)
.usages(&ctx.sema) .usages(&ctx.sema)
@ -381,7 +381,7 @@ impl LocalUsages {
} }
impl Function { impl Function {
fn return_type(&self, ctx: &AssistContext) -> FunType { fn return_type(&self, ctx: &AssistContext<'_>) -> FunType {
match &self.ret_ty { match &self.ret_ty {
RetType::Expr(ty) if ty.is_unit() => FunType::Unit, RetType::Expr(ty) if ty.is_unit() => FunType::Unit,
RetType::Expr(ty) => FunType::Single(ty.clone()), RetType::Expr(ty) => FunType::Single(ty.clone()),
@ -396,7 +396,7 @@ impl Function {
} }
} }
fn self_param_adt(&self, ctx: &AssistContext) -> Option<ast::Adt> { fn self_param_adt(&self, ctx: &AssistContext<'_>) -> Option<ast::Adt> {
let self_param = self.self_param.as_ref()?; let self_param = self.self_param.as_ref()?;
let def = ctx.sema.to_def(self_param)?; let def = ctx.sema.to_def(self_param)?;
let adt = def.ty(ctx.db()).strip_references().as_adt()?; let adt = def.ty(ctx.db()).strip_references().as_adt()?;
@ -421,7 +421,7 @@ impl Param {
} }
} }
fn to_arg(&self, ctx: &AssistContext) -> ast::Expr { fn to_arg(&self, ctx: &AssistContext<'_>) -> ast::Expr {
let var = path_expr_from_local(ctx, self.var); let var = path_expr_from_local(ctx, self.var);
match self.kind() { match self.kind() {
ParamKind::Value | ParamKind::MutValue => var, ParamKind::Value | ParamKind::MutValue => var,
@ -430,7 +430,7 @@ impl Param {
} }
} }
fn to_param(&self, ctx: &AssistContext, module: hir::Module) -> ast::Param { fn to_param(&self, ctx: &AssistContext<'_>, module: hir::Module) -> ast::Param {
let var = self.var.name(ctx.db()).to_string(); let var = self.var.name(ctx.db()).to_string();
let var_name = make::name(&var); let var_name = make::name(&var);
let pat = match self.kind() { let pat = match self.kind() {
@ -452,7 +452,7 @@ impl Param {
} }
impl TryKind { impl TryKind {
fn of_ty(ty: hir::Type, ctx: &AssistContext) -> Option<TryKind> { fn of_ty(ty: hir::Type, ctx: &AssistContext<'_>) -> Option<TryKind> {
if ty.is_unknown() { if ty.is_unknown() {
// We favour Result for `expr?` // We favour Result for `expr?`
return Some(TryKind::Result { ty }); return Some(TryKind::Result { ty });
@ -485,7 +485,7 @@ impl FlowKind {
} }
} }
fn expr_ty(&self, ctx: &AssistContext) -> Option<hir::Type> { fn expr_ty(&self, ctx: &AssistContext<'_>) -> Option<hir::Type> {
match self { match self {
FlowKind::Return(Some(expr)) | FlowKind::Break(_, Some(expr)) => { FlowKind::Return(Some(expr)) | FlowKind::Break(_, Some(expr)) => {
ctx.sema.type_of_expr(expr).map(TypeInfo::adjusted) ctx.sema.type_of_expr(expr).map(TypeInfo::adjusted)
@ -691,7 +691,7 @@ impl FunctionBody {
/// whether it contains an await expression. /// whether it contains an await expression.
fn analyze( fn analyze(
&self, &self,
sema: &Semantics<RootDatabase>, sema: &Semantics<'_, RootDatabase>,
) -> (FxIndexSet<Local>, Option<ast::SelfParam>) { ) -> (FxIndexSet<Local>, Option<ast::SelfParam>) {
let mut self_param = None; let mut self_param = None;
let mut res = FxIndexSet::default(); let mut res = FxIndexSet::default();
@ -741,7 +741,7 @@ impl FunctionBody {
(res, self_param) (res, self_param)
} }
fn analyze_container(&self, sema: &Semantics<RootDatabase>) -> Option<ContainerInfo> { fn analyze_container(&self, sema: &Semantics<'_, RootDatabase>) -> Option<ContainerInfo> {
let mut ancestors = self.parent()?.ancestors(); let mut ancestors = self.parent()?.ancestors();
let infer_expr_opt = |expr| sema.type_of_expr(&expr?).map(TypeInfo::adjusted); let infer_expr_opt = |expr| sema.type_of_expr(&expr?).map(TypeInfo::adjusted);
let mut parent_loop = None; let mut parent_loop = None;
@ -837,7 +837,7 @@ impl FunctionBody {
}) })
} }
fn return_ty(&self, ctx: &AssistContext) -> Option<RetType> { fn return_ty(&self, ctx: &AssistContext<'_>) -> Option<RetType> {
match self.tail_expr() { match self.tail_expr() {
Some(expr) => ctx.sema.type_of_expr(&expr).map(TypeInfo::original).map(RetType::Expr), Some(expr) => ctx.sema.type_of_expr(&expr).map(TypeInfo::original).map(RetType::Expr),
None => Some(RetType::Stmt), None => Some(RetType::Stmt),
@ -847,7 +847,7 @@ impl FunctionBody {
/// Local variables defined inside `body` that are accessed outside of it /// Local variables defined inside `body` that are accessed outside of it
fn ret_values<'a>( fn ret_values<'a>(
&self, &self,
ctx: &'a AssistContext, ctx: &'a AssistContext<'_>,
parent: &SyntaxNode, parent: &SyntaxNode,
) -> impl Iterator<Item = OutlivedLocal> + 'a { ) -> impl Iterator<Item = OutlivedLocal> + 'a {
let parent = parent.clone(); let parent = parent.clone();
@ -860,7 +860,7 @@ impl FunctionBody {
/// Analyses the function body for external control flow. /// Analyses the function body for external control flow.
fn external_control_flow( fn external_control_flow(
&self, &self,
ctx: &AssistContext, ctx: &AssistContext<'_>,
container_info: &ContainerInfo, container_info: &ContainerInfo,
) -> Option<ControlFlow> { ) -> Option<ControlFlow> {
let mut ret_expr = None; let mut ret_expr = None;
@ -950,7 +950,7 @@ impl FunctionBody {
/// Computes additional info that affects param type and mutability /// Computes additional info that affects param type and mutability
fn extracted_function_params( fn extracted_function_params(
&self, &self,
ctx: &AssistContext, ctx: &AssistContext<'_>,
container_info: &ContainerInfo, container_info: &ContainerInfo,
locals: impl Iterator<Item = Local>, locals: impl Iterator<Item = Local>,
) -> Vec<Param> { ) -> Vec<Param> {
@ -1042,7 +1042,11 @@ fn generic_parents(parent: &SyntaxNode) -> Vec<GenericParent> {
} }
/// checks if relevant var is used with `&mut` access inside body /// checks if relevant var is used with `&mut` access inside body
fn has_exclusive_usages(ctx: &AssistContext, usages: &LocalUsages, body: &FunctionBody) -> bool { fn has_exclusive_usages(
ctx: &AssistContext<'_>,
usages: &LocalUsages,
body: &FunctionBody,
) -> bool {
usages usages
.iter() .iter()
.filter(|reference| body.contains_range(reference.range)) .filter(|reference| body.contains_range(reference.range))
@ -1053,7 +1057,7 @@ fn has_exclusive_usages(ctx: &AssistContext, usages: &LocalUsages, body: &Functi
fn reference_is_exclusive( fn reference_is_exclusive(
reference: &FileReference, reference: &FileReference,
node: &dyn HasTokenAtOffset, node: &dyn HasTokenAtOffset,
ctx: &AssistContext, ctx: &AssistContext<'_>,
) -> bool { ) -> bool {
// we directly modify variable with set: `n = 0`, `n += 1` // we directly modify variable with set: `n = 0`, `n += 1`
if reference.category == Some(ReferenceCategory::Write) { if reference.category == Some(ReferenceCategory::Write) {
@ -1070,7 +1074,7 @@ fn reference_is_exclusive(
} }
/// checks if this expr requires `&mut` access, recurses on field access /// checks if this expr requires `&mut` access, recurses on field access
fn expr_require_exclusive_access(ctx: &AssistContext, expr: &ast::Expr) -> Option<bool> { fn expr_require_exclusive_access(ctx: &AssistContext<'_>, expr: &ast::Expr) -> Option<bool> {
if let ast::Expr::MacroExpr(_) = expr { if let ast::Expr::MacroExpr(_) = expr {
// FIXME: expand macro and check output for mutable usages of the variable? // FIXME: expand macro and check output for mutable usages of the variable?
return None; return None;
@ -1172,7 +1176,7 @@ fn path_element_of_reference(
/// list local variables defined inside `body` /// list local variables defined inside `body`
fn locals_defined_in_body( fn locals_defined_in_body(
sema: &Semantics<RootDatabase>, sema: &Semantics<'_, RootDatabase>,
body: &FunctionBody, body: &FunctionBody,
) -> FxIndexSet<Local> { ) -> FxIndexSet<Local> {
// FIXME: this doesn't work well with macros // FIXME: this doesn't work well with macros
@ -1190,7 +1194,7 @@ fn locals_defined_in_body(
/// Returns usage details if local variable is used after(outside of) body /// Returns usage details if local variable is used after(outside of) body
fn local_outlives_body( fn local_outlives_body(
ctx: &AssistContext, ctx: &AssistContext<'_>,
body_range: TextRange, body_range: TextRange,
local: Local, local: Local,
parent: &SyntaxNode, parent: &SyntaxNode,
@ -1215,7 +1219,7 @@ fn local_outlives_body(
/// checks if the relevant local was defined before(outside of) body /// checks if the relevant local was defined before(outside of) body
fn is_defined_outside_of_body( fn is_defined_outside_of_body(
ctx: &AssistContext, ctx: &AssistContext<'_>,
body: &FunctionBody, body: &FunctionBody,
src: &hir::InFile<Either<ast::IdentPat, ast::SelfParam>>, src: &hir::InFile<Either<ast::IdentPat, ast::SelfParam>>,
) -> bool { ) -> bool {
@ -1260,7 +1264,7 @@ fn node_to_insert_after(body: &FunctionBody, anchor: Anchor) -> Option<SyntaxNod
last_ancestor last_ancestor
} }
fn make_call(ctx: &AssistContext, fun: &Function, indent: IndentLevel) -> String { fn make_call(ctx: &AssistContext<'_>, fun: &Function, indent: IndentLevel) -> String {
let ret_ty = fun.return_type(ctx); let ret_ty = fun.return_type(ctx);
let args = make::arg_list(fun.params.iter().map(|param| param.to_arg(ctx))); let args = make::arg_list(fun.params.iter().map(|param| param.to_arg(ctx)));
@ -1429,13 +1433,13 @@ impl FlowHandler {
} }
} }
fn path_expr_from_local(ctx: &AssistContext, var: Local) -> ast::Expr { fn path_expr_from_local(ctx: &AssistContext<'_>, var: Local) -> ast::Expr {
let name = var.name(ctx.db()).to_string(); let name = var.name(ctx.db()).to_string();
make::expr_path(make::ext::ident_path(&name)) make::expr_path(make::ext::ident_path(&name))
} }
fn format_function( fn format_function(
ctx: &AssistContext, ctx: &AssistContext<'_>,
module: hir::Module, module: hir::Module,
fun: &Function, fun: &Function,
old_indent: IndentLevel, old_indent: IndentLevel,
@ -1490,7 +1494,7 @@ fn format_function(
} }
fn make_generic_params_and_where_clause( fn make_generic_params_and_where_clause(
ctx: &AssistContext, ctx: &AssistContext<'_>,
fun: &Function, fun: &Function,
) -> (Option<ast::GenericParamList>, Option<ast::WhereClause>) { ) -> (Option<ast::GenericParamList>, Option<ast::WhereClause>) {
let used_type_params = fun.type_params(ctx); let used_type_params = fun.type_params(ctx);
@ -1502,7 +1506,7 @@ fn make_generic_params_and_where_clause(
} }
fn make_generic_param_list( fn make_generic_param_list(
ctx: &AssistContext, ctx: &AssistContext<'_>,
fun: &Function, fun: &Function,
used_type_params: &[TypeParam], used_type_params: &[TypeParam],
) -> Option<ast::GenericParamList> { ) -> Option<ast::GenericParamList> {
@ -1525,7 +1529,7 @@ fn make_generic_param_list(
} }
fn param_is_required( fn param_is_required(
ctx: &AssistContext, ctx: &AssistContext<'_>,
param: &ast::GenericParam, param: &ast::GenericParam,
used_type_params: &[TypeParam], used_type_params: &[TypeParam],
) -> bool { ) -> bool {
@ -1539,7 +1543,7 @@ fn param_is_required(
} }
fn make_where_clause( fn make_where_clause(
ctx: &AssistContext, ctx: &AssistContext<'_>,
fun: &Function, fun: &Function,
used_type_params: &[TypeParam], used_type_params: &[TypeParam],
) -> Option<ast::WhereClause> { ) -> Option<ast::WhereClause> {
@ -1562,7 +1566,7 @@ fn make_where_clause(
} }
fn pred_is_required( fn pred_is_required(
ctx: &AssistContext, ctx: &AssistContext<'_>,
pred: &ast::WherePred, pred: &ast::WherePred,
used_type_params: &[TypeParam], used_type_params: &[TypeParam],
) -> bool { ) -> bool {
@ -1572,7 +1576,7 @@ fn pred_is_required(
} }
} }
fn resolved_type_param(ctx: &AssistContext, pred: &ast::WherePred) -> Option<TypeParam> { fn resolved_type_param(ctx: &AssistContext<'_>, pred: &ast::WherePred) -> Option<TypeParam> {
let path = match pred.ty()? { let path = match pred.ty()? {
ast::Type::PathType(path_type) => path_type.path(), ast::Type::PathType(path_type) => path_type.path(),
_ => None, _ => None,
@ -1586,7 +1590,7 @@ fn resolved_type_param(ctx: &AssistContext, pred: &ast::WherePred) -> Option<Typ
impl Function { impl Function {
/// Collect all the `TypeParam`s used in the `body` and `params`. /// Collect all the `TypeParam`s used in the `body` and `params`.
fn type_params(&self, ctx: &AssistContext) -> Vec<TypeParam> { fn type_params(&self, ctx: &AssistContext<'_>) -> Vec<TypeParam> {
let type_params_in_descendant_paths = let type_params_in_descendant_paths =
self.body.descendant_paths().filter_map(|it| match ctx.sema.resolve_path(&it) { self.body.descendant_paths().filter_map(|it| match ctx.sema.resolve_path(&it) {
Some(PathResolution::TypeParam(type_param)) => Some(type_param), Some(PathResolution::TypeParam(type_param)) => Some(type_param),
@ -1596,13 +1600,13 @@ impl Function {
type_params_in_descendant_paths.chain(type_params_in_params).collect() type_params_in_descendant_paths.chain(type_params_in_params).collect()
} }
fn make_param_list(&self, ctx: &AssistContext, module: hir::Module) -> ast::ParamList { fn make_param_list(&self, ctx: &AssistContext<'_>, module: hir::Module) -> ast::ParamList {
let self_param = self.self_param.clone(); let self_param = self.self_param.clone();
let params = self.params.iter().map(|param| param.to_param(ctx, module)); let params = self.params.iter().map(|param| param.to_param(ctx, module));
make::param_list(self_param, params) make::param_list(self_param, params)
} }
fn make_ret_ty(&self, ctx: &AssistContext, module: hir::Module) -> Option<ast::RetType> { fn make_ret_ty(&self, ctx: &AssistContext<'_>, module: hir::Module) -> Option<ast::RetType> {
let fun_ty = self.return_type(ctx); let fun_ty = self.return_type(ctx);
let handler = if self.mods.is_in_tail { let handler = if self.mods.is_in_tail {
FlowHandler::None FlowHandler::None
@ -1649,7 +1653,7 @@ impl Function {
} }
impl FunType { impl FunType {
fn make_ty(&self, ctx: &AssistContext, module: hir::Module) -> ast::Type { fn make_ty(&self, ctx: &AssistContext<'_>, module: hir::Module) -> ast::Type {
match self { match self {
FunType::Unit => make::ty_unit(), FunType::Unit => make::ty_unit(),
FunType::Single(ty) => make_ty(ty, ctx, module), FunType::Single(ty) => make_ty(ty, ctx, module),
@ -1672,7 +1676,7 @@ impl FunType {
} }
fn make_body( fn make_body(
ctx: &AssistContext, ctx: &AssistContext<'_>,
old_indent: IndentLevel, old_indent: IndentLevel,
new_indent: IndentLevel, new_indent: IndentLevel,
fun: &Function, fun: &Function,
@ -1821,17 +1825,17 @@ fn with_tail_expr(block: ast::BlockExpr, tail_expr: ast::Expr) -> ast::BlockExpr
make::block_expr(stmts, Some(tail_expr)) make::block_expr(stmts, Some(tail_expr))
} }
fn format_type(ty: &hir::Type, ctx: &AssistContext, module: hir::Module) -> String { fn format_type(ty: &hir::Type, ctx: &AssistContext<'_>, module: hir::Module) -> String {
ty.display_source_code(ctx.db(), module.into()).ok().unwrap_or_else(|| "_".to_string()) ty.display_source_code(ctx.db(), module.into()).ok().unwrap_or_else(|| "_".to_string())
} }
fn make_ty(ty: &hir::Type, ctx: &AssistContext, module: hir::Module) -> ast::Type { fn make_ty(ty: &hir::Type, ctx: &AssistContext<'_>, module: hir::Module) -> ast::Type {
let ty_str = format_type(ty, ctx, module); let ty_str = format_type(ty, ctx, module);
make::ty(&ty_str) make::ty(&ty_str)
} }
fn rewrite_body_segment( fn rewrite_body_segment(
ctx: &AssistContext, ctx: &AssistContext<'_>,
params: &[Param], params: &[Param],
handler: &FlowHandler, handler: &FlowHandler,
syntax: &SyntaxNode, syntax: &SyntaxNode,
@ -1842,7 +1846,7 @@ fn rewrite_body_segment(
} }
/// change all usages to account for added `&`/`&mut` for some params /// change all usages to account for added `&`/`&mut` for some params
fn fix_param_usages(ctx: &AssistContext, params: &[Param], syntax: &SyntaxNode) -> SyntaxNode { fn fix_param_usages(ctx: &AssistContext<'_>, params: &[Param], syntax: &SyntaxNode) -> SyntaxNode {
let mut usages_for_param: Vec<(&Param, Vec<ast::Expr>)> = Vec::new(); let mut usages_for_param: Vec<(&Param, Vec<ast::Expr>)> = Vec::new();
let tm = TreeMutator::new(syntax); let tm = TreeMutator::new(syntax);

View file

@ -53,7 +53,7 @@ use super::remove_unused_param::range_to_remove;
// name + 2 // name + 2
// } // }
// ``` // ```
pub(crate) fn extract_module(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn extract_module(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
if ctx.has_empty_selection() { if ctx.has_empty_selection() {
return None; return None;
} }
@ -234,7 +234,7 @@ fn extract_target(node: &SyntaxNode, selection_range: TextRange) -> Option<Modul
impl Module { impl Module {
fn get_usages_and_record_fields( fn get_usages_and_record_fields(
&self, &self,
ctx: &AssistContext, ctx: &AssistContext<'_>,
) -> (HashMap<FileId, Vec<(TextRange, String)>>, Vec<SyntaxNode>) { ) -> (HashMap<FileId, Vec<(TextRange, String)>>, Vec<SyntaxNode>) {
let mut adt_fields = Vec::new(); let mut adt_fields = Vec::new();
let mut refs: HashMap<FileId, Vec<(TextRange, String)>> = HashMap::new(); let mut refs: HashMap<FileId, Vec<(TextRange, String)>> = HashMap::new();
@ -318,7 +318,7 @@ impl Module {
fn expand_and_group_usages_file_wise( fn expand_and_group_usages_file_wise(
&self, &self,
ctx: &AssistContext, ctx: &AssistContext<'_>,
node_def: Definition, node_def: Definition,
refs_in_files: &mut HashMap<FileId, Vec<(TextRange, String)>>, refs_in_files: &mut HashMap<FileId, Vec<(TextRange, String)>>,
) { ) {
@ -396,7 +396,7 @@ impl Module {
fn resolve_imports( fn resolve_imports(
&mut self, &mut self,
curr_parent_module: Option<ast::Module>, curr_parent_module: Option<ast::Module>,
ctx: &AssistContext, ctx: &AssistContext<'_>,
) -> Vec<TextRange> { ) -> Vec<TextRange> {
let mut import_paths_to_be_removed: Vec<TextRange> = vec![]; let mut import_paths_to_be_removed: Vec<TextRange> = vec![];
let mut node_set: HashSet<String> = HashSet::new(); let mut node_set: HashSet<String> = HashSet::new();
@ -471,7 +471,7 @@ impl Module {
def: Definition, def: Definition,
node_syntax: &SyntaxNode, node_syntax: &SyntaxNode,
curr_parent_module: &Option<ast::Module>, curr_parent_module: &Option<ast::Module>,
ctx: &AssistContext, ctx: &AssistContext<'_>,
) -> Option<TextRange> { ) -> Option<TextRange> {
//We only need to find in the current file //We only need to find in the current file
let selection_range = ctx.selection_trimmed(); let selection_range = ctx.selection_trimmed();
@ -684,7 +684,7 @@ fn check_intersection_and_push(
fn does_source_exists_outside_sel_in_same_mod( fn does_source_exists_outside_sel_in_same_mod(
def: Definition, def: Definition,
ctx: &AssistContext, ctx: &AssistContext<'_>,
curr_parent_module: &Option<ast::Module>, curr_parent_module: &Option<ast::Module>,
selection_range: TextRange, selection_range: TextRange,
curr_file_id: FileId, curr_file_id: FileId,
@ -904,7 +904,7 @@ fn add_change_vis(vis: Option<ast::Visibility>, node_or_token_opt: Option<syntax
fn compare_hir_and_ast_module( fn compare_hir_and_ast_module(
ast_module: &ast::Module, ast_module: &ast::Module,
hir_module: hir::Module, hir_module: hir::Module,
ctx: &AssistContext, ctx: &AssistContext<'_>,
) -> Option<()> { ) -> Option<()> {
let hir_mod_name = hir_module.name(ctx.db())?; let hir_mod_name = hir_module.name(ctx.db())?;
let ast_mod_name = ast_module.name()?; let ast_mod_name = ast_module.name()?;

View file

@ -37,7 +37,7 @@ use crate::{assist_context::AssistBuilder, AssistContext, AssistId, AssistKind,
// ``` // ```
pub(crate) fn extract_struct_from_enum_variant( pub(crate) fn extract_struct_from_enum_variant(
acc: &mut Assists, acc: &mut Assists,
ctx: &AssistContext, ctx: &AssistContext<'_>,
) -> Option<()> { ) -> Option<()> {
let variant = ctx.find_node_at_offset::<ast::Variant>()?; let variant = ctx.find_node_at_offset::<ast::Variant>()?;
let field_list = extract_field_list_if_applicable(&variant)?; let field_list = extract_field_list_if_applicable(&variant)?;
@ -373,7 +373,7 @@ fn apply_references(
} }
fn process_references( fn process_references(
ctx: &AssistContext, ctx: &AssistContext<'_>,
builder: &mut AssistBuilder, builder: &mut AssistBuilder,
visited_modules: &mut FxHashSet<Module>, visited_modules: &mut FxHashSet<Module>,
enum_module_def: &ModuleDef, enum_module_def: &ModuleDef,
@ -407,7 +407,7 @@ fn process_references(
} }
fn reference_to_node( fn reference_to_node(
sema: &hir::Semantics<RootDatabase>, sema: &hir::Semantics<'_, RootDatabase>,
reference: FileReference, reference: FileReference,
) -> Option<(ast::PathSegment, SyntaxNode, hir::Module)> { ) -> Option<(ast::PathSegment, SyntaxNode, hir::Module)> {
let segment = let segment =

View file

@ -25,7 +25,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// field: Type, // field: Type,
// } // }
// ``` // ```
pub(crate) fn extract_type_alias(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn extract_type_alias(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
if ctx.has_empty_selection() { if ctx.has_empty_selection() {
return None; return None;
} }

View file

@ -27,7 +27,7 @@ use crate::{utils::suggest_name, AssistContext, AssistId, AssistKind, Assists};
// var_name * 4; // var_name * 4;
// } // }
// ``` // ```
pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
if ctx.has_empty_selection() { if ctx.has_empty_selection() {
return None; return None;
} }
@ -164,7 +164,7 @@ fn valid_target_expr(node: SyntaxNode) -> Option<ast::Expr> {
} }
} }
fn get_receiver_type(ctx: &AssistContext, expression: &ast::Expr) -> Option<hir::Type> { fn get_receiver_type(ctx: &AssistContext<'_>, expression: &ast::Expr) -> Option<hir::Type> {
let receiver = get_receiver(expression.clone())?; let receiver = get_receiver(expression.clone())?;
Some(ctx.sema.type_of_expr(&receiver)?.original()) Some(ctx.sema.type_of_expr(&receiver)?.original())
} }

View file

@ -30,12 +30,12 @@ use crate::{utils::vis_offset, AssistContext, AssistId, AssistKind, Assists};
// m::frobnicate() {} // m::frobnicate() {}
// } // }
// ``` // ```
pub(crate) fn fix_visibility(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn fix_visibility(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
add_vis_to_referenced_module_def(acc, ctx) add_vis_to_referenced_module_def(acc, ctx)
.or_else(|| add_vis_to_referenced_record_field(acc, ctx)) .or_else(|| add_vis_to_referenced_record_field(acc, ctx))
} }
fn add_vis_to_referenced_module_def(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { fn add_vis_to_referenced_module_def(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let path: ast::Path = ctx.find_node_at_offset()?; let path: ast::Path = ctx.find_node_at_offset()?;
let path_res = ctx.sema.resolve_path(&path)?; let path_res = ctx.sema.resolve_path(&path)?;
let def = match path_res { let def = match path_res {
@ -82,7 +82,7 @@ fn add_vis_to_referenced_module_def(acc: &mut Assists, ctx: &AssistContext) -> O
}) })
} }
fn add_vis_to_referenced_record_field(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { fn add_vis_to_referenced_record_field(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let record_field: ast::RecordExprField = ctx.find_node_at_offset()?; let record_field: ast::RecordExprField = ctx.find_node_at_offset()?;
let (record_field_def, _, _) = ctx.sema.resolve_record_field(&record_field)?; let (record_field_def, _, _) = ctx.sema.resolve_record_field(&record_field)?;

View file

@ -17,7 +17,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// let _ = 2 + 90; // let _ = 2 + 90;
// } // }
// ``` // ```
pub(crate) fn flip_binexpr(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn flip_binexpr(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let expr = ctx.find_node_at_offset::<BinExpr>()?; let expr = ctx.find_node_at_offset::<BinExpr>()?;
let lhs = expr.lhs()?.syntax().clone(); let lhs = expr.lhs()?.syntax().clone();
let rhs = expr.rhs()?.syntax().clone(); let rhs = expr.rhs()?.syntax().clone();

View file

@ -17,7 +17,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// ((3, 4), (1, 2)); // ((3, 4), (1, 2));
// } // }
// ``` // ```
pub(crate) fn flip_comma(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn flip_comma(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let comma = ctx.find_token_syntax_at_offset(T![,])?; let comma = ctx.find_token_syntax_at_offset(T![,])?;
let prev = non_trivia_sibling(comma.clone().into(), Direction::Prev)?; let prev = non_trivia_sibling(comma.clone().into(), Direction::Prev)?;
let next = non_trivia_sibling(comma.clone().into(), Direction::Next)?; let next = non_trivia_sibling(comma.clone().into(), Direction::Next)?;

View file

@ -17,7 +17,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// ``` // ```
// fn foo<T: Copy + Clone>() { } // fn foo<T: Copy + Clone>() { }
// ``` // ```
pub(crate) fn flip_trait_bound(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn flip_trait_bound(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
// We want to replicate the behavior of `flip_binexpr` by only suggesting // We want to replicate the behavior of `flip_binexpr` by only suggesting
// the assist when the cursor is on a `+` // the assist when the cursor is on a `+`
let plus = ctx.find_token_syntax_at_offset(T![+])?; let plus = ctx.find_token_syntax_at_offset(T![+])?;

View file

@ -31,7 +31,7 @@ use syntax::{
// } // }
// ``` // ```
pub(crate) fn generate_constant(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn generate_constant(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let constant_token = ctx.find_node_at_offset::<ast::NameRef>()?; let constant_token = ctx.find_node_at_offset::<ast::NameRef>()?;
if constant_token.to_string().chars().any(|it| !(it.is_uppercase() || it == '_')) { if constant_token.to_string().chars().any(|it| !(it.is_uppercase() || it == '_')) {
cov_mark::hit!(not_constant_name); cov_mark::hit!(not_constant_name);
@ -113,7 +113,7 @@ fn get_text_for_generate_constant(
} }
fn target_data_for_generate_constant( fn target_data_for_generate_constant(
ctx: &AssistContext, ctx: &AssistContext<'_>,
current_module: Module, current_module: Module,
constant_module: Module, constant_module: Module,
) -> Option<(TextSize, IndentLevel, Option<FileId>, String)> { ) -> Option<(TextSize, IndentLevel, Option<FileId>, String)> {

View file

@ -30,7 +30,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// ``` // ```
pub(crate) fn generate_default_from_enum_variant( pub(crate) fn generate_default_from_enum_variant(
acc: &mut Assists, acc: &mut Assists,
ctx: &AssistContext, ctx: &AssistContext<'_>,
) -> Option<()> { ) -> Option<()> {
let variant = ctx.find_node_at_offset::<ast::Variant>()?; let variant = ctx.find_node_at_offset::<ast::Variant>()?;
let variant_name = variant.name()?; let variant_name = variant.name()?;

View file

@ -40,7 +40,7 @@ use crate::{
// } // }
// } // }
// ``` // ```
pub(crate) fn generate_default_from_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn generate_default_from_new(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let fn_node = ctx.find_node_at_offset::<ast::Fn>()?; let fn_node = ctx.find_node_at_offset::<ast::Fn>()?;
let fn_name = fn_node.name()?; let fn_name = fn_node.name()?;
@ -122,7 +122,7 @@ fn generate_trait_impl_text_from_impl(impl_: &ast::Impl, trait_text: &str, code:
buf buf
} }
fn is_default_implemented(ctx: &AssistContext, impl_: &Impl) -> bool { fn is_default_implemented(ctx: &AssistContext<'_>, impl_: &Impl) -> bool {
let db = ctx.sema.db; let db = ctx.sema.db;
let impl_ = ctx.sema.to_def(impl_); let impl_ = ctx.sema.to_def(impl_);
let impl_def = match impl_ { let impl_def = match impl_ {

View file

@ -42,7 +42,7 @@ use syntax::ast::edit::AstNodeEdit;
// } // }
// } // }
// ``` // ```
pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let strukt = ctx.find_node_at_offset::<ast::Struct>()?; let strukt = ctx.find_node_at_offset::<ast::Struct>()?;
let strukt_name = strukt.name()?; let strukt_name = strukt.name()?;
let current_module = ctx.sema.scope(strukt.syntax())?.module(); let current_module = ctx.sema.scope(strukt.syntax())?.module();

View file

@ -39,11 +39,11 @@ use crate::{
// } // }
// } // }
// ``` // ```
pub(crate) fn generate_deref(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn generate_deref(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
generate_record_deref(acc, ctx).or_else(|| generate_tuple_deref(acc, ctx)) generate_record_deref(acc, ctx).or_else(|| generate_tuple_deref(acc, ctx))
} }
fn generate_record_deref(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { fn generate_record_deref(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let strukt = ctx.find_node_at_offset::<ast::Struct>()?; let strukt = ctx.find_node_at_offset::<ast::Struct>()?;
let field = ctx.find_node_at_offset::<ast::RecordField>()?; let field = ctx.find_node_at_offset::<ast::RecordField>()?;
@ -80,7 +80,7 @@ fn generate_record_deref(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
) )
} }
fn generate_tuple_deref(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { fn generate_tuple_deref(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let strukt = ctx.find_node_at_offset::<ast::Struct>()?; let strukt = ctx.find_node_at_offset::<ast::Struct>()?;
let field = ctx.find_node_at_offset::<ast::TupleField>()?; let field = ctx.find_node_at_offset::<ast::TupleField>()?;
let field_list = ctx.find_node_at_offset::<ast::TupleFieldList>()?; let field_list = ctx.find_node_at_offset::<ast::TupleFieldList>()?;

View file

@ -24,7 +24,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// y: u32, // y: u32,
// } // }
// ``` // ```
pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let cap = ctx.config.snippet_cap?; let cap = ctx.config.snippet_cap?;
let nominal = ctx.find_node_at_offset::<ast::Adt>()?; let nominal = ctx.find_node_at_offset::<ast::Adt>()?;
let node_start = derive_insertion_offset(&nominal)?; let node_start = derive_insertion_offset(&nominal)?;

View file

@ -42,7 +42,7 @@ use crate::assist_context::{AssistContext, Assists};
// ``` // ```
pub(crate) fn generate_documentation_template( pub(crate) fn generate_documentation_template(
acc: &mut Assists, acc: &mut Assists,
ctx: &AssistContext, ctx: &AssistContext<'_>,
) -> Option<()> { ) -> Option<()> {
let name = ctx.find_node_at_offset::<ast::Name>()?; let name = ctx.find_node_at_offset::<ast::Name>()?;
let ast_func = name.syntax().parent().and_then(ast::Fn::cast)?; let ast_func = name.syntax().parent().and_then(ast::Fn::cast)?;
@ -94,7 +94,7 @@ pub(crate) fn generate_documentation_template(
// /// ``` // /// ```
// pub fn add(a: i32, b: i32) -> i32 { a + b } // pub fn add(a: i32, b: i32) -> i32 { a + b }
// ``` // ```
pub(crate) fn generate_doc_example(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn generate_doc_example(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let tok: ast::Comment = ctx.find_token_at_offset()?; let tok: ast::Comment = ctx.find_token_at_offset()?;
let node = tok.syntax().parent()?; let node = tok.syntax().parent()?;
let last_doc_token = let last_doc_token =
@ -126,7 +126,7 @@ pub(crate) fn generate_doc_example(acc: &mut Assists, ctx: &AssistContext) -> Op
) )
} }
fn make_example_for_fn(ast_func: &ast::Fn, ctx: &AssistContext) -> Option<String> { fn make_example_for_fn(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option<String> {
if !is_public(ast_func, ctx)? { if !is_public(ast_func, ctx)? {
// Doctests for private items can't actually name the item, so they're pretty useless. // Doctests for private items can't actually name the item, so they're pretty useless.
return None; return None;
@ -176,7 +176,7 @@ fn make_example_for_fn(ast_func: &ast::Fn, ctx: &AssistContext) -> Option<String
Some(example) Some(example)
} }
fn introduction_builder(ast_func: &ast::Fn, ctx: &AssistContext) -> Option<String> { fn introduction_builder(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option<String> {
let hir_func = ctx.sema.to_def(ast_func)?; let hir_func = ctx.sema.to_def(ast_func)?;
let container = hir_func.as_assoc_item(ctx.db())?.container(ctx.db()); let container = hir_func.as_assoc_item(ctx.db())?.container(ctx.db());
if let hir::AssocItemContainer::Impl(imp) = container { if let hir::AssocItemContainer::Impl(imp) = container {
@ -270,7 +270,7 @@ fn safety_builder(ast_func: &ast::Fn) -> Option<Vec<String>> {
} }
/// Checks if the function is public / exported /// Checks if the function is public / exported
fn is_public(ast_func: &ast::Fn, ctx: &AssistContext) -> Option<bool> { fn is_public(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option<bool> {
let hir_func = ctx.sema.to_def(ast_func)?; let hir_func = ctx.sema.to_def(ast_func)?;
Some( Some(
hir_func.visibility(ctx.db()) == Visibility::Public hir_func.visibility(ctx.db()) == Visibility::Public
@ -279,7 +279,7 @@ fn is_public(ast_func: &ast::Fn, ctx: &AssistContext) -> Option<bool> {
} }
/// Checks that all parent modules of the function are public / exported /// Checks that all parent modules of the function are public / exported
fn all_parent_mods_public(hir_func: &hir::Function, ctx: &AssistContext) -> bool { fn all_parent_mods_public(hir_func: &hir::Function, ctx: &AssistContext<'_>) -> bool {
let mut module = hir_func.module(ctx.db()); let mut module = hir_func.module(ctx.db());
loop { loop {
if let Some(parent) = module.parent(ctx.db()) { if let Some(parent) = module.parent(ctx.db()) {
@ -294,7 +294,7 @@ fn all_parent_mods_public(hir_func: &hir::Function, ctx: &AssistContext) -> bool
} }
/// Returns the name of the current crate /// Returns the name of the current crate
fn crate_name(ast_func: &ast::Fn, ctx: &AssistContext) -> Option<String> { fn crate_name(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option<String> {
let krate = ctx.sema.scope(ast_func.syntax())?.krate(); let krate = ctx.sema.scope(ast_func.syntax())?.krate();
Some(krate.display_name(ctx.db())?.to_string()) Some(krate.display_name(ctx.db())?.to_string())
} }
@ -351,7 +351,7 @@ fn self_partial_type(ast_func: &ast::Fn) -> Option<String> {
} }
/// Helper function to determine if the function is in a trait implementation /// Helper function to determine if the function is in a trait implementation
fn is_in_trait_impl(ast_func: &ast::Fn, ctx: &AssistContext) -> bool { fn is_in_trait_impl(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> bool {
ctx.sema ctx.sema
.to_def(ast_func) .to_def(ast_func)
.and_then(|hir_func| hir_func.as_assoc_item(ctx.db())) .and_then(|hir_func| hir_func.as_assoc_item(ctx.db()))
@ -360,7 +360,7 @@ fn is_in_trait_impl(ast_func: &ast::Fn, ctx: &AssistContext) -> bool {
} }
/// Helper function to determine if the function definition is in a trait definition /// Helper function to determine if the function definition is in a trait definition
fn is_in_trait_def(ast_func: &ast::Fn, ctx: &AssistContext) -> bool { fn is_in_trait_def(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> bool {
ctx.sema ctx.sema
.to_def(ast_func) .to_def(ast_func)
.and_then(|hir_func| hir_func.as_assoc_item(ctx.db())) .and_then(|hir_func| hir_func.as_assoc_item(ctx.db()))
@ -462,7 +462,7 @@ fn string_vec_from(string_array: &[&str]) -> Vec<String> {
} }
/// Helper function to build the path of the module in the which is the node /// Helper function to build the path of the module in the which is the node
fn build_path(ast_func: &ast::Fn, ctx: &AssistContext) -> Option<String> { fn build_path(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option<String> {
let crate_name = crate_name(ast_func, ctx)?; let crate_name = crate_name(ast_func, ctx)?;
let leaf = self_partial_type(ast_func) let leaf = self_partial_type(ast_func)
.or_else(|| ast_func.name().map(|n| n.to_string())) .or_else(|| ast_func.name().map(|n| n.to_string()))
@ -480,7 +480,7 @@ fn return_type(ast_func: &ast::Fn) -> Option<ast::Type> {
} }
/// Helper function to determine if the function returns some data /// Helper function to determine if the function returns some data
fn returns_a_value(ast_func: &ast::Fn, ctx: &AssistContext) -> bool { fn returns_a_value(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> bool {
ctx.sema ctx.sema
.to_def(ast_func) .to_def(ast_func)
.map(|hir_func| hir_func.ret_type(ctx.db())) .map(|hir_func| hir_func.ret_type(ctx.db()))

View file

@ -37,7 +37,7 @@ use crate::{
// } // }
// } // }
// ``` // ```
pub(crate) fn generate_enum_is_method(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn generate_enum_is_method(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let variant = ctx.find_node_at_offset::<ast::Variant>()?; let variant = ctx.find_node_at_offset::<ast::Variant>()?;
let variant_name = variant.name()?; let variant_name = variant.name()?;
let parent_enum = ast::Adt::Enum(variant.parent_enum()); let parent_enum = ast::Adt::Enum(variant.parent_enum());

View file

@ -36,7 +36,10 @@ use crate::{
// } // }
// } // }
// ``` // ```
pub(crate) fn generate_enum_try_into_method(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn generate_enum_try_into_method(
acc: &mut Assists,
ctx: &AssistContext<'_>,
) -> Option<()> {
generate_enum_projection_method( generate_enum_projection_method(
acc, acc,
ctx, ctx,
@ -80,7 +83,7 @@ pub(crate) fn generate_enum_try_into_method(acc: &mut Assists, ctx: &AssistConte
// } // }
// } // }
// ``` // ```
pub(crate) fn generate_enum_as_method(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn generate_enum_as_method(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
generate_enum_projection_method( generate_enum_projection_method(
acc, acc,
ctx, ctx,
@ -108,7 +111,7 @@ struct ProjectionProps {
fn generate_enum_projection_method( fn generate_enum_projection_method(
acc: &mut Assists, acc: &mut Assists,
ctx: &AssistContext, ctx: &AssistContext<'_>,
assist_id: &'static str, assist_id: &'static str,
assist_description: &str, assist_description: &str,
props: ProjectionProps, props: ProjectionProps,

View file

@ -31,7 +31,7 @@ use crate::assist_context::{AssistContext, Assists};
// let country = Countries::Lesotho; // let country = Countries::Lesotho;
// } // }
// ``` // ```
pub(crate) fn generate_enum_variant(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn generate_enum_variant(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let path_expr: ast::PathExpr = ctx.find_node_at_offset()?; let path_expr: ast::PathExpr = ctx.find_node_at_offset()?;
let path = path_expr.path()?; let path = path_expr.path()?;
@ -58,7 +58,7 @@ pub(crate) fn generate_enum_variant(acc: &mut Assists, ctx: &AssistContext) -> O
fn add_variant_to_accumulator( fn add_variant_to_accumulator(
acc: &mut Assists, acc: &mut Assists,
ctx: &AssistContext, ctx: &AssistContext<'_>,
target: syntax::TextRange, target: syntax::TextRange,
adt: hir::Enum, adt: hir::Enum,
name_ref: &ast::NameRef, name_ref: &ast::NameRef,

View file

@ -20,7 +20,10 @@ use crate::{utils::generate_trait_impl_text, AssistContext, AssistId, AssistKind
// } // }
// } // }
// ``` // ```
pub(crate) fn generate_from_impl_for_enum(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn generate_from_impl_for_enum(
acc: &mut Assists,
ctx: &AssistContext<'_>,
) -> Option<()> {
let variant = ctx.find_node_at_offset::<ast::Variant>()?; let variant = ctx.find_node_at_offset::<ast::Variant>()?;
let variant_name = variant.name()?; let variant_name = variant.name()?;
let enum_ = ast::Adt::Enum(variant.parent_enum()); let enum_ = ast::Adt::Enum(variant.parent_enum());

View file

@ -46,11 +46,11 @@ use crate::{
// } // }
// //
// ``` // ```
pub(crate) fn generate_function(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn generate_function(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
gen_fn(acc, ctx).or_else(|| gen_method(acc, ctx)) gen_fn(acc, ctx).or_else(|| gen_method(acc, ctx))
} }
fn gen_fn(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { fn gen_fn(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let path_expr: ast::PathExpr = ctx.find_node_at_offset()?; let path_expr: ast::PathExpr = ctx.find_node_at_offset()?;
let call = path_expr.syntax().parent().and_then(ast::CallExpr::cast)?; let call = path_expr.syntax().parent().and_then(ast::CallExpr::cast)?;
let path = path_expr.path()?; let path = path_expr.path()?;
@ -113,7 +113,7 @@ fn gen_fn(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
) )
} }
fn gen_method(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { fn gen_method(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let call: ast::MethodCallExpr = ctx.find_node_at_offset()?; let call: ast::MethodCallExpr = ctx.find_node_at_offset()?;
if ctx.sema.resolve_method_call(&call).is_some() { if ctx.sema.resolve_method_call(&call).is_some() {
return None; return None;
@ -149,7 +149,7 @@ fn gen_method(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
fn add_func_to_accumulator( fn add_func_to_accumulator(
acc: &mut Assists, acc: &mut Assists,
ctx: &AssistContext, ctx: &AssistContext<'_>,
text_range: TextRange, text_range: TextRange,
function_builder: FunctionBuilder, function_builder: FunctionBuilder,
insert_offset: TextSize, insert_offset: TextSize,
@ -172,7 +172,7 @@ fn add_func_to_accumulator(
} }
fn get_adt_source( fn get_adt_source(
ctx: &AssistContext, ctx: &AssistContext<'_>,
adt: &hir::Adt, adt: &hir::Adt,
fn_name: &str, fn_name: &str,
) -> Option<(Option<ast::Impl>, FileId)> { ) -> Option<(Option<ast::Impl>, FileId)> {
@ -229,7 +229,7 @@ impl FunctionBuilder {
/// Prepares a generated function that matches `call`. /// Prepares a generated function that matches `call`.
/// The function is generated in `target_module` or next to `call` /// The function is generated in `target_module` or next to `call`
fn from_call( fn from_call(
ctx: &AssistContext, ctx: &AssistContext<'_>,
call: &ast::CallExpr, call: &ast::CallExpr,
fn_name: &str, fn_name: &str,
target_module: Option<hir::Module>, target_module: Option<hir::Module>,
@ -261,7 +261,7 @@ impl FunctionBuilder {
} }
fn from_method_call( fn from_method_call(
ctx: &AssistContext, ctx: &AssistContext<'_>,
call: &ast::MethodCallExpr, call: &ast::MethodCallExpr,
name: &ast::NameRef, name: &ast::NameRef,
target_module: Module, target_module: Module,
@ -344,7 +344,7 @@ impl FunctionBuilder {
/// * If we could infer the return type, don't focus it (and thus focus the function body) so the /// * If we could infer the return type, don't focus it (and thus focus the function body) so the
/// user can change the `todo!` function body. /// user can change the `todo!` function body.
fn make_return_type( fn make_return_type(
ctx: &AssistContext, ctx: &AssistContext<'_>,
call: &ast::Expr, call: &ast::Expr,
target_module: Module, target_module: Module,
) -> (Option<ast::RetType>, bool) { ) -> (Option<ast::RetType>, bool) {
@ -367,7 +367,7 @@ fn make_return_type(
} }
fn get_fn_target( fn get_fn_target(
ctx: &AssistContext, ctx: &AssistContext<'_>,
target_module: &Option<Module>, target_module: &Option<Module>,
call: CallExpr, call: CallExpr,
) -> Option<(GeneratedFunctionTarget, FileId, TextSize)> { ) -> Option<(GeneratedFunctionTarget, FileId, TextSize)> {
@ -385,7 +385,7 @@ fn get_fn_target(
} }
fn get_method_target( fn get_method_target(
ctx: &AssistContext, ctx: &AssistContext<'_>,
target_module: &Module, target_module: &Module,
impl_: &Option<ast::Impl>, impl_: &Option<ast::Impl>,
) -> Option<(GeneratedFunctionTarget, TextSize)> { ) -> Option<(GeneratedFunctionTarget, TextSize)> {
@ -423,7 +423,7 @@ impl GeneratedFunctionTarget {
/// Computes the type variables and arguments required for the generated function /// Computes the type variables and arguments required for the generated function
fn fn_args( fn fn_args(
ctx: &AssistContext, ctx: &AssistContext<'_>,
target_module: hir::Module, target_module: hir::Module,
call: ast::CallableExpr, call: ast::CallableExpr,
) -> Option<(Option<ast::GenericParamList>, ast::ParamList)> { ) -> Option<(Option<ast::GenericParamList>, ast::ParamList)> {
@ -482,7 +482,7 @@ fn deduplicate_arg_names(arg_names: &mut Vec<String>) {
} }
} }
fn fn_arg_name(sema: &Semantics<RootDatabase>, arg_expr: &ast::Expr) -> String { fn fn_arg_name(sema: &Semantics<'_, RootDatabase>, arg_expr: &ast::Expr) -> String {
let name = (|| match arg_expr { let name = (|| match arg_expr {
ast::Expr::CastExpr(cast_expr) => Some(fn_arg_name(sema, &cast_expr.expr()?)), ast::Expr::CastExpr(cast_expr) => Some(fn_arg_name(sema, &cast_expr.expr()?)),
expr => { expr => {
@ -510,9 +510,9 @@ fn fn_arg_name(sema: &Semantics<RootDatabase>, arg_expr: &ast::Expr) -> String {
} }
} }
fn fn_arg_type(ctx: &AssistContext, target_module: hir::Module, fn_arg: &ast::Expr) -> String { fn fn_arg_type(ctx: &AssistContext<'_>, target_module: hir::Module, fn_arg: &ast::Expr) -> String {
fn maybe_displayed_type( fn maybe_displayed_type(
ctx: &AssistContext, ctx: &AssistContext<'_>,
target_module: hir::Module, target_module: hir::Module,
fn_arg: &ast::Expr, fn_arg: &ast::Expr,
) -> Option<String> { ) -> Option<String> {
@ -593,7 +593,7 @@ fn next_space_for_fn_in_impl(impl_: &ast::Impl) -> Option<GeneratedFunctionTarge
} }
} }
fn module_is_descendant(module: &hir::Module, ans: &hir::Module, ctx: &AssistContext) -> bool { fn module_is_descendant(module: &hir::Module, ans: &hir::Module, ctx: &AssistContext<'_>) -> bool {
if module == ans { if module == ans {
return true; return true;
} }

View file

@ -43,7 +43,7 @@ use crate::{
// } // }
// } // }
// ``` // ```
pub(crate) fn generate_getter(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn generate_getter(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
generate_getter_impl(acc, ctx, false) generate_getter_impl(acc, ctx, false)
} }
@ -68,13 +68,13 @@ pub(crate) fn generate_getter(acc: &mut Assists, ctx: &AssistContext) -> Option<
// } // }
// } // }
// ``` // ```
pub(crate) fn generate_getter_mut(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn generate_getter_mut(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
generate_getter_impl(acc, ctx, true) generate_getter_impl(acc, ctx, true)
} }
pub(crate) fn generate_getter_impl( pub(crate) fn generate_getter_impl(
acc: &mut Assists, acc: &mut Assists,
ctx: &AssistContext, ctx: &AssistContext<'_>,
mutable: bool, mutable: bool,
) -> Option<()> { ) -> Option<()> {
let strukt = ctx.find_node_at_offset::<ast::Struct>()?; let strukt = ctx.find_node_at_offset::<ast::Struct>()?;

View file

@ -21,7 +21,7 @@ use crate::{utils::generate_impl_text, AssistContext, AssistId, AssistKind, Assi
// $0 // $0
// } // }
// ``` // ```
pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let nominal = ctx.find_node_at_offset::<ast::Adt>()?; let nominal = ctx.find_node_at_offset::<ast::Adt>()?;
let name = nominal.name()?; let name = nominal.name()?;
let target = nominal.syntax().text_range(); let target = nominal.syntax().text_range();

View file

@ -39,7 +39,7 @@ use crate::{
// } // }
// } // }
// ``` // ```
pub(crate) fn generate_is_empty_from_len(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn generate_is_empty_from_len(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let fn_node = ctx.find_node_at_offset::<ast::Fn>()?; let fn_node = ctx.find_node_at_offset::<ast::Fn>()?;
let fn_name = fn_node.name()?; let fn_name = fn_node.name()?;
@ -86,7 +86,7 @@ pub(crate) fn generate_is_empty_from_len(acc: &mut Assists, ctx: &AssistContext)
} }
fn get_impl_method( fn get_impl_method(
ctx: &AssistContext, ctx: &AssistContext<'_>,
impl_: &ast::Impl, impl_: &ast::Impl,
fn_name: &Name, fn_name: &Name,
) -> Option<hir::Function> { ) -> Option<hir::Function> {

View file

@ -29,7 +29,7 @@ use crate::{
// fn $0new(data: T) -> Self { Self { data } } // fn $0new(data: T) -> Self { Self { data } }
// } // }
// ``` // ```
pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let strukt = ctx.find_node_at_offset::<ast::Struct>()?; let strukt = ctx.find_node_at_offset::<ast::Struct>()?;
// We want to only apply this to non-union structs with named fields // We want to only apply this to non-union structs with named fields

View file

@ -27,7 +27,7 @@ use crate::{
// } // }
// } // }
// ``` // ```
pub(crate) fn generate_setter(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn generate_setter(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let strukt = ctx.find_node_at_offset::<ast::Struct>()?; let strukt = ctx.find_node_at_offset::<ast::Struct>()?;
let field = ctx.find_node_at_offset::<ast::RecordField>()?; let field = ctx.find_node_at_offset::<ast::RecordField>()?;

View file

@ -59,7 +59,7 @@ use crate::{
// }; // };
// } // }
// ``` // ```
pub(crate) fn inline_into_callers(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn inline_into_callers(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let def_file = ctx.file_id(); let def_file = ctx.file_id();
let name = ctx.find_node_at_offset::<ast::Name>()?; let name = ctx.find_node_at_offset::<ast::Name>()?;
let ast_func = name.syntax().parent().and_then(ast::Fn::cast)?; let ast_func = name.syntax().parent().and_then(ast::Fn::cast)?;
@ -174,7 +174,7 @@ pub(crate) fn inline_into_callers(acc: &mut Assists, ctx: &AssistContext) -> Opt
// }; // };
// } // }
// ``` // ```
pub(crate) fn inline_call(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn inline_call(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let name_ref: ast::NameRef = ctx.find_node_at_offset()?; let name_ref: ast::NameRef = ctx.find_node_at_offset()?;
let call_info = CallInfo::from_name_ref(name_ref.clone())?; let call_info = CallInfo::from_name_ref(name_ref.clone())?;
let (function, label) = match &call_info.node { let (function, label) = match &call_info.node {
@ -294,7 +294,7 @@ fn get_fn_params(
} }
fn inline( fn inline(
sema: &Semantics<RootDatabase>, sema: &Semantics<'_, RootDatabase>,
function_def_file_id: FileId, function_def_file_id: FileId,
function: hir::Function, function: hir::Function,
fn_body: &ast::BlockExpr, fn_body: &ast::BlockExpr,

View file

@ -32,7 +32,7 @@ use crate::{
// (1 + 2) * 4; // (1 + 2) * 4;
// } // }
// ``` // ```
pub(crate) fn inline_local_variable(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn inline_local_variable(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let file_id = ctx.file_id(); let file_id = ctx.file_id();
let range = ctx.selection_trimmed(); let range = ctx.selection_trimmed();
let InlineData { let_stmt, delete_let, references, target } = let InlineData { let_stmt, delete_let, references, target } =
@ -149,7 +149,7 @@ struct InlineData {
} }
fn inline_let( fn inline_let(
sema: &Semantics<RootDatabase>, sema: &Semantics<'_, RootDatabase>,
let_stmt: ast::LetStmt, let_stmt: ast::LetStmt,
range: TextRange, range: TextRange,
file_id: FileId, file_id: FileId,
@ -184,7 +184,7 @@ fn inline_let(
} }
fn inline_usage( fn inline_usage(
sema: &Semantics<RootDatabase>, sema: &Semantics<'_, RootDatabase>,
path_expr: ast::PathExpr, path_expr: ast::PathExpr,
range: TextRange, range: TextRange,
file_id: FileId, file_id: FileId,

View file

@ -35,7 +35,7 @@ use crate::{
// let a: Vec<u32>; // let a: Vec<u32>;
// } // }
// ``` // ```
pub(crate) fn inline_type_alias(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn inline_type_alias(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
enum Replacement { enum Replacement {
Generic { lifetime_map: LifetimeMap, const_and_type_map: ConstAndTypeMap }, Generic { lifetime_map: LifetimeMap, const_and_type_map: ConstAndTypeMap },
Plain, Plain,
@ -252,7 +252,7 @@ fn create_replacement(
updated_concrete_type.to_string() updated_concrete_type.to_string()
} }
fn get_type_alias(ctx: &AssistContext, path: &ast::PathType) -> Option<ast::TypeAlias> { fn get_type_alias(ctx: &AssistContext<'_>, path: &ast::PathType) -> Option<ast::TypeAlias> {
let resolved_path = ctx.sema.resolve_path(&path.path()?)?; let resolved_path = ctx.sema.resolve_path(&path.path()?)?;
// We need the generics in the correct order to be able to map any provided // We need the generics in the correct order to be able to map any provided

View file

@ -16,7 +16,7 @@ use crate::{utils::suggest_name, AssistContext, AssistId, AssistKind, Assists};
// ``` // ```
// fn foo<B: Bar>(bar: B) {} // fn foo<B: Bar>(bar: B) {}
// ``` // ```
pub(crate) fn introduce_named_generic(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn introduce_named_generic(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let impl_trait_type = ctx.find_node_at_offset::<ast::ImplTraitType>()?; let impl_trait_type = ctx.find_node_at_offset::<ast::ImplTraitType>()?;
let param = impl_trait_type.syntax().parent().and_then(ast::Param::cast)?; let param = impl_trait_type.syntax().parent().and_then(ast::Param::cast)?;
let fn_ = param.syntax().ancestors().find_map(ast::Fn::cast)?; let fn_ = param.syntax().ancestors().find_map(ast::Fn::cast)?;

View file

@ -33,7 +33,7 @@ static ASSIST_LABEL: &str = "Introduce named lifetime";
// } // }
// } // }
// ``` // ```
pub(crate) fn introduce_named_lifetime(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn introduce_named_lifetime(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
// FIXME: How can we handle renaming any one of multiple anonymous lifetimes? // FIXME: How can we handle renaming any one of multiple anonymous lifetimes?
// FIXME: should also add support for the case fun(f: &Foo) -> &$0Foo // FIXME: should also add support for the case fun(f: &Foo) -> &$0Foo
let lifetime = let lifetime =

View file

@ -26,7 +26,7 @@ use crate::{
// if y { B } else { A } // if y { B } else { A }
// } // }
// ``` // ```
pub(crate) fn invert_if(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn invert_if(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let if_keyword = ctx.find_token_syntax_at_offset(T![if])?; let if_keyword = ctx.find_token_syntax_at_offset(T![if])?;
let expr = ast::IfExpr::cast(if_keyword.parent()?)?; let expr = ast::IfExpr::cast(if_keyword.parent()?)?;
let if_range = if_keyword.text_range(); let if_range = if_keyword.text_range();

View file

@ -22,7 +22,7 @@ use Edit::*;
// ``` // ```
// use std::{fmt::Formatter, io}; // use std::{fmt::Formatter, io};
// ``` // ```
pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let (target, edits) = if ctx.has_empty_selection() { let (target, edits) = if ctx.has_empty_selection() {
// Merge a neighbor // Merge a neighbor
let tree: ast::UseTree = ctx.find_node_at_offset()?; let tree: ast::UseTree = ctx.find_node_at_offset()?;

View file

@ -32,7 +32,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists, TextRange};
// } // }
// } // }
// ``` // ```
pub(crate) fn merge_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn merge_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let current_arm = ctx.find_node_at_offset::<ast::MatchArm>()?; let current_arm = ctx.find_node_at_offset::<ast::MatchArm>()?;
// Don't try to handle arms with guards for now - can add support for this later // Don't try to handle arms with guards for now - can add support for this later
if current_arm.guard().is_some() { if current_arm.guard().is_some() {
@ -97,7 +97,7 @@ fn contains_placeholder(a: &ast::MatchArm) -> bool {
fn are_same_types( fn are_same_types(
current_arm_types: &HashMap<String, Option<TypeInfo>>, current_arm_types: &HashMap<String, Option<TypeInfo>>,
arm: &ast::MatchArm, arm: &ast::MatchArm,
ctx: &AssistContext, ctx: &AssistContext<'_>,
) -> bool { ) -> bool {
let arm_types = get_arm_types(ctx, arm); let arm_types = get_arm_types(ctx, arm);
for (other_arm_type_name, other_arm_type) in arm_types { for (other_arm_type_name, other_arm_type) in arm_types {
@ -112,14 +112,14 @@ fn are_same_types(
} }
fn get_arm_types( fn get_arm_types(
context: &AssistContext, context: &AssistContext<'_>,
arm: &ast::MatchArm, arm: &ast::MatchArm,
) -> HashMap<String, Option<TypeInfo>> { ) -> HashMap<String, Option<TypeInfo>> {
let mut mapping: HashMap<String, Option<TypeInfo>> = HashMap::new(); let mut mapping: HashMap<String, Option<TypeInfo>> = HashMap::new();
fn recurse( fn recurse(
map: &mut HashMap<String, Option<TypeInfo>>, map: &mut HashMap<String, Option<TypeInfo>>,
ctx: &AssistContext, ctx: &AssistContext<'_>,
pat: &Option<ast::Pat>, pat: &Option<ast::Pat>,
) { ) {
if let Some(local_pat) = pat { if let Some(local_pat) = pat {

View file

@ -20,7 +20,10 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// f(x) // f(x)
// } // }
// ``` // ```
pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn move_bounds_to_where_clause(
acc: &mut Assists,
ctx: &AssistContext<'_>,
) -> Option<()> {
let type_param_list = ctx.find_node_at_offset::<ast::GenericParamList>()?; let type_param_list = ctx.find_node_at_offset::<ast::GenericParamList>()?;
let mut type_params = type_param_list.type_or_const_params(); let mut type_params = type_param_list.type_or_const_params();

View file

@ -23,7 +23,7 @@ use crate::{
// ``` // ```
// fn t() {} // fn t() {}
// ``` // ```
pub(crate) fn move_from_mod_rs(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn move_from_mod_rs(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let source_file = ctx.find_node_at_offset::<ast::SourceFile>()?; let source_file = ctx.find_node_at_offset::<ast::SourceFile>()?;
let module = ctx.sema.to_module_def(ctx.file_id())?; let module = ctx.sema.to_module_def(ctx.file_id())?;
// Enable this assist if the user select all "meaningful" content in the source file // Enable this assist if the user select all "meaningful" content in the source file

View file

@ -32,7 +32,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// } // }
// } // }
// ``` // ```
pub(crate) fn move_guard_to_arm_body(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn move_guard_to_arm_body(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let match_arm = ctx.find_node_at_offset::<MatchArm>()?; let match_arm = ctx.find_node_at_offset::<MatchArm>()?;
let guard = match_arm.guard()?; let guard = match_arm.guard()?;
if ctx.offset() > guard.syntax().text_range().end() { if ctx.offset() > guard.syntax().text_range().end() {
@ -91,7 +91,10 @@ pub(crate) fn move_guard_to_arm_body(acc: &mut Assists, ctx: &AssistContext) ->
// } // }
// } // }
// ``` // ```
pub(crate) fn move_arm_cond_to_match_guard(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn move_arm_cond_to_match_guard(
acc: &mut Assists,
ctx: &AssistContext<'_>,
) -> Option<()> {
let match_arm: MatchArm = ctx.find_node_at_offset::<MatchArm>()?; let match_arm: MatchArm = ctx.find_node_at_offset::<MatchArm>()?;
let match_pat = match_arm.pat()?; let match_pat = match_arm.pat()?;
let arm_body = match_arm.expr()?; let arm_body = match_arm.expr()?;

View file

@ -24,7 +24,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// ``` // ```
// mod foo; // mod foo;
// ``` // ```
pub(crate) fn move_module_to_file(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn move_module_to_file(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let module_ast = ctx.find_node_at_offset::<ast::Module>()?; let module_ast = ctx.find_node_at_offset::<ast::Module>()?;
let module_items = module_ast.item_list()?; let module_items = module_ast.item_list()?;

View file

@ -23,7 +23,7 @@ use crate::{
// ``` // ```
// fn t() {} // fn t() {}
// ``` // ```
pub(crate) fn move_to_mod_rs(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn move_to_mod_rs(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let source_file = ctx.find_node_at_offset::<ast::SourceFile>()?; let source_file = ctx.find_node_at_offset::<ast::SourceFile>()?;
let module = ctx.sema.to_module_def(ctx.file_id())?; let module = ctx.sema.to_module_def(ctx.file_id())?;
// Enable this assist if the user select all "meaningful" content in the source file // Enable this assist if the user select all "meaningful" content in the source file

View file

@ -15,7 +15,7 @@ const MIN_NUMBER_OF_DIGITS_TO_FORMAT: usize = 5;
// ``` // ```
// const _: i32 = 1_012_345; // const _: i32 = 1_012_345;
// ``` // ```
pub(crate) fn reformat_number_literal(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn reformat_number_literal(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let literal = ctx.find_node_at_offset::<ast::Literal>()?; let literal = ctx.find_node_at_offset::<ast::Literal>()?;
let literal = match literal.kind() { let literal = match literal.kind() {
ast::LiteralKind::IntNumber(it) => it, ast::LiteralKind::IntNumber(it) => it,

View file

@ -44,7 +44,7 @@ use crate::{
// } // }
// } // }
// ``` // ```
pub(crate) fn promote_local_to_const(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn promote_local_to_const(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let pat = ctx.find_node_at_offset::<ast::IdentPat>()?; let pat = ctx.find_node_at_offset::<ast::IdentPat>()?;
let name = pat.name()?; let name = pat.name()?;
if !pat.is_simple_ident() { if !pat.is_simple_ident() {
@ -95,7 +95,7 @@ pub(crate) fn promote_local_to_const(acc: &mut Assists, ctx: &AssistContext) ->
) )
} }
fn is_body_const(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> bool { fn is_body_const(sema: &Semantics<'_, RootDatabase>, expr: &ast::Expr) -> bool {
let mut is_const = true; let mut is_const = true;
preorder_expr(expr, &mut |ev| { preorder_expr(expr, &mut |ev| {
let expr = match ev { let expr = match ev {

View file

@ -35,7 +35,7 @@ use crate::{
// }; // };
// } // }
// ``` // ```
pub(crate) fn pull_assignment_up(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn pull_assignment_up(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let assign_expr = ctx.find_node_at_offset::<ast::BinExpr>()?; let assign_expr = ctx.find_node_at_offset::<ast::BinExpr>()?;
let op_kind = assign_expr.op_kind()?; let op_kind = assign_expr.op_kind()?;
@ -151,7 +151,7 @@ impl<'a> AssignmentsCollector<'a> {
} }
fn is_equivalent( fn is_equivalent(
sema: &hir::Semantics<ide_db::RootDatabase>, sema: &hir::Semantics<'_, ide_db::RootDatabase>,
expr0: &ast::Expr, expr0: &ast::Expr,
expr1: &ast::Expr, expr1: &ast::Expr,
) -> bool { ) -> bool {

View file

@ -32,7 +32,7 @@ use crate::{
// Foo::foo(&foo); // Foo::foo(&foo);
// } // }
// ``` // ```
pub(crate) fn qualify_method_call(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn qualify_method_call(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let name: ast::NameRef = ctx.find_node_at_offset()?; let name: ast::NameRef = ctx.find_node_at_offset()?;
let call = name.syntax().parent().and_then(ast::MethodCallExpr::cast)?; let call = name.syntax().parent().and_then(ast::MethodCallExpr::cast)?;

View file

@ -35,7 +35,7 @@ use crate::{
// } // }
// # pub mod std { pub mod collections { pub struct HashMap { } } } // # pub mod std { pub mod collections { pub struct HashMap { } } }
// ``` // ```
pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let (import_assets, syntax_under_caret) = find_importable_node(ctx)?; let (import_assets, syntax_under_caret) = find_importable_node(ctx)?;
let mut proposed_imports = import_assets.search_for_relative_paths(&ctx.sema); let mut proposed_imports = import_assets.search_for_relative_paths(&ctx.sema);
if proposed_imports.is_empty() { if proposed_imports.is_empty() {

Some files were not shown because too many files have changed in this diff Show more