Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upSpurious dead code warning when item is only used in impls #18290
Comments
arielb1
changed the title
Spurious "constant item is never used" when a constant is used only in impls
Spurious dead code warning when a constant is used only in impls
Oct 24, 2014
sfackler
added
the
A-lint
label
Oct 24, 2014
GGist
referenced this issue
Oct 30, 2014
Closed
Dead code warning when a constant is used only in a range match #18464
ghost
self-assigned this
Dec 12, 2014
This comment has been minimized.
This comment has been minimized.
|
Updated code: const TLC: usize = 4;
trait Tr { fn doit(&self); }
impl Tr for [usize; TLC] {
fn doit(&self) { println!("called 4"); }
}
fn main() {
let s = [0,1,2,3];
s.doit(); // which .doit is called depends on architecture
}Still gives the warning. |
This comment has been minimized.
This comment has been minimized.
|
Not particularly related to constants: impls just aren't counted as uses for types they refer to. struct X;
struct Y;
struct Z;
trait Foo<T> {
type Ty;
fn foo() -> Self::Ty;
}
impl Foo<Y> for X {
type Ty = Z;
fn foo() -> Self::Ty { unimplemented!() }
}
fn main() {
X::foo();
} |
This comment has been minimized.
This comment has been minimized.
|
I hit another case with this just in the last few days using nightly via rustup; impls don't appear to be involved? const ACT_STRINGS: &'static [&'static str] = &["set name=foo value=foo"];
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn parse() {
for astr in ACT_STRINGS.iter() {
println!("{}", astr);
}
}
}
Changing the I suspect my case is issue #33166 ? |
This comment has been minimized.
This comment has been minimized.
|
Triage:
|
Mark-Simulacrum
changed the title
Spurious dead code warning when a constant is used only in impls
Spurious dead code warning when item is only used in impls
Jun 22, 2017
Mark-Simulacrum
referenced this issue
Jun 22, 2017
Closed
Incorrect "type alias is never used" #42303
Mark-Simulacrum
added
the
C-bug
label
Jul 22, 2017
This was referenced Jul 22, 2017
This comment has been minimized.
This comment has been minimized.
|
|
Mark-Simulacrum
marked this as
a duplicate of
#41203
Jul 27, 2017
This was referenced Jul 28, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
arielb1 commentedOct 24, 2014
It seems that if a
constis only used inimpls, but not in actual code, then rustc emits a "constant item is never used" warning, as in the following code:Which prints (when compiled and then run):