about summary refs log tree commit diff
path: root/src/test
AgeCommit message (Collapse)AuthorLines
2021-09-17Rollup merge of #88954 - nbdd0121:panic3, r=oli-obkGuillaume Gomez-37/+83
Allow `panic!("{}", computed_str)` in const fn. Special-case `panic!("{}", arg)` and translate it to `panic_display(&arg)`. `panic_display` will behave like `panic_any` in cosnt eval and behave like `panic!(format_args!("{}", arg))` in runtime. This should bring Rust 2015 and 2021 to feature parity in terms of `const_panic`; and hopefully would unblock the stabilisation of #51999. `@rustbot` modify labels: +T-compiler +T-libs +A-const-eval +A-const-fn r? `@oli-obk`
2021-09-17Rollup merge of #88899 - FabianWolff:issue-88844, r=matthewjasperGuillaume Gomez-0/+26
Do not issue E0071 if a type error has already been reported Fixes #88844. A suggested fix is already included in the error message for E0412, so with my changes, E0071 is simply not emitted anymore if the type in question is a "type error". This makes sense, I think, because we cannot confidently state that something is "not a struct" if we couldn't resolve it properly; and it's unnecessary to pollute the output with this additional error message, as it is a direct consequence of the former error. I have also addressed the issue mentioned in https://github.com/rust-lang/rust/issues/88844#issuecomment-917324856 by changing the fixed example in the documentation to more closely match the erroneous code example.
2021-09-17Rollup merge of #87566 - JohnTitor:find-eqeq-on-assoc-type-bounds, r=estebankGuillaume Gomez-0/+42
Recover invalid assoc type bounds using `==` Fix #87493 r? `@estebank`
2021-09-17Rollup merge of #87460 - FabianWolff:issue-87456, r=Aaron1011Guillaume Gomez-211/+495
Point to closure when emitting 'cannot move out' for captured variable Attempts to fix #87456. The error message now points to the capturing closure, but I was not able to explain _why_ the closure implements `Fn` or `FnMut` (`TypeckResults::closure_kind_origins` did not contain anything for the closure in question). cc `@Aaron1011`
2021-09-17Rollup merge of #86422 - JohnTitor:clearer-parens-err-for-loop, r=estebankGuillaume Gomez-7/+10
Emit clearer diagnostics for parens around `for` loop heads Fixes #63113 r? `@estebank`
2021-09-17Apply review commentsYuki Okushi-4/+6
2021-09-17Rollup merge of #89033 - cuviper:sysroot-lib-path, r=Mark-SimulacrumYuki Okushi-0/+13
Set the library path in sysroot-crates-are-unstable Most of the `run-make-fulldeps` tests use a make-driven rustc command that includes `HOST_RPATH_DIR` in the library path, but this particular test runs from python instead. When the toolchain is built without `rpath` enabled, we need that library path in the environment so it can find its own libraries.
2021-09-17Rollup merge of #88911 - FabianWolff:issue-88653, r=petrochenkovYuki Okushi-0/+31
Improve error message for type mismatch in generator arguments Fixes #88653. The code example given there is invalid because the `Generator` trait (unlike the `Fn` traits) does not take the generator arguments in tupled-up form (because there can only be one argument, from my understanding). Hence, the type error in the example in #88653 is correct, because the given generator takes a `bool` argument, whereas the function's return type talks about a generator with a `(bool,)` argument. The error message is both confusing and wrong, though: It is wrong because it displays the wrong "expected signature", and it is confusing because both the "expected" and "found" notes point at the same span. With my changes, I get the following, more helpful output: ``` error[E0631]: type mismatch in generator arguments --> test.rs:5:22 | 5 | fn foo(bar: bool) -> impl Generator<(bool,)> { | ^^^^^^^^^^^^^^^^^^^^^^^ expected signature of `fn((bool,)) -> _` 6 | |bar| { | ----- found signature of `fn(bool) -> _` ```
2021-09-17Rollup merge of #88883 - c410-f3r:tests, r=petrochenkovYuki Okushi-35/+0
Move some tests to more reasonable directories - 7 cc #73494 r? ``@petrochenkov``
2021-09-17Rollup merge of #88735 - hnj2:patch-1, r=GuillaumeGomezYuki Okushi-0/+9
Don't lint about missing code examples in derived traits When the `missing_doc_code_examples` lint is performed it also requires that derived Trait implementations have a code example for each member etc., which causes undesirable behavior. # Examples With `missing_doc_code_examples` enable we are not able to use the `Clone` derive macro due to the generated code not being documented: ```rust #[deny(rustdoc::missing_doc_code_examples)] /// docs /// ``` /// let s = SomeStruct; /// ``` #[derive(Clone)] pub struct SomeStruct; ``` yields: ``` Documenting testt v0.1.0 (<redacted>) error: missing code example in this documentation --> src/lib.rs:7:10 | 7 | #[derive(Clone)] | ^^^^^ | note: the lint level is defined here --> src/lib.rs:1:8 | 1 | #[deny(rustdoc::missing_doc_code_examples)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing code example in this documentation --> src/lib.rs:7:10 | 7 | #[derive(Clone)] | ^^^^^ error: could not document `testt` Caused by: process didn't exit successfully: `rustdoc ... ``` closes #81775
2021-09-17Rollup merge of #87529 - FabianWolff:issue-87496, r=nikomatsakisYuki Okushi-0/+28
Fix ICE in `improper_ctypes_definitions` lint with all-ZST transparent types Fixes #87496. There is also another function in the same file that looks fishy, but I haven't been able to produce an ICE there, and in any case, it's not related to #87496: https://github.com/rust-lang/rust/blob/fd853c00e255559255885aadff9e93a1760c8728/compiler/rustc_lint/src/types.rs#L720-L734 r? ```@JohnTitor```
2021-09-17Recover invalid assoc type bounds using `==`Yuki Okushi-0/+40
2021-09-17Use `multipart_suggestion`Yuki Okushi-3/+7
2021-09-17Emit clearer diagnostics for parens around `for` loop headsYuki Okushi-5/+4
2021-09-17Make diagnostics clearer for `?` operatorsYuki Okushi-2/+25
2021-09-16Set the library path in sysroot-crates-are-unstableJosh Stone-0/+13
Most of the `run-make-fulldeps` tests use a make-driven rustc command that includes `HOST_RPATH_DIR` in the library path, but this particular test runs from python instead. When the toolchain is built without `rpath` enabled, we need that library path in the environment so it can find its own libraries.
2021-09-17Don't lint about missing code examples in derived traitsHans-0/+9
Fixes #81775
2021-09-16Auto merge of #88719 - estebank:point-at-arg-for-obligation, r=nagisabors-335/+690
Point at argument instead of call for their obligations When an obligation is introduced by a specific `fn` argument, point at the argument instead of the `fn` call if the obligation fails to be fulfilled. Move the information about pointing at the call argument expression in an unmet obligation span from the `FulfillmentError` to a new `ObligationCauseCode`. When giving an error about an obligation introduced by a function call that an argument doesn't fulfill, and that argument is a block, add a span_label pointing at the innermost tail expression. Current output: ``` error[E0425]: cannot find value `x` in this scope --> f10.rs:4:14 | 4 | Some(x * 2) | ^ not found in this scope error[E0277]: expected a `FnOnce<({integer},)>` closure, found `Option<_>` --> f10.rs:2:31 | 2 | let p = Some(45).and_then({ | ______________________--------_^ | | | | | required by a bound introduced by this call 3 | | |x| println!("doubling {}", x); 4 | | Some(x * 2) | | ----------- 5 | | }); | |_____^ expected an `FnOnce<({integer},)>` closure, found `Option<_>` | = help: the trait `FnOnce<({integer},)>` is not implemented for `Option<_>` ``` Previous output: ``` error[E0425]: cannot find value `x` in this scope --> f10.rs:4:14 | 4 | Some(x * 2) | ^ not found in this scope error[E0277]: expected a `FnOnce<({integer},)>` closure, found `Option<_>` --> f10.rs:2:22 | 2 | let p = Some(45).and_then({ | ^^^^^^^^ expected an `FnOnce<({integer},)>` closure, found `Option<_>` | = help: the trait `FnOnce<({integer},)>` is not implemented for `Option<_>` ``` Partially address #27300. Will require rebasing on top of #88546.
2021-09-16Auto merge of #89019 - Manishearth:rollup-5qp8a5s, r=Manishearthbors-64/+82
Rollup of 10 pull requests Successful merges: - #88292 (Enable --generate-link-to-definition for rustc's docs) - #88729 (Recover from `Foo(a: 1, b: 2)`) - #88875 (cleanup(rustc_trait_selection): remove vestigial code from rustc_on_unimplemented) - #88892 (Move object safety suggestions to the end of the error) - #88928 (Document the closure arguments for `reduce`.) - #88976 (Clean up and add doc comments for CStr) - #88983 (Allow calling `get_body_with_borrowck_facts` without `-Z polonius`) - #88985 (Update clobber_abi list to include k[1-7] regs) - #88986 (Update the backtrace crate) - #89009 (Fix typo in `break` docs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-09-16Rollup merge of #88892 - estebank:trait-objects, r=petrochenkovManish Goregaokar-40/+40
Move object safety suggestions to the end of the error
2021-09-16Rollup merge of #88729 - estebank:struct-literal-using-parens, r=oli-obkManish Goregaokar-24/+42
Recover from `Foo(a: 1, b: 2)` Detect likely `struct` literal using parentheses as delimiters and emit targeted suggestion instead of type ascription parse error. Fix #61326.
2021-09-16Auto merge of #88979 - tmiasko:no-remove-zsts-in-generators, r=oli-obkbors-0/+16
Disable RemoveZsts in generators to avoid query cycles Querying layout of a generator requires its optimized MIR. Thus computing layout during MIR optimization of a generator might create a query cycle. Disable RemoveZsts in generators to avoid the issue (similar approach is used in ConstProp transform already). Fixes #88972.
2021-09-16fix rebaseEsteban Kuber-0/+18
2021-09-16Point at argument when evaluating `Path`'s boundsEsteban Kuber-46/+10
When evaluating an `ExprKind::Call`, we first have to `check_expr` on it's callee. When this one is a `ExprKind::Path`, we had to evaluate the bounds introduced for its arguments, but by the time we evaluated them we no longer had access to the argument spans. Now we special case this so that we can point at the right place on unsatisfied bounds. This also allows the E0277 deduplication to kick in correctly, so we now emit fewer errors.
2021-09-16Fix rebaseEsteban Kuber-3/+12
2021-09-16Remove unnecessary labelEsteban Kuber-28/+7
2021-09-16fix rebaseEsteban Kuber-1/+3
2021-09-16Point at call span that introduced obligation for the argEsteban Kuber-249/+657
2021-09-16Refactor `FulfillmentError` to track less dataEsteban Kuber-3/+3
Move the information about pointing at the call argument expression in an unmet obligation span from the `FulfillmentError` to a new `ObligationCauseCode`.
2021-09-16Point at argument instead of call for their obligationsEsteban Kuber-47/+22
When an obligation is introduced by a specific `fn` argument, point at the argument instead of the `fn` call if the obligation fails to be fulfilled.
2021-09-16Auto merge of #86809 - DevinR528:reachable-pat, r=Nadrierilbors-5/+340
Add non_exhaustive_omitted_patterns lint related to rfc-2008-non_exhaustive Fixes: #84332 This PR adds `non_exhaustive_omitted_patterns`, an allow by default lint that is triggered when a `non_exhaustive` type is missing explicit patterns. The warning or deny attribute can be put above the wildcard `_` pattern on enums or on the expression for enums or structs. The lint is capable of warning about multiple types within the same pattern. This lint will not be triggered for `if let ..` patterns. ```rust // crate A #[non_exhaustive] pub struct Foo { a: u8, b: usize, } #[non_exhaustive] pub enum Bar { A(Foo), B, } // crate B #[deny(non_exhaustive_omitted_patterns)] // here match Bar::B { Bar::B => {} #[deny(non_exhaustive_omitted_patterns)] // or here _ => {} } #[warn(non_exhaustive_omitted_patterns)] // only here let Foo { a, .. } = Foo::default(); #[deny(non_exhaustive_omitted_patterns)] match Bar::B { // triggers for Bar::B, and Foo.b Bar::A(Foo { a, .. }) => {} // if the attribute was here only Bar::B would cause a warning _ => {} } ```
2021-09-16Auto merge of #88992 - Manishearth:rollup-k9hijii, r=Manishearthbors-395/+145
Rollup of 8 pull requests Successful merges: - #87320 (Introduce -Z remap-cwd-prefix switch) - #88690 (Accept `m!{ .. }.method()` and `m!{ .. }?` statements. ) - #88775 (Revert anon union parsing) - #88841 (feat(rustc_typeck): suggest removing bad parens in `(recv.method)()`) - #88907 (Highlight the `const fn` if error happened because of a bound on the impl block) - #88915 (`Wrapping<T>` has the same layout and ABI as `T`) - #88933 (Remove implementation of `min_align_of` intrinsic) - #88951 (Update books) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-09-15Disable debuginfo test on Windows that fails in new cdb version.Eric Huss-0/+2
2021-09-15Rollup merge of #88907 - ↵Manish Goregaokar-4/+23
WaffleLapkin:targeted_const_fn_with_a_bound_in_impl_block_error, r=estebank Highlight the `const fn` if error happened because of a bound on the impl block Currently, for the following code, the compiler produces the errors like the following: ```rust struct Type<T>(T); impl<T: Clone> Type<T> { const fn f() {} } ``` ```text error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable --> ./test.rs:3:6 | 3 | impl<T: Clone> Type<T> { | ^ | = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable ``` This can be confusing (especially to newcomers) since the error mentions "const fn parameters", but highlights only the impl. This PR adds function highlighting, changing the error to the following: ```text error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable --> ./test.rs:3:6 | 3 | impl<T: Clone> Type<T> { | ^ 4 | pub const fn f() {} | ---------------- function declared as const here | = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable ``` --- I've originally wanted to point directly to `const` token, but couldn't find a way to get it's span. It seems like this span is lost during the AST -> HIR lowering. Also, since the errors for object casts in `const fn`s (`&T` -> `&dyn Trait`) seem to trigger the same error, this PR accidentally changes these errors too. Not sure if it's desired or how to fix this. P.S. it's my first time contributing to diagnostics, so feedback is very appreciated! --- r? ```@estebank``` ```@rustbot``` label: +A-diagnostics
2021-09-15Rollup merge of #88841 - notriddle:notriddle/method-parens, r=estebankManish Goregaokar-0/+33
feat(rustc_typeck): suggest removing bad parens in `(recv.method)()` Fixes #88803
2021-09-15Rollup merge of #88775 - pnkfelix:revert-anon-union-parsing, r=davidtwcoManish Goregaokar-389/+15
Revert anon union parsing Revert PR #84571 and #85515, which implemented anonymous union parsing in a manner that broke the context-sensitivity for the `union` keyword and thus broke stable Rust code. Fix #88583.
2021-09-15Rollup merge of #88690 - m-ou-se:macro-braces-dot-question-expr-parse, r=nagisaManish Goregaokar-0/+11
Accept `m!{ .. }.method()` and `m!{ .. }?` statements. This PR fixes something that I keep running into when using `quote!{}.into()` in a proc macro to convert the `proc_macro2::TokenStream` to a `proc_macro::TokenStream`: Before: ``` error: expected expression, found `.` --> src/lib.rs:6:6 | 4 | quote! { 5 | ... 6 | }.into() | ^ expected expression ``` After: ``` ``` (No output, compiles fine.) --- Context: For expressions like `{ 1 }` and `if true { 1 } else { 2 }`, we accept them as full statements without a trailing `;`, which means the following is not accepted: ```rust { 1 } - 1 // error ``` since that is parsed as two statements: `{ 1 }` and `-1`. Syntactically correct, but the type of `{ 1 }` should be `()` as there is no `;`. However, for specifically `.` and `?` after the `}`, we do [continue parsing it as an expression](https://github.com/rust-lang/rust/blob/13db8440bbbe42870bc828d4ec3e965b38670277/compiler/rustc_parse/src/parser/expr.rs#L864-L876): ```rust { "abc" }.len(); // ok ``` For braced macro invocations, we do not do this: ```rust vec![1, 2, 3].len(); // ok vec!{1, 2, 3}.len(); // error ``` (It parses `vec!{1, 2, 3}` as a full statement, and then complains about `.len()` not being a valid expression.) This PR changes this to also look for a `.` and `?` after a braced macro invocation. We can be sure the macro is an expression and not a full statement in those cases, since no statement can start with a `.` or `?`.
2021-09-15Rollup merge of #87320 - danakj:debug-compilation-dir, r=michaelwoeristerManish Goregaokar-2/+63
Introduce -Z remap-cwd-prefix switch This switch remaps any absolute paths rooted under the current working directory to a new value. This includes remapping the debug info in `DW_AT_comp_dir` and `DW_AT_decl_file`. Importantly, this flag does not require passing the current working directory to the compiler, such that the command line can be run on any machine (with the same input files) and produce the same results. This is critical property for debugging compiler issues that crop up on remote machines. This is based on adetaylor's https://github.com/rust-lang/rust/commit/dbc4ae7cba0ba8d650b91ddd459b86a02a2d05c5 Major Change Proposal: https://github.com/rust-lang/compiler-team/issues/450 Discussed on #38322. Would resolve issue #87325.
2021-09-15Allow `panic!("{}", computed_str)` in const fn.Gary Guo-37/+83
2021-09-15Disable both reproducible-build tests for crate-type=bindanakj-4/+5
These tests fail on Windows, as the build is not deterministic there for bin targets. Issue https://github.com/rust-lang/rust/issues/88982 is filed for this problem.
2021-09-15Move some tests to more reasonable directoriesCaio-35/+0
2021-09-15Disable RemoveZsts in generators to avoid query cyclesTomasz Miąsko-0/+16
Querying layout of a generator requires its optimized MIR. Thus computing layout during MIR optimization of a generator might create a query cycle. Disable RemoveZsts in generators to avoid the issue (similar approach is used in ConstProp transform already).
2021-09-15Verify bin crates are not deterministic on Windowsdanakj-3/+21
This disables the remap_cwd_bin test which is failing on windows, and adds a test for --remap-path-prefix making a bin crate instead, to see if it will fail the same way.
2021-09-15Move object safety suggestions to the end of the errorEsteban Kuber-40/+40
2021-09-15Auto merge of #88558 - fee1-dead:const-drop, r=oli-obkbors-0/+274
Const drop The changes are pretty primitive at this point. But at least it works. ^-^ Problems with the current change that I can think of now: - [x] `~const Drop` shouldn't change anything in the non-const world. - [x] types that do not have drop glues shouldn't fail to satisfy `~const Drop` in const contexts. `struct S { a: u8, b: u16 }` This might not fail for `needs_non_const_drop`, but it will fail in `rustc_trait_selection`. - [x] The current change accepts types that have `const Drop` impls but have non-const `Drop` glue. Fixes #88424. Significant Changes: - `~const Drop` is no longer treated as a normal trait bound. In non-const contexts, this bound has no effect, but in const contexts, this restricts the input type and all of its transitive fields to either a) have a `const Drop` impl or b) can be trivially dropped (i.e. no drop glue) - `T: ~const Drop` will not be linted like `T: Drop`. - Instead of recursing and iterating through the type in `rustc_mir::transform::check_consts`, we use the trait system to special case `~const Drop`. See [`rustc_trait_selection::...::candidate_assembly#assemble_const_drop_candidates`](https://github.com/fee1-dead/rust/blob/const-drop/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs#L817) and others. Changes not related to `const Drop`ping and/or changes that are insignificant: - `Node.constness_for_typeck` no longer returns `hir::Constness::Const` for type aliases in traits. This was previously used to hack how we determine default bound constness for items. But because we now use an explicit opt-in, it is no longer needed. - Removed `is_const_impl_raw` query. We have `impl_constness`, and the only existing use of that query uses `HirId`, which means we can just operate it with hir. - `ty::Destructor` now has a field `constness`, which represents the constness of the destructor. r? `@oli-obk`
2021-09-15Point to closure when emitting 'cannot move out' for captured variableFabian Wolff-211/+495
2021-09-14Add reachable_patterns lint to rfc-2008-non_exhaustiveDevin Ragotzy-5/+340
Add linting on non_exhaustive structs and enum variants Add ui tests for non_exhaustive reachable lint Rename to non_exhaustive_omitted_patterns and avoid triggering on if let
2021-09-14Auto merge of #73314 - GuillaumeGomez:display-warnings, r=jyn514bors-0/+33
Rename "--display-warnings" to "--display-doctest-warnings" Fixes #41574. cc `@ollie27` r? `@kinnison`
2021-09-14Add test for --display-doctest-warnings optionGuillaume Gomez-0/+33
2021-09-14Auto merge of #88914 - GuillaumeGomez:rollup-h5svc6w, r=GuillaumeGomezbors-5/+115
Rollup of 7 pull requests Successful merges: - #88033 (Add links for primitives in "jump to definition" feature) - #88722 (Make `UnsafeCell::get_mut` const) - #88851 (Fix duplicate bounds for const_trait_impl) - #88859 (interpreter PointerArithmetic: use new Size helper methods) - #88885 (Fix jump def background) - #88894 (Improve error message for missing trait in trait impl) - #88896 (Reduce possibility of flaky tests) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup