Skip to content

Rollup of 4 pull requests #5342

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 9 commits into from
Mar 19, 2020
Merged
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
3 changes: 2 additions & 1 deletion .github/workflows/clippy_bors.yml
Original file line number Diff line number Diff line change
@@ -208,8 +208,9 @@ jobs:
- name: Extract Binaries
run: |
DIR=$CARGO_TARGET_DIR/debug
rm $DIR/deps/integration-*.d
mv $DIR/deps/integration-* $DIR/integration
find $DIR ! -executable -o -type d ! -path $DIR | xargs rm -rf
mv $DIR/integration-* $DIR/integration
rm -rf $CARGO_TARGET_DIR/release

- name: Upload Binaries
4 changes: 2 additions & 2 deletions clippy_lints/src/functions.rs
Original file line number Diff line number Diff line change
@@ -486,7 +486,7 @@ fn is_mutable_pat(cx: &LateContext<'_, '_>, pat: &hir::Pat<'_>, tys: &mut FxHash
if let hir::PatKind::Wild = pat.kind {
return false; // ignore `_` patterns
}
let def_id = pat.hir_id.owner_def_id();
let def_id = pat.hir_id.owner.to_def_id();
if cx.tcx.has_typeck_tables(def_id) {
is_mutable_ty(cx, &cx.tcx.typeck_tables_of(def_id).pat_ty(pat), pat.span, tys)
} else {
@@ -601,7 +601,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> {
Call(_, args) | MethodCall(_, _, args) => {
let mut tys = FxHashSet::default();
for arg in args {
let def_id = arg.hir_id.owner_def_id();
let def_id = arg.hir_id.owner.to_def_id();
if self.cx.tcx.has_typeck_tables(def_id)
&& is_mutable_ty(
self.cx,
4 changes: 2 additions & 2 deletions clippy_lints/src/inherent_impl.rs
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MultipleInherentImpl {
// but filter out implementations that have generic params (type or lifetime)
// or are derived from a macro
if !in_macro(item.span) && generics.params.is_empty() {
self.impls.insert(item.hir_id.owner_def_id(), item.span);
self.impls.insert(item.hir_id.owner.to_def_id(), item.span);
}
}
}
@@ -69,7 +69,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MultipleInherentImpl {
// Retrieve all inherent implementations from the crate, grouped by type
for impls in cx
.tcx
.crate_inherent_impls(item.hir_id.owner_def_id().krate)
.crate_inherent_impls(item.hir_id.owner.to_def_id().krate)
.inherent_impls
.values()
{
2 changes: 1 addition & 1 deletion clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
@@ -56,9 +56,9 @@ extern crate rustc_trait_selection;
#[allow(unused_extern_crates)]
extern crate rustc_typeck;

use rustc::session::Session;
use rustc_data_structures::fx::FxHashSet;
use rustc_lint::LintId;
use rustc_session::Session;

/// Macro used to declare a Clippy lint.
///
2 changes: 1 addition & 1 deletion clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
@@ -1679,7 +1679,7 @@ fn check_for_mutation(
span_low: None,
span_high: None,
};
let def_id = def_id::DefId::local(body.hir_id.owner);
let def_id = body.hir_id.owner.to_def_id();
cx.tcx.infer_ctxt().enter(|infcx| {
ExprUseVisitor::new(&mut delegate, &infcx, def_id, cx.param_env, cx.tables).walk_expr(body);
});
2 changes: 1 addition & 1 deletion clippy_lints/src/missing_doc.rs
Original file line number Diff line number Diff line change
@@ -135,7 +135,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
hir::ItemKind::Fn(..) => {
// ignore main()
if it.ident.name == sym!(main) {
let def_id = cx.tcx.hir().local_def_id(it.hir_id);
let def_id = it.hir_id.owner;
let def_key = cx.tcx.hir().def_key(def_id);
if def_key.parent == Some(hir::def_id::CRATE_DEF_INDEX) {
return;
2 changes: 1 addition & 1 deletion clippy_lints/src/missing_inline.rs
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@ fn check_missing_inline_attrs(cx: &LateContext<'_, '_>, attrs: &[ast::Attribute]
}

fn is_executable(cx: &LateContext<'_, '_>) -> bool {
use rustc::session::config::CrateType;
use rustc_session::config::CrateType;

cx.tcx.sess.crate_types.get().iter().any(|t: &CrateType| match t {
CrateType::Executable => true,
4 changes: 2 additions & 2 deletions clippy_lints/src/new_without_default.rs
Original file line number Diff line number Diff line change
@@ -149,9 +149,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
if_chain! {
if let Some(ref impling_types) = self.impling_types;
if let Some(self_def) = cx.tcx.type_of(self_did).ty_adt_def();
if self_def.did.is_local();
if let Some(self_def_id) = self_def.did.as_local();
then {
let self_id = cx.tcx.hir().local_def_id_to_hir_id(self_def.did.to_local());
let self_id = cx.tcx.hir().local_def_id_to_hir_id(self_def_id);
if impling_types.contains(&self_id) {
return;
}
2 changes: 1 addition & 1 deletion clippy_lints/src/swap.rs
Original file line number Diff line number Diff line change
@@ -99,7 +99,7 @@ fn check_manual_swap(cx: &LateContext<'_, '_>, block: &Block<'_>) {
then {
if let ExprKind::Field(ref lhs1, _) = lhs1.kind {
if let ExprKind::Field(ref lhs2, _) = lhs2.kind {
if lhs1.hir_id.owner_def_id() == lhs2.hir_id.owner_def_id() {
if lhs1.hir_id.owner == lhs2.hir_id.owner {
return;
}
}
2 changes: 1 addition & 1 deletion clippy_lints/src/trivially_copy_pass_by_ref.rs
Original file line number Diff line number Diff line change
@@ -3,13 +3,13 @@ use std::cmp;
use crate::utils::{is_copy, is_self_ty, snippet, span_lint_and_sugg};
use if_chain::if_chain;
use matches::matches;
use rustc::session::config::Config as SessionConfig;
use rustc::ty;
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_hir::intravisit::FnKind;
use rustc_hir::{Body, FnDecl, HirId, ItemKind, MutTy, Mutability, Node};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::config::Config as SessionConfig;
use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::Span;
use rustc_target::abi::LayoutOf;
2 changes: 1 addition & 1 deletion clippy_lints/src/utils/attrs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc::session::Session;
use rustc_ast::ast;
use rustc_errors::Applicability;
use rustc_session::Session;
use std::str::FromStr;

/// Deprecation status of attributes known by Clippy.
2 changes: 1 addition & 1 deletion clippy_lints/src/utils/author.rs
Original file line number Diff line number Diff line change
@@ -3,14 +3,14 @@

use crate::utils::{get_attr, higher};
use rustc::hir::map::Map;
use rustc::session::Session;
use rustc_ast::ast::{Attribute, LitFloatType, LitKind};
use rustc_ast::walk_list;
use rustc_data_structures::fx::FxHashMap;
use rustc_hir as hir;
use rustc_hir::intravisit::{NestedVisitorMap, Visitor};
use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, Pat, PatKind, QPath, Stmt, StmtKind, TyKind};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_session::Session;
use rustc_session::{declare_lint_pass, declare_tool_lint};

declare_clippy_lint! {
2 changes: 1 addition & 1 deletion clippy_lints/src/utils/inspector.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! checks for attributes

use crate::utils::get_attr;
use rustc::session::Session;
use rustc_ast::ast::Attribute;
use rustc_hir as hir;
use rustc_hir::print;
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_session::Session;
use rustc_session::{declare_lint_pass, declare_tool_lint};

declare_clippy_lint! {
4 changes: 2 additions & 2 deletions clippy_lints/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -297,8 +297,8 @@ pub fn qpath_res(cx: &LateContext<'_, '_>, qpath: &hir::QPath<'_>, id: hir::HirI
match qpath {
hir::QPath::Resolved(_, path) => path.res,
hir::QPath::TypeRelative(..) => {
if cx.tcx.has_typeck_tables(id.owner_def_id()) {
cx.tcx.typeck_tables_of(id.owner_def_id()).qpath_res(qpath, id)
if cx.tcx.has_typeck_tables(id.owner.to_def_id()) {
cx.tcx.typeck_tables_of(id.owner.to_def_id()).qpath_res(qpath, id)
} else {
Res::Err
}
4 changes: 2 additions & 2 deletions clippy_lints/src/utils/usage.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ use rustc_ast::ast;
use rustc_data_structures::fx::FxHashSet;
use rustc_hir::def::Res;
use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
use rustc_hir::{def_id, Expr, HirId, Path};
use rustc_hir::{Expr, HirId, Path};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::LateContext;
use rustc_span::symbol::Ident;
@@ -17,7 +17,7 @@ pub fn mutated_variables<'a, 'tcx>(expr: &'tcx Expr<'_>, cx: &'a LateContext<'a,
used_mutably: FxHashSet::default(),
skip: false,
};
let def_id = def_id::DefId::local(expr.hir_id.owner);
let def_id = expr.hir_id.owner.to_def_id();
cx.tcx.infer_ctxt().enter(|infcx| {
ExprUseVisitor::new(&mut delegate, &infcx, def_id, cx.param_env, cx.tables).walk_expr(expr);
});
2 changes: 1 addition & 1 deletion clippy_lints/src/wildcard_imports.rs
Original file line number Diff line number Diff line change
@@ -85,7 +85,7 @@ impl LateLintPass<'_, '_> for WildcardImports {
if let ItemKind::Use(use_path, UseKind::Glob) = &item.kind;
// don't lint prelude glob imports
if !use_path.segments.iter().last().map_or(false, |ps| ps.ident.as_str() == "prelude");
let used_imports = cx.tcx.names_imported_by_glob_use(item.hir_id.owner_def_id());
let used_imports = cx.tcx.names_imported_by_glob_use(item.hir_id.owner.to_def_id());
if !used_imports.is_empty(); // Already handled by `unused_imports`
then {
let mut applicability = Applicability::MachineApplicable;
2 changes: 1 addition & 1 deletion clippy_lints/src/write.rs
Original file line number Diff line number Diff line change
@@ -357,7 +357,7 @@ impl Write {
};
let tts = tts.clone();

let mut parser = parser::Parser::new(&cx.sess.parse_sess, tts, None, false, false, None);
let mut parser = parser::Parser::new(&cx.sess.parse_sess, tts, false, None);
let mut expr: Option<Expr> = None;
if is_write {
expr = match parser.parse_expr().map_err(|mut err| err.cancel()) {
8 changes: 4 additions & 4 deletions tests/ui/inefficient_to_string.stderr
Original file line number Diff line number Diff line change
@@ -35,21 +35,21 @@ LL | let _: String = rrrstring.to_string();
|
= help: `&&std::string::String` implements `ToString` through a slower blanket impl, but `std::string::String` has a fast specialization of `ToString`

error: calling `to_string` on `&&std::borrow::Cow<'_, str>`
error: calling `to_string` on `&&std::borrow::Cow<str>`
--> $DIR/inefficient_to_string.rs:29:21
|
LL | let _: String = rrcow.to_string();
| ^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(*rrcow).to_string()`
|
= help: `&std::borrow::Cow<'_, str>` implements `ToString` through a slower blanket impl, but `std::borrow::Cow<'_, str>` has a fast specialization of `ToString`
= help: `&std::borrow::Cow<str>` implements `ToString` through a slower blanket impl, but `std::borrow::Cow<str>` has a fast specialization of `ToString`

error: calling `to_string` on `&&&std::borrow::Cow<'_, str>`
error: calling `to_string` on `&&&std::borrow::Cow<str>`
--> $DIR/inefficient_to_string.rs:30:21
|
LL | let _: String = rrrcow.to_string();
| ^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(**rrrcow).to_string()`
|
= help: `&&std::borrow::Cow<'_, str>` implements `ToString` through a slower blanket impl, but `std::borrow::Cow<'_, str>` has a fast specialization of `ToString`
= help: `&&std::borrow::Cow<str>` implements `ToString` through a slower blanket impl, but `std::borrow::Cow<str>` has a fast specialization of `ToString`

error: aborting due to 6 previous errors

2 changes: 1 addition & 1 deletion tests/ui/transmute.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: transmute from a type (`&'a T`) to itself
error: transmute from a type (`&T`) to itself
--> $DIR/transmute.rs:19:20
|
LL | let _: &'a T = core::intrinsics::transmute(t);
28 changes: 27 additions & 1 deletion tests/ui/transmute_ptr_to_ptr.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
error: transmute from a type (`&T`) to itself
--> $DIR/transmute_ptr_to_ptr.rs:8:5
|
LL | std::mem::transmute::<&'a T, &'static T>(t)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::useless-transmute` implied by `-D warnings`

error: transmute from a type (`&T`) to itself
--> $DIR/transmute_ptr_to_ptr.rs:13:5
|
LL | std::mem::transmute::<&'a T, &'b T>(t)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: transmute from a pointer to a pointer
--> $DIR/transmute_ptr_to_ptr.rs:29:29
|
@@ -36,5 +50,17 @@ error: transmute from a reference to a reference
LL | let _: &GenericParam<f32> = std::mem::transmute(&GenericParam { t: 1u32 });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&GenericParam { t: 1u32 } as *const GenericParam<u32> as *const GenericParam<f32>)`

error: aborting due to 6 previous errors
error: transmute from a type (`&LifetimeParam`) to itself
--> $DIR/transmute_ptr_to_ptr.rs:50:47
|
LL | let _: &LifetimeParam<'static> = unsafe { std::mem::transmute(&lp) };
| ^^^^^^^^^^^^^^^^^^^^^^^^

error: transmute from a type (`&GenericParam<&LifetimeParam>`) to itself
--> $DIR/transmute_ptr_to_ptr.rs:51:62
|
LL | let _: &GenericParam<&LifetimeParam<'static>> = unsafe { std::mem::transmute(&GenericParam { t: &lp }) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 10 previous errors

4 changes: 2 additions & 2 deletions tests/ui/transmute_ptr_to_ref.stderr
Original file line number Diff line number Diff line change
@@ -42,13 +42,13 @@ error: transmute from a pointer type (`*mut U`) to a reference type (`&T`)
LL | let _: &T = std::mem::transmute(om);
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(om as *const T)`

error: transmute from a pointer type (`*const i32`) to a reference type (`&issue1231::Foo<'_, u8>`)
error: transmute from a pointer type (`*const i32`) to a reference type (`&issue1231::Foo<u8>`)
--> $DIR/transmute_ptr_to_ref.rs:32:32
|
LL | let _: &Foo<u8> = unsafe { std::mem::transmute::<_, &Foo<_>>(raw) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(raw as *const Foo<_>)`

error: transmute from a pointer type (`*const i32`) to a reference type (`&issue1231::Foo<'_, &u8>`)
error: transmute from a pointer type (`*const i32`) to a reference type (`&issue1231::Foo<&u8>`)
--> $DIR/transmute_ptr_to_ref.rs:34:33
|
LL | let _: &Foo<&u8> = unsafe { std::mem::transmute::<_, &Foo<&_>>(raw) };