提交 9cf699d2 编写于 作者: B bors

Auto merge of #98412 - calebcartwright:sync-rustfmt, r=calebcartwright

Sync rustfmt

We had a bug in the update we made ~1 week ago, so running a somewhat early sync to pull the fix in
......@@ -4712,7 +4712,7 @@ dependencies = [
[[package]]
name = "rustfmt-nightly"
version = "1.5.0"
version = "1.5.1"
dependencies = [
"annotate-snippets 0.9.1",
"anyhow",
......
......@@ -35,15 +35,5 @@ jobs:
sh rustup-init.sh -y --default-toolchain none
rustup target add ${{ matrix.target }}
- name: build
run: |
rustc -Vv
cargo -V
cargo build
env:
RUSTFLAGS: '-D warnings'
- name: test
run: cargo test
env:
RUSTFLAGS: '-D warnings'
- name: Build and Test
run: ./ci/build_and_test.sh
......@@ -32,11 +32,5 @@ jobs:
sh rustup-init.sh -y --default-toolchain none
rustup target add ${{ matrix.target }}
- name: build
run: |
rustc -Vv
cargo -V
cargo build
- name: test
run: cargo test
- name: Build and Test
run: ./ci/build_and_test.sh
......@@ -57,13 +57,6 @@ jobs:
if: matrix.target == 'x86_64-pc-windows-gnu' && matrix.channel == 'nightly'
shell: bash
- name: build
run: |
rustc -Vv
cargo -V
cargo build
shell: cmd
- name: test
run: cargo test
- name: Build and Test
shell: cmd
run: ci\build_and_test.bat
......@@ -2,7 +2,29 @@
## [Unreleased]
## [1.5.0] 2022-06-13
## [1.5.1] 2022-06-24
**N.B** A bug was introduced in v1.5.0/nightly-2022-06-15 which modified formatting. If you happened to run rustfmt over your code with one of those ~10 nightlies it's possible you may have seen formatting changes, and you may see additional changes after this fix since that bug has now been reverted.
### Fixed
- Correct an issue introduced in v1.5.0 where formatting changes were unintentionally introduced in a few cases with a large/long construct in a right hand side position (e.g. a large chain on the RHS of a local/assignment statement)
- `cargo fmt --version` properly displays the version value again [#5395](https://github.com/rust-lang/rustfmt/issues/5395)
### Changed
- Properly sort imports containing raw identifiers [#3791](https://github.com/rust-lang/rustfmt/issues/3791) (note this is change version gated, and not applied by default)
### Added
- Add new configuration option, `doc_comment_code_block_width`, which allows for setting a shorter width limit to use for formatting code snippets in doc comments [#5384](https://github.com/rust-lang/rustfmt/issues/5384)
### Install/Download Options
- **rustup (nightly)** - nightly-2022-06-24
- **GitHub Release Binaries** - [Release v1.5.1](https://github.com/rust-lang/rustfmt/releases/tag/v1.5.0)
- **Build from source** - [Tag v1.5.1](https://github.com/rust-lang/rustfmt/tree/v1.5.1), see instructions for how to [install rustfmt from source][install-from-source]
## [1.5.0] 2022-06-14
### Changed
......@@ -75,7 +97,7 @@
- Improved performance when formatting large and deeply nested expression trees, often found in generated code, which have many expressions that exceed `max_width` [#5128](https://github.com/rust-lang/rustfmt/issues/5128), [#4867](https://github.com/rust-lang/rustfmt/issues/4867), [#4476](https://github.com/rust-lang/rustfmt/issues/4476), [#5139](https://github.com/rust-lang/rustfmt/pull/5139)
### Install/Download Options
- **rustup (nightly)** - *pending*
- **rustup (nightly)** - nightly-2022-06-15
- **GitHub Release Binaries** - [Release v1.5.0](https://github.com/rust-lang/rustfmt/releases/tag/v1.5.0)
- **Build from source** - [Tag v1.5.0](https://github.com/rust-lang/rustfmt/tree/v1.5.0), see instructions for how to [install rustfmt from source][install-from-source]
......
......@@ -485,7 +485,7 @@ dependencies = [
[[package]]
name = "rustfmt-nightly"
version = "1.5.0"
version = "1.5.1"
dependencies = [
"annotate-snippets",
"anyhow",
......
[package]
name = "rustfmt-nightly"
version = "1.5.0"
version = "1.5.1"
description = "Tool to find and fix Rust formatting issues"
repository = "https://github.com/rust-lang/rustfmt"
readme = "README.md"
......@@ -65,3 +65,7 @@ rustfmt-config_proc_macro = { version = "0.2", path = "config_proc_macro" }
rustc-workspace-hack = "1.0.0"
# Rustc dependencies are loaded from the sysroot, Cargo doesn't know about them.
[package.metadata.rust-analyzer]
# This package uses #[feature(rustc_private)]
rustc_private = true
......@@ -926,6 +926,14 @@ fn add_one(x: i32) -> i32 {
}
```
## `doc_comment_code_block_width`
Max width for code snippets included in doc comments. Only used if [`format_code_in_doc_comments`](#format_code_in_doc_comments) is true.
- **Default value**: `100`
- **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width)
- **Stable**: No (tracking issue: [#5359](https://github.com/rust-lang/rustfmt/issues/5359))
## `format_generated_files`
Format generated files. A file is considered generated
......
set "RUSTFLAGS=-D warnings"
:: Print version information
rustc -Vv || exit /b 1
cargo -V || exit /b 1
:: Build and test main crate
cargo build --locked || exit /b 1
cargo test || exit /b 1
:: Build and test other crates
cd config_proc_macro || exit /b 1
cargo build --locked || exit /b 1
cargo test || exit /b 1
#!/bin/bash
set -euo pipefail
export RUSTFLAGS="-D warnings"
# Print version information
rustc -Vv
cargo -V
# Build and test main crate
cargo build --locked
cargo test
# Build and test other crates
cd config_proc_macro
cargo build --locked
cargo test
......@@ -15,7 +15,7 @@ set -ex
# it again.
#
#which cargo-fmt || cargo install --force
CFG_RELEASE=nightly CFG_RELEASE_CHANNEL=nightly cargo install --path . --force
CFG_RELEASE=nightly CFG_RELEASE_CHANNEL=nightly cargo install --path . --force --locked
echo "Integration tests for: ${INTEGRATION}"
cargo fmt -- --version
......
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "proc-macro2"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e98a83a9f9b331f54b924e68a66acb1bb35cb01fb0a23645139967abefb697e8"
dependencies = [
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe"
dependencies = [
"proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2",
]
[[package]]
name = "rustfmt-config_proc_macro"
version = "0.1.2"
version = "0.2.0"
dependencies = [
"proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2",
"quote",
"serde",
"syn",
]
[[package]]
name = "serde"
version = "1.0.99"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fec2851eb56d010dc9a21b89ca53ee75e6528bab60c11e89d38390904982da9f"
dependencies = [
"serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.99"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb4dc18c61206b08dc98216c98faa0232f4337e1e1b8574551d5bad29ea1b425"
dependencies = [
"proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "syn"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf"
dependencies = [
"proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "unicode-xid"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e98a83a9f9b331f54b924e68a66acb1bb35cb01fb0a23645139967abefb697e8"
"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe"
"checksum serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)" = "fec2851eb56d010dc9a21b89ca53ee75e6528bab60c11e89d38390904982da9f"
"checksum serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)" = "cb4dc18c61206b08dc98216c98faa0232f4337e1e1b8574551d5bad29ea1b425"
"checksum syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf"
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
......@@ -29,6 +29,8 @@ pub fn config_type(_args: TokenStream, input: TokenStream) -> TokenStream {
/// Used to conditionally output the TokenStream for tests that need to be run on nightly only.
///
/// ```rust
/// # use rustfmt_config_proc_macro::nightly_only_test;
///
/// #[nightly_only_test]
/// #[test]
/// fn test_needs_nightly_rustfmt() {
......@@ -49,6 +51,8 @@ pub fn nightly_only_test(_args: TokenStream, input: TokenStream) -> TokenStream
/// Used to conditionally output the TokenStream for tests that need to be run on stable only.
///
/// ```rust
/// # use rustfmt_config_proc_macro::stable_only_test;
///
/// #[stable_only_test]
/// #[test]
/// fn test_needs_stable_rustfmt() {
......
[toolchain]
channel = "nightly-2022-06-06"
channel = "nightly-2022-06-21"
components = ["rustc-dev"]
......@@ -14,7 +14,7 @@
use std::process::Command;
use std::str;
use clap::{CommandFactory, Parser};
use clap::{AppSettings, CommandFactory, Parser};
#[path = "test/mod.rs"]
#[cfg(test)]
......@@ -22,6 +22,7 @@
#[derive(Parser)]
#[clap(
global_setting(AppSettings::NoAutoVersion),
bin_name = "cargo fmt",
about = "This utility formats all bin and lib files of \
the current crate using rustfmt."
......
......@@ -730,6 +730,10 @@ fn handle_line(
{
let mut config = self.fmt.config.clone();
config.set().wrap_comments(false);
let comment_max_width = config
.doc_comment_code_block_width()
.min(config.max_width());
config.set().max_width(comment_max_width);
if let Some(s) =
crate::format_code_block(&self.code_block_buffer, &config, false)
{
......
......@@ -57,6 +57,8 @@
// Comments. macros, and strings
wrap_comments: bool, false, false, "Break comments to fit on the line";
format_code_in_doc_comments: bool, false, false, "Format the code snippet in doc comments.";
doc_comment_code_block_width: usize, 100, false, "Maximum width for code snippets in doc \
comments. No effect unless format_code_in_doc_comments = true";
comment_width: usize, 80, false,
"Maximum length of comments. No effect unless wrap_comments = true";
normalize_comments: bool, false, false, "Convert /* */ comments to // comments where possible";
......@@ -532,6 +534,7 @@ fn test_dump_default_config() {
single_line_if_else_max_width = 50
wrap_comments = false
format_code_in_doc_comments = false
doc_comment_code_block_width = 100
comment_width = 80
normalize_comments = false
normalize_doc_attributes = false
......
use std::borrow::Cow;
use std::cmp::min;
use std::collections::HashMap;
use itertools::Itertools;
use rustc_ast::token::{Delimiter, LitKind};
......@@ -23,7 +22,7 @@
use crate::matches::rewrite_match;
use crate::overflow::{self, IntoOverflowableItem, OverflowableItem};
use crate::pairs::{rewrite_all_pairs, rewrite_pair, PairParts};
use crate::rewrite::{QueryId, Rewrite, RewriteContext};
use crate::rewrite::{Rewrite, RewriteContext};
use crate::shape::{Indent, Shape};
use crate::source_map::{LineRangeUtils, SpanUtils};
use crate::spanned::Spanned;
......@@ -54,54 +53,6 @@ pub(crate) fn format_expr(
expr_type: ExprType,
context: &RewriteContext<'_>,
shape: Shape,
) -> Option<String> {
// when max_width is tight, we should check all possible formattings, in order to find
// if we can fit expression in the limit. Doing it recursively takes exponential time
// relative to input size, and people hit it with rustfmt takes minutes in #4476 #4867 #5128
// By memoization of format_expr function, we format each pair of expression and shape
// only once, so worst case execution time becomes O(n*max_width^3).
if context.inside_macro() || context.is_macro_def {
// span ids are not unique in macros, so we don't memoize result of them.
return format_expr_inner(expr, expr_type, context, shape);
}
let clean;
let query_id = QueryId {
shape,
span: expr.span,
};
if let Some(map) = context.memoize.take() {
if let Some(r) = map.get(&query_id) {
let r = r.clone();
context.memoize.set(Some(map)); // restore map in the memoize cell for other users
return r;
}
context.memoize.set(Some(map));
clean = false;
} else {
context.memoize.set(Some(HashMap::default()));
clean = true; // We got None, so we are the top level called function. When
// this function finishes, no one is interested in what is in the map, because
// all of them are sub expressions of this top level expression, and this is
// done. So we should clean up memoize map to save some memory.
}
let r = format_expr_inner(expr, expr_type, context, shape);
if clean {
context.memoize.set(None);
} else {
if let Some(mut map) = context.memoize.take() {
map.insert(query_id, r.clone()); // insert the result in the memoize map
context.memoize.set(Some(map)); // so it won't be computed again
}
}
r
}
fn format_expr_inner(
expr: &ast::Expr,
expr_type: ExprType,
context: &RewriteContext<'_>,
shape: Shape,
) -> Option<String> {
skip_out_of_file_lines_range!(context, expr.span);
......
......@@ -2,7 +2,6 @@
use std::collections::HashMap;
use std::io::{self, Write};
use std::rc::Rc;
use std::time::{Duration, Instant};
use rustc_ast::ast;
......@@ -203,7 +202,6 @@ fn format_file(
self.config,
&snippet_provider,
self.report.clone(),
Rc::default(),
);
visitor.skip_context.update_with_attrs(&self.krate.attrs);
visitor.is_macro_def = is_macro_def;
......
此差异已折叠。
......@@ -12,7 +12,7 @@
use rustc_span::{symbol::sym, Span};
use crate::config::{Config, GroupImportsTactic};
use crate::imports::{normalize_use_trees_with_granularity, UseSegment, UseTree};
use crate::imports::{normalize_use_trees_with_granularity, UseSegmentKind, UseTree};
use crate::items::{is_mod_decl, rewrite_extern_crate, rewrite_mod};
use crate::lists::{itemize_list, write_list, ListFormatting, ListItem};
use crate::rewrite::RewriteContext;
......@@ -182,16 +182,16 @@ fn group_imports(uts: Vec<UseTree>) -> Vec<Vec<UseTree>> {
external_imports.push(ut);
continue;
}
match &ut.path[0] {
UseSegment::Ident(id, _) => match id.as_ref() {
match &ut.path[0].kind {
UseSegmentKind::Ident(id, _) => match id.as_ref() {
"std" | "alloc" | "core" => std_imports.push(ut),
_ => external_imports.push(ut),
},
UseSegment::Slf(_) | UseSegment::Super(_) | UseSegment::Crate(_) => {
UseSegmentKind::Slf(_) | UseSegmentKind::Super(_) | UseSegmentKind::Crate(_) => {
local_imports.push(ut)
}
// These are probably illegal here
UseSegment::Glob | UseSegment::List(_) => external_imports.push(ut),
UseSegmentKind::Glob | UseSegmentKind::List(_) => external_imports.push(ut),
}
}
......
......@@ -12,7 +12,6 @@
use crate::skip::SkipContext;
use crate::visitor::SnippetProvider;
use crate::FormatReport;
use rustc_data_structures::stable_map::FxHashMap;
pub(crate) trait Rewrite {
/// Rewrite self into shape.
......@@ -25,22 +24,10 @@ fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String>
}
}
#[derive(Clone, PartialEq, Eq, Hash)]
pub(crate) struct QueryId {
pub(crate) shape: Shape,
pub(crate) span: Span,
}
// We use Option<HashMap> instead of HashMap, because in case of `None`
// the function clean the memoize map, but it doesn't clean when
// there is `Some(empty)`, so they are different.
pub(crate) type Memoize = Rc<Cell<Option<FxHashMap<QueryId, Option<String>>>>>;
#[derive(Clone)]
pub(crate) struct RewriteContext<'a> {
pub(crate) parse_sess: &'a ParseSess,
pub(crate) config: &'a Config,
pub(crate) memoize: Memoize,
pub(crate) inside_macro: Rc<Cell<bool>>,
// Force block indent style even if we are using visual indent style.
pub(crate) use_block: Cell<bool>,
......
......@@ -4,7 +4,7 @@
use crate::Config;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[derive(Copy, Clone, Debug)]
pub(crate) struct Indent {
// Width of the block indent, in characters. Must be a multiple of
// Config::tab_spaces.
......@@ -139,7 +139,7 @@ fn sub(self, rhs: usize) -> Indent {
// 8096 is close enough to infinite for rustfmt.
const INFINITE_SHAPE_WIDTH: usize = 8096;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[derive(Copy, Clone, Debug)]
pub(crate) struct Shape {
pub(crate) width: usize,
// The current indentation of code.
......
......@@ -17,7 +17,7 @@
use crate::macros::{macro_style, rewrite_macro, rewrite_macro_def, MacroPosition};
use crate::modules::Module;
use crate::parse::session::ParseSess;
use crate::rewrite::{Memoize, Rewrite, RewriteContext};
use crate::rewrite::{Rewrite, RewriteContext};
use crate::shape::{Indent, Shape};
use crate::skip::{is_skip_attr, SkipContext};
use crate::source_map::{LineRangeUtils, SpanUtils};
......@@ -71,7 +71,6 @@ pub(crate) fn end_pos(&self) -> BytePos {
pub(crate) struct FmtVisitor<'a> {
parent_context: Option<&'a RewriteContext<'a>>,
pub(crate) memoize: Memoize,
pub(crate) parse_sess: &'a ParseSess,
pub(crate) buffer: String,
pub(crate) last_pos: BytePos,
......@@ -759,7 +758,6 @@ pub(crate) fn from_context(ctx: &'a RewriteContext<'_>) -> FmtVisitor<'a> {
ctx.config,
ctx.snippet_provider,
ctx.report.clone(),
ctx.memoize.clone(),
);
visitor.skip_context.update(ctx.skip_context.clone());
visitor.set_parent_context(ctx);
......@@ -771,12 +769,10 @@ pub(crate) fn from_parse_sess(
config: &'a Config,
snippet_provider: &'a SnippetProvider,
report: FormatReport,
memoize: Memoize,
) -> FmtVisitor<'a> {
FmtVisitor {
parent_context: None,
parse_sess: parse_session,
memoize,
buffer: String::with_capacity(snippet_provider.big_snippet.len() * 2),
last_pos: BytePos(0),
block_indent: Indent::empty(),
......@@ -999,7 +995,6 @@ pub(crate) fn get_context(&self) -> RewriteContext<'_> {
RewriteContext {
parse_sess: self.parse_sess,
config: self.config,
memoize: self.memoize.clone(),
inside_macro: Rc::new(Cell::new(false)),
use_block: Cell::new(false),
is_if_else_block: Cell::new(false),
......
// rustfmt-format_code_in_doc_comments: true
// rustfmt-doc_comment_code_block_width: 100
/// ```rust
/// impl Test {
/// pub const fn from_bytes(v: &[u8]) -> Result<Self, ParserError> {
/// Self::from_bytes_manual_slice(v, 0, v.len() )
/// }
/// }
/// ```
impl Test {
pub const fn from_bytes(v: &[u8]) -> Result<Self, ParserError> {
Self::from_bytes_manual_slice(v, 0, v.len() )
}
}
// rustfmt-max_width: 50
// rustfmt-format_code_in_doc_comments: true
// rustfmt-doc_comment_code_block_width: 100
/// ```rust
/// impl Test {
/// pub const fn from_bytes(v: &[u8]) -> Result<Self, ParserError> {
/// Self::from_bytes_manual_slice(v, 0, v.len() )
/// }
/// }
/// ```
impl Test {
pub const fn from_bytes(v: &[u8]) -> Result<Self, ParserError> {
Self::from_bytes_manual_slice(v, 0, v.len() )
}
}
// rustfmt-format_code_in_doc_comments: true
// rustfmt-doc_comment_code_block_width: 50
/// ```rust
/// impl Test {
/// pub const fn from_bytes(v: &[u8]) -> Result<Self, ParserError> {
/// Self::from_bytes_manual_slice(v, 0, v.len() )
/// }
/// }
/// ```
impl Test {
pub const fn from_bytes(v: &[u8]) -> Result<Self, ParserError> {
Self::from_bytes_manual_slice(v, 0, v.len() )
}
}
// rustfmt-version:One
use websocket::client::ClientBuilder;
use websocket::r#async::futures::Stream;
use websocket::result::WebSocketError;
// rustfmt-version:Two
use websocket::client::ClientBuilder;
use websocket::r#async::futures::Stream;
use websocket::result::WebSocketError;
// rustfmt-format_code_in_doc_comments: true
// rustfmt-doc_comment_code_block_width: 100
/// ```rust
/// impl Test {
/// pub const fn from_bytes(v: &[u8]) -> Result<Self, ParserError> {
/// Self::from_bytes_manual_slice(v, 0, v.len())
/// }
/// }
/// ```
impl Test {
pub const fn from_bytes(v: &[u8]) -> Result<Self, ParserError> {
Self::from_bytes_manual_slice(v, 0, v.len())
}
}
// rustfmt-max_width: 50
// rustfmt-format_code_in_doc_comments: true
// rustfmt-doc_comment_code_block_width: 100
/// ```rust
/// impl Test {
/// pub const fn from_bytes(
/// v: &[u8],
/// ) -> Result<Self, ParserError> {
/// Self::from_bytes_manual_slice(
/// v,
/// 0,
/// v.len(),
/// )
/// }
/// }
/// ```
impl Test {
pub const fn from_bytes(
v: &[u8],
) -> Result<Self, ParserError> {
Self::from_bytes_manual_slice(
v,
0,
v.len(),
)
}
}
// rustfmt-format_code_in_doc_comments: true
// rustfmt-doc_comment_code_block_width: 50
/// ```rust
/// impl Test {
/// pub const fn from_bytes(
/// v: &[u8],
/// ) -> Result<Self, ParserError> {
/// Self::from_bytes_manual_slice(
/// v,
/// 0,
/// v.len(),
/// )
/// }
/// }
/// ```
impl Test {
pub const fn from_bytes(v: &[u8]) -> Result<Self, ParserError> {
Self::from_bytes_manual_slice(v, 0, v.len())
}
}
// rustfmt-version:One
use websocket::client::ClientBuilder;
use websocket::r#async::futures::Stream;
use websocket::result::WebSocketError;
// rustfmt-version:Two
use websocket::r#async::futures::Stream;
use websocket::client::ClientBuilder;
use websocket::result::WebSocketError;
// rustfmt-max_width: 140
impl NotificationRepository {
fn set_status_changed(
&self,
repo_tx_conn: &RepoTxConn,
rid: &RoutableId,
changed_at: NaiveDateTime,
) -> NukeResult<Option<NotificationStatus>> {
repo_tx_conn.run(move |conn| {
let res = diesel::update(client_notification::table)
.filter(
client_notification::routable_id.eq(DieselRoutableId(rid.clone())).and(
client_notification::changed_at
.lt(changed_at)
.or(client_notification::changed_at.is_null()),
),
)
.set(client_notification::changed_at.eq(changed_at))
.returning((
client_notification::id,
client_notification::changed_at,
client_notification::polled_at,
client_notification::notified_at,
))
.get_result::<(Uuid, Option<NaiveDateTime>, Option<NaiveDateTime>, Option<NaiveDateTime>)>(conn)
.optional()?;
match res {
Some(row) => {
let client_id = client_contract::table
.inner_join(client_notification::table)
.filter(client_notification::id.eq(row.0))
.select(client_contract::client_id)
.get_result::<Uuid>(conn)?;
Ok(Some(NotificationStatus {
client_id: client_id.into(),
changed_at: row.1,
polled_at: row.2,
notified_at: row.3,
}))
}
None => Ok(None),
}
})
}
}
mod modA {
mod modB {
mod modC {
mod modD {
mod modE {
fn func() {
state . rule (Rule :: myrule , | state | { state . sequence (| state | { state . sequence (| state | { state . match_string ("abc") . and_then (| state | { super :: hidden :: skip (state) }) . and_then (| state | { state . match_string ("def") }) }) . and_then (| state | { super :: hidden :: skip (state) }) . and_then (| state | { state . sequence (| state | { state . optional (| state | { state . sequence (| state | { state . match_string ("abc") . and_then (| state | { super :: hidden :: skip (state) }) . and_then (| state | { state . match_string ("def") }) }) . and_then (| state | { state . repeat (| state | { state . sequence (| state | { super :: hidden :: skip (state) . and_then (| state | { state . sequence (| state | { state . match_string ("abc") . and_then (| state | { super :: hidden :: skip (state) }) . and_then (| state | { state . match_string ("def") }) }) }) }) }) }) }) }) }) }) });
}
}
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册