Account for pub
in const
-> static
suggestion
This commit is contained in:
parent
ee220daca3
commit
0528693ff5
@ -1214,8 +1214,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems {
|
||||
// don't have anything to attach a symbol to
|
||||
let msg = "const items should never be #[no_mangle]";
|
||||
let mut err = cx.struct_span_lint(NO_MANGLE_CONST_ITEMS, it.span, msg);
|
||||
|
||||
// account for "pub const" (#45562)
|
||||
let start = cx.tcx.sess.codemap().span_to_snippet(it.span)
|
||||
.map(|snippet| snippet.find("const").unwrap_or(0))
|
||||
.unwrap_or(0) as u32;
|
||||
// `const` is 5 chars
|
||||
let const_span = it.span.with_hi(BytePos(it.span.lo().0 + 5));
|
||||
let const_span = it.span.with_hi(BytePos(it.span.lo().0 + start + 5));
|
||||
err.span_suggestion(const_span,
|
||||
"try a static value",
|
||||
"pub static".to_owned());
|
||||
|
14
src/test/ui/suggestions/issue-45562.rs
Normal file
14
src/test/ui/suggestions/issue-45562.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#[no_mangle] pub const RAH: usize = 5;
|
||||
//~^ ERROR const items should never be #[no_mangle]
|
||||
|
||||
fn main() {}
|
12
src/test/ui/suggestions/issue-45562.stderr
Normal file
12
src/test/ui/suggestions/issue-45562.stderr
Normal file
@ -0,0 +1,12 @@
|
||||
error: const items should never be #[no_mangle]
|
||||
--> $DIR/issue-45562.rs:11:14
|
||||
|
|
||||
11 | #[no_mangle] pub const RAH: usize = 5;
|
||||
| ---------^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| help: try a static value: `pub static`
|
||||
|
|
||||
= note: #[deny(no_mangle_const_items)] on by default
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
Reference in New Issue
Block a user