From 39eb1482318ffd59461a88e27625a4cdcc9a5f47 Mon Sep 17 00:00:00 2001 From: Matt Fellenz Date: Tue, 28 Jun 2022 17:01:37 -0700 Subject: [PATCH 1/9] Follow C-RW-VALUE in std::io::Cursor example --- library/std/src/io/cursor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/io/cursor.rs b/library/std/src/io/cursor.rs index f3fbfc4478951..570c2a5f0cd39 100644 --- a/library/std/src/io/cursor.rs +++ b/library/std/src/io/cursor.rs @@ -34,7 +34,7 @@ use crate::io::{self, ErrorKind, IoSlice, IoSliceMut, ReadBuf, SeekFrom}; /// use std::fs::File; /// /// // a library function we've written -/// fn write_ten_bytes_at_end(writer: &mut W) -> io::Result<()> { +/// fn write_ten_bytes_at_end(mut writer: W) -> io::Result<()> { /// writer.seek(SeekFrom::End(-10))?; /// /// for i in 0..10 { From 22a456ad47f42179268165b009e8925a84d4c43f Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 29 May 2022 13:21:36 +0900 Subject: [PATCH 2/9] Stabilize `nonnull_slice_from_raw_parts` --- library/alloc/src/lib.rs | 1 - library/alloc/tests/lib.rs | 3 +-- library/core/src/ptr/non_null.rs | 13 +++++-------- library/std/src/lib.rs | 1 - 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 7fde8f670a231..1020c5f97a8d2 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -129,7 +129,6 @@ #![feature(maybe_uninit_slice)] #![feature(maybe_uninit_uninit_array)] #![cfg_attr(test, feature(new_uninit))] -#![feature(nonnull_slice_from_raw_parts)] #![feature(pattern)] #![feature(pointer_byte_offsets)] #![feature(provide_any)] diff --git a/library/alloc/tests/lib.rs b/library/alloc/tests/lib.rs index f30ebd77e2466..4811fedfb96b0 100644 --- a/library/alloc/tests/lib.rs +++ b/library/alloc/tests/lib.rs @@ -8,7 +8,7 @@ #![feature(const_cow_is_borrowed)] #![feature(const_heap)] #![feature(const_mut_refs)] -#![feature(const_nonnull_slice_from_raw_parts)] +#![feature(const_slice_from_raw_parts_mut)] #![feature(const_ptr_write)] #![feature(const_try)] #![feature(core_intrinsics)] @@ -36,7 +36,6 @@ #![feature(const_default_impls)] #![feature(const_trait_impl)] #![feature(const_str_from_utf8)] -#![feature(nonnull_slice_from_raw_parts)] #![feature(panic_update_hook)] #![feature(pointer_is_aligned)] #![feature(slice_flatten)] diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index f3ef094cbccc5..4814ccfd10ffd 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -467,8 +467,6 @@ impl NonNull<[T]> { /// # Examples /// /// ```rust - /// #![feature(nonnull_slice_from_raw_parts)] - /// /// use std::ptr::NonNull; /// /// // create a slice pointer when starting out with a pointer to the first element @@ -480,8 +478,8 @@ impl NonNull<[T]> { /// /// (Note that this example artificially demonstrates a use of this method, /// but `let slice = NonNull::from(&x[..]);` would be a better way to write code like this.) - #[unstable(feature = "nonnull_slice_from_raw_parts", issue = "71941")] - #[rustc_const_unstable(feature = "const_nonnull_slice_from_raw_parts", issue = "71941")] + #[stable(feature = "nonnull_slice_from_raw_parts", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_unstable(feature = "const_slice_from_raw_parts_mut", issue = "67456")] #[must_use] #[inline] pub const fn slice_from_raw_parts(data: NonNull, len: usize) -> Self { @@ -499,7 +497,6 @@ impl NonNull<[T]> { /// # Examples /// /// ```rust - /// #![feature(nonnull_slice_from_raw_parts)] /// use std::ptr::NonNull; /// /// let slice: NonNull<[i8]> = NonNull::slice_from_raw_parts(NonNull::dangling(), 3); @@ -519,7 +516,7 @@ impl NonNull<[T]> { /// # Examples /// /// ```rust - /// #![feature(slice_ptr_get, nonnull_slice_from_raw_parts)] + /// #![feature(slice_ptr_get)] /// use std::ptr::NonNull; /// /// let slice: NonNull<[i8]> = NonNull::slice_from_raw_parts(NonNull::dangling(), 3); @@ -539,7 +536,7 @@ impl NonNull<[T]> { /// # Examples /// /// ```rust - /// #![feature(slice_ptr_get, nonnull_slice_from_raw_parts)] + /// #![feature(slice_ptr_get)] /// use std::ptr::NonNull; /// /// let slice: NonNull<[i8]> = NonNull::slice_from_raw_parts(NonNull::dangling(), 3); @@ -673,7 +670,7 @@ impl NonNull<[T]> { /// # Examples /// /// ``` - /// #![feature(slice_ptr_get, nonnull_slice_from_raw_parts)] + /// #![feature(slice_ptr_get)] /// use std::ptr::NonNull; /// /// let x = &mut [1, 2, 4]; diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 64b62fd3bba4f..439fd93cb9762 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -294,7 +294,6 @@ #![feature(is_some_with)] #![feature(maybe_uninit_slice)] #![feature(maybe_uninit_write_slice)] -#![feature(nonnull_slice_from_raw_parts)] #![feature(panic_can_unwind)] #![feature(panic_info_message)] #![feature(panic_internals)] From 5e49f099a9a6a4bf9776315e19b58b09fb159f87 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 12 Mar 2023 10:10:12 +0000 Subject: [PATCH 3/9] Use an IndexVec to debug fingerprints. --- compiler/rustc_query_system/src/dep_graph/graph.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs index 3dbcc4d2e8aab..6c73135eb6a80 100644 --- a/compiler/rustc_query_system/src/dep_graph/graph.rs +++ b/compiler/rustc_query_system/src/dep_graph/graph.rs @@ -1053,7 +1053,7 @@ pub(super) struct CurrentDepGraph { /// This is used to verify that fingerprints do not change between the creation of a node /// and its recomputation. #[cfg(debug_assertions)] - fingerprints: Lock, Fingerprint>>, + fingerprints: Lock>>, /// Used to trap when a specific edge is added to the graph. /// This is used for debug purposes and is only active with `debug_assertions`. @@ -1139,7 +1139,7 @@ impl CurrentDepGraph { #[cfg(debug_assertions)] forbidden_edge, #[cfg(debug_assertions)] - fingerprints: Lock::new(Default::default()), + fingerprints: Lock::new(IndexVec::from_elem_n(None, new_node_count_estimate)), total_read_count: AtomicU64::new(0), total_duplicate_read_count: AtomicU64::new(0), node_intern_event_id, @@ -1151,14 +1151,8 @@ impl CurrentDepGraph { if let Some(forbidden_edge) = &self.forbidden_edge { forbidden_edge.index_to_node.lock().insert(dep_node_index, key); } - match self.fingerprints.lock().entry(key) { - Entry::Vacant(v) => { - v.insert(fingerprint); - } - Entry::Occupied(o) => { - assert_eq!(*o.get(), fingerprint, "Unstable fingerprints for {:?}", key); - } - } + let previous = *self.fingerprints.lock().get_or_insert_with(dep_node_index, || fingerprint); + assert_eq!(previous, fingerprint, "Unstable fingerprints for {:?}", key); } /// Writes the node to the current dep-graph and allocates a `DepNodeIndex` for it. From 08f3deb3d5a2164d8a601d37c87f2453b2f09eed Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Sat, 25 Mar 2023 22:27:24 +0100 Subject: [PATCH 4/9] fix type suggestions in match arms --- .../rustc_infer/src/infer/error_reporting/mod.rs | 3 ++- tests/ui/inference/char-as-str-single.fixed | 9 +++++++++ tests/ui/inference/char-as-str-single.rs | 9 +++++++++ tests/ui/inference/char-as-str-single.stderr | 15 ++++++++++++++- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index fd16363a1db01..75c3d9f641dda 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -1942,7 +1942,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { escaped } let mut err = struct_span_err!(self.tcx.sess, span, E0308, "{}", failure_str); - if let Some((expected, found)) = trace.values.ty() { + let values = self.resolve_vars_if_possible(trace.values); + if let Some((expected, found)) = values.ty() { match (expected.kind(), found.kind()) { (ty::Tuple(_), ty::Tuple(_)) => {} // If a tuple of length one was expected and the found expression has diff --git a/tests/ui/inference/char-as-str-single.fixed b/tests/ui/inference/char-as-str-single.fixed index bab1854dc5173..1621a279f03ff 100644 --- a/tests/ui/inference/char-as-str-single.fixed +++ b/tests/ui/inference/char-as-str-single.fixed @@ -10,3 +10,12 @@ fn main() { let _: char = '人'; //~ ERROR mismatched types let _: char = '\''; //~ ERROR mismatched types } + +// regression test for https://github.com/rust-lang/rust/issues/109586 +#[allow(dead_code)] +fn convert_c_to_str(c: char) { + match c { + 'A' => {} //~ ERROR mismatched types + _ => {} + } +} diff --git a/tests/ui/inference/char-as-str-single.rs b/tests/ui/inference/char-as-str-single.rs index 736920643b2c4..2903142f15991 100644 --- a/tests/ui/inference/char-as-str-single.rs +++ b/tests/ui/inference/char-as-str-single.rs @@ -10,3 +10,12 @@ fn main() { let _: char = "人"; //~ ERROR mismatched types let _: char = "'"; //~ ERROR mismatched types } + +// regression test for https://github.com/rust-lang/rust/issues/109586 +#[allow(dead_code)] +fn convert_c_to_str(c: char) { + match c { + "A" => {} //~ ERROR mismatched types + _ => {} + } +} diff --git a/tests/ui/inference/char-as-str-single.stderr b/tests/ui/inference/char-as-str-single.stderr index 3375ec6ac32ca..9149efe324071 100644 --- a/tests/ui/inference/char-as-str-single.stderr +++ b/tests/ui/inference/char-as-str-single.stderr @@ -37,6 +37,19 @@ help: if you meant to write a `char` literal, use single quotes LL | let _: char = '\''; | ~~~~ -error: aborting due to 3 previous errors +error[E0308]: mismatched types + --> $DIR/char-as-str-single.rs:18:9 + | +LL | match c { + | - this expression has type `char` +LL | "A" => {} + | ^^^ expected `char`, found `&str` + | +help: if you meant to write a `char` literal, use single quotes + | +LL | 'A' => {} + | ~~~ + +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0308`. From 28982a1e471e7dad82f3f1c1f0a9e9d15d3495d5 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 26 Mar 2023 17:50:02 +0200 Subject: [PATCH 5/9] Fix "Directly go to item in search if there is only one result" setting --- src/librustdoc/html/static/js/search.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 36ff20e299e1e..d764981c3cf5d 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -1888,11 +1888,7 @@ function initSearch(rawSearchIndex) { function showResults(results, go_to_first, filterCrates) { const search = searchState.outputElement(); if (go_to_first || (results.others.length === 1 - && getSettingValue("go-to-only-result") === "true" - // By default, the search DOM element is "empty" (meaning it has no children not - // text content). Once a search has been run, it won't be empty, even if you press - // ESC or empty the search input (which also "cancels" the search). - && (!search.firstChild || search.firstChild.innerText !== searchState.loadingText)) + && getSettingValue("go-to-only-result") === "true") ) { const elem = document.createElement("a"); elem.href = results.others[0].href; From bc9eec04b7e9713e7d0bde0ad4f8bfc8574082a6 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 26 Mar 2023 17:49:52 +0200 Subject: [PATCH 6/9] Add GUI test for "Directly go to item in search if there is only one result" setting --- .../setting-go-to-only-result.goml | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tests/rustdoc-gui/setting-go-to-only-result.goml diff --git a/tests/rustdoc-gui/setting-go-to-only-result.goml b/tests/rustdoc-gui/setting-go-to-only-result.goml new file mode 100644 index 0000000000000..3811011a64e6f --- /dev/null +++ b/tests/rustdoc-gui/setting-go-to-only-result.goml @@ -0,0 +1,63 @@ +// Checks that the setting "Directly go to item in search if there is only one result " is working as expected. + +define-function: ( + "check-setting", + (storage_value, setting_attribute_value), + block { + assert-local-storage: {"rustdoc-go-to-only-result": |storage_value|} + click: "#settings-menu" + wait-for: "#settings" + assert-property: ("#go-to-only-result", {"checked": |setting_attribute_value|}) + } +) + +goto: "file://" + |DOC_PATH| + "/lib2/index.html" + +call-function: ("check-setting", { + "storage_value": null, + "setting_attribute_value": "false", +}) + +// By default, the search doesn't automatically go to the page if there is only one result. +goto: "file://" + |DOC_PATH| + "/lib2/index.html?search=HasALongTraitWithParams" +// It will timeout if the setting isn't working. +wait-for: "#search" +assert-document-property: ({"URL": "/lib2/index.html"}, CONTAINS) + +// Now we change its value. +click: "#settings-menu" +wait-for: "#settings" +click: "#go-to-only-result" +assert-local-storage: {"rustdoc-go-to-only-result": "true"} + +goto: "file://" + |DOC_PATH| + "/lib2/index.html" +// We enter it into the search. +write: (".search-input", "HasALongTraitWithParams") +wait-for-document-property: {"title": "HasALongTraitWithParams in lib2 - Rust"} +assert-document-property: ({"URL": "/lib2/struct.HasALongTraitWithParams.html"}, ENDS_WITH) + +// We try again to see if it goes to the only result +goto: "file://" + |DOC_PATH| + "/lib2/index.html?search=HasALongTraitWithParams" +wait-for-document-property: {"title": "HasALongTraitWithParams in lib2 - Rust"} +assert-document-property: ({"URL": "/lib2/struct.HasALongTraitWithParams.html"}, ENDS_WITH) + +// We check the settings +call-function: ("check-setting", { + "storage_value": "true", + "setting_attribute_value": "true", +}) + +// And now we re-disable the setting. +click: "#go-to-only-result" +assert-local-storage: {"rustdoc-go-to-only-result": "false"} + +goto: "file://" + |DOC_PATH| + "/lib2/index.html?search=HasALongTraitWithParams" +// It will timeout if the setting isn't working. +wait-for: "#search" +assert-document-property: ({"URL": "/lib2/index.html"}, CONTAINS) + +// And we check everything is back the way it was before. +call-function: ("check-setting", { + "storage_value": "false", + "setting_attribute_value": "false", +}) From b874502a2064fef93cb25aebf31b8ea1c5a41621 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 6 Oct 2022 16:45:16 +0000 Subject: [PATCH 7/9] Remove unnecessary raw pointer in __rust_start_panic arg It is no longer necessary as __rust_start_panic switched to the Rust abi. --- library/panic_abort/src/android.rs | 4 ++-- library/panic_abort/src/lib.rs | 2 +- library/panic_unwind/src/lib.rs | 4 ++-- library/std/src/panicking.rs | 15 +++++---------- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/library/panic_abort/src/android.rs b/library/panic_abort/src/android.rs index 0fd824f8a458d..20b5b6b514685 100644 --- a/library/panic_abort/src/android.rs +++ b/library/panic_abort/src/android.rs @@ -15,7 +15,7 @@ type SetAbortMessageType = unsafe extern "C" fn(*const libc::c_char) -> (); // // Weakly resolve the symbol for android_set_abort_message. This function is only available // for API >= 21. -pub(crate) unsafe fn android_set_abort_message(payload: *mut &mut dyn BoxMeUp) { +pub(crate) unsafe fn android_set_abort_message(payload: &mut dyn BoxMeUp) { let func_addr = libc::dlsym(libc::RTLD_DEFAULT, ANDROID_SET_ABORT_MESSAGE.as_ptr() as *const libc::c_char) as usize; @@ -23,7 +23,7 @@ pub(crate) unsafe fn android_set_abort_message(payload: *mut &mut dyn BoxMeUp) { return; } - let payload = (*payload).get(); + let payload = payload.get(); let msg = match payload.downcast_ref::<&'static str>() { Some(msg) => msg.as_bytes(), None => match payload.downcast_ref::() { diff --git a/library/panic_abort/src/lib.rs b/library/panic_abort/src/lib.rs index a3cebf99c5342..b193d79b0e1a8 100644 --- a/library/panic_abort/src/lib.rs +++ b/library/panic_abort/src/lib.rs @@ -29,7 +29,7 @@ pub unsafe extern "C" fn __rust_panic_cleanup(_: *mut u8) -> *mut (dyn Any + Sen // "Leak" the payload and shim to the relevant abort on the platform in question. #[rustc_std_internal_symbol] -pub unsafe fn __rust_start_panic(_payload: *mut &mut dyn BoxMeUp) -> u32 { +pub unsafe fn __rust_start_panic(_payload: &mut dyn BoxMeUp) -> u32 { // Android has the ability to attach a message as part of the abort. #[cfg(target_os = "android")] android::android_set_abort_message(_payload); diff --git a/library/panic_unwind/src/lib.rs b/library/panic_unwind/src/lib.rs index ea3c9a7a663c2..ce78ab82ef942 100644 --- a/library/panic_unwind/src/lib.rs +++ b/library/panic_unwind/src/lib.rs @@ -99,8 +99,8 @@ pub unsafe extern "C" fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any // Entry point for raising an exception, just delegates to the platform-specific // implementation. #[rustc_std_internal_symbol] -pub unsafe fn __rust_start_panic(payload: *mut &mut dyn BoxMeUp) -> u32 { - let payload = Box::from_raw((*payload).take_box()); +pub unsafe fn __rust_start_panic(payload: &mut dyn BoxMeUp) -> u32 { + let payload = Box::from_raw(payload.take_box()); imp::panic(payload) } diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index e59f32af77df8..e505466e535a0 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -46,12 +46,10 @@ extern "C" { fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any + Send + 'static); } -#[allow(improper_ctypes)] extern "Rust" { - /// `payload` is passed through another layer of raw pointers as `&mut dyn Trait` is not - /// FFI-safe. `BoxMeUp` lazily performs allocation only when needed (this avoids allocations - /// when using the "abort" panic runtime). - fn __rust_start_panic(payload: *mut &mut dyn BoxMeUp) -> u32; + /// `BoxMeUp` lazily performs allocation only when needed (this avoids + /// allocations when using the "abort" panic runtime). + fn __rust_start_panic(payload: &mut dyn BoxMeUp) -> u32; } /// This function is called by the panic runtime if FFI code catches a Rust @@ -738,10 +736,7 @@ pub fn rust_panic_without_hook(payload: Box) -> ! { /// yer breakpoints. #[inline(never)] #[cfg_attr(not(test), rustc_std_internal_symbol)] -fn rust_panic(mut msg: &mut dyn BoxMeUp) -> ! { - let code = unsafe { - let obj = &mut msg as *mut &mut dyn BoxMeUp; - __rust_start_panic(obj) - }; +fn rust_panic(msg: &mut dyn BoxMeUp) -> ! { + let code = unsafe { __rust_start_panic(msg) }; rtabort!("failed to initiate panic, error {code}") } From 72c917d4be2dfb53c01466335175ed69eba9b5ad Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sun, 26 Mar 2023 18:55:37 +0200 Subject: [PATCH 8/9] debuginfo: Get pointer size/align from tcx.data_layout instead of layout_of This avoids some type interning and a query execution. It also just makes the code simpler. --- compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index c1b3f34e5a6d4..e2a592d851a8c 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -176,15 +176,14 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>( return_if_di_node_created_in_meantime!(cx, unique_type_id); - let (thin_pointer_size, thin_pointer_align) = - cx.size_and_align_of(cx.tcx.mk_imm_ptr(cx.tcx.types.unit)); + let data_layout = &cx.tcx.data_layout; let ptr_type_debuginfo_name = compute_debuginfo_type_name(cx.tcx, ptr_type, true); match fat_pointer_kind(cx, pointee_type) { None => { // This is a thin pointer. Create a regular pointer type and give it the correct name. debug_assert_eq!( - (thin_pointer_size, thin_pointer_align), + (data_layout.pointer_size, data_layout.pointer_align.abi), cx.size_and_align_of(ptr_type), "ptr_type={}, pointee_type={}", ptr_type, @@ -195,8 +194,8 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>( llvm::LLVMRustDIBuilderCreatePointerType( DIB(cx), pointee_type_di_node, - thin_pointer_size.bits(), - thin_pointer_align.bits() as u32, + data_layout.pointer_size.bits(), + data_layout.pointer_align.abi.bits() as u32, 0, // Ignore DWARF address space. ptr_type_debuginfo_name.as_ptr().cast(), ptr_type_debuginfo_name.len(), From 1ce4b37900cf0c7f5e146b866b5a8fae2b93f9fc Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 26 Mar 2023 20:33:54 +0000 Subject: [PATCH 9/9] Don't elaborate non-obligations into obligations --- .../rustc_hir_analysis/src/astconv/mod.rs | 9 +-- .../rustc_hir_analysis/src/check/wfcheck.rs | 7 +- .../src/collect/item_bounds.rs | 11 +-- .../src/impl_wf_check/min_specialization.rs | 34 ++++---- compiler/rustc_hir_typeck/src/closure.rs | 10 +-- .../rustc_hir_typeck/src/method/confirm.rs | 8 +- compiler/rustc_infer/src/traits/util.rs | 78 ++++++++++--------- compiler/rustc_lint/src/unused.rs | 4 +- .../rustc_mir_transform/src/const_prop.rs | 2 +- .../src/const_prop_lint.rs | 2 +- .../src/solve/assembly.rs | 2 +- .../src/traits/auto_trait.rs | 3 +- .../src/traits/coherence.rs | 4 +- .../src/traits/error_reporting/ambiguity.rs | 6 +- .../src/traits/error_reporting/mod.rs | 4 +- .../rustc_trait_selection/src/traits/mod.rs | 6 +- .../src/traits/object_safety.rs | 42 +++++----- .../rustc_trait_selection/src/traits/wf.rs | 6 +- .../src/needless_pass_by_value.rs | 4 +- src/tools/clippy/clippy_utils/src/lib.rs | 1 - 20 files changed, 112 insertions(+), 131 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 6d9dfe9697c0c..4ab6bb5908bcd 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -1427,13 +1427,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { for (base_trait_ref, span, constness) in regular_traits_refs_spans { assert_eq!(constness, ty::BoundConstness::NotConst); - for obligation in traits::elaborate_trait_ref(tcx, base_trait_ref) { - debug!( - "conv_object_ty_poly_trait_ref: observing object predicate `{:?}`", - obligation.predicate - ); + for pred in traits::elaborate_trait_ref(tcx, base_trait_ref) { + debug!("conv_object_ty_poly_trait_ref: observing object predicate `{:?}`", pred); - let bound_predicate = obligation.predicate.kind(); + let bound_predicate = pred.kind(); match bound_predicate.skip_binder() { ty::PredicateKind::Clause(ty::Clause::Trait(pred)) => { let pred = bound_predicate.rebind(pred); diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 491bd04f346bd..c912a8a640d45 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1912,14 +1912,13 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> { // Check elaborated bounds. let implied_obligations = traits::elaborate_predicates_with_span(tcx, predicates_with_span); - for obligation in implied_obligations { + for (pred, obligation_span) in implied_obligations { // We lower empty bounds like `Vec:` as // `WellFormed(Vec)`, which will later get checked by // regular WF checking - if let ty::PredicateKind::WellFormed(..) = obligation.predicate.kind().skip_binder() { + if let ty::PredicateKind::WellFormed(..) = pred.kind().skip_binder() { continue; } - let pred = obligation.predicate; // Match the existing behavior. if pred.is_global() && !pred.has_late_bound_vars() { let pred = self.normalize(span, None, pred); @@ -1930,8 +1929,6 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> { if let Some(hir::Generics { predicates, .. }) = hir_node.and_then(|node| node.generics()) { - let obligation_span = obligation.cause.span(); - span = predicates .iter() // There seems to be no better way to find out which predicate we are in diff --git a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs index aa66d7bb5efc8..d2e45c28658bd 100644 --- a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs +++ b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs @@ -130,12 +130,9 @@ pub(super) fn item_bounds( tcx: TyCtxt<'_>, def_id: DefId, ) -> ty::EarlyBinder<&'_ ty::List>> { - let bounds = tcx.mk_predicates_from_iter( - util::elaborate_predicates( - tcx, - tcx.explicit_item_bounds(def_id).iter().map(|&(bound, _span)| bound), - ) - .map(|obligation| obligation.predicate), - ); + let bounds = tcx.mk_predicates_from_iter(util::elaborate_predicates( + tcx, + tcx.explicit_item_bounds(def_id).iter().map(|&(bound, _span)| bound), + )); ty::EarlyBinder(bounds) } diff --git a/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs b/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs index 7f1e4ccc9647b..dfa9e6148aab5 100644 --- a/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs +++ b/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs @@ -318,16 +318,8 @@ fn check_predicates<'tcx>( span: Span, ) { let instantiated = tcx.predicates_of(impl1_def_id).instantiate(tcx, impl1_substs); - let impl1_predicates: Vec<_> = traits::elaborate_predicates_with_span( - tcx, - std::iter::zip( - instantiated.predicates, - // Don't drop predicates (unsound!) because `spans` is too short - instantiated.spans.into_iter().chain(std::iter::repeat(span)), - ), - ) - .map(|obligation| (obligation.predicate, obligation.cause.span)) - .collect(); + let impl1_predicates: Vec<_> = + traits::elaborate_predicates_with_span(tcx, instantiated.into_iter()).collect(); let mut impl2_predicates = if impl2_node.is_from_trait() { // Always applicable traits have to be always applicable without any @@ -341,7 +333,6 @@ fn check_predicates<'tcx>( .predicates .into_iter(), ) - .map(|obligation| obligation.predicate) .collect() }; debug!(?impl1_predicates, ?impl2_predicates); @@ -361,12 +352,16 @@ fn check_predicates<'tcx>( // which is sound because we forbid impls like the following // // impl AlwaysApplicable for D { } - let always_applicable_traits = impl1_predicates.iter().copied().filter(|&(predicate, _)| { - matches!( - trait_predicate_kind(tcx, predicate), - Some(TraitSpecializationKind::AlwaysApplicable) - ) - }); + let always_applicable_traits = impl1_predicates + .iter() + .copied() + .filter(|&(predicate, _)| { + matches!( + trait_predicate_kind(tcx, predicate), + Some(TraitSpecializationKind::AlwaysApplicable) + ) + }) + .map(|(pred, _span)| pred); // Include the well-formed predicates of the type parameters of the impl. for arg in tcx.impl_trait_ref(impl1_def_id).unwrap().subst_identity().substs { @@ -380,10 +375,7 @@ fn check_predicates<'tcx>( traits::elaborate_obligations(tcx, obligations).map(|obligation| obligation.predicate), ) } - impl2_predicates.extend( - traits::elaborate_predicates_with_span(tcx, always_applicable_traits) - .map(|obligation| obligation.predicate), - ); + impl2_predicates.extend(traits::elaborate_predicates(tcx, always_applicable_traits)); for (predicate, span) in impl1_predicates { if !impl2_predicates.iter().any(|pred2| trait_predicates_eq(tcx, predicate, *pred2, span)) { diff --git a/compiler/rustc_hir_typeck/src/closure.rs b/compiler/rustc_hir_typeck/src/closure.rs index ec391ea80f48b..47a8b0801664f 100644 --- a/compiler/rustc_hir_typeck/src/closure.rs +++ b/compiler/rustc_hir_typeck/src/closure.rs @@ -204,15 +204,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut expected_sig = None; let mut expected_kind = None; - for obligation in traits::elaborate_predicates_with_span( + for (pred, span) in traits::elaborate_predicates_with_span( self.tcx, // Reverse the obligations here, since `elaborate_*` uses a stack, // and we want to keep inference generally in the same order of // the registered obligations. predicates.rev(), ) { - debug!(?obligation.predicate); - let bound_predicate = obligation.predicate.kind(); + debug!(?pred); + let bound_predicate = pred.kind(); // Given a Projection predicate, we can potentially infer // the complete signature. @@ -220,9 +220,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { && let ty::PredicateKind::Clause(ty::Clause::Projection(proj_predicate)) = bound_predicate.skip_binder() { let inferred_sig = self.normalize( - obligation.cause.span, + span, self.deduce_sig_from_projection( - Some(obligation.cause.span), + Some(span), bound_predicate.rebind(proj_predicate), ), ); diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs index a0aa43deadcfd..2762e778591ee 100644 --- a/compiler/rustc_hir_typeck/src/method/confirm.rs +++ b/compiler/rustc_hir_typeck/src/method/confirm.rs @@ -576,17 +576,13 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { traits::elaborate_predicates(self.tcx, predicates.predicates.iter().copied()) // We don't care about regions here. - .filter_map(|obligation| match obligation.predicate.kind().skip_binder() { + .filter_map(|pred| match pred.kind().skip_binder() { ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)) if trait_pred.def_id() == sized_def_id => { let span = predicates .iter() - .find_map( - |(p, span)| { - if p == obligation.predicate { Some(span) } else { None } - }, - ) + .find_map(|(p, span)| if p == pred { Some(span) } else { None }) .unwrap_or(rustc_span::DUMMY_SP); Some((trait_pred, span)) } diff --git a/compiler/rustc_infer/src/traits/util.rs b/compiler/rustc_infer/src/traits/util.rs index 0d2faeba5fc0f..f3797499866ac 100644 --- a/compiler/rustc_infer/src/traits/util.rs +++ b/compiler/rustc_infer/src/traits/util.rs @@ -74,44 +74,58 @@ pub struct Elaborator<'tcx> { pub fn elaborate_trait_ref<'tcx>( tcx: TyCtxt<'tcx>, trait_ref: ty::PolyTraitRef<'tcx>, -) -> Elaborator<'tcx> { +) -> impl Iterator> { elaborate_predicates(tcx, std::iter::once(trait_ref.without_const().to_predicate(tcx))) } pub fn elaborate_trait_refs<'tcx>( tcx: TyCtxt<'tcx>, trait_refs: impl Iterator>, -) -> Elaborator<'tcx> { - let predicates = trait_refs.map(|trait_ref| trait_ref.without_const().to_predicate(tcx)); +) -> impl Iterator> { + let predicates = trait_refs.map(move |trait_ref| trait_ref.without_const().to_predicate(tcx)); elaborate_predicates(tcx, predicates) } pub fn elaborate_predicates<'tcx>( tcx: TyCtxt<'tcx>, predicates: impl Iterator>, -) -> Elaborator<'tcx> { - let obligations = predicates - .map(|predicate| { - predicate_obligation(predicate, ty::ParamEnv::empty(), ObligationCause::dummy()) - }) - .collect(); - elaborate_obligations(tcx, obligations) +) -> impl Iterator> { + elaborate_obligations( + tcx, + predicates + .map(|predicate| { + Obligation::new( + tcx, + // We'll dump the cause/param-env later + ObligationCause::dummy(), + ty::ParamEnv::empty(), + predicate, + ) + }) + .collect(), + ) + .map(|obl| obl.predicate) } pub fn elaborate_predicates_with_span<'tcx>( tcx: TyCtxt<'tcx>, predicates: impl Iterator, Span)>, -) -> Elaborator<'tcx> { - let obligations = predicates - .map(|(predicate, span)| { - predicate_obligation( - predicate, - ty::ParamEnv::empty(), - ObligationCause::dummy_with_span(span), - ) - }) - .collect(); - elaborate_obligations(tcx, obligations) +) -> impl Iterator, Span)> { + elaborate_obligations( + tcx, + predicates + .map(|(predicate, span)| { + Obligation::new( + tcx, + // We'll dump the cause/param-env later + ObligationCause::dummy_with_span(span), + ty::ParamEnv::empty(), + predicate, + ) + }) + .collect(), + ) + .map(|obl| (obl.predicate, obl.cause.span)) } pub fn elaborate_obligations<'tcx>( @@ -141,10 +155,6 @@ impl<'tcx> Elaborator<'tcx> { self.stack.extend(obligations.into_iter().filter(|o| self.visited.insert(o.predicate))); } - pub fn filter_to_traits(self) -> FilterToTraits { - FilterToTraits::new(self) - } - fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) { let tcx = self.visited.tcx; @@ -325,20 +335,18 @@ impl<'tcx> Iterator for Elaborator<'tcx> { // Supertrait iterator /////////////////////////////////////////////////////////////////////////// -pub type Supertraits<'tcx> = FilterToTraits>; - pub fn supertraits<'tcx>( tcx: TyCtxt<'tcx>, trait_ref: ty::PolyTraitRef<'tcx>, -) -> Supertraits<'tcx> { - elaborate_trait_ref(tcx, trait_ref).filter_to_traits() +) -> impl Iterator> { + FilterToTraits::new(elaborate_trait_ref(tcx, trait_ref)) } pub fn transitive_bounds<'tcx>( tcx: TyCtxt<'tcx>, - bounds: impl Iterator>, -) -> Supertraits<'tcx> { - elaborate_trait_refs(tcx, bounds).filter_to_traits() + trait_refs: impl Iterator>, +) -> impl Iterator> { + FilterToTraits::new(elaborate_trait_refs(tcx, trait_refs)) } /// A specialized variant of `elaborate_trait_refs` that only elaborates trait references that may @@ -393,12 +401,12 @@ impl FilterToTraits { } } -impl<'tcx, I: Iterator>> Iterator for FilterToTraits { +impl<'tcx, I: Iterator>> Iterator for FilterToTraits { type Item = ty::PolyTraitRef<'tcx>; fn next(&mut self) -> Option> { - while let Some(obligation) = self.base_iterator.next() { - if let Some(data) = obligation.predicate.to_opt_poly_trait_pred() { + while let Some(pred) = self.base_iterator.next() { + if let Some(data) = pred.to_opt_poly_trait_pred() { return Some(data.map_bound(|t| t.trait_ref)); } } diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index faca61fc29bf9..42e59f92840e0 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -258,11 +258,11 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { cx.tcx, cx.tcx.explicit_item_bounds(def).iter().cloned(), ) - .find_map(|obligation| { + .find_map(|(pred, _span)| { // We only look at the `DefId`, so it is safe to skip the binder here. if let ty::PredicateKind::Clause(ty::Clause::Trait( ref poly_trait_predicate, - )) = obligation.predicate.kind().skip_binder() + )) = pred.kind().skip_binder() { let def_id = poly_trait_predicate.trait_ref.def_id; diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index c1cf6ee0f9ec1..e7075d5e79120 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -117,7 +117,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp { .filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None }); if traits::impossible_predicates( tcx, - traits::elaborate_predicates(tcx, predicates).map(|o| o.predicate).collect(), + traits::elaborate_predicates(tcx, predicates).collect(), ) { trace!("ConstProp skipped for {:?}: found unsatisfiable predicates", def_id); return; diff --git a/compiler/rustc_mir_transform/src/const_prop_lint.rs b/compiler/rustc_mir_transform/src/const_prop_lint.rs index 45bd98f39d2ba..60401b054922a 100644 --- a/compiler/rustc_mir_transform/src/const_prop_lint.rs +++ b/compiler/rustc_mir_transform/src/const_prop_lint.rs @@ -93,7 +93,7 @@ impl<'tcx> MirLint<'tcx> for ConstProp { .filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None }); if traits::impossible_predicates( tcx, - traits::elaborate_predicates(tcx, predicates).map(|o| o.predicate).collect(), + traits::elaborate_predicates(tcx, predicates).collect(), ) { trace!("ConstProp skipped for {:?}: found unsatisfiable predicates", def_id); return; diff --git a/compiler/rustc_trait_selection/src/solve/assembly.rs b/compiler/rustc_trait_selection/src/solve/assembly.rs index 995fec78c4076..b2658614fd3df 100644 --- a/compiler/rustc_trait_selection/src/solve/assembly.rs +++ b/compiler/rustc_trait_selection/src/solve/assembly.rs @@ -470,7 +470,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { for assumption in elaborate_predicates(tcx, bounds.iter().map(|bound| bound.with_self_ty(tcx, self_ty))) { - match G::consider_object_bound_candidate(self, goal, assumption.predicate) { + match G::consider_object_bound_candidate(self, goal, assumption) { Ok(result) => { candidates.push(Candidate { source: CandidateSource::BuiltinImpl, result }) } diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index 6b3a59b1ed545..878c502655cf6 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -349,8 +349,7 @@ impl<'tcx> AutoTraitFinder<'tcx> { let normalized_preds = elaborate_predicates( tcx, computed_preds.clone().chain(user_computed_preds.iter().cloned()), - ) - .map(|o| o.predicate); + ); new_env = ty::ParamEnv::new( tcx.mk_predicates_from_iter(normalized_preds), param_env.reveal(), diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 98e00e8223bbc..03ba125cf2b5f 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -367,8 +367,8 @@ fn negative_impl_exists<'tcx>( } // Try to prove a negative obligation exists for super predicates - for o in util::elaborate_predicates(infcx.tcx, iter::once(o.predicate)) { - if resolve_negative_obligation(infcx.fork(), &o, body_def_id) { + for pred in util::elaborate_predicates(infcx.tcx, iter::once(o.predicate)) { + if resolve_negative_obligation(infcx.fork(), &o.with(infcx.tcx, pred), body_def_id) { return true; } } diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/ambiguity.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/ambiguity.rs index 84045c4d0edea..672b3365ff4a9 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/ambiguity.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/ambiguity.rs @@ -82,15 +82,15 @@ pub fn recompute_applicable_impls<'tcx>( let predicates = tcx.predicates_of(obligation.cause.body_id.to_def_id()).instantiate_identity(tcx); - for obligation in elaborate_predicates_with_span(tcx, predicates.into_iter()) { - let kind = obligation.predicate.kind(); + for (pred, span) in elaborate_predicates_with_span(tcx, predicates.into_iter()) { + let kind = pred.kind(); if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)) = kind.skip_binder() && param_env_candidate_may_apply(kind.rebind(trait_pred)) { if kind.rebind(trait_pred.trait_ref) == ty::TraitRef::identity(tcx, trait_pred.def_id()) { ambiguities.push(Ambiguity::ParamEnv(tcx.def_span(trait_pred.def_id()))) } else { - ambiguities.push(Ambiguity::ParamEnv(obligation.cause.span)) + ambiguities.push(Ambiguity::ParamEnv(span)) } } } diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 296fd1ed5248f..c19798213b70c 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -1624,8 +1624,8 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } }; - for obligation in super::elaborate_predicates(self.tcx, std::iter::once(cond)) { - let bound_predicate = obligation.predicate.kind(); + for pred in super::elaborate_predicates(self.tcx, std::iter::once(cond)) { + let bound_predicate = pred.kind(); if let ty::PredicateKind::Clause(ty::Clause::Trait(implication)) = bound_predicate.skip_binder() { diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index e89706067046a..8d831dca6e309 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -66,7 +66,7 @@ pub use self::util::{expand_trait_aliases, TraitAliasExpander}; pub use self::util::{get_vtable_index_of_object_method, impl_item_is_final, upcast_choices}; pub use self::util::{ supertrait_def_ids, supertraits, transitive_bounds, transitive_bounds_that_define_assoc_type, - SupertraitDefIds, Supertraits, + SupertraitDefIds, }; pub use self::chalk_fulfill::FulfillmentContext as ChalkFulfillmentContext; @@ -267,9 +267,7 @@ pub fn normalize_param_env_or_error<'tcx>( // and errors will get reported then; so outside of type inference we // can be sure that no errors should occur. let mut predicates: Vec<_> = - util::elaborate_predicates(tcx, unnormalized_env.caller_bounds().into_iter()) - .map(|obligation| obligation.predicate) - .collect(); + util::elaborate_predicates(tcx, unnormalized_env.caller_bounds().into_iter()).collect(); debug!("normalize_param_env_or_error: elaborated-predicates={:?}", predicates); diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index 5d2af5ff33c8f..dbf6b78572a19 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -379,26 +379,24 @@ fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool { // Search for a predicate like `Self : Sized` amongst the trait bounds. let predicates = tcx.predicates_of(def_id); let predicates = predicates.instantiate_identity(tcx).predicates; - elaborate_predicates(tcx, predicates.into_iter()).any(|obligation| { - match obligation.predicate.kind().skip_binder() { - ty::PredicateKind::Clause(ty::Clause::Trait(ref trait_pred)) => { - trait_pred.def_id() == sized_def_id && trait_pred.self_ty().is_param(0) - } - ty::PredicateKind::Clause(ty::Clause::Projection(..)) - | ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..)) - | ty::PredicateKind::Subtype(..) - | ty::PredicateKind::Coerce(..) - | ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..)) - | ty::PredicateKind::WellFormed(..) - | ty::PredicateKind::ObjectSafe(..) - | ty::PredicateKind::ClosureKind(..) - | ty::PredicateKind::Clause(ty::Clause::TypeOutlives(..)) - | ty::PredicateKind::ConstEvaluatable(..) - | ty::PredicateKind::ConstEquate(..) - | ty::PredicateKind::AliasRelate(..) - | ty::PredicateKind::Ambiguous - | ty::PredicateKind::TypeWellFormedFromEnv(..) => false, + elaborate_predicates(tcx, predicates.into_iter()).any(|pred| match pred.kind().skip_binder() { + ty::PredicateKind::Clause(ty::Clause::Trait(ref trait_pred)) => { + trait_pred.def_id() == sized_def_id && trait_pred.self_ty().is_param(0) } + ty::PredicateKind::Clause(ty::Clause::Projection(..)) + | ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..)) + | ty::PredicateKind::Subtype(..) + | ty::PredicateKind::Coerce(..) + | ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..)) + | ty::PredicateKind::WellFormed(..) + | ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::Clause(ty::Clause::TypeOutlives(..)) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) + | ty::PredicateKind::AliasRelate(..) + | ty::PredicateKind::Ambiguous + | ty::PredicateKind::TypeWellFormedFromEnv(..) => false, }) } @@ -669,9 +667,9 @@ fn object_ty_for_trait<'tcx>( debug!(?trait_predicate); let mut elaborated_predicates: Vec<_> = elaborate_trait_ref(tcx, trait_ref) - .filter_map(|obligation| { - debug!(?obligation); - let pred = obligation.predicate.to_opt_poly_projection_pred()?; + .filter_map(|pred| { + debug!(?pred); + let pred = pred.to_opt_poly_projection_pred()?; Some(pred.map_bound(|p| { ty::ExistentialPredicate::Projection(ty::ExistentialProjection::erase_self_ty( tcx, p, diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index ec5bd982a3c98..156674e33c334 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -921,9 +921,9 @@ pub(crate) fn required_region_bounds<'tcx>( assert!(!erased_self_ty.has_escaping_bound_vars()); traits::elaborate_predicates(tcx, predicates) - .filter_map(|obligation| { - debug!(?obligation); - match obligation.predicate.kind().skip_binder() { + .filter_map(|pred| { + debug!(?pred); + match pred.kind().skip_binder() { ty::PredicateKind::Clause(ty::Clause::Projection(..)) | ty::PredicateKind::Clause(ty::Clause::Trait(..)) | ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..)) diff --git a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs index 1ab81aee7b8d5..327e090d38be8 100644 --- a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs +++ b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs @@ -124,9 +124,9 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds().iter()) .filter(|p| !p.is_global()) - .filter_map(|obligation| { + .filter_map(|pred| { // Note that we do not want to deal with qualified predicates here. - match obligation.predicate.kind().no_bound_vars() { + match pred.kind().no_bound_vars() { Some(ty::PredicateKind::Clause(ty::Clause::Trait(pred))) if pred.def_id() != sized_trait => { Some(pred) }, diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index 29830557a4454..fd06c0b86775a 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -2106,7 +2106,6 @@ pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_>, did: DefId) -> bool { traits::impossible_predicates( cx.tcx, traits::elaborate_predicates(cx.tcx, predicates) - .map(|o| o.predicate) .collect::>(), ) }