about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection
AgeCommit message (Collapse)AuthorLines
2022-08-25Don't create an extra infcx in report_closure_arg_mismatchMichael Goulet-3/+1
2022-08-25no unnormalized types for implied boundslcnr-1/+12
2022-08-25Rollup merge of #99332 - jyn514:stabilize-label-break-value, r=petrochenkovYuki Okushi-1/+1
Stabilize `#![feature(label_break_value)]` See the stabilization report in https://github.com/rust-lang/rust/issues/48594#issuecomment-1186213313.
2022-08-24Use ExprItemObligation and ExprBindingObligation tooMichael Goulet-1/+3
2022-08-24Note binding obligation causes for const equate errorsMichael Goulet-3/+16
2022-08-24Rollup merge of #100888 - ↵Matthias Krüger-11/+146
spastorino:coherence-negative-impls-implied-bounds, r=lcnr Coherence negative impls implied bounds Fixes #93875 This PR is rebased on top of #100789 and it would need to include that one which is already r+ed. r? ``@nikomatsakis`` cc ``@lcnr`` (which I've talked about https://github.com/rust-lang/rust/commit/3222f420d9d2312efe0735eb48160c7b070adc54, I guess after you finish your reordering of modules and work with OutlivesEnvironmentEnv this commit can just be reverted).
2022-08-23Stabilize `#![feature(label_break_value)]`Joshua Nelson-1/+1
# Stabilization proposal The feature was implemented in https://github.com/rust-lang/rust/pull/50045 by est31 and has been in nightly since 2018-05-16 (over 4 years now). There are [no open issues][issue-label] other than the tracking issue. There is a strong consensus that `break` is the right keyword and we should not use `return`. There have been several concerns raised about this feature on the tracking issue (other than the one about tests, which has been fixed, and an interaction with try blocks, which has been fixed). 1. nrc's original comment about cost-benefit analysis: https://github.com/rust-lang/rust/issues/48594#issuecomment-422235234 2. joshtriplett's comments about seeing use cases: https://github.com/rust-lang/rust/issues/48594#issuecomment-422281176 3. withoutboats's comments that Rust does not need more control flow constructs: https://github.com/rust-lang/rust/issues/48594#issuecomment-450050630 Many different examples of code that's simpler using this feature have been provided: - A lexer by rpjohnst which must repeat code without label-break-value: https://github.com/rust-lang/rust/issues/48594#issuecomment-422502014 - A snippet by SergioBenitez which avoids using a new function and adding several new return points to a function: https://github.com/rust-lang/rust/issues/48594#issuecomment-427628251. This particular case would also work if `try` blocks were stabilized (at the cost of making the code harder to optimize). - Several examples by JohnBSmith: https://github.com/rust-lang/rust/issues/48594#issuecomment-434651395 - Several examples by Centril: https://github.com/rust-lang/rust/issues/48594#issuecomment-440154733 - An example by petrochenkov where this is used in the compiler itself to avoid duplicating error checking code: https://github.com/rust-lang/rust/issues/48594#issuecomment-443557569 - Amanieu recently provided another example related to complex conditions, where try blocks would not have helped: https://github.com/rust-lang/rust/issues/48594#issuecomment-1184213006 Additionally, petrochenkov notes that this is strictly more powerful than labelled loops due to macros which accidentally exit a loop instead of being consumed by the macro matchers: https://github.com/rust-lang/rust/issues/48594#issuecomment-450246249 nrc later resolved their concern, mostly because of the aforementioned macro problems. joshtriplett suggested that macros could be able to generate IR directly (https://github.com/rust-lang/rust/issues/48594#issuecomment-451685983) but there are no open RFCs, and the design space seems rather speculative. joshtriplett later resolved his concerns, due to a symmetry between this feature and existing labelled break: https://github.com/rust-lang/rust/issues/48594#issuecomment-632960804 withoutboats has regrettably left the language team. joshtriplett later posted that the lang team would consider starting an FCP given a stabilization report: https://github.com/rust-lang/rust/issues/48594#issuecomment-1111269353 [issue-label]: https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+label%3AF-label_break_value+ ## Report + Feature gate: - https://github.com/rust-lang/rust/blob/d695a497bbf4b20d2580b75075faa80230d41667/src/test/ui/feature-gates/feature-gate-label_break_value.rs + Diagnostics: - https://github.com/rust-lang/rust/blob/6b2d3d5f3cd1e553d87b5496632132565b6779d3/compiler/rustc_parse/src/parser/diagnostics.rs#L2629 - https://github.com/rust-lang/rust/blob/f65bf0b2bb1a99f73095c01a118f3c37d3ee614c/compiler/rustc_resolve/src/diagnostics.rs#L749 - https://github.com/rust-lang/rust/blob/f65bf0b2bb1a99f73095c01a118f3c37d3ee614c/compiler/rustc_resolve/src/diagnostics.rs#L1001 - https://github.com/rust-lang/rust/blob/111df9e6eda1d752233482c1309d00d20a4bbf98/compiler/rustc_passes/src/loops.rs#L254 - https://github.com/rust-lang/rust/blob/d695a497bbf4b20d2580b75075faa80230d41667/compiler/rustc_parse/src/parser/expr.rs#L2079 - https://github.com/rust-lang/rust/blob/d695a497bbf4b20d2580b75075faa80230d41667/compiler/rustc_parse/src/parser/expr.rs#L1569 + Tests: - https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_continue.rs - https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_unlabeled_break.rs - https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_illegal_uses.rs - https://github.com/rust-lang/rust/blob/master/src/test/ui/lint/unused_labels.rs - https://github.com/rust-lang/rust/blob/master/src/test/ui/run-pass/for-loop-while/label_break_value.rs ## Interactions with other features Labels follow the hygiene of local variables. label-break-value is permitted within `try` blocks: ```rust let _: Result<(), ()> = try { 'foo: { Err(())?; break 'foo; } }; ``` label-break-value is disallowed within closures, generators, and async blocks: ```rust 'a: { || break 'a //~^ ERROR use of unreachable label `'a` //~| ERROR `break` inside of a closure } ``` label-break-value is disallowed on [_BlockExpression_]; it can only occur as a [_LoopExpression_]: ```rust fn labeled_match() { match false 'b: { //~ ERROR block label not supported here _ => {} } } macro_rules! m { ($b:block) => { 'lab: $b; //~ ERROR cannot use a `block` macro fragment here unsafe $b; //~ ERROR cannot use a `block` macro fragment here |x: u8| -> () $b; //~ ERROR cannot use a `block` macro fragment here } } fn foo() { m!({}); } ``` [_BlockExpression_]: https://doc.rust-lang.org/nightly/reference/expressions/block-expr.html [_LoopExpression_]: https://doc.rust-lang.org/nightly/reference/expressions/loop-expr.html
2022-08-23Rollup merge of #100368 - chenyukang:fix-100321, r=lcnrDylan DPC-3/+0
InferCtxt tainted_by_errors_flag should be Option<ErrorGuaranteed> Fixes #100321. Use Cell<Option<ErrorGuaranteed>> to guarantee that we emit an error when that flag is set.
2022-08-23Use CRATE_HIR_ID and CRATE_DEF_ID for obligations from foreign cratesSantiago Pastorino-11/+13
2022-08-23Do not use unneeded extra errors variableSantiago Pastorino-2/+1
2022-08-23Permit negative impls coherence to take advantage of implied boundsSantiago Pastorino-8/+26
2022-08-23Move InferCtxtExt to rustc_trait_selectionSantiago Pastorino-0/+116
2022-08-23Rollup merge of #100789 - compiler-errors:issue-99662, r=spastorinoMatthias Krüger-13/+8
Use separate infcx to solve obligations during negative coherence I feel like I fixed this already but I may have fixed it then forgot to push the branch... Also fixes up some redundant param-envs being passed around (since they're already passed around in the `Obligation`) Fixes #99662 r? ``@spastorino``
2022-08-22safe transmute: use `Assume` struct to provide analysis optionsJack Wrenn-16/+4
This was left as a TODO in #92268, and brings the trait more in line with what was defined in MCP411. `Assume::visibility` has been renamed to `Assume::safety`, as library safety is what's actually being assumed; visibility is just the mechanism by which it is currently checked (this may change). ref: https://github.com/rust-lang/compiler-team/issues/411 ref: https://github.com/rust-lang/rust/issues/99571
2022-08-22remove hack fix since we don't have no overflow diagnosticyukang-3/+0
2022-08-22Auto merge of #100868 - Dylan-DPC:rollup-a1hfi1r, r=Dylan-DPCbors-0/+12
Rollup of 5 pull requests Successful merges: - #93162 (Std module docs improvements) - #99386 (Add tests that check `Vec::retain` predicate execution order.) - #99915 (Recover keywords in trait bounds) - #100694 (Migrate rustc_ast_passes diagnostics to `SessionDiagnostic` and translatable messages (first part)) - #100757 (Catch overflow early) Failed merges: - #99917 (Move Error trait into core) r? `@ghost` `@rustbot` modify labels: rollup
2022-08-22Rollup merge of #100757 - ouz-a:issue-95134, r=jackh726Dylan DPC-0/+12
Catch overflow early Although this code should raise an overflow error, it didn't because [check_recursion_limit](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_trait_selection/traits/select/struct.SelectionContext.html#method.check_recursion_limit) it checks for `depth = 128` but not for `129` which should have triggered the overflow error. Anyways this catches that error early. Fixes #95134
2022-08-22Auto merge of #100676 - lcnr:implied-bounds-yay, r=nikomatsakisbors-1/+22
implied bounds: explicitly state which types are assumed to be wf Adds a new query which maps each definition to the types which that definition assumes to be well formed. The intent is to make it easier to reason about implied bounds. This change should not influence the user-facing behavior of rustc. Notably, `borrowck` still only assumes that the function signature of associated functions is well formed while `wfcheck` assumes that the both the function signature and the impl trait ref is well formed. Not sure if that by itself can trigger UB or whether it's just annoying. As a next step, we can add `WellFormed` predicates to `predicates_of` of these items and can stop adding the wf bounds at each place which uses them. I also intend to move the computation from `assumed_wf_types` to `implied_bounds` into the `param_env` computation. This requires me to take a deeper look at `compare_predicate_entailment` which is currently somewhat weird wrt implied bounds so I am not touching this here. r? `@nikomatsakis`
2022-08-21Bless tests after #100769Michael Goulet-92/+95
2022-08-21Adjust messages, address some nitsMichael Goulet-38/+38
2022-08-21Targeted fixes addressing erroneous suggestionsMichael Goulet-9/+27
2022-08-21Note closure kind mismatch causeMichael Goulet-2/+1
2022-08-21Rework point-at-argMichael Goulet-46/+34
2022-08-20Rollup merge of #100796 - TaKO8Ki:remove-unnecessary-string-searching, ↵Matthias Krüger-14/+17
r=compiler-errors Refactor: remove unnecessary string searchings This patch removes unnecessary string searchings for checking if function arguments have `&` and `&mut`.
2022-08-20Rollup merge of #100769 - ↵Matthias Krüger-7/+25
TaKO8Ki:suggest-adding-reference-to-trait-assoc-item, r=cjgillot Suggest adding a reference to a trait assoc item fixes #100289
2022-08-20use more descriptive namesTakayuki Maeda-93/+95
2022-08-20remove unnecessary string searchingsTakayuki Maeda-14/+17
remove unnecessary string searchings for checking if function arguments have `&` and `&mut`
2022-08-20Use separate infcx to solve obligations during negative coherenceMichael Goulet-13/+8
2022-08-20suggest adding a reference to a trait assoc itemTakayuki Maeda-85/+101
2022-08-19Catch overflow earlyouz-a-0/+12
2022-08-18Reword "Required because of the requirements on the impl of ..."Andy Wang-6/+6
2022-08-18Auto merge of #99860 - oli-obk:revert_97346, r=pnkfelixbors-4/+14
Revert "Rollup merge of #97346 - JohnTitor:remove-back-compat-hacks, … …r=oli-obk" This reverts commit c703d11dccb4a895c7aead3b2fcd8cea8c483184, reversing changes made to 64eb9ab869bc3f9ef3645302fbf22e706eea16cf. it didn't apply cleanly, so now it works the same for RPIT and for TAIT instead of just working for RPIT, but we should keep those in sync anyway. It also exposed a TAIT bug (see the feature gated test that now ICEs). r? `@pnkfelix` fixes #99536
2022-08-18Avoid overflow in is_impossible_methodMichael Goulet-3/+10
2022-08-17dedup some codelcnr-1/+22
2022-08-17`is_knowable` use `Result` instead of `Option`lcnr-8/+8
2022-08-16Fix error message with non-tupled bare fn traitMichael Goulet-3/+27
2022-08-15Rollup merge of #100514 - compiler-errors:issue-100191, r=spastorinoMatthias Krüger-1/+7
Delay span bug when failing to normalize negative coherence impl subject due to other malformed impls Fixes #100191 r? ``@spastorino``
2022-08-14TypeError can be CopyMichael Goulet-5/+3
2022-08-14Rollup merge of #99861 - lcnr:orphan-check-cg, r=jackh726Dylan DPC-1/+15
orphan check: rationalize our handling of constants cc `@rust-lang/types` `@rust-lang/project-const-generics` on whether you agree with this reasoning. r? types
2022-08-13Delay span bug when failing to normalize negative coherence impl subject due ↵Michael Goulet-1/+7
to other malformed impls
2022-08-13wf correctly shallow_resolve constslcnr-9/+7
2022-08-13avoid cloning and then iteratingKaDiWa-1/+1
2022-08-12Adjust cfgsMark Rousskov-1/+0
2022-08-11Auto merge of #100315 - compiler-errors:norm-ct-in-proj, r=lcnrbors-3/+20
Keep going if normalized projection has unevaluated consts in `QueryNormalizer` #100312 was the wrong approach, I think this is the right one. When normalizing a type, if we see that it's a projection, we currently defer to `tcx.normalize_projection_ty`, which normalizes the projections away but doesn't touch the unevaluated constants. So now we just continue to fold the type if it has unevaluated constants so we make sure to evaluate those too, if we can. Fixes #100217 Fixes #83972 Fixes #84669 Fixes #86710 Fixes #82268 Fixes #73298
2022-08-09Move folding into just projection casesMichael Goulet-10/+20
2022-08-09Auto merge of #99217 - lcnr:implied-bounds-pre-norm, r=lcnrbors-0/+21
consider unnormalized types for implied bounds extracted, and slightly modified, from #98900 The idea here is that generally, rustc is split into things which can assume its inputs are well formed[^1], and things which have verify that themselves. Generally most predicates should only deal with well formed inputs, e.g. a `&'a &'b (): Trait` predicate should be able to assume that `'b: 'a` holds. Normalization can loosen wf requirements (see #91068) and must therefore not be used in places which still have to check well formedness. The only such place should hopefully be `WellFormed` predicates fixes #87748 and #98543 r? `@jackh726` cc `@rust-lang/types` [^1]: These places may still encounter non-wf inputs and have to deal with them without causing an ICE as we may check for well formedness out of order.
2022-08-09Rollup merge of #100221 - compiler-errors:impossible-trait-items, ↵Dylan DPC-1/+76
r=lcnr,notriddle,camelid Don't document impossible to call default trait items on impls Closes #100176 This only skips documenting _default_ trait items on impls, not ones that are written inside the impl block. This is a conservative approach, since I think we should document all items written in an impl block (I guess unless hidden or whatever), but the existence of this new query I added makes this easy to extend to other rustdoc cases.
2022-08-09don't normalize wf predicateslcnr-0/+21
this allows us to soundly use unnormalized projections for wf
2022-08-09Keep going if normalized projection has unevaluated consts in QueryNormalizerMichael Goulet-1/+8
2022-08-08Adjust wordingMichael Goulet-3/+3