From e1b074a2a8b89741621d13cdf22ce893e2c3fb8b Mon Sep 17 00:00:00 2001 From: marmeladema Date: Sun, 24 Apr 2022 16:44:09 +0200 Subject: Recover most `impl Trait` and `dyn Trait` lifetime bound suggestions under NLL --- .../ui/impl-trait/issues/issue-88236-2.nll.stderr | 6 +++- .../must_outlive_least_region_or_bound.nll.stderr | 36 ++++++++++++++++++++-- src/test/ui/issues/issue-16922.nll.stderr | 5 +++ src/test/ui/nll/mir_check_cast_unsize.stderr | 5 +++ ...ject-lifetime-default-from-box-error.nll.stderr | 5 +++ .../region-object-lifetime-in-coercion.nll.stderr | 23 ++++++++++++++ .../regions-close-object-into-object-2.nll.stderr | 9 ++++++ .../regions-close-object-into-object-4.nll.stderr | 9 ++++++ .../regions/regions-proc-bound-capture.nll.stderr | 9 ++++++ .../trait-object-nested-in-impl-trait.nll.stderr | 22 +++++++++++-- .../dyn-trait-underscore.nll.stderr | 5 +++ 11 files changed, 128 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/test/ui/impl-trait/issues/issue-88236-2.nll.stderr b/src/test/ui/impl-trait/issues/issue-88236-2.nll.stderr index 9cf8ff76c87..66cffa9e36c 100644 --- a/src/test/ui/impl-trait/issues/issue-88236-2.nll.stderr +++ b/src/test/ui/impl-trait/issues/issue-88236-2.nll.stderr @@ -24,10 +24,14 @@ LL | fn make_bad_impl<'b>(x: &'b ()) -> impl for<'a> Hrtb<'a, Assoc = impl Send LL | x | ^ returning this value requires that `'b` must outlive `'static` | -help: to allow this `impl Trait` to capture borrowed data with lifetime `'b`, add `'b` as a bound +help: to declare that the `impl Trait` captures data from argument `x`, you can add an explicit `'b` lifetime bound | LL | fn make_bad_impl<'b>(x: &'b ()) -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> + 'b { | ++++ +help: to declare that the `impl Trait` captures data from argument `x`, you can add an explicit `'b` lifetime bound + | +LL | fn make_bad_impl<'b>(x: &'b ()) -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a + 'b> { + | ++++ error: implementation of `Hrtb` is not general enough --> $DIR/issue-88236-2.rs:20:5 diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr index 0059f729bae..5a190649b63 100644 --- a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr +++ b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr @@ -32,7 +32,14 @@ LL | fn elided2(x: &i32) -> impl Copy + 'static { x } | | | let's call the lifetime of this reference `'1` | - = help: consider replacing `'1` with `'static` +help: consider changing the `impl Trait`'s explicit `'static` bound to the lifetime of argument `x` + | +LL | fn elided2(x: &i32) -> impl Copy + '_ { x } + | ~~ +help: alternatively, add an explicit `'static` bound to this reference + | +LL | fn elided2(x: &'static i32) -> impl Copy + 'static { x } + | ~~~~~~~~~~~~ error: lifetime may not live long enough --> $DIR/must_outlive_least_region_or_bound.rs:11:55 @@ -40,7 +47,14 @@ error: lifetime may not live long enough LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x } | -- lifetime `'a` defined here ^ returning this value requires that `'a` must outlive `'static` | - = help: consider replacing `'a` with `'static` +help: consider changing the `impl Trait`'s explicit `'static` bound to the lifetime of argument `x` + | +LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'a { x } + | ~~ +help: alternatively, add an explicit `'static` bound to this reference + | +LL | fn explicit2<'a>(x: &'static i32) -> impl Copy + 'static { x } + | ~~~~~~~~~~~~ error[E0621]: explicit lifetime required in the type of `x` --> $DIR/must_outlive_least_region_or_bound.rs:13:41 @@ -57,6 +71,15 @@ LL | fn elided5(x: &i32) -> (Box, impl Debug) { (Box::new(x), x) } | - ^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'static` | | | let's call the lifetime of this reference `'1` + | +help: to declare that the trait object captures data from argument `x`, you can add an explicit `'_` lifetime bound + | +LL | fn elided5(x: &i32) -> (Box, impl Debug) { (Box::new(x), x) } + | ++++ +help: to declare that the `impl Trait` captures data from argument `x`, you can add an explicit `'_` lifetime bound + | +LL | fn elided5(x: &i32) -> (Box, impl Debug + '_) { (Box::new(x), x) } + | ++++ error: lifetime may not live long enough --> $DIR/must_outlive_least_region_or_bound.rs:29:69 @@ -64,7 +87,14 @@ error: lifetime may not live long enough LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x } | -- lifetime `'a` defined here ^ returning this value requires that `'a` must outlive `'static` | - = help: consider replacing `'a` with `'static` +help: consider changing the `impl Trait`'s explicit `'static` bound to the lifetime of argument `x` + | +LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'a { x } + | ~~ +help: alternatively, add an explicit `'static` bound to this reference + | +LL | fn with_bound<'a>(x: &'static i32) -> impl LifetimeTrait<'a> + 'static { x } + | ~~~~~~~~~~~~ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds --> $DIR/must_outlive_least_region_or_bound.rs:34:5 diff --git a/src/test/ui/issues/issue-16922.nll.stderr b/src/test/ui/issues/issue-16922.nll.stderr index 7f4f5b22eb3..9d9f32a97c0 100644 --- a/src/test/ui/issues/issue-16922.nll.stderr +++ b/src/test/ui/issues/issue-16922.nll.stderr @@ -5,6 +5,11 @@ LL | fn foo(value: &T) -> Box { | - let's call the lifetime of this reference `'1` LL | Box::new(value) as Box | ^^^^^^^^^^^^^^^ cast requires that `'1` must outlive `'static` + | +help: to declare that the trait object captures data from argument `value`, you can add an explicit `'_` lifetime bound + | +LL | fn foo(value: &T) -> Box { + | ++++ error: aborting due to previous error diff --git a/src/test/ui/nll/mir_check_cast_unsize.stderr b/src/test/ui/nll/mir_check_cast_unsize.stderr index 364d6c17ea7..8d02ef71d1b 100644 --- a/src/test/ui/nll/mir_check_cast_unsize.stderr +++ b/src/test/ui/nll/mir_check_cast_unsize.stderr @@ -5,6 +5,11 @@ LL | fn bar<'a>(x: &'a u32) -> &'static dyn Debug { | -- lifetime `'a` defined here LL | x | ^ returning this value requires that `'a` must outlive `'static` + | +help: to declare that the trait object captures data from argument `x`, you can add an explicit `'a` lifetime bound + | +LL | fn bar<'a>(x: &'a u32) -> &'static dyn Debug + 'a { + | ++++ error: aborting due to previous error diff --git a/src/test/ui/object-lifetime/object-lifetime-default-from-box-error.nll.stderr b/src/test/ui/object-lifetime/object-lifetime-default-from-box-error.nll.stderr index ae02c58d080..43695a7511d 100644 --- a/src/test/ui/object-lifetime/object-lifetime-default-from-box-error.nll.stderr +++ b/src/test/ui/object-lifetime/object-lifetime-default-from-box-error.nll.stderr @@ -6,6 +6,11 @@ LL | fn load(ss: &mut SomeStruct) -> Box { ... LL | ss.r | ^^^^ returning this value requires that `'1` must outlive `'static` + | +help: to declare that the trait object captures data from argument `ss`, you can add an explicit `'_` lifetime bound + | +LL | fn load(ss: &mut SomeStruct) -> Box { + | ++++ error[E0507]: cannot move out of `ss.r` which is behind a mutable reference --> $DIR/object-lifetime-default-from-box-error.rs:18:5 diff --git a/src/test/ui/regions/region-object-lifetime-in-coercion.nll.stderr b/src/test/ui/regions/region-object-lifetime-in-coercion.nll.stderr index 4d72724586e..724b06ce8b1 100644 --- a/src/test/ui/regions/region-object-lifetime-in-coercion.nll.stderr +++ b/src/test/ui/regions/region-object-lifetime-in-coercion.nll.stderr @@ -5,6 +5,15 @@ LL | fn a(v: &[u8]) -> Box { | - let's call the lifetime of this reference `'1` LL | let x: Box = Box::new(v); | ^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'1` must outlive `'static` + | +help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `v` + | +LL | fn a(v: &[u8]) -> Box { + | ~~ +help: alternatively, add an explicit `'static` bound to this reference + | +LL | fn a(v: &'static [u8]) -> Box { + | ~~~~~~~~~~~~~ error: lifetime may not live long enough --> $DIR/region-object-lifetime-in-coercion.rs:19:5 @@ -13,6 +22,15 @@ LL | fn b(v: &[u8]) -> Box { | - let's call the lifetime of this reference `'1` LL | Box::new(v) | ^^^^^^^^^^^ returning this value requires that `'1` must outlive `'static` + | +help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `v` + | +LL | fn b(v: &[u8]) -> Box { + | ~~ +help: alternatively, add an explicit `'static` bound to this reference + | +LL | fn b(v: &'static [u8]) -> Box { + | ~~~~~~~~~~~~~ error: lifetime may not live long enough --> $DIR/region-object-lifetime-in-coercion.rs:27:5 @@ -22,6 +40,11 @@ LL | fn c(v: &[u8]) -> Box { ... LL | Box::new(v) | ^^^^^^^^^^^ returning this value requires that `'1` must outlive `'static` + | +help: to declare that the trait object captures data from argument `v`, you can add an explicit `'_` lifetime bound + | +LL | fn c(v: &[u8]) -> Box { + | ++++ error: lifetime may not live long enough --> $DIR/region-object-lifetime-in-coercion.rs:33:5 diff --git a/src/test/ui/regions/regions-close-object-into-object-2.nll.stderr b/src/test/ui/regions/regions-close-object-into-object-2.nll.stderr index 1a79da2776b..473c99b672f 100644 --- a/src/test/ui/regions/regions-close-object-into-object-2.nll.stderr +++ b/src/test/ui/regions/regions-close-object-into-object-2.nll.stderr @@ -5,6 +5,15 @@ LL | fn g<'a, T: 'static>(v: Box + 'a>) -> Box { | -- lifetime `'a` defined here LL | Box::new(B(&*v)) as Box | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static` + | +help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `v` + | +LL | fn g<'a, T: 'static>(v: Box + 'a>) -> Box { + | ~~ +help: alternatively, add an explicit `'static` bound to this reference + | +LL | fn g<'a, T: 'static>(v: Box<(dyn A + 'static)>) -> Box { + | ~~~~~~~~~~~~~~~~~~~~~~~~~ error[E0515]: cannot return value referencing local data `*v` --> $DIR/regions-close-object-into-object-2.rs:13:5 diff --git a/src/test/ui/regions/regions-close-object-into-object-4.nll.stderr b/src/test/ui/regions/regions-close-object-into-object-4.nll.stderr index 993b13ddbf8..05ddc09b2d0 100644 --- a/src/test/ui/regions/regions-close-object-into-object-4.nll.stderr +++ b/src/test/ui/regions/regions-close-object-into-object-4.nll.stderr @@ -29,6 +29,15 @@ LL | fn i<'a, T, U>(v: Box+'a>) -> Box { | -- lifetime `'a` defined here LL | Box::new(B(&*v)) as Box | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static` + | +help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `v` + | +LL | fn i<'a, T, U>(v: Box+'a>) -> Box { + | ~~ +help: alternatively, add an explicit `'static` bound to this reference + | +LL | fn i<'a, T, U>(v: Box<(dyn A + 'static)>) -> Box { + | ~~~~~~~~~~~~~~~~~~~~~~~~~ error[E0515]: cannot return value referencing local data `*v` --> $DIR/regions-close-object-into-object-4.rs:13:5 diff --git a/src/test/ui/regions/regions-proc-bound-capture.nll.stderr b/src/test/ui/regions/regions-proc-bound-capture.nll.stderr index 6120a53eb09..ce4d2d4d111 100644 --- a/src/test/ui/regions/regions-proc-bound-capture.nll.stderr +++ b/src/test/ui/regions/regions-proc-bound-capture.nll.stderr @@ -6,6 +6,15 @@ LL | fn static_proc(x: &isize) -> Box (isize) + 'static> { LL | // This is illegal, because the region bound on `proc` is 'static. LL | Box::new(move || { *x }) | ^^^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'static` + | +help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `x` + | +LL | fn static_proc(x: &isize) -> Box (isize) + '_> { + | ~~ +help: alternatively, add an explicit `'static` bound to this reference + | +LL | fn static_proc(x: &'static isize) -> Box (isize) + 'static> { + | ~~~~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.nll.stderr b/src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.nll.stderr index 3ed3827b97d..6c65e4f0175 100644 --- a/src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.nll.stderr +++ b/src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.nll.stderr @@ -9,10 +9,14 @@ LL | | remaining: self.0.iter(), LL | | } | |_________^ returning this value requires that `'1` must outlive `'static` | -help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound +help: to declare that the `impl Trait` captures data from argument `self`, you can add an explicit `'_` lifetime bound | LL | fn iter(&self) -> impl Iterator> + '_ { | ++++ +help: to declare that the trait object captures data from argument `self`, you can add an explicit `'_` lifetime bound + | +LL | fn iter(&self) -> impl Iterator> { + | ++++ error: lifetime may not live long enough --> $DIR/trait-object-nested-in-impl-trait.rs:39:9 @@ -24,6 +28,11 @@ LL | | current: None, LL | | remaining: self.0.iter(), LL | | } | |_________^ returning this value requires that `'1` must outlive `'static` + | +help: to declare that the trait object captures data from argument `self`, you can add an explicit `'_` lifetime bound + | +LL | fn iter(&self) -> impl Iterator> + '_ { + | ++++ error: lifetime may not live long enough --> $DIR/trait-object-nested-in-impl-trait.rs:50:9 @@ -35,6 +44,11 @@ LL | | current: None, LL | | remaining: self.0.iter(), LL | | } | |_________^ returning this value requires that `'a` must outlive `'static` + | +help: to declare that the trait object captures data from argument `self`, you can add an explicit `'a` lifetime bound + | +LL | fn iter<'a>(&'a self) -> impl Iterator> + 'a { + | ++++ error: lifetime may not live long enough --> $DIR/trait-object-nested-in-impl-trait.rs:61:9 @@ -47,10 +61,14 @@ LL | | remaining: self.0.iter(), LL | | } | |_________^ returning this value requires that `'a` must outlive `'static` | -help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a bound +help: to declare that the `impl Trait` captures data from argument `self`, you can add an explicit `'a` lifetime bound | LL | fn iter<'a>(&'a self) -> impl Iterator> + 'a { | ++++ +help: to declare that the trait object captures data from argument `self`, you can add an explicit `'a` lifetime bound + | +LL | fn iter<'a>(&'a self) -> impl Iterator> { + | ++++ error: aborting due to 4 previous errors diff --git a/src/test/ui/underscore-lifetime/dyn-trait-underscore.nll.stderr b/src/test/ui/underscore-lifetime/dyn-trait-underscore.nll.stderr index 53d45f6a8f2..0ffb77cf021 100644 --- a/src/test/ui/underscore-lifetime/dyn-trait-underscore.nll.stderr +++ b/src/test/ui/underscore-lifetime/dyn-trait-underscore.nll.stderr @@ -6,6 +6,11 @@ LL | fn a(items: &[T]) -> Box> { LL | // ^^^^^^^^^^^^^^^^^^^^^ bound *here* defaults to `'static` LL | Box::new(items.iter()) | ^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'static` + | +help: to declare that the trait object captures data from argument `items`, you can add an explicit `'_` lifetime bound + | +LL | fn a(items: &[T]) -> Box + '_> { + | ++++ error: aborting due to previous error -- cgit 1.4.1-3-g733a5 From 8a28aa48d20ac4fd64d47815b84f1daf0c62f460 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 24 Apr 2022 23:32:59 -0700 Subject: Fix issue 96381 --- compiler/rustc_typeck/src/astconv/mod.rs | 8 ++++---- src/test/rustdoc/issue-96381.rs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 src/test/rustdoc/issue-96381.rs (limited to 'src') diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index 1cd0ace8adb..1caf93e5fe0 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -2681,21 +2681,21 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let trait_ref = self.instantiate_mono_trait_ref(i.of_trait.as_ref()?, self.ast_ty_to_ty(i.self_ty)); - let x: &ty::AssocItem = tcx.associated_items(trait_ref.def_id).find_by_name_and_kind( + let assoc = tcx.associated_items(trait_ref.def_id).find_by_name_and_kind( tcx, *ident, ty::AssocKind::Fn, trait_ref.def_id, )?; - let fn_sig = tcx.fn_sig(x.def_id).subst( + let fn_sig = tcx.fn_sig(assoc.def_id).subst( tcx, - trait_ref.substs.extend_to(tcx, x.def_id, |param, _| tcx.mk_param_from_def(param)), + trait_ref.substs.extend_to(tcx, assoc.def_id, |param, _| tcx.mk_param_from_def(param)), ); let ty = if let Some(arg_idx) = arg_idx { fn_sig.input(arg_idx) } else { fn_sig.output() }; - Some(tcx.erase_late_bound_regions(ty)) + Some(tcx.liberate_late_bound_regions(fn_hir_id.expect_owner().to_def_id(), ty)) } fn validate_late_bound_regions( diff --git a/src/test/rustdoc/issue-96381.rs b/src/test/rustdoc/issue-96381.rs new file mode 100644 index 00000000000..f0f123f85a0 --- /dev/null +++ b/src/test/rustdoc/issue-96381.rs @@ -0,0 +1,16 @@ +// should-fail + +#![allow(unused)] + +trait Foo: Sized { + fn bar(i: i32, t: T, s: &Self) -> (T, i32); +} + +impl Foo for () { + fn bar(i: _, t: _, s: _) -> _ { + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + (1, 2) + } +} + +fn main() {} -- cgit 1.4.1-3-g733a5 From ae38f3572041aa7779f01628e08f707a434ae2a6 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 25 Apr 2022 15:38:43 -0700 Subject: rustdoc: do not write `{{root}}` in `pub use ::foo` docs --- src/librustdoc/html/format.rs | 3 ++- src/test/rustdoc/issue-95873.rs | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 src/test/rustdoc/issue-95873.rs (limited to 'src') diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index d3545236e3d..118807a8286 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -18,6 +18,7 @@ use rustc_hir::def_id::DefId; use rustc_middle::ty; use rustc_middle::ty::DefIdTree; use rustc_middle::ty::TyCtxt; +use rustc_span::symbol::kw; use rustc_span::{sym, Symbol}; use rustc_target::spec::abi::Abi; @@ -679,7 +680,7 @@ fn resolved_path<'cx>( if print_all { for seg in &path.segments[..path.segments.len() - 1] { - write!(w, "{}::", seg.name)?; + write!(w, "{}::", if seg.name == kw::PathRoot { "" } else { seg.name.as_str() })?; } } if w.alternate() { diff --git a/src/test/rustdoc/issue-95873.rs b/src/test/rustdoc/issue-95873.rs new file mode 100644 index 00000000000..1ed7e582275 --- /dev/null +++ b/src/test/rustdoc/issue-95873.rs @@ -0,0 +1,2 @@ +// @!has issue_95873/index.html '{{root}}' +pub use ::std as x; -- cgit 1.4.1-3-g733a5 From c2a9a685819abcf2050bd342385724db9bf35547 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 26 Apr 2022 07:13:30 -0700 Subject: Update src/test/rustdoc/issue-95873.rs Co-authored-by: Guillaume Gomez --- src/test/rustdoc/issue-95873.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/test/rustdoc/issue-95873.rs b/src/test/rustdoc/issue-95873.rs index 1ed7e582275..ff33fb63a0b 100644 --- a/src/test/rustdoc/issue-95873.rs +++ b/src/test/rustdoc/issue-95873.rs @@ -1,2 +1,2 @@ -// @!has issue_95873/index.html '{{root}}' +// @has issue_95873/index.html "//*[@class='item-left import-item']" "pub use ::std as x;" pub use ::std as x; -- cgit 1.4.1-3-g733a5 From 45cdb2be10756f584540f349a379730c43fe0976 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 26 Apr 2022 13:58:23 +0200 Subject: Update rustdoc search parser to handle `!` correctly --- src/librustdoc/html/static/js/search.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index c4e74ea0657..c1d2ec540b0 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -310,10 +310,20 @@ window.initSearch = function(rawSearchIndex) { */ function getIdentEndPosition(parserState) { let end = parserState.pos; + let foundExclamation = false; while (parserState.pos < parserState.length) { const c = parserState.userQuery[parserState.pos]; if (!isIdentCharacter(c)) { - if (isErrorCharacter(c)) { + if (c === "!") { + if (foundExclamation) { + throw new Error("Cannot have more than one `!` in an ident"); + } else if (parserState.pos + 1 < parserState.length && + isIdentCharacter(parserState.userQuery[parserState.pos + 1])) + { + throw new Error("`!` can only be at the end of an ident"); + } + foundExclamation = true; + } else if (isErrorCharacter(c)) { throw new Error(`Unexpected \`${c}\``); } else if ( isStopCharacter(c) || @@ -329,6 +339,7 @@ window.initSearch = function(rawSearchIndex) { } // Skip current ":". parserState.pos += 1; + foundExclamation = false; } else { throw new Error(`Unexpected \`${c}\``); } @@ -591,7 +602,7 @@ window.initSearch = function(rawSearchIndex) { * * The supported syntax by this parser is as follow: * - * ident = *(ALPHA / DIGIT / "_") + * ident = *(ALPHA / DIGIT / "_") [!] * path = ident *(DOUBLE-COLON ident) * arg = path [generics] * arg-without-generic = path -- cgit 1.4.1-3-g733a5 From 4ea149905b460e086809d7a34dfcbdca312bee3d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 26 Apr 2022 13:58:43 +0200 Subject: Update rustdoc search test to check `!` --- src/test/rustdoc-js-std/parser-errors.js | 20 +++++++ src/test/rustdoc-js-std/parser-ident.js | 93 ++++++++++++++++++++++++++++++ src/test/rustdoc-js-std/parser-returned.js | 23 +++++++- 3 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 src/test/rustdoc-js-std/parser-ident.js (limited to 'src') diff --git a/src/test/rustdoc-js-std/parser-errors.js b/src/test/rustdoc-js-std/parser-errors.js index 779ab867c12..dc42031e05f 100644 --- a/src/test/rustdoc-js-std/parser-errors.js +++ b/src/test/rustdoc-js-std/parser-errors.js @@ -35,6 +35,8 @@ const QUERY = [ "a,:", " a<> :", "mod : :", + "a!a", + "a!!", ]; const PARSED = [ @@ -362,4 +364,22 @@ const PARSED = [ userQuery: "mod : :", error: 'Unexpected `:`', }, + { + elems: [], + foundElems: 0, + original: "a!a", + returned: [], + typeFilter: -1, + userQuery: "a!a", + error: '`!` can only be at the end of an ident', + }, + { + elems: [], + foundElems: 0, + original: "a!!", + returned: [], + typeFilter: -1, + userQuery: "a!!", + error: 'Cannot have more than one `!` in an ident', + }, ]; diff --git a/src/test/rustdoc-js-std/parser-ident.js b/src/test/rustdoc-js-std/parser-ident.js new file mode 100644 index 00000000000..4b5ab01ac76 --- /dev/null +++ b/src/test/rustdoc-js-std/parser-ident.js @@ -0,0 +1,93 @@ +const QUERY = [ + "R", + "!", + "a!", + "a!::b", + "a!::b!", +]; + +const PARSED = [ + { + elems: [{ + name: "r", + fullPath: ["r"], + pathWithoutLast: [], + pathLast: "r", + generics: [ + { + name: "!", + fullPath: ["!"], + pathWithoutLast: [], + pathLast: "!", + generics: [], + }, + ], + }], + foundElems: 1, + original: "R", + returned: [], + typeFilter: -1, + userQuery: "r", + error: null, + }, + { + elems: [{ + name: "!", + fullPath: ["!"], + pathWithoutLast: [], + pathLast: "!", + generics: [], + }], + foundElems: 1, + original: "!", + returned: [], + typeFilter: -1, + userQuery: "!", + error: null, + }, + { + elems: [{ + name: "a!", + fullPath: ["a!"], + pathWithoutLast: [], + pathLast: "a!", + generics: [], + }], + foundElems: 1, + original: "a!", + returned: [], + typeFilter: -1, + userQuery: "a!", + error: null, + }, + { + elems: [{ + name: "a!::b", + fullPath: ["a!", "b"], + pathWithoutLast: ["a!"], + pathLast: "b", + generics: [], + }], + foundElems: 1, + original: "a!::b", + returned: [], + typeFilter: -1, + userQuery: "a!::b", + error: null, + }, + { + elems: [{ + name: "a!::b!", + fullPath: ["a!", "b!"], + pathWithoutLast: ["a!"], + pathLast: "b!", + generics: [], + }], + foundElems: 1, + original: "a!::b!", + returned: [], + typeFilter: -1, + userQuery: "a!::b!", + error: null, + }, +]; diff --git a/src/test/rustdoc-js-std/parser-returned.js b/src/test/rustdoc-js-std/parser-returned.js index b45466aa940..6fce17dcabd 100644 --- a/src/test/rustdoc-js-std/parser-returned.js +++ b/src/test/rustdoc-js-std/parser-returned.js @@ -1,4 +1,10 @@ -const QUERY = ['-> F

', '-> P', '->,a', 'aaaaa->a']; +const QUERY = [ + "-> F

", + "-> P", + "->,a", + "aaaaa->a", + "-> !", +]; const PARSED = [ { @@ -75,4 +81,19 @@ const PARSED = [ userQuery: "aaaaa->a", error: null, }, + { + elems: [], + foundElems: 1, + original: "-> !", + returned: [{ + name: "!", + fullPath: ["!"], + pathWithoutLast: [], + pathLast: "!", + generics: [], + }], + typeFilter: -1, + userQuery: "-> !", + error: null, + }, ]; -- cgit 1.4.1-3-g733a5 From 14a127be3ed2ea1151875e11b188a569ebc836a9 Mon Sep 17 00:00:00 2001 From: George <33588728+George-lewis@users.noreply.github.com> Date: Tue, 26 Apr 2022 17:04:44 -0400 Subject: Add new diagnostic --- compiler/rustc_hir/src/hir.rs | 6 ++++ compiler/rustc_typeck/src/check/expr.rs | 25 ++++++++++++++ compiler/rustc_typeck/src/check/method/suggest.rs | 38 +++++++++++++++------- compiler/rustc_typeck/src/check/mod.rs | 38 +++++++++++++++++++++- src/test/ui/functions-closures/fn-help-with-err.rs | 6 ++-- .../ui/functions-closures/fn-help-with-err.stderr | 6 ++-- src/test/ui/issues/issue-29124.stderr | 12 +++---- src/test/ui/issues/issue-57362-1.stderr | 5 +-- .../ui/typeck/issue-87181/empty-tuple-method.rs | 14 ++++++++ .../typeck/issue-87181/empty-tuple-method.stderr | 16 +++++++++ src/test/ui/typeck/issue-87181/enum-variant.rs | 16 +++++++++ src/test/ui/typeck/issue-87181/enum-variant.stderr | 16 +++++++++ src/test/ui/typeck/issue-87181/tuple-field.rs | 14 ++++++++ src/test/ui/typeck/issue-87181/tuple-field.stderr | 16 +++++++++ src/test/ui/typeck/issue-87181/tuple-method.rs | 14 ++++++++ src/test/ui/typeck/issue-87181/tuple-method.stderr | 16 +++++++++ ...unboxed-closures-static-call-wrong-trait.stderr | 6 ++-- 17 files changed, 234 insertions(+), 30 deletions(-) create mode 100644 src/test/ui/typeck/issue-87181/empty-tuple-method.rs create mode 100644 src/test/ui/typeck/issue-87181/empty-tuple-method.stderr create mode 100644 src/test/ui/typeck/issue-87181/enum-variant.rs create mode 100644 src/test/ui/typeck/issue-87181/enum-variant.stderr create mode 100644 src/test/ui/typeck/issue-87181/tuple-field.rs create mode 100644 src/test/ui/typeck/issue-87181/tuple-field.stderr create mode 100644 src/test/ui/typeck/issue-87181/tuple-method.rs create mode 100644 src/test/ui/typeck/issue-87181/tuple-method.stderr (limited to 'src') diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index ef56093bed8..2d01673b61d 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -3314,6 +3314,12 @@ impl<'hir> Node<'hir> { _ => None, } } + + /// Get the fields for the tuple-constructor, + /// if this node is a tuple constructor, otherwise None + pub fn tuple_fields(&self) -> Option<&'hir [FieldDef<'hir>]> { + if let Node::Ctor(&VariantData::Tuple(fields, _)) = self { Some(fields) } else { None } + } } // Some nodes are used a lot. Make sure they don't unintentionally get bigger. diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 480a5512249..47cb1ea48cb 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -21,11 +21,13 @@ use crate::errors::{ }; use crate::type_error_struct; +use super::suggest_call_constructor; use crate::errors::{AddressOfTemporaryTaken, ReturnStmtOutsideOfFnBody, StructExprNonExhaustive}; use rustc_ast as ast; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_errors::Diagnostic; +use rustc_errors::EmissionGuarantee; use rustc_errors::ErrorGuaranteed; use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, DiagnosticId}; use rustc_hir as hir; @@ -1986,6 +1988,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.tcx().ty_error() } + fn check_call_constructor( + &self, + err: &mut DiagnosticBuilder<'_, G>, + base: &'tcx hir::Expr<'tcx>, + def_id: DefId, + ) { + let local_id = def_id.expect_local(); + let hir_id = self.tcx.hir().local_def_id_to_hir_id(local_id); + let node = self.tcx.hir().get(hir_id); + + if let Some(fields) = node.tuple_fields() { + let kind = match self.tcx.opt_def_kind(local_id) { + Some(DefKind::Ctor(of, _)) => of, + _ => return, + }; + + suggest_call_constructor(base.span, kind, fields.len(), err); + } + } + fn suggest_await_on_field_access( &self, err: &mut Diagnostic, @@ -2055,6 +2077,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::Opaque(_, _) => { self.suggest_await_on_field_access(&mut err, field, base, expr_t.peel_refs()); } + ty::FnDef(def_id, _) => { + self.check_call_constructor(&mut err, base, def_id); + } _ => {} } diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index 88e0a4bada8..95c9c775e37 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -8,6 +8,7 @@ use rustc_errors::{ MultiSpan, }; use rustc_hir as hir; +use rustc_hir::def::DefKind; use rustc_hir::def_id::DefId; use rustc_hir::lang_items::LangItem; use rustc_hir::{ExprKind, Node, QPath}; @@ -29,7 +30,7 @@ use std::cmp::Ordering; use std::iter; use super::probe::{Mode, ProbeScope}; -use super::{CandidateSource, MethodError, NoMatchData}; +use super::{super::suggest_call_constructor, CandidateSource, MethodError, NoMatchData}; impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn is_fn_ty(&self, ty: Ty<'tcx>, span: Span) -> bool { @@ -488,19 +489,32 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } if self.is_fn_ty(rcvr_ty, span) { - fn report_function(err: &mut Diagnostic, name: T) { - err.note( - &format!("`{}` is a function, perhaps you wish to call it", name,), - ); - } - if let SelfSource::MethodCall(expr) = source { - if let Ok(expr_string) = tcx.sess.source_map().span_to_snippet(expr.span) { - report_function(&mut err, expr_string); - } else if let ExprKind::Path(QPath::Resolved(_, path)) = expr.kind { - if let Some(segment) = path.segments.last() { - report_function(&mut err, segment.ident); + let suggest = if let ty::FnDef(def_id, _) = rcvr_ty.kind() { + let local_id = def_id.expect_local(); + let hir_id = tcx.hir().local_def_id_to_hir_id(local_id); + let node = tcx.hir().get(hir_id); + let fields = node.tuple_fields(); + + if let Some(fields) = fields + && let Some(DefKind::Ctor(of, _)) = self.tcx.opt_def_kind(local_id) { + Some((fields, of)) + } else { + None } + } else { + None + }; + + // If the function is a tuple constructor, we recommend that they call it + if let Some((fields, kind)) = suggest { + suggest_call_constructor(expr.span, kind, fields.len(), &mut err); + } else { + // General case + err.span_label( + expr.span, + "this is a function, perhaps you wish to call it", + ); } } } diff --git a/compiler/rustc_typeck/src/check/mod.rs b/compiler/rustc_typeck/src/check/mod.rs index 0d5e7b28a4e..f7bb30cd13e 100644 --- a/compiler/rustc_typeck/src/check/mod.rs +++ b/compiler/rustc_typeck/src/check/mod.rs @@ -98,12 +98,15 @@ pub use check::{check_item_type, check_wf_new}; pub use diverges::Diverges; pub use expectation::Expectation; pub use fn_ctxt::*; +use hir::def::CtorOf; pub use inherited::{Inherited, InheritedBuilder}; use crate::astconv::AstConv; use crate::check::gather_locals::GatherLocalsVisitor; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_errors::{pluralize, struct_span_err, Applicability, MultiSpan}; +use rustc_errors::{ + pluralize, struct_span_err, Applicability, DiagnosticBuilder, EmissionGuarantee, MultiSpan, +}; use rustc_hir as hir; use rustc_hir::def::Res; use rustc_hir::def_id::{DefId, LocalDefId}; @@ -988,3 +991,36 @@ fn has_expected_num_generic_args<'tcx>( generics.count() == expected + if generics.has_self { 1 } else { 0 } }) } + +/// Suggests calling the constructor of a tuple struct or enum variant +/// +/// * `snippet` - The snippet of code that references the constructor +/// * `span` - The span of the snippet +/// * `params` - The number of parameters the constructor accepts +/// * `err` - A mutable diagnostic builder to add the suggestion to +fn suggest_call_constructor( + span: Span, + kind: CtorOf, + params: usize, + err: &mut DiagnosticBuilder<'_, G>, +) { + // Note: tuple-structs don't have named fields, so just use placeholders + let args = vec!["_"; params].join(", "); + let applicable = if params > 0 { + Applicability::HasPlaceholders + } else { + // When n = 0, it's an empty-tuple struct/enum variant + // so we trivially know how to construct it + Applicability::MachineApplicable + }; + let kind = match kind { + CtorOf::Struct => "a struct", + CtorOf::Variant => "an enum variant", + }; + err.span_label(span, &format!("this is the constructor of {kind}")); + err.multipart_suggestion( + "call the constructor", + vec![(span.shrink_to_lo(), "(".to_string()), (span.shrink_to_hi(), format!(")({args})"))], + applicable, + ); +} diff --git a/src/test/ui/functions-closures/fn-help-with-err.rs b/src/test/ui/functions-closures/fn-help-with-err.rs index f8a81af786f..3d2bcb8ad35 100644 --- a/src/test/ui/functions-closures/fn-help-with-err.rs +++ b/src/test/ui/functions-closures/fn-help-with-err.rs @@ -3,14 +3,14 @@ fn main() { let arc = std::sync::Arc::new(oops); //~^ ERROR cannot find value `oops` in this scope //~| NOTE not found - // The error "note: `arc` is a function, perhaps you wish to call it" MUST NOT appear. + // The error "note: this is a function, perhaps you wish to call it" MUST NOT appear. arc.blablabla(); //~^ ERROR no method named `blablabla` //~| NOTE method not found let arc2 = std::sync::Arc::new(|| 1); - // The error "note: `arc2` is a function, perhaps you wish to call it" SHOULD appear + // The error "note: this is a function, perhaps you wish to call it" SHOULD appear arc2.blablabla(); //~^ ERROR no method named `blablabla` //~| NOTE method not found - //~| NOTE `arc2` is a function, perhaps you wish to call it + //~| NOTE this is a function, perhaps you wish to call it } diff --git a/src/test/ui/functions-closures/fn-help-with-err.stderr b/src/test/ui/functions-closures/fn-help-with-err.stderr index 4d6b3282ad9..3e42cb1fb6e 100644 --- a/src/test/ui/functions-closures/fn-help-with-err.stderr +++ b/src/test/ui/functions-closures/fn-help-with-err.stderr @@ -14,9 +14,9 @@ error[E0599]: no method named `blablabla` found for struct `Arc<[closure@$DIR/fn --> $DIR/fn-help-with-err.rs:12:10 | LL | arc2.blablabla(); - | ^^^^^^^^^ method not found in `Arc<[closure@$DIR/fn-help-with-err.rs:10:36: 10:40]>` - | - = note: `arc2` is a function, perhaps you wish to call it + | ---- ^^^^^^^^^ method not found in `Arc<[closure@$DIR/fn-help-with-err.rs:10:36: 10:40]>` + | | + | this is a function, perhaps you wish to call it error: aborting due to 3 previous errors diff --git a/src/test/ui/issues/issue-29124.stderr b/src/test/ui/issues/issue-29124.stderr index 42d89cd01a4..c5d2ec08409 100644 --- a/src/test/ui/issues/issue-29124.stderr +++ b/src/test/ui/issues/issue-29124.stderr @@ -2,17 +2,17 @@ error[E0599]: no method named `x` found for fn item `fn() -> Ret {Obj::func}` in --> $DIR/issue-29124.rs:15:15 | LL | Obj::func.x(); - | ^ method not found in `fn() -> Ret {Obj::func}` - | - = note: `Obj::func` is a function, perhaps you wish to call it + | --------- ^ method not found in `fn() -> Ret {Obj::func}` + | | + | this is a function, perhaps you wish to call it error[E0599]: no method named `x` found for fn item `fn() -> Ret {func}` in the current scope --> $DIR/issue-29124.rs:17:10 | LL | func.x(); - | ^ method not found in `fn() -> Ret {func}` - | - = note: `func` is a function, perhaps you wish to call it + | ---- ^ method not found in `fn() -> Ret {func}` + | | + | this is a function, perhaps you wish to call it error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-57362-1.stderr b/src/test/ui/issues/issue-57362-1.stderr index 5c611cd43d3..8e19f14009a 100644 --- a/src/test/ui/issues/issue-57362-1.stderr +++ b/src/test/ui/issues/issue-57362-1.stderr @@ -2,9 +2,10 @@ error[E0599]: no method named `f` found for fn pointer `fn(&u8)` in the current --> $DIR/issue-57362-1.rs:20:7 | LL | a.f(); - | ^ method not found in `fn(&u8)` + | - ^ method not found in `fn(&u8)` + | | + | this is a function, perhaps you wish to call it | - = note: `a` is a function, perhaps you wish to call it = help: items from traits can only be used if the trait is implemented and in scope note: `Trait` defines an item `f`, perhaps you need to implement it --> $DIR/issue-57362-1.rs:8:1 diff --git a/src/test/ui/typeck/issue-87181/empty-tuple-method.rs b/src/test/ui/typeck/issue-87181/empty-tuple-method.rs new file mode 100644 index 00000000000..9f97f7dcadf --- /dev/null +++ b/src/test/ui/typeck/issue-87181/empty-tuple-method.rs @@ -0,0 +1,14 @@ +struct Bar { + bar: T +} + +struct Foo(); +impl Foo { + fn foo() { } +} + +fn main() { + let thing = Bar { bar: Foo }; + thing.bar.foo(); + //~^ ERROR no method named `foo` found for fn item `fn() -> Foo {Foo}` in the current scope [E0599] +} \ No newline at end of file diff --git a/src/test/ui/typeck/issue-87181/empty-tuple-method.stderr b/src/test/ui/typeck/issue-87181/empty-tuple-method.stderr new file mode 100644 index 00000000000..6ed70b301e4 --- /dev/null +++ b/src/test/ui/typeck/issue-87181/empty-tuple-method.stderr @@ -0,0 +1,16 @@ +error[E0599]: no method named `foo` found for fn item `fn() -> Foo {Foo}` in the current scope + --> $DIR/empty-tuple-method.rs:12:15 + | +LL | thing.bar.foo(); + | --------- ^^^ method not found in `fn() -> Foo {Foo}` + | | + | this is the constructor of a struct + | +help: call the constructor + | +LL | (thing.bar)().foo(); + | + +++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/ui/typeck/issue-87181/enum-variant.rs b/src/test/ui/typeck/issue-87181/enum-variant.rs new file mode 100644 index 00000000000..fcc89d9f07d --- /dev/null +++ b/src/test/ui/typeck/issue-87181/enum-variant.rs @@ -0,0 +1,16 @@ +struct Bar { + bar: T +} + +enum Foo{ + Tup() +} +impl Foo { + fn foo() { } +} + +fn main() { + let thing = Bar { bar: Foo::Tup }; + thing.bar.foo(); + //~^ ERROR no method named `foo` found for fn item `fn() -> Foo {Foo::Tup}` in the current scope [E0599] +} \ No newline at end of file diff --git a/src/test/ui/typeck/issue-87181/enum-variant.stderr b/src/test/ui/typeck/issue-87181/enum-variant.stderr new file mode 100644 index 00000000000..a3a818696ab --- /dev/null +++ b/src/test/ui/typeck/issue-87181/enum-variant.stderr @@ -0,0 +1,16 @@ +error[E0599]: no method named `foo` found for fn item `fn() -> Foo {Foo::Tup}` in the current scope + --> $DIR/enum-variant.rs:14:15 + | +LL | thing.bar.foo(); + | --------- ^^^ method not found in `fn() -> Foo {Foo::Tup}` + | | + | this is the constructor of an enum variant + | +help: call the constructor + | +LL | (thing.bar)().foo(); + | + +++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/ui/typeck/issue-87181/tuple-field.rs b/src/test/ui/typeck/issue-87181/tuple-field.rs new file mode 100644 index 00000000000..ff1355160bd --- /dev/null +++ b/src/test/ui/typeck/issue-87181/tuple-field.rs @@ -0,0 +1,14 @@ +struct Bar { + bar: T +} + +struct Foo(char, u16); +impl Foo { + fn foo() { } +} + +fn main() { + let thing = Bar { bar: Foo }; + thing.bar.0; + //~^ ERROR no field `0` on type `fn(char, u16) -> Foo {Foo}` [E0609] +} \ No newline at end of file diff --git a/src/test/ui/typeck/issue-87181/tuple-field.stderr b/src/test/ui/typeck/issue-87181/tuple-field.stderr new file mode 100644 index 00000000000..4d22ada0247 --- /dev/null +++ b/src/test/ui/typeck/issue-87181/tuple-field.stderr @@ -0,0 +1,16 @@ +error[E0609]: no field `0` on type `fn(char, u16) -> Foo {Foo}` + --> $DIR/tuple-field.rs:12:15 + | +LL | thing.bar.0; + | --------- ^ + | | + | this is the constructor of a struct + | +help: call the constructor + | +LL | (thing.bar)(_, _).0; + | + +++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0609`. diff --git a/src/test/ui/typeck/issue-87181/tuple-method.rs b/src/test/ui/typeck/issue-87181/tuple-method.rs new file mode 100644 index 00000000000..e0eadde35ce --- /dev/null +++ b/src/test/ui/typeck/issue-87181/tuple-method.rs @@ -0,0 +1,14 @@ +struct Bar { + bar: T +} + +struct Foo(u8, i32); +impl Foo { + fn foo() { } +} + +fn main() { + let thing = Bar { bar: Foo }; + thing.bar.foo(); + //~^ ERROR no method named `foo` found for fn item `fn(u8, i32) -> Foo {Foo}` in the current scope [E0599] +} \ No newline at end of file diff --git a/src/test/ui/typeck/issue-87181/tuple-method.stderr b/src/test/ui/typeck/issue-87181/tuple-method.stderr new file mode 100644 index 00000000000..1e392e17984 --- /dev/null +++ b/src/test/ui/typeck/issue-87181/tuple-method.stderr @@ -0,0 +1,16 @@ +error[E0599]: no method named `foo` found for fn item `fn(u8, i32) -> Foo {Foo}` in the current scope + --> $DIR/tuple-method.rs:12:15 + | +LL | thing.bar.foo(); + | --------- ^^^ method not found in `fn(u8, i32) -> Foo {Foo}` + | | + | this is the constructor of a struct + | +help: call the constructor + | +LL | (thing.bar)(_, _).foo(); + | + +++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/ui/unboxed-closures/unboxed-closures-static-call-wrong-trait.stderr b/src/test/ui/unboxed-closures/unboxed-closures-static-call-wrong-trait.stderr index 0b6d94e71f0..e9883903674 100644 --- a/src/test/ui/unboxed-closures/unboxed-closures-static-call-wrong-trait.stderr +++ b/src/test/ui/unboxed-closures/unboxed-closures-static-call-wrong-trait.stderr @@ -2,9 +2,9 @@ error[E0599]: no method named `call` found for closure `[closure@$DIR/unboxed-cl --> $DIR/unboxed-closures-static-call-wrong-trait.rs:7:10 | LL | mut_.call((0, )); - | ^^^^ method not found in `[closure@$DIR/unboxed-closures-static-call-wrong-trait.rs:6:26: 6:31]` - | - = note: `mut_` is a function, perhaps you wish to call it + | ---- ^^^^ method not found in `[closure@$DIR/unboxed-closures-static-call-wrong-trait.rs:6:26: 6:31]` + | | + | this is a function, perhaps you wish to call it error: aborting due to previous error -- cgit 1.4.1-3-g733a5 From a6b570b209d4806cf0f6e424145ab33bc42da6be Mon Sep 17 00:00:00 2001 From: George <33588728+George-lewis@users.noreply.github.com> Date: Tue, 26 Apr 2022 17:05:49 -0400 Subject: Tidy --- src/test/ui/typeck/issue-87181/empty-tuple-method.rs | 2 +- src/test/ui/typeck/issue-87181/enum-variant.rs | 2 +- src/test/ui/typeck/issue-87181/tuple-field.rs | 2 +- src/test/ui/typeck/issue-87181/tuple-method.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/test/ui/typeck/issue-87181/empty-tuple-method.rs b/src/test/ui/typeck/issue-87181/empty-tuple-method.rs index 9f97f7dcadf..1875d8280cb 100644 --- a/src/test/ui/typeck/issue-87181/empty-tuple-method.rs +++ b/src/test/ui/typeck/issue-87181/empty-tuple-method.rs @@ -11,4 +11,4 @@ fn main() { let thing = Bar { bar: Foo }; thing.bar.foo(); //~^ ERROR no method named `foo` found for fn item `fn() -> Foo {Foo}` in the current scope [E0599] -} \ No newline at end of file +} diff --git a/src/test/ui/typeck/issue-87181/enum-variant.rs b/src/test/ui/typeck/issue-87181/enum-variant.rs index fcc89d9f07d..3b926b90f10 100644 --- a/src/test/ui/typeck/issue-87181/enum-variant.rs +++ b/src/test/ui/typeck/issue-87181/enum-variant.rs @@ -13,4 +13,4 @@ fn main() { let thing = Bar { bar: Foo::Tup }; thing.bar.foo(); //~^ ERROR no method named `foo` found for fn item `fn() -> Foo {Foo::Tup}` in the current scope [E0599] -} \ No newline at end of file +} diff --git a/src/test/ui/typeck/issue-87181/tuple-field.rs b/src/test/ui/typeck/issue-87181/tuple-field.rs index ff1355160bd..00e3b460ecf 100644 --- a/src/test/ui/typeck/issue-87181/tuple-field.rs +++ b/src/test/ui/typeck/issue-87181/tuple-field.rs @@ -11,4 +11,4 @@ fn main() { let thing = Bar { bar: Foo }; thing.bar.0; //~^ ERROR no field `0` on type `fn(char, u16) -> Foo {Foo}` [E0609] -} \ No newline at end of file +} diff --git a/src/test/ui/typeck/issue-87181/tuple-method.rs b/src/test/ui/typeck/issue-87181/tuple-method.rs index e0eadde35ce..e88f642b070 100644 --- a/src/test/ui/typeck/issue-87181/tuple-method.rs +++ b/src/test/ui/typeck/issue-87181/tuple-method.rs @@ -11,4 +11,4 @@ fn main() { let thing = Bar { bar: Foo }; thing.bar.foo(); //~^ ERROR no method named `foo` found for fn item `fn(u8, i32) -> Foo {Foo}` in the current scope [E0599] -} \ No newline at end of file +} -- cgit 1.4.1-3-g733a5