Skip to content

Rustup #5691

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 10 commits into from
Jun 7, 2020
3 changes: 2 additions & 1 deletion .github/workflows/clippy_bors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ jobs:
matrix:
integration:
- 'rust-lang/cargo'
- 'rust-lang/rls'
# FIXME: re-enable once fmt_macros is renamed in RLS
# - 'rust-lang/rls'
- 'rust-lang/chalk'
- 'rust-lang/rustfmt'
- 'Marwes/combine'
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/future_not_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FutureNotSend {
let trait_ref = trait_pred.to_poly_trait_ref();
db.note(&*format!(
"`{}` doesn't implement `{}`",
trait_ref.self_ty(),
trait_ref.skip_binder().self_ty(),
trait_ref.print_only_trait_path(),
));
}
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
// FIXME: switch to something more ergonomic here, once available.
// (Currently there is no way to opt into sysroot crates without `extern crate`.)
#[allow(unused_extern_crates)]
extern crate fmt_macros;
#[allow(unused_extern_crates)]
extern crate rustc_ast;
#[allow(unused_extern_crates)]
extern crate rustc_ast_pretty;
Expand Down Expand Up @@ -48,6 +46,8 @@ extern crate rustc_mir;
#[allow(unused_extern_crates)]
extern crate rustc_parse;
#[allow(unused_extern_crates)]
extern crate rustc_parse_format;
#[allow(unused_extern_crates)]
extern crate rustc_session;
#[allow(unused_extern_crates)]
extern crate rustc_span;
Expand Down
5 changes: 5 additions & 0 deletions clippy_lints/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ pub fn implements_trait<'a, '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;
}
let ty = cx.tcx.erase_regions(&ty);
let ty_params = cx.tcx.mk_substs(ty_params.iter());
cx.tcx.type_implements_trait((trait_id, ty, ty_params, cx.param_env))
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ impl Write {
tts: &TokenStream,
is_write: bool,
) -> (Option<StrLit>, Option<Expr>) {
use fmt_macros::{
use rustc_parse_format::{
AlignUnknown, ArgumentImplicitlyIs, ArgumentIs, ArgumentNamed, CountImplied, FormatSpec, ParseMode, Parser,
Piece,
};
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/or_fun_call.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn or_fun_call() {
with_enum.unwrap_or(Enum::A(5));

let with_const_fn = Some(Duration::from_secs(1));
with_const_fn.unwrap_or(Duration::from_secs(5));
with_const_fn.unwrap_or_else(|| Duration::from_secs(5));

let with_constructor = Some(vec![1]);
with_constructor.unwrap_or_else(make);
Expand Down Expand Up @@ -94,7 +94,7 @@ fn test_or_with_ctors() {

let b = "b".to_string();
let _ = Some(Bar("a".to_string(), Duration::from_secs(1)))
.or(Some(Bar(b, Duration::from_secs(2))));
.or_else(|| Some(Bar(b, Duration::from_secs(2))));

let vec = vec!["foo"];
let _ = opt.ok_or(vec.len());
Expand Down
18 changes: 15 additions & 3 deletions tests/ui/or_fun_call.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
error: use of `unwrap_or` followed by a function call
--> $DIR/or_fun_call.rs:32:19
|
LL | with_const_fn.unwrap_or(Duration::from_secs(5));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| Duration::from_secs(5))`
|
= note: `-D clippy::or-fun-call` implied by `-D warnings`

error: use of `unwrap_or` followed by a function call
--> $DIR/or_fun_call.rs:35:22
|
LL | with_constructor.unwrap_or(make());
| ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(make)`
|
= note: `-D clippy::or-fun-call` implied by `-D warnings`

error: use of `unwrap_or` followed by a call to `new`
--> $DIR/or_fun_call.rs:38:5
Expand Down Expand Up @@ -78,5 +84,11 @@ error: use of `or` followed by a function call
LL | let _ = Some("a".to_string()).or(Some("b".to_string()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some("b".to_string()))`

error: aborting due to 13 previous errors
error: use of `or` followed by a function call
--> $DIR/or_fun_call.rs:97:10
|
LL | .or(Some(Bar(b, Duration::from_secs(2))));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some(Bar(b, Duration::from_secs(2))))`

error: aborting due to 15 previous errors