mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 15:11:30 +00:00
Auto merge of #7468 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
This commit is contained in:
commit
54a20a02ec
14 changed files with 40 additions and 50 deletions
|
@ -592,7 +592,7 @@ Released 2021-02-11
|
|||
|
||||
* Previously deprecated [`str_to_string`] and [`string_to_string`] have been un-deprecated
|
||||
as `restriction` lints [#6333](https://github.com/rust-lang/rust-clippy/pull/6333)
|
||||
* Deprecate `panic_params` lint. This is now available in rustc as `non_fmt_panic`
|
||||
* Deprecate `panic_params` lint. This is now available in rustc as `non_fmt_panics`
|
||||
[#6351](https://github.com/rust-lang/rust-clippy/pull/6351)
|
||||
* Move [`map_err_ignore`] to `restriction`
|
||||
[#6416](https://github.com/rust-lang/rust-clippy/pull/6416)
|
||||
|
|
|
@ -26,6 +26,7 @@ use rustc_span::source_map::{BytePos, FilePathMapping, MultiSpan, SourceMap, Spa
|
|||
use rustc_span::{sym, FileName, Pos};
|
||||
use std::io;
|
||||
use std::ops::Range;
|
||||
use std::thread;
|
||||
use url::Url;
|
||||
|
||||
declare_clippy_lint! {
|
||||
|
@ -584,17 +585,17 @@ fn get_current_span(spans: &[(usize, Span)], idx: usize) -> (usize, Span) {
|
|||
}
|
||||
|
||||
fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) {
|
||||
fn has_needless_main(code: &str, edition: Edition) -> bool {
|
||||
fn has_needless_main(code: String, edition: Edition) -> bool {
|
||||
rustc_driver::catch_fatal_errors(|| {
|
||||
rustc_span::with_session_globals(edition, || {
|
||||
let filename = FileName::anon_source_code(code);
|
||||
rustc_span::create_session_globals_then(edition, || {
|
||||
let filename = FileName::anon_source_code(&code);
|
||||
|
||||
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
|
||||
let emitter = EmitterWriter::new(box io::sink(), None, false, false, false, None, false);
|
||||
let handler = Handler::with_emitter(false, None, box emitter);
|
||||
let sess = ParseSess::with_span_handler(handler, sm);
|
||||
|
||||
let mut parser = match maybe_new_parser_from_source_str(&sess, filename, code.into()) {
|
||||
let mut parser = match maybe_new_parser_from_source_str(&sess, filename, code) {
|
||||
Ok(p) => p,
|
||||
Err(errs) => {
|
||||
for mut err in errs {
|
||||
|
@ -649,7 +650,13 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) {
|
|||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
if has_needless_main(text, edition) {
|
||||
// Because of the global session, we need to create a new session in a different thread with
|
||||
// the edition we need.
|
||||
let text = text.to_owned();
|
||||
if thread::spawn(move || has_needless_main(text, edition))
|
||||
.join()
|
||||
.expect("thread::spawn failed")
|
||||
{
|
||||
span_lint(cx, NEEDLESS_DOCTEST_MAIN, span, "needless `fn main` in doctest");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#![allow(rustc::default_hash_types)]
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
|
|
|
@ -2177,7 +2177,7 @@ pub fn register_renamed(ls: &mut rustc_lint::LintStore) {
|
|||
ls.register_renamed("clippy::unused_label", "unused_labels");
|
||||
ls.register_renamed("clippy::drop_bounds", "drop_bounds");
|
||||
ls.register_renamed("clippy::temporary_cstring_as_ptr", "temporary_cstring_as_ptr");
|
||||
ls.register_renamed("clippy::panic_params", "non_fmt_panic");
|
||||
ls.register_renamed("clippy::panic_params", "non_fmt_panics");
|
||||
ls.register_renamed("clippy::unknown_clippy_lints", "unknown_lints");
|
||||
}
|
||||
|
||||
|
|
|
@ -662,14 +662,7 @@ fn in_attributes_expansion(expr: &Expr<'_>) -> bool {
|
|||
use rustc_span::hygiene::MacroKind;
|
||||
if expr.span.from_expansion() {
|
||||
let data = expr.span.ctxt().outer_expn_data();
|
||||
matches!(
|
||||
data.kind,
|
||||
ExpnKind::Macro {
|
||||
kind: MacroKind::Attr,
|
||||
name: _,
|
||||
proc_macro: _
|
||||
}
|
||||
)
|
||||
matches!(data.kind, ExpnKind::Macro(MacroKind::Attr, _))
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
|
|
@ -120,8 +120,8 @@ fn is_mutable_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span) -> bo
|
|||
},
|
||||
Tuple(..) => ty.tuple_fields().any(|ty| is_mutable_type(cx, ty, span)),
|
||||
Adt(..) => {
|
||||
cx.tcx.layout_of(cx.param_env.and(ty)).is_ok()
|
||||
&& !ty.has_escaping_bound_vars()
|
||||
!ty.has_escaping_bound_vars()
|
||||
&& cx.tcx.layout_of(cx.param_env.and(ty)).is_ok()
|
||||
&& !ty.is_freeze(cx.tcx.at(span), cx.param_env)
|
||||
},
|
||||
_ => false,
|
||||
|
|
|
@ -8,12 +8,7 @@ use super::UNIT_CMP;
|
|||
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
|
||||
if expr.span.from_expansion() {
|
||||
if let Some(callee) = expr.span.source_callee() {
|
||||
if let ExpnKind::Macro {
|
||||
kind: MacroKind::Bang,
|
||||
name: symbol,
|
||||
proc_macro: _,
|
||||
} = callee.kind
|
||||
{
|
||||
if let ExpnKind::Macro(MacroKind::Bang, symbol) = callee.kind {
|
||||
if let ExprKind::Binary(ref cmp, left, _) = expr.kind {
|
||||
let op = cmp.node;
|
||||
if op.is_comparison() && cx.typeck_results().expr_ty(left).is_unit() {
|
||||
|
|
|
@ -520,7 +520,9 @@ fn get_lint_group_and_level_or_lint(
|
|||
lint_name: &str,
|
||||
item: &'hir Item<'_>,
|
||||
) -> Option<(String, &'static str)> {
|
||||
let result = cx.lint_store.check_lint_name(lint_name, Some(sym::clippy));
|
||||
let result = cx
|
||||
.lint_store
|
||||
.check_lint_name(cx.sess(), lint_name, Some(sym::clippy), &[]);
|
||||
if let CheckLintNameResult::Tool(Ok(lint_lst)) = result {
|
||||
if let Some(group) = get_lint_group(cx, lint_lst[0]) {
|
||||
if EXCLUDED_LINT_GROUPS.contains(&group.as_str()) {
|
||||
|
|
|
@ -285,7 +285,7 @@ impl FormatExpn<'tcx> {
|
|||
if let Some(init) = local.init;
|
||||
if let ExprKind::Call(_, [format_args]) = init.kind;
|
||||
let expn_data = expr.span.ctxt().outer_expn_data();
|
||||
if let ExpnKind::Macro { name: sym::format, .. } = expn_data.kind;
|
||||
if let ExpnKind::Macro(_, sym::format) = expn_data.kind;
|
||||
if let Some(format_args) = FormatArgsExpn::parse(format_args);
|
||||
then {
|
||||
Some(FormatExpn {
|
||||
|
@ -320,7 +320,7 @@ impl FormatArgsExpn<'tcx> {
|
|||
/// Parses an expanded `format_args!` or `format_args_nl!` invocation
|
||||
pub fn parse(expr: &'tcx Expr<'tcx>) -> Option<Self> {
|
||||
if_chain! {
|
||||
if let ExpnKind::Macro { name, .. } = expr.span.ctxt().outer_expn_data().kind;
|
||||
if let ExpnKind::Macro(_, name) = expr.span.ctxt().outer_expn_data().kind;
|
||||
let name = name.as_str();
|
||||
if name.ends_with("format_args") || name.ends_with("format_args_nl");
|
||||
if let ExprKind::Call(_, args) = expr.kind;
|
||||
|
|
|
@ -483,7 +483,7 @@ pub fn path_to_res(cx: &LateContext<'_>, path: &[&str]) -> Res {
|
|||
_ => return Res::Err,
|
||||
};
|
||||
let tcx = cx.tcx;
|
||||
let crates = tcx.crates();
|
||||
let crates = tcx.crates(());
|
||||
let krate = try_res!(crates.iter().find(|&&num| tcx.crate_name(num).as_str() == krate));
|
||||
let first = try_res!(item_child_by_name(tcx, krate.as_def_id(), first));
|
||||
let last = path
|
||||
|
@ -953,12 +953,7 @@ pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
|
|||
let data = span.ctxt().outer_expn_data();
|
||||
let new_span = data.call_site;
|
||||
|
||||
if let ExpnKind::Macro {
|
||||
kind: MacroKind::Bang,
|
||||
name: mac_name,
|
||||
proc_macro: _,
|
||||
} = data.kind
|
||||
{
|
||||
if let ExpnKind::Macro(MacroKind::Bang, mac_name) = data.kind {
|
||||
if mac_name.as_str() == name {
|
||||
return Some(new_span);
|
||||
}
|
||||
|
@ -986,12 +981,7 @@ pub fn is_direct_expn_of(span: Span, name: &str) -> Option<Span> {
|
|||
let data = span.ctxt().outer_expn_data();
|
||||
let new_span = data.call_site;
|
||||
|
||||
if let ExpnKind::Macro {
|
||||
kind: MacroKind::Bang,
|
||||
name: mac_name,
|
||||
proc_macro: _,
|
||||
} = data.kind
|
||||
{
|
||||
if let ExpnKind::Macro(MacroKind::Bang, mac_name) = data.kind {
|
||||
if mac_name.as_str() == name {
|
||||
return Some(new_span);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ use rustc_middle::ty::{self, AdtDef, IntTy, Ty, TypeFoldable, UintTy};
|
|||
use rustc_span::sym;
|
||||
use rustc_span::symbol::{Ident, Symbol};
|
||||
use rustc_span::DUMMY_SP;
|
||||
use rustc_trait_selection::infer::InferCtxtExt;
|
||||
use rustc_trait_selection::traits::query::normalize::AtExt;
|
||||
|
||||
use crate::{match_def_path, must_use_attr};
|
||||
|
@ -112,6 +113,7 @@ pub fn has_iter_method(cx: &LateContext<'_>, probably_ref_ty: Ty<'_>) -> Option<
|
|||
}
|
||||
|
||||
/// Checks whether a type implements a trait.
|
||||
/// The function returns false in case the type contains an inference variable.
|
||||
/// See also `get_trait_def_id`.
|
||||
pub fn implements_trait<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
|
@ -119,16 +121,19 @@ pub fn implements_trait<'tcx>(
|
|||
trait_id: DefId,
|
||||
ty_params: &[GenericArg<'tcx>],
|
||||
) -> bool {
|
||||
// Do not check on infer_types to avoid panic in evaluate_obligation.
|
||||
if ty.has_infer_types() {
|
||||
return false;
|
||||
}
|
||||
// Clippy shouldn't have infer types
|
||||
assert!(!ty.needs_infer());
|
||||
|
||||
let ty = cx.tcx.erase_regions(ty);
|
||||
if ty.has_escaping_bound_vars() {
|
||||
return false;
|
||||
}
|
||||
let ty_params = cx.tcx.mk_substs(ty_params.iter());
|
||||
cx.tcx.type_implements_trait((trait_id, ty, ty_params, cx.param_env))
|
||||
cx.tcx.infer_ctxt().enter(|infcx| {
|
||||
infcx
|
||||
.type_implements_trait(trait_id, ty, ty_params, cx.param_env)
|
||||
.must_apply_modulo_regions()
|
||||
})
|
||||
}
|
||||
|
||||
/// Checks whether this type implements `Drop`.
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
[toolchain]
|
||||
channel = "nightly-2021-07-01"
|
||||
channel = "nightly-2021-07-15"
|
||||
components = ["llvm-tools-preview", "rustc-dev", "rust-src"]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#![allow(non_fmt_panic)]
|
||||
#![allow(non_fmt_panics)]
|
||||
|
||||
macro_rules! assert_const {
|
||||
($len:expr) => {
|
||||
|
|
|
@ -60,11 +60,11 @@ error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cs
|
|||
LL | #[warn(clippy::temporary_cstring_as_ptr)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr`
|
||||
|
||||
error: lint `clippy::panic_params` has been renamed to `non_fmt_panic`
|
||||
error: lint `clippy::panic_params` has been renamed to `non_fmt_panics`
|
||||
--> $DIR/deprecated.rs:11:8
|
||||
|
|
||||
LL | #[warn(clippy::panic_params)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panic`
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics`
|
||||
|
||||
error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints`
|
||||
--> $DIR/deprecated.rs:12:8
|
||||
|
|
Loading…
Reference in a new issue