Skip to content

Rustup #7468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jul 15, 2021
Merged

Rustup #7468

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 12 additions & 5 deletions clippy_lints/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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");
}
}
Expand Down
2 changes: 0 additions & 2 deletions clippy_lints/src/implicit_hasher.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(rustc::default_hash_types)]

use std::borrow::Cow;
use std::collections::BTreeMap;

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
9 changes: 1 addition & 8 deletions clippy_lints/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/mut_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 1 addition & 6 deletions clippy_lints/src/unit_types/unit_cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 3 additions & 1 deletion clippy_lints/src/utils/internal_lints/metadata_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
4 changes: 2 additions & 2 deletions clippy_utils/src/higher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 3 additions & 13 deletions clippy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
15 changes: 10 additions & 5 deletions clippy_utils/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -112,23 +113,27 @@ 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>,
ty: Ty<'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`.
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2021-07-01"
channel = "nightly-2021-07-15"
components = ["llvm-tools-preview", "rustc-dev", "rust-src"]
2 changes: 1 addition & 1 deletion tests/ui/assertions_on_constants.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(non_fmt_panic)]
#![allow(non_fmt_panics)]

macro_rules! assert_const {
($len:expr) => {
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/deprecated.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down