Skip to content

Commit

Permalink
Auto merge of #4825 - Manishearth:rustup, r=Manishearth
Browse files Browse the repository at this point in the history
Rustup to rustc 1.41.0-nightly (35ef33a 2019-11-21)

I don't have the right fix for the fmtstr tests, and I'm also hitting problems caused by messense/rustc-test#3

List of rustups:
- rust-lang/rust#66271 (syntax: Keep string literals in ABIs and `asm!` more precisely)
- rust-lang/rust#65355 (Stabilize `!` in Rust 1.41.0)
- rust-lang/rust#66515 (Reduce size of `hir::Expr` by boxing more of `hir::InlineAsm`)
- rust-lang/rust#66389 (Specific labels when referring to "expected" and "found" types)
- rust-lang/rust#66074 ([mir-opt] Turn on the `ConstProp` pass by default)

changelog: none
  • Loading branch information
bors committed Nov 23, 2019
2 parents b4f1769 + 7bae5bd commit 3870050
Show file tree
Hide file tree
Showing 25 changed files with 126 additions and 178 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util"}

[dev-dependencies]
cargo_metadata = "0.9.0"
compiletest_rs = { version = "0.3.24", features = ["tmp"] }
compiletest_rs = { version = "0.4.0", features = ["tmp"] }
tester = "0.7"
lazy_static = "1.0"
clippy-mini-macro-test = { version = "0.2", path = "mini-macro" }
serde = { version = "1.0", features = ["derive"] }
Expand Down
1 change: 0 additions & 1 deletion clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#![feature(box_syntax)]
#![feature(box_patterns)]
#![feature(never_type)]
#![feature(rustc_private)]
#![feature(slice_patterns)]
#![feature(stmt_expr_attributes)]
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ fn never_loop_expr(expr: &Expr, main_loop_id: HirId) -> NeverLoopResult {
ExprKind::Struct(_, _, None)
| ExprKind::Yield(_, _)
| ExprKind::Closure(_, _, _, _, _)
| ExprKind::InlineAsm(_, _, _)
| ExprKind::InlineAsm(_)
| ExprKind::Path(_)
| ExprKind::Lit(_)
| ExprKind::Err => NeverLoopResult::Otherwise,
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/utils/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,8 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
println!("Ret(None) = {};", current);
}
},
ExprKind::InlineAsm(_, ref _input, ref _output) => {
println!("InlineAsm(_, ref input, ref output) = {};", current);
ExprKind::InlineAsm(_) => {
println!("InlineAsm(_) = {};", current);
println!(" // unimplemented: `ExprKind::InlineAsm` is not further destructured at the moment");
},
ExprKind::Struct(ref path, ref fields, ref opt_base) => {
Expand Down
8 changes: 5 additions & 3 deletions clippy_lints/src/utils/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,16 @@ fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr, indent: usize) {
print_expr(cx, e, indent + 1);
}
},
hir::ExprKind::InlineAsm(_, ref input, ref output) => {
hir::ExprKind::InlineAsm(ref asm) => {
let inputs = &asm.inputs_exprs;
let outputs = &asm.outputs_exprs;
println!("{}InlineAsm", ind);
println!("{}inputs:", ind);
for e in input {
for e in inputs.iter() {
print_expr(cx, e, indent + 1);
}
println!("{}outputs:", ind);
for e in output {
for e in outputs.iter() {
print_expr(cx, e, indent + 1);
}
},
Expand Down
92 changes: 35 additions & 57 deletions clippy_lints/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use rustc_errors::Applicability;
use rustc_lexer::unescape::{self, EscapeError};
use rustc_parse::parser;
use syntax::ast::*;
use syntax::symbol::Symbol;
use syntax::token;
use syntax::tokenstream::TokenStream;
use syntax_pos::{BytePos, Span};
Expand Down Expand Up @@ -190,7 +191,7 @@ impl EarlyLintPass for Write {
if mac.path == sym!(println) {
span_lint(cx, PRINT_STDOUT, mac.span, "use of `println!`");
if let (Some(fmt_str), _) = check_tts(cx, &mac.tts, false) {
if fmt_str.contents.is_empty() {
if fmt_str.symbol == Symbol::intern("") {
span_lint_and_sugg(
cx,
PRINTLN_EMPTY_STRING,
Expand All @@ -205,7 +206,7 @@ impl EarlyLintPass for Write {
} else if mac.path == sym!(print) {
span_lint(cx, PRINT_STDOUT, mac.span, "use of `print!`");
if let (Some(fmt_str), _) = check_tts(cx, &mac.tts, false) {
if check_newlines(&fmt_str.contents, fmt_str.style) {
if check_newlines(&fmt_str) {
span_lint_and_then(
cx,
PRINT_WITH_NEWLINE,
Expand All @@ -216,7 +217,7 @@ impl EarlyLintPass for Write {
"use `println!` instead",
vec![
(mac.path.span, String::from("println")),
(fmt_str.newline_span(), String::new()),
(newline_span(&fmt_str), String::new()),
],
Applicability::MachineApplicable,
);
Expand All @@ -226,7 +227,7 @@ impl EarlyLintPass for Write {
}
} else if mac.path == sym!(write) {
if let (Some(fmt_str), _) = check_tts(cx, &mac.tts, true) {
if check_newlines(&fmt_str.contents, fmt_str.style) {
if check_newlines(&fmt_str) {
span_lint_and_then(
cx,
WRITE_WITH_NEWLINE,
Expand All @@ -237,7 +238,7 @@ impl EarlyLintPass for Write {
"use `writeln!()` instead",
vec![
(mac.path.span, String::from("writeln")),
(fmt_str.newline_span(), String::new()),
(newline_span(&fmt_str), String::new()),
],
Applicability::MachineApplicable,
);
Expand All @@ -247,7 +248,7 @@ impl EarlyLintPass for Write {
}
} else if mac.path == sym!(writeln) {
if let (Some(fmt_str), expr) = check_tts(cx, &mac.tts, true) {
if fmt_str.contents.is_empty() {
if fmt_str.symbol == Symbol::intern("") {
let mut applicability = Applicability::MachineApplicable;
let suggestion = expr.map_or_else(
move || {
Expand All @@ -272,37 +273,27 @@ impl EarlyLintPass for Write {
}
}

/// The arguments of a `print[ln]!` or `write[ln]!` invocation.
struct FmtStr {
/// The contents of the format string (inside the quotes).
contents: String,
style: StrStyle,
/// The span of the format string, including quotes, the raw marker, and any raw hashes.
span: Span,
}

impl FmtStr {
/// Given a format string that ends in a newline and its span, calculates the span of the
/// newline.
fn newline_span(&self) -> Span {
let sp = self.span;
/// Given a format string that ends in a newline and its span, calculates the span of the
/// newline.
fn newline_span(fmtstr: &StrLit) -> Span {
let sp = fmtstr.span;
let contents = &fmtstr.symbol.as_str();

let newline_sp_hi = sp.hi()
- match self.style {
StrStyle::Cooked => BytePos(1),
StrStyle::Raw(hashes) => BytePos((1 + hashes).into()),
};

let newline_sp_len = if self.contents.ends_with('\n') {
BytePos(1)
} else if self.contents.ends_with(r"\n") {
BytePos(2)
} else {
panic!("expected format string to contain a newline");
let newline_sp_hi = sp.hi()
- match fmtstr.style {
StrStyle::Cooked => BytePos(1),
StrStyle::Raw(hashes) => BytePos((1 + hashes).into()),
};

sp.with_lo(newline_sp_hi - newline_sp_len).with_hi(newline_sp_hi)
}
let newline_sp_len = if contents.ends_with('\n') {
BytePos(1)
} else if contents.ends_with(r"\n") {
BytePos(2)
} else {
panic!("expected format string to contain a newline");
};

sp.with_lo(newline_sp_hi - newline_sp_len).with_hi(newline_sp_hi)
}

/// Checks the arguments of `print[ln]!` and `write[ln]!` calls. It will return a tuple of two
Expand All @@ -325,7 +316,7 @@ impl FmtStr {
/// (Some("string to write: {}"), Some(buf))
/// ```
#[allow(clippy::too_many_lines)]
fn check_tts<'a>(cx: &EarlyContext<'a>, tts: &TokenStream, is_write: bool) -> (Option<FmtStr>, Option<Expr>) {
fn check_tts<'a>(cx: &EarlyContext<'a>, tts: &TokenStream, is_write: bool) -> (Option<StrLit>, Option<Expr>) {
use fmt_macros::*;
let tts = tts.clone();

Expand All @@ -342,12 +333,11 @@ fn check_tts<'a>(cx: &EarlyContext<'a>, tts: &TokenStream, is_write: bool) -> (O
}
}

let (fmtstr, fmtstyle) = match parser.parse_str().map_err(|mut err| err.cancel()) {
Ok((fmtstr, fmtstyle)) => (fmtstr.to_string(), fmtstyle),
let fmtstr = match parser.parse_str_lit() {
Ok(fmtstr) => fmtstr,
Err(_) => return (None, expr),
};
let fmtspan = parser.prev_span;
let tmp = fmtstr.clone();
let tmp = fmtstr.symbol.as_str();
let mut args = vec![];
let mut fmt_parser = Parser::new(&tmp, None, Vec::new(), false);
while let Some(piece) = fmt_parser.next() {
Expand Down Expand Up @@ -377,26 +367,12 @@ fn check_tts<'a>(cx: &EarlyContext<'a>, tts: &TokenStream, is_write: bool) -> (O
ty_span: None,
};
if !parser.eat(&token::Comma) {
return (
Some(FmtStr {
contents: fmtstr,
style: fmtstyle,
span: fmtspan,
}),
expr,
);
return (Some(fmtstr), expr);
}
let token_expr = if let Ok(expr) = parser.parse_expr().map_err(|mut err| err.cancel()) {
expr
} else {
return (
Some(FmtStr {
contents: fmtstr,
style: fmtstyle,
span: fmtspan,
}),
None,
);
return (Some(fmtstr), None);
};
match &token_expr.kind {
ExprKind::Lit(_) => {
Expand Down Expand Up @@ -448,11 +424,13 @@ fn check_tts<'a>(cx: &EarlyContext<'a>, tts: &TokenStream, is_write: bool) -> (O
/// Checks if the format string contains a single newline that terminates it.
///
/// Literal and escaped newlines are both checked (only literal for raw strings).
fn check_newlines(contents: &str, style: StrStyle) -> bool {
fn check_newlines(fmtstr: &StrLit) -> bool {
let mut has_internal_newline = false;
let mut last_was_cr = false;
let mut should_lint = false;

let contents = &fmtstr.symbol.as_str();

let mut cb = |r: Range<usize>, c: Result<char, EscapeError>| {
let c = c.unwrap();

Expand All @@ -466,7 +444,7 @@ fn check_newlines(contents: &str, style: StrStyle) -> bool {
}
};

match style {
match fmtstr.style {
StrStyle::Cooked => unescape::unescape_str(contents, &mut cb),
StrStyle::Raw(_) => unescape::unescape_raw_str(contents, &mut cb),
}
Expand Down
6 changes: 6 additions & 0 deletions src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ impl rustc_driver::Callbacks for ClippyCallbacks {
clippy_lints::register_pre_expansion_lints(&mut lint_store, &conf);
clippy_lints::register_renamed(&mut lint_store);
}));

// FIXME: #4825; This is required, because Clippy lints that are based on MIR have to be
// run on the unoptimized MIR. On the other hand this results in some false negatives. If
// MIR passes can be enabled / disabled separately, we should figure out, what passes to
// use for Clippy.
config.opts.debugging_opts.mir_opt_level = 0;
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/compile-test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![feature(test)]

use compiletest_rs as compiletest;
extern crate test;
extern crate tester as test;

use std::env::{set_var, var};
use std::ffi::OsStr;
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/builtin-type-shadow.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ LL | fn foo<u32>(a: u32) -> u32 {
LL | 42
| ^^ expected type parameter `u32`, found integer
|
= note: expected type `u32`
found type `{integer}`
= note: expected type parameter `u32`
found type `{integer}`
= help: type parameters must be constrained to match other types
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters

Expand Down
1 change: 0 additions & 1 deletion tests/ui/diverging_sub_expression.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(never_type)]
#![warn(clippy::diverging_sub_expression)]
#![allow(clippy::match_same_arms, clippy::logic_bug)]

Expand Down
12 changes: 6 additions & 6 deletions tests/ui/diverging_sub_expression.stderr
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
error: sub-expression diverges
--> $DIR/diverging_sub_expression.rs:21:10
--> $DIR/diverging_sub_expression.rs:20:10
|
LL | b || diverge();
| ^^^^^^^^^
|
= note: `-D clippy::diverging-sub-expression` implied by `-D warnings`

error: sub-expression diverges
--> $DIR/diverging_sub_expression.rs:22:10
--> $DIR/diverging_sub_expression.rs:21:10
|
LL | b || A.foo();
| ^^^^^^^

error: sub-expression diverges
--> $DIR/diverging_sub_expression.rs:31:26
--> $DIR/diverging_sub_expression.rs:30:26
|
LL | 6 => true || return,
| ^^^^^^

error: sub-expression diverges
--> $DIR/diverging_sub_expression.rs:32:26
--> $DIR/diverging_sub_expression.rs:31:26
|
LL | 7 => true || continue,
| ^^^^^^^^

error: sub-expression diverges
--> $DIR/diverging_sub_expression.rs:35:26
--> $DIR/diverging_sub_expression.rs:34:26
|
LL | 3 => true || diverge(),
| ^^^^^^^^^

error: sub-expression diverges
--> $DIR/diverging_sub_expression.rs:40:26
--> $DIR/diverging_sub_expression.rs:39:26
|
LL | _ => true || break,
| ^^^^^
Expand Down
22 changes: 1 addition & 21 deletions tests/ui/indexing_slicing.stderr
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
error: index out of bounds: the len is 4 but the index is 4
--> $DIR/indexing_slicing.rs:18:5
|
LL | x[4]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays.
| ^^^^
|
= note: `#[deny(const_err)]` on by default

error: index out of bounds: the len is 4 but the index is 8
--> $DIR/indexing_slicing.rs:19:5
|
LL | x[1 << 3]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays.
| ^^^^^^^^^

error: index out of bounds: the len is 4 but the index is 15
--> $DIR/indexing_slicing.rs:54:5
|
LL | x[N]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays.
| ^^^^

error: indexing may panic.
--> $DIR/indexing_slicing.rs:13:5
|
Expand Down Expand Up @@ -209,5 +189,5 @@ LL | v[M];
|
= help: Consider using `.get(n)` or `.get_mut(n)` instead

error: aborting due to 27 previous errors
error: aborting due to 24 previous errors

2 changes: 1 addition & 1 deletion tests/ui/infallible_destructuring_match.fixed
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// run-rustfix
#![feature(exhaustive_patterns, never_type)]
#![feature(exhaustive_patterns)]
#![allow(dead_code, unreachable_code, unused_variables)]
#![allow(clippy::let_and_return)]

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/infallible_destructuring_match.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// run-rustfix
#![feature(exhaustive_patterns, never_type)]
#![feature(exhaustive_patterns)]
#![allow(dead_code, unreachable_code, unused_variables)]
#![allow(clippy::let_and_return)]

Expand Down
1 change: 0 additions & 1 deletion tests/ui/must_use_candidates.fixed
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// run-rustfix
#![feature(never_type)]
#![allow(unused_mut)]
#![warn(clippy::must_use_candidate)]
use std::rc::Rc;
Expand Down
1 change: 0 additions & 1 deletion tests/ui/must_use_candidates.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// run-rustfix
#![feature(never_type)]
#![allow(unused_mut)]
#![warn(clippy::must_use_candidate)]
use std::rc::Rc;
Expand Down
Loading

0 comments on commit 3870050

Please sign in to comment.