about summary refs log tree commit diff
path: root/src
AgeCommit message (Collapse)AuthorLines
2021-12-29Add a pretty printer test of impl<T> const TraitDavid Tolnay-0/+6
2021-12-29Rollup merge of #92372 - dtolnay:fntype, r=jackh726Matthias Krüger-1/+1
Print space after formal generic params in fn type Follow-up to #92238 fixing one of the FIXMEs. ```rust macro_rules! repro { ($ty:ty) => { stringify!($ty) }; } fn main() { println!("{}", repro!(for<'a> fn(&'a u8))); } ``` Before:&ensp;`for<'a>fn(&'a u8)` After:&ensp;`for<'a> fn(&'a u8)` The pretty printer's `print_formal_generic_params` already prints formal generic params correctly with a space, we just need to call it when printing BareFn types instead of reimplementing the printing incorrectly without a space. https://github.com/rust-lang/rust/blob/83b15bfe1c15f325bc186ebfe3691b729ed59f2b/compiler/rustc_ast_pretty/src/pprust/state.rs#L1394-L1400
2021-12-29Rollup merge of #92371 - dtolnay:attrblock, r=oli-obkMatthias Krüger-12/+12
Remove pretty printer space inside block with only outer attrs Follow-up to #92238 fixing one of the FIXMEs. ```rust macro_rules! repro { ($expr:expr) => { stringify!($expr) }; } fn main() { println!("{}", repro!(#[attr] {})); } ``` Before:&ensp;`#[attr] { }` After:&ensp;`#[attr] {}`
2021-12-29Rollup merge of #92351 - TmLev:master, r=GuillaumeGomezMatthias Krüger-2/+23
Add long error explanation for E0227 Part of the #61137.
2021-12-29Rollup merge of #92340 - camelid:search-index-cleanup, r=GuillaumeGomezMatthias Krüger-50/+65
rustdoc: Start cleaning up search index generation I'm trying to simplify and clean up the code, partly to make #90779 easier. r? `@GuillaumeGomez`
2021-12-29Rollup merge of #92237 - compiler-errors:issue-92100, r=cjgillotMatthias Krüger-0/+46
Visit expressions in-order when resolving pattern bindings [edited:] Visit the pattern's sub-expressions before defining any bindings. Otherwise, we might get into a case where a Lit/Range expression in a pattern has a qpath pointing to a Ident pattern that is defined after it, causing an ICE when lowering to HIR. I have a more detailed explanation in the issue linked. Fixes #92100
2021-12-29Rollup merge of #92118 - jackh726:type-alias-position-error, r=petrochenkovMatthias Krüger-0/+77
Parse and suggest moving where clauses after equals for type aliases ~Mostly the same as #90076, but doesn't make any syntax changes.~ Whether or not we want to land the syntax changes, we should parse the invalid where clause position and suggest moving. r? `@nikomatsakis` cc `@petrochenkov` you might have thoughts on implementation
2021-12-29Rollup merge of #92075 - jyn514:resolve-cleanup, r=camelidMatthias Krüger-16/+25
rustdoc: Only special case struct fields for intra-doc links, not enum variants Variants are already handled by `resolve_str_path_error`, rustdoc doesn't need to consider them separately. Thanks `@camelid` for catching this! Eventually I'd like to fix the "combine this with `variant_field`" comment but that needs `resolve_field` to take a `ty_res` parameter to avoid it being super hacky (cc https://github.com/rust-lang/rust/issues/83761#issuecomment-813026026). r? `@camelid`
2021-12-29Auto merge of #92283 - vacuus:print-generic-bounds, r=camelid,GuillaumeGomezbors-3/+1
rustdoc: Remove `String` allocation in iteration in `print_generic_bounds` (I realized only after making the commit that maybe I shouldn't refer to iteration as looping, but it's close enough) The string representation of a `clean::GenericBound` instance (evaluated [here](https://github.com/rust-lang/rust/blob/master/src/librustdoc/html/format.rs#L397)) is deterministic for a given `self` (the instance), `cx` and `f`, and since `cx` and `f` are constant (as far as I can tell) for a given invocation of `print_generic_bounds`, `self` is the determining factor. Therefore, using the data in `self` shouldn't differ in effect from using its string representation. Given the totality of the function calls needed to evaluate the string representation as well as the actual allocation, at the very least, this shouldn't negatively affect performance.
2021-12-28Auto merge of #92269 - vacuus:clean-generics-print, r=camelidbors-5/+6
rustdoc: Remove `collect` call in `clean::Generics::print`
2021-12-28Add regression test for #59502Noah Lev-0/+13
This issue was fixed using a hacky recursion "fuel" argument, but the issue was never minimized nor was a regression test added. The underlying bug is still unfixed, so this test should help with fixing it and removing the `recurse` hack.
2021-12-28Explain why struct fields are handled by assoc. item codeNoah Lev-0/+12
2021-12-28Remove unused parameterNoah Lev-6/+5
2021-12-28Print space after formal generic params in fn typeDavid Tolnay-1/+1
2021-12-28Only special case struct fields for intra-doc links, not enum variantsJoshua Nelson-16/+13
Variants are already handled by `resolve_str_path_error`, rustdoc doesn't need to consider them separately.
2021-12-28Remove pretty printer space inside block with only outer attrsDavid Tolnay-12/+12
2021-12-28Parse and suggest moving where clauses after equals for type aliasesJack Huey-0/+77
2021-12-28Rollup merge of #92344 - lnicola:rust-analyzer-2021-12-28, r=lnicolaMatthias Krüger-16/+16
:arrow_up: rust-analyzer r? ``@ghost``
2021-12-28Rollup merge of #92333 - compiler-errors:elided-lifetime-spans, r=cjgillotMatthias Krüger-3/+80
Tighten span when suggesting lifetime on path This is kind of a hack. Really the issue here is that we want to suggest the segment's span if the path resolves to something defined outside of the macro, and the macro's span if it resolves to something defined within.. I'll look into seeing if we can do something like that. Fixes #92324 r? `@cjgillot`
2021-12-28Rollup merge of #92238 - dtolnay:stringifytest, r=Mark-SimulacrumMatthias Krüger-0/+879
Add a test suite for stringify macro This attempts to cover the behavior of `stringify!` on various interpolated syntax tree nodes. The pretty printer has a history of unsightly whitespace (double spaces, missing spaces, spaces where there shouldn't be spaces) &mdash; #91437, #91562, #91568. There are several such issues left; the test cases that I consider to be currently behaving incorrectly are marked with `// FIXME` in the PR.
2021-12-28Rollup merge of #92219 - ehuss:remove-vcvars, r=Mark-SimulacrumMatthias Krüger-1/+0
Remove VCVARS_BAT This environment variable is no longer used. It was used in the original Azure Pipelines configuration (#60777). When GitHub Actions were added (#70190), it was no longer used, and I suspect it was just an oversight while transitioning the configuration.
2021-12-28docs(error-codes): Add long error explanation for E0227TmLev-2/+23
2021-12-28:arrow_up: rust-analyzerLaurențiu Nicola-16/+16
2021-12-27Tighten span when suggesting lifetime on pathMichael Goulet-3/+80
2021-12-27Give clearer names to several search index functionsNoah Lev-14/+26
2021-12-27Coalesce two arguments as `&Function`Noah Lev-6/+8
2021-12-27Make `search_index` functions private where possibleNoah Lev-2/+2
Now the only two crate-public items are `build_index` and `get_index_search_type` (because for some reason the latter is also used in `formats::cache`).
2021-12-27Move `ExternalLocation` to `clean::types`Noah Lev-19/+19
It was previously defined in `render::search_index` but wasn't used at all there. `clean::types` seems like a better fit since that's where `ExternalCrate` is defined.
2021-12-27rustdoc: Remove some unnecessary `cache` parametersNoah Lev-24/+13
Based on https://github.com/rust-lang/rust/pull/80883#issuecomment-774437832. The `tcx` parameters do seem to be used though, so I only removed the `cache` parameters.
2021-12-27Rename `rustdoc::html::render::cache` to `search_index`Noah Lev-6/+6
The old name wasn't very clear, while the new one makes it clear that this is the code responsible for creating the search index.
2021-12-27intra-doc: Use an enum to represent URL fragmentsNoah Lev-78/+113
This is a step in the direction of computing the links more lazily, which I think will simplify the implementation of intra-doc links. This will also make it easier to eventually use the actual `Res` for associated items, enum variants, and fields, rather than their HTML page's `Res`.
2021-12-27Remove needless `return`Noah Lev-1/+1
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-27Visit patterns' literal expressions before binding new identsMichael Goulet-0/+46
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-26Auto merge of #92257 - fee1-dead:fix_env_further_bounds, r=oli-obkbors-1/+30
normalize env constness for nested obligations Closes #92230.
2021-12-25Remove unneeded call to `collect`Roc Yu-5/+6
2021-12-25Remove `String` allocation in loopRoc Yu-3/+1
2021-12-25Auto merge of #92262 - notriddle:notriddle/unused-hash, r=jyn514bors-11/+2
rustdoc: remove unused Hash impl
2021-12-25Auto merge of #92227 - Kobzol:rustdoc-doc-hidden, r=jyn514bors-16/+7
Rustdoc: use `is_doc_hidden` method on more places While profiling `rustdoc`, I noticed that finding out if some item is marked with `#[doc(hidden)]` is relatively hot, so I tried to optimize it. I noticed that there is already a method called `is_doc_hidden` on `TyCtxt`, but it wasn't used much, so I replaced the manual calls to `attrs(...).has_word(...)` with this method. Just by doing that, perf. was improved locally, although I'm not sure if the semantics of the previous calls and this method are the same? As another step, I tried to querify `is_doc_hidden`, but I didn't include that here until we see the perf. results from the first commit and until I find whether this change is OK at all :) Can I ask for a perf. run? Thanks. r? `@jyn514`
2021-12-25Auto merge of #92247 - lnicola:rust-analyzer-2021-12-24, r=lnicolabors-21/+16
:arrow_up: rust-analyzer r? `@ghost`
2021-12-24Auto merge of #92229 - fee1-dead:fix-rustdoc-const-drop, r=dtolnaybors-20/+35
Do not display `~const Drop` in rustdoc Although `T: ~const Drop` is still at an experimental stage, we have already begun inserting these bounds in libstd. This change hides them from rustdoc because 1. `~const` should not be documented in general as it is not yet official syntax; 2. users are not expected to know what `~const Drop` means yet.
2021-12-24rustdoc: remove unused Hash implMichael Howell-11/+2
2021-12-25bless ui testDeadbeef-1/+16
2021-12-25normalize env constness for nested obligationsDeadbeef-0/+14