Flag unsafe blocks from format! as compiler-generated
This commit is contained in:
parent
19a6fabad8
commit
11e9c48353
5 changed files with 21 additions and 5 deletions
|
@ -1133,8 +1133,9 @@ impl Visitor<@mut Context> for UnusedUnsafeLintVisitor {
|
||||||
match e.node {
|
match e.node {
|
||||||
// Don't warn about generated blocks, that'll just pollute the
|
// Don't warn about generated blocks, that'll just pollute the
|
||||||
// output.
|
// output.
|
||||||
ast::ExprBlock(ref blk) if blk.rules == ast::UnsafeBlock(false) => {
|
ast::ExprBlock(ref blk) => {
|
||||||
if !cx.tcx.used_unsafe.contains(&blk.id) {
|
if blk.rules == ast::UnsafeBlock(ast::UserProvided) &&
|
||||||
|
!cx.tcx.used_unsafe.contains(&blk.id) {
|
||||||
cx.span_lint(unused_unsafe, blk.span,
|
cx.span_lint(unused_unsafe, blk.span,
|
||||||
"unnecessary `unsafe` block");
|
"unnecessary `unsafe` block");
|
||||||
}
|
}
|
||||||
|
|
|
@ -479,7 +479,13 @@ pub struct Field {
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
|
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
|
||||||
pub enum BlockCheckMode {
|
pub enum BlockCheckMode {
|
||||||
DefaultBlock,
|
DefaultBlock,
|
||||||
UnsafeBlock(/* generated internally */ bool),
|
UnsafeBlock(UnsafeSource),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
|
||||||
|
pub enum UnsafeSource {
|
||||||
|
CompilerGenerated,
|
||||||
|
UserProvided,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable,IterBytes)]
|
#[deriving(Clone, Eq, Encodable, Decodable,IterBytes)]
|
||||||
|
|
|
@ -632,7 +632,7 @@ impl Context {
|
||||||
stmts: ~[],
|
stmts: ~[],
|
||||||
expr: Some(result),
|
expr: Some(result),
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
rules: ast::UnsafeBlock,
|
rules: ast::UnsafeBlock(ast::CompilerGenerated),
|
||||||
span: self.fmtsp,
|
span: self.fmtsp,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1792,7 +1792,7 @@ impl Parser {
|
||||||
} else if self.eat_keyword(keywords::Match) {
|
} else if self.eat_keyword(keywords::Match) {
|
||||||
return self.parse_match_expr();
|
return self.parse_match_expr();
|
||||||
} else if self.eat_keyword(keywords::Unsafe) {
|
} else if self.eat_keyword(keywords::Unsafe) {
|
||||||
return self.parse_block_expr(lo, UnsafeBlock(false));
|
return self.parse_block_expr(lo, UnsafeBlock(ast::UserProvided));
|
||||||
} else if *self.token == token::LBRACKET {
|
} else if *self.token == token::LBRACKET {
|
||||||
self.bump();
|
self.bump();
|
||||||
let mutbl = self.parse_mutability();
|
let mutbl = self.parse_mutability();
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
// xfail-fast: check-fast screws up repr paths
|
// xfail-fast: check-fast screws up repr paths
|
||||||
|
|
||||||
|
#[deny(warnings)];
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
struct A;
|
struct A;
|
||||||
|
@ -226,6 +228,13 @@ pub fn main() {
|
||||||
let a = ~3;
|
let a = ~3;
|
||||||
format!("{:?}", a);
|
format!("{:?}", a);
|
||||||
format!("{:?}", a);
|
format!("{:?}", a);
|
||||||
|
|
||||||
|
// make sure that format! doesn't cause spurious unused-unsafe warnings when
|
||||||
|
// it's inside of an outer unsafe block
|
||||||
|
unsafe {
|
||||||
|
let a: int = ::std::cast::transmute(3u);
|
||||||
|
format!("{}", a);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Basic test to make sure that we can invoke the `write!` macro with an
|
// Basic test to make sure that we can invoke the `write!` macro with an
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue