Skip to content

Commit 92fda92

Browse files
authored
Rollup merge of rust-lang#61098 - varkor:fix-overflowing-literal-in-loop, r=estebank
Fix overflowing literal lint in loops Fixes rust-lang#60459. r? @estebank
2 parents 3388028 + 12de24c commit 92fda92

File tree

5 files changed

+34
-17
lines changed

5 files changed

+34
-17
lines changed

Diff for: src/librustc/lint/mod.rs

+16-15
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::util::nodemap::NodeMap;
3535
use errors::{DiagnosticBuilder, DiagnosticId};
3636
use std::{hash, ptr};
3737
use syntax::ast;
38-
use syntax::source_map::{MultiSpan, ExpnFormat};
38+
use syntax::source_map::{MultiSpan, ExpnFormat, CompilerDesugaringKind};
3939
use syntax::early_buffered_lints::BufferedEarlyLintId;
4040
use syntax::edition::Edition;
4141
use syntax::symbol::{Symbol, sym};
@@ -887,21 +887,22 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool {
887887
};
888888

889889
match info.format {
890-
ExpnFormat::MacroAttribute(..) => return true, // definitely a plugin
891-
ExpnFormat::CompilerDesugaring(_) => return true, // well, it's "external"
892-
ExpnFormat::MacroBang(..) => {} // check below
893-
}
894-
895-
let def_site = match info.def_site {
896-
Some(span) => span,
897-
// no span for the def_site means it's an external macro
898-
None => return true,
899-
};
890+
ExpnFormat::MacroAttribute(..) => true, // definitely a plugin
891+
ExpnFormat::CompilerDesugaring(CompilerDesugaringKind::ForLoop) => false,
892+
ExpnFormat::CompilerDesugaring(_) => true, // well, it's "external"
893+
ExpnFormat::MacroBang(..) => {
894+
let def_site = match info.def_site {
895+
Some(span) => span,
896+
// no span for the def_site means it's an external macro
897+
None => return true,
898+
};
900899

901-
match sess.source_map().span_to_snippet(def_site) {
902-
Ok(code) => !code.starts_with("macro_rules"),
903-
// no snippet = external macro or compiler-builtin expansion
904-
Err(_) => true,
900+
match sess.source_map().span_to_snippet(def_site) {
901+
Ok(code) => !code.starts_with("macro_rules"),
902+
// no snippet = external macro or compiler-builtin expansion
903+
Err(_) => true,
904+
}
905+
}
905906
}
906907
}
907908

Diff for: src/test/ui/lint/deny-overflowing-literals.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
fn main() {
22
let x: u8 = 256;
33
//~^ error: literal out of range for `u8`
4+
5+
for _ in 0..256u8 {}
6+
//~^ error: range endpoint is out of range for `u8`
47
}

Diff for: src/test/ui/lint/deny-overflowing-literals.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,11 @@ LL | let x: u8 = 256;
66
|
77
= note: #[deny(overflowing_literals)] on by default
88

9-
error: aborting due to previous error
9+
error: range endpoint is out of range for `u8`
10+
--> $DIR/deny-overflowing-literals.rs:5:14
11+
|
12+
LL | for _ in 0..256u8 {}
13+
| ^^^^^^^^ help: use an inclusive range instead: `0..=255u8`
14+
15+
error: aborting due to 2 previous errors
1016

Diff for: src/test/ui/unreachable/unreachable-loop-patterns.rs

+1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ impl Iterator for Void {
1919
fn main() {
2020
for _ in unimplemented!() as Void {}
2121
//~^ ERROR unreachable pattern
22+
//~^^ ERROR unreachable pattern
2223
}

Diff for: src/test/ui/unreachable/unreachable-loop-patterns.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,11 @@ note: lint level defined here
1010
LL | #![deny(unreachable_patterns)]
1111
| ^^^^^^^^^^^^^^^^^^^^
1212

13-
error: aborting due to previous error
13+
error: unreachable pattern
14+
--> $DIR/unreachable-loop-patterns.rs:20:14
15+
|
16+
LL | for _ in unimplemented!() as Void {}
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^
18+
19+
error: aborting due to 2 previous errors
1420

0 commit comments

Comments
 (0)