Skip to content

Commit 935e641

Browse files
author
Oliver Schneider
committed
only warn for private items or public references
1 parent 1376cbd commit 935e641

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/librustc_lint/builtin.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,23 @@ impl LintPass for StaticCouldBeConst {
122122
}
123123

124124
fn check_item(&mut self, cx: &Context, it: &ast::Item) {
125-
let expr = match it.node {
126-
ast::ItemStatic(_, ast::MutImmutable, ref expr) => expr,
125+
let (ty, expr) = match it.node {
126+
ast::ItemStatic(ref ty, ast::MutImmutable, ref expr) => (ty, expr),
127127
_ => return,
128128
};
129129
let const_qualif = cx.tcx.const_qualif_map.borrow()[&expr.id];
130130
if const_qualif.contains(check_const::ConstQualif::MUTABLE_MEM) {
131131
return;
132132
}
133+
// public item?
134+
if cx.exported_items.contains(&it.id) {
135+
let ty = cx.tcx.ast_ty_to_ty_cache.borrow()[&ty.id];
136+
match ty.sty {
137+
ty::sty::ty_rptr(..) => {},
138+
// don't warn for public non-refs
139+
_ => return,
140+
}
141+
}
133142
cx.span_lint(STATIC_COULD_BE_CONST, it.span, "static could be replaced by a const");
134143
}
135144
}

0 commit comments

Comments
 (0)