diff --git a/src/liballoc/raw_vec.rs b/src/liballoc/raw_vec.rs index 56e284a12fa83..bc2dade52f6d1 100644 --- a/src/liballoc/raw_vec.rs +++ b/src/liballoc/raw_vec.rs @@ -9,7 +9,7 @@ use core::ptr::{NonNull, Unique}; use core::slice; use crate::alloc::{ - handle_alloc_error, AllocErr, + handle_alloc_error, AllocInit::{self, *}, AllocRef, Global, Layout, ReallocPlacement::{self, *}, @@ -211,13 +211,13 @@ impl RawVec { } } - /// Ensures that the buffer contains at least enough space to hold - /// `used_capacity + needed_extra_capacity` elements. If it doesn't already have - /// enough capacity, will reallocate enough space plus comfortable slack - /// space to get amortized `O(1)` behavior. Will limit this behavior - /// if it would needlessly cause itself to panic. + /// Ensures that the buffer contains at least enough space to hold `len + + /// additional` elements. If it doesn't already have enough capacity, will + /// reallocate enough space plus comfortable slack space to get amortized + /// `O(1)` behavior. Will limit this behavior if it would needlessly cause + /// itself to panic. /// - /// If `used_capacity` exceeds `self.capacity()`, this may fail to actually allocate + /// If `len` exceeds `self.capacity()`, this may fail to actually allocate /// the requested space. This is not really unsafe, but the unsafe /// code *you* write that relies on the behavior of this function may break. /// @@ -263,8 +263,8 @@ impl RawVec { /// # vector.push_all(&[1, 3, 5, 7, 9]); /// # } /// ``` - pub fn reserve(&mut self, used_capacity: usize, needed_extra_capacity: usize) { - match self.try_reserve(used_capacity, needed_extra_capacity) { + pub fn reserve(&mut self, len: usize, additional: usize) { + match self.try_reserve(len, additional) { Err(CapacityOverflow) => capacity_overflow(), Err(AllocError { layout, .. }) => handle_alloc_error(layout), Ok(()) => { /* yay */ } @@ -272,55 +272,23 @@ impl RawVec { } /// The same as `reserve`, but returns on errors instead of panicking or aborting. - pub fn try_reserve( - &mut self, - used_capacity: usize, - needed_extra_capacity: usize, - ) -> Result<(), TryReserveError> { - if self.needs_to_grow(used_capacity, needed_extra_capacity) { - self.grow_amortized(used_capacity, needed_extra_capacity, MayMove) + pub fn try_reserve(&mut self, len: usize, additional: usize) -> Result<(), TryReserveError> { + if self.needs_to_grow(len, additional) { + self.grow_amortized(len, additional) } else { Ok(()) } } - /// Attempts to ensure that the buffer contains at least enough space to hold - /// `used_capacity + needed_extra_capacity` elements. If it doesn't already have - /// enough capacity, will reallocate in place enough space plus comfortable slack - /// space to get amortized `O(1)` behavior. Will limit this behaviour - /// if it would needlessly cause itself to panic. + /// Ensures that the buffer contains at least enough space to hold `len + + /// additional` elements. If it doesn't already, will reallocate the + /// minimum possible amount of memory necessary. Generally this will be + /// exactly the amount of memory necessary, but in principle the allocator + /// is free to give back more than we asked for. /// - /// If `used_capacity` exceeds `self.capacity()`, this may fail to actually allocate - /// the requested space. This is not really unsafe, but the unsafe - /// code *you* write that relies on the behavior of this function may break. - /// - /// Returns `true` if the reallocation attempt has succeeded. - /// - /// # Panics - /// - /// * Panics if the requested capacity exceeds `usize::MAX` bytes. - /// * Panics on 32-bit platforms if the requested capacity exceeds - /// `isize::MAX` bytes. - pub fn reserve_in_place(&mut self, used_capacity: usize, needed_extra_capacity: usize) -> bool { - // This is more readable than putting this in one line: - // `!self.needs_to_grow(...) || self.grow(...).is_ok()` - if self.needs_to_grow(used_capacity, needed_extra_capacity) { - self.grow_amortized(used_capacity, needed_extra_capacity, InPlace).is_ok() - } else { - true - } - } - - /// Ensures that the buffer contains at least enough space to hold - /// `used_capacity + needed_extra_capacity` elements. If it doesn't already, - /// will reallocate the minimum possible amount of memory necessary. - /// Generally this will be exactly the amount of memory necessary, - /// but in principle the allocator is free to give back more than what - /// we asked for. - /// - /// If `used_capacity` exceeds `self.capacity()`, this may fail to actually allocate - /// the requested space. This is not really unsafe, but the unsafe - /// code *you* write that relies on the behavior of this function may break. + /// If `len` exceeds `self.capacity()`, this may fail to actually allocate + /// the requested space. This is not really unsafe, but the unsafe code + /// *you* write that relies on the behavior of this function may break. /// /// # Panics /// @@ -331,8 +299,8 @@ impl RawVec { /// # Aborts /// /// Aborts on OOM. - pub fn reserve_exact(&mut self, used_capacity: usize, needed_extra_capacity: usize) { - match self.try_reserve_exact(used_capacity, needed_extra_capacity) { + pub fn reserve_exact(&mut self, len: usize, additional: usize) { + match self.try_reserve_exact(len, additional) { Err(CapacityOverflow) => capacity_overflow(), Err(AllocError { layout, .. }) => handle_alloc_error(layout), Ok(()) => { /* yay */ } @@ -342,14 +310,10 @@ impl RawVec { /// The same as `reserve_exact`, but returns on errors instead of panicking or aborting. pub fn try_reserve_exact( &mut self, - used_capacity: usize, - needed_extra_capacity: usize, + len: usize, + additional: usize, ) -> Result<(), TryReserveError> { - if self.needs_to_grow(used_capacity, needed_extra_capacity) { - self.grow_exact(used_capacity, needed_extra_capacity) - } else { - Ok(()) - } + if self.needs_to_grow(len, additional) { self.grow_exact(len, additional) } else { Ok(()) } } /// Shrinks the allocation down to the specified amount. If the given amount @@ -374,8 +338,8 @@ impl RawVec { impl RawVec { /// Returns if the buffer needs to grow to fulfill the needed extra capacity. /// Mainly used to make inlining reserve-calls possible without inlining `grow`. - fn needs_to_grow(&self, used_capacity: usize, needed_extra_capacity: usize) -> bool { - needed_extra_capacity > self.capacity().wrapping_sub(used_capacity) + fn needs_to_grow(&self, len: usize, additional: usize) -> bool { + additional > self.capacity().wrapping_sub(len) } fn capacity_from_bytes(excess: usize) -> usize { @@ -395,14 +359,9 @@ impl RawVec { // so that all of the code that depends on `T` is within it, while as much // of the code that doesn't depend on `T` as possible is in functions that // are non-generic over `T`. - fn grow_amortized( - &mut self, - used_capacity: usize, - needed_extra_capacity: usize, - placement: ReallocPlacement, - ) -> Result<(), TryReserveError> { + fn grow_amortized(&mut self, len: usize, additional: usize) -> Result<(), TryReserveError> { // This is ensured by the calling contexts. - debug_assert!(needed_extra_capacity > 0); + debug_assert!(additional > 0); if mem::size_of::() == 0 { // Since we return a capacity of `usize::MAX` when `elem_size` is @@ -411,8 +370,7 @@ impl RawVec { } // Nothing we can really do about these checks, sadly. - let required_cap = - used_capacity.checked_add(needed_extra_capacity).ok_or(CapacityOverflow)?; + let required_cap = len.checked_add(additional).ok_or(CapacityOverflow)?; // This guarantees exponential growth. The doubling cannot overflow // because `cap <= isize::MAX` and the type of `cap` is `usize`. @@ -437,7 +395,7 @@ impl RawVec { let new_layout = Layout::array::(cap); // `finish_grow` is non-generic over `T`. - let memory = finish_grow(new_layout, placement, self.current_memory(), &mut self.alloc)?; + let memory = finish_grow(new_layout, self.current_memory(), &mut self.alloc)?; self.set_memory(memory); Ok(()) } @@ -445,22 +403,18 @@ impl RawVec { // The constraints on this method are much the same as those on // `grow_amortized`, but this method is usually instantiated less often so // it's less critical. - fn grow_exact( - &mut self, - used_capacity: usize, - needed_extra_capacity: usize, - ) -> Result<(), TryReserveError> { + fn grow_exact(&mut self, len: usize, additional: usize) -> Result<(), TryReserveError> { if mem::size_of::() == 0 { // Since we return a capacity of `usize::MAX` when the type size is // 0, getting to here necessarily means the `RawVec` is overfull. return Err(CapacityOverflow); } - let cap = used_capacity.checked_add(needed_extra_capacity).ok_or(CapacityOverflow)?; + let cap = len.checked_add(additional).ok_or(CapacityOverflow)?; let new_layout = Layout::array::(cap); // `finish_grow` is non-generic over `T`. - let memory = finish_grow(new_layout, MayMove, self.current_memory(), &mut self.alloc)?; + let memory = finish_grow(new_layout, self.current_memory(), &mut self.alloc)?; self.set_memory(memory); Ok(()) } @@ -494,7 +448,6 @@ impl RawVec { // much smaller than the number of `T` types.) fn finish_grow( new_layout: Result, - placement: ReallocPlacement, current_memory: Option<(NonNull, Layout)>, alloc: &mut A, ) -> Result @@ -508,12 +461,9 @@ where let memory = if let Some((ptr, old_layout)) = current_memory { debug_assert_eq!(old_layout.align(), new_layout.align()); - unsafe { alloc.grow(ptr, old_layout, new_layout.size(), placement, Uninitialized) } + unsafe { alloc.grow(ptr, old_layout, new_layout.size(), MayMove, Uninitialized) } } else { - match placement { - MayMove => alloc.alloc(new_layout, Uninitialized), - InPlace => Err(AllocErr), - } + alloc.alloc(new_layout, Uninitialized) } .map_err(|_| AllocError { layout: new_layout, non_exhaustive: () })?; diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 42fb1f8c737b3..79dde39c8074b 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -2965,12 +2965,12 @@ impl Drain<'_, T> { } /// Makes room for inserting more elements before the tail. - unsafe fn move_tail(&mut self, extra_capacity: usize) { + unsafe fn move_tail(&mut self, additional: usize) { let vec = self.vec.as_mut(); - let used_capacity = self.tail_start + self.tail_len; - vec.buf.reserve(used_capacity, extra_capacity); + let len = self.tail_start + self.tail_len; + vec.buf.reserve(len, additional); - let new_tail_start = self.tail_start + extra_capacity; + let new_tail_start = self.tail_start + additional; let src = vec.as_ptr().add(self.tail_start); let dst = vec.as_mut_ptr().add(new_tail_start); ptr::copy(src, dst, self.tail_len); diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index bbe80c26dcbf9..4da336f8e288d 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -146,18 +146,18 @@ impl TypedArena { } #[inline] - fn can_allocate(&self, len: usize) -> bool { - let available_capacity_bytes = self.end.get() as usize - self.ptr.get() as usize; - let at_least_bytes = len.checked_mul(mem::size_of::()).unwrap(); - available_capacity_bytes >= at_least_bytes + fn can_allocate(&self, additional: usize) -> bool { + let available_bytes = self.end.get() as usize - self.ptr.get() as usize; + let additional_bytes = additional.checked_mul(mem::size_of::()).unwrap(); + available_bytes >= additional_bytes } /// Ensures there's enough space in the current chunk to fit `len` objects. #[inline] - fn ensure_capacity(&self, len: usize) { - if !self.can_allocate(len) { - self.grow(len); - debug_assert!(self.can_allocate(len)); + fn ensure_capacity(&self, additional: usize) { + if !self.can_allocate(additional) { + self.grow(additional); + debug_assert!(self.can_allocate(additional)); } } @@ -214,36 +214,31 @@ impl TypedArena { /// Grows the arena. #[inline(never)] #[cold] - fn grow(&self, n: usize) { + fn grow(&self, additional: usize) { unsafe { - // We need the element size in to convert chunk sizes (ranging from + // We need the element size to convert chunk sizes (ranging from // PAGE to HUGE_PAGE bytes) to element counts. let elem_size = cmp::max(1, mem::size_of::()); let mut chunks = self.chunks.borrow_mut(); - let (chunk, mut new_capacity); + let mut new_cap; if let Some(last_chunk) = chunks.last_mut() { let used_bytes = self.ptr.get() as usize - last_chunk.start() as usize; - let currently_used_cap = used_bytes / mem::size_of::(); - last_chunk.entries = currently_used_cap; - if last_chunk.storage.reserve_in_place(currently_used_cap, n) { - self.end.set(last_chunk.end()); - return; - } else { - // If the previous chunk's capacity is less than HUGE_PAGE - // bytes, then this chunk will be least double the previous - // chunk's size. - new_capacity = last_chunk.storage.capacity(); - if new_capacity < HUGE_PAGE / elem_size { - new_capacity = new_capacity.checked_mul(2).unwrap(); - } + last_chunk.entries = used_bytes / mem::size_of::(); + + // If the previous chunk's capacity is less than HUGE_PAGE + // bytes, then this chunk will be least double the previous + // chunk's size. + new_cap = last_chunk.storage.capacity(); + if new_cap < HUGE_PAGE / elem_size { + new_cap = new_cap.checked_mul(2).unwrap(); } } else { - new_capacity = PAGE / elem_size; + new_cap = PAGE / elem_size; } - // Also ensure that this chunk can fit `n`. - new_capacity = cmp::max(n, new_capacity); + // Also ensure that this chunk can fit `additional`. + new_cap = cmp::max(additional, new_cap); - chunk = TypedArenaChunk::::new(new_capacity); + let chunk = TypedArenaChunk::::new(new_cap); self.ptr.set(chunk.start()); self.end.set(chunk.end()); chunks.push(chunk); @@ -347,31 +342,28 @@ impl DroplessArena { #[inline(never)] #[cold] - fn grow(&self, needed_bytes: usize) { + fn grow(&self, additional: usize) { unsafe { let mut chunks = self.chunks.borrow_mut(); - let (chunk, mut new_capacity); + let mut new_cap; if let Some(last_chunk) = chunks.last_mut() { - let used_bytes = self.ptr.get() as usize - last_chunk.start() as usize; - if last_chunk.storage.reserve_in_place(used_bytes, needed_bytes) { - self.end.set(last_chunk.end()); - return; - } else { - // If the previous chunk's capacity is less than HUGE_PAGE - // bytes, then this chunk will be least double the previous - // chunk's size. - new_capacity = last_chunk.storage.capacity(); - if new_capacity < HUGE_PAGE { - new_capacity = new_capacity.checked_mul(2).unwrap(); - } + // There is no need to update `last_chunk.entries` because that + // field isn't used by `DroplessArena`. + + // If the previous chunk's capacity is less than HUGE_PAGE + // bytes, then this chunk will be least double the previous + // chunk's size. + new_cap = last_chunk.storage.capacity(); + if new_cap < HUGE_PAGE { + new_cap = new_cap.checked_mul(2).unwrap(); } } else { - new_capacity = PAGE; + new_cap = PAGE; } - // Also ensure that this chunk can fit `needed_bytes`. - new_capacity = cmp::max(needed_bytes, new_capacity); + // Also ensure that this chunk can fit `additional`. + new_cap = cmp::max(additional, new_cap); - chunk = TypedArenaChunk::::new(new_capacity); + let chunk = TypedArenaChunk::::new(new_cap); self.ptr.set(chunk.start()); self.end.set(chunk.end()); chunks.push(chunk); @@ -386,7 +378,7 @@ impl DroplessArena { self.align(align); let future_end = intrinsics::arith_offset(self.ptr.get(), bytes as isize); - if (future_end as *mut u8) >= self.end.get() { + if (future_end as *mut u8) > self.end.get() { self.grow(bytes); } diff --git a/src/libcore/mem/maybe_uninit.rs b/src/libcore/mem/maybe_uninit.rs index 01c97444ae3ae..499016545e967 100644 --- a/src/libcore/mem/maybe_uninit.rs +++ b/src/libcore/mem/maybe_uninit.rs @@ -214,7 +214,6 @@ use crate::mem::ManuallyDrop; /// remain `#[repr(transparent)]`. That said, `MaybeUninit` will *always* guarantee that it has /// the same size, alignment, and ABI as `T`; it's just that the way `MaybeUninit` implements that /// guarantee may evolve. -#[allow(missing_debug_implementations)] #[stable(feature = "maybe_uninit", since = "1.36.0")] // Lang item so we can wrap other types in it. This is useful for generators. #[lang = "maybe_uninit"] diff --git a/src/libcore/num/wrapping.rs b/src/libcore/num/wrapping.rs index 82fa6acfbd62a..bb648ba8c25de 100644 --- a/src/libcore/num/wrapping.rs +++ b/src/libcore/num/wrapping.rs @@ -337,14 +337,10 @@ Basic usage: #![feature(wrapping_int_impl)] use std::num::Wrapping; -assert_eq!(>::min_value(), ", -"Wrapping(", stringify!($t), "::min_value())); +assert_eq!(>::MIN, Wrapping(", stringify!($t), "::MIN)); ```"), #[unstable(feature = "wrapping_int_impl", issue = "32463")] - #[inline] - pub const fn min_value() -> Self { - Wrapping(<$t>::min_value()) - } + pub const MIN: Self = Self(<$t>::MIN); } doc_comment! { @@ -358,14 +354,10 @@ Basic usage: #![feature(wrapping_int_impl)] use std::num::Wrapping; -assert_eq!(>::max_value(), ", -"Wrapping(", stringify!($t), "::max_value())); +assert_eq!(>::MAX, Wrapping(", stringify!($t), "::MAX)); ```"), #[unstable(feature = "wrapping_int_impl", issue = "32463")] - #[inline] - pub const fn max_value() -> Self { - Wrapping(<$t>::max_value()) - } + pub const MAX: Self = Self(<$t>::MAX); } doc_comment! { diff --git a/src/librustc_error_codes/error_codes/E0637.md b/src/librustc_error_codes/error_codes/E0637.md index e114d3d0f94ae..d9068950bdfee 100644 --- a/src/librustc_error_codes/error_codes/E0637.md +++ b/src/librustc_error_codes/error_codes/E0637.md @@ -1,6 +1,7 @@ An underscore `_` character has been used as the identifier for a lifetime. -Erroneous example: +Erroneous code example: + ```compile_fail,E0106,E0637 fn longest<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str { //^^ `'_` is a reserved lifetime name @@ -11,6 +12,7 @@ fn longest<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str { } } ``` + `'_`, cannot be used as a lifetime identifier because it is a reserved for the anonymous lifetime. To fix this, use a lowercase letter such as 'a, or a series of lowercase letters such as `'foo`. For more information, see [the @@ -18,6 +20,7 @@ book][bk-no]. For more information on using the anonymous lifetime in rust nightly, see [the nightly book][bk-al]. Corrected example: + ``` fn longest<'a>(str1: &'a str, str2: &'a str) -> &'a str { if str1.len() > str2.len() { diff --git a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs index cfbea9ee0f196..e3846d8d73d60 100644 --- a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs +++ b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs @@ -1909,6 +1909,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { let self_ty = self.resolve_vars_if_possible(&trait_ref.self_ty()); + // Do not check on infer_types to avoid panic in evaluate_obligation. + if self_ty.has_infer_types() { + return; + } + let self_ty = self.tcx.erase_regions(&self_ty); + let impls_future = self.tcx.type_implements_trait(( future_trait, self_ty, diff --git a/src/librustc_trait_selection/traits/mod.rs b/src/librustc_trait_selection/traits/mod.rs index b45de72ab0262..958ba69a8262c 100644 --- a/src/librustc_trait_selection/traits/mod.rs +++ b/src/librustc_trait_selection/traits/mod.rs @@ -540,13 +540,6 @@ fn type_implements_trait<'tcx>( trait_def_id, ty, params, param_env ); - // Do not check on infer_types to avoid panic in evaluate_obligation. - if ty.has_infer_types() { - return false; - } - - let ty = tcx.erase_regions(&ty); - let trait_ref = ty::TraitRef { def_id: trait_def_id, substs: tcx.mk_substs_trait(ty, params) }; let obligation = Obligation { diff --git a/src/test/ui/proc-macro/auxiliary/test-macros.rs b/src/test/ui/proc-macro/auxiliary/test-macros.rs index 27efa44f98032..fb8016cd43896 100644 --- a/src/test/ui/proc-macro/auxiliary/test-macros.rs +++ b/src/test/ui/proc-macro/auxiliary/test-macros.rs @@ -108,5 +108,6 @@ pub fn print_attr(_: TokenStream, input: TokenStream) -> TokenStream { #[proc_macro_derive(Print, attributes(print_helper))] pub fn print_derive(input: TokenStream) -> TokenStream { - print_helper(input, "DERIVE") + print_helper(input, "DERIVE"); + TokenStream::new() } diff --git a/src/test/ui/proc-macro/dollar-crate.rs b/src/test/ui/proc-macro/dollar-crate.rs index aadd87ffaf203..5f2549376d1ba 100644 --- a/src/test/ui/proc-macro/dollar-crate.rs +++ b/src/test/ui/proc-macro/dollar-crate.rs @@ -1,3 +1,4 @@ +// check-pass // edition:2018 // aux-build:test-macros.rs // aux-build:dollar-crate-external.rs @@ -23,7 +24,7 @@ mod local { struct A($crate::S); #[derive(Print)] - struct D($crate::S); //~ ERROR the name `D` is defined multiple times + struct D($crate::S); }; } @@ -33,7 +34,7 @@ mod local { mod external { use crate::dollar_crate_external; - dollar_crate_external::external!(); //~ ERROR the name `D` is defined multiple times + dollar_crate_external::external!(); } fn main() {} diff --git a/src/test/ui/proc-macro/dollar-crate.stderr b/src/test/ui/proc-macro/dollar-crate.stderr deleted file mode 100644 index 465f242580dfb..0000000000000 --- a/src/test/ui/proc-macro/dollar-crate.stderr +++ /dev/null @@ -1,30 +0,0 @@ -error[E0428]: the name `D` is defined multiple times - --> $DIR/dollar-crate.rs:26:13 - | -LL | struct D($crate::S); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | `D` redefined here - | previous definition of the type `D` here -... -LL | local!(); - | --------- in this macro invocation - | - = note: `D` must be defined only once in the type namespace of this module - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0428]: the name `D` is defined multiple times - --> $DIR/dollar-crate.rs:36:5 - | -LL | dollar_crate_external::external!(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | `D` redefined here - | previous definition of the type `D` here - | - = note: `D` must be defined only once in the type namespace of this module - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0428`. diff --git a/src/test/ui/proc-macro/input-interpolated.rs b/src/test/ui/proc-macro/input-interpolated.rs new file mode 100644 index 0000000000000..b57ce99b13841 --- /dev/null +++ b/src/test/ui/proc-macro/input-interpolated.rs @@ -0,0 +1,25 @@ +// Check what token streams proc macros see when interpolated tokens are passed to them as input. + +// check-pass +// aux-build:test-macros.rs + +#[macro_use] +extern crate test_macros; + +macro_rules! pass_ident { + ($i:ident) => { + fn f() { + print_bang!($i); + } + + #[print_attr] + const $i: u8 = 0; + + #[derive(Print)] + struct $i {} + }; +} + +pass_ident!(A); + +fn main() {} diff --git a/src/test/ui/proc-macro/input-interpolated.stdout b/src/test/ui/proc-macro/input-interpolated.stdout new file mode 100644 index 0000000000000..7529db3bd06f8 --- /dev/null +++ b/src/test/ui/proc-macro/input-interpolated.stdout @@ -0,0 +1,69 @@ +PRINT-BANG INPUT (DISPLAY): A +PRINT-BANG RE-COLLECTED (DISPLAY): A +PRINT-BANG INPUT (DEBUG): TokenStream [ + Group { + delimiter: None, + stream: TokenStream [ + Ident { + ident: "A", + span: #0 bytes(402..403), + }, + ], + span: #3 bytes(269..271), + }, +] +PRINT-ATTR INPUT (DISPLAY): const A: u8 = 0; +PRINT-ATTR RE-COLLECTED (DISPLAY): const A : u8 = 0 ; +PRINT-ATTR INPUT (DEBUG): TokenStream [ + Ident { + ident: "const", + span: #0 bytes(0..0), + }, + Ident { + ident: "A", + span: #0 bytes(0..0), + }, + Punct { + ch: ':', + spacing: Alone, + span: #0 bytes(0..0), + }, + Ident { + ident: "u8", + span: #0 bytes(0..0), + }, + Punct { + ch: '=', + spacing: Alone, + span: #0 bytes(0..0), + }, + Literal { + kind: Integer, + symbol: "0", + suffix: None, + span: #0 bytes(0..0), + }, + Punct { + ch: ';', + spacing: Alone, + span: #0 bytes(0..0), + }, +] +PRINT-DERIVE INPUT (DISPLAY): struct A { +} +PRINT-DERIVE RE-COLLECTED (DISPLAY): struct A { } +PRINT-DERIVE INPUT (DEBUG): TokenStream [ + Ident { + ident: "struct", + span: #0 bytes(0..0), + }, + Ident { + ident: "A", + span: #0 bytes(0..0), + }, + Group { + delimiter: Brace, + stream: TokenStream [], + span: #0 bytes(0..0), + }, +] diff --git a/src/test/ui/suggestions/issue-72766.rs b/src/test/ui/suggestions/issue-72766.rs new file mode 100644 index 0000000000000..0448f0719589d --- /dev/null +++ b/src/test/ui/suggestions/issue-72766.rs @@ -0,0 +1,20 @@ +// edition:2018 +// compile-flags: -Cincremental=tmp/issue-72766 + +pub struct SadGirl; + +impl SadGirl { + pub async fn call(&self) -> Result<(), ()> { + Ok(()) + } +} + +async fn async_main() -> Result<(), ()> { + // should be `.call().await?` + SadGirl {}.call()?; //~ ERROR: the `?` operator can only be applied to values + Ok(()) +} + +fn main() { + let _ = async_main(); +} diff --git a/src/test/ui/suggestions/issue-72766.stderr b/src/test/ui/suggestions/issue-72766.stderr new file mode 100644 index 0000000000000..4290f3b4bf1aa --- /dev/null +++ b/src/test/ui/suggestions/issue-72766.stderr @@ -0,0 +1,15 @@ +error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try` + --> $DIR/issue-72766.rs:14:5 + | +LL | SadGirl {}.call()?; + | ^^^^^^^^^^^^^^^^^^ + | | + | the `?` operator cannot be applied to type `impl std::future::Future` + | help: consider using `.await` here: `SadGirl {}.call().await?` + | + = help: the trait `std::ops::Try` is not implemented for `impl std::future::Future` + = note: required by `std::ops::Try::into_result` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/tools/clippy/clippy_lints/src/utils/mod.rs b/src/tools/clippy/clippy_lints/src/utils/mod.rs index 6c1488664bf00..6dd8fef7e82da 100644 --- a/src/tools/clippy/clippy_lints/src/utils/mod.rs +++ b/src/tools/clippy/clippy_lints/src/utils/mod.rs @@ -323,6 +323,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)) }