about summary refs log tree commit diff
path: root/src/test
AgeCommit message (Collapse)AuthorLines
2021-12-27Rollup merge of #92307 - hiroshi-maybe:fix-minor-typos, r=camelidMatthias Krüger-1/+1
Fix minor typos
2021-12-27Rollup merge of #92303 - Patrick-Poitras:issue-26186, r=jackh726Matthias Krüger-0/+62
Add test cases for issue #26186 Closes #26186 It seems that issue #26186 has been solved at some point since the issue has been last updated. I've merged together the examples that were supplied by `@Osspial,` `@Mark-Simulacrum,` `@Diggsey,` `@eefriedman` and `@shepmaster,` so that we can add this to the testing suite and prevent these issues from re-occurring.
2021-12-27Rollup merge of #92112 - SparrowLii:issue92010, r=cjgillotMatthias Krüger-0/+24
Fix the error of checking `base_expr` twice in type_changing_struct_update Fixes #92010
2021-12-27Rollup merge of #90586 - jswrenn:relax-privacy-lints, r=petrochenkovMatthias Krüger-81/+320
Relax priv-in-pub lint on generic bounds and where clauses of trait impls. The priv-in-pub lint is a legacy mechanism of the compiler, supplanted by a reachability-based [type privacy](https://github.com/rust-lang/rfcs/blob/master/text/2145-type-privacy.md) analysis. This PR does **not** relax type privacy; it only relaxes the lint (as proposed by the type privacy RFC) in the case of trait impls. ## Current Behavior On public trait impls, it's currently an **error** to have a `where` bound constraining a private type with a trait: ```rust pub trait Trait {} pub struct Type {} struct Priv {} impl Trait for Priv {} impl Trait for Type where Priv: Trait // ERROR {} ``` ...and it's a **warning** to have have a public type constrained by a private trait: ```rust pub trait Trait {} pub struct Type {} pub struct Pub {} trait Priv {} impl Priv for Pub {} impl Trait for Type where Pub: Priv // WARNING {} ``` This lint applies to `where` clauses in other contexts, too; e.g. on free functions: ```rust struct Priv<T>(T); pub trait Pub {} impl<T: Pub> Pub for Priv<T> {} pub fn function<T>() where Priv<T>: Pub // WARNING {} ``` **These constraints could be relaxed without issue.** ## New Behavior This lint is relaxed for `where` clauses on trait impls, such that it's okay to have a `where` bound constraining a private type with a trait: ```rust pub trait Trait {} pub struct Type {} struct Priv {} impl Trait for Priv {} impl Trait for Type where Priv: Trait // OK {} ``` ...and it's okay to have a public type constrained by a private trait: ```rust pub trait Trait {} pub struct Type {} pub struct Pub {} trait Priv {} impl Priv for Pub {} impl Trait for Type where Pub: Priv // OK {} ``` ## Rationale While the priv-in-pub lint is not essential for soundness, it *can* help programmers avoid pitfalls that would make their libraries difficult to use by others. For instance, such a lint *is* useful for free functions; e.g. if a downstream crate tries to call the `function` in the previous snippet in a generic context: ```rust fn callsite<T>() where Priv<T>: Pub // ERROR: omitting this bound is a compile error, but including it is too { function::<T>() } ``` ...it cannot do so without repeating `function`'s `where` bound, which we cannot do because `Priv` is out-of-scope. A lint for this case is arguably helpful. However, this same reasoning **doesn't** hold for trait impls. To call an unconstrained method on a public trait impl with private bounds, you don't need to forward those private bounds, you can forward the public trait: ```rust mod upstream { pub trait Trait { fn method(&self) {} } pub struct Type<T>(T); pub struct Pub<T>(T); trait Priv {} impl<T: Priv> Priv for Pub<T> {} impl<T> Trait for Type<T> where Pub<T>: Priv // WARNING {} } mod downstream { use super::upstream::*; fn function<T>(value: Type<T>) where Type<T>: Trait // <- no private deets! { value.method(); } } ``` **This PR only eliminates the lint on trait impls.** It leaves it intact for all other contexts, including trait definitions, inherent impls, and function definitions. It doesn't need to exist in those cases either, but I figured I'd first target a case where it's mostly pointless. ## Other Notes - See discussion [on zulip](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/relax.20priv-in-pub.20lint.20for.20trait.20impl.20.60where.60.20bounds/near/222458397). - This PR effectively reverts #79291.
2021-12-26fix typo: intialized -> initializedHiroshi Kori-1/+1
2021-12-27relax priv-in-pub lint on generic bounds and where clauses in trait implsJack Wrenn-81/+320
2021-12-26Add test cases for issue #26186PFPoitras-0/+62
2021-12-25bless ui testDeadbeef-1/+16
2021-12-25normalize env constness for nested obligationsDeadbeef-0/+14
2021-12-24Auto merge of #91342 - RalfJung:fn-abi, r=eddyb,oli-obkbors-2/+2
CTFE eval_fn_call: use FnAbi to determine argument skipping and compatibility This makes use of the `FnAbi` type in CTFE/Miri, which `@eddyb` has been saying for years is what we should do.^^ `FnAbi` is used to - determine which arguments to skip (rather than the previous heuristic of skipping ZST arguments with the Rust ABI) - impose further restrictions on whether caller and callee are consistent in how a given argument is passed I was hoping it would also simplify the code, but that is not the case -- the previous type compatibility checks are still required (AFAIK), only the ZST skipping is gone and that took barely any code. We also need some hacks because `FnAbi` assumes a certain way of implementing `caller_location` (by passing extra arguments), but Miri can just read the caller location from the call stack so it doesn't need those arguments. (The fact that every backend has to separately implement support for these arguments seems suboptimal -- looks like this might have been better implemented on the MIR level.) To avoid having to implement those unnecessary arguments in Miri, we just compute *whether* the argument is present on the caller/callee side, but don't actually pass that argument around. I have no idea if this looks the way `@eddyb` thinks it should look... but it makes Miri's test suite pass. ;) One of rustc's tests fails unfortunately (`ui/const-generics/issues/issue-67739.rs`), some const generic code that is evaluated too early -- I think that should raise `TooGeneric` but instead it ICEs. My assumption is this is some FnAbi code that has not been properly tested on polymorphic code, but it might also be me calling that FnAbi code the wrong way. r? `@oli-obk` `@eddyb` Fixes https://github.com/rust-lang/rust/issues/56166 Miri PR at https://github.com/rust-lang/miri/pull/1928
2021-12-23Rollup merge of #92166 - fee1-dead:patch-2, r=jyn514Matthias Krüger-1/+1
Fixed a small typo in ui test comments
2021-12-23Auto merge of #92155 - m-ou-se:panic-fn, r=eddybbors-14/+14
Use panic() instead of panic!() in some places in core. See https://github.com/rust-lang/rust/pull/92068 and https://github.com/rust-lang/rust/pull/92140. This avoids the `panic!()` macro in a few potentially hot paths. This becomes more relevant when switching `core` to Rust 2021, as it'll avoid format_args!() and save some compilation time. (It doesn't make a huge difference, but still.) (Also the errors in const panic become slightly nicer.)
2021-12-23Rollup merge of #91544 - rukai:91492, r=wesleywiserMatthias Krüger-0/+79
Fix duplicate derive clone suggestion closes https://github.com/rust-lang/rust/issues/91492 The addition of: ```rust derives.sort(); derives.dedup(); ``` is what actually solves the problem. The rest is just cleanup. I want to improve the diagnostic message to provide the suggestion as a proper diff but ran into some problems, so I'll attempt that again in a follow up PR.
2021-12-22Fixed a small typo in ui test commentsfee1-dead-1/+1
2021-12-21Auto merge of #92149 - fee1-dead:cache-fix, r=oli-obkbors-0/+29
Fix bad caching of `~const Drop` bounds Fixes #92111.
2021-12-21Use panic() instead of panic!() in some places in core.Mara Bos-14/+14
2021-12-21Rollup merge of #91770 - TaKO8Ki:suggest-adding-cfg-test, r=joshtriplettMatthias Krüger-0/+234
Suggest adding a `#[cfg(test)]` to to a test module closes #88138
2021-12-21Fix bad caching of `~const Drop` boundsDeadbeef-0/+29
2021-12-20Fixup tests for issue-86035Michael Goulet-4/+4
2021-12-20Test for issue-86035Michael Goulet-0/+97
2021-12-20compare calling convention instead of call ABIRalf Jung-2/+2
2021-12-20Auto merge of #92041 - Aaron1011:remove-speculative-evaluation, r=jackh726bors-0/+34
Remove 'speculative evaluation' of predicates Performing 'speculative evaluation' introduces caching bugs that cannot be fixed without invasive changes to projection. Hopefully, we can win back most of the performance lost by re-adding 'cache completion' Fixes #90662
2021-12-20Auto merge of #91900 - pitaj:fix-91714, r=jyn514bors-39/+18
rustdoc: make `--passes` and `--no-defaults` have no effect Fixes #91714 One potential issue is that currently there is no stable way to achieve `--document-hidden-items`. This affects test `issue-15347`. I also had to modify the tests `issue-42875` and `no-compiler-export`. Regardless of combinations of `--document-hidden-items` and `--document-private-items`, I was unable to get these to pass without the modifications. I left behind a comment noting the change.
2021-12-20add test filesSparrowLii-0/+24
2021-12-19Rollup merge of #91791 - terrarier2111:fix-float-ice, r=nagisaMatthias Krüger-0/+29
Fix an ICE when lowering a float with missing exponent magnitude This fixes: https://github.com/rust-lang/rust/issues/91434
2021-12-19Fix an ICE when lowering a float with missing exponent magnitudethreadexception-0/+29
Co-authored-by: Simonas Kazlauskas <github@kazlauskas.me>
2021-12-19Auto merge of #91957 - nnethercote:rm-SymbolStr, r=oli-obkbors-1/+1
Remove `SymbolStr` This was originally proposed in https://github.com/rust-lang/rust/pull/74554#discussion_r466203544. As well as removing the icky `SymbolStr` type, it allows the removal of a lot of `&` and `*` occurrences. Best reviewed one commit at a time. r? `@oli-obk`
2021-12-19Rollup merge of #91956 - notriddle:notriddle/unused-parens-range, r=nagisaMatthias Krüger-0/+48
fix(rustc_lint): better detect when parens are necessary Fixes #90807
2021-12-19Rollup merge of #91834 - GuillaumeGomez:improve-gui-test-readability, r=jshaMatthias Krüger-66/+278
Update browser-ui-test version and improve rustdoc-gui tests readability Since the `0.5.1`, we can use trailing commas. I also used the opportunity to clean up the existing tests. r? `@notriddle`
2021-12-18Auto merge of #92065 - matthiaskrgr:rollup-qmpcsuj, r=matthiaskrgrbors-4/+53
Rollup of 7 pull requests Successful merges: - #91566 (Apply path remapping to DW_AT_GNU_dwo_name when producing split DWARF) - #91926 (Remove `in_band_lifetimes` from `rustc_metadata`) - #91931 (Remove `in_band_lifetimes` from `rustc_codegen_llvm`) - #92024 (rustc_codegen_llvm: Give each codegen unit a unique DWARF name on all platforms, not just Apple ones.) - #92037 (Use a const ParamEnv when in default_method_body_is_const) - #92047 (Set `RUST_BACKTRACE=0` when running location-detail tests) - #92050 (Add a space and 2 grave accents ) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-12-18Auto merge of #92064 - matthiaskrgr:rollup-tgj2pai, r=matthiaskrgrbors-20/+20
Rollup of 7 pull requests Successful merges: - #91858 (pass -Wl,-z,origin to set DF_ORIGIN when using rpath) - #91923 (Remove `in_band_lifetimes` from `rustc_query_impl`) - #91925 (Remove `in_band_lifetimes` from `rustc_privacy`) - #91977 (Clean up search code and unify function returned values) - #92018 (Fix typo in "new region bound" suggestion) - #92022 (Eliminate duplicate codes of expected_found_bool) - #92032 (hir: Do not introduce dummy type names for `extern` blocks in def paths) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-12-18Rollup merge of #92047 - Aaron1011:location-detail-backtrace, r=Mark-SimulacrumMatthias Krüger-3/+7
Set `RUST_BACKTRACE=0` when running location-detail tests This ensures that the output does not depend on environment variables set in the shell.
2021-12-18Rollup merge of #92037 - fee1-dead:fix_env_dmbic, r=oli-obkMatthias Krüger-0/+36
Use a const ParamEnv when in default_method_body_is_const r? `@oli-obk` This PR fixes the param_env function to return `constness: Const` correctly for trait methods marked with `#[default_method_body_is_const]`. The snippet below is erroneously accepted by the compiler and has been fixed by this change. ([Playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=12dc6681b2eeee5f604203d96259eeb4)) ```rust #![feature(const_fn_trait_bound)] #![feature(const_trait_impl)] trait Tr {} impl Tr for () {} const fn foo<T>() where T: ~const Tr {} pub trait Foo { #[default_method_body_is_const] fn foo() { foo::<()>(); } } ```
2021-12-18Rollup merge of #91566 - cbeuw:remap-dwo-name, r=davidtwcoMatthias Krüger-1/+10
Apply path remapping to DW_AT_GNU_dwo_name when producing split DWARF `--remap-path-prefix` doesn't apply to paths to `.o` (in case of packed) or `.dwo` (in case of unpacked) files in `DW_AT_GNU_dwo_name`. GCC also has this bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91888
2021-12-18Rollup merge of #92018 - estebank:missing-ticks, r=oli-obkMatthias Krüger-20/+20
Fix typo in "new region bound" suggestion The lifetime name shoud always appear in text surrounded by `.
2021-12-18Auto merge of #92062 - matthiaskrgr:rollup-en3p4sb, r=matthiaskrgrbors-9/+29
Rollup of 7 pull requests Successful merges: - #91439 (Mark defaulted `PartialEq`/`PartialOrd` methods as const) - #91516 (Improve suggestion to change struct field to &mut) - #91896 (Remove `in_band_lifetimes` for `rustc_passes`) - #91909 (:arrow_up: rust-analyzer) - #91922 (Remove `in_band_lifetimes` from `rustc_mir_dataflow`) - #92025 (Revert "socket ancillary data implementation for dragonflybsd.") - #92030 (Update stdlib to the 2021 edition) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-12-18Rollup merge of #91516 - rukai:improve_mut_addition_help, r=estebankMatthias Krüger-9/+29
Improve suggestion to change struct field to &mut r? ``@estebank`` Now displays a proper underline style suggestion instead of including the code change inline with the message.
2021-12-18Rollup merge of #91975 - cjgillot:noinline-generator, r=jackh726Matthias Krüger-11/+6
Move generator check earlier in inlining. Inlining into generator may create references to other generators. For instance, inlining `Pin::<&mut from_generator::GenFuture<[generator1]>>::new_unchecked` into `generator2`. This cross reference can then create cycles when computing inlining for `generator1`. In order to avoid this kind of surprises, we forbid all inlining into generators, and rely on LLVM to do the right thing. The existing `remove-zst-query-cycle` already ICEs in inline-mir mode, so we use it as test. Split from #91743.
2021-12-18Rollup merge of #91928 - fee1-dead:constification1, r=oli-obkMatthias Krüger-12/+12
Constify (most) `Option` methods r? ``@oli-obk``
2021-12-18Rollup merge of #91910 - tmiasko:miri-extern-type, r=RalfJungMatthias Krüger-0/+58
miri: lift restriction on extern types being the only field in a struct Fixes #91827. r? ````@RalfJung````
2021-12-18Rollup merge of #91818 - camelid:unused-result-type, r=jackh726Matthias Krüger-2/+2
Show the unused type for `unused_results` lint I think it's helpful to know what type was unused when looking at these warnings. The type will likely determine whether the result *should* be used, or whether it should just be ignored. Including the type also matches the behavior of the `must_use` lint: unused `SomeType` that must be used.
2021-12-18Rollup merge of #89090 - cjgillot:bare-dyn, r=jackh726Matthias Krüger-203/+654
Lint bare traits in AstConv. Removing the lint from lowering allows to: - make lowering querification easier; - have the lint implementation in only one place. r? `@estebank`
2021-12-18Rollup merge of #87901 - poliorcetics:pub-pub-pub, r=jackh726Matthias Krüger-15/+64
Fix suggestion of additional `pub` when using `pub pub fn ...` Fix #87694. Marked as draft to start with because I want to explore doing the same fix for `const const fn` and other repeated-but-valid keywords. `@rustbot` label A-diagnostics D-invalid-suggestion T-compiler
2021-12-18get_mut_span_in_struct_field uses span.betweenLucas Kent-1/+1
2021-12-17Auto merge of #89841 - cormacrelf:let-else-typed, r=nagisabors-19/+683
Implement let-else type annotations natively Tracking issue: #87335 Fixes #89688, fixes #89807, edit: fixes #89960 as well As explained in https://github.com/rust-lang/rust/issues/89688#issuecomment-940405082, the previous desugaring moved the let-else scrutinee into a dummy variable, which meant if you wanted to refer to it again in the else block, it had moved. This introduces a new hir type, ~~`hir::LetExpr`~~ `hir::Let`, which takes over all the fields of `hir::ExprKind::Let(...)` and adds an optional type annotation. The `hir::Let` is then treated like a `hir::Local` when type checking a function body, specifically: * `GatherLocalsVisitor` overrides a new `Visitor::visit_let_expr` and does pretty much exactly what it does for `visit_local`, assigning a local type to the `hir::Let` ~~(they could be deduplicated but they are right next to each other, so at least we know they're the same)~~ * It reuses the code in `check_decl_local` to typecheck the `hir::Let`, simply returning 'bool' for the expression type after doing that. * ~~`FnCtxt::check_expr_let` passes this local type in to `demand_scrutinee_type`, and then imitates check_decl_local's pattern checking~~ * ~~`demand_scrutinee_type` (the blindest change for me, please give this extra scrutiny) uses this local type instead of of creating a new one~~ * ~~Just realised the `check_expr_with_needs` was passing NoExpectation further down, need to pass the type there too. And apparently this Expectation API already exists.~~ Some other misc notes: * ~~Is the clippy code supposed to be autoformatted? I tried not to give huge diffs but maybe some rustfmt changes simply haven't hit it yet.~~ * in `rustc_ast_lowering/src/block.rs`, I noticed some existing `self.alias_attrs()` calls in `LoweringContext::lower_stmts` seem to be copying attributes from the lowered locals/etc to the statements. Is that right? I'm new at this, I don't know.
2021-12-17Remove 'speculative evaluation' of predicatesAaron Hill-0/+34
Performing 'speculative evaluation' introduces caching bugs that cannot be fixed without invasive changes to projection. Hopefully, we can win back most of the performance lost by re-adding 'cache completion' Fixes #90662
2021-12-17fix(rustc_lint): mark the parens around `(1..loop {})` as unusedMichael Howell-0/+40
2021-12-17Auto merge of #91838 - scottmcm:array-slice-eq-via-arrays-not-slices, r=dtolnaybors-3/+16
Do array-slice equality via array equality, rather than always via slices ~~Draft because it needs a rebase after #91766 eventually gets through bors.~~ This enables the optimizations from #85828 to be used for array-to-slice comparisons too, not just array-to-array. For example, <https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=5f9ba69b3d5825a782f897c830d3a6aa> ```rust pub fn demo(x: &[u8], y: [u8; 4]) -> bool { *x == y } ``` Currently writes the array to stack for no reason: ```nasm sub rsp, 4 mov dword ptr [rsp], edx cmp rsi, 4 jne .LBB0_1 mov eax, dword ptr [rdi] cmp eax, dword ptr [rsp] sete al add rsp, 4 ret .LBB0_1: xor eax, eax add rsp, 4 ret ``` Whereas with the change in this PR it just compares it directly: ```nasm cmp rsi, 4 jne .LBB1_1 cmp dword ptr [rdi], edx sete al ret .LBB1_1: xor eax, eax ret ```
2021-12-17Set `RUST_BACKTRACE=0` when running location-detail testsAaron Hill-3/+7
This ensures that the output does not depend on environment variables set in the shell.
2021-12-17Bless ui testsDeadbeef-12/+12