refactor: move move char consts to widestring

This time, move char constants from `src/expand.rs` to
`fish_widestring`, which resolves a dependency cycle between
`src/expand.rs` and `src/common.rs`.

Part of #12625
This commit is contained in:
Daniel Rainer
2026-04-11 02:29:39 +02:00
committed by Johannes Altmanninger
parent 816077281d
commit c13038b968
7 changed files with 49 additions and 50 deletions

View File

@@ -76,6 +76,33 @@ pub mod prelude {
#[allow(dead_code)]
pub const ANY_SENTINEL: char = char_offset(WILDCARD_RESERVED_BASE, 3);
/// Character representing a home directory.
pub const HOME_DIRECTORY: char = char_offset(EXPAND_RESERVED_BASE, 0);
/// Character representing process expansion for %self.
pub const PROCESS_EXPAND_SELF: char = char_offset(EXPAND_RESERVED_BASE, 1);
/// Character representing variable expansion.
pub const VARIABLE_EXPAND: char = char_offset(EXPAND_RESERVED_BASE, 2);
/// Character representing variable expansion into a single element.
pub const VARIABLE_EXPAND_SINGLE: char = char_offset(EXPAND_RESERVED_BASE, 3);
/// Character representing the start of a bracket expansion.
pub const BRACE_BEGIN: char = char_offset(EXPAND_RESERVED_BASE, 4);
/// Character representing the end of a bracket expansion.
pub const BRACE_END: char = char_offset(EXPAND_RESERVED_BASE, 5);
/// Character representing separation between two bracket elements.
pub const BRACE_SEP: char = char_offset(EXPAND_RESERVED_BASE, 6);
/// Character that takes the place of any whitespace within non-quoted text in braces
pub const BRACE_SPACE: char = char_offset(EXPAND_RESERVED_BASE, 7);
/// Separate subtokens in a token with this character.
pub const INTERNAL_SEPARATOR: char = char_offset(EXPAND_RESERVED_BASE, 8);
/// Character representing an empty variable expansion. Only used transitively while expanding
/// variables.
pub const VARIABLE_EXPAND_EMPTY: char = char_offset(EXPAND_RESERVED_BASE, 9);
const _: () = assert!(
EXPAND_RESERVED_END as u32 > VARIABLE_EXPAND_EMPTY as u32,
"Characters used in expansions must stay within private use area"
);
/// Return true if the character is in a range reserved for fish's private use.
///
/// NOTE: This is used when tokenizing the input. It is also used when reading input, before

View File

@@ -7,7 +7,6 @@
common::{PROGRAM_NAME, get_program_name, unescape_string},
env::{EnvStack, env_init, environment::Environment as _},
err_fmt, err_str,
expand::INTERNAL_SEPARATOR,
global_safety::RelaxedAtomicBool,
highlight::{HighlightRole, HighlightSpec, colorize, highlight_shell},
locale::set_libc_locales,
@@ -26,7 +25,7 @@
use fish_common::{ReadExt as _, UnescapeFlags, UnescapeStringStyle};
use fish_wcstringutil::count_preceding_backslashes;
use fish_wgetopt::{ArgType, WGetopter, WOption, wopt};
use fish_widestring::{bytes2wcstring, osstr2wcstring, wcs2bytes};
use fish_widestring::{INTERNAL_SEPARATOR, bytes2wcstring, osstr2wcstring, wcs2bytes};
use std::{
ffi::OsStr,
fmt::Write as _,

View File

@@ -1,10 +1,7 @@
//! Prototypes for various functions, mostly string utilities, that are used by most parts of fish.
use crate::expand::{
BRACE_BEGIN, BRACE_END, BRACE_SEP, BRACE_SPACE, HOME_DIRECTORY, INTERNAL_SEPARATOR,
PROCESS_EXPAND_SELF, PROCESS_EXPAND_SELF_STR, VARIABLE_EXPAND, VARIABLE_EXPAND_SINGLE,
};
use crate::{
expand::PROCESS_EXPAND_SELF_STR,
global_safety::{AtomicRef, RelaxedAtomicBool},
prelude::*,
terminal::Outputter,
@@ -14,8 +11,10 @@
use fish_fallback::fish_wcwidth;
use fish_feature_flags::{FeatureFlag, feature_test};
use fish_widestring::{
ANY_CHAR, ANY_STRING, ANY_STRING_RECURSIVE, ASCII_MAX, BYTE_MAX, UCS2_MAX, bytes2wcstring,
decode_byte_from_char, fish_reserved_codepoint, subslice_position, wcs2bytes,
ANY_CHAR, ANY_STRING, ANY_STRING_RECURSIVE, ASCII_MAX, BRACE_BEGIN, BRACE_END, BRACE_SEP,
BRACE_SPACE, BYTE_MAX, HOME_DIRECTORY, INTERNAL_SEPARATOR, PROCESS_EXPAND_SELF, UCS2_MAX,
VARIABLE_EXPAND, VARIABLE_EXPAND_SINGLE, bytes2wcstring, decode_byte_from_char,
fish_reserved_codepoint, subslice_position, wcs2bytes,
};
use nix::sys::termios::Termios;
use std::{

View File

@@ -31,8 +31,9 @@
use fish_util::wcsfilecmp_glob;
use fish_wcstringutil::{join_strings, trim};
use fish_widestring::{
ANY_CHAR, ANY_STRING, ANY_STRING_RECURSIVE, EXPAND_RESERVED_BASE, EXPAND_RESERVED_END,
char_offset, osstr2wcstring,
ANY_CHAR, ANY_STRING, ANY_STRING_RECURSIVE, BRACE_BEGIN, BRACE_END, BRACE_SEP, BRACE_SPACE,
HOME_DIRECTORY, INTERNAL_SEPARATOR, PROCESS_EXPAND_SELF, VARIABLE_EXPAND,
VARIABLE_EXPAND_EMPTY, VARIABLE_EXPAND_SINGLE, osstr2wcstring,
};
use nix::unistd::{User, getpid};
@@ -82,33 +83,6 @@ pub struct ExpandFlags : u16 {
}
}
/// Character representing a home directory.
pub const HOME_DIRECTORY: char = char_offset(EXPAND_RESERVED_BASE, 0);
/// Character representing process expansion for %self.
pub const PROCESS_EXPAND_SELF: char = char_offset(EXPAND_RESERVED_BASE, 1);
/// Character representing variable expansion.
pub const VARIABLE_EXPAND: char = char_offset(EXPAND_RESERVED_BASE, 2);
/// Character representing variable expansion into a single element.
pub const VARIABLE_EXPAND_SINGLE: char = char_offset(EXPAND_RESERVED_BASE, 3);
/// Character representing the start of a bracket expansion.
pub const BRACE_BEGIN: char = char_offset(EXPAND_RESERVED_BASE, 4);
/// Character representing the end of a bracket expansion.
pub const BRACE_END: char = char_offset(EXPAND_RESERVED_BASE, 5);
/// Character representing separation between two bracket elements.
pub const BRACE_SEP: char = char_offset(EXPAND_RESERVED_BASE, 6);
/// Character that takes the place of any whitespace within non-quoted text in braces
pub const BRACE_SPACE: char = char_offset(EXPAND_RESERVED_BASE, 7);
/// Separate subtokens in a token with this character.
pub const INTERNAL_SEPARATOR: char = char_offset(EXPAND_RESERVED_BASE, 8);
/// Character representing an empty variable expansion. Only used transitively while expanding
/// variables.
pub const VARIABLE_EXPAND_EMPTY: char = char_offset(EXPAND_RESERVED_BASE, 9);
const _: () = assert!(
EXPAND_RESERVED_END as u32 > VARIABLE_EXPAND_EMPTY as u32,
"Characters used in expansions must stay within private use area"
);
impl ExpandResult {
pub fn new(result: ExpandResultCode) -> Self {
Self { result, status: 0 }

View File

@@ -4,10 +4,7 @@
// and provide them optimistically.
use crate::common::unescape_string;
use crate::{
expand::{
BRACE_BEGIN, BRACE_END, BRACE_SEP, ExpandFlags, HOME_DIRECTORY, INTERNAL_SEPARATOR,
PROCESS_EXPAND_SELF, VARIABLE_EXPAND, VARIABLE_EXPAND_SINGLE, expand_one, expand_tilde,
},
expand::{ExpandFlags, expand_one, expand_tilde},
operation_context::OperationContext,
path::path_apply_working_directory,
redirection::RedirectionMode,
@@ -18,7 +15,11 @@
use fish_wcstringutil::{
string_prefixes_string, string_prefixes_string_case_insensitive, string_suffixes_string,
};
use fish_widestring::{ANY_CHAR, ANY_STRING, ANY_STRING_RECURSIVE, L, WExt as _, WString, wstr};
use fish_widestring::{
ANY_CHAR, ANY_STRING, ANY_STRING_RECURSIVE, BRACE_BEGIN, BRACE_END, BRACE_SEP, HOME_DIRECTORY,
INTERNAL_SEPARATOR, L, PROCESS_EXPAND_SELF, VARIABLE_EXPAND, VARIABLE_EXPAND_SINGLE, WExt as _,
WString, wstr,
};
use libc::PATH_MAX;
use nix::unistd::AccessFlags;
use std::collections::{HashMap, HashSet};

View File

@@ -6,11 +6,7 @@
},
builtins::shared::builtin_exists,
common::{unescape_string, valid_var_name, valid_var_name_char},
expand::{
BRACE_BEGIN, BRACE_END, BRACE_SEP, ExpandFlags, ExpandResultCode, INTERNAL_SEPARATOR,
VARIABLE_EXPAND, VARIABLE_EXPAND_EMPTY, VARIABLE_EXPAND_SINGLE, expand_one,
expand_to_command_and_args,
},
expand::{ExpandFlags, ExpandResultCode, expand_one, expand_to_command_and_args},
operation_context::OperationContext,
parse_constants::{
ERROR_BAD_VAR_CHAR1, ERROR_BRACKETED_VARIABLE_QUOTED1, ERROR_BRACKETED_VARIABLE1,
@@ -29,7 +25,10 @@
use fish_common::{UnescapeFlags, UnescapeStringStyle, help_section};
use fish_feature_flags::{FeatureFlag, feature_test};
use fish_wcstringutil::{count_newlines, truncate};
use fish_widestring::{ANY_CHAR, ANY_STRING, ANY_STRING_RECURSIVE};
use fish_widestring::{
ANY_CHAR, ANY_STRING, ANY_STRING_RECURSIVE, BRACE_BEGIN, BRACE_END, BRACE_SEP,
INTERNAL_SEPARATOR, VARIABLE_EXPAND, VARIABLE_EXPAND_EMPTY, VARIABLE_EXPAND_SINGLE,
};
use std::ops::Range;
use std::{iter, ops};

View File

@@ -3,13 +3,13 @@
//! path-related issues.
use crate::env::{EnvMode, EnvSetMode, EnvStack, Environment, FALLBACK_PATH};
use crate::expand::{HOME_DIRECTORY, expand_tilde};
use crate::expand::expand_tilde;
use crate::flog::{flog, flogf};
use crate::prelude::*;
use crate::wutil::{normalize_path, path_normalize_for_cd, waccess, wdirname, wstat};
use cfg_if::cfg_if;
use errno::{Errno, errno, set_errno};
use fish_widestring::{wcs2osstring, wcs2zstring};
use fish_widestring::{HOME_DIRECTORY, wcs2osstring, wcs2zstring};
use libc::{EACCES, ENOENT, ENOTDIR, X_OK};
use nix::unistd::AccessFlags;
use std::ffi::OsStr;