From bfd16ab109dcdaf1a7ddfef9f1f39e9e5f2218df Mon Sep 17 00:00:00 2001 From: Donald Hoskins Date: Wed, 9 Feb 2022 10:24:53 -0500 Subject: [PATCH 01/15] mips64-openwrt-linux-musl: correct soft-foat MIPS64 targets under OpenWrt require soft-float fpu support. Rust-lang requires soft-float defined in tuple definition and isn't over-ridden by toolchain compile-time CFLAGS/LDFLAGS Set explicit soft-float for tuple. Signed-off-by: Donald Hoskins --- compiler/rustc_target/src/spec/mips64_openwrt_linux_musl.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_target/src/spec/mips64_openwrt_linux_musl.rs b/compiler/rustc_target/src/spec/mips64_openwrt_linux_musl.rs index 1199ed44202f9..5991cd8bfa90a 100644 --- a/compiler/rustc_target/src/spec/mips64_openwrt_linux_musl.rs +++ b/compiler/rustc_target/src/spec/mips64_openwrt_linux_musl.rs @@ -6,7 +6,7 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { let mut base = super::linux_musl_base::opts(); base.cpu = "mips64r2".to_string(); - base.features = "+mips64r2".to_string(); + base.features = "+mips64r2,+soft-float".to_string(); base.max_atomic_width = Some(64); base.crt_static_default = false; From 64406c5996a0775493c8a2acd457e612bd84cde6 Mon Sep 17 00:00:00 2001 From: Tomoaki Kawada Date: Thu, 10 Feb 2022 13:10:25 +0900 Subject: [PATCH 02/15] kmc-solid: Use the filesystem thread-safety wrapper Neither the SOLID filesystem API nor built-in filesystems guarantee thread safety by default. Although this may suffice in general embedded- system use cases, and in fact the API can be used from multiple threads without any problems in many cases, this has been a source of unsoundness in `std::sys::solid::fs`. This commit updates the `std` code to leverage the filesystem thread- safety wrapper to enforce thread safety. This is done by prefixing all paths passed to the filesystem API with `\TS`. (Note that relative paths aren't supported in this platform.) --- library/std/src/sys/solid/fs.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/library/std/src/sys/solid/fs.rs b/library/std/src/sys/solid/fs.rs index a6ed10f7789d2..a2cbee4dcf07b 100644 --- a/library/std/src/sys/solid/fs.rs +++ b/library/std/src/sys/solid/fs.rs @@ -289,7 +289,26 @@ impl OpenOptions { } fn cstr(path: &Path) -> io::Result { - Ok(CString::new(path.as_os_str().as_bytes())?) + let path = path.as_os_str().as_bytes(); + + if !path.starts_with(br"\") { + // Relative paths aren't supported + return Err(crate::io::const_io_error!( + crate::io::ErrorKind::Unsupported, + "relative path is not supported on this platform", + )); + } + + // Apply the thread-safety wrapper + const SAFE_PREFIX: &[u8] = br"\TS"; + let wrapped_path = [SAFE_PREFIX, &path, &[0]].concat(); + + CString::from_vec_with_nul(wrapped_path).map_err(|_| { + crate::io::const_io_error!( + io::ErrorKind::InvalidInput, + "path provided contains a nul byte", + ) + }) } impl File { From 784c7a6cadf218b518734c4f21690334401ff83a Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 10 Feb 2022 22:45:58 -0800 Subject: [PATCH 03/15] only mark projection as ambiguous if GAT substs are constrained --- .../rustc_infer/src/infer/type_variable.rs | 2 +- .../src/traits/project.rs | 57 +++++++++---------- .../src/traits/select/mod.rs | 27 ++++++++- .../generic-associated-types/issue-74824.rs | 1 - .../issue-74824.stderr | 11 +--- .../generic-associated-types/issue-93874.rs | 35 ++++++++++++ 6 files changed, 89 insertions(+), 44 deletions(-) create mode 100644 src/test/ui/generic-associated-types/issue-93874.rs diff --git a/compiler/rustc_infer/src/infer/type_variable.rs b/compiler/rustc_infer/src/infer/type_variable.rs index 82970f214fa66..6a968005f3eaa 100644 --- a/compiler/rustc_infer/src/infer/type_variable.rs +++ b/compiler/rustc_infer/src/infer/type_variable.rs @@ -259,7 +259,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> { let index = self.values().push(TypeVariableData { origin }); assert_eq!(eq_key.vid.as_u32(), index as u32); - debug!("new_var(index={:?}, universe={:?}, origin={:?}", eq_key.vid, universe, origin,); + debug!("new_var(index={:?}, universe={:?}, origin={:?})", eq_key.vid, universe, origin); eq_key.vid } diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 36cc14610cb4b..a8d15d98eea57 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -1073,16 +1073,6 @@ fn project<'cx, 'tcx>( return Ok(Projected::Progress(Progress::error(selcx.tcx()))); } - // If the obligation contains any inference types or consts in associated - // type substs, then we don't assemble any candidates. - // This isn't really correct, but otherwise we can end up in a case where - // we constrain inference variables by selecting a single predicate, when - // we need to stay general. See issue #91762. - let (_, predicate_own_substs) = obligation.predicate.trait_ref_and_own_substs(selcx.tcx()); - if predicate_own_substs.iter().any(|g| g.has_infer_types_or_consts()) { - return Err(ProjectionError::TooManyCandidates); - } - let mut candidates = ProjectionCandidateSet::None; // Make sure that the following procedures are kept in order. ParamEnv @@ -1180,7 +1170,7 @@ fn assemble_candidates_from_trait_def<'cx, 'tcx>( ProjectionCandidate::TraitDef, bounds.iter(), true, - ) + ); } /// In the case of a trait object like @@ -1245,27 +1235,34 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>( let bound_predicate = predicate.kind(); if let ty::PredicateKind::Projection(data) = predicate.kind().skip_binder() { let data = bound_predicate.rebind(data); - let same_def_id = data.projection_def_id() == obligation.predicate.item_def_id; - - let is_match = same_def_id - && infcx.probe(|_| { - selcx.match_projection_projections( - obligation, - data, - potentially_unnormalized_candidates, - ) - }); + if data.projection_def_id() != obligation.predicate.item_def_id { + continue; + } - if is_match { - candidate_set.push_candidate(ctor(data)); + let is_match = infcx.probe(|_| { + selcx.match_projection_projections( + obligation, + data, + potentially_unnormalized_candidates, + ) + }); - if potentially_unnormalized_candidates - && !obligation.predicate.has_infer_types_or_consts() - { - // HACK: Pick the first trait def candidate for a fully - // inferred predicate. This is to allow duplicates that - // differ only in normalization. - return; + match is_match { + Some(true) => { + candidate_set.push_candidate(ctor(data)); + + if potentially_unnormalized_candidates + && !obligation.predicate.has_infer_types_or_consts() + { + // HACK: Pick the first trait def candidate for a fully + // inferred predicate. This is to allow duplicates that + // differ only in normalization. + return; + } + } + Some(false) => {} + None => { + candidate_set.mark_ambiguous(); } } } diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index a183a20a2fed0..4ca60a65485c5 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1508,12 +1508,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { }) } + /// Return Some(true) if the obligation's predicate type applies to the env_predicate, and + /// Some(false) if it does not. Returns None in the case that the projection type is a GAT, + /// and applying this env_predicate constrains any of the obligation's GAT substitutions. pub(super) fn match_projection_projections( &mut self, obligation: &ProjectionTyObligation<'tcx>, env_predicate: PolyProjectionPredicate<'tcx>, potentially_unnormalized_candidates: bool, - ) -> bool { + ) -> Option { let mut nested_obligations = Vec::new(); let (infer_predicate, _) = self.infcx.replace_bound_vars_with_fresh_vars( obligation.cause.span, @@ -1535,7 +1538,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { infer_predicate.projection_ty }; - self.infcx + let is_match = self + .infcx .at(&obligation.cause, obligation.param_env) .define_opaque_types(false) .sup(obligation.predicate, infer_projection) @@ -1545,7 +1549,24 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { nested_obligations.into_iter().chain(obligations), ) .map_or(false, |res| res.may_apply()) - }) + }); + + if is_match { + let generics = self.tcx().generics_of(obligation.predicate.item_def_id); + if !generics.params.is_empty() { + // If any of the obligation's predicate substs shallow-resolve to + // something new, that means that we must have newly inferred something + // about the GAT. We should give up with ambiguity in that case. + if obligation.predicate.substs[generics.parent_count..] + .iter() + .any(|&p| p.has_infer_types_or_consts() && self.infcx.shallow_resolve(p) != p) + { + return None; + } + } + } + + Some(is_match) } /////////////////////////////////////////////////////////////////////////// diff --git a/src/test/ui/generic-associated-types/issue-74824.rs b/src/test/ui/generic-associated-types/issue-74824.rs index 01f99fa448749..1bbf7aac5cdab 100644 --- a/src/test/ui/generic-associated-types/issue-74824.rs +++ b/src/test/ui/generic-associated-types/issue-74824.rs @@ -17,7 +17,6 @@ impl UnsafeCopy for T {} fn main() { let b = Box::new(42usize); let copy = <()>::copy(&b); - //~^ type annotations needed let raw_b = Box::deref(&b) as *const _; let raw_copy = Box::deref(©) as *const _; diff --git a/src/test/ui/generic-associated-types/issue-74824.stderr b/src/test/ui/generic-associated-types/issue-74824.stderr index e7ebf5964ba41..8517eb9fa2102 100644 --- a/src/test/ui/generic-associated-types/issue-74824.stderr +++ b/src/test/ui/generic-associated-types/issue-74824.stderr @@ -27,13 +27,6 @@ help: consider restricting type parameter `T` LL | type Copy: Copy = Box; | +++++++++++++++++++ -error[E0282]: type annotations needed - --> $DIR/issue-74824.rs:19:16 - | -LL | let copy = <()>::copy(&b); - | ^^^^^^^^^^ cannot infer type for type parameter `T` declared on the associated function `copy` - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors -Some errors have detailed explanations: E0277, E0282. -For more information about an error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/generic-associated-types/issue-93874.rs b/src/test/ui/generic-associated-types/issue-93874.rs new file mode 100644 index 0000000000000..f403d75167d8a --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-93874.rs @@ -0,0 +1,35 @@ +// check-pass + +#![feature(generic_associated_types)] + +pub trait Build { + type Output; + fn build(self, input: O) -> Self::Output; +} + +pub struct IdentityBuild; +impl Build for IdentityBuild { + type Output = O; + fn build(self, input: O) -> Self::Output { + input + } +} + +fn a() { + let _x: u8 = IdentityBuild.build(10); +} + +fn b() { + let _x: Vec = IdentityBuild.build(Vec::new()); +} + +fn c() { + let mut f = IdentityBuild.build(|| ()); + (f)(); +} + +pub fn main() { + a(); + b(); + c(); +} From fbbcb089c52e6dce88600be36a1cc97884294d4f Mon Sep 17 00:00:00 2001 From: Will Crichton Date: Fri, 11 Feb 2022 21:48:59 -0800 Subject: [PATCH 04/15] Add --scrape-tests flags so rustdoc can scrape examples from tests --- src/doc/rustdoc/src/unstable-features.md | 3 +++ src/librustdoc/core.rs | 3 +++ src/librustdoc/lib.rs | 3 +++ src/librustdoc/scrape_examples.rs | 15 +++++++++++---- .../rustdoc-scrape-examples-multiple/scrape.mk | 3 ++- .../rustdoc-scrape-examples-test/Makefile | 6 ++++++ .../rustdoc-scrape-examples-test/examples/ex.rs | 6 ++++++ .../rustdoc-scrape-examples-test/src/lib.rs | 3 +++ 8 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 src/test/run-make/rustdoc-scrape-examples-test/Makefile create mode 100644 src/test/run-make/rustdoc-scrape-examples-test/examples/ex.rs create mode 100644 src/test/run-make/rustdoc-scrape-examples-test/src/lib.rs diff --git a/src/doc/rustdoc/src/unstable-features.md b/src/doc/rustdoc/src/unstable-features.md index d60be193bda2b..c7fd5ed6fcb2e 100644 --- a/src/doc/rustdoc/src/unstable-features.md +++ b/src/doc/rustdoc/src/unstable-features.md @@ -509,3 +509,6 @@ reverse-dependency like `examples/ex.rs` is given to rustdoc with the target crate being documented (`foobar`) and a path to output the calls (`output.calls`). Then, the generated calls file can be passed via `--with-examples` to the subsequent documentation of `foobar`. + +To scrape examples from test code, e.g. functions marked `#[test]`, then +add the `--scrape-tests` flag. diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 1f14a333c005d..955572850c6e8 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -200,6 +200,7 @@ crate fn create_config( lint_opts, describe_lints, lint_cap, + scrape_examples_options, .. }: RustdocOptions, ) -> rustc_interface::Config { @@ -227,6 +228,7 @@ crate fn create_config( let crate_types = if proc_macro_crate { vec![CrateType::ProcMacro] } else { vec![CrateType::Rlib] }; + let test = scrape_examples_options.map(|opts| opts.scrape_tests).unwrap_or(false); // plays with error output here! let sessopts = config::Options { maybe_sysroot, @@ -244,6 +246,7 @@ crate fn create_config( edition, describe_lints, crate_name, + test, ..Options::default() }; diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 68028604fa463..dbd0168284251 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -596,6 +596,9 @@ fn opts() -> Vec { "collect function call information for functions from the target crate", ) }), + unstable("scrape-tests", |o| { + o.optflag("", "scrape-tests", "Include test code when scraping examples") + }), unstable("with-examples", |o| { o.optmulti( "", diff --git a/src/librustdoc/scrape_examples.rs b/src/librustdoc/scrape_examples.rs index 16882cf83d09c..80292b208663d 100644 --- a/src/librustdoc/scrape_examples.rs +++ b/src/librustdoc/scrape_examples.rs @@ -34,6 +34,7 @@ use std::path::PathBuf; crate struct ScrapeExamplesOptions { output_path: PathBuf, target_crates: Vec, + crate scrape_tests: bool, } impl ScrapeExamplesOptions { @@ -43,16 +44,22 @@ impl ScrapeExamplesOptions { ) -> Result, i32> { let output_path = matches.opt_str("scrape-examples-output-path"); let target_crates = matches.opt_strs("scrape-examples-target-crate"); - match (output_path, !target_crates.is_empty()) { - (Some(output_path), true) => Ok(Some(ScrapeExamplesOptions { + let scrape_tests = matches.opt_present("scrape-tests"); + match (output_path, !target_crates.is_empty(), scrape_tests) { + (Some(output_path), true, _) => Ok(Some(ScrapeExamplesOptions { output_path: PathBuf::from(output_path), target_crates, + scrape_tests, })), - (Some(_), false) | (None, true) => { + (Some(_), false, _) | (None, true, _) => { diag.err("must use --scrape-examples-output-path and --scrape-examples-target-crate together"); Err(1) } - (None, false) => Ok(None), + (None, false, true) => { + diag.err("must use --scrape-examples-output-path and --scrape-examples-target-crate with --scrape-tests"); + Err(1) + } + (None, false, false) => Ok(None), } } } diff --git a/src/test/run-make/rustdoc-scrape-examples-multiple/scrape.mk b/src/test/run-make/rustdoc-scrape-examples-multiple/scrape.mk index 1fa1fae1a0b71..d49b6c1f290cb 100644 --- a/src/test/run-make/rustdoc-scrape-examples-multiple/scrape.mk +++ b/src/test/run-make/rustdoc-scrape-examples-multiple/scrape.mk @@ -7,7 +7,8 @@ $(TMPDIR)/%.calls: $(TMPDIR)/libfoobar.rmeta --extern foobar=$(TMPDIR)/libfoobar.rmeta \ -Z unstable-options \ --scrape-examples-output-path $@ \ - --scrape-examples-target-crate foobar + --scrape-examples-target-crate foobar \ + $(extra_flags) $(TMPDIR)/lib%.rmeta: src/lib.rs $(RUSTC) src/lib.rs --crate-name $* --crate-type lib --emit=metadata diff --git a/src/test/run-make/rustdoc-scrape-examples-test/Makefile b/src/test/run-make/rustdoc-scrape-examples-test/Makefile new file mode 100644 index 0000000000000..9f80a8d96022f --- /dev/null +++ b/src/test/run-make/rustdoc-scrape-examples-test/Makefile @@ -0,0 +1,6 @@ +extra_flags := --scrape-tests +deps := ex + +-include ../rustdoc-scrape-examples-multiple/scrape.mk + +all: scrape diff --git a/src/test/run-make/rustdoc-scrape-examples-test/examples/ex.rs b/src/test/run-make/rustdoc-scrape-examples-test/examples/ex.rs new file mode 100644 index 0000000000000..d1a9a74e7825c --- /dev/null +++ b/src/test/run-make/rustdoc-scrape-examples-test/examples/ex.rs @@ -0,0 +1,6 @@ +fn main() {} + +#[test] +fn a_test() { + foobar::ok(); +} diff --git a/src/test/run-make/rustdoc-scrape-examples-test/src/lib.rs b/src/test/run-make/rustdoc-scrape-examples-test/src/lib.rs new file mode 100644 index 0000000000000..22be1ad41010f --- /dev/null +++ b/src/test/run-make/rustdoc-scrape-examples-test/src/lib.rs @@ -0,0 +1,3 @@ +// @has foobar/fn.ok.html '//*[@class="docblock scraped-example-list"]' '' + +pub fn ok() {} From 7c6ff4b269a588ddd39f80fa443d3cd161cfc88b Mon Sep 17 00:00:00 2001 From: Jack Huey <31162821+jackh726@users.noreply.github.com> Date: Sat, 12 Feb 2022 14:39:58 -0500 Subject: [PATCH 05/15] Add the known-bug compiletest prop --- src/tools/compiletest/src/header.rs | 15 +++++++++++++++ src/tools/compiletest/src/runtest.rs | 9 ++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index da7a19139c65b..82630c7a2f946 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -126,6 +126,12 @@ pub struct TestProps { // empty before the test starts. Incremental mode tests will reuse the // incremental directory between passes in the same test. pub incremental: bool, + // If `true`, this test is a known bug. + // + // When set, some requirements are relaxed. Currently, this only means no + // error annotations are needed, but this may be updated in the future to + // include other relaxations. + pub known_bug: bool, // How far should the test proceed while still passing. pass_mode: Option, // Ignore `--pass` overrides from the command line for this test. @@ -176,6 +182,7 @@ impl TestProps { forbid_output: vec![], incremental_dir: None, incremental: false, + known_bug: false, pass_mode: None, fail_mode: None, ignore_pass: false, @@ -362,6 +369,10 @@ impl TestProps { if !self.incremental { self.incremental = config.parse_incremental(ln); } + + if !self.known_bug { + self.known_bug = config.parse_known_bug(ln); + } }); } @@ -751,6 +762,10 @@ impl Config { fn parse_incremental(&self, line: &str) -> bool { self.parse_name_directive(line, "incremental") } + + fn parse_known_bug(&self, line: &str) -> bool { + self.parse_name_directive(line, "known-bug") + } } fn expand_variables(mut value: String, config: &Config) -> String { diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index f6ddac3a65e06..03f8256d5e324 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1310,7 +1310,14 @@ impl<'test> TestCx<'test> { } None => { - if self.is_unexpected_compiler_message(actual_error, expect_help, expect_note) { + // If the test is a known bug, don't require that the error is annotated + if !self.props.known_bug + && self.is_unexpected_compiler_message( + actual_error, + expect_help, + expect_note, + ) + { self.error(&format!( "{}:{}: unexpected {}: '{}'", file_name, From e660d52e3ddcea7c45070526064a45f5a1964366 Mon Sep 17 00:00:00 2001 From: Jack Huey <31162821+jackh726@users.noreply.github.com> Date: Sat, 12 Feb 2022 14:48:07 -0500 Subject: [PATCH 06/15] Use known-bug prop for GAT bug tests --- src/test/ui/generic-associated-types/bugs/issue-80626.rs | 2 +- .../ui/generic-associated-types/bugs/issue-80626.stderr | 2 +- src/test/ui/generic-associated-types/bugs/issue-86218.rs | 2 +- .../ui/generic-associated-types/bugs/issue-86218.stderr | 4 ++-- src/test/ui/generic-associated-types/bugs/issue-87735.rs | 3 ++- .../ui/generic-associated-types/bugs/issue-87735.stderr | 2 +- src/test/ui/generic-associated-types/bugs/issue-87748.rs | 3 ++- .../ui/generic-associated-types/bugs/issue-87748.stderr | 6 +++--- src/test/ui/generic-associated-types/bugs/issue-87755.rs | 2 +- .../ui/generic-associated-types/bugs/issue-87755.stderr | 2 +- src/test/ui/generic-associated-types/bugs/issue-87803.rs | 3 ++- .../ui/generic-associated-types/bugs/issue-87803.stderr | 2 +- src/test/ui/generic-associated-types/bugs/issue-88382.rs | 2 +- .../ui/generic-associated-types/bugs/issue-88382.stderr | 4 ++-- src/test/ui/generic-associated-types/bugs/issue-88460.rs | 2 +- .../ui/generic-associated-types/bugs/issue-88460.stderr | 4 ++-- src/test/ui/generic-associated-types/bugs/issue-88526.rs | 3 ++- .../ui/generic-associated-types/bugs/issue-88526.stderr | 2 +- src/test/ui/generic-associated-types/bugs/issue-89008.rs | 5 +++-- .../ui/generic-associated-types/bugs/issue-89008.stderr | 4 ++-- 20 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/test/ui/generic-associated-types/bugs/issue-80626.rs b/src/test/ui/generic-associated-types/bugs/issue-80626.rs index aea8aaf4bb393..a637da6cf6fa7 100644 --- a/src/test/ui/generic-associated-types/bugs/issue-80626.rs +++ b/src/test/ui/generic-associated-types/bugs/issue-80626.rs @@ -1,4 +1,5 @@ // check-fail +// known-bug // This should pass, but it requires `Sized` to be coinductive. @@ -11,7 +12,6 @@ trait Allocator { enum LinkedList { Head, Next(A::Allocated) - //~^ overflow } fn main() {} diff --git a/src/test/ui/generic-associated-types/bugs/issue-80626.stderr b/src/test/ui/generic-associated-types/bugs/issue-80626.stderr index e18af9c257f7f..8b0cc78e99949 100644 --- a/src/test/ui/generic-associated-types/bugs/issue-80626.stderr +++ b/src/test/ui/generic-associated-types/bugs/issue-80626.stderr @@ -1,5 +1,5 @@ error[E0275]: overflow evaluating the requirement `LinkedList: Sized` - --> $DIR/issue-80626.rs:13:10 + --> $DIR/issue-80626.rs:14:10 | LL | Next(A::Allocated) | ^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/generic-associated-types/bugs/issue-86218.rs b/src/test/ui/generic-associated-types/bugs/issue-86218.rs index 3f8776a363770..68cd0fd7efce0 100644 --- a/src/test/ui/generic-associated-types/bugs/issue-86218.rs +++ b/src/test/ui/generic-associated-types/bugs/issue-86218.rs @@ -1,4 +1,5 @@ // check-fail +// known-bug // This should pass, but seems to run into a TAIT issue. @@ -20,7 +21,6 @@ trait Yay { impl<'a> Yay<&'a ()> for () { type InnerStream<'s> = impl Stream + 's; - //~^ the type fn foo<'s>() -> Self::InnerStream<'s> { todo!() } } diff --git a/src/test/ui/generic-associated-types/bugs/issue-86218.stderr b/src/test/ui/generic-associated-types/bugs/issue-86218.stderr index 9f4efc0addb73..98a5f4254bb1b 100644 --- a/src/test/ui/generic-associated-types/bugs/issue-86218.stderr +++ b/src/test/ui/generic-associated-types/bugs/issue-86218.stderr @@ -1,11 +1,11 @@ error[E0477]: the type `impl Stream` does not fulfill the required lifetime - --> $DIR/issue-86218.rs:22:28 + --> $DIR/issue-86218.rs:23:28 | LL | type InnerStream<'s> = impl Stream + 's; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: type must outlive the lifetime `'s` as defined here as required by this binding - --> $DIR/issue-86218.rs:22:22 + --> $DIR/issue-86218.rs:23:22 | LL | type InnerStream<'s> = impl Stream + 's; | ^^ diff --git a/src/test/ui/generic-associated-types/bugs/issue-87735.rs b/src/test/ui/generic-associated-types/bugs/issue-87735.rs index 5f7a42a740df6..6d6063f8085ba 100644 --- a/src/test/ui/generic-associated-types/bugs/issue-87735.rs +++ b/src/test/ui/generic-associated-types/bugs/issue-87735.rs @@ -1,4 +1,5 @@ // check-fail +// known-bug // This should pass, but we need an extension of implied bounds (probably). @@ -23,7 +24,7 @@ struct Foo(T); #[derive(Debug)] struct FooRef<'a, U>(&'a [U]); -impl<'b, T, U> AsRef2 for Foo //~ the type parameter +impl<'b, T, U> AsRef2 for Foo where // * `for<'b, 'c> T: AsRef2 = &'c [U]>>` does not work // diff --git a/src/test/ui/generic-associated-types/bugs/issue-87735.stderr b/src/test/ui/generic-associated-types/bugs/issue-87735.stderr index 31b3a9619b6af..0a18b5f0cbdaa 100644 --- a/src/test/ui/generic-associated-types/bugs/issue-87735.stderr +++ b/src/test/ui/generic-associated-types/bugs/issue-87735.stderr @@ -1,5 +1,5 @@ error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates - --> $DIR/issue-87735.rs:26:13 + --> $DIR/issue-87735.rs:27:13 | LL | impl<'b, T, U> AsRef2 for Foo | ^ unconstrained type parameter diff --git a/src/test/ui/generic-associated-types/bugs/issue-87748.rs b/src/test/ui/generic-associated-types/bugs/issue-87748.rs index 4dbaf429ead26..ffcfd62cbb3be 100644 --- a/src/test/ui/generic-associated-types/bugs/issue-87748.rs +++ b/src/test/ui/generic-associated-types/bugs/issue-87748.rs @@ -1,4 +1,5 @@ // check-fail +// known-bug // This should pass, but unnormalized input args aren't treated as implied. @@ -14,7 +15,7 @@ struct Foo; impl MyTrait for Foo { type Assoc<'a, 'b> where 'b: 'a = u32; - fn do_sth(_: u32) {} //~ lifetime bound + fn do_sth(_: u32) {} // fn do_sth(_: Self::Assoc<'static, 'static>) {} // fn do_sth(_: Self::Assoc<'_, '_>) {} } diff --git a/src/test/ui/generic-associated-types/bugs/issue-87748.stderr b/src/test/ui/generic-associated-types/bugs/issue-87748.stderr index c38d447859233..60bb48efbc895 100644 --- a/src/test/ui/generic-associated-types/bugs/issue-87748.stderr +++ b/src/test/ui/generic-associated-types/bugs/issue-87748.stderr @@ -1,16 +1,16 @@ error[E0478]: lifetime bound not satisfied - --> $DIR/issue-87748.rs:17:5 + --> $DIR/issue-87748.rs:18:5 | LL | fn do_sth(_: u32) {} | ^^^^^^^^^^^^^^^^^ | note: lifetime parameter instantiated with the anonymous lifetime #2 defined here - --> $DIR/issue-87748.rs:17:5 + --> $DIR/issue-87748.rs:18:5 | LL | fn do_sth(_: u32) {} | ^^^^^^^^^^^^^^^^^ note: but lifetime parameter must outlive the anonymous lifetime #1 defined here - --> $DIR/issue-87748.rs:17:5 + --> $DIR/issue-87748.rs:18:5 | LL | fn do_sth(_: u32) {} | ^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/generic-associated-types/bugs/issue-87755.rs b/src/test/ui/generic-associated-types/bugs/issue-87755.rs index 1cd3534ba77a0..31cea12a3e241 100644 --- a/src/test/ui/generic-associated-types/bugs/issue-87755.rs +++ b/src/test/ui/generic-associated-types/bugs/issue-87755.rs @@ -1,4 +1,5 @@ // check-fail +// known-bug // This should pass. @@ -15,7 +16,6 @@ struct Bar; impl Foo for Bar { type Ass = Bar; - //~^ overflow } fn main() {} diff --git a/src/test/ui/generic-associated-types/bugs/issue-87755.stderr b/src/test/ui/generic-associated-types/bugs/issue-87755.stderr index d2dc991a2b640..5d1aff0117c13 100644 --- a/src/test/ui/generic-associated-types/bugs/issue-87755.stderr +++ b/src/test/ui/generic-associated-types/bugs/issue-87755.stderr @@ -1,5 +1,5 @@ error[E0275]: overflow evaluating the requirement `::Ass == _` - --> $DIR/issue-87755.rs:17:16 + --> $DIR/issue-87755.rs:18:16 | LL | type Ass = Bar; | ^^^ diff --git a/src/test/ui/generic-associated-types/bugs/issue-87803.rs b/src/test/ui/generic-associated-types/bugs/issue-87803.rs index 3d2ff38ab049e..57a4b028d93ea 100644 --- a/src/test/ui/generic-associated-types/bugs/issue-87803.rs +++ b/src/test/ui/generic-associated-types/bugs/issue-87803.rs @@ -1,4 +1,5 @@ // check-fail +// known-bug // This should pass, but using a type alias vs a reference directly // changes late-bound -> early-bound. @@ -18,7 +19,7 @@ impl Scanner for IdScanner { type Input<'a> = &'a str; type Token<'a> = &'a str; - fn scan<'a>(&mut self, s : &'a str) -> &'a str { //~ lifetime parameters + fn scan<'a>(&mut self, s : &'a str) -> &'a str { s } } diff --git a/src/test/ui/generic-associated-types/bugs/issue-87803.stderr b/src/test/ui/generic-associated-types/bugs/issue-87803.stderr index 759c0440d07ba..c81c051d32a89 100644 --- a/src/test/ui/generic-associated-types/bugs/issue-87803.stderr +++ b/src/test/ui/generic-associated-types/bugs/issue-87803.stderr @@ -1,5 +1,5 @@ error[E0195]: lifetime parameters or bounds on method `scan` do not match the trait declaration - --> $DIR/issue-87803.rs:21:12 + --> $DIR/issue-87803.rs:22:12 | LL | fn scan<'a>(&mut self, i : Self::Input<'a>) -> Self::Token<'a>; | ---- lifetimes in impl do not match this method in trait diff --git a/src/test/ui/generic-associated-types/bugs/issue-88382.rs b/src/test/ui/generic-associated-types/bugs/issue-88382.rs index f4633ca516999..c9f342405278a 100644 --- a/src/test/ui/generic-associated-types/bugs/issue-88382.rs +++ b/src/test/ui/generic-associated-types/bugs/issue-88382.rs @@ -1,4 +1,5 @@ // check-fail +// known-bug // This should pass, but has a missed normalization due to HRTB. @@ -25,7 +26,6 @@ fn do_something(i: I, mut f: impl for<'a> Fn(&mut I::Iterator<'a>)) fn main() { do_something(SomeImplementation(), |_| ()); do_something(SomeImplementation(), test); - //~^ type mismatch } fn test<'a, I: Iterable>(_: &mut I::Iterator<'a>) {} diff --git a/src/test/ui/generic-associated-types/bugs/issue-88382.stderr b/src/test/ui/generic-associated-types/bugs/issue-88382.stderr index 05bc58cbba4e6..d06c3ec8de75e 100644 --- a/src/test/ui/generic-associated-types/bugs/issue-88382.stderr +++ b/src/test/ui/generic-associated-types/bugs/issue-88382.stderr @@ -1,5 +1,5 @@ error[E0631]: type mismatch in function arguments - --> $DIR/issue-88382.rs:27:40 + --> $DIR/issue-88382.rs:28:40 | LL | do_something(SomeImplementation(), test); | ------------ ^^^^ expected signature of `for<'a> fn(&mut ::Iterator<'a>) -> _` @@ -10,7 +10,7 @@ LL | fn test<'a, I: Iterable>(_: &mut I::Iterator<'a>) {} | ------------------------------------------------- found signature of `for<'r> fn(&'r mut std::iter::Empty) -> _` | note: required by a bound in `do_something` - --> $DIR/issue-88382.rs:21:56 + --> $DIR/issue-88382.rs:22:56 | LL | fn do_something(i: I, mut f: impl for<'a> Fn(&mut I::Iterator<'a>)) { | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `do_something` diff --git a/src/test/ui/generic-associated-types/bugs/issue-88460.rs b/src/test/ui/generic-associated-types/bugs/issue-88460.rs index 7e62790cc50c3..b31d012d2fc41 100644 --- a/src/test/ui/generic-associated-types/bugs/issue-88460.rs +++ b/src/test/ui/generic-associated-types/bugs/issue-88460.rs @@ -1,4 +1,5 @@ // check-fail +// known-bug // This should pass, but has a missed normalization due to HRTB. @@ -27,5 +28,4 @@ impl Trait for Foo { fn main() { test(Foo); - //~^ the trait bound } diff --git a/src/test/ui/generic-associated-types/bugs/issue-88460.stderr b/src/test/ui/generic-associated-types/bugs/issue-88460.stderr index 604658da7d2c2..0b83e9da1ab7a 100644 --- a/src/test/ui/generic-associated-types/bugs/issue-88460.stderr +++ b/src/test/ui/generic-associated-types/bugs/issue-88460.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `for<'a> <_ as Trait>::Assoc<'a>: Marker` is not satisfied - --> $DIR/issue-88460.rs:29:5 + --> $DIR/issue-88460.rs:30:5 | LL | test(Foo); | ^^^^ the trait `for<'a> Marker` is not implemented for `<_ as Trait>::Assoc<'a>` | note: required by a bound in `test` - --> $DIR/issue-88460.rs:16:27 + --> $DIR/issue-88460.rs:17:27 | LL | fn test(value: T) | ---- required by a bound in this diff --git a/src/test/ui/generic-associated-types/bugs/issue-88526.rs b/src/test/ui/generic-associated-types/bugs/issue-88526.rs index 90568fcb40125..c72a450b9261c 100644 --- a/src/test/ui/generic-associated-types/bugs/issue-88526.rs +++ b/src/test/ui/generic-associated-types/bugs/issue-88526.rs @@ -1,4 +1,5 @@ // check-fail +// known-bug // This should pass, but requires more logic. @@ -23,7 +24,7 @@ struct TestB f: F, } -impl<'q, Q, I, F> A for TestB //~ the type parameter +impl<'q, Q, I, F> A for TestB where Q: A = &'q I>, F: Fn(I), diff --git a/src/test/ui/generic-associated-types/bugs/issue-88526.stderr b/src/test/ui/generic-associated-types/bugs/issue-88526.stderr index ccc5ae0b621a1..127c889bf715e 100644 --- a/src/test/ui/generic-associated-types/bugs/issue-88526.stderr +++ b/src/test/ui/generic-associated-types/bugs/issue-88526.stderr @@ -1,5 +1,5 @@ error[E0207]: the type parameter `I` is not constrained by the impl trait, self type, or predicates - --> $DIR/issue-88526.rs:26:13 + --> $DIR/issue-88526.rs:27:13 | LL | impl<'q, Q, I, F> A for TestB | ^ unconstrained type parameter diff --git a/src/test/ui/generic-associated-types/bugs/issue-89008.rs b/src/test/ui/generic-associated-types/bugs/issue-89008.rs index 5d850849fd21c..1581b7105a867 100644 --- a/src/test/ui/generic-associated-types/bugs/issue-89008.rs +++ b/src/test/ui/generic-associated-types/bugs/issue-89008.rs @@ -1,5 +1,6 @@ // check-fail // edition:2021 +// known-bug // This should pass, but seems to run into a TAIT bug. @@ -31,11 +32,11 @@ trait X { struct Y; impl X for Y { - type LineStream<'a, Repr> = impl Stream; //~ could not find + type LineStream<'a, Repr> = impl Stream; type LineStreamFut<'a, Repr> = impl Future> ; - fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> { //~ type mismatch + fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> { async {empty()} } } diff --git a/src/test/ui/generic-associated-types/bugs/issue-89008.stderr b/src/test/ui/generic-associated-types/bugs/issue-89008.stderr index 48745fe0fbd96..c2687ca540153 100644 --- a/src/test/ui/generic-associated-types/bugs/issue-89008.stderr +++ b/src/test/ui/generic-associated-types/bugs/issue-89008.stderr @@ -1,5 +1,5 @@ error[E0271]: type mismatch resolving ` as Future>::Output == impl Stream` - --> $DIR/issue-89008.rs:38:43 + --> $DIR/issue-89008.rs:39:43 | LL | type LineStream<'a, Repr> = impl Stream; | ------------------------ the expected opaque type @@ -11,7 +11,7 @@ LL | fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> { found struct `Empty<_>` error: could not find defining uses - --> $DIR/issue-89008.rs:34:33 + --> $DIR/issue-89008.rs:35:33 | LL | type LineStream<'a, Repr> = impl Stream; | ^^^^^^^^^^^^^^^^^^^^^^^^ From 5aae6546c0839189bd03d49ef3d92833a9f1b060 Mon Sep 17 00:00:00 2001 From: Jack Huey <31162821+jackh726@users.noreply.github.com> Date: Sat, 12 Feb 2022 18:43:32 -0500 Subject: [PATCH 07/15] Cleanup header parsing by extracting common logic --- src/tools/compiletest/src/header.rs | 397 ++++++++++++---------------- 1 file changed, 168 insertions(+), 229 deletions(-) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 82630c7a2f946..5b8ee9fbdc97e 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -41,12 +41,15 @@ impl EarlyProps { pub fn from_reader(config: &Config, testfile: &Path, rdr: R) -> Self { let mut props = EarlyProps::default(); iter_header(testfile, rdr, &mut |_, ln| { - if let Some(s) = config.parse_aux_build(ln) { - props.aux.push(s); - } - if let Some(ac) = config.parse_aux_crate(ln) { - props.aux_crate.push(ac); - } + config.push_name_value_directive(ln, directives::AUX_BUILD, &mut props.aux, |r| { + r.trim().to_string() + }); + config.push_name_value_directive( + ln, + directives::AUX_CRATE, + &mut props.aux_crate, + Config::parse_aux_crate, + ); config.parse_and_update_revisions(ln, &mut props.revisions); }); return props; @@ -156,6 +159,38 @@ pub struct TestProps { pub stderr_per_bitwidth: bool, } +mod directives { + pub const ERROR_PATTERN: &'static str = "error-pattern"; + pub const COMPILE_FLAGS: &'static str = "compile-flags"; + pub const RUN_FLAGS: &'static str = "run-flags"; + pub const SHOULD_ICE: &'static str = "should-ice"; + pub const BUILD_AUX_DOCS: &'static str = "build-aux-docs"; + pub const FORCE_HOST: &'static str = "force-host"; + pub const CHECK_STDOUT: &'static str = "check-stdout"; + pub const CHECK_RUN_RESULTS: &'static str = "check-run-results"; + pub const DONT_CHECK_COMPILER_STDOUT: &'static str = "dont-check-compiler-stdout"; + pub const DONT_CHECK_COMPILER_STDERR: &'static str = "dont-check-compiler-stderr"; + pub const NO_PREFER_DYNAMIC: &'static str = "no-prefer-dynamic"; + pub const PRETTY_EXPANDED: &'static str = "pretty-expanded"; + pub const PRETTY_MODE: &'static str = "pretty-mode"; + pub const PRETTY_COMPARE_ONLY: &'static str = "pretty-compare-only"; + pub const AUX_BUILD: &'static str = "aux-build"; + pub const AUX_CRATE: &'static str = "aux-crate"; + pub const EXEC_ENV: &'static str = "exec-env"; + pub const RUSTC_ENV: &'static str = "rustc-env"; + pub const UNSET_RUSTC_ENV: &'static str = "unset-rustc-env"; + pub const FORBID_OUTPUT: &'static str = "forbid-output"; + pub const CHECK_TEST_LINE_NUMBERS_MATCH: &'static str = "check-test-line-numbers-match"; + pub const IGNORE_PASS: &'static str = "ignore-pass"; + pub const FAILURE_STATUS: &'static str = "failure-status"; + pub const RUN_RUSTFIX: &'static str = "run-rustfix"; + pub const RUSTFIX_ONLY_MACHINE_APPLICABLE: &'static str = "rustfix-only-machine-applicable"; + pub const ASSEMBLY_OUTPUT: &'static str = "assembly-output"; + pub const STDERR_PER_BITWIDTH: &'static str = "stderr-per-bitwidth"; + pub const INCREMENTAL: &'static str = "incremental"; + pub const KNOWN_BUG: &'static str = "known-bug"; +} + impl TestProps { pub fn new() -> Self { TestProps { @@ -235,11 +270,16 @@ impl TestProps { return; } - if let Some(ep) = config.parse_error_pattern(ln) { - self.error_patterns.push(ep); - } + use directives::*; + + config.push_name_value_directive( + ln, + ERROR_PATTERN, + &mut self.error_patterns, + |r| r, + ); - if let Some(flags) = config.parse_compile_flags(ln) { + if let Some(flags) = config.parse_name_value_directive(ln, COMPILE_FLAGS) { self.compile_flags.extend(flags.split_whitespace().map(|s| s.to_owned())); } @@ -250,93 +290,73 @@ impl TestProps { config.parse_and_update_revisions(ln, &mut self.revisions); - if self.run_flags.is_none() { - self.run_flags = config.parse_run_flags(ln); - } + config.set_name_value_directive(ln, RUN_FLAGS, &mut self.run_flags, |r| r); if self.pp_exact.is_none() { self.pp_exact = config.parse_pp_exact(ln, testfile); } - if !self.should_ice { - self.should_ice = config.parse_should_ice(ln); - } - - if !self.build_aux_docs { - self.build_aux_docs = config.parse_build_aux_docs(ln); - } - - if !self.force_host { - self.force_host = config.parse_force_host(ln); - } - - if !self.check_stdout { - self.check_stdout = config.parse_check_stdout(ln); - } - - if !self.check_run_results { - self.check_run_results = config.parse_check_run_results(ln); - } - - if !self.dont_check_compiler_stdout { - self.dont_check_compiler_stdout = config.parse_dont_check_compiler_stdout(ln); - } - - if !self.dont_check_compiler_stderr { - self.dont_check_compiler_stderr = config.parse_dont_check_compiler_stderr(ln); - } - - if !self.no_prefer_dynamic { - self.no_prefer_dynamic = config.parse_no_prefer_dynamic(ln); - } - - if !self.pretty_expanded { - self.pretty_expanded = config.parse_pretty_expanded(ln); - } - - if let Some(m) = config.parse_pretty_mode(ln) { + config.set_name_directive(ln, SHOULD_ICE, &mut self.should_ice); + config.set_name_directive(ln, BUILD_AUX_DOCS, &mut self.build_aux_docs); + config.set_name_directive(ln, FORCE_HOST, &mut self.force_host); + config.set_name_directive(ln, CHECK_STDOUT, &mut self.check_stdout); + config.set_name_directive(ln, CHECK_RUN_RESULTS, &mut self.check_run_results); + config.set_name_directive( + ln, + DONT_CHECK_COMPILER_STDOUT, + &mut self.dont_check_compiler_stdout, + ); + config.set_name_directive( + ln, + DONT_CHECK_COMPILER_STDERR, + &mut self.dont_check_compiler_stderr, + ); + config.set_name_directive(ln, NO_PREFER_DYNAMIC, &mut self.no_prefer_dynamic); + config.set_name_directive(ln, PRETTY_EXPANDED, &mut self.pretty_expanded); + + if let Some(m) = config.parse_name_value_directive(ln, PRETTY_MODE) { self.pretty_mode = m; } - if !self.pretty_compare_only { - self.pretty_compare_only = config.parse_pretty_compare_only(ln); - } - - if let Some(ab) = config.parse_aux_build(ln) { - self.aux_builds.push(ab); - } - - if let Some(ac) = config.parse_aux_crate(ln) { - self.aux_crates.push(ac); - } - - if let Some(ee) = config.parse_env(ln, "exec-env") { - self.exec_env.push(ee); - } - - if let Some(ee) = config.parse_env(ln, "rustc-env") { - self.rustc_env.push(ee); - } - - if let Some(ev) = config.parse_name_value_directive(ln, "unset-rustc-env") { - self.unset_rustc_env.push(ev); - } - - if let Some(of) = config.parse_forbid_output(ln) { - self.forbid_output.push(of); - } - - if !self.check_test_line_numbers_match { - self.check_test_line_numbers_match = - config.parse_check_test_line_numbers_match(ln); - } + config.set_name_directive(ln, PRETTY_COMPARE_ONLY, &mut self.pretty_compare_only); + config.push_name_value_directive(ln, AUX_BUILD, &mut self.aux_builds, |r| { + r.trim().to_string() + }); + config.push_name_value_directive( + ln, + AUX_CRATE, + &mut self.aux_crates, + Config::parse_aux_crate, + ); + config.push_name_value_directive( + ln, + EXEC_ENV, + &mut self.exec_env, + Config::parse_env, + ); + config.push_name_value_directive( + ln, + RUSTC_ENV, + &mut self.rustc_env, + Config::parse_env, + ); + config.push_name_value_directive( + ln, + UNSET_RUSTC_ENV, + &mut self.unset_rustc_env, + |r| r, + ); + config.push_name_value_directive(ln, FORBID_OUTPUT, &mut self.forbid_output, |r| r); + config.set_name_directive( + ln, + CHECK_TEST_LINE_NUMBERS_MATCH, + &mut self.check_test_line_numbers_match, + ); self.update_pass_mode(ln, cfg, config); self.update_fail_mode(ln, config); - if !self.ignore_pass { - self.ignore_pass = config.parse_ignore_pass(ln); - } + config.set_name_directive(ln, IGNORE_PASS, &mut self.ignore_pass); if let Some(rule) = config.parse_custom_normalization(ln, "normalize-stdout") { self.normalize_stdout.push(rule); @@ -345,34 +365,28 @@ impl TestProps { self.normalize_stderr.push(rule); } - if let Some(code) = config.parse_failure_status(ln) { + if let Some(code) = config + .parse_name_value_directive(ln, FAILURE_STATUS) + .and_then(|code| code.trim().parse::().ok()) + { self.failure_status = code; } - if !self.run_rustfix { - self.run_rustfix = config.parse_run_rustfix(ln); - } - - if !self.rustfix_only_machine_applicable { - self.rustfix_only_machine_applicable = - config.parse_rustfix_only_machine_applicable(ln); - } - - if self.assembly_output.is_none() { - self.assembly_output = config.parse_assembly_output(ln); - } - - if !self.stderr_per_bitwidth { - self.stderr_per_bitwidth = config.parse_stderr_per_bitwidth(ln); - } - - if !self.incremental { - self.incremental = config.parse_incremental(ln); - } - - if !self.known_bug { - self.known_bug = config.parse_known_bug(ln); - } + config.set_name_directive(ln, RUN_RUSTFIX, &mut self.run_rustfix); + config.set_name_directive( + ln, + RUSTFIX_ONLY_MACHINE_APPLICABLE, + &mut self.rustfix_only_machine_applicable, + ); + config.set_name_value_directive( + ln, + ASSEMBLY_OUTPUT, + &mut self.assembly_output, + |r| r.trim().to_string(), + ); + config.set_name_directive(ln, STDERR_PER_BITWIDTH, &mut self.stderr_per_bitwidth); + config.set_name_directive(ln, INCREMENTAL, &mut self.incremental); + config.set_name_directive(ln, KNOWN_BUG, &mut self.known_bug); }); } @@ -514,33 +528,12 @@ fn iter_header(testfile: &Path, rdr: R, it: &mut dyn FnMut(Option<&str> } impl Config { - fn parse_should_ice(&self, line: &str) -> bool { - self.parse_name_directive(line, "should-ice") - } - fn parse_error_pattern(&self, line: &str) -> Option { - self.parse_name_value_directive(line, "error-pattern") - } - - fn parse_forbid_output(&self, line: &str) -> Option { - self.parse_name_value_directive(line, "forbid-output") - } - - fn parse_aux_build(&self, line: &str) -> Option { - self.parse_name_value_directive(line, "aux-build").map(|r| r.trim().to_string()) - } - - fn parse_aux_crate(&self, line: &str) -> Option<(String, String)> { - self.parse_name_value_directive(line, "aux-crate").map(|r| { - let mut parts = r.trim().splitn(2, '='); - ( - parts.next().expect("missing aux-crate name (e.g. log=log.rs)").to_string(), - parts.next().expect("missing aux-crate value (e.g. log=log.rs)").to_string(), - ) - }) - } - - fn parse_compile_flags(&self, line: &str) -> Option { - self.parse_name_value_directive(line, "compile-flags") + fn parse_aux_crate(r: String) -> (String, String) { + let mut parts = r.trim().splitn(2, '='); + ( + parts.next().expect("missing aux-crate name (e.g. log=log.rs)").to_string(), + parts.next().expect("missing aux-crate value (e.g. log=log.rs)").to_string(), + ) } fn parse_and_update_revisions(&self, line: &str, existing: &mut Vec) { @@ -555,87 +548,18 @@ impl Config { } } - fn parse_run_flags(&self, line: &str) -> Option { - self.parse_name_value_directive(line, "run-flags") - } - - fn parse_force_host(&self, line: &str) -> bool { - self.parse_name_directive(line, "force-host") - } - - fn parse_build_aux_docs(&self, line: &str) -> bool { - self.parse_name_directive(line, "build-aux-docs") - } + fn parse_env(nv: String) -> (String, String) { + // nv is either FOO or FOO=BAR + let mut strs: Vec = nv.splitn(2, '=').map(str::to_owned).collect(); - fn parse_check_stdout(&self, line: &str) -> bool { - self.parse_name_directive(line, "check-stdout") - } - - fn parse_check_run_results(&self, line: &str) -> bool { - self.parse_name_directive(line, "check-run-results") - } - - fn parse_dont_check_compiler_stdout(&self, line: &str) -> bool { - self.parse_name_directive(line, "dont-check-compiler-stdout") - } - - fn parse_dont_check_compiler_stderr(&self, line: &str) -> bool { - self.parse_name_directive(line, "dont-check-compiler-stderr") - } - - fn parse_no_prefer_dynamic(&self, line: &str) -> bool { - self.parse_name_directive(line, "no-prefer-dynamic") - } - - fn parse_pretty_expanded(&self, line: &str) -> bool { - self.parse_name_directive(line, "pretty-expanded") - } - - fn parse_pretty_mode(&self, line: &str) -> Option { - self.parse_name_value_directive(line, "pretty-mode") - } - - fn parse_pretty_compare_only(&self, line: &str) -> bool { - self.parse_name_directive(line, "pretty-compare-only") - } - - fn parse_failure_status(&self, line: &str) -> Option { - match self.parse_name_value_directive(line, "failure-status") { - Some(code) => code.trim().parse::().ok(), - _ => None, - } - } - - fn parse_check_test_line_numbers_match(&self, line: &str) -> bool { - self.parse_name_directive(line, "check-test-line-numbers-match") - } - - fn parse_ignore_pass(&self, line: &str) -> bool { - self.parse_name_directive(line, "ignore-pass") - } - - fn parse_stderr_per_bitwidth(&self, line: &str) -> bool { - self.parse_name_directive(line, "stderr-per-bitwidth") - } - - fn parse_assembly_output(&self, line: &str) -> Option { - self.parse_name_value_directive(line, "assembly-output").map(|r| r.trim().to_string()) - } - - fn parse_env(&self, line: &str, name: &str) -> Option<(String, String)> { - self.parse_name_value_directive(line, name).map(|nv| { - // nv is either FOO or FOO=BAR - let mut strs: Vec = nv.splitn(2, '=').map(str::to_owned).collect(); - - match strs.len() { - 1 => (strs.pop().unwrap(), String::new()), - 2 => { - let end = strs.pop().unwrap(); - (strs.pop().unwrap(), end) - } - n => panic!("Expected 1 or 2 strings, not {}", n), + match strs.len() { + 1 => (strs.pop().unwrap(), String::new()), + 2 => { + let end = strs.pop().unwrap(); + (strs.pop().unwrap(), end) } - }) + n => panic!("Expected 1 or 2 strings, not {}", n), + } } fn parse_pp_exact(&self, line: &str, testfile: &Path) -> Option { @@ -747,24 +671,38 @@ impl Config { None } - fn parse_run_rustfix(&self, line: &str) -> bool { - self.parse_name_directive(line, "run-rustfix") - } - - fn parse_rustfix_only_machine_applicable(&self, line: &str) -> bool { - self.parse_name_directive(line, "rustfix-only-machine-applicable") - } - fn parse_edition(&self, line: &str) -> Option { self.parse_name_value_directive(line, "edition") } - fn parse_incremental(&self, line: &str) -> bool { - self.parse_name_directive(line, "incremental") + fn set_name_directive(&self, line: &str, directive: &str, value: &mut bool) { + if !*value { + *value = self.parse_name_directive(line, directive) + } + } + + fn set_name_value_directive( + &self, + line: &str, + directive: &str, + value: &mut Option, + parse: impl FnOnce(String) -> T, + ) { + if value.is_none() { + *value = self.parse_name_value_directive(line, directive).map(parse); + } } - fn parse_known_bug(&self, line: &str) -> bool { - self.parse_name_directive(line, "known-bug") + fn push_name_value_directive( + &self, + line: &str, + directive: &str, + values: &mut Vec, + parse: impl FnOnce(String) -> T, + ) { + if let Some(value) = self.parse_name_value_directive(line, directive).map(parse) { + values.push(value); + } } } @@ -916,7 +854,8 @@ pub fn make_test_description( ignore |= !has_hwasan && config.parse_name_directive(ln, "needs-sanitizer-hwaddress"); ignore |= config.target_panic == PanicStrategy::Abort && config.parse_name_directive(ln, "needs-unwind"); - ignore |= config.target == "wasm32-unknown-unknown" && config.parse_check_run_results(ln); + ignore |= config.target == "wasm32-unknown-unknown" + && config.parse_name_directive(ln, directives::CHECK_RUN_RESULTS); ignore |= config.debugger == Some(Debugger::Cdb) && ignore_cdb(config, ln); ignore |= config.debugger == Some(Debugger::Gdb) && ignore_gdb(config, ln); ignore |= config.debugger == Some(Debugger::Lldb) && ignore_lldb(config, ln); From 36cf48bae70957f28c141cdefdb248688c87e11c Mon Sep 17 00:00:00 2001 From: Jack Huey <31162821+jackh726@users.noreply.github.com> Date: Mon, 14 Feb 2022 17:22:49 -0500 Subject: [PATCH 08/15] Don't allow error annotations in known-bug tests --- src/tools/compiletest/src/runtest.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 03f8256d5e324..7fe7db0801b47 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1274,6 +1274,16 @@ impl<'test> TestCx<'test> { self.fatal_proc_rec("process did not return an error status", proc_res); } + if self.props.known_bug { + if !expected_errors.is_empty() { + self.fatal_proc_rec( + "`known_bug` tests should not have an expected errors", + proc_res, + ); + } + return; + } + // On Windows, keep all '\' path separators to match the paths reported in the JSON output // from the compiler let os_file_name = self.testpaths.file.display().to_string(); @@ -1311,13 +1321,7 @@ impl<'test> TestCx<'test> { None => { // If the test is a known bug, don't require that the error is annotated - if !self.props.known_bug - && self.is_unexpected_compiler_message( - actual_error, - expect_help, - expect_note, - ) - { + if self.is_unexpected_compiler_message(actual_error, expect_help, expect_note) { self.error(&format!( "{}:{}: unexpected {}: '{}'", file_name, From 879e4f8131b71050b00407befd6f1669389fe9ed Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 12 Feb 2022 13:30:30 -0800 Subject: [PATCH 09/15] use an enum in matches_projection_projection --- .../src/traits/project.rs | 7 ++-- .../src/traits/select/mod.rs | 37 ++++++++++++------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index a8d15d98eea57..584e412b8a228 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -19,6 +19,7 @@ use super::{Normalized, NormalizedTy, ProjectionCacheEntry, ProjectionCacheKey}; use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use crate::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime}; use crate::traits::error_reporting::InferCtxtExt as _; +use crate::traits::select::ProjectionMatchesProjection; use rustc_data_structures::sso::SsoHashSet; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_errors::ErrorReported; @@ -1248,7 +1249,7 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>( }); match is_match { - Some(true) => { + ProjectionMatchesProjection::Yes => { candidate_set.push_candidate(ctor(data)); if potentially_unnormalized_candidates @@ -1260,10 +1261,10 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>( return; } } - Some(false) => {} - None => { + ProjectionMatchesProjection::Ambiguous => { candidate_set.mark_ambiguous(); } + ProjectionMatchesProjection::No => {} } } } diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 4ca60a65485c5..2f85417a5b618 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1508,15 +1508,18 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { }) } - /// Return Some(true) if the obligation's predicate type applies to the env_predicate, and - /// Some(false) if it does not. Returns None in the case that the projection type is a GAT, + /// Return `Yes` if the obligation's predicate type applies to the env_predicate, and + /// `No` if it does not. Return `Ambiguous` in the case that the projection type is a GAT, /// and applying this env_predicate constrains any of the obligation's GAT substitutions. + /// + /// This behavior is a somewhat of a hack to prevent overconstraining inference variables + /// in cases like #91762. pub(super) fn match_projection_projections( &mut self, obligation: &ProjectionTyObligation<'tcx>, env_predicate: PolyProjectionPredicate<'tcx>, potentially_unnormalized_candidates: bool, - ) -> Option { + ) -> ProjectionMatchesProjection { let mut nested_obligations = Vec::new(); let (infer_predicate, _) = self.infcx.replace_bound_vars_with_fresh_vars( obligation.cause.span, @@ -1553,20 +1556,22 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { if is_match { let generics = self.tcx().generics_of(obligation.predicate.item_def_id); - if !generics.params.is_empty() { - // If any of the obligation's predicate substs shallow-resolve to - // something new, that means that we must have newly inferred something - // about the GAT. We should give up with ambiguity in that case. - if obligation.predicate.substs[generics.parent_count..] + // FIXME(generic-associated-types): Addresses aggressive inference in #92917. + // If this type is a GAT, and of the GAT substs resolve to something new, + // that means that we must have newly inferred something about the GAT. + // We should give up in that case. + if !generics.params.is_empty() + && obligation.predicate.substs[generics.parent_count..] .iter() .any(|&p| p.has_infer_types_or_consts() && self.infcx.shallow_resolve(p) != p) - { - return None; - } + { + ProjectionMatchesProjection::Ambiguous + } else { + ProjectionMatchesProjection::Yes } + } else { + ProjectionMatchesProjection::No } - - Some(is_match) } /////////////////////////////////////////////////////////////////////////// @@ -2766,3 +2771,9 @@ impl<'o, 'tcx> fmt::Debug for TraitObligationStack<'o, 'tcx> { write!(f, "TraitObligationStack({:?})", self.obligation) } } + +pub enum ProjectionMatchesProjection { + Yes, + Ambiguous, + No, +} From 3a73ca587bb8a8fb52d6045fbe31d50d5a56ff19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20BRANSTETT?= Date: Wed, 29 Sep 2021 02:39:30 +0200 Subject: [PATCH 10/15] Implement --check-cfg option (RFC 3013) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Urgau Co-authored-by: Marcelina KoÅ›cielnicka --- compiler/rustc_attr/src/builtin.rs | 31 ++++++- compiler/rustc_driver/src/lib.rs | 2 + compiler/rustc_interface/src/interface.rs | 91 ++++++++++++++++++- compiler/rustc_interface/src/util.rs | 8 ++ compiler/rustc_lint_defs/src/builtin.rs | 38 ++++++++ compiler/rustc_session/src/config.rs | 89 +++++++++++++++++- compiler/rustc_session/src/parse.rs | 4 + compiler/rustc_span/src/symbol.rs | 2 + src/librustdoc/core.rs | 1 + src/librustdoc/doctest.rs | 1 + src/test/run-make-fulldeps/issue-19371/foo.rs | 1 + src/test/ui/check-cfg/empty-names.rs | 10 ++ src/test/ui/check-cfg/empty-names.stderr | 10 ++ src/test/ui/check-cfg/empty-values.rs | 6 ++ src/test/ui/check-cfg/empty-values.stderr | 2 + .../invalid-arguments.anything_else.stderr | 2 + ...nvalid-arguments.names_simple_ident.stderr | 2 + src/test/ui/check-cfg/invalid-arguments.rs | 10 ++ ...valid-arguments.values_simple_ident.stderr | 2 + ...id-arguments.values_string_literals.stderr | 2 + src/test/ui/check-cfg/invalid-cfg-name.rs | 14 +++ src/test/ui/check-cfg/invalid-cfg-name.stderr | 10 ++ src/test/ui/check-cfg/invalid-cfg-value.rs | 17 ++++ .../ui/check-cfg/invalid-cfg-value.stderr | 10 ++ .../feature-gates/feature-gate-check-cfg.rs | 3 + .../feature-gate-check-cfg.stderr | 2 + src/tools/tidy/src/ui_tests.rs | 2 +- 27 files changed, 365 insertions(+), 7 deletions(-) create mode 100644 src/test/ui/check-cfg/empty-names.rs create mode 100644 src/test/ui/check-cfg/empty-names.stderr create mode 100644 src/test/ui/check-cfg/empty-values.rs create mode 100644 src/test/ui/check-cfg/empty-values.stderr create mode 100644 src/test/ui/check-cfg/invalid-arguments.anything_else.stderr create mode 100644 src/test/ui/check-cfg/invalid-arguments.names_simple_ident.stderr create mode 100644 src/test/ui/check-cfg/invalid-arguments.rs create mode 100644 src/test/ui/check-cfg/invalid-arguments.values_simple_ident.stderr create mode 100644 src/test/ui/check-cfg/invalid-arguments.values_string_literals.stderr create mode 100644 src/test/ui/check-cfg/invalid-cfg-name.rs create mode 100644 src/test/ui/check-cfg/invalid-cfg-name.stderr create mode 100644 src/test/ui/check-cfg/invalid-cfg-value.rs create mode 100644 src/test/ui/check-cfg/invalid-cfg-value.stderr create mode 100644 src/test/ui/feature-gates/feature-gate-check-cfg.rs create mode 100644 src/test/ui/feature-gates/feature-gate-check-cfg.stderr diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index dca7f5dd48769..49043e9f5f9d6 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -1,10 +1,13 @@ //! Parsing and validation of builtin attributes -use rustc_ast::{self as ast, Attribute, Lit, LitKind, MetaItem, MetaItemKind, NestedMetaItem}; +use rustc_ast as ast; +use rustc_ast::node_id::CRATE_NODE_ID; +use rustc_ast::{Attribute, Lit, LitKind, MetaItem, MetaItemKind, NestedMetaItem}; use rustc_ast_pretty::pprust; use rustc_errors::{struct_span_err, Applicability}; use rustc_feature::{find_gated_cfg, is_builtin_attr_name, Features, GatedCfg}; use rustc_macros::HashStable_Generic; +use rustc_session::lint::builtin::UNEXPECTED_CFGS; use rustc_session::parse::{feature_err, ParseSess}; use rustc_session::Session; use rustc_span::hygiene::Transparency; @@ -458,8 +461,30 @@ pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Feat true } MetaItemKind::NameValue(..) | MetaItemKind::Word => { - let ident = cfg.ident().expect("multi-segment cfg predicate"); - sess.config.contains(&(ident.name, cfg.value_str())) + let name = cfg.ident().expect("multi-segment cfg predicate").name; + let value = cfg.value_str(); + if sess.check_config.names_checked && !sess.check_config.names_valid.contains(&name) + { + sess.buffer_lint( + UNEXPECTED_CFGS, + cfg.span, + CRATE_NODE_ID, + "unexpected `cfg` condition name", + ); + } + if let Some(val) = value { + if sess.check_config.values_checked.contains(&name) + && !sess.check_config.values_valid.contains(&(name, val)) + { + sess.buffer_lint( + UNEXPECTED_CFGS, + cfg.span, + CRATE_NODE_ID, + "unexpected `cfg` condition value", + ); + } + } + sess.config.contains(&(name, value)) } } }) diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index ca4e7b5142ee7..dd235063b5cf7 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -216,10 +216,12 @@ fn run_compiler( } let cfg = interface::parse_cfgspecs(matches.opt_strs("cfg")); + let check_cfg = interface::parse_check_cfg(matches.opt_strs("check-cfg")); let (odir, ofile) = make_output(&matches); let mut config = interface::Config { opts: sopts, crate_cfg: cfg, + crate_check_cfg: check_cfg, input: Input::File(PathBuf::new()), input_path: None, output_file: ofile, diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 237aef1cf23aa..81d33411c4e86 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -2,7 +2,7 @@ pub use crate::passes::BoxedResolver; use crate::util; use rustc_ast::token; -use rustc_ast::{self as ast, MetaItemKind}; +use rustc_ast::{self as ast, LitKind, MetaItemKind}; use rustc_codegen_ssa::traits::CodegenBackend; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::Lrc; @@ -13,12 +13,13 @@ use rustc_lint::LintStore; use rustc_middle::ty; use rustc_parse::maybe_new_parser_from_source_str; use rustc_query_impl::QueryCtxt; -use rustc_session::config::{self, ErrorOutputType, Input, OutputFilenames}; +use rustc_session::config::{self, CheckCfg, ErrorOutputType, Input, OutputFilenames}; use rustc_session::early_error; use rustc_session::lint; use rustc_session::parse::{CrateConfig, ParseSess}; use rustc_session::{DiagnosticOutput, Session}; use rustc_span::source_map::{FileLoader, FileName}; +use rustc_span::symbol::sym; use std::path::PathBuf; use std::result; use std::sync::{Arc, Mutex}; @@ -140,6 +141,90 @@ pub fn parse_cfgspecs(cfgspecs: Vec) -> FxHashSet<(String, Option) -> CheckCfg { + rustc_span::create_default_session_if_not_set_then(move |_| { + let mut cfg = CheckCfg::default(); + + 'specs: for s in specs { + let sess = ParseSess::with_silent_emitter(Some(format!( + "this error occurred on the command line: `--check-cfg={}`", + s + ))); + let filename = FileName::cfg_spec_source_code(&s); + + macro_rules! error { + ($reason: expr) => { + early_error( + ErrorOutputType::default(), + &format!( + concat!("invalid `--check-cfg` argument: `{}` (", $reason, ")"), + s + ), + ); + }; + } + + match maybe_new_parser_from_source_str(&sess, filename, s.to_string()) { + Ok(mut parser) => match &mut parser.parse_meta_item() { + Ok(meta_item) if parser.token == token::Eof => { + if let Some(args) = meta_item.meta_item_list() { + if meta_item.has_name(sym::names) { + cfg.names_checked = true; + for arg in args { + if arg.is_word() && arg.ident().is_some() { + let ident = arg.ident().expect("multi-segment cfg key"); + cfg.names_valid.insert(ident.name.to_string()); + } else { + error!("`names()` arguments must be simple identifers"); + } + } + continue 'specs; + } else if meta_item.has_name(sym::values) { + if let Some((name, values)) = args.split_first() { + if name.is_word() && name.ident().is_some() { + let ident = name.ident().expect("multi-segment cfg key"); + cfg.values_checked.insert(ident.to_string()); + for val in values { + if let Some(LitKind::Str(s, _)) = + val.literal().map(|lit| &lit.kind) + { + cfg.values_valid + .insert((ident.to_string(), s.to_string())); + } else { + error!( + "`values()` arguments must be string literals" + ); + } + } + + continue 'specs; + } else { + error!( + "`values()` first argument must be a simple identifer" + ); + } + } + } + } + } + Ok(..) => {} + Err(err) => err.cancel(), + }, + Err(errs) => errs.into_iter().for_each(|mut err| err.cancel()), + } + + error!( + "expected `names(name1, name2, ... nameN)` or \ + `values(name, \"value1\", \"value2\", ... \"valueN\")`" + ); + } + + cfg.names_valid.extend(cfg.values_checked.iter().cloned()); + cfg + }) +} + /// The compiler configuration pub struct Config { /// Command line options @@ -147,6 +232,7 @@ pub struct Config { /// cfg! configuration in addition to the default ones pub crate_cfg: FxHashSet<(String, Option)>, + pub crate_check_cfg: CheckCfg, pub input: Input, pub input_path: Option, @@ -190,6 +276,7 @@ pub fn create_compiler_and_run(config: Config, f: impl FnOnce(&Compiler) -> R let (mut sess, codegen_backend) = util::create_session( config.opts, config.crate_cfg, + config.crate_check_cfg, config.diagnostic_output, config.file_loader, config.input_path.clone(), diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index 6d9183eda9d32..4b1b01de54942 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -15,6 +15,7 @@ use rustc_parse::validate_attr; use rustc_query_impl::QueryCtxt; use rustc_resolve::{self, Resolver}; use rustc_session as session; +use rustc_session::config::CheckCfg; use rustc_session::config::{self, CrateType}; use rustc_session::config::{ErrorOutputType, Input, OutputFilenames}; use rustc_session::lint::{self, BuiltinLintDiagnostics, LintBuffer}; @@ -67,6 +68,7 @@ pub fn add_configuration( pub fn create_session( sopts: config::Options, cfg: FxHashSet<(String, Option)>, + check_cfg: CheckCfg, diagnostic_output: DiagnosticOutput, file_loader: Option>, input_path: Option, @@ -102,7 +104,13 @@ pub fn create_session( let mut cfg = config::build_configuration(&sess, config::to_crate_config(cfg)); add_configuration(&mut cfg, &mut sess, &*codegen_backend); + + let mut check_cfg = config::to_crate_check_config(check_cfg); + check_cfg.fill_well_known(); + check_cfg.fill_actual(&cfg); + sess.parse_sess.config = cfg; + sess.parse_sess.check_config = check_cfg; (Lrc::new(sess), Lrc::new(codegen_backend)) } diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index f4eba25475eee..adec1a3ab00d6 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -2957,6 +2957,43 @@ declare_lint! { }; } +declare_lint! { + /// The `unexpected_cfgs` lint detects unexpected conditional compilation conditions. + /// + /// ### Example + /// + /// ```text + /// rustc --check-cfg 'names()' + /// ``` + /// + /// ```rust,ignore (needs command line option) + /// #[cfg(widnows)] + /// fn foo() {} + /// ``` + /// + /// This will produce: + /// + /// ```text + /// warning: unknown condition name used + /// --> lint_example.rs:1:7 + /// | + /// 1 | #[cfg(widnows)] + /// | ^^^^^^^ + /// | + /// = note: `#[warn(unexpected_cfgs)]` on by default + /// ``` + /// + /// ### Explanation + /// + /// This lint is only active when a `--check-cfg='names(...)'` option has been passed + /// to the compiler and triggers whenever an unknown condition name or value is used. + /// The known condition include names or values passed in `--check-cfg`, `--cfg`, and some + /// well-knows names and values built into the compiler. + pub UNEXPECTED_CFGS, + Warn, + "detects unexpected names and values in `#[cfg]` conditions", +} + declare_lint_pass! { /// Does nothing as a lint pass, but registers some `Lint`s /// that are used by other parts of the compiler. @@ -3055,6 +3092,7 @@ declare_lint_pass! { DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME, DUPLICATE_MACRO_ATTRIBUTES, SUSPICIOUS_AUTO_TRAIT_IMPLS, + UNEXPECTED_CFGS, ] } diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 8630ffec241f9..f90766875d290 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -16,7 +16,7 @@ use rustc_target::spec::{LinkerFlavor, SplitDebuginfo, Target, TargetTriple, Tar use rustc_serialize::json; -use crate::parse::CrateConfig; +use crate::parse::{CrateCheckConfig, CrateConfig}; use rustc_feature::UnstableFeatures; use rustc_span::edition::{Edition, DEFAULT_EDITION, EDITION_NAME_LIST, LATEST_STABLE_EDITION}; use rustc_span::source_map::{FileName, FilePathMapping}; @@ -921,6 +921,7 @@ pub const fn default_lib_output() -> CrateType { } fn default_configuration(sess: &Session) -> CrateConfig { + // NOTE: This should be kept in sync with `CrateCheckConfig::fill_well_known` below. let end = &sess.target.endian; let arch = &sess.target.arch; let wordsz = sess.target.pointer_width.to_string(); @@ -1005,6 +1006,91 @@ pub fn to_crate_config(cfg: FxHashSet<(String, Option)>) -> CrateConfig cfg.into_iter().map(|(a, b)| (Symbol::intern(&a), b.map(|b| Symbol::intern(&b)))).collect() } +/// The parsed `--check-cfg` options +pub struct CheckCfg { + /// Set if `names()` checking is enabled + pub names_checked: bool, + /// The union of all `names()` + pub names_valid: FxHashSet, + /// The set of names for which `values()` was used + pub values_checked: FxHashSet, + /// The set of all (name, value) pairs passed in `values()` + pub values_valid: FxHashSet<(T, T)>, +} + +impl Default for CheckCfg { + fn default() -> Self { + CheckCfg { + names_checked: false, + names_valid: FxHashSet::default(), + values_checked: FxHashSet::default(), + values_valid: FxHashSet::default(), + } + } +} + +impl CheckCfg { + fn map_data(&self, f: impl Fn(&T) -> O) -> CheckCfg { + CheckCfg { + names_checked: self.names_checked, + names_valid: self.names_valid.iter().map(|a| f(a)).collect(), + values_checked: self.values_checked.iter().map(|a| f(a)).collect(), + values_valid: self.values_valid.iter().map(|(a, b)| (f(a), f(b))).collect(), + } + } +} + +/// Converts the crate `--check-cfg` options from `String` to `Symbol`. +/// `rustc_interface::interface::Config` accepts this in the compiler configuration, +/// but the symbol interner is not yet set up then, so we must convert it later. +pub fn to_crate_check_config(cfg: CheckCfg) -> CrateCheckConfig { + cfg.map_data(|s| Symbol::intern(s)) +} + +impl CrateCheckConfig { + /// Fills a `CrateCheckConfig` with well-known configuration names. + pub fn fill_well_known(&mut self) { + // NOTE: This should be kept in sync with `default_configuration` + const WELL_KNOWN_NAMES: &[Symbol] = &[ + sym::unix, + sym::windows, + sym::target_os, + sym::target_family, + sym::target_arch, + sym::target_endian, + sym::target_pointer_width, + sym::target_env, + sym::target_abi, + sym::target_vendor, + sym::target_thread_local, + sym::target_has_atomic_load_store, + sym::target_has_atomic, + sym::target_has_atomic_equal_alignment, + sym::panic, + sym::sanitize, + sym::debug_assertions, + sym::proc_macro, + sym::test, + sym::doc, + sym::doctest, + sym::feature, + ]; + for &name in WELL_KNOWN_NAMES { + self.names_valid.insert(name); + } + } + + /// Fills a `CrateCheckConfig` with configuration names and values that are actually active. + pub fn fill_actual(&mut self, cfg: &CrateConfig) { + for &(k, v) in cfg { + self.names_valid.insert(k); + if let Some(v) = v { + self.values_valid.insert((k, v)); + } + } + } +} + pub fn build_configuration(sess: &Session, mut user_cfg: CrateConfig) -> CrateConfig { // Combine the configuration requested by the session (command line) with // some default and generated configuration items. @@ -1148,6 +1234,7 @@ pub fn rustc_short_optgroups() -> Vec { vec![ opt::flag_s("h", "help", "Display this message"), opt::multi_s("", "cfg", "Configure the compilation environment", "SPEC"), + opt::multi("", "check-cfg", "Provide list of valid cfg options for checking", "SPEC"), opt::multi_s( "L", "", diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index d5b520325e550..7113f9b0a2f5a 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -1,6 +1,7 @@ //! Contains `ParseSess` which holds state living beyond what one `Parser` might. //! It also serves as an input to the parser itself. +use crate::config::CheckCfg; use crate::lint::{BufferedEarlyLint, BuiltinLintDiagnostics, Lint, LintId}; use rustc_ast::node_id::NodeId; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; @@ -18,6 +19,7 @@ use std::str; /// The set of keys (and, optionally, values) that define the compilation /// environment of the crate, used to drive conditional compilation. pub type CrateConfig = FxHashSet<(Symbol, Option)>; +pub type CrateCheckConfig = CheckCfg; /// Collected spans during parsing for places where a certain feature was /// used and should be feature gated accordingly in `check_crate`. @@ -117,6 +119,7 @@ pub struct ParseSess { pub span_diagnostic: Handler, pub unstable_features: UnstableFeatures, pub config: CrateConfig, + pub check_config: CrateCheckConfig, pub edition: Edition, pub missing_fragment_specifiers: Lock>, /// Places where raw identifiers were used. This is used to avoid complaining about idents @@ -162,6 +165,7 @@ impl ParseSess { span_diagnostic: handler, unstable_features: UnstableFeatures::from_environment(None), config: FxHashSet::default(), + check_config: CrateCheckConfig::default(), edition: ExpnId::root().expn_data().edition, missing_fragment_specifiers: Default::default(), raw_identifier_spans: Lock::new(Vec::new()), diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index cab1d4e21c9b5..1d8b5ab75c291 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -908,6 +908,7 @@ symbols! { naked, naked_functions, name, + names, native_link_modifiers, native_link_modifiers_as_needed, native_link_modifiers_bundle, @@ -1478,6 +1479,7 @@ symbols! { va_list, va_start, val, + values, var, variant_count, vec, diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 1f14a333c005d..5d2f774f8cff3 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -250,6 +250,7 @@ crate fn create_config( interface::Config { opts: sessopts, crate_cfg: interface::parse_cfgspecs(cfgs), + crate_check_cfg: interface::parse_check_cfg(vec![]), input, input_path: cpath, output_file: None, diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 6c55721c0dd94..6f398c176832d 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -91,6 +91,7 @@ crate fn run(options: RustdocOptions) -> Result<(), ErrorReported> { let config = interface::Config { opts: sessopts, crate_cfg: interface::parse_cfgspecs(cfgs), + crate_check_cfg: interface::parse_check_cfg(vec![]), input, input_path: None, output_file: None, diff --git a/src/test/run-make-fulldeps/issue-19371/foo.rs b/src/test/run-make-fulldeps/issue-19371/foo.rs index 4acabbb70ede2..ec711eb4e487e 100644 --- a/src/test/run-make-fulldeps/issue-19371/foo.rs +++ b/src/test/run-make-fulldeps/issue-19371/foo.rs @@ -49,6 +49,7 @@ fn compile(code: String, output: PathBuf, sysroot: PathBuf) { let config = interface::Config { opts, crate_cfg: Default::default(), + crate_check_cfg: Default::default(), input, input_path: None, output_file: Some(output), diff --git a/src/test/ui/check-cfg/empty-names.rs b/src/test/ui/check-cfg/empty-names.rs new file mode 100644 index 0000000000000..046ff0364e271 --- /dev/null +++ b/src/test/ui/check-cfg/empty-names.rs @@ -0,0 +1,10 @@ +// Check warning for unexpected cfg +// +// check-pass +// compile-flags: --check-cfg=names() -Z unstable-options + +#[cfg(unknown_key = "value")] +//~^ WARNING unexpected `cfg` condition name +pub fn f() {} + +fn main() {} diff --git a/src/test/ui/check-cfg/empty-names.stderr b/src/test/ui/check-cfg/empty-names.stderr new file mode 100644 index 0000000000000..f926d1133cced --- /dev/null +++ b/src/test/ui/check-cfg/empty-names.stderr @@ -0,0 +1,10 @@ +warning: unexpected `cfg` condition name + --> $DIR/empty-names.rs:6:7 + | +LL | #[cfg(unknown_key = "value")] + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(unexpected_cfgs)]` on by default + +warning: 1 warning emitted + diff --git a/src/test/ui/check-cfg/empty-values.rs b/src/test/ui/check-cfg/empty-values.rs new file mode 100644 index 0000000000000..38ef9e51c7a1f --- /dev/null +++ b/src/test/ui/check-cfg/empty-values.rs @@ -0,0 +1,6 @@ +// Check that a an empty values() is rejected +// +// check-fail +// compile-flags: --check-cfg=values() -Z unstable-options + +fn main() {} diff --git a/src/test/ui/check-cfg/empty-values.stderr b/src/test/ui/check-cfg/empty-values.stderr new file mode 100644 index 0000000000000..106d5b7b47f9b --- /dev/null +++ b/src/test/ui/check-cfg/empty-values.stderr @@ -0,0 +1,2 @@ +error: invalid `--check-cfg` argument: `values()` (expected `names(name1, name2, ... nameN)` or `values(name, "value1", "value2", ... "valueN")`) + diff --git a/src/test/ui/check-cfg/invalid-arguments.anything_else.stderr b/src/test/ui/check-cfg/invalid-arguments.anything_else.stderr new file mode 100644 index 0000000000000..850924d993ac9 --- /dev/null +++ b/src/test/ui/check-cfg/invalid-arguments.anything_else.stderr @@ -0,0 +1,2 @@ +error: invalid `--check-cfg` argument: `anything_else(...)` (expected `names(name1, name2, ... nameN)` or `values(name, "value1", "value2", ... "valueN")`) + diff --git a/src/test/ui/check-cfg/invalid-arguments.names_simple_ident.stderr b/src/test/ui/check-cfg/invalid-arguments.names_simple_ident.stderr new file mode 100644 index 0000000000000..bdfbc3d54a2c5 --- /dev/null +++ b/src/test/ui/check-cfg/invalid-arguments.names_simple_ident.stderr @@ -0,0 +1,2 @@ +error: invalid `--check-cfg` argument: `names("NOT_IDENT")` (`names()` arguments must be simple identifers) + diff --git a/src/test/ui/check-cfg/invalid-arguments.rs b/src/test/ui/check-cfg/invalid-arguments.rs new file mode 100644 index 0000000000000..5090ce3e845d3 --- /dev/null +++ b/src/test/ui/check-cfg/invalid-arguments.rs @@ -0,0 +1,10 @@ +// Check that invalid --check-cfg are rejected +// +// check-fail +// revisions: anything_else names_simple_ident values_simple_ident values_string_literals +// [anything_else]compile-flags: -Z unstable-options --check-cfg=anything_else(...) +// [names_simple_ident]compile-flags: -Z unstable-options --check-cfg=names("NOT_IDENT") +// [values_simple_ident]compile-flags: -Z unstable-options --check-cfg=values("NOT_IDENT") +// [values_string_literals]compile-flags: -Z unstable-options --check-cfg=values(test,12) + +fn main() {} diff --git a/src/test/ui/check-cfg/invalid-arguments.values_simple_ident.stderr b/src/test/ui/check-cfg/invalid-arguments.values_simple_ident.stderr new file mode 100644 index 0000000000000..b25882baaf3e6 --- /dev/null +++ b/src/test/ui/check-cfg/invalid-arguments.values_simple_ident.stderr @@ -0,0 +1,2 @@ +error: invalid `--check-cfg` argument: `values("NOT_IDENT")` (`values()` first argument must be a simple identifer) + diff --git a/src/test/ui/check-cfg/invalid-arguments.values_string_literals.stderr b/src/test/ui/check-cfg/invalid-arguments.values_string_literals.stderr new file mode 100644 index 0000000000000..5853b4741a642 --- /dev/null +++ b/src/test/ui/check-cfg/invalid-arguments.values_string_literals.stderr @@ -0,0 +1,2 @@ +error: invalid `--check-cfg` argument: `values(test,12)` (`values()` arguments must be string literals) + diff --git a/src/test/ui/check-cfg/invalid-cfg-name.rs b/src/test/ui/check-cfg/invalid-cfg-name.rs new file mode 100644 index 0000000000000..8499d3d4448da --- /dev/null +++ b/src/test/ui/check-cfg/invalid-cfg-name.rs @@ -0,0 +1,14 @@ +// Check warning for invalid configuration name +// +// edition:2018 +// check-pass +// compile-flags: --check-cfg=names() -Z unstable-options + +#[cfg(widnows)] +//~^ WARNING unexpected `cfg` condition name +pub fn f() {} + +#[cfg(windows)] +pub fn g() {} + +pub fn main() {} diff --git a/src/test/ui/check-cfg/invalid-cfg-name.stderr b/src/test/ui/check-cfg/invalid-cfg-name.stderr new file mode 100644 index 0000000000000..2587685afa048 --- /dev/null +++ b/src/test/ui/check-cfg/invalid-cfg-name.stderr @@ -0,0 +1,10 @@ +warning: unexpected `cfg` condition name + --> $DIR/invalid-cfg-name.rs:7:7 + | +LL | #[cfg(widnows)] + | ^^^^^^^ + | + = note: `#[warn(unexpected_cfgs)]` on by default + +warning: 1 warning emitted + diff --git a/src/test/ui/check-cfg/invalid-cfg-value.rs b/src/test/ui/check-cfg/invalid-cfg-value.rs new file mode 100644 index 0000000000000..a60095a5aae9d --- /dev/null +++ b/src/test/ui/check-cfg/invalid-cfg-value.rs @@ -0,0 +1,17 @@ +// Check warning for invalid configuration value +// +// edition:2018 +// check-pass +// compile-flags: --check-cfg=values(feature,"serde","full") --cfg=feature="rand" -Z unstable-options + +#[cfg(feature = "sedre")] +//~^ WARNING unexpected `cfg` condition value +pub fn f() {} + +#[cfg(feature = "serde")] +pub fn g() {} + +#[cfg(feature = "rand")] +pub fn h() {} + +pub fn main() {} diff --git a/src/test/ui/check-cfg/invalid-cfg-value.stderr b/src/test/ui/check-cfg/invalid-cfg-value.stderr new file mode 100644 index 0000000000000..c591d8474a261 --- /dev/null +++ b/src/test/ui/check-cfg/invalid-cfg-value.stderr @@ -0,0 +1,10 @@ +warning: unexpected `cfg` condition value + --> $DIR/invalid-cfg-value.rs:7:7 + | +LL | #[cfg(feature = "sedre")] + | ^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(unexpected_cfgs)]` on by default + +warning: 1 warning emitted + diff --git a/src/test/ui/feature-gates/feature-gate-check-cfg.rs b/src/test/ui/feature-gates/feature-gate-check-cfg.rs new file mode 100644 index 0000000000000..4012a3b04b522 --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-check-cfg.rs @@ -0,0 +1,3 @@ +// compile-flags: --check-cfg "names()" + +fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-check-cfg.stderr b/src/test/ui/feature-gates/feature-gate-check-cfg.stderr new file mode 100644 index 0000000000000..9b27c2bc058a7 --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-check-cfg.stderr @@ -0,0 +1,2 @@ +error: the `-Z unstable-options` flag must also be passed to enable the flag `check-cfg` + diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs index 203e33e8b1f38..95847dcd46be5 100644 --- a/src/tools/tidy/src/ui_tests.rs +++ b/src/tools/tidy/src/ui_tests.rs @@ -7,7 +7,7 @@ use std::path::Path; const ENTRY_LIMIT: usize = 1000; // FIXME: The following limits should be reduced eventually. -const ROOT_ENTRY_LIMIT: usize = 982; +const ROOT_ENTRY_LIMIT: usize = 983; const ISSUES_ENTRY_LIMIT: usize = 2310; fn check_entries(path: &Path, bad: &mut bool) { From 568aeda9e955ca2a4c043bc2ae7f854e60f6103a Mon Sep 17 00:00:00 2001 From: Ivan Lozano Date: Fri, 3 Dec 2021 16:11:13 -0500 Subject: [PATCH 11/15] MemTagSanitizer Support Adds support for the LLVM MemTagSanitizer. --- compiler/rustc_codegen_llvm/src/attributes.rs | 13 ++++++++++++ compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 1 + .../rustc_llvm/llvm-wrapper/LLVMWrapper.h | 1 + .../rustc_llvm/llvm-wrapper/RustWrapper.cpp | 2 ++ compiler/rustc_session/src/options.rs | 3 ++- compiler/rustc_span/src/symbol.rs | 1 + .../src/spec/aarch64_linux_android.rs | 4 +++- .../src/spec/aarch64_unknown_linux_gnu.rs | 1 + compiler/rustc_target/src/spec/mod.rs | 4 ++++ compiler/rustc_typeck/src/collect.rs | 4 +++- .../src/compiler-flags/sanitizer.md | 20 +++++++++++++++++-- .../codegen/sanitizer_memtag_attr_check.rs | 12 +++++++++++ .../ui/invalid/invalid-no-sanitize.stderr | 2 +- src/tools/compiletest/src/header.rs | 2 ++ src/tools/compiletest/src/util.rs | 3 +++ 15 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 src/test/codegen/sanitizer_memtag_attr_check.rs diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index 2472789601e70..4d054ec3d8170 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -55,6 +55,19 @@ pub fn sanitize<'ll>(cx: &CodegenCx<'ll, '_>, no_sanitize: SanitizerSet, llfn: & if enabled.contains(SanitizerSet::HWADDRESS) { llvm::Attribute::SanitizeHWAddress.apply_llfn(Function, llfn); } + if enabled.contains(SanitizerSet::MEMTAG) { + // Check to make sure the mte target feature is actually enabled. + let sess = cx.tcx.sess; + let features = llvm_util::llvm_global_features(sess).join(","); + let mte_feature_enabled = features.rfind("+mte"); + let mte_feature_disabled = features.rfind("-mte"); + + if mte_feature_enabled.is_none() || (mte_feature_disabled > mte_feature_enabled) { + sess.err("`-Zsanitizer=memtag` requires `-Ctarget-feature=+mte`"); + } + + llvm::Attribute::SanitizeMemTag.apply_llfn(Function, llfn); + } } /// Tell LLVM to emit or not emit the information necessary to unwind the stack for the function. diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 4f62c68556841..bb6a2cd1cf956 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -190,6 +190,7 @@ pub enum Attribute { StackProtectStrong = 31, StackProtect = 32, NoUndef = 33, + SanitizeMemTag = 34, } /// LLVMIntPredicate diff --git a/compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h b/compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h index 9e0a9b354e196..a2b0e9b4d29d8 100644 --- a/compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h +++ b/compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h @@ -83,6 +83,7 @@ enum LLVMRustAttribute { StackProtectStrong = 31, StackProtect = 32, NoUndef = 33, + SanitizeMemTag = 34, }; typedef struct OpaqueRustString *RustStringRef; diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp index fb9c5e6a527a7..bf2d6fb125274 100644 --- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp @@ -226,6 +226,8 @@ static Attribute::AttrKind fromRust(LLVMRustAttribute Kind) { return Attribute::StackProtect; case NoUndef: return Attribute::NoUndef; + case SanitizeMemTag: + return Attribute::SanitizeMemTag; } report_fatal_error("bad AttributeKind"); } diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index ae1b638c34467..05f616d4e33ce 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -376,7 +376,7 @@ mod desc { pub const parse_panic_strategy: &str = "either `unwind` or `abort`"; pub const parse_opt_panic_strategy: &str = parse_panic_strategy; pub const parse_relro_level: &str = "one of: `full`, `partial`, or `off`"; - pub const parse_sanitizers: &str = "comma separated list of sanitizers: `address`, `cfi`, `hwaddress`, `leak`, `memory` or `thread`"; + pub const parse_sanitizers: &str = "comma separated list of sanitizers: `address`, `cfi`, `hwaddress`, `leak`, `memory`, `memtag`, or `thread`"; pub const parse_sanitizer_memory_track_origins: &str = "0, 1, or 2"; pub const parse_cfguard: &str = "either a boolean (`yes`, `no`, `on`, `off`, etc), `checks`, or `nochecks`"; @@ -638,6 +638,7 @@ mod parse { "cfi" => SanitizerSet::CFI, "leak" => SanitizerSet::LEAK, "memory" => SanitizerSet::MEMORY, + "memtag" => SanitizerSet::MEMTAG, "thread" => SanitizerSet::THREAD, "hwaddress" => SanitizerSet::HWADDRESS, _ => return false, diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index ebc0e72bba6ab..ce6f86033c2fb 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -875,6 +875,7 @@ symbols! { mem_zeroed, member_constraints, memory, + memtag, message, meta, metadata_type, diff --git a/compiler/rustc_target/src/spec/aarch64_linux_android.rs b/compiler/rustc_target/src/spec/aarch64_linux_android.rs index 1e9abbbe1e787..5692925f63beb 100644 --- a/compiler/rustc_target/src/spec/aarch64_linux_android.rs +++ b/compiler/rustc_target/src/spec/aarch64_linux_android.rs @@ -14,7 +14,9 @@ pub fn target() -> Target { // As documented in https://developer.android.com/ndk/guides/cpu-features.html // the neon (ASIMD) and FP must exist on all android aarch64 targets. features: "+neon,+fp-armv8".to_string(), - supported_sanitizers: SanitizerSet::CFI | SanitizerSet::HWADDRESS, + supported_sanitizers: SanitizerSet::CFI + | SanitizerSet::HWADDRESS + | SanitizerSet::MEMTAG, ..super::android_base::opts() }, } diff --git a/compiler/rustc_target/src/spec/aarch64_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/aarch64_unknown_linux_gnu.rs index 850381f7fb073..974a5b84d1dc4 100644 --- a/compiler/rustc_target/src/spec/aarch64_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/aarch64_unknown_linux_gnu.rs @@ -14,6 +14,7 @@ pub fn target() -> Target { | SanitizerSet::CFI | SanitizerSet::LEAK | SanitizerSet::MEMORY + | SanitizerSet::MEMTAG | SanitizerSet::THREAD | SanitizerSet::HWADDRESS, ..super::linux_gnu_base::opts() diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index d735f3d41fdb0..ed758710ecd57 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -606,6 +606,7 @@ bitflags::bitflags! { const THREAD = 1 << 3; const HWADDRESS = 1 << 4; const CFI = 1 << 5; + const MEMTAG = 1 << 6; } } @@ -619,6 +620,7 @@ impl SanitizerSet { SanitizerSet::CFI => "cfi", SanitizerSet::LEAK => "leak", SanitizerSet::MEMORY => "memory", + SanitizerSet::MEMTAG => "memtag", SanitizerSet::THREAD => "thread", SanitizerSet::HWADDRESS => "hwaddress", _ => return None, @@ -652,6 +654,7 @@ impl IntoIterator for SanitizerSet { SanitizerSet::CFI, SanitizerSet::LEAK, SanitizerSet::MEMORY, + SanitizerSet::MEMTAG, SanitizerSet::THREAD, SanitizerSet::HWADDRESS, ] @@ -1881,6 +1884,7 @@ impl Target { Some("cfi") => SanitizerSet::CFI, Some("leak") => SanitizerSet::LEAK, Some("memory") => SanitizerSet::MEMORY, + Some("memtag") => SanitizerSet::MEMTAG, Some("thread") => SanitizerSet::THREAD, Some("hwaddress") => SanitizerSet::HWADDRESS, Some(s) => return Err(format!("unknown sanitizer {}", s)), diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index 88dc90dd3e7b0..be3ac3b107109 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -3008,6 +3008,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs { codegen_fn_attrs.no_sanitize |= SanitizerSet::CFI; } else if item.has_name(sym::memory) { codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMORY; + } else if item.has_name(sym::memtag) { + codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMTAG; } else if item.has_name(sym::thread) { codegen_fn_attrs.no_sanitize |= SanitizerSet::THREAD; } else if item.has_name(sym::hwaddress) { @@ -3015,7 +3017,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs { } else { tcx.sess .struct_span_err(item.span(), "invalid argument for `no_sanitize`") - .note("expected one of: `address`, `hwaddress`, `memory` or `thread`") + .note("expected one of: `address`, `cfi`, `hwaddress`, `memory`, `memtag`, or `thread`") .emit(); } } diff --git a/src/doc/unstable-book/src/compiler-flags/sanitizer.md b/src/doc/unstable-book/src/compiler-flags/sanitizer.md index d630f4ecb7b22..457851b0cc7a4 100644 --- a/src/doc/unstable-book/src/compiler-flags/sanitizer.md +++ b/src/doc/unstable-book/src/compiler-flags/sanitizer.md @@ -16,11 +16,13 @@ This feature allows for use of one of following sanitizers: AddressSanitizer, but based on partial hardware assistance. * [LeakSanitizer][clang-lsan] a run-time memory leak detector. * [MemorySanitizer][clang-msan] a detector of uninitialized reads. +* [MemTagSanitizer][clang-memtag] fast memory error detector based on + Armv8.5-A Memory Tagging Extension. * [ThreadSanitizer][clang-tsan] a fast data race detector. To enable a sanitizer compile with `-Zsanitizer=address`,`-Zsanitizer=cfi`, -`-Zsanitizer=hwaddress`, `-Zsanitizer=leak`, `-Zsanitizer=memory` or -`-Zsanitizer=thread`. +`-Zsanitizer=hwaddress`, `-Zsanitizer=leak`, `-Zsanitizer=memory`, +`-Zsanitizer=memtag`, or `-Zsanitizer=thread`. # AddressSanitizer @@ -494,6 +496,20 @@ $ cargo run -Zbuild-std --target x86_64-unknown-linux-gnu #0 0x560c04b2bc50 in memory::main::hd2333c1899d997f5 $CWD/src/main.rs:3 ``` +# MemTagSanitizer + +MemTagSanitizer detects a similar class of errors as AddressSanitizer and HardwareAddressSanitizer, but with lower overhead suitable for use as hardening for production binaries. + +MemTagSanitizer is supported on the following targets: + +* `aarch64-linux-android` +* `aarch64-unknown-linux-gnu` + +MemTagSanitizer requires hardware support and the `mte` target feature. +To enable this target feature compile with `-C target-feature="+mte"`. + +More information can be found in the associated [LLVM documentation](https://llvm.org/docs/MemTagSanitizer.html). + # ThreadSanitizer ThreadSanitizer is a data race detection tool. It is supported on the following diff --git a/src/test/codegen/sanitizer_memtag_attr_check.rs b/src/test/codegen/sanitizer_memtag_attr_check.rs new file mode 100644 index 0000000000000..2fd362656d4b7 --- /dev/null +++ b/src/test/codegen/sanitizer_memtag_attr_check.rs @@ -0,0 +1,12 @@ +// This tests that the sanitize_memtag attribute is +// applied when enabling the memtag sanitizer. +// +// needs-sanitizer-memtag +// compile-flags: -Zsanitizer=memtag -Ctarget-feature=+mte + +#![crate_type = "lib"] + +// CHECK: ; Function Attrs:{{.*}}sanitize_memtag +pub fn tagged() {} + +// CHECK: attributes #0 = {{.*}}sanitize_memtag diff --git a/src/test/ui/invalid/invalid-no-sanitize.stderr b/src/test/ui/invalid/invalid-no-sanitize.stderr index 4c0b17c7d3769..5a92555eb322e 100644 --- a/src/test/ui/invalid/invalid-no-sanitize.stderr +++ b/src/test/ui/invalid/invalid-no-sanitize.stderr @@ -4,7 +4,7 @@ error: invalid argument for `no_sanitize` LL | #[no_sanitize(brontosaurus)] | ^^^^^^^^^^^^ | - = note: expected one of: `address`, `hwaddress`, `memory` or `thread` + = note: expected one of: `address`, `cfi`, `hwaddress`, `memory`, `memtag`, or `thread` error: aborting due to previous error diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index da7a19139c65b..60c94eff47a0d 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -863,6 +863,7 @@ pub fn make_test_description( let has_msan = util::MSAN_SUPPORTED_TARGETS.contains(&&*config.target); let has_tsan = util::TSAN_SUPPORTED_TARGETS.contains(&&*config.target); let has_hwasan = util::HWASAN_SUPPORTED_TARGETS.contains(&&*config.target); + let has_memtag = util::MEMTAG_SUPPORTED_TARGETS.contains(&&*config.target); // for `-Z gcc-ld=lld` let has_rust_lld = config .compile_lib_path @@ -899,6 +900,7 @@ pub fn make_test_description( ignore |= !has_msan && config.parse_name_directive(ln, "needs-sanitizer-memory"); ignore |= !has_tsan && config.parse_name_directive(ln, "needs-sanitizer-thread"); ignore |= !has_hwasan && config.parse_name_directive(ln, "needs-sanitizer-hwaddress"); + ignore |= !has_memtag && config.parse_name_directive(ln, "needs-sanitizer-memtag"); ignore |= config.target_panic == PanicStrategy::Abort && config.parse_name_directive(ln, "needs-unwind"); ignore |= config.target == "wasm32-unknown-unknown" && config.parse_check_run_results(ln); diff --git a/src/tools/compiletest/src/util.rs b/src/tools/compiletest/src/util.rs index 6ca145a58e92a..bed509d77be77 100644 --- a/src/tools/compiletest/src/util.rs +++ b/src/tools/compiletest/src/util.rs @@ -117,6 +117,9 @@ pub const TSAN_SUPPORTED_TARGETS: &[&str] = &[ pub const HWASAN_SUPPORTED_TARGETS: &[&str] = &["aarch64-linux-android", "aarch64-unknown-linux-gnu"]; +pub const MEMTAG_SUPPORTED_TARGETS: &[&str] = + &["aarch64-linux-android", "aarch64-unknown-linux-gnu"]; + const BIG_ENDIAN: &[&str] = &[ "aarch64_be", "armebv7r", From f04f732503a239b3fac22be2238d21971aa03dce Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 11 Jan 2022 19:00:34 -0800 Subject: [PATCH 12/15] Add more information to `impl Trait` deny error --- compiler/rustc_ast_lowering/src/block.rs | 4 +- compiler/rustc_ast_lowering/src/expr.rs | 26 +-- compiler/rustc_ast_lowering/src/item.rs | 148 +++++++++++----- compiler/rustc_ast_lowering/src/lib.rs | 129 +++++++++++--- compiler/rustc_ast_lowering/src/pat.rs | 8 +- compiler/rustc_ast_lowering/src/path.rs | 16 +- .../feature-gate-associated_type_bounds.rs | 6 +- ...feature-gate-associated_type_bounds.stderr | 12 +- src/test/ui/impl-trait/issues/issue-54600.rs | 2 +- .../ui/impl-trait/issues/issue-54600.stderr | 4 +- src/test/ui/impl-trait/issues/issue-54840.rs | 2 +- .../ui/impl-trait/issues/issue-54840.stderr | 4 +- src/test/ui/impl-trait/issues/issue-58504.rs | 2 +- .../ui/impl-trait/issues/issue-58504.stderr | 4 +- src/test/ui/impl-trait/issues/issue-58956.rs | 4 +- .../ui/impl-trait/issues/issue-58956.stderr | 8 +- src/test/ui/impl-trait/issues/issue-70971.rs | 2 +- .../ui/impl-trait/issues/issue-70971.stderr | 4 +- src/test/ui/impl-trait/issues/issue-79099.rs | 2 +- .../ui/impl-trait/issues/issue-79099.stderr | 4 +- ...sue-83929-impl-trait-in-generic-default.rs | 4 +- ...83929-impl-trait-in-generic-default.stderr | 8 +- src/test/ui/impl-trait/issues/issue-84919.rs | 2 +- .../ui/impl-trait/issues/issue-84919.stderr | 4 +- src/test/ui/impl-trait/issues/issue-86642.rs | 2 +- .../ui/impl-trait/issues/issue-86642.stderr | 4 +- src/test/ui/impl-trait/issues/issue-87295.rs | 2 +- .../ui/impl-trait/issues/issue-87295.stderr | 4 +- .../ui/impl-trait/nested_impl_trait.stderr | 8 +- src/test/ui/impl-trait/where-allowed.rs | 82 ++++----- src/test/ui/impl-trait/where-allowed.stderr | 164 +++++++++++++----- src/test/ui/issues/issue-47715.stderr | 16 +- .../type-alias-impl-trait-fn-type.rs | 2 +- .../type-alias-impl-trait-fn-type.stderr | 4 +- 34 files changed, 487 insertions(+), 210 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/block.rs b/compiler/rustc_ast_lowering/src/block.rs index 082c5bb783347..3a7e0a70585f1 100644 --- a/compiler/rustc_ast_lowering/src/block.rs +++ b/compiler/rustc_ast_lowering/src/block.rs @@ -97,7 +97,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let ty = l .ty .as_ref() - .map(|t| self.lower_ty(t, ImplTraitContext::Disallowed(ImplTraitPosition::Binding))); + .map(|t| self.lower_ty(t, ImplTraitContext::Disallowed(ImplTraitPosition::Variable))); let init = l.kind.init().map(|init| self.lower_expr(init)); let hir_id = self.lower_node_id(l.id); let pat = self.lower_pat(&l.pat); @@ -127,7 +127,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let ty = local .ty .as_ref() - .map(|t| self.lower_ty(t, ImplTraitContext::Disallowed(ImplTraitPosition::Binding))); + .map(|t| self.lower_ty(t, ImplTraitContext::Disallowed(ImplTraitPosition::Variable))); let span = self.lower_span(local.span); let span = self.mark_span_with_reason(DesugaringKind::LetElse, span, None); let init = self.lower_expr(init); diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 17bc8d7591b40..d48ff10b97d91 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -1,3 +1,5 @@ +use crate::{FnDeclKind, ImplTraitPosition}; + use super::{ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs}; use rustc_ast::attr; @@ -53,7 +55,7 @@ impl<'hir> LoweringContext<'_, 'hir> { ParamMode::Optional, 0, ParenthesizedGenericArgs::Err, - ImplTraitContext::disallowed(), + ImplTraitContext::Disallowed(ImplTraitPosition::Path), )); let args = self.lower_exprs(args); hir::ExprKind::MethodCall(hir_seg, args, self.lower_span(span)) @@ -74,12 +76,14 @@ impl<'hir> LoweringContext<'_, 'hir> { } ExprKind::Cast(ref expr, ref ty) => { let expr = self.lower_expr(expr); - let ty = self.lower_ty(ty, ImplTraitContext::disallowed()); + let ty = + self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type)); hir::ExprKind::Cast(expr, ty) } ExprKind::Type(ref expr, ref ty) => { let expr = self.lower_expr(expr); - let ty = self.lower_ty(ty, ImplTraitContext::disallowed()); + let ty = + self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type)); hir::ExprKind::Type(expr, ty) } ExprKind::AddrOf(k, m, ref ohs) => { @@ -203,7 +207,7 @@ impl<'hir> LoweringContext<'_, 'hir> { qself, path, ParamMode::Optional, - ImplTraitContext::disallowed(), + ImplTraitContext::Disallowed(ImplTraitPosition::Path), ); hir::ExprKind::Path(qpath) } @@ -239,7 +243,7 @@ impl<'hir> LoweringContext<'_, 'hir> { &se.qself, &se.path, ParamMode::Optional, - ImplTraitContext::disallowed(), + ImplTraitContext::Disallowed(ImplTraitPosition::Path), )), self.arena .alloc_from_iter(se.fields.iter().map(|x| self.lower_expr_field(x))), @@ -538,7 +542,9 @@ impl<'hir> LoweringContext<'_, 'hir> { body: impl FnOnce(&mut Self) -> hir::Expr<'hir>, ) -> hir::ExprKind<'hir> { let output = match ret_ty { - Some(ty) => hir::FnRetTy::Return(self.lower_ty(&ty, ImplTraitContext::disallowed())), + Some(ty) => hir::FnRetTy::Return( + self.lower_ty(&ty, ImplTraitContext::Disallowed(ImplTraitPosition::AsyncBlock)), + ), None => hir::FnRetTy::DefaultReturn(self.lower_span(span)), }; @@ -827,7 +833,7 @@ impl<'hir> LoweringContext<'_, 'hir> { }); // Lower outside new scope to preserve `is_in_loop_condition`. - let fn_decl = self.lower_fn_decl(decl, None, false, None); + let fn_decl = self.lower_fn_decl(decl, None, FnDeclKind::Closure, None); hir::ExprKind::Closure( capture_clause, @@ -919,7 +925,7 @@ impl<'hir> LoweringContext<'_, 'hir> { // We need to lower the declaration outside the new scope, because we // have to conserve the state of being inside a loop condition for the // closure argument types. - let fn_decl = self.lower_fn_decl(&outer_decl, None, false, None); + let fn_decl = self.lower_fn_decl(&outer_decl, None, FnDeclKind::Closure, None); hir::ExprKind::Closure( capture_clause, @@ -1064,7 +1070,7 @@ impl<'hir> LoweringContext<'_, 'hir> { qself, path, ParamMode::Optional, - ImplTraitContext::disallowed(), + ImplTraitContext::Disallowed(ImplTraitPosition::Path), ); // Destructure like a tuple struct. let tuple_struct_pat = @@ -1089,7 +1095,7 @@ impl<'hir> LoweringContext<'_, 'hir> { &se.qself, &se.path, ParamMode::Optional, - ImplTraitContext::disallowed(), + ImplTraitContext::Disallowed(ImplTraitPosition::Path), ); let fields_omitted = match &se.rest { StructRest::Base(e) => { diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index f48cf212a984b..6489c729cfe50 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -1,6 +1,6 @@ use super::{AnonymousLifetimeMode, LoweringContext, ParamMode}; use super::{ImplTraitContext, ImplTraitPosition}; -use crate::Arena; +use crate::{Arena, FnDeclKind}; use rustc_ast::ptr::P; use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor}; @@ -246,7 +246,12 @@ impl<'hir> LoweringContext<'_, 'hir> { AnonymousLifetimeMode::PassThrough, |this, idty| { let ret_id = asyncness.opt_return_id(); - this.lower_fn_decl(&decl, Some((fn_def_id, idty)), true, ret_id) + this.lower_fn_decl( + &decl, + Some((fn_def_id, idty)), + FnDeclKind::Fn, + ret_id, + ) }, ); let sig = hir::FnSig { @@ -287,12 +292,18 @@ impl<'hir> LoweringContext<'_, 'hir> { capturable_lifetimes: &mut FxHashSet::default(), }, ); - let generics = self.lower_generics(generics, ImplTraitContext::disallowed()); + let generics = self.lower_generics( + generics, + ImplTraitContext::Disallowed(ImplTraitPosition::Generic), + ); hir::ItemKind::TyAlias(ty, generics) } ItemKind::TyAlias(box TyAlias { ref generics, ty: None, .. }) => { let ty = self.arena.alloc(self.ty(span, hir::TyKind::Err)); - let generics = self.lower_generics(generics, ImplTraitContext::disallowed()); + let generics = self.lower_generics( + generics, + ImplTraitContext::Disallowed(ImplTraitPosition::Generic), + ); hir::ItemKind::TyAlias(ty, generics) } ItemKind::Enum(ref enum_definition, ref generics) => hir::ItemKind::Enum( @@ -301,20 +312,29 @@ impl<'hir> LoweringContext<'_, 'hir> { enum_definition.variants.iter().map(|x| self.lower_variant(x)), ), }, - self.lower_generics(generics, ImplTraitContext::disallowed()), + self.lower_generics( + generics, + ImplTraitContext::Disallowed(ImplTraitPosition::Generic), + ), ), ItemKind::Struct(ref struct_def, ref generics) => { let struct_def = self.lower_variant_data(hir_id, struct_def); hir::ItemKind::Struct( struct_def, - self.lower_generics(generics, ImplTraitContext::disallowed()), + self.lower_generics( + generics, + ImplTraitContext::Disallowed(ImplTraitPosition::Generic), + ), ) } ItemKind::Union(ref vdata, ref generics) => { let vdata = self.lower_variant_data(hir_id, vdata); hir::ItemKind::Union( vdata, - self.lower_generics(generics, ImplTraitContext::disallowed()), + self.lower_generics( + generics, + ImplTraitContext::Disallowed(ImplTraitPosition::Generic), + ), ) } ItemKind::Impl(box Impl { @@ -347,10 +367,14 @@ impl<'hir> LoweringContext<'_, 'hir> { AnonymousLifetimeMode::CreateParameter, |this, _| { let trait_ref = trait_ref.as_ref().map(|trait_ref| { - this.lower_trait_ref(trait_ref, ImplTraitContext::disallowed()) + this.lower_trait_ref( + trait_ref, + ImplTraitContext::Disallowed(ImplTraitPosition::Trait), + ) }); - let lowered_ty = this.lower_ty(ty, ImplTraitContext::disallowed()); + let lowered_ty = this + .lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type)); (trait_ref, lowered_ty) }, @@ -390,21 +414,33 @@ impl<'hir> LoweringContext<'_, 'hir> { ref bounds, ref items, }) => { - let bounds = self.lower_param_bounds(bounds, ImplTraitContext::disallowed()); + let bounds = self.lower_param_bounds( + bounds, + ImplTraitContext::Disallowed(ImplTraitPosition::Bound), + ); let items = self .arena .alloc_from_iter(items.iter().map(|item| self.lower_trait_item_ref(item))); hir::ItemKind::Trait( is_auto, self.lower_unsafety(unsafety), - self.lower_generics(generics, ImplTraitContext::disallowed()), + self.lower_generics( + generics, + ImplTraitContext::Disallowed(ImplTraitPosition::Generic), + ), bounds, items, ) } ItemKind::TraitAlias(ref generics, ref bounds) => hir::ItemKind::TraitAlias( - self.lower_generics(generics, ImplTraitContext::disallowed()), - self.lower_param_bounds(bounds, ImplTraitContext::disallowed()), + self.lower_generics( + generics, + ImplTraitContext::Disallowed(ImplTraitPosition::Generic), + ), + self.lower_param_bounds( + bounds, + ImplTraitContext::Disallowed(ImplTraitPosition::Bound), + ), ), ItemKind::MacroDef(MacroDef { ref body, macro_rules }) => { let body = P(self.lower_mac_args(body)); @@ -423,7 +459,7 @@ impl<'hir> LoweringContext<'_, 'hir> { span: Span, body: Option<&Expr>, ) -> (&'hir hir::Ty<'hir>, hir::BodyId) { - let ty = self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Binding)); + let ty = self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type)); (ty, self.lower_const_body(span, body)) } @@ -667,7 +703,7 @@ impl<'hir> LoweringContext<'_, 'hir> { |this, _| { ( // Disallow `impl Trait` in foreign items. - this.lower_fn_decl(fdec, None, false, None), + this.lower_fn_decl(fdec, None, FnDeclKind::ExternFn, None), this.lower_fn_params_to_names(fdec), ) }, @@ -676,7 +712,8 @@ impl<'hir> LoweringContext<'_, 'hir> { hir::ForeignItemKind::Fn(fn_dec, fn_args, generics) } ForeignItemKind::Static(ref t, m, _) => { - let ty = self.lower_ty(t, ImplTraitContext::disallowed()); + let ty = + self.lower_ty(t, ImplTraitContext::Disallowed(ImplTraitPosition::Type)); hir::ForeignItemKind::Static(ty, m) } ForeignItemKind::TyAlias(..) => hir::ForeignItemKind::Type, @@ -744,11 +781,11 @@ impl<'hir> LoweringContext<'_, 'hir> { qself, path, ParamMode::ExplicitNamed, // no `'_` in declarations (Issue #61124) - ImplTraitContext::disallowed(), + ImplTraitContext::Disallowed(ImplTraitPosition::Path), ); self.arena.alloc(t) } else { - self.lower_ty(&f.ty, ImplTraitContext::disallowed()) + self.lower_ty(&f.ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type)) }; let hir_id = self.lower_node_id(f.id); self.lower_attrs(hir_id, &f.attrs); @@ -771,14 +808,19 @@ impl<'hir> LoweringContext<'_, 'hir> { let (generics, kind) = match i.kind { AssocItemKind::Const(_, ref ty, ref default) => { - let ty = self.lower_ty(ty, ImplTraitContext::disallowed()); + let ty = self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type)); let body = default.as_ref().map(|x| self.lower_const_body(i.span, Some(x))); (hir::Generics::empty(), hir::TraitItemKind::Const(ty, body)) } AssocItemKind::Fn(box Fn { ref sig, ref generics, body: None, .. }) => { let names = self.lower_fn_params_to_names(&sig.decl); - let (generics, sig) = - self.lower_method_sig(generics, sig, trait_item_def_id, false, None); + let (generics, sig) = self.lower_method_sig( + generics, + sig, + trait_item_def_id, + FnDeclKind::Trait, + None, + ); (generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Required(names))) } AssocItemKind::Fn(box Fn { ref sig, ref generics, body: Some(ref body), .. }) => { @@ -789,16 +831,24 @@ impl<'hir> LoweringContext<'_, 'hir> { generics, sig, trait_item_def_id, - false, + FnDeclKind::Trait, asyncness.opt_return_id(), ); (generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Provided(body_id))) } AssocItemKind::TyAlias(box TyAlias { ref generics, ref bounds, ref ty, .. }) => { - let ty = ty.as_ref().map(|x| self.lower_ty(x, ImplTraitContext::disallowed())); - let generics = self.lower_generics(generics, ImplTraitContext::disallowed()); + let ty = ty.as_ref().map(|x| { + self.lower_ty(x, ImplTraitContext::Disallowed(ImplTraitPosition::Type)) + }); + let generics = self.lower_generics( + generics, + ImplTraitContext::Disallowed(ImplTraitPosition::Generic), + ); let kind = hir::TraitItemKind::Type( - self.lower_param_bounds(bounds, ImplTraitContext::disallowed()), + self.lower_param_bounds( + bounds, + ImplTraitContext::Disallowed(ImplTraitPosition::Bound), + ), ty, ); @@ -850,7 +900,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let (generics, kind) = match &i.kind { AssocItemKind::Const(_, ty, expr) => { - let ty = self.lower_ty(ty, ImplTraitContext::disallowed()); + let ty = self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type)); ( hir::Generics::empty(), hir::ImplItemKind::Const(ty, self.lower_const_body(i.span, expr.as_deref())), @@ -861,19 +911,21 @@ impl<'hir> LoweringContext<'_, 'hir> { let asyncness = sig.header.asyncness; let body_id = self.lower_maybe_async_body(i.span, &sig.decl, asyncness, body.as_deref()); - let impl_trait_return_allow = !self.is_in_trait_impl; let (generics, sig) = self.lower_method_sig( generics, sig, impl_item_def_id, - impl_trait_return_allow, + if self.is_in_trait_impl { FnDeclKind::Impl } else { FnDeclKind::Inherent }, asyncness.opt_return_id(), ); (generics, hir::ImplItemKind::Fn(sig, body_id)) } AssocItemKind::TyAlias(box TyAlias { generics, ty, .. }) => { - let generics = self.lower_generics(generics, ImplTraitContext::disallowed()); + let generics = self.lower_generics( + generics, + ImplTraitContext::Disallowed(ImplTraitPosition::Generic), + ); let kind = match ty { None => { let ty = self.arena.alloc(self.ty(i.span, hir::TyKind::Err)); @@ -1248,7 +1300,7 @@ impl<'hir> LoweringContext<'_, 'hir> { generics: &Generics, sig: &FnSig, fn_def_id: LocalDefId, - impl_trait_return_allow: bool, + kind: FnDeclKind, is_async: Option, ) -> (hir::Generics<'hir>, hir::FnSig<'hir>) { let header = self.lower_fn_header(sig.header); @@ -1256,14 +1308,7 @@ impl<'hir> LoweringContext<'_, 'hir> { generics, fn_def_id, AnonymousLifetimeMode::PassThrough, - |this, idty| { - this.lower_fn_decl( - &sig.decl, - Some((fn_def_id, idty)), - impl_trait_return_allow, - is_async, - ) - }, + |this, idty| this.lower_fn_decl(&sig.decl, Some((fn_def_id, idty)), kind, is_async), ); (generics, hir::FnSig { header, decl, span: self.lower_span(sig.span) }) } @@ -1409,11 +1454,19 @@ impl<'hir> LoweringContext<'_, 'hir> { span, }) => self.with_in_scope_lifetime_defs(&bound_generic_params, |this| { hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate { - bound_generic_params: this - .lower_generic_params(bound_generic_params, ImplTraitContext::disallowed()), - bounded_ty: this.lower_ty(bounded_ty, ImplTraitContext::disallowed()), + bound_generic_params: this.lower_generic_params( + bound_generic_params, + ImplTraitContext::Disallowed(ImplTraitPosition::Generic), + ), + bounded_ty: this.lower_ty( + bounded_ty, + ImplTraitContext::Disallowed(ImplTraitPosition::Type), + ), bounds: this.arena.alloc_from_iter(bounds.iter().map(|bound| { - this.lower_param_bound(bound, ImplTraitContext::disallowed()) + this.lower_param_bound( + bound, + ImplTraitContext::Disallowed(ImplTraitPosition::Bound), + ) })), span: this.lower_span(span), }) @@ -1425,13 +1478,18 @@ impl<'hir> LoweringContext<'_, 'hir> { }) => hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate { span: self.lower_span(span), lifetime: self.lower_lifetime(lifetime), - bounds: self.lower_param_bounds(bounds, ImplTraitContext::disallowed()), + bounds: self.lower_param_bounds( + bounds, + ImplTraitContext::Disallowed(ImplTraitPosition::Bound), + ), }), WherePredicate::EqPredicate(WhereEqPredicate { id, ref lhs_ty, ref rhs_ty, span }) => { hir::WherePredicate::EqPredicate(hir::WhereEqPredicate { hir_id: self.lower_node_id(id), - lhs_ty: self.lower_ty(lhs_ty, ImplTraitContext::disallowed()), - rhs_ty: self.lower_ty(rhs_ty, ImplTraitContext::disallowed()), + lhs_ty: self + .lower_ty(lhs_ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type)), + rhs_ty: self + .lower_ty(rhs_ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type)), span: self.lower_span(span), }) } diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 60b5aeb52b18f..803c93c259eeb 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -256,19 +256,28 @@ enum ImplTraitContext<'b, 'a> { /// Position in which `impl Trait` is disallowed. #[derive(Debug, Copy, Clone, PartialEq, Eq)] enum ImplTraitPosition { - /// Disallowed in `let` / `const` / `static` bindings. - Binding, - - /// All other positions. - Other, + Path, + Variable, + Type, + Trait, + AsyncBlock, + Bound, + Generic, + ExternFnParam, + ClosureParam, + PointerParam, + FnTraitParam, + TraitParam, + ImplParam, + ExternFnReturn, + ClosureReturn, + PointerReturn, + FnTraitReturn, + TraitReturn, + ImplReturn, } impl<'a> ImplTraitContext<'_, 'a> { - #[inline] - fn disallowed() -> Self { - ImplTraitContext::Disallowed(ImplTraitPosition::Other) - } - fn reborrow<'this>(&'this mut self) -> ImplTraitContext<'this, 'a> { use self::ImplTraitContext::*; match self { @@ -284,6 +293,54 @@ impl<'a> ImplTraitContext<'_, 'a> { } } +impl std::fmt::Display for ImplTraitPosition { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let name = match self { + ImplTraitPosition::Path => "path", + ImplTraitPosition::Variable => "variable", + ImplTraitPosition::Type => "type", + ImplTraitPosition::Trait => "trait", + ImplTraitPosition::AsyncBlock => "async block", + ImplTraitPosition::Bound => "bound", + ImplTraitPosition::Generic => "generic", + ImplTraitPosition::ExternFnParam => "`extern fn` param", + ImplTraitPosition::ClosureParam => "closure param", + ImplTraitPosition::PointerParam => "`fn` pointer param", + ImplTraitPosition::FnTraitParam => "`Fn` trait param", + ImplTraitPosition::TraitParam => "trait method param", + ImplTraitPosition::ImplParam => "`impl` method param", + ImplTraitPosition::ExternFnReturn => "`extern fn` return", + ImplTraitPosition::ClosureReturn => "closure return", + ImplTraitPosition::PointerReturn => "`fn` pointer return", + ImplTraitPosition::FnTraitReturn => "`Fn` trait return", + ImplTraitPosition::TraitReturn => "trait method return", + ImplTraitPosition::ImplReturn => "`impl` method return", + }; + + write!(f, "{}", name) + } +} + +#[derive(Debug)] +enum FnDeclKind { + Fn, + Inherent, + ExternFn, + Closure, + Pointer, + Trait, + Impl, +} + +impl FnDeclKind { + fn impl_trait_return_allowed(&self) -> bool { + match self { + FnDeclKind::Fn | FnDeclKind::Inherent => true, + _ => false, + } + } +} + pub fn lower_crate<'a, 'hir>( sess: &'a Session, krate: &'a Crate, @@ -1232,11 +1289,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { hir::TyKind::BareFn(this.arena.alloc(hir::BareFnTy { generic_params: this.lower_generic_params( &f.generic_params, - ImplTraitContext::disallowed(), + ImplTraitContext::Disallowed(ImplTraitPosition::Generic), ), unsafety: this.lower_unsafety(f.unsafety), abi: this.lower_extern(f.ext), - decl: this.lower_fn_decl(&f.decl, None, false, None), + decl: this.lower_fn_decl(&f.decl, None, FnDeclKind::Pointer, None), param_names: this.lower_fn_params_to_names(&f.decl), })) }) @@ -1357,14 +1414,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { }), )) } - ImplTraitContext::Disallowed(_) => { + ImplTraitContext::Disallowed(position) => { let mut err = struct_span_err!( self.sess, t.span, E0562, - "`impl Trait` not allowed outside of {}", - "function and method return types", + "`impl Trait` not allowed outside of \ + function and inherent method return types", ); + err.note(&format!("found `impl Trait` in {}", position)); err.emit(); hir::TyKind::Err } @@ -1528,16 +1586,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { &mut self, decl: &FnDecl, mut in_band_ty_params: Option<(LocalDefId, &mut Vec>)>, - impl_trait_return_allow: bool, + kind: FnDeclKind, make_ret_async: Option, ) -> &'hir hir::FnDecl<'hir> { debug!( "lower_fn_decl(\ fn_decl: {:?}, \ in_band_ty_params: {:?}, \ - impl_trait_return_allow: {}, \ + kind: {:?}, \ make_ret_async: {:?})", - decl, in_band_ty_params, impl_trait_return_allow, make_ret_async, + decl, in_band_ty_params, kind, make_ret_async, ); let lt_mode = if make_ret_async.is_some() { // In `async fn`, argument-position elided lifetimes @@ -1567,7 +1625,19 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { ImplTraitContext::Universal(ibty, this.current_hir_id_owner), ) } else { - this.lower_ty_direct(¶m.ty, ImplTraitContext::disallowed()) + this.lower_ty_direct( + ¶m.ty, + ImplTraitContext::Disallowed(match kind { + FnDeclKind::Fn | FnDeclKind::Inherent => { + unreachable!("fn should allow in-band lifetimes") + } + FnDeclKind::ExternFn => ImplTraitPosition::ExternFnParam, + FnDeclKind::Closure => ImplTraitPosition::ClosureParam, + FnDeclKind::Pointer => ImplTraitPosition::PointerParam, + FnDeclKind::Trait => ImplTraitPosition::TraitParam, + FnDeclKind::Impl => ImplTraitPosition::ImplParam, + }), + ) } })) }); @@ -1582,13 +1652,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { match decl.output { FnRetTy::Ty(ref ty) => { let context = match in_band_ty_params { - Some((def_id, _)) if impl_trait_return_allow => { + Some((def_id, _)) if kind.impl_trait_return_allowed() => { ImplTraitContext::ReturnPositionOpaqueTy { fn_def_id: def_id, origin: hir::OpaqueTyOrigin::FnReturn(def_id), } } - _ => ImplTraitContext::disallowed(), + _ => ImplTraitContext::Disallowed(match kind { + FnDeclKind::Fn | FnDeclKind::Inherent => { + unreachable!("fn should allow in-band lifetimes") + } + FnDeclKind::ExternFn => ImplTraitPosition::ExternFnReturn, + FnDeclKind::Closure => ImplTraitPosition::ClosureReturn, + FnDeclKind::Pointer => ImplTraitPosition::PointerReturn, + FnDeclKind::Trait => ImplTraitPosition::TraitReturn, + FnDeclKind::Impl => ImplTraitPosition::ImplReturn, + }), }; hir::FnRetTy::Return(self.lower_ty(ty, context)) } @@ -1915,7 +1994,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { GenericParamKind::Type { ref default, .. } => { let kind = hir::GenericParamKind::Type { default: default.as_ref().map(|x| { - self.lower_ty(x, ImplTraitContext::Disallowed(ImplTraitPosition::Other)) + self.lower_ty(x, ImplTraitContext::Disallowed(ImplTraitPosition::Type)) }), synthetic: false, }; @@ -1923,9 +2002,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { (hir::ParamName::Plain(self.lower_ident(param.ident)), kind) } GenericParamKind::Const { ref ty, kw_span: _, ref default } => { - let ty = self - .with_anonymous_lifetime_mode(AnonymousLifetimeMode::ReportError, |this| { - this.lower_ty(&ty, ImplTraitContext::disallowed()) + let ty = + self.with_anonymous_lifetime_mode(AnonymousLifetimeMode::ReportError, |this| { + this.lower_ty(&ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type)) }); let default = default.as_ref().map(|def| self.lower_anon_const(def)); ( diff --git a/compiler/rustc_ast_lowering/src/pat.rs b/compiler/rustc_ast_lowering/src/pat.rs index ebae77984330f..2c331767b8958 100644 --- a/compiler/rustc_ast_lowering/src/pat.rs +++ b/compiler/rustc_ast_lowering/src/pat.rs @@ -1,3 +1,5 @@ +use crate::ImplTraitPosition; + use super::{ImplTraitContext, LoweringContext, ParamMode}; use rustc_ast::ptr::P; @@ -33,7 +35,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { qself, path, ParamMode::Optional, - ImplTraitContext::disallowed(), + ImplTraitContext::Disallowed(ImplTraitPosition::Path), ); let (pats, ddpos) = self.lower_pat_tuple(pats, "tuple struct"); break hir::PatKind::TupleStruct(qpath, pats, ddpos); @@ -49,7 +51,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { qself, path, ParamMode::Optional, - ImplTraitContext::disallowed(), + ImplTraitContext::Disallowed(ImplTraitPosition::Path), ); break hir::PatKind::Path(qpath); } @@ -59,7 +61,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { qself, path, ParamMode::Optional, - ImplTraitContext::disallowed(), + ImplTraitContext::Disallowed(ImplTraitPosition::Path), ); let fs = self.arena.alloc_from_iter(fields.iter().map(|f| hir::PatField { diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs index 79262235cd9f2..b35e3a071619a 100644 --- a/compiler/rustc_ast_lowering/src/path.rs +++ b/compiler/rustc_ast_lowering/src/path.rs @@ -1,3 +1,5 @@ +use crate::ImplTraitPosition; + use super::{AnonymousLifetimeMode, ImplTraitContext, LoweringContext, ParamMode}; use super::{GenericArgsCtor, ParenthesizedGenericArgs}; @@ -184,7 +186,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { param_mode, 0, ParenthesizedGenericArgs::Err, - ImplTraitContext::disallowed(), + ImplTraitContext::Disallowed(ImplTraitPosition::Path), ) })), span: self.lower_span(p.span), @@ -392,11 +394,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { // we generally don't permit such things (see #51008). self.with_anonymous_lifetime_mode(AnonymousLifetimeMode::PassThrough, |this| { let ParenthesizedArgs { span, inputs, inputs_span, output } = data; - let inputs = this.arena.alloc_from_iter( - inputs.iter().map(|ty| this.lower_ty_direct(ty, ImplTraitContext::disallowed())), - ); + let inputs = this.arena.alloc_from_iter(inputs.iter().map(|ty| { + this.lower_ty_direct( + ty, + ImplTraitContext::Disallowed(ImplTraitPosition::FnTraitParam), + ) + })); let output_ty = match output { - FnRetTy::Ty(ty) => this.lower_ty(&ty, ImplTraitContext::disallowed()), + FnRetTy::Ty(ty) => this + .lower_ty(&ty, ImplTraitContext::Disallowed(ImplTraitPosition::FnTraitReturn)), FnRetTy::Default(_) => this.arena.alloc(this.ty_tup(*span, &[])), }; let args = smallvec![GenericArg::Type(this.ty_tup(*inputs_span, inputs))]; diff --git a/src/test/ui/feature-gates/feature-gate-associated_type_bounds.rs b/src/test/ui/feature-gates/feature-gate-associated_type_bounds.rs index 1e48996acb833..38be85ff8201e 100644 --- a/src/test/ui/feature-gates/feature-gate-associated_type_bounds.rs +++ b/src/test/ui/feature-gates/feature-gate-associated_type_bounds.rs @@ -57,20 +57,20 @@ fn _rpit_dyn() -> Box> { Box::new(S1) } const _cdef: impl Tr1 = S1; //~^ ERROR associated type bounds are unstable -//~| ERROR `impl Trait` not allowed outside of function and method return types [E0562] +//~| ERROR `impl Trait` not allowed outside of function and inherent method return types [E0562] // FIXME: uncomment when `impl_trait_in_bindings` feature is fixed. // const _cdef_dyn: &dyn Tr1 = &S1; static _sdef: impl Tr1 = S1; //~^ ERROR associated type bounds are unstable -//~| ERROR `impl Trait` not allowed outside of function and method return types [E0562] +//~| ERROR `impl Trait` not allowed outside of function and inherent method return types [E0562] // FIXME: uncomment when `impl_trait_in_bindings` feature is fixed. // static _sdef_dyn: &dyn Tr1 = &S1; fn main() { let _: impl Tr1 = S1; //~^ ERROR associated type bounds are unstable - //~| ERROR `impl Trait` not allowed outside of function and method return types [E0562] + //~| ERROR `impl Trait` not allowed outside of function and inherent method return types [E0562] // FIXME: uncomment when `impl_trait_in_bindings` feature is fixed. // let _: &dyn Tr1 = &S1; } diff --git a/src/test/ui/feature-gates/feature-gate-associated_type_bounds.stderr b/src/test/ui/feature-gates/feature-gate-associated_type_bounds.stderr index 8c5d72d7efefb..26f10622344da 100644 --- a/src/test/ui/feature-gates/feature-gate-associated_type_bounds.stderr +++ b/src/test/ui/feature-gates/feature-gate-associated_type_bounds.stderr @@ -115,23 +115,29 @@ LL | let _: impl Tr1 = S1; = note: see issue #52662 for more information = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/feature-gate-associated_type_bounds.rs:58:14 | LL | const _cdef: impl Tr1 = S1; | ^^^^^^^^^^^^^^^^^^^ + | + = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/feature-gate-associated_type_bounds.rs:64:15 | LL | static _sdef: impl Tr1 = S1; | ^^^^^^^^^^^^^^^^^^^ + | + = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/feature-gate-associated_type_bounds.rs:71:12 | LL | let _: impl Tr1 = S1; | ^^^^^^^^^^^^^^^^^^^ + | + = note: found `impl Trait` in variable error[E0277]: the trait bound `<::A as Iterator>::Item: Copy` is not satisfied --> $DIR/feature-gate-associated_type_bounds.rs:15:28 diff --git a/src/test/ui/impl-trait/issues/issue-54600.rs b/src/test/ui/impl-trait/issues/issue-54600.rs index 7a64799302332..e0e8f27401738 100644 --- a/src/test/ui/impl-trait/issues/issue-54600.rs +++ b/src/test/ui/impl-trait/issues/issue-54600.rs @@ -2,6 +2,6 @@ use std::fmt::Debug; fn main() { let x: Option = Some(44_u32); - //~^ `impl Trait` not allowed outside of function and method return types + //~^ `impl Trait` not allowed outside of function and inherent method return types println!("{:?}", x); } diff --git a/src/test/ui/impl-trait/issues/issue-54600.stderr b/src/test/ui/impl-trait/issues/issue-54600.stderr index 4d0c32c6bb708..c9626175ff511 100644 --- a/src/test/ui/impl-trait/issues/issue-54600.stderr +++ b/src/test/ui/impl-trait/issues/issue-54600.stderr @@ -1,8 +1,10 @@ -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/issue-54600.rs:4:19 | LL | let x: Option = Some(44_u32); | ^^^^^^^^^^ + | + = note: found `impl Trait` in variable error: aborting due to previous error diff --git a/src/test/ui/impl-trait/issues/issue-54840.rs b/src/test/ui/impl-trait/issues/issue-54840.rs index 030d5715d5739..8756d1c7de394 100644 --- a/src/test/ui/impl-trait/issues/issue-54840.rs +++ b/src/test/ui/impl-trait/issues/issue-54840.rs @@ -3,5 +3,5 @@ use std::ops::Add; fn main() { let i: i32 = 0; let j: &impl Add = &i; - //~^ `impl Trait` not allowed outside of function and method return types + //~^ `impl Trait` not allowed outside of function and inherent method return types } diff --git a/src/test/ui/impl-trait/issues/issue-54840.stderr b/src/test/ui/impl-trait/issues/issue-54840.stderr index b8046b7482f72..a947e0fc46d47 100644 --- a/src/test/ui/impl-trait/issues/issue-54840.stderr +++ b/src/test/ui/impl-trait/issues/issue-54840.stderr @@ -1,8 +1,10 @@ -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/issue-54840.rs:5:13 | LL | let j: &impl Add = &i; | ^^^^^^^^ + | + = note: found `impl Trait` in variable error: aborting due to previous error diff --git a/src/test/ui/impl-trait/issues/issue-58504.rs b/src/test/ui/impl-trait/issues/issue-58504.rs index aac33b3b3e5c5..ccbe187cef685 100644 --- a/src/test/ui/impl-trait/issues/issue-58504.rs +++ b/src/test/ui/impl-trait/issues/issue-58504.rs @@ -8,5 +8,5 @@ fn mk_gen() -> impl Generator { fn main() { let gens: [impl Generator;2] = [ mk_gen(), mk_gen() ]; - //~^ `impl Trait` not allowed outside of function and method return types + //~^ `impl Trait` not allowed outside of function and inherent method return types } diff --git a/src/test/ui/impl-trait/issues/issue-58504.stderr b/src/test/ui/impl-trait/issues/issue-58504.stderr index ff1010f066182..6c59bcfa11da2 100644 --- a/src/test/ui/impl-trait/issues/issue-58504.stderr +++ b/src/test/ui/impl-trait/issues/issue-58504.stderr @@ -1,8 +1,10 @@ -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/issue-58504.rs:10:16 | LL | let gens: [impl Generator;2] = [ mk_gen(), mk_gen() ]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: found `impl Trait` in variable error: aborting due to previous error diff --git a/src/test/ui/impl-trait/issues/issue-58956.rs b/src/test/ui/impl-trait/issues/issue-58956.rs index 5fe18b6e9b54a..615dc5b2f29c4 100644 --- a/src/test/ui/impl-trait/issues/issue-58956.rs +++ b/src/test/ui/impl-trait/issues/issue-58956.rs @@ -5,9 +5,9 @@ impl Lam for B {} pub struct Wrap(T); const _A: impl Lam = { - //~^ `impl Trait` not allowed outside of function and method return types + //~^ `impl Trait` not allowed outside of function and inherent method return types let x: Wrap = Wrap(B); - //~^ `impl Trait` not allowed outside of function and method return types + //~^ `impl Trait` not allowed outside of function and inherent method return types x.0 }; diff --git a/src/test/ui/impl-trait/issues/issue-58956.stderr b/src/test/ui/impl-trait/issues/issue-58956.stderr index 00ebf170ab2fe..f9bcb94d49d2d 100644 --- a/src/test/ui/impl-trait/issues/issue-58956.stderr +++ b/src/test/ui/impl-trait/issues/issue-58956.stderr @@ -1,14 +1,18 @@ -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/issue-58956.rs:7:11 | LL | const _A: impl Lam = { | ^^^^^^^^ + | + = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/issue-58956.rs:9:17 | LL | let x: Wrap = Wrap(B); | ^^^^^^^^ + | + = note: found `impl Trait` in variable error: aborting due to 2 previous errors diff --git a/src/test/ui/impl-trait/issues/issue-70971.rs b/src/test/ui/impl-trait/issues/issue-70971.rs index d4dc2fd877b67..4329cf6264476 100644 --- a/src/test/ui/impl-trait/issues/issue-70971.rs +++ b/src/test/ui/impl-trait/issues/issue-70971.rs @@ -1,4 +1,4 @@ fn main() { let x : (impl Copy,) = (true,); - //~^ `impl Trait` not allowed outside of function and method return types + //~^ `impl Trait` not allowed outside of function and inherent method return types } diff --git a/src/test/ui/impl-trait/issues/issue-70971.stderr b/src/test/ui/impl-trait/issues/issue-70971.stderr index 31993da3e32f3..831c0980068c3 100644 --- a/src/test/ui/impl-trait/issues/issue-70971.stderr +++ b/src/test/ui/impl-trait/issues/issue-70971.stderr @@ -1,8 +1,10 @@ -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/issue-70971.rs:2:14 | LL | let x : (impl Copy,) = (true,); | ^^^^^^^^^ + | + = note: found `impl Trait` in variable error: aborting due to previous error diff --git a/src/test/ui/impl-trait/issues/issue-79099.rs b/src/test/ui/impl-trait/issues/issue-79099.rs index f72533d42e1fa..add2d72907cd4 100644 --- a/src/test/ui/impl-trait/issues/issue-79099.rs +++ b/src/test/ui/impl-trait/issues/issue-79099.rs @@ -1,7 +1,7 @@ struct Bug { V1: [(); { let f: impl core::future::Future = async { 1 }; - //~^ `impl Trait` not allowed outside of function and method return types + //~^ `impl Trait` not allowed outside of function and inherent method return types //~| expected identifier 1 }], diff --git a/src/test/ui/impl-trait/issues/issue-79099.stderr b/src/test/ui/impl-trait/issues/issue-79099.stderr index 394b697a2504b..c70eb5a1e9d80 100644 --- a/src/test/ui/impl-trait/issues/issue-79099.stderr +++ b/src/test/ui/impl-trait/issues/issue-79099.stderr @@ -9,11 +9,13 @@ LL | let f: impl core::future::Future = async { 1 }; = help: set `edition = "2021"` in `Cargo.toml` = note: for more on editions, read https://doc.rust-lang.org/edition-guide -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/issue-79099.rs:3:16 | LL | let f: impl core::future::Future = async { 1 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: found `impl Trait` in variable error: aborting due to 2 previous errors diff --git a/src/test/ui/impl-trait/issues/issue-83929-impl-trait-in-generic-default.rs b/src/test/ui/impl-trait/issues/issue-83929-impl-trait-in-generic-default.rs index 773cd0b81cc53..d9d2e3929b10c 100644 --- a/src/test/ui/impl-trait/issues/issue-83929-impl-trait-in-generic-default.rs +++ b/src/test/ui/impl-trait/issues/issue-83929-impl-trait-in-generic-default.rs @@ -1,8 +1,8 @@ struct Foo(T); -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types type Result = std::result::Result; -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types // should not cause ICE fn x() -> Foo { diff --git a/src/test/ui/impl-trait/issues/issue-83929-impl-trait-in-generic-default.stderr b/src/test/ui/impl-trait/issues/issue-83929-impl-trait-in-generic-default.stderr index d44dcf1f7fa23..1cac44e796b2c 100644 --- a/src/test/ui/impl-trait/issues/issue-83929-impl-trait-in-generic-default.stderr +++ b/src/test/ui/impl-trait/issues/issue-83929-impl-trait-in-generic-default.stderr @@ -1,14 +1,18 @@ -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/issue-83929-impl-trait-in-generic-default.rs:1:16 | LL | struct Foo(T); | ^^^^^^^^^ + | + = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/issue-83929-impl-trait-in-generic-default.rs:4:20 | LL | type Result = std::result::Result; | ^^^^^^^^^^^^^^^^^^^^^^ + | + = note: found `impl Trait` in type error: aborting due to 2 previous errors diff --git a/src/test/ui/impl-trait/issues/issue-84919.rs b/src/test/ui/impl-trait/issues/issue-84919.rs index 479bad97cdf32..6abe3cd7ea5c1 100644 --- a/src/test/ui/impl-trait/issues/issue-84919.rs +++ b/src/test/ui/impl-trait/issues/issue-84919.rs @@ -3,7 +3,7 @@ impl Trait for () {} fn foo<'a: 'a>() { let _x: impl Trait = (); - //~^ `impl Trait` not allowed outside of function and method return types + //~^ `impl Trait` not allowed outside of function and inherent method return types } fn main() {} diff --git a/src/test/ui/impl-trait/issues/issue-84919.stderr b/src/test/ui/impl-trait/issues/issue-84919.stderr index bb1bcfefe64ee..36fc750cf87b0 100644 --- a/src/test/ui/impl-trait/issues/issue-84919.stderr +++ b/src/test/ui/impl-trait/issues/issue-84919.stderr @@ -1,8 +1,10 @@ -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/issue-84919.rs:5:13 | LL | let _x: impl Trait = (); | ^^^^^^^^^^ + | + = note: found `impl Trait` in variable error: aborting due to previous error diff --git a/src/test/ui/impl-trait/issues/issue-86642.rs b/src/test/ui/impl-trait/issues/issue-86642.rs index 8953ff8158148..c7e4045f43205 100644 --- a/src/test/ui/impl-trait/issues/issue-86642.rs +++ b/src/test/ui/impl-trait/issues/issue-86642.rs @@ -1,5 +1,5 @@ static x: impl Fn(&str) -> Result<&str, ()> = move |source| { - //~^ `impl Trait` not allowed outside of function and method return types + //~^ `impl Trait` not allowed outside of function and inherent method return types let res = (move |source| Ok(source))(source); let res = res.or((move |source| Ok(source))(source)); res diff --git a/src/test/ui/impl-trait/issues/issue-86642.stderr b/src/test/ui/impl-trait/issues/issue-86642.stderr index 2fc0a6fe1f50e..d12f0f3d2a9f3 100644 --- a/src/test/ui/impl-trait/issues/issue-86642.stderr +++ b/src/test/ui/impl-trait/issues/issue-86642.stderr @@ -1,8 +1,10 @@ -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/issue-86642.rs:1:11 | LL | static x: impl Fn(&str) -> Result<&str, ()> = move |source| { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: found `impl Trait` in type error: aborting due to previous error diff --git a/src/test/ui/impl-trait/issues/issue-87295.rs b/src/test/ui/impl-trait/issues/issue-87295.rs index 2f2bfe147bd66..da75e777398f5 100644 --- a/src/test/ui/impl-trait/issues/issue-87295.rs +++ b/src/test/ui/impl-trait/issues/issue-87295.rs @@ -14,5 +14,5 @@ impl Struct { fn main() { let _do_not_waste: Struct> = Struct::new(()); - //~^ `impl Trait` not allowed outside of function and method return types + //~^ `impl Trait` not allowed outside of function and inherent method return types } diff --git a/src/test/ui/impl-trait/issues/issue-87295.stderr b/src/test/ui/impl-trait/issues/issue-87295.stderr index f5c7603ce4918..6bdc356b6a406 100644 --- a/src/test/ui/impl-trait/issues/issue-87295.stderr +++ b/src/test/ui/impl-trait/issues/issue-87295.stderr @@ -1,8 +1,10 @@ -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/issue-87295.rs:16:31 | LL | let _do_not_waste: Struct> = Struct::new(()); | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: found `impl Trait` in variable error: aborting due to previous error diff --git a/src/test/ui/impl-trait/nested_impl_trait.stderr b/src/test/ui/impl-trait/nested_impl_trait.stderr index 59c7e4d5f4e92..c6a56ea0e302f 100644 --- a/src/test/ui/impl-trait/nested_impl_trait.stderr +++ b/src/test/ui/impl-trait/nested_impl_trait.stderr @@ -34,17 +34,21 @@ LL | fn bad(x: impl Into) -> impl Into { x } | | nested `impl Trait` here | outer `impl Trait` -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/nested_impl_trait.rs:8:32 | LL | fn bad_in_fn_syntax(x: fn() -> impl Into) {} | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: found `impl Trait` in `fn` pointer return -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/nested_impl_trait.rs:25:42 | LL | fn allowed_in_ret_type() -> impl Fn() -> impl Into { | ^^^^^^^^^^^^^^ + | + = note: found `impl Trait` in `Fn` trait return error: aborting due to 6 previous errors diff --git a/src/test/ui/impl-trait/where-allowed.rs b/src/test/ui/impl-trait/where-allowed.rs index 35fb42d621322..07d28dbd025ac 100644 --- a/src/test/ui/impl-trait/where-allowed.rs +++ b/src/test/ui/impl-trait/where-allowed.rs @@ -13,61 +13,61 @@ fn in_adt_in_parameters(_: Vec) { panic!() } // Disallowed fn in_fn_parameter_in_parameters(_: fn(impl Debug)) { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types // Disallowed fn in_fn_return_in_parameters(_: fn() -> impl Debug) { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types // Disallowed fn in_fn_parameter_in_return() -> fn(impl Debug) { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types // Disallowed fn in_fn_return_in_return() -> fn() -> impl Debug { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types // Disallowed fn in_dyn_Fn_parameter_in_parameters(_: &dyn Fn(impl Debug)) { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types // Disallowed fn in_dyn_Fn_return_in_parameters(_: &dyn Fn() -> impl Debug) { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types // Disallowed fn in_dyn_Fn_parameter_in_return() -> &'static dyn Fn(impl Debug) { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types // Disallowed fn in_dyn_Fn_return_in_return() -> &'static dyn Fn() -> impl Debug { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types // Disallowed fn in_impl_Fn_parameter_in_parameters(_: &impl Fn(impl Debug)) { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types //~^^ ERROR nested `impl Trait` is not allowed // Disallowed fn in_impl_Fn_return_in_parameters(_: &impl Fn() -> impl Debug) { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types // Disallowed fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types //~| ERROR nested `impl Trait` is not allowed // Disallowed fn in_impl_Fn_return_in_return() -> &'static impl Fn() -> impl Debug { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types // Disallowed fn in_Fn_parameter_in_generics (_: F) { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types // Disallowed fn in_Fn_return_in_generics impl Debug> (_: F) { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types // Allowed @@ -80,22 +80,22 @@ fn in_impl_Trait_in_return() -> impl IntoIterator { // Disallowed struct InBraceStructField { x: impl Debug } -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types // Disallowed struct InAdtInBraceStructField { x: Vec } -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types // Disallowed struct InTupleStructField(impl Debug); -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types // Disallowed enum InEnum { InBraceVariant { x: impl Debug }, - //~^ ERROR `impl Trait` not allowed outside of function and method return types + //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types InTupleVariant(impl Debug), - //~^ ERROR `impl Trait` not allowed outside of function and method return types + //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types } // Allowed @@ -106,7 +106,7 @@ trait InTraitDefnParameters { // Disallowed trait InTraitDefnReturn { fn in_return() -> impl Debug; - //~^ ERROR `impl Trait` not allowed outside of function and method return types + //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types } // Allowed and disallowed in trait impls @@ -123,7 +123,7 @@ impl DummyTrait for () { // Allowed fn in_trait_impl_return() -> impl Debug { () } - //~^ ERROR `impl Trait` not allowed outside of function and method return types + //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types } // Allowed @@ -136,10 +136,10 @@ impl DummyType { // Disallowed extern "C" { fn in_foreign_parameters(_: impl Debug); - //~^ ERROR `impl Trait` not allowed outside of function and method return types + //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types fn in_foreign_return() -> impl Debug; - //~^ ERROR `impl Trait` not allowed outside of function and method return types + //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types } // Allowed @@ -155,97 +155,97 @@ type InTypeAlias = impl Debug; //~^ ERROR `impl Trait` in type aliases is unstable type InReturnInTypeAlias = fn() -> impl Debug; -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types //~| ERROR `impl Trait` in type aliases is unstable // Disallowed in impl headers impl PartialEq for () { - //~^ ERROR `impl Trait` not allowed outside of function and method return types + //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types } // Disallowed in impl headers impl PartialEq<()> for impl Debug { - //~^ ERROR `impl Trait` not allowed outside of function and method return types + //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types } // Disallowed in inherent impls impl impl Debug { - //~^ ERROR `impl Trait` not allowed outside of function and method return types + //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types } // Disallowed in inherent impls struct InInherentImplAdt { t: T } impl InInherentImplAdt { - //~^ ERROR `impl Trait` not allowed outside of function and method return types + //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types } // Disallowed in where clauses fn in_fn_where_clause() where impl Debug: Debug -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types { } // Disallowed in where clauses fn in_adt_in_fn_where_clause() where Vec: Debug -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types { } // Disallowed fn in_trait_parameter_in_fn_where_clause() where T: PartialEq -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types { } // Disallowed fn in_Fn_parameter_in_fn_where_clause() where T: Fn(impl Debug) -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types { } // Disallowed fn in_Fn_return_in_fn_where_clause() where T: Fn() -> impl Debug -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types { } // Disallowed struct InStructGenericParamDefault(T); -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types // Disallowed enum InEnumGenericParamDefault { Variant(T) } -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types // Disallowed trait InTraitGenericParamDefault {} -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types // Disallowed type InTypeAliasGenericParamDefault = T; -//~^ ERROR `impl Trait` not allowed outside of function and method return types +//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types // Disallowed impl T {} //~^ ERROR defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions //~| WARNING this was previously accepted by the compiler but is being phased out -//~| ERROR `impl Trait` not allowed outside of function and method return types +//~| ERROR `impl Trait` not allowed outside of function and inherent method return types //~| ERROR no nominal type found // Disallowed fn in_method_generic_param_default(_: T) {} //~^ ERROR defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions //~| WARNING this was previously accepted by the compiler but is being phased out -//~| ERROR `impl Trait` not allowed outside of function and method return types +//~| ERROR `impl Trait` not allowed outside of function and inherent method return types fn main() { let _in_local_variable: impl Fn() = || {}; - //~^ ERROR `impl Trait` not allowed outside of function and method return types + //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types let _in_return_in_local_variable = || -> impl Fn() { || {} }; - //~^ ERROR `impl Trait` not allowed outside of function and method return types + //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types } diff --git a/src/test/ui/impl-trait/where-allowed.stderr b/src/test/ui/impl-trait/where-allowed.stderr index 236cf449e85fa..579c7d2ff79ba 100644 --- a/src/test/ui/impl-trait/where-allowed.stderr +++ b/src/test/ui/impl-trait/where-allowed.stderr @@ -43,251 +43,333 @@ LL | type InReturnInTypeAlias = fn() -> impl Debug; = note: see issue #63063 for more information = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:15:40 | LL | fn in_fn_parameter_in_parameters(_: fn(impl Debug)) { panic!() } | ^^^^^^^^^^ + | + = note: found `impl Trait` in `fn` pointer param -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:19:42 | LL | fn in_fn_return_in_parameters(_: fn() -> impl Debug) { panic!() } | ^^^^^^^^^^ + | + = note: found `impl Trait` in `fn` pointer return -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:23:38 | LL | fn in_fn_parameter_in_return() -> fn(impl Debug) { panic!() } | ^^^^^^^^^^ + | + = note: found `impl Trait` in `fn` pointer param -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:27:40 | LL | fn in_fn_return_in_return() -> fn() -> impl Debug { panic!() } | ^^^^^^^^^^ + | + = note: found `impl Trait` in `fn` pointer return -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:31:49 | LL | fn in_dyn_Fn_parameter_in_parameters(_: &dyn Fn(impl Debug)) { panic!() } | ^^^^^^^^^^ + | + = note: found `impl Trait` in `Fn` trait param -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:35:51 | LL | fn in_dyn_Fn_return_in_parameters(_: &dyn Fn() -> impl Debug) { panic!() } | ^^^^^^^^^^ + | + = note: found `impl Trait` in `Fn` trait return -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:39:55 | LL | fn in_dyn_Fn_parameter_in_return() -> &'static dyn Fn(impl Debug) { panic!() } | ^^^^^^^^^^ + | + = note: found `impl Trait` in `Fn` trait param -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:43:57 | LL | fn in_dyn_Fn_return_in_return() -> &'static dyn Fn() -> impl Debug { panic!() } | ^^^^^^^^^^ + | + = note: found `impl Trait` in `Fn` trait return -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:47:51 | LL | fn in_impl_Fn_parameter_in_parameters(_: &impl Fn(impl Debug)) { panic!() } | ^^^^^^^^^^ + | + = note: found `impl Trait` in `Fn` trait param -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:52:53 | LL | fn in_impl_Fn_return_in_parameters(_: &impl Fn() -> impl Debug) { panic!() } | ^^^^^^^^^^ + | + = note: found `impl Trait` in `Fn` trait return -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:56:57 | LL | fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic!() } | ^^^^^^^^^^ + | + = note: found `impl Trait` in `Fn` trait param -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:61:59 | LL | fn in_impl_Fn_return_in_return() -> &'static impl Fn() -> impl Debug { panic!() } | ^^^^^^^^^^ + | + = note: found `impl Trait` in `Fn` trait return -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:65:38 | LL | fn in_Fn_parameter_in_generics (_: F) { panic!() } | ^^^^^^^^^^ + | + = note: found `impl Trait` in `Fn` trait param -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:69:40 | LL | fn in_Fn_return_in_generics impl Debug> (_: F) { panic!() } | ^^^^^^^^^^ + | + = note: found `impl Trait` in `Fn` trait return -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:82:32 | LL | struct InBraceStructField { x: impl Debug } | ^^^^^^^^^^ + | + = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:86:41 | LL | struct InAdtInBraceStructField { x: Vec } | ^^^^^^^^^^ + | + = note: found `impl Trait` in path -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:90:27 | LL | struct InTupleStructField(impl Debug); | ^^^^^^^^^^ + | + = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:95:25 | LL | InBraceVariant { x: impl Debug }, | ^^^^^^^^^^ + | + = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:97:20 | LL | InTupleVariant(impl Debug), | ^^^^^^^^^^ + | + = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:108:23 | LL | fn in_return() -> impl Debug; | ^^^^^^^^^^ + | + = note: found `impl Trait` in trait method return -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:125:34 | LL | fn in_trait_impl_return() -> impl Debug { () } | ^^^^^^^^^^ + | + = note: found `impl Trait` in `impl` method return -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:138:33 | LL | fn in_foreign_parameters(_: impl Debug); | ^^^^^^^^^^ + | + = note: found `impl Trait` in `extern fn` param -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:141:31 | LL | fn in_foreign_return() -> impl Debug; | ^^^^^^^^^^ + | + = note: found `impl Trait` in `extern fn` return -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:157:39 | LL | type InReturnInTypeAlias = fn() -> impl Debug; | ^^^^^^^^^^ + | + = note: found `impl Trait` in `fn` pointer return -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:162:16 | LL | impl PartialEq for () { | ^^^^^^^^^^ + | + = note: found `impl Trait` in trait -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:167:24 | LL | impl PartialEq<()> for impl Debug { | ^^^^^^^^^^ + | + = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:172:6 | LL | impl impl Debug { | ^^^^^^^^^^ + | + = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:178:24 | LL | impl InInherentImplAdt { | ^^^^^^^^^^ + | + = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:184:11 | LL | where impl Debug: Debug | ^^^^^^^^^^ + | + = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:191:15 | LL | where Vec: Debug | ^^^^^^^^^^ + | + = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:198:24 | LL | where T: PartialEq | ^^^^^^^^^^ + | + = note: found `impl Trait` in bound -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:205:17 | LL | where T: Fn(impl Debug) | ^^^^^^^^^^ + | + = note: found `impl Trait` in `Fn` trait param -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:212:22 | LL | where T: Fn() -> impl Debug | ^^^^^^^^^^ + | + = note: found `impl Trait` in `Fn` trait return -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:218:40 | LL | struct InStructGenericParamDefault(T); | ^^^^^^^^^^ + | + = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:222:36 | LL | enum InEnumGenericParamDefault { Variant(T) } | ^^^^^^^^^^ + | + = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:226:38 | LL | trait InTraitGenericParamDefault {} | ^^^^^^^^^^ + | + = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:230:41 | LL | type InTypeAliasGenericParamDefault = T; | ^^^^^^^^^^ + | + = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:234:11 | LL | impl T {} | ^^^^^^^^^^ + | + = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:241:40 | LL | fn in_method_generic_param_default(_: T) {} | ^^^^^^^^^^ + | + = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:247:29 | LL | let _in_local_variable: impl Fn() = || {}; | ^^^^^^^^^ + | + = note: found `impl Trait` in variable -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/where-allowed.rs:249:46 | LL | let _in_return_in_local_variable = || -> impl Fn() { || {} }; | ^^^^^^^^^ + | + = note: found `impl Trait` in closure return error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions --> $DIR/where-allowed.rs:234:7 diff --git a/src/test/ui/issues/issue-47715.stderr b/src/test/ui/issues/issue-47715.stderr index 63a28d997e11a..5cccc7f3432be 100644 --- a/src/test/ui/issues/issue-47715.stderr +++ b/src/test/ui/issues/issue-47715.stderr @@ -1,26 +1,34 @@ -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/issue-47715.rs:9:37 | LL | struct Container> { | ^^^^^^^^ + | + = note: found `impl Trait` in generic -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/issue-47715.rs:14:30 | LL | enum Enum> { | ^^^^^^^^ + | + = note: found `impl Trait` in generic -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/issue-47715.rs:19:32 | LL | union Union + Copy> { | ^^^^^^^^ + | + = note: found `impl Trait` in generic -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/issue-47715.rs:24:30 | LL | type Type> = T; | ^^^^^^^^ + | + = note: found `impl Trait` in generic error: aborting due to 4 previous errors diff --git a/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-fn-type.rs b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-fn-type.rs index 299bdf562dc41..35b2e0fe7d988 100644 --- a/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-fn-type.rs +++ b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-fn-type.rs @@ -4,7 +4,7 @@ // FIXME: this is ruled out for now but should work type Foo = fn() -> impl Send; -//~^ ERROR: `impl Trait` not allowed outside of function and method return types +//~^ ERROR: `impl Trait` not allowed outside of function and inherent method return types fn make_foo() -> Foo { || 15 diff --git a/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-fn-type.stderr b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-fn-type.stderr index 1c5d57d4af761..89235215643c3 100644 --- a/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-fn-type.stderr +++ b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-fn-type.stderr @@ -1,8 +1,10 @@ -error[E0562]: `impl Trait` not allowed outside of function and method return types +error[E0562]: `impl Trait` not allowed outside of function and inherent method return types --> $DIR/type-alias-impl-trait-fn-type.rs:6:20 | LL | type Foo = fn() -> impl Send; | ^^^^^^^^^ + | + = note: found `impl Trait` in `fn` pointer return error: aborting due to previous error From 207fb5f070174368ebb56a17b6f4e5a161cabe51 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 17 Feb 2022 19:18:42 -0800 Subject: [PATCH 13/15] fix impl trait message, bless tests --- compiler/rustc_ast_lowering/src/lib.rs | 7 +- .../feature-gate-associated_type_bounds.rs | 6 +- ...feature-gate-associated_type_bounds.stderr | 12 +- src/test/ui/impl-trait/issues/issue-54600.rs | 2 +- .../ui/impl-trait/issues/issue-54600.stderr | 4 +- src/test/ui/impl-trait/issues/issue-54840.rs | 2 +- .../ui/impl-trait/issues/issue-54840.stderr | 4 +- src/test/ui/impl-trait/issues/issue-58504.rs | 2 +- .../ui/impl-trait/issues/issue-58504.stderr | 4 +- src/test/ui/impl-trait/issues/issue-58956.rs | 4 +- .../ui/impl-trait/issues/issue-58956.stderr | 8 +- src/test/ui/impl-trait/issues/issue-70971.rs | 2 +- .../ui/impl-trait/issues/issue-70971.stderr | 4 +- src/test/ui/impl-trait/issues/issue-79099.rs | 2 +- .../ui/impl-trait/issues/issue-79099.stderr | 4 +- ...sue-83929-impl-trait-in-generic-default.rs | 4 +- ...83929-impl-trait-in-generic-default.stderr | 8 +- src/test/ui/impl-trait/issues/issue-84919.rs | 2 +- .../ui/impl-trait/issues/issue-84919.stderr | 4 +- src/test/ui/impl-trait/issues/issue-86642.rs | 2 +- .../ui/impl-trait/issues/issue-86642.stderr | 4 +- src/test/ui/impl-trait/issues/issue-87295.rs | 2 +- .../ui/impl-trait/issues/issue-87295.stderr | 4 +- src/test/ui/impl-trait/nested_impl_trait.rs | 4 +- .../ui/impl-trait/nested_impl_trait.stderr | 8 +- src/test/ui/impl-trait/where-allowed.rs | 82 ++++----- src/test/ui/impl-trait/where-allowed.stderr | 164 +++++------------- src/test/ui/issues/issue-47715.rs | 8 +- src/test/ui/issues/issue-47715.stderr | 16 +- .../type-alias-impl-trait-fn-type.rs | 2 +- .../type-alias-impl-trait-fn-type.stderr | 4 +- 31 files changed, 129 insertions(+), 256 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 803c93c259eeb..bdbee3e2f4b3a 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -297,7 +297,7 @@ impl std::fmt::Display for ImplTraitPosition { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let name = match self { ImplTraitPosition::Path => "path", - ImplTraitPosition::Variable => "variable", + ImplTraitPosition::Variable => "variable binding", ImplTraitPosition::Type => "type", ImplTraitPosition::Trait => "trait", ImplTraitPosition::AsyncBlock => "async block", @@ -1419,10 +1419,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { self.sess, t.span, E0562, - "`impl Trait` not allowed outside of \ - function and inherent method return types", + "`impl Trait` only allowed in function and inherent method return types, not in {}", + position ); - err.note(&format!("found `impl Trait` in {}", position)); err.emit(); hir::TyKind::Err } diff --git a/src/test/ui/feature-gates/feature-gate-associated_type_bounds.rs b/src/test/ui/feature-gates/feature-gate-associated_type_bounds.rs index 38be85ff8201e..a93fb7977131d 100644 --- a/src/test/ui/feature-gates/feature-gate-associated_type_bounds.rs +++ b/src/test/ui/feature-gates/feature-gate-associated_type_bounds.rs @@ -57,20 +57,20 @@ fn _rpit_dyn() -> Box> { Box::new(S1) } const _cdef: impl Tr1 = S1; //~^ ERROR associated type bounds are unstable -//~| ERROR `impl Trait` not allowed outside of function and inherent method return types [E0562] +//~| ERROR `impl Trait` only allowed in function and inherent method return types // FIXME: uncomment when `impl_trait_in_bindings` feature is fixed. // const _cdef_dyn: &dyn Tr1 = &S1; static _sdef: impl Tr1 = S1; //~^ ERROR associated type bounds are unstable -//~| ERROR `impl Trait` not allowed outside of function and inherent method return types [E0562] +//~| ERROR `impl Trait` only allowed in function and inherent method return types // FIXME: uncomment when `impl_trait_in_bindings` feature is fixed. // static _sdef_dyn: &dyn Tr1 = &S1; fn main() { let _: impl Tr1 = S1; //~^ ERROR associated type bounds are unstable - //~| ERROR `impl Trait` not allowed outside of function and inherent method return types [E0562] + //~| ERROR `impl Trait` only allowed in function and inherent method return types // FIXME: uncomment when `impl_trait_in_bindings` feature is fixed. // let _: &dyn Tr1 = &S1; } diff --git a/src/test/ui/feature-gates/feature-gate-associated_type_bounds.stderr b/src/test/ui/feature-gates/feature-gate-associated_type_bounds.stderr index 26f10622344da..5be1d97a05985 100644 --- a/src/test/ui/feature-gates/feature-gate-associated_type_bounds.stderr +++ b/src/test/ui/feature-gates/feature-gate-associated_type_bounds.stderr @@ -115,29 +115,23 @@ LL | let _: impl Tr1 = S1; = note: see issue #52662 for more information = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type --> $DIR/feature-gate-associated_type_bounds.rs:58:14 | LL | const _cdef: impl Tr1 = S1; | ^^^^^^^^^^^^^^^^^^^ - | - = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type --> $DIR/feature-gate-associated_type_bounds.rs:64:15 | LL | static _sdef: impl Tr1 = S1; | ^^^^^^^^^^^^^^^^^^^ - | - = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in variable binding --> $DIR/feature-gate-associated_type_bounds.rs:71:12 | LL | let _: impl Tr1 = S1; | ^^^^^^^^^^^^^^^^^^^ - | - = note: found `impl Trait` in variable error[E0277]: the trait bound `<::A as Iterator>::Item: Copy` is not satisfied --> $DIR/feature-gate-associated_type_bounds.rs:15:28 diff --git a/src/test/ui/impl-trait/issues/issue-54600.rs b/src/test/ui/impl-trait/issues/issue-54600.rs index e0e8f27401738..3024fedf7b5fb 100644 --- a/src/test/ui/impl-trait/issues/issue-54600.rs +++ b/src/test/ui/impl-trait/issues/issue-54600.rs @@ -2,6 +2,6 @@ use std::fmt::Debug; fn main() { let x: Option = Some(44_u32); - //~^ `impl Trait` not allowed outside of function and inherent method return types + //~^ `impl Trait` only allowed in function and inherent method return types println!("{:?}", x); } diff --git a/src/test/ui/impl-trait/issues/issue-54600.stderr b/src/test/ui/impl-trait/issues/issue-54600.stderr index c9626175ff511..316566a57a896 100644 --- a/src/test/ui/impl-trait/issues/issue-54600.stderr +++ b/src/test/ui/impl-trait/issues/issue-54600.stderr @@ -1,10 +1,8 @@ -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in variable binding --> $DIR/issue-54600.rs:4:19 | LL | let x: Option = Some(44_u32); | ^^^^^^^^^^ - | - = note: found `impl Trait` in variable error: aborting due to previous error diff --git a/src/test/ui/impl-trait/issues/issue-54840.rs b/src/test/ui/impl-trait/issues/issue-54840.rs index 8756d1c7de394..8f1e0ece03a62 100644 --- a/src/test/ui/impl-trait/issues/issue-54840.rs +++ b/src/test/ui/impl-trait/issues/issue-54840.rs @@ -3,5 +3,5 @@ use std::ops::Add; fn main() { let i: i32 = 0; let j: &impl Add = &i; - //~^ `impl Trait` not allowed outside of function and inherent method return types + //~^ `impl Trait` only allowed in function and inherent method return types } diff --git a/src/test/ui/impl-trait/issues/issue-54840.stderr b/src/test/ui/impl-trait/issues/issue-54840.stderr index a947e0fc46d47..8d82133ac9029 100644 --- a/src/test/ui/impl-trait/issues/issue-54840.stderr +++ b/src/test/ui/impl-trait/issues/issue-54840.stderr @@ -1,10 +1,8 @@ -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in variable binding --> $DIR/issue-54840.rs:5:13 | LL | let j: &impl Add = &i; | ^^^^^^^^ - | - = note: found `impl Trait` in variable error: aborting due to previous error diff --git a/src/test/ui/impl-trait/issues/issue-58504.rs b/src/test/ui/impl-trait/issues/issue-58504.rs index ccbe187cef685..e5865d0dfff34 100644 --- a/src/test/ui/impl-trait/issues/issue-58504.rs +++ b/src/test/ui/impl-trait/issues/issue-58504.rs @@ -8,5 +8,5 @@ fn mk_gen() -> impl Generator { fn main() { let gens: [impl Generator;2] = [ mk_gen(), mk_gen() ]; - //~^ `impl Trait` not allowed outside of function and inherent method return types + //~^ `impl Trait` only allowed in function and inherent method return types } diff --git a/src/test/ui/impl-trait/issues/issue-58504.stderr b/src/test/ui/impl-trait/issues/issue-58504.stderr index 6c59bcfa11da2..6656e9fc3fbfc 100644 --- a/src/test/ui/impl-trait/issues/issue-58504.stderr +++ b/src/test/ui/impl-trait/issues/issue-58504.stderr @@ -1,10 +1,8 @@ -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in variable binding --> $DIR/issue-58504.rs:10:16 | LL | let gens: [impl Generator;2] = [ mk_gen(), mk_gen() ]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: found `impl Trait` in variable error: aborting due to previous error diff --git a/src/test/ui/impl-trait/issues/issue-58956.rs b/src/test/ui/impl-trait/issues/issue-58956.rs index 615dc5b2f29c4..68cfcd9ba4f9e 100644 --- a/src/test/ui/impl-trait/issues/issue-58956.rs +++ b/src/test/ui/impl-trait/issues/issue-58956.rs @@ -5,9 +5,9 @@ impl Lam for B {} pub struct Wrap(T); const _A: impl Lam = { - //~^ `impl Trait` not allowed outside of function and inherent method return types + //~^ `impl Trait` only allowed in function and inherent method return types let x: Wrap = Wrap(B); - //~^ `impl Trait` not allowed outside of function and inherent method return types + //~^ `impl Trait` only allowed in function and inherent method return types x.0 }; diff --git a/src/test/ui/impl-trait/issues/issue-58956.stderr b/src/test/ui/impl-trait/issues/issue-58956.stderr index f9bcb94d49d2d..123fb4df4b3c8 100644 --- a/src/test/ui/impl-trait/issues/issue-58956.stderr +++ b/src/test/ui/impl-trait/issues/issue-58956.stderr @@ -1,18 +1,14 @@ -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type --> $DIR/issue-58956.rs:7:11 | LL | const _A: impl Lam = { | ^^^^^^^^ - | - = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in variable binding --> $DIR/issue-58956.rs:9:17 | LL | let x: Wrap = Wrap(B); | ^^^^^^^^ - | - = note: found `impl Trait` in variable error: aborting due to 2 previous errors diff --git a/src/test/ui/impl-trait/issues/issue-70971.rs b/src/test/ui/impl-trait/issues/issue-70971.rs index 4329cf6264476..f8ae18bacd67d 100644 --- a/src/test/ui/impl-trait/issues/issue-70971.rs +++ b/src/test/ui/impl-trait/issues/issue-70971.rs @@ -1,4 +1,4 @@ fn main() { let x : (impl Copy,) = (true,); - //~^ `impl Trait` not allowed outside of function and inherent method return types + //~^ `impl Trait` only allowed in function and inherent method return types } diff --git a/src/test/ui/impl-trait/issues/issue-70971.stderr b/src/test/ui/impl-trait/issues/issue-70971.stderr index 831c0980068c3..4dda4c22aa2cf 100644 --- a/src/test/ui/impl-trait/issues/issue-70971.stderr +++ b/src/test/ui/impl-trait/issues/issue-70971.stderr @@ -1,10 +1,8 @@ -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in variable binding --> $DIR/issue-70971.rs:2:14 | LL | let x : (impl Copy,) = (true,); | ^^^^^^^^^ - | - = note: found `impl Trait` in variable error: aborting due to previous error diff --git a/src/test/ui/impl-trait/issues/issue-79099.rs b/src/test/ui/impl-trait/issues/issue-79099.rs index add2d72907cd4..da53594f3d091 100644 --- a/src/test/ui/impl-trait/issues/issue-79099.rs +++ b/src/test/ui/impl-trait/issues/issue-79099.rs @@ -1,7 +1,7 @@ struct Bug { V1: [(); { let f: impl core::future::Future = async { 1 }; - //~^ `impl Trait` not allowed outside of function and inherent method return types + //~^ `impl Trait` only allowed in function and inherent method return types //~| expected identifier 1 }], diff --git a/src/test/ui/impl-trait/issues/issue-79099.stderr b/src/test/ui/impl-trait/issues/issue-79099.stderr index c70eb5a1e9d80..4c9ec2a83ff37 100644 --- a/src/test/ui/impl-trait/issues/issue-79099.stderr +++ b/src/test/ui/impl-trait/issues/issue-79099.stderr @@ -9,13 +9,11 @@ LL | let f: impl core::future::Future = async { 1 }; = help: set `edition = "2021"` in `Cargo.toml` = note: for more on editions, read https://doc.rust-lang.org/edition-guide -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in variable binding --> $DIR/issue-79099.rs:3:16 | LL | let f: impl core::future::Future = async { 1 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: found `impl Trait` in variable error: aborting due to 2 previous errors diff --git a/src/test/ui/impl-trait/issues/issue-83929-impl-trait-in-generic-default.rs b/src/test/ui/impl-trait/issues/issue-83929-impl-trait-in-generic-default.rs index d9d2e3929b10c..344f359529b61 100644 --- a/src/test/ui/impl-trait/issues/issue-83929-impl-trait-in-generic-default.rs +++ b/src/test/ui/impl-trait/issues/issue-83929-impl-trait-in-generic-default.rs @@ -1,8 +1,8 @@ struct Foo(T); -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types type Result = std::result::Result; -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types // should not cause ICE fn x() -> Foo { diff --git a/src/test/ui/impl-trait/issues/issue-83929-impl-trait-in-generic-default.stderr b/src/test/ui/impl-trait/issues/issue-83929-impl-trait-in-generic-default.stderr index 1cac44e796b2c..e635e554e2384 100644 --- a/src/test/ui/impl-trait/issues/issue-83929-impl-trait-in-generic-default.stderr +++ b/src/test/ui/impl-trait/issues/issue-83929-impl-trait-in-generic-default.stderr @@ -1,18 +1,14 @@ -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type --> $DIR/issue-83929-impl-trait-in-generic-default.rs:1:16 | LL | struct Foo(T); | ^^^^^^^^^ - | - = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type --> $DIR/issue-83929-impl-trait-in-generic-default.rs:4:20 | LL | type Result = std::result::Result; | ^^^^^^^^^^^^^^^^^^^^^^ - | - = note: found `impl Trait` in type error: aborting due to 2 previous errors diff --git a/src/test/ui/impl-trait/issues/issue-84919.rs b/src/test/ui/impl-trait/issues/issue-84919.rs index 6abe3cd7ea5c1..a0b73743a2b2d 100644 --- a/src/test/ui/impl-trait/issues/issue-84919.rs +++ b/src/test/ui/impl-trait/issues/issue-84919.rs @@ -3,7 +3,7 @@ impl Trait for () {} fn foo<'a: 'a>() { let _x: impl Trait = (); - //~^ `impl Trait` not allowed outside of function and inherent method return types + //~^ `impl Trait` only allowed in function and inherent method return types } fn main() {} diff --git a/src/test/ui/impl-trait/issues/issue-84919.stderr b/src/test/ui/impl-trait/issues/issue-84919.stderr index 36fc750cf87b0..5abe1bd877943 100644 --- a/src/test/ui/impl-trait/issues/issue-84919.stderr +++ b/src/test/ui/impl-trait/issues/issue-84919.stderr @@ -1,10 +1,8 @@ -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in variable binding --> $DIR/issue-84919.rs:5:13 | LL | let _x: impl Trait = (); | ^^^^^^^^^^ - | - = note: found `impl Trait` in variable error: aborting due to previous error diff --git a/src/test/ui/impl-trait/issues/issue-86642.rs b/src/test/ui/impl-trait/issues/issue-86642.rs index c7e4045f43205..e6e95771400d3 100644 --- a/src/test/ui/impl-trait/issues/issue-86642.rs +++ b/src/test/ui/impl-trait/issues/issue-86642.rs @@ -1,5 +1,5 @@ static x: impl Fn(&str) -> Result<&str, ()> = move |source| { - //~^ `impl Trait` not allowed outside of function and inherent method return types + //~^ `impl Trait` only allowed in function and inherent method return types let res = (move |source| Ok(source))(source); let res = res.or((move |source| Ok(source))(source)); res diff --git a/src/test/ui/impl-trait/issues/issue-86642.stderr b/src/test/ui/impl-trait/issues/issue-86642.stderr index d12f0f3d2a9f3..0ec118d5be802 100644 --- a/src/test/ui/impl-trait/issues/issue-86642.stderr +++ b/src/test/ui/impl-trait/issues/issue-86642.stderr @@ -1,10 +1,8 @@ -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type --> $DIR/issue-86642.rs:1:11 | LL | static x: impl Fn(&str) -> Result<&str, ()> = move |source| { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: found `impl Trait` in type error: aborting due to previous error diff --git a/src/test/ui/impl-trait/issues/issue-87295.rs b/src/test/ui/impl-trait/issues/issue-87295.rs index da75e777398f5..aeb8f83326e4d 100644 --- a/src/test/ui/impl-trait/issues/issue-87295.rs +++ b/src/test/ui/impl-trait/issues/issue-87295.rs @@ -14,5 +14,5 @@ impl Struct { fn main() { let _do_not_waste: Struct> = Struct::new(()); - //~^ `impl Trait` not allowed outside of function and inherent method return types + //~^ `impl Trait` only allowed in function and inherent method return types } diff --git a/src/test/ui/impl-trait/issues/issue-87295.stderr b/src/test/ui/impl-trait/issues/issue-87295.stderr index 6bdc356b6a406..0b043056b84a6 100644 --- a/src/test/ui/impl-trait/issues/issue-87295.stderr +++ b/src/test/ui/impl-trait/issues/issue-87295.stderr @@ -1,10 +1,8 @@ -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in variable binding --> $DIR/issue-87295.rs:16:31 | LL | let _do_not_waste: Struct> = Struct::new(()); | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: found `impl Trait` in variable error: aborting due to previous error diff --git a/src/test/ui/impl-trait/nested_impl_trait.rs b/src/test/ui/impl-trait/nested_impl_trait.rs index be2c21a7743ce..06a2191a01761 100644 --- a/src/test/ui/impl-trait/nested_impl_trait.rs +++ b/src/test/ui/impl-trait/nested_impl_trait.rs @@ -7,7 +7,7 @@ fn bad_in_ret_position(x: impl Into) -> impl Into { x } fn bad_in_fn_syntax(x: fn() -> impl Into) {} //~^ ERROR nested `impl Trait` is not allowed -//~^^ `impl Trait` not allowed +//~| `impl Trait` only allowed in function and inherent method return types fn bad_in_arg_position(_: impl Into) { } //~^ ERROR nested `impl Trait` is not allowed @@ -23,7 +23,7 @@ fn allowed_in_assoc_type() -> impl Iterator { } fn allowed_in_ret_type() -> impl Fn() -> impl Into { -//~^ `impl Trait` not allowed +//~^ `impl Trait` only allowed in function and inherent method return types || 5 } diff --git a/src/test/ui/impl-trait/nested_impl_trait.stderr b/src/test/ui/impl-trait/nested_impl_trait.stderr index c6a56ea0e302f..4444e6a454f89 100644 --- a/src/test/ui/impl-trait/nested_impl_trait.stderr +++ b/src/test/ui/impl-trait/nested_impl_trait.stderr @@ -34,21 +34,17 @@ LL | fn bad(x: impl Into) -> impl Into { x } | | nested `impl Trait` here | outer `impl Trait` -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `fn` pointer return --> $DIR/nested_impl_trait.rs:8:32 | LL | fn bad_in_fn_syntax(x: fn() -> impl Into) {} | ^^^^^^^^^^^^^^^^^^^^^ - | - = note: found `impl Trait` in `fn` pointer return -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `Fn` trait return --> $DIR/nested_impl_trait.rs:25:42 | LL | fn allowed_in_ret_type() -> impl Fn() -> impl Into { | ^^^^^^^^^^^^^^ - | - = note: found `impl Trait` in `Fn` trait return error: aborting due to 6 previous errors diff --git a/src/test/ui/impl-trait/where-allowed.rs b/src/test/ui/impl-trait/where-allowed.rs index 07d28dbd025ac..c1dd46c7ff7fd 100644 --- a/src/test/ui/impl-trait/where-allowed.rs +++ b/src/test/ui/impl-trait/where-allowed.rs @@ -13,61 +13,61 @@ fn in_adt_in_parameters(_: Vec) { panic!() } // Disallowed fn in_fn_parameter_in_parameters(_: fn(impl Debug)) { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types // Disallowed fn in_fn_return_in_parameters(_: fn() -> impl Debug) { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types // Disallowed fn in_fn_parameter_in_return() -> fn(impl Debug) { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types // Disallowed fn in_fn_return_in_return() -> fn() -> impl Debug { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types // Disallowed fn in_dyn_Fn_parameter_in_parameters(_: &dyn Fn(impl Debug)) { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types // Disallowed fn in_dyn_Fn_return_in_parameters(_: &dyn Fn() -> impl Debug) { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types // Disallowed fn in_dyn_Fn_parameter_in_return() -> &'static dyn Fn(impl Debug) { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types // Disallowed fn in_dyn_Fn_return_in_return() -> &'static dyn Fn() -> impl Debug { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types // Disallowed fn in_impl_Fn_parameter_in_parameters(_: &impl Fn(impl Debug)) { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types //~^^ ERROR nested `impl Trait` is not allowed // Disallowed fn in_impl_Fn_return_in_parameters(_: &impl Fn() -> impl Debug) { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types // Disallowed fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types //~| ERROR nested `impl Trait` is not allowed // Disallowed fn in_impl_Fn_return_in_return() -> &'static impl Fn() -> impl Debug { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types // Disallowed fn in_Fn_parameter_in_generics (_: F) { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types // Disallowed fn in_Fn_return_in_generics impl Debug> (_: F) { panic!() } -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types // Allowed @@ -80,22 +80,22 @@ fn in_impl_Trait_in_return() -> impl IntoIterator { // Disallowed struct InBraceStructField { x: impl Debug } -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types // Disallowed struct InAdtInBraceStructField { x: Vec } -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types // Disallowed struct InTupleStructField(impl Debug); -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types // Disallowed enum InEnum { InBraceVariant { x: impl Debug }, - //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types + //~^ ERROR `impl Trait` only allowed in function and inherent method return types InTupleVariant(impl Debug), - //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types + //~^ ERROR `impl Trait` only allowed in function and inherent method return types } // Allowed @@ -106,7 +106,7 @@ trait InTraitDefnParameters { // Disallowed trait InTraitDefnReturn { fn in_return() -> impl Debug; - //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types + //~^ ERROR `impl Trait` only allowed in function and inherent method return types } // Allowed and disallowed in trait impls @@ -123,7 +123,7 @@ impl DummyTrait for () { // Allowed fn in_trait_impl_return() -> impl Debug { () } - //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types + //~^ ERROR `impl Trait` only allowed in function and inherent method return types } // Allowed @@ -136,10 +136,10 @@ impl DummyType { // Disallowed extern "C" { fn in_foreign_parameters(_: impl Debug); - //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types + //~^ ERROR `impl Trait` only allowed in function and inherent method return types fn in_foreign_return() -> impl Debug; - //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types + //~^ ERROR `impl Trait` only allowed in function and inherent method return types } // Allowed @@ -155,97 +155,97 @@ type InTypeAlias = impl Debug; //~^ ERROR `impl Trait` in type aliases is unstable type InReturnInTypeAlias = fn() -> impl Debug; -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types //~| ERROR `impl Trait` in type aliases is unstable // Disallowed in impl headers impl PartialEq for () { - //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types + //~^ ERROR `impl Trait` only allowed in function and inherent method return types } // Disallowed in impl headers impl PartialEq<()> for impl Debug { - //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types + //~^ ERROR `impl Trait` only allowed in function and inherent method return types } // Disallowed in inherent impls impl impl Debug { - //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types + //~^ ERROR `impl Trait` only allowed in function and inherent method return types } // Disallowed in inherent impls struct InInherentImplAdt { t: T } impl InInherentImplAdt { - //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types + //~^ ERROR `impl Trait` only allowed in function and inherent method return types } // Disallowed in where clauses fn in_fn_where_clause() where impl Debug: Debug -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types { } // Disallowed in where clauses fn in_adt_in_fn_where_clause() where Vec: Debug -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types { } // Disallowed fn in_trait_parameter_in_fn_where_clause() where T: PartialEq -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types { } // Disallowed fn in_Fn_parameter_in_fn_where_clause() where T: Fn(impl Debug) -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types { } // Disallowed fn in_Fn_return_in_fn_where_clause() where T: Fn() -> impl Debug -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types { } // Disallowed struct InStructGenericParamDefault(T); -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types // Disallowed enum InEnumGenericParamDefault { Variant(T) } -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types // Disallowed trait InTraitGenericParamDefault {} -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types // Disallowed type InTypeAliasGenericParamDefault = T; -//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR `impl Trait` only allowed in function and inherent method return types // Disallowed impl T {} //~^ ERROR defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions //~| WARNING this was previously accepted by the compiler but is being phased out -//~| ERROR `impl Trait` not allowed outside of function and inherent method return types +//~| ERROR `impl Trait` only allowed in function and inherent method return types //~| ERROR no nominal type found // Disallowed fn in_method_generic_param_default(_: T) {} //~^ ERROR defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions //~| WARNING this was previously accepted by the compiler but is being phased out -//~| ERROR `impl Trait` not allowed outside of function and inherent method return types +//~| ERROR `impl Trait` only allowed in function and inherent method return types fn main() { let _in_local_variable: impl Fn() = || {}; - //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types + //~^ ERROR `impl Trait` only allowed in function and inherent method return types let _in_return_in_local_variable = || -> impl Fn() { || {} }; - //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types + //~^ ERROR `impl Trait` only allowed in function and inherent method return types } diff --git a/src/test/ui/impl-trait/where-allowed.stderr b/src/test/ui/impl-trait/where-allowed.stderr index 579c7d2ff79ba..eef20c2de94bc 100644 --- a/src/test/ui/impl-trait/where-allowed.stderr +++ b/src/test/ui/impl-trait/where-allowed.stderr @@ -43,333 +43,251 @@ LL | type InReturnInTypeAlias = fn() -> impl Debug; = note: see issue #63063 for more information = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `fn` pointer param --> $DIR/where-allowed.rs:15:40 | LL | fn in_fn_parameter_in_parameters(_: fn(impl Debug)) { panic!() } | ^^^^^^^^^^ - | - = note: found `impl Trait` in `fn` pointer param -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `fn` pointer return --> $DIR/where-allowed.rs:19:42 | LL | fn in_fn_return_in_parameters(_: fn() -> impl Debug) { panic!() } | ^^^^^^^^^^ - | - = note: found `impl Trait` in `fn` pointer return -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `fn` pointer param --> $DIR/where-allowed.rs:23:38 | LL | fn in_fn_parameter_in_return() -> fn(impl Debug) { panic!() } | ^^^^^^^^^^ - | - = note: found `impl Trait` in `fn` pointer param -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `fn` pointer return --> $DIR/where-allowed.rs:27:40 | LL | fn in_fn_return_in_return() -> fn() -> impl Debug { panic!() } | ^^^^^^^^^^ - | - = note: found `impl Trait` in `fn` pointer return -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `Fn` trait param --> $DIR/where-allowed.rs:31:49 | LL | fn in_dyn_Fn_parameter_in_parameters(_: &dyn Fn(impl Debug)) { panic!() } | ^^^^^^^^^^ - | - = note: found `impl Trait` in `Fn` trait param -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `Fn` trait return --> $DIR/where-allowed.rs:35:51 | LL | fn in_dyn_Fn_return_in_parameters(_: &dyn Fn() -> impl Debug) { panic!() } | ^^^^^^^^^^ - | - = note: found `impl Trait` in `Fn` trait return -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `Fn` trait param --> $DIR/where-allowed.rs:39:55 | LL | fn in_dyn_Fn_parameter_in_return() -> &'static dyn Fn(impl Debug) { panic!() } | ^^^^^^^^^^ - | - = note: found `impl Trait` in `Fn` trait param -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `Fn` trait return --> $DIR/where-allowed.rs:43:57 | LL | fn in_dyn_Fn_return_in_return() -> &'static dyn Fn() -> impl Debug { panic!() } | ^^^^^^^^^^ - | - = note: found `impl Trait` in `Fn` trait return -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `Fn` trait param --> $DIR/where-allowed.rs:47:51 | LL | fn in_impl_Fn_parameter_in_parameters(_: &impl Fn(impl Debug)) { panic!() } | ^^^^^^^^^^ - | - = note: found `impl Trait` in `Fn` trait param -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `Fn` trait return --> $DIR/where-allowed.rs:52:53 | LL | fn in_impl_Fn_return_in_parameters(_: &impl Fn() -> impl Debug) { panic!() } | ^^^^^^^^^^ - | - = note: found `impl Trait` in `Fn` trait return -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `Fn` trait param --> $DIR/where-allowed.rs:56:57 | LL | fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic!() } | ^^^^^^^^^^ - | - = note: found `impl Trait` in `Fn` trait param -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `Fn` trait return --> $DIR/where-allowed.rs:61:59 | LL | fn in_impl_Fn_return_in_return() -> &'static impl Fn() -> impl Debug { panic!() } | ^^^^^^^^^^ - | - = note: found `impl Trait` in `Fn` trait return -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `Fn` trait param --> $DIR/where-allowed.rs:65:38 | LL | fn in_Fn_parameter_in_generics (_: F) { panic!() } | ^^^^^^^^^^ - | - = note: found `impl Trait` in `Fn` trait param -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `Fn` trait return --> $DIR/where-allowed.rs:69:40 | LL | fn in_Fn_return_in_generics impl Debug> (_: F) { panic!() } | ^^^^^^^^^^ - | - = note: found `impl Trait` in `Fn` trait return -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type --> $DIR/where-allowed.rs:82:32 | LL | struct InBraceStructField { x: impl Debug } | ^^^^^^^^^^ - | - = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in path --> $DIR/where-allowed.rs:86:41 | LL | struct InAdtInBraceStructField { x: Vec } | ^^^^^^^^^^ - | - = note: found `impl Trait` in path -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type --> $DIR/where-allowed.rs:90:27 | LL | struct InTupleStructField(impl Debug); | ^^^^^^^^^^ - | - = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type --> $DIR/where-allowed.rs:95:25 | LL | InBraceVariant { x: impl Debug }, | ^^^^^^^^^^ - | - = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type --> $DIR/where-allowed.rs:97:20 | LL | InTupleVariant(impl Debug), | ^^^^^^^^^^ - | - = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in trait method return --> $DIR/where-allowed.rs:108:23 | LL | fn in_return() -> impl Debug; | ^^^^^^^^^^ - | - = note: found `impl Trait` in trait method return -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `impl` method return --> $DIR/where-allowed.rs:125:34 | LL | fn in_trait_impl_return() -> impl Debug { () } | ^^^^^^^^^^ - | - = note: found `impl Trait` in `impl` method return -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `extern fn` param --> $DIR/where-allowed.rs:138:33 | LL | fn in_foreign_parameters(_: impl Debug); | ^^^^^^^^^^ - | - = note: found `impl Trait` in `extern fn` param -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `extern fn` return --> $DIR/where-allowed.rs:141:31 | LL | fn in_foreign_return() -> impl Debug; | ^^^^^^^^^^ - | - = note: found `impl Trait` in `extern fn` return -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `fn` pointer return --> $DIR/where-allowed.rs:157:39 | LL | type InReturnInTypeAlias = fn() -> impl Debug; | ^^^^^^^^^^ - | - = note: found `impl Trait` in `fn` pointer return -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in trait --> $DIR/where-allowed.rs:162:16 | LL | impl PartialEq for () { | ^^^^^^^^^^ - | - = note: found `impl Trait` in trait -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type --> $DIR/where-allowed.rs:167:24 | LL | impl PartialEq<()> for impl Debug { | ^^^^^^^^^^ - | - = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type --> $DIR/where-allowed.rs:172:6 | LL | impl impl Debug { | ^^^^^^^^^^ - | - = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type --> $DIR/where-allowed.rs:178:24 | LL | impl InInherentImplAdt { | ^^^^^^^^^^ - | - = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type --> $DIR/where-allowed.rs:184:11 | LL | where impl Debug: Debug | ^^^^^^^^^^ - | - = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type --> $DIR/where-allowed.rs:191:15 | LL | where Vec: Debug | ^^^^^^^^^^ - | - = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in bound --> $DIR/where-allowed.rs:198:24 | LL | where T: PartialEq | ^^^^^^^^^^ - | - = note: found `impl Trait` in bound -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `Fn` trait param --> $DIR/where-allowed.rs:205:17 | LL | where T: Fn(impl Debug) | ^^^^^^^^^^ - | - = note: found `impl Trait` in `Fn` trait param -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `Fn` trait return --> $DIR/where-allowed.rs:212:22 | LL | where T: Fn() -> impl Debug | ^^^^^^^^^^ - | - = note: found `impl Trait` in `Fn` trait return -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type --> $DIR/where-allowed.rs:218:40 | LL | struct InStructGenericParamDefault(T); | ^^^^^^^^^^ - | - = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type --> $DIR/where-allowed.rs:222:36 | LL | enum InEnumGenericParamDefault { Variant(T) } | ^^^^^^^^^^ - | - = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type --> $DIR/where-allowed.rs:226:38 | LL | trait InTraitGenericParamDefault {} | ^^^^^^^^^^ - | - = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type --> $DIR/where-allowed.rs:230:41 | LL | type InTypeAliasGenericParamDefault = T; | ^^^^^^^^^^ - | - = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type --> $DIR/where-allowed.rs:234:11 | LL | impl T {} | ^^^^^^^^^^ - | - = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type --> $DIR/where-allowed.rs:241:40 | LL | fn in_method_generic_param_default(_: T) {} | ^^^^^^^^^^ - | - = note: found `impl Trait` in type -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in variable binding --> $DIR/where-allowed.rs:247:29 | LL | let _in_local_variable: impl Fn() = || {}; | ^^^^^^^^^ - | - = note: found `impl Trait` in variable -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in closure return --> $DIR/where-allowed.rs:249:46 | LL | let _in_return_in_local_variable = || -> impl Fn() { || {} }; | ^^^^^^^^^ - | - = note: found `impl Trait` in closure return error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions --> $DIR/where-allowed.rs:234:7 diff --git a/src/test/ui/issues/issue-47715.rs b/src/test/ui/issues/issue-47715.rs index 478ac6a2e8910..b8088c18dadfe 100644 --- a/src/test/ui/issues/issue-47715.rs +++ b/src/test/ui/issues/issue-47715.rs @@ -7,22 +7,22 @@ trait Iterable { } struct Container> { - //~^ ERROR `impl Trait` not allowed + //~^ ERROR `impl Trait` only allowed in function and inherent method return types field: T } enum Enum> { - //~^ ERROR `impl Trait` not allowed + //~^ ERROR `impl Trait` only allowed in function and inherent method return types A(T), } union Union + Copy> { - //~^ ERROR `impl Trait` not allowed + //~^ ERROR `impl Trait` only allowed in function and inherent method return types x: T, } type Type> = T; -//~^ ERROR `impl Trait` not allowed +//~^ ERROR `impl Trait` only allowed in function and inherent method return types fn main() { } diff --git a/src/test/ui/issues/issue-47715.stderr b/src/test/ui/issues/issue-47715.stderr index 5cccc7f3432be..0ee9388bf2b2c 100644 --- a/src/test/ui/issues/issue-47715.stderr +++ b/src/test/ui/issues/issue-47715.stderr @@ -1,34 +1,26 @@ -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in generic --> $DIR/issue-47715.rs:9:37 | LL | struct Container> { | ^^^^^^^^ - | - = note: found `impl Trait` in generic -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in generic --> $DIR/issue-47715.rs:14:30 | LL | enum Enum> { | ^^^^^^^^ - | - = note: found `impl Trait` in generic -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in generic --> $DIR/issue-47715.rs:19:32 | LL | union Union + Copy> { | ^^^^^^^^ - | - = note: found `impl Trait` in generic -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in generic --> $DIR/issue-47715.rs:24:30 | LL | type Type> = T; | ^^^^^^^^ - | - = note: found `impl Trait` in generic error: aborting due to 4 previous errors diff --git a/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-fn-type.rs b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-fn-type.rs index 35b2e0fe7d988..857066c78c902 100644 --- a/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-fn-type.rs +++ b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-fn-type.rs @@ -4,7 +4,7 @@ // FIXME: this is ruled out for now but should work type Foo = fn() -> impl Send; -//~^ ERROR: `impl Trait` not allowed outside of function and inherent method return types +//~^ ERROR: `impl Trait` only allowed in function and inherent method return types fn make_foo() -> Foo { || 15 diff --git a/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-fn-type.stderr b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-fn-type.stderr index 89235215643c3..a31cf1a51ccd7 100644 --- a/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-fn-type.stderr +++ b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-fn-type.stderr @@ -1,10 +1,8 @@ -error[E0562]: `impl Trait` not allowed outside of function and inherent method return types +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `fn` pointer return --> $DIR/type-alias-impl-trait-fn-type.rs:6:20 | LL | type Foo = fn() -> impl Send; | ^^^^^^^^^ - | - = note: found `impl Trait` in `fn` pointer return error: aborting due to previous error From 4bed7485da0706dfc30f019f94f07fcdf5122358 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Thu, 14 Oct 2021 21:44:43 +0200 Subject: [PATCH 14/15] Suggest `impl Trait` return type Address #85991 Suggest the `impl Trait` return type syntax if the user tried to return a generic parameter and we get a type mismatch The suggestion is not emitted if the param appears in the function parameters, and only get the bounds that actually involve `T: ` directly It also checks whether the generic param is contained in any where bound (where it isn't the self type), and if one is found (like `Option: Send`), it is not suggested. This also adds `TyS::contains`, which recursively vistits the type and looks if the other type is contained anywhere --- compiler/rustc_middle/src/ty/sty.rs | 24 +++- .../src/check/fn_ctxt/suggestions.rs | 116 +++++++++++++++++- src/test/ui/return/return-impl-trait-bad.rs | 31 +++++ .../ui/return/return-impl-trait-bad.stderr | 59 +++++++++ src/test/ui/return/return-impl-trait.fixed | 30 +++++ src/test/ui/return/return-impl-trait.rs | 30 +++++ src/test/ui/return/return-impl-trait.stderr | 34 +++++ 7 files changed, 321 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/return/return-impl-trait-bad.rs create mode 100644 src/test/ui/return/return-impl-trait-bad.stderr create mode 100644 src/test/ui/return/return-impl-trait.fixed create mode 100644 src/test/ui/return/return-impl-trait.rs create mode 100644 src/test/ui/return/return-impl-trait.stderr diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 9835211a74865..7c6d6ea1cb6ee 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -8,7 +8,9 @@ use crate::infer::canonical::Canonical; use crate::ty::fold::ValidateBoundVars; use crate::ty::subst::{GenericArg, InternalSubsts, Subst, SubstsRef}; use crate::ty::InferTy::{self, *}; -use crate::ty::{self, AdtDef, DefIdTree, Discr, Term, Ty, TyCtxt, TypeFlags, TypeFoldable}; +use crate::ty::{ + self, AdtDef, DefIdTree, Discr, Term, Ty, TyCtxt, TypeFlags, TypeFoldable, TypeVisitor, +}; use crate::ty::{DelaySpanBugEmitted, List, ParamEnv}; use polonius_engine::Atom; use rustc_data_structures::captures::Captures; @@ -24,7 +26,7 @@ use std::borrow::Cow; use std::cmp::Ordering; use std::fmt; use std::marker::PhantomData; -use std::ops::{Deref, Range}; +use std::ops::{ControlFlow, Deref, Range}; use ty::util::IntTypeExt; #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] @@ -2072,6 +2074,24 @@ impl<'tcx> Ty<'tcx> { !matches!(self.kind(), Param(_) | Infer(_) | Error(_)) } + /// Checks whether a type recursively contains another type + /// + /// Example: `Option<()>` contains `()` + pub fn contains(self, other: Ty<'tcx>) -> bool { + struct ContainsTyVisitor<'tcx>(Ty<'tcx>); + + impl<'tcx> TypeVisitor<'tcx> for ContainsTyVisitor<'tcx> { + type BreakTy = (); + + fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { + if self.0 == t { ControlFlow::BREAK } else { t.super_visit_with(self) } + } + } + + let cf = self.visit_with(&mut ContainsTyVisitor(other)); + cf.is_break() + } + /// Returns the type and mutability of `*ty`. /// /// The parameter `explicit` indicates if this is an *explicit* dereference. diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs index 86cf850d72322..f9c482713f1fe 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs @@ -8,8 +8,12 @@ use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind}; use rustc_hir::lang_items::LangItem; -use rustc_hir::{Expr, ExprKind, ItemKind, Node, Path, QPath, Stmt, StmtKind, TyKind}; +use rustc_hir::{ + Expr, ExprKind, GenericBound, ItemKind, Node, Path, QPath, Stmt, StmtKind, TyKind, + WherePredicate, +}; use rustc_infer::infer::{self, TyCtxtInferExt}; + use rustc_middle::lint::in_external_macro; use rustc_middle::ty::{self, Binder, Ty}; use rustc_span::symbol::{kw, sym}; @@ -559,6 +563,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let ty = self.tcx.erase_late_bound_regions(ty); if self.can_coerce(expected, ty) { err.span_label(sp, format!("expected `{}` because of return type", expected)); + self.try_suggest_return_impl_trait(err, expected, ty, fn_id); return true; } false @@ -566,6 +571,115 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } + /// check whether the return type is a generic type with a trait bound + /// only suggest this if the generic param is not present in the arguments + /// if this is true, hint them towards changing the return type to `impl Trait` + /// ``` + /// fn cant_name_it u32>() -> T { + /// || 3 + /// } + /// ``` + fn try_suggest_return_impl_trait( + &self, + err: &mut DiagnosticBuilder<'_>, + expected: Ty<'tcx>, + found: Ty<'tcx>, + fn_id: hir::HirId, + ) { + // Only apply the suggestion if: + // - the return type is a generic parameter + // - the generic param is not used as a fn param + // - the generic param has at least one bound + // - the generic param doesn't appear in any other bounds where it's not the Self type + // Suggest: + // - Changing the return type to be `impl ` + + debug!("try_suggest_return_impl_trait, expected = {:?}, found = {:?}", expected, found); + + let ty::Param(expected_ty_as_param) = expected.kind() else { return }; + + let fn_node = self.tcx.hir().find(fn_id); + + let Some(hir::Node::Item(hir::Item { + kind: + hir::ItemKind::Fn( + hir::FnSig { decl: hir::FnDecl { inputs: fn_parameters, output: fn_return, .. }, .. }, + hir::Generics { params, where_clause, .. }, + _body_id, + ), + .. + })) = fn_node else { return }; + + let Some(expected_generic_param) = params.get(expected_ty_as_param.index as usize) else { return }; + + // get all where BoundPredicates here, because they are used in to cases below + let where_predicates = where_clause + .predicates + .iter() + .filter_map(|p| match p { + WherePredicate::BoundPredicate(hir::WhereBoundPredicate { + bounds, + bounded_ty, + .. + }) => { + // FIXME: Maybe these calls to `ast_ty_to_ty` can be removed (and the ones below) + let ty = >::ast_ty_to_ty(self, bounded_ty); + Some((ty, bounds)) + } + _ => None, + }) + .map(|(ty, bounds)| match ty.kind() { + ty::Param(param_ty) if param_ty == expected_ty_as_param => Ok(Some(bounds)), + // check whether there is any predicate that contains our `T`, like `Option: Send` + _ => match ty.contains(expected) { + true => Err(()), + false => Ok(None), + }, + }) + .collect::, _>>(); + + let Ok(where_predicates) = where_predicates else { return }; + + // now get all predicates in the same types as the where bounds, so we can chain them + let predicates_from_where = + where_predicates.iter().flatten().map(|bounds| bounds.iter()).flatten(); + + // extract all bounds from the source code using their spans + let all_matching_bounds_strs = expected_generic_param + .bounds + .iter() + .chain(predicates_from_where) + .filter_map(|bound| match bound { + GenericBound::Trait(_, _) => { + self.tcx.sess.source_map().span_to_snippet(bound.span()).ok() + } + _ => None, + }) + .collect::>(); + + if all_matching_bounds_strs.len() == 0 { + return; + } + + let all_bounds_str = all_matching_bounds_strs.join(" + "); + + let ty_param_used_in_fn_params = fn_parameters.iter().any(|param| { + let ty = >::ast_ty_to_ty(self, param); + matches!(ty.kind(), ty::Param(fn_param_ty_param) if expected_ty_as_param == fn_param_ty_param) + }); + + if ty_param_used_in_fn_params { + return; + } + + err.span_suggestion( + fn_return.span(), + "consider using an impl return type", + format!("impl {}", all_bounds_str), + Applicability::MaybeIncorrect, + ); + } + pub(in super::super) fn suggest_missing_break_or_return_expr( &self, err: &mut DiagnosticBuilder<'_>, diff --git a/src/test/ui/return/return-impl-trait-bad.rs b/src/test/ui/return/return-impl-trait-bad.rs new file mode 100644 index 0000000000000..e3f6ddb9a1497 --- /dev/null +++ b/src/test/ui/return/return-impl-trait-bad.rs @@ -0,0 +1,31 @@ +trait Trait {} +impl Trait for () {} + +fn bad_echo(_t: T) -> T { + "this should not suggest impl Trait" //~ ERROR mismatched types +} + +fn bad_echo_2(_t: T) -> T { + "this will not suggest it, because that would probably be wrong" //~ ERROR mismatched types +} + +fn other_bounds_bad() -> T +where + T: Send, + Option: Send, +{ + "don't suggest this, because Option places additional constraints" //~ ERROR mismatched types +} + +// FIXME: implement this check +trait GenericTrait {} + +fn used_in_trait() -> T +where + T: Send, + (): GenericTrait, +{ + "don't suggest this, because the generic param is used in the bound." //~ ERROR mismatched types +} + +fn main() {} diff --git a/src/test/ui/return/return-impl-trait-bad.stderr b/src/test/ui/return/return-impl-trait-bad.stderr new file mode 100644 index 0000000000000..237b85ee66a10 --- /dev/null +++ b/src/test/ui/return/return-impl-trait-bad.stderr @@ -0,0 +1,59 @@ +error[E0308]: mismatched types + --> $DIR/return-impl-trait-bad.rs:5:5 + | +LL | fn bad_echo(_t: T) -> T { + | - - expected `T` because of return type + | | + | this type parameter +LL | "this should not suggest impl Trait" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type parameter `T`, found `&str` + | + = note: expected type parameter `T` + found reference `&'static str` + +error[E0308]: mismatched types + --> $DIR/return-impl-trait-bad.rs:9:5 + | +LL | fn bad_echo_2(_t: T) -> T { + | - - expected `T` because of return type + | | + | this type parameter +LL | "this will not suggest it, because that would probably be wrong" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type parameter `T`, found `&str` + | + = note: expected type parameter `T` + found reference `&'static str` + +error[E0308]: mismatched types + --> $DIR/return-impl-trait-bad.rs:17:5 + | +LL | fn other_bounds_bad() -> T + | - - expected `T` because of return type + | | + | this type parameter +... +LL | "don't suggest this, because Option places additional constraints" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type parameter `T`, found `&str` + | + = note: expected type parameter `T` + found reference `&'static str` + +error[E0308]: mismatched types + --> $DIR/return-impl-trait-bad.rs:28:5 + | +LL | fn used_in_trait() -> T + | - - + | | | + | | expected `T` because of return type + | | help: consider using an impl return type: `impl Send` + | this type parameter +... +LL | "don't suggest this, because the generic param is used in the bound." + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type parameter `T`, found `&str` + | + = note: expected type parameter `T` + found reference `&'static str` + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/return/return-impl-trait.fixed b/src/test/ui/return/return-impl-trait.fixed new file mode 100644 index 0000000000000..ff2b02f73ea65 --- /dev/null +++ b/src/test/ui/return/return-impl-trait.fixed @@ -0,0 +1,30 @@ +// run-rustfix + +trait Trait {} +impl Trait for () {} + +// this works +fn foo() -> impl Trait { + () +} + +fn bar() -> impl Trait + std::marker::Sync + Send +where + T: Send, +{ + () //~ ERROR mismatched types +} + +fn other_bounds() -> impl Trait +where + T: Trait, + Vec: Clone, +{ + () //~ ERROR mismatched types +} + +fn main() { + foo(); + bar::<()>(); + other_bounds::<()>(); +} diff --git a/src/test/ui/return/return-impl-trait.rs b/src/test/ui/return/return-impl-trait.rs new file mode 100644 index 0000000000000..e905d712f622d --- /dev/null +++ b/src/test/ui/return/return-impl-trait.rs @@ -0,0 +1,30 @@ +// run-rustfix + +trait Trait {} +impl Trait for () {} + +// this works +fn foo() -> impl Trait { + () +} + +fn bar() -> T +where + T: Send, +{ + () //~ ERROR mismatched types +} + +fn other_bounds() -> T +where + T: Trait, + Vec: Clone, +{ + () //~ ERROR mismatched types +} + +fn main() { + foo(); + bar::<()>(); + other_bounds::<()>(); +} diff --git a/src/test/ui/return/return-impl-trait.stderr b/src/test/ui/return/return-impl-trait.stderr new file mode 100644 index 0000000000000..43d40972fcac0 --- /dev/null +++ b/src/test/ui/return/return-impl-trait.stderr @@ -0,0 +1,34 @@ +error[E0308]: mismatched types + --> $DIR/return-impl-trait.rs:15:5 + | +LL | fn bar() -> T + | - - + | | | + | | expected `T` because of return type + | this type parameter help: consider using an impl return type: `impl Trait + std::marker::Sync + Send` +... +LL | () + | ^^ expected type parameter `T`, found `()` + | + = note: expected type parameter `T` + found unit type `()` + +error[E0308]: mismatched types + --> $DIR/return-impl-trait.rs:23:5 + | +LL | fn other_bounds() -> T + | - - + | | | + | | expected `T` because of return type + | | help: consider using an impl return type: `impl Trait` + | this type parameter +... +LL | () + | ^^ expected type parameter `T`, found `()` + | + = note: expected type parameter `T` + found unit type `()` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. From 11250b8661f2f37e96827d6d5434833221b355d2 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Thu, 10 Feb 2022 20:50:16 +0000 Subject: [PATCH 15/15] asm: Allow the use of r8-r14 as clobbers on Thumb1 Previously these were entirely disallowed, except for r11 which was allowed by accident. --- compiler/rustc_ast_lowering/src/asm.rs | 11 +-- compiler/rustc_target/src/asm/aarch64.rs | 1 + compiler/rustc_target/src/asm/arm.rs | 17 +++- compiler/rustc_target/src/asm/bpf.rs | 1 + compiler/rustc_target/src/asm/mod.rs | 108 +++++++++++++++-------- compiler/rustc_target/src/asm/riscv.rs | 1 + compiler/rustc_target/src/asm/x86.rs | 4 + 7 files changed, 97 insertions(+), 46 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/asm.rs b/compiler/rustc_ast_lowering/src/asm.rs index 5a85356d96daa..18fcc99ffbaa0 100644 --- a/compiler/rustc_ast_lowering/src/asm.rs +++ b/compiler/rustc_ast_lowering/src/asm.rs @@ -129,13 +129,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { .operands .iter() .map(|(op, op_sp)| { - let lower_reg = |reg| match reg { + let lower_reg = |reg, is_clobber| match reg { InlineAsmRegOrRegClass::Reg(s) => { asm::InlineAsmRegOrRegClass::Reg(if let Some(asm_arch) = asm_arch { asm::InlineAsmReg::parse( asm_arch, &sess.target_features, &sess.target, + is_clobber, s, ) .unwrap_or_else(|e| { @@ -162,24 +163,24 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let op = match *op { InlineAsmOperand::In { reg, ref expr } => hir::InlineAsmOperand::In { - reg: lower_reg(reg), + reg: lower_reg(reg, false), expr: self.lower_expr_mut(expr), }, InlineAsmOperand::Out { reg, late, ref expr } => hir::InlineAsmOperand::Out { - reg: lower_reg(reg), + reg: lower_reg(reg, expr.is_none()), late, expr: expr.as_ref().map(|expr| self.lower_expr_mut(expr)), }, InlineAsmOperand::InOut { reg, late, ref expr } => { hir::InlineAsmOperand::InOut { - reg: lower_reg(reg), + reg: lower_reg(reg, false), late, expr: self.lower_expr_mut(expr), } } InlineAsmOperand::SplitInOut { reg, late, ref in_expr, ref out_expr } => { hir::InlineAsmOperand::SplitInOut { - reg: lower_reg(reg), + reg: lower_reg(reg, false), late, in_expr: self.lower_expr_mut(in_expr), out_expr: out_expr.as_ref().map(|expr| self.lower_expr_mut(expr)), diff --git a/compiler/rustc_target/src/asm/aarch64.rs b/compiler/rustc_target/src/asm/aarch64.rs index da875508676d4..d184ad4e78ae5 100644 --- a/compiler/rustc_target/src/asm/aarch64.rs +++ b/compiler/rustc_target/src/asm/aarch64.rs @@ -77,6 +77,7 @@ pub fn reserved_x18( _arch: InlineAsmArch, _target_features: &FxHashSet, target: &Target, + _is_clobber: bool, ) -> Result<(), &'static str> { if target.os == "android" || target.is_like_fuchsia diff --git a/compiler/rustc_target/src/asm/arm.rs b/compiler/rustc_target/src/asm/arm.rs index e3615b43c70eb..b2d5bb3736afd 100644 --- a/compiler/rustc_target/src/asm/arm.rs +++ b/compiler/rustc_target/src/asm/arm.rs @@ -66,10 +66,13 @@ fn frame_pointer_is_r7(target_features: &FxHashSet, target: &Target) -> } fn frame_pointer_r11( - _arch: InlineAsmArch, + arch: InlineAsmArch, target_features: &FxHashSet, target: &Target, + is_clobber: bool, ) -> Result<(), &'static str> { + not_thumb1(arch, target_features, target, is_clobber)?; + if !frame_pointer_is_r7(target_features, target) { Err("the frame pointer (r11) cannot be used as an operand for inline asm") } else { @@ -81,6 +84,7 @@ fn frame_pointer_r7( _arch: InlineAsmArch, target_features: &FxHashSet, target: &Target, + _is_clobber: bool, ) -> Result<(), &'static str> { if frame_pointer_is_r7(target_features, target) { Err("the frame pointer (r7) cannot be used as an operand for inline asm") @@ -93,9 +97,13 @@ fn not_thumb1( _arch: InlineAsmArch, target_features: &FxHashSet, _target: &Target, + is_clobber: bool, ) -> Result<(), &'static str> { - if target_features.contains(&sym::thumb_mode) && !target_features.contains(&sym::thumb2) { - Err("high registers (r8+) cannot be used in Thumb-1 code") + if !is_clobber + && target_features.contains(&sym::thumb_mode) + && !target_features.contains(&sym::thumb2) + { + Err("high registers (r8+) can only be used as clobbers in Thumb-1 code") } else { Ok(()) } @@ -105,8 +113,9 @@ fn reserved_r9( arch: InlineAsmArch, target_features: &FxHashSet, target: &Target, + is_clobber: bool, ) -> Result<(), &'static str> { - not_thumb1(arch, target_features, target)?; + not_thumb1(arch, target_features, target, is_clobber)?; // We detect this using the reserved-r9 feature instead of using the target // because the relocation model can be changed with compiler options. diff --git a/compiler/rustc_target/src/asm/bpf.rs b/compiler/rustc_target/src/asm/bpf.rs index d94fcb53e24c9..b4d982f3836be 100644 --- a/compiler/rustc_target/src/asm/bpf.rs +++ b/compiler/rustc_target/src/asm/bpf.rs @@ -47,6 +47,7 @@ fn only_alu32( _arch: InlineAsmArch, target_features: &FxHashSet, _target: &Target, + _is_clobber: bool, ) -> Result<(), &'static str> { if !target_features.contains(&sym::alu32) { Err("register can't be used without the `alu32` target feature") diff --git a/compiler/rustc_target/src/asm/mod.rs b/compiler/rustc_target/src/asm/mod.rs index a84410d0f3c46..fd95b0338a6e1 100644 --- a/compiler/rustc_target/src/asm/mod.rs +++ b/compiler/rustc_target/src/asm/mod.rs @@ -83,12 +83,13 @@ macro_rules! def_regs { _arch: super::InlineAsmArch, _target_features: &rustc_data_structures::fx::FxHashSet, _target: &crate::spec::Target, + _is_clobber: bool, name: &str, ) -> Result { match name { $( $($alias)|* | $reg_name => { - $($filter(_arch, _target_features, _target)?;)? + $($filter(_arch, _target_features, _target, _is_clobber)?;)? Ok(Self::$reg) } )* @@ -112,7 +113,7 @@ macro_rules! def_regs { #[allow(unused_imports)] use super::{InlineAsmReg, InlineAsmRegClass}; $( - if $($filter(_arch, _target_features, _target).is_ok() &&)? true { + if $($filter(_arch, _target_features, _target, false).is_ok() &&)? true { if let Some(set) = _map.get_mut(&InlineAsmRegClass::$arch($arch_regclass::$class)) { set.insert(InlineAsmReg::$arch($arch_reg::$reg)); } @@ -298,6 +299,7 @@ impl InlineAsmReg { arch: InlineAsmArch, target_features: &FxHashSet, target: &Target, + is_clobber: bool, name: Symbol, ) -> Result { // FIXME: use direct symbol comparison for register names @@ -305,47 +307,79 @@ impl InlineAsmReg { let name = name.as_str(); Ok(match arch { InlineAsmArch::X86 | InlineAsmArch::X86_64 => { - Self::X86(X86InlineAsmReg::parse(arch, target_features, target, name)?) + Self::X86(X86InlineAsmReg::parse(arch, target_features, target, is_clobber, name)?) } InlineAsmArch::Arm => { - Self::Arm(ArmInlineAsmReg::parse(arch, target_features, target, name)?) - } - InlineAsmArch::AArch64 => { - Self::AArch64(AArch64InlineAsmReg::parse(arch, target_features, target, name)?) - } - InlineAsmArch::RiscV32 | InlineAsmArch::RiscV64 => { - Self::RiscV(RiscVInlineAsmReg::parse(arch, target_features, target, name)?) - } - InlineAsmArch::Nvptx64 => { - Self::Nvptx(NvptxInlineAsmReg::parse(arch, target_features, target, name)?) - } - InlineAsmArch::PowerPC | InlineAsmArch::PowerPC64 => { - Self::PowerPC(PowerPCInlineAsmReg::parse(arch, target_features, target, name)?) - } - InlineAsmArch::Hexagon => { - Self::Hexagon(HexagonInlineAsmReg::parse(arch, target_features, target, name)?) - } - InlineAsmArch::Mips | InlineAsmArch::Mips64 => { - Self::Mips(MipsInlineAsmReg::parse(arch, target_features, target, name)?) - } - InlineAsmArch::S390x => { - Self::S390x(S390xInlineAsmReg::parse(arch, target_features, target, name)?) - } - InlineAsmArch::SpirV => { - Self::SpirV(SpirVInlineAsmReg::parse(arch, target_features, target, name)?) - } - InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => { - Self::Wasm(WasmInlineAsmReg::parse(arch, target_features, target, name)?) + Self::Arm(ArmInlineAsmReg::parse(arch, target_features, target, is_clobber, name)?) } + InlineAsmArch::AArch64 => Self::AArch64(AArch64InlineAsmReg::parse( + arch, + target_features, + target, + is_clobber, + name, + )?), + InlineAsmArch::RiscV32 | InlineAsmArch::RiscV64 => Self::RiscV( + RiscVInlineAsmReg::parse(arch, target_features, target, is_clobber, name)?, + ), + InlineAsmArch::Nvptx64 => Self::Nvptx(NvptxInlineAsmReg::parse( + arch, + target_features, + target, + is_clobber, + name, + )?), + InlineAsmArch::PowerPC | InlineAsmArch::PowerPC64 => Self::PowerPC( + PowerPCInlineAsmReg::parse(arch, target_features, target, is_clobber, name)?, + ), + InlineAsmArch::Hexagon => Self::Hexagon(HexagonInlineAsmReg::parse( + arch, + target_features, + target, + is_clobber, + name, + )?), + InlineAsmArch::Mips | InlineAsmArch::Mips64 => Self::Mips(MipsInlineAsmReg::parse( + arch, + target_features, + target, + is_clobber, + name, + )?), + InlineAsmArch::S390x => Self::S390x(S390xInlineAsmReg::parse( + arch, + target_features, + target, + is_clobber, + name, + )?), + InlineAsmArch::SpirV => Self::SpirV(SpirVInlineAsmReg::parse( + arch, + target_features, + target, + is_clobber, + name, + )?), + InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => Self::Wasm(WasmInlineAsmReg::parse( + arch, + target_features, + target, + is_clobber, + name, + )?), InlineAsmArch::Bpf => { - Self::Bpf(BpfInlineAsmReg::parse(arch, target_features, target, name)?) + Self::Bpf(BpfInlineAsmReg::parse(arch, target_features, target, is_clobber, name)?) } InlineAsmArch::Avr => { - Self::Avr(AvrInlineAsmReg::parse(arch, target_features, target, name)?) - } - InlineAsmArch::Msp430 => { - Self::Msp430(Msp430InlineAsmReg::parse(arch, target_features, target, name)?) + Self::Avr(AvrInlineAsmReg::parse(arch, target_features, target, is_clobber, name)?) } + InlineAsmArch::Msp430 => Self::Msp430(Msp430InlineAsmReg::parse( + arch, + target_features, + target, + is_clobber, + name, + )?), }) } @@ -844,7 +878,7 @@ impl InlineAsmClobberAbi { }, InlineAsmArch::AArch64 => match name { "C" | "system" | "efiapi" => { - Ok(if aarch64::reserved_x18(arch, target_features, target).is_err() { + Ok(if aarch64::reserved_x18(arch, target_features, target, true).is_err() { InlineAsmClobberAbi::AArch64NoX18 } else { InlineAsmClobberAbi::AArch64 diff --git a/compiler/rustc_target/src/asm/riscv.rs b/compiler/rustc_target/src/asm/riscv.rs index 39644d232badb..e145ba8a16e64 100644 --- a/compiler/rustc_target/src/asm/riscv.rs +++ b/compiler/rustc_target/src/asm/riscv.rs @@ -56,6 +56,7 @@ fn not_e( _arch: InlineAsmArch, target_features: &FxHashSet, _target: &Target, + _is_clobber: bool, ) -> Result<(), &'static str> { if target_features.contains(&sym::e) { Err("register can't be used with the `e` target feature") diff --git a/compiler/rustc_target/src/asm/x86.rs b/compiler/rustc_target/src/asm/x86.rs index 01d32570f78a2..a8ee80ec4ea27 100644 --- a/compiler/rustc_target/src/asm/x86.rs +++ b/compiler/rustc_target/src/asm/x86.rs @@ -141,6 +141,7 @@ fn x86_64_only( arch: InlineAsmArch, _target_features: &FxHashSet, _target: &Target, + _is_clobber: bool, ) -> Result<(), &'static str> { match arch { InlineAsmArch::X86 => Err("register is only available on x86_64"), @@ -153,6 +154,7 @@ fn high_byte( arch: InlineAsmArch, _target_features: &FxHashSet, _target: &Target, + _is_clobber: bool, ) -> Result<(), &'static str> { match arch { InlineAsmArch::X86_64 => Err("high byte registers cannot be used as an operand on x86_64"), @@ -164,6 +166,7 @@ fn rbx_reserved( arch: InlineAsmArch, _target_features: &FxHashSet, _target: &Target, + _is_clobber: bool, ) -> Result<(), &'static str> { match arch { InlineAsmArch::X86 => Ok(()), @@ -178,6 +181,7 @@ fn esi_reserved( arch: InlineAsmArch, _target_features: &FxHashSet, _target: &Target, + _is_clobber: bool, ) -> Result<(), &'static str> { match arch { InlineAsmArch::X86 => {