Comments (5)
So basically suggest the usage of a union type instead of the trait object?
Yeah, I'm not sure what the heuristics should be either.
from rust-clippy.
I think @kmcallister is referring to fn foo<T: SomeTrait>(t: &T)
vs. fn foo(t: &SomeTrait)
rather than explicit ADTs.
from rust-clippy.
Oh, I see.
from rust-clippy.
It seems like the main requirement for this would be to look at every function declaration, such as fn foo(t: &SomeTrait)
, and then be able to determine that SomeTrait
is a trait and not a struct or enum. Once you have that info, you can choose to emit a lint or not.
Maybe the RLS could help with this? not sure.
from rust-clippy.
Detecting whether the argument is a trait object is easy. Since any generic type with a bound on a trait can be turned into a trait object of that type, this would be a trivial transformation. The issues with transforming a random function from dynamic dispatch to static dispatch is that someone might be using the function by passing it a trait object. They might not have a chance to do anything else. So we'd also need to add a ?Sized
bound.
In gennral you can convert any fn foo(t: &SomeTrait)
to fn foo<T: SomeTrait + ?Sized>(t: &T)
without breaking anything.
Additionally there are cases where we do not want to use static dispatch in order to reduce compiletimes of downstream crates.
from rust-clippy.
Related Issues (20)
- Another unconditional_recursion false positive in PartialEq field comparison HOT 3
- Lints for functions with `Result` return types which only return `Ok(...)` or `Err(...)` HOT 2
- Race condition in clippy --fix when two lints apply to the same expression with assert and format in it.
- `significant_drop_tightening` recommends dropping a lock in the middle of a loop
- `semicolon_if_nothing_returned` on an attribute macro HOT 1
- unused or incorrect lints in Cargo.toml fail silently HOT 1
- lint suggests dropping temporary with significant drop after another function takes ownership of it. HOT 1
- dbg_macro ignored in macro call sites HOT 1
- unconditional_recursion false positive in PartialEq field comparison (2) HOT 1
- not_unsafe_ptr_arg_deref with function in an extern block HOT 2
- clippy::useless_asref warns in cases where map callback performs a method call before a clone
- `clippy::from_over_into` produces incorrect suggested code for unit type
- `.as_ref().map(|x| *x)` is no longer warned
- Add a warning when wrapping an unwrapped Optional into an Optional HOT 3
- `multiple_crate_versions` doesn't report when name contains a dash
- Issue with map(clone) on Option in latest nightly HOT 5
- Warn if user calls `.to_string()` multiple times on variable. HOT 1
- unconditional_recursion false positive in `PartialEq` with `Deref` HOT 1
- err_missing_error
- Autofix for needless_return with unsafe block produces invalid code
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-clippy.