Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/hir/src/diagnostics.rs11
-rw-r--r--crates/hir/src/lib.rs20
-rw-r--r--crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs79
-rw-r--r--crates/ide-diagnostics/src/lib.rs2
4 files changed, 111 insertions, 1 deletions
diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs
index cf9a2b73d9..1cb36f9b02 100644
--- a/crates/hir/src/diagnostics.rs
+++ b/crates/hir/src/diagnostics.rs
@@ -12,7 +12,7 @@ use hir_def::path::ModPath;
use hir_expand::{name::Name, HirFileId, InFile};
use syntax::{ast, AstPtr, SyntaxError, SyntaxNodePtr, TextRange};
-use crate::{AssocItem, Field, Local, MacroKind, Type};
+use crate::{AssocItem, Field, Local, MacroKind, Trait, Type};
macro_rules! diagnostics {
($($diag:ident,)*) => {
@@ -55,6 +55,7 @@ diagnostics![
ReplaceFilterMapNextWithFindMap,
TraitImplIncorrectSafety,
TraitImplMissingAssocItems,
+ TraitImplRedundantAssocItems,
TraitImplOrphan,
TypedHole,
TypeMismatch,
@@ -310,3 +311,11 @@ pub struct TraitImplMissingAssocItems {
pub impl_: AstPtr<ast::Impl>,
pub missing: Vec<(Name, AssocItem)>,
}
+
+#[derive(Debug, PartialEq, Eq)]
+pub struct TraitImplRedundantAssocItems {
+ pub file_id: HirFileId,
+ pub trait_: Trait,
+ pub impl_: AstPtr<ast::Impl>,
+ pub assoc_item: (Name, AssocItem),
+}
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 4a0c384e8a..5137bff055 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -693,6 +693,26 @@ impl Module {
},
));
+ let redundant = impl_assoc_items_scratch
+ .iter()
+ .filter(|(id, name)| {
+ !items.iter().any(|(impl_name, impl_item)| {
+ discriminant(impl_item) == discriminant(id) && impl_name == name
+ })
+ })
+ .map(|(item, name)| (name.clone(), AssocItem::from(*item)));
+ for (name, assoc_item) in redundant {
+ acc.push(
+ TraitImplRedundantAssocItems {
+ trait_,
+ file_id,
+ impl_: ast_id_map.get(node.ast_id()),
+ assoc_item: (name, assoc_item),
+ }
+ .into(),
+ )
+ }
+
let missing: Vec<_> = required_items
.filter(|(name, id)| {
!impl_assoc_items_scratch.iter().any(|(impl_item, impl_name)| {
diff --git a/crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs b/crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs
new file mode 100644
index 0000000000..8200143914
--- /dev/null
+++ b/crates/ide-diagnostics/src/handlers/trait_impl_redundant_assoc_item.rs
@@ -0,0 +1,79 @@
+use hir::{Const, Function, HasSource, TypeAlias};
+use ide_db::base_db::FileRange;
+
+use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext};
+
+// Diagnostic: trait-impl-redundant-assoc_item
+//
+// Diagnoses redundant trait items in a trait impl.
+pub(crate) fn trait_impl_redundant_assoc_item(
+ ctx: &DiagnosticsContext<'_>,
+ d: &hir::TraitImplRedundantAssocItems,
+) -> Diagnostic {
+ let name = d.assoc_item.0.clone();
+ let assoc_item = d.assoc_item.1;
+ let db = ctx.sema.db;
+
+ let default_range = d.impl_.syntax_node_ptr().text_range();
+ let trait_name = d.trait_.name(db).to_smol_str();
+
+ let (redundant_item_name, diagnostic_range) = match assoc_item {
+ hir::AssocItem::Function(id) => (
+ format!("`fn {}`", name.display(db)),
+ Function::from(id)
+ .source(db)
+ .map(|it| it.syntax().value.text_range())
+ .unwrap_or(default_range),
+ ),
+ hir::AssocItem::Const(id) => (
+ format!("`const {}`", name.display(db)),
+ Const::from(id)
+ .source(db)
+ .map(|it| it.syntax().value.text_range())
+ .unwrap_or(default_range),
+ ),
+ hir::AssocItem::TypeAlias(id) => (
+ format!("`type {}`", name.display(db)),
+ TypeAlias::from(id)
+ .source(db)
+ .map(|it| it.syntax().value.text_range())
+ .unwrap_or(default_range),
+ ),
+ };
+
+ Diagnostic::new(
+ DiagnosticCode::RustcHardError("E0407"),
+ format!("{redundant_item_name} is not a member of trait `{trait_name}`"),
+ FileRange { file_id: d.file_id.file_id().unwrap(), range: diagnostic_range },
+ )
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::tests::check_diagnostics;
+
+ #[test]
+ fn trait_with_default_value() {
+ check_diagnostics(
+ r#"
+trait Marker {
+ const FLAG: bool = false;
+ fn boo();
+ fn foo () {}
+}
+struct Foo;
+impl Marker for Foo {
+ type T = i32;
+ //^^^^^^^^^^^^^ error: `type T` is not a member of trait `Marker`
+
+ const FLAG: bool = true;
+
+ fn bar() {}
+ //^^^^^^^^^^^ error: `fn bar` is not a member of trait `Marker`
+
+ fn boo() {}
+}
+ "#,
+ )
+ }
+}
diff --git a/crates/ide-diagnostics/src/lib.rs b/crates/ide-diagnostics/src/lib.rs
index 35272e8726..6cfd5f1832 100644
--- a/crates/ide-diagnostics/src/lib.rs
+++ b/crates/ide-diagnostics/src/lib.rs
@@ -47,6 +47,7 @@ mod handlers {
pub(crate) mod trait_impl_orphan;
pub(crate) mod trait_impl_incorrect_safety;
pub(crate) mod trait_impl_missing_assoc_item;
+ pub(crate) mod trait_impl_redundant_assoc_item;
pub(crate) mod typed_hole;
pub(crate) mod type_mismatch;
pub(crate) mod unimplemented_builtin_macro;
@@ -364,6 +365,7 @@ pub fn diagnostics(
AnyDiagnostic::ReplaceFilterMapNextWithFindMap(d) => handlers::replace_filter_map_next_with_find_map::replace_filter_map_next_with_find_map(&ctx, &d),
AnyDiagnostic::TraitImplIncorrectSafety(d) => handlers::trait_impl_incorrect_safety::trait_impl_incorrect_safety(&ctx, &d),
AnyDiagnostic::TraitImplMissingAssocItems(d) => handlers::trait_impl_missing_assoc_item::trait_impl_missing_assoc_item(&ctx, &d),
+ AnyDiagnostic::TraitImplRedundantAssocItems(d) => handlers::trait_impl_redundant_assoc_item::trait_impl_redundant_assoc_item(&ctx, &d),
AnyDiagnostic::TraitImplOrphan(d) => handlers::trait_impl_orphan::trait_impl_orphan(&ctx, &d),
AnyDiagnostic::TypedHole(d) => handlers::typed_hole::typed_hole(&ctx, &d),
AnyDiagnostic::TypeMismatch(d) => handlers::type_mismatch::type_mismatch(&ctx, &d),
gen-version.sh
-rwxr-xr-x
434
git @ c48035d
m---------
html.c
-rw-r--r--
7390
html.h
-rw-r--r--
1327
parsing.c
-rw-r--r--
4739
robots.txt
-rw-r--r--
68
scan-tree.c
-rw-r--r--
6505
scan-tree.h
-rw-r--r--
150
shared.c
-rw-r--r--
13227
tests
d---------
ui-atom.c
-rw-r--r--
3778
ui-atom.h
-rw-r--r--
118
ui-blame.c
-rw-r--r--
7626
ui-blame.h
-rw-r--r--
100
ui-blob.c
-rw-r--r--
4396
ui-blob.h
-rw-r--r--
308
ui-clone.c
-rw-r--r--
2938
ui-clone.h
-rw-r--r--
151
ui-commit.c
-rw-r--r--
4433
ui-commit.h
-rw-r--r--
129
ui-diff.c
-rw-r--r--
13120
ui-diff.h
-rw-r--r--
432
ui-log.c
-rw-r--r--
14852
ui-log.h
-rw-r--r--
284
ui-patch.c
-rw-r--r--
2696
ui-patch.h
-rw-r--r--
164
ui-plain.c
-rw-r--r--
5181
ui-plain.h
-rw-r--r--
100
ui-refs.c
-rw-r--r--
5459
ui-refs.h
-rw-r--r--
186
ui-repolist.c
-rw-r--r--
8557
ui-repolist.h
-rw-r--r--
154
ui-shared.c
-rw-r--r--
31147
ui-shared.h
-rw-r--r--
4009
ui-snapshot.c
-rw-r--r--
8660
ui-snapshot.h
-rw-r--r--
177
ui-ssdiff.c
-rw-r--r--
9527
ui-ssdiff.h
-rw-r--r--
495
ui-stats.c
-rw-r--r--
9967
ui-stats.h
-rw-r--r--
624
ui-summary.c
-rw-r--r--
3660
ui-summary.h
-rw-r--r--
162
ui-tag.c
-rw-r--r--
2956
ui-tag.h
-rw-r--r--
101
ui-tree.c
-rw-r--r--
9876
ui-tree.h
-rw-r--r--
119
README.md

cgit - CGI for Git

This is an attempt to create a fast web interface for the Git SCM, using a built-in cache to decrease server I/O pressure.

Installation

Building cgit involves building a proper version of Git. How to do this depends on how you obtained the cgit sources:

a) If you're working in a cloned cgit repository, you first need to initialize and update the Git submodule:

$ git submodule init     # register the Git submodule in .git/config
$ $EDITOR .git/config    # if you want to specify a different url for git
$ git submodule update   # clone/fetch and checkout correct git version

b) If you're building from a cgit tarball, you can download a proper git version like this:

$ make get-git

When either a) or b) has been performed, you can build and install cgit like this:

$ make
$ sudo make install

This will install cgit.cgi and cgit.css into /var/www/htdocs/cgit. You can configure this location (and a few other things) by providing a cgit.conf file (see the Makefile for details).

If you'd like to compile without Lua support, you may use:

$ make NO_LUA=1

And if you'd like to specify a Lua implementation, you may use:

$ make LUA_PKGCONFIG=lua5.1

If this is not specified, the Lua implementation will be auto-detected, preferring LuaJIT if many are present. Acceptable values are generally "lua", "luajit", "lua5.1", and "lua5.2".

Dependencies

  • libzip
  • libcrypto (OpenSSL)
  • libssl (OpenSSL)
  • optional: luajit or lua, most reliably used when pkg-config is available

Apache configuration

A new Directory section must probably be added for cgit, possibly something like this:

<Directory "/var/www/htdocs/cgit/">
    AllowOverride None
    Options +ExecCGI
    Order allow,deny
    Allow from all
</Directory>

Runtime configuration

The file /etc/cgitrc is read by cgit before handling a request. In addition to runtime parameters, this file may also contain a list of repositories displayed by cgit (see cgitrc.5.txt for further details).

The cache

When cgit is invoked it looks for a cache file matching the request and returns it to the client. If no such cache file exists (or if it has expired), the content for the request is written into the proper cache file before the file is returned.

If the cache file has expired but cgit is unable to obtain a lock for it, the stale cache file is returned to the client. This is done to favour page throughput over page freshness.

The generated content contains the complete response to the client, including the HTTP headers Modified and Expires.

Online presence