From 49f01d823fc936919a4f093c45ad858d27fda2e9 Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 23 May 2019 21:39:27 +0100 Subject: [PATCH 1/3] Fix missing overflowing literal lint in for loop --- src/librustc/lint/mod.rs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 512e4d434434c..fc2fff6a81fe0 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -35,7 +35,7 @@ use crate::util::nodemap::NodeMap; use errors::{DiagnosticBuilder, DiagnosticId}; use std::{hash, ptr}; use syntax::ast; -use syntax::source_map::{MultiSpan, ExpnFormat}; +use syntax::source_map::{MultiSpan, ExpnFormat, CompilerDesugaringKind}; use syntax::early_buffered_lints::BufferedEarlyLintId; use syntax::edition::Edition; use syntax::symbol::{Symbol, sym}; @@ -887,21 +887,22 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool { }; match info.format { - ExpnFormat::MacroAttribute(..) => return true, // definitely a plugin - ExpnFormat::CompilerDesugaring(_) => return true, // well, it's "external" - ExpnFormat::MacroBang(..) => {} // check below - } - - let def_site = match info.def_site { - Some(span) => span, - // no span for the def_site means it's an external macro - None => return true, - }; + ExpnFormat::MacroAttribute(..) => true, // definitely a plugin + ExpnFormat::CompilerDesugaring(CompilerDesugaringKind::ForLoop) => false, + ExpnFormat::CompilerDesugaring(_) => true, // well, it's "external" + ExpnFormat::MacroBang(..) => { + let def_site = match info.def_site { + Some(span) => span, + // no span for the def_site means it's an external macro + None => return true, + }; - match sess.source_map().span_to_snippet(def_site) { - Ok(code) => !code.starts_with("macro_rules"), - // no snippet = external macro or compiler-builtin expansion - Err(_) => true, + match sess.source_map().span_to_snippet(def_site) { + Ok(code) => !code.starts_with("macro_rules"), + // no snippet = external macro or compiler-builtin expansion + Err(_) => true, + } + } } } From 3e4cefe1bda1b37eedad1d6c3d4166dd8d41c5a2 Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 23 May 2019 21:39:36 +0100 Subject: [PATCH 2/3] Update unreachable loop patterns test --- src/test/ui/unreachable/unreachable-loop-patterns.rs | 1 + src/test/ui/unreachable/unreachable-loop-patterns.stderr | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/test/ui/unreachable/unreachable-loop-patterns.rs b/src/test/ui/unreachable/unreachable-loop-patterns.rs index 3c878410f7710..56ab1a270a75d 100644 --- a/src/test/ui/unreachable/unreachable-loop-patterns.rs +++ b/src/test/ui/unreachable/unreachable-loop-patterns.rs @@ -19,4 +19,5 @@ impl Iterator for Void { fn main() { for _ in unimplemented!() as Void {} //~^ ERROR unreachable pattern + //~^^ ERROR unreachable pattern } diff --git a/src/test/ui/unreachable/unreachable-loop-patterns.stderr b/src/test/ui/unreachable/unreachable-loop-patterns.stderr index d2f255c3e104d..254d1178d142e 100644 --- a/src/test/ui/unreachable/unreachable-loop-patterns.stderr +++ b/src/test/ui/unreachable/unreachable-loop-patterns.stderr @@ -10,5 +10,11 @@ note: lint level defined here LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ -error: aborting due to previous error +error: unreachable pattern + --> $DIR/unreachable-loop-patterns.rs:20:14 + | +LL | for _ in unimplemented!() as Void {} + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors From 12de24ce81fbbcc1a2b170a719cc792dfa559c81 Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 23 May 2019 21:48:26 +0100 Subject: [PATCH 3/3] Add test for denying overflowing literal in loop --- src/test/ui/lint/deny-overflowing-literals.rs | 3 +++ src/test/ui/lint/deny-overflowing-literals.stderr | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/test/ui/lint/deny-overflowing-literals.rs b/src/test/ui/lint/deny-overflowing-literals.rs index b887f66e94bd6..21c8ba7d6ce4e 100644 --- a/src/test/ui/lint/deny-overflowing-literals.rs +++ b/src/test/ui/lint/deny-overflowing-literals.rs @@ -1,4 +1,7 @@ fn main() { let x: u8 = 256; //~^ error: literal out of range for `u8` + + for _ in 0..256u8 {} + //~^ error: range endpoint is out of range for `u8` } diff --git a/src/test/ui/lint/deny-overflowing-literals.stderr b/src/test/ui/lint/deny-overflowing-literals.stderr index 1263a7bb7fd1b..c97872b5222e8 100644 --- a/src/test/ui/lint/deny-overflowing-literals.stderr +++ b/src/test/ui/lint/deny-overflowing-literals.stderr @@ -6,5 +6,11 @@ LL | let x: u8 = 256; | = note: #[deny(overflowing_literals)] on by default -error: aborting due to previous error +error: range endpoint is out of range for `u8` + --> $DIR/deny-overflowing-literals.rs:5:14 + | +LL | for _ in 0..256u8 {} + | ^^^^^^^^ help: use an inclusive range instead: `0..=255u8` + +error: aborting due to 2 previous errors