diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index b786c52e6880f..324e04b198101 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -2718,13 +2718,12 @@ impl<'a> Parser<'a> { )); } this.expect_one_of(&[token::Comma], &[token::CloseDelim(Delimiter::Brace)]) - .map_err(|mut err| { - match (sm.span_to_lines(expr.span), sm.span_to_lines(arm_start_span)) { - (Ok(ref expr_lines), Ok(ref arm_start_lines)) - if arm_start_lines.lines[0].end_col - == expr_lines.lines[0].end_col - && expr_lines.lines.len() == 2 - && this.token == token::FatArrow => + .or_else(|mut err| { + if this.token == token::FatArrow { + if let Ok(expr_lines) = sm.span_to_lines(expr.span) + && let Ok(arm_start_lines) = sm.span_to_lines(arm_start_span) + && arm_start_lines.lines[0].end_col == expr_lines.lines[0].end_col + && expr_lines.lines.len() == 2 { // We check whether there's any trailing code in the parse span, // if there isn't, we very likely have the following: @@ -2743,15 +2742,41 @@ impl<'a> Parser<'a> { ",".to_owned(), Applicability::MachineApplicable, ); + return Err(err); } - _ => { - err.span_label( - arrow_span, - "while parsing the `match` arm starting here", - ); + } else { + // FIXME(compiler-errors): We could also recover `; PAT =>` here + + // Try to parse a following `PAT =>`, if successful + // then we should recover. + let mut snapshot = this.create_snapshot_for_diagnostic(); + let pattern_follows = snapshot + .parse_pat_allow_top_alt( + None, + RecoverComma::Yes, + RecoverColon::Yes, + CommaRecoveryMode::EitherTupleOrPipe, + ) + .map_err(|err| err.cancel()) + .is_ok(); + if pattern_follows && snapshot.check(&TokenKind::FatArrow) { + err.cancel(); + this.struct_span_err( + hi.shrink_to_hi(), + "expected `,` following `match` arm", + ) + .span_suggestion( + hi.shrink_to_hi(), + "missing a comma here to end this `match` arm", + ",".to_owned(), + Applicability::MachineApplicable, + ) + .emit(); + return Ok(true); } } - err + err.span_label(arrow_span, "while parsing the `match` arm starting here"); + Err(err) })?; } else { this.eat(&token::Comma); diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 6720399aacb07..48c3c467becc8 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -204,25 +204,7 @@ impl<'a> Parser<'a> { let mut def = || mem::replace(def, Defaultness::Final); let info = if self.eat_keyword(kw::Use) { - // USE ITEM - let tree = self.parse_use_tree()?; - - // If wildcard or glob-like brace syntax doesn't have `;`, - // the user may not know `*` or `{}` should be the last. - if let Err(mut e) = self.expect_semi() { - match tree.kind { - UseTreeKind::Glob => { - e.note("the wildcard token must be last on the path"); - } - UseTreeKind::Nested(..) => { - e.note("glob-like brace syntax must be last on the path"); - } - _ => (), - } - return Err(e); - } - - (Ident::empty(), ItemKind::Use(tree)) + self.parse_use_item()? } else if self.check_fn_front_matter(def_final) { // FUNCTION ITEM let (ident, sig, generics, body) = self.parse_fn(attrs, fn_parse_mode, lo, vis)?; @@ -288,7 +270,12 @@ impl<'a> Parser<'a> { } else if let IsMacroRulesItem::Yes { has_bang } = self.is_macro_rules_item() { // MACRO_RULES ITEM self.parse_item_macro_rules(vis, has_bang)? - } else if vis.kind.is_pub() && self.isnt_macro_invocation() { + } else if self.isnt_macro_invocation() + && (self.token.is_ident_named(Symbol::intern("import")) + || self.token.is_ident_named(Symbol::intern("using"))) + { + return self.recover_import_as_use(); + } else if self.isnt_macro_invocation() && vis.kind.is_pub() { self.recover_missing_kw_before_item()?; return Ok(None); } else if macros_allowed && self.check_path() { @@ -300,6 +287,48 @@ impl<'a> Parser<'a> { Ok(Some(info)) } + fn recover_import_as_use(&mut self) -> PResult<'a, Option<(Ident, ItemKind)>> { + let span = self.token.span; + let token_name = super::token_descr(&self.token); + let snapshot = self.create_snapshot_for_diagnostic(); + self.bump(); + match self.parse_use_item() { + Ok(u) => { + self.struct_span_err(span, format!("expected item, found {token_name}")) + .span_suggestion_short( + span, + "items are imported using the `use` keyword", + "use".to_owned(), + Applicability::MachineApplicable, + ) + .emit(); + Ok(Some(u)) + } + Err(e) => { + e.cancel(); + self.restore_snapshot(snapshot); + Ok(None) + } + } + } + + fn parse_use_item(&mut self) -> PResult<'a, (Ident, ItemKind)> { + let tree = self.parse_use_tree()?; + if let Err(mut e) = self.expect_semi() { + match tree.kind { + UseTreeKind::Glob => { + e.note("the wildcard token must be last on the path"); + } + UseTreeKind::Nested(..) => { + e.note("glob-like brace syntax must be last on the path"); + } + _ => (), + } + return Err(e); + } + Ok((Ident::empty(), ItemKind::Use(tree))) + } + /// When parsing a statement, would the start of a path be an item? pub(super) fn is_path_start_item(&mut self) -> bool { self.is_kw_followed_by_ident(kw::Union) // no: `union::b`, yes: `union U { .. }` diff --git a/compiler/rustc_trait_selection/src/traits/util.rs b/compiler/rustc_trait_selection/src/traits/util.rs index f2e31c068a0d3..3a00c41d90ae6 100644 --- a/compiler/rustc_trait_selection/src/traits/util.rs +++ b/compiler/rustc_trait_selection/src/traits/util.rs @@ -304,22 +304,24 @@ pub fn get_vtable_index_of_object_method<'tcx, N>( tcx: TyCtxt<'tcx>, object: &super::ImplSourceObjectData<'tcx, N>, method_def_id: DefId, -) -> usize { +) -> Option { let existential_trait_ref = object .upcast_trait_ref .map_bound(|trait_ref| ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref)); let existential_trait_ref = tcx.erase_regions(existential_trait_ref); + // Count number of methods preceding the one we are selecting and // add them to the total offset. - let index = tcx + if let Some(index) = tcx .own_existential_vtable_entries(existential_trait_ref) .iter() .copied() .position(|def_id| def_id == method_def_id) - .unwrap_or_else(|| { - bug!("get_vtable_index_of_object_method: {:?} was not found", method_def_id); - }); - object.vtable_base + index + { + Some(object.vtable_base + index) + } else { + None + } } pub fn closure_trait_ref_and_return_type<'tcx>( diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index 17eac2bb2c9e9..c78a5855edb82 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -347,11 +347,15 @@ fn resolve_associated_item<'tcx>( _ => None, }, traits::ImplSource::Object(ref data) => { - let index = traits::get_vtable_index_of_object_method(tcx, data, trait_item_id); - Some(Instance { - def: ty::InstanceDef::Virtual(trait_item_id, index), - substs: rcvr_substs, - }) + if let Some(index) = traits::get_vtable_index_of_object_method(tcx, data, trait_item_id) + { + Some(Instance { + def: ty::InstanceDef::Virtual(trait_item_id, index), + substs: rcvr_substs, + }) + } else { + None + } } traits::ImplSource::Builtin(..) => { if Some(trait_ref.def_id) == tcx.lang_items().clone_trait() { diff --git a/library/alloc/tests/lib.rs b/library/alloc/tests/lib.rs index ffc7944ec7e1b..367cdcdcc061c 100644 --- a/library/alloc/tests/lib.rs +++ b/library/alloc/tests/lib.rs @@ -7,7 +7,6 @@ #![feature(const_convert)] #![feature(const_cow_is_borrowed)] #![feature(const_heap)] -#![feature(const_intrinsic_copy)] #![feature(const_mut_refs)] #![feature(const_nonnull_slice_from_raw_parts)] #![feature(const_ptr_write)] diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 0b76790c0097e..7c10ed65c4c4c 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -2118,11 +2118,11 @@ pub(crate) fn is_nonoverlapping(src: *const T, dst: *const T, count: usize) - /// [`Vec::append`]: ../../std/vec/struct.Vec.html#method.append #[doc(alias = "memcpy")] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")] +#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")] #[inline] pub const unsafe fn copy_nonoverlapping(src: *const T, dst: *mut T, count: usize) { extern "rust-intrinsic" { - #[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")] + #[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")] pub fn copy_nonoverlapping(src: *const T, dst: *mut T, count: usize); } @@ -2200,11 +2200,11 @@ pub const unsafe fn copy_nonoverlapping(src: *const T, dst: *mut T, count: us /// ``` #[doc(alias = "memmove")] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")] +#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")] #[inline] pub const unsafe fn copy(src: *const T, dst: *mut T, count: usize) { extern "rust-intrinsic" { - #[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")] + #[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")] fn copy(src: *const T, dst: *mut T, count: usize); } diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index cfcc3ffb9c092..093c7d298734a 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -114,7 +114,6 @@ #![feature(const_convert)] #![feature(const_inherent_unchecked_arith)] #![feature(const_int_unchecked_arith)] -#![feature(const_intrinsic_copy)] #![feature(const_intrinsic_forget)] #![feature(const_likely)] #![feature(const_maybe_uninit_uninit_array)] diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 490d7594bb82f..74aa0d9c7bcb2 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -1199,7 +1199,7 @@ impl *const T { /// See [`ptr::copy`] for safety concerns and examples. /// /// [`ptr::copy`]: crate::ptr::copy() - #[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")] + #[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")] #[stable(feature = "pointer_methods", since = "1.26.0")] #[inline] pub const unsafe fn copy_to(self, dest: *mut T, count: usize) @@ -1218,7 +1218,7 @@ impl *const T { /// See [`ptr::copy_nonoverlapping`] for safety concerns and examples. /// /// [`ptr::copy_nonoverlapping`]: crate::ptr::copy_nonoverlapping() - #[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")] + #[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")] #[stable(feature = "pointer_methods", since = "1.26.0")] #[inline] pub const unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize) diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index a3b4e5886ef68..8fb0bfbe2e31b 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -1136,7 +1136,7 @@ pub const unsafe fn read(src: *const T) -> T { // We are calling the intrinsics directly to avoid function calls in the generated code // as `intrinsics::copy_nonoverlapping` is a wrapper function. extern "rust-intrinsic" { - #[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")] + #[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")] fn copy_nonoverlapping(src: *const T, dst: *mut T, count: usize); } @@ -1331,7 +1331,7 @@ pub const unsafe fn write(dst: *mut T, src: T) { // We are calling the intrinsics directly to avoid function calls in the generated code // as `intrinsics::copy_nonoverlapping` is a wrapper function. extern "rust-intrinsic" { - #[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")] + #[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")] fn copy_nonoverlapping(src: *const T, dst: *mut T, count: usize); } diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 5846c855e8f64..b988090f4bc4c 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -1311,7 +1311,7 @@ impl *mut T { /// See [`ptr::copy`] for safety concerns and examples. /// /// [`ptr::copy`]: crate::ptr::copy() - #[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")] + #[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")] #[stable(feature = "pointer_methods", since = "1.26.0")] #[inline(always)] pub const unsafe fn copy_to(self, dest: *mut T, count: usize) @@ -1330,7 +1330,7 @@ impl *mut T { /// See [`ptr::copy_nonoverlapping`] for safety concerns and examples. /// /// [`ptr::copy_nonoverlapping`]: crate::ptr::copy_nonoverlapping() - #[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")] + #[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")] #[stable(feature = "pointer_methods", since = "1.26.0")] #[inline(always)] pub const unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize) @@ -1349,7 +1349,7 @@ impl *mut T { /// See [`ptr::copy`] for safety concerns and examples. /// /// [`ptr::copy`]: crate::ptr::copy() - #[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")] + #[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")] #[stable(feature = "pointer_methods", since = "1.26.0")] #[inline(always)] pub const unsafe fn copy_from(self, src: *const T, count: usize) @@ -1368,7 +1368,7 @@ impl *mut T { /// See [`ptr::copy_nonoverlapping`] for safety concerns and examples. /// /// [`ptr::copy_nonoverlapping`]: crate::ptr::copy_nonoverlapping() - #[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")] + #[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")] #[stable(feature = "pointer_methods", since = "1.26.0")] #[inline(always)] pub const unsafe fn copy_from_nonoverlapping(self, src: *const T, count: usize) diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs index 40b2b49bdbd7d..3e2956eac8753 100644 --- a/library/core/tests/ptr.rs +++ b/library/core/tests/ptr.rs @@ -19,6 +19,7 @@ fn test_const_from_raw_parts() { #[test] fn test() { unsafe { + #[repr(C)] struct Pair { fst: isize, snd: isize, diff --git a/src/test/ui/consts/copy-intrinsic.rs b/src/test/ui/consts/copy-intrinsic.rs index 5ab90324b8f86..249bbb5991cc9 100644 --- a/src/test/ui/consts/copy-intrinsic.rs +++ b/src/test/ui/consts/copy-intrinsic.rs @@ -2,14 +2,14 @@ // ignore-tidy-linelength #![feature(intrinsics, staged_api)] -#![feature(const_mut_refs, const_intrinsic_copy)] +#![feature(const_mut_refs)] use std::mem; extern "rust-intrinsic" { - #[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")] + #[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")] fn copy_nonoverlapping(src: *const T, dst: *mut T, count: usize); - #[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")] + #[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")] fn copy(src: *const T, dst: *mut T, count: usize); } diff --git a/src/test/ui/consts/intrinsic_without_const_stab.rs b/src/test/ui/consts/intrinsic_without_const_stab.rs index d5f694986fc89..40ec65d51beec 100644 --- a/src/test/ui/consts/intrinsic_without_const_stab.rs +++ b/src/test/ui/consts/intrinsic_without_const_stab.rs @@ -1,8 +1,8 @@ -#![feature(intrinsics, staged_api, const_intrinsic_copy)] +#![feature(intrinsics, staged_api)] #![stable(feature = "core", since = "1.6.0")] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")] +#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")] #[inline] pub const unsafe fn copy(src: *const T, dst: *mut T, count: usize) { // Const stability attributes are not inherited from parent items. diff --git a/src/test/ui/consts/intrinsic_without_const_stab_fail.rs b/src/test/ui/consts/intrinsic_without_const_stab_fail.rs index 8b37268b0b205..2b0745b3c110c 100644 --- a/src/test/ui/consts/intrinsic_without_const_stab_fail.rs +++ b/src/test/ui/consts/intrinsic_without_const_stab_fail.rs @@ -1,4 +1,4 @@ -#![feature(intrinsics, staged_api, const_intrinsic_copy)] +#![feature(intrinsics, staged_api)] #![stable(feature = "core", since = "1.6.0")] extern "rust-intrinsic" { @@ -6,7 +6,7 @@ extern "rust-intrinsic" { } #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")] +#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")] #[inline] pub const unsafe fn stuff(src: *const T, dst: *mut T, count: usize) { unsafe { copy(src, dst, count) } //~ ERROR cannot call non-const fn diff --git a/src/test/ui/did_you_mean/use_instead_of_import.fixed b/src/test/ui/did_you_mean/use_instead_of_import.fixed new file mode 100644 index 0000000000000..87d453e1565c5 --- /dev/null +++ b/src/test/ui/did_you_mean/use_instead_of_import.fixed @@ -0,0 +1,15 @@ +// run-rustfix + +use std::{ + //~^ ERROR expected item, found `import` + io::Write, + rc::Rc, +}; + +pub use std::io; +//~^ ERROR expected item, found `using` + +fn main() { + let x = Rc::new(1); + let _ = write!(io::stdout(), "{:?}", x); +} diff --git a/src/test/ui/did_you_mean/use_instead_of_import.rs b/src/test/ui/did_you_mean/use_instead_of_import.rs new file mode 100644 index 0000000000000..59e83732328d9 --- /dev/null +++ b/src/test/ui/did_you_mean/use_instead_of_import.rs @@ -0,0 +1,15 @@ +// run-rustfix + +import std::{ + //~^ ERROR expected item, found `import` + io::Write, + rc::Rc, +}; + +pub using std::io; +//~^ ERROR expected item, found `using` + +fn main() { + let x = Rc::new(1); + let _ = write!(io::stdout(), "{:?}", x); +} diff --git a/src/test/ui/did_you_mean/use_instead_of_import.stderr b/src/test/ui/did_you_mean/use_instead_of_import.stderr new file mode 100644 index 0000000000000..b22954af80f06 --- /dev/null +++ b/src/test/ui/did_you_mean/use_instead_of_import.stderr @@ -0,0 +1,14 @@ +error: expected item, found `import` + --> $DIR/use_instead_of_import.rs:3:1 + | +LL | import std::{ + | ^^^^^^ help: items are imported using the `use` keyword + +error: expected item, found `using` + --> $DIR/use_instead_of_import.rs:9:5 + | +LL | pub using std::io; + | ^^^^^ help: items are imported using the `use` keyword + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/parser/match-arm-without-braces.rs b/src/test/ui/parser/match-arm-without-braces.rs index 55a887427696d..bba38fd0fa4c9 100644 --- a/src/test/ui/parser/match-arm-without-braces.rs +++ b/src/test/ui/parser/match-arm-without-braces.rs @@ -45,9 +45,9 @@ fn main() { 15; } match S::get(16) { - Some(Val::Foo) => 17 - _ => 18, //~ ERROR expected one of - } + Some(Val::Foo) => 17 //~ ERROR expected `,` following `match` arm + _ => 18, + }; match S::get(19) { Some(Val::Foo) => 20; //~ ERROR `match` arm body without braces diff --git a/src/test/ui/parser/match-arm-without-braces.stderr b/src/test/ui/parser/match-arm-without-braces.stderr index 4831d79ef2bb3..37d55aa53f87c 100644 --- a/src/test/ui/parser/match-arm-without-braces.stderr +++ b/src/test/ui/parser/match-arm-without-braces.stderr @@ -52,15 +52,11 @@ LL ~ { 14; LL ~ 15; } | -error: expected one of `,`, `.`, `?`, `}`, or an operator, found reserved identifier `_` - --> $DIR/match-arm-without-braces.rs:49:9 +error: expected `,` following `match` arm + --> $DIR/match-arm-without-braces.rs:48:29 | LL | Some(Val::Foo) => 17 - | -- - expected one of `,`, `.`, `?`, `}`, or an operator - | | - | while parsing the `match` arm starting here -LL | _ => 18, - | ^ unexpected token + | ^ help: missing a comma here to end this `match` arm: `,` error: `match` arm body without braces --> $DIR/match-arm-without-braces.rs:53:11 diff --git a/src/test/ui/traits/vtable/issue-97381.rs b/src/test/ui/traits/vtable/issue-97381.rs new file mode 100644 index 0000000000000..393cf91efc2d2 --- /dev/null +++ b/src/test/ui/traits/vtable/issue-97381.rs @@ -0,0 +1,30 @@ +use std::ops::Deref; +trait MyTrait: Deref {} +struct MyStruct(u32); +impl MyTrait for MyStruct {} +impl Deref for MyStruct { + type Target = u32; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} +fn get_concrete_value(i: u32) -> MyStruct { + MyStruct(i) +} +fn get_boxed_value(i: u32) -> Box { + Box::new(get_concrete_value(i)) +} +fn main() { + let v = [1, 2, 3] + .iter() + .map(|i| get_boxed_value(*i)) + .collect::>(); + + let el = &v[0]; + + for _ in v { + //~^ ERROR cannot move out of `v` because it is borrowed + println!("{}", ***el > 0); + } +} diff --git a/src/test/ui/traits/vtable/issue-97381.stderr b/src/test/ui/traits/vtable/issue-97381.stderr new file mode 100644 index 0000000000000..f88c8716ff740 --- /dev/null +++ b/src/test/ui/traits/vtable/issue-97381.stderr @@ -0,0 +1,15 @@ +error[E0505]: cannot move out of `v` because it is borrowed + --> $DIR/issue-97381.rs:26:14 + | +LL | let el = &v[0]; + | - borrow of `v` occurs here +LL | +LL | for _ in v { + | ^ move out of `v` occurs here +LL | +LL | println!("{}", ***el > 0); + | ---- borrow later used here + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0505`. diff --git a/src/test/ui/type/type-unsatisfiable.rs b/src/test/ui/type/type-unsatisfiable.rs new file mode 100644 index 0000000000000..7fbbb50dc115f --- /dev/null +++ b/src/test/ui/type/type-unsatisfiable.rs @@ -0,0 +1,59 @@ +// revisions: lib usage +//[lib] compile-flags: --crate-type=lib +//[lib] build-pass + +use std::ops::Sub; +trait Vector2 { + type ScalarType; + + fn from_values(x: Self::ScalarType, y: Self::ScalarType) -> Self + where + Self: Sized; + + fn x(&self) -> Self::ScalarType; + fn y(&self) -> Self::ScalarType; +} + +impl Sub for dyn Vector2 +where + T: Sub, + (dyn Vector2): Sized, +{ + type Output = dyn Vector2; + + fn sub(self, rhs: Self) -> Self::Output { + Self::from_values(self.x() - rhs.x(), self.y() - rhs.y()) + } +} + +struct Vec2 { + x: i32, + y: i32, +} + +impl Vector2 for Vec2 { + type ScalarType = i32; + + fn from_values(x: Self::ScalarType, y: Self::ScalarType) -> Self + where + Self: Sized, + { + Self { x, y } + } + + fn x(&self) -> Self::ScalarType { + self.x + } + fn y(&self) -> Self::ScalarType { + self.y + } +} + +#[cfg(usage)] +fn main() { + let hey: Box> = Box::new(Vec2 { x: 1, y: 2 }); + let word: Box> = Box::new(Vec2 { x: 1, y: 2 }); + + let bar = *hey - *word; + //[usage]~^ ERROR cannot subtract +} diff --git a/src/test/ui/type/type-unsatisfiable.usage.stderr b/src/test/ui/type/type-unsatisfiable.usage.stderr new file mode 100644 index 0000000000000..56e2e30afaca5 --- /dev/null +++ b/src/test/ui/type/type-unsatisfiable.usage.stderr @@ -0,0 +1,11 @@ +error[E0369]: cannot subtract `(dyn Vector2 + 'static)` from `dyn Vector2` + --> $DIR/type-unsatisfiable.rs:57:20 + | +LL | let bar = *hey - *word; + | ---- ^ ----- (dyn Vector2 + 'static) + | | + | dyn Vector2 + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0369`.