Skip to content

Commit

Permalink
Apply nightly clippy fixes (#11083)
Browse files Browse the repository at this point in the history
<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx

you can also mention related issues, PRs or discussions!
-->

# Description
<!--
Thank you for improving Nushell. Please, check our [contributing
guide](../CONTRIBUTING.md) and talk to the core team before making major
changes.

Description of your pull request goes here. **Provide examples and/or
screenshots** if your changes affect the user experience.
-->
Clippy fixes for rust 1.76.0-nightly

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

N/A
# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
  • Loading branch information
nibon7 committed Nov 17, 2023
1 parent 5063e01 commit f41c93b
Show file tree
Hide file tree
Showing 25 changed files with 57 additions and 58 deletions.
2 changes: 1 addition & 1 deletion crates/nu-cli/src/completions/completer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl NuCompleter {
let mut callee_stack = stack.gather_captures(&self.engine_state, &block.captures);

// Line
if let Some(pos_arg) = block.signature.required_positional.get(0) {
if let Some(pos_arg) = block.signature.required_positional.first() {
if let Some(var_id) = pos_arg.var_id {
callee_stack.add_var(
var_id,
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-cli/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn gather_env_vars(
let name = if let Some(Token {
contents: TokenContents::Item,
span,
}) = parts.get(0)
}) = parts.first()
{
let mut working_set = StateWorkingSet::new(engine_state);
let bytes = working_set.get_span_contents(*span);
Expand Down
10 changes: 5 additions & 5 deletions crates/nu-cli/tests/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ fn dotnu_completions() {
let suggestions = completer.complete(&completion_str, completion_str.len());

assert_eq!(1, suggestions.len());
assert_eq!("custom_completion.nu", suggestions.get(0).unwrap().value);
assert_eq!("custom_completion.nu", suggestions.first().unwrap().value);

// Test use completion
let completion_str = "use ".to_string();
let suggestions = completer.complete(&completion_str, completion_str.len());

assert_eq!(1, suggestions.len());
assert_eq!("custom_completion.nu", suggestions.get(0).unwrap().value);
assert_eq!("custom_completion.nu", suggestions.first().unwrap().value);
}

#[test]
Expand All @@ -141,7 +141,7 @@ fn external_completer_trailing_space() {

let suggestions = run_external_completion(block, &input);
assert_eq!(3, suggestions.len());
assert_eq!("gh", suggestions.get(0).unwrap().value);
assert_eq!("gh", suggestions.first().unwrap().value);
assert_eq!("alias", suggestions.get(1).unwrap().value);
assert_eq!("", suggestions.get(2).unwrap().value);
}
Expand All @@ -153,7 +153,7 @@ fn external_completer_no_trailing_space() {

let suggestions = run_external_completion(block, &input);
assert_eq!(2, suggestions.len());
assert_eq!("gh", suggestions.get(0).unwrap().value);
assert_eq!("gh", suggestions.first().unwrap().value);
assert_eq!("alias", suggestions.get(1).unwrap().value);
}

Expand All @@ -164,7 +164,7 @@ fn external_completer_pass_flags() {

let suggestions = run_external_completion(block, &input);
assert_eq!(3, suggestions.len());
assert_eq!("gh", suggestions.get(0).unwrap().value);
assert_eq!("gh", suggestions.first().unwrap().value);
assert_eq!("api", suggestions.get(1).unwrap().value);
assert_eq!("--", suggestions.get(2).unwrap().value);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-cmd-dataframe/src/dataframe/eager/drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?;

let new_df = col_string
.get(0)
.first()
.ok_or_else(|| {
ShellError::GenericError(
"Empty names list".into(),
Expand Down
6 changes: 3 additions & 3 deletions crates/nu-cmd-dataframe/src/dataframe/eager/sql_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ impl SQLContext {
fn execute_select(&self, select_stmt: &Select) -> Result<LazyFrame, PolarsError> {
// Determine involved dataframe
// Implicit join require some more work in query parsers, Explicit join are preferred for now.
let tbl = select_stmt.from.get(0).ok_or_else(|| {
let tbl = select_stmt.from.first().ok_or_else(|| {
PolarsError::ComputeError(ErrString::from("No table found in select statement"))
})?;
let mut alias_map = HashMap::new();
let tbl_name = match &tbl.relation {
TableFactor::Table { name, alias, .. } => {
let tbl_name = name
.0
.get(0)
.first()
.ok_or_else(|| {
PolarsError::ComputeError(ErrString::from(
"No table found in select statement",
Expand Down Expand Up @@ -182,7 +182,7 @@ impl SQLContext {
))
} else {
let ast = ast
.get(0)
.first()
.ok_or_else(|| PolarsError::ComputeError(ErrString::from("No statement found")))?;
Ok(match ast {
Statement::Query(query) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ impl NuDataFrame {
let series = self
.df
.get_columns()
.get(0)
.first()
.expect("We have already checked that the width is 1");

Ok(series.clone())
Expand Down
4 changes: 2 additions & 2 deletions crates/nu-cmd-dataframe/src/dataframe/values/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub(crate) fn convert_columns(
) -> Result<(Vec<Spanned<String>>, Span), ShellError> {
// First column span
let mut col_span = columns
.get(0)
.first()
.ok_or_else(|| {
ShellError::GenericError(
"Empty column list".into(),
Expand Down Expand Up @@ -54,7 +54,7 @@ pub(crate) fn convert_columns_string(
) -> Result<(Vec<String>, Span), ShellError> {
// First column span
let mut col_span = columns
.get(0)
.first()
.ok_or_else(|| {
ShellError::GenericError(
"Empty column list".into(),
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/filters/group_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ fn group_closure(
));
}

let value = match collection.get(0) {
let value = match collection.first() {
Some(Value::Error { .. }) | None => Value::string(error_key, span),
Some(return_value) => return_value.clone(),
};
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/filters/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ fn insert(
ctrlc,
)
} else {
if let Some(PathMember::Int { val, .. }) = cell_path.members.get(0) {
if let Some(PathMember::Int { val, .. }) = cell_path.members.first() {
let mut input = input.into_iter();
let mut pre_elems = vec![];

Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/filters/reject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ fn reject(
let mut new_rows = vec![];
for column in cell_paths {
let CellPath { ref members } = column;
match members.get(0) {
match members.first() {
Some(PathMember::Int { val, span, .. }) => {
if members.len() > 1 {
return Err(ShellError::GenericError(
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/filters/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ fn select(

for column in columns {
let CellPath { ref members } = column;
match members.get(0) {
match members.first() {
Some(PathMember::Int { val, span, .. }) => {
if members.len() > 1 {
return Err(ShellError::GenericError(
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/filters/transpose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub fn transpose(

if args.header_row {
for i in input.iter() {
if let Some(desc) = descs.get(0) {
if let Some(desc) = descs.first() {
match &i.get_data_by_key(desc) {
Some(x) => {
if let Ok(s) = x.as_string() {
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/filters/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ fn update(
)?
.set_metadata(mdclone))
} else {
if let Some(PathMember::Int { val, span, .. }) = cell_path.members.get(0) {
if let Some(PathMember::Int { val, span, .. }) = cell_path.members.first() {
let mut input = input.into_iter();
let mut pre_elems = vec![];

Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/filters/upsert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ fn upsert(
ctrlc,
)
} else {
if let Some(PathMember::Int { val, span, .. }) = cell_path.members.get(0) {
if let Some(PathMember::Int { val, span, .. }) = cell_path.members.first() {
let mut input = input.into_iter();
let mut pre_elems = vec![];

Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/formats/from/nuon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Command for FromNuon {
let mut block = nu_parser::parse(&mut working_set, None, string_input.as_bytes(), false);

if let Some(pipeline) = block.pipelines.get(1) {
if let Some(element) = pipeline.elements.get(0) {
if let Some(element) = pipeline.elements.first() {
return Err(ShellError::GenericError(
"error when loading nuon text".into(),
"could not load nuon text".into(),
Expand Down
4 changes: 2 additions & 2 deletions crates/nu-command/src/math/reducers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub fn min(data: Vec<Value>, span: Span, head: Span) -> Result<Value, ShellError
}

pub fn sum(data: Vec<Value>, span: Span, head: Span) -> Result<Value, ShellError> {
let initial_value = data.get(0);
let initial_value = data.first();

let mut acc = match initial_value {
Some(v) => {
Expand Down Expand Up @@ -124,7 +124,7 @@ pub fn sum(data: Vec<Value>, span: Span, head: Span) -> Result<Value, ShellError
}

pub fn product(data: Vec<Value>, span: Span, head: Span) -> Result<Value, ShellError> {
let initial_value = data.get(0);
let initial_value = data.first();

let mut acc = match initial_value {
Some(v) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-explore/src/nu_common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub use nu_protocol::{Config as NuConfig, Span as NuSpan};
pub type NuText = (String, TextStyle);
pub type CtrlC = Option<Arc<AtomicBool>>;

pub use command::{is_ignored_command, run_command_with_value, run_nu_command};
pub use command::run_command_with_value;
pub use lscolor::{create_lscolors, lscolorize};
pub use string::{string_width, truncate_str};
pub use table::try_build_table;
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-explore/src/views/record/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ fn build_table_as_record(v: &RecordView) -> Value {
let layer = v.get_layer_last();

let cols = layer.columns.to_vec();
let vals = layer.records.get(0).map_or(Vec::new(), |row| row.clone());
let vals = layer.records.first().map_or(Vec::new(), |row| row.clone());

Value::record(Record::from_raw_cols_vals(cols, vals), NuSpan::unknown())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-json/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn main() {

// Extract the array
let array : &mut Vec<Value> = sample.get_mut("array").unwrap().as_array_mut().unwrap();
println!("first: {}", array.get(0).unwrap());
println!("first: {}", array.first().unwrap());

// Add a value
array.push(Value::String("tak".to_string()));
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl LanguageServer {
engine_state: EngineState,
ctrlc: Arc<AtomicBool>,
) -> Result<()> {
let server_capabilities = serde_json::to_value(&ServerCapabilities {
let server_capabilities = serde_json::to_value(ServerCapabilities {
text_document_sync: Some(lsp_types::TextDocumentSyncCapability::Kind(
TextDocumentSyncKind::INCREMENTAL,
)),
Expand Down
22 changes: 11 additions & 11 deletions crates/nu-parser/src/parse_keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ pub const UNALIASABLE_PARSER_KEYWORDS: &[&[u8]] = &[
/// Check whether spans start with a parser keyword that can be aliased
pub fn is_unaliasable_parser_keyword(working_set: &StateWorkingSet, spans: &[Span]) -> bool {
// try two words
if let (Some(span1), Some(span2)) = (spans.get(0), spans.get(1)) {
if let (Some(span1), Some(span2)) = (spans.first(), spans.get(1)) {
let cmd_name = working_set.get_span_contents(span(&[*span1, *span2]));
return UNALIASABLE_PARSER_KEYWORDS.contains(&cmd_name);
}

// try one word
if let Some(span1) = spans.get(0) {
if let Some(span1) = spans.first() {
let cmd_name = working_set.get_span_contents(*span1);
UNALIASABLE_PARSER_KEYWORDS.contains(&cmd_name)
} else {
Expand Down Expand Up @@ -653,7 +653,7 @@ pub fn parse_extern(

let (command_spans, rest_spans) = spans.split_at(split_id);

if let Some(name_span) = rest_spans.get(0) {
if let Some(name_span) = rest_spans.first() {
if let Some(err) = detect_params_in_name(
working_set,
*name_span,
Expand Down Expand Up @@ -1135,7 +1135,7 @@ pub fn parse_export_in_module(
) -> (Pipeline, Vec<Exportable>) {
let spans = &lite_command.parts[..];

let export_span = if let Some(sp) = spans.get(0) {
let export_span = if let Some(sp) = spans.first() {
if working_set.get_span_contents(*sp) != b"export" {
working_set.error(ParseError::UnknownState(
"expected export statement".into(),
Expand Down Expand Up @@ -1209,7 +1209,7 @@ pub fn parse_export_in_module(
expr: Expr::Call(ref def_call),
..
},
)) = pipeline.elements.get(0)
)) = pipeline.elements.first()
{
call = def_call.clone();

Expand Down Expand Up @@ -1249,7 +1249,7 @@ pub fn parse_export_in_module(
expr: Expr::Call(ref def_call),
..
},
)) = pipeline.elements.get(0)
)) = pipeline.elements.first()
{
call = def_call.clone();

Expand Down Expand Up @@ -1310,7 +1310,7 @@ pub fn parse_export_in_module(
expr: Expr::Call(ref def_call),
..
},
)) = pipeline.elements.get(0)
)) = pipeline.elements.first()
{
call = def_call.clone();

Expand Down Expand Up @@ -1370,7 +1370,7 @@ pub fn parse_export_in_module(
expr: Expr::Call(ref alias_call),
..
},
)) = pipeline.elements.get(0)
)) = pipeline.elements.first()
{
call = alias_call.clone();

Expand Down Expand Up @@ -1429,7 +1429,7 @@ pub fn parse_export_in_module(
expr: Expr::Call(ref use_call),
..
},
)) = pipeline.elements.get(0)
)) = pipeline.elements.first()
{
call = use_call.clone();

Expand Down Expand Up @@ -1466,7 +1466,7 @@ pub fn parse_export_in_module(
expr: Expr::Call(ref module_call),
..
},
)) = pipeline.elements.get(0)
)) = pipeline.elements.first()
{
call = module_call.clone();

Expand Down Expand Up @@ -1523,7 +1523,7 @@ pub fn parse_export_in_module(
expr: Expr::Call(ref def_call),
..
},
)) = pipeline.elements.get(0)
)) = pipeline.elements.first()
{
call = def_call.clone();

Expand Down
6 changes: 3 additions & 3 deletions crates/nu-parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1572,10 +1572,10 @@ pub fn parse_brace_expr(
let (tokens, _) = lex(bytes, span.start + 1, &[b'\r', b'\n', b'\t'], &[b':'], true);

let second_token = tokens
.get(0)
.first()
.map(|token| working_set.get_span_contents(token.span));

let second_token_contents = tokens.get(0).map(|token| token.contents);
let second_token_contents = tokens.first().map(|token| token.contents);

let third_token = tokens
.get(1)
Expand Down Expand Up @@ -2666,7 +2666,7 @@ pub fn parse_string_strict(working_set: &mut StateWorkingSet, span: Span) -> Exp
}

pub fn parse_import_pattern(working_set: &mut StateWorkingSet, spans: &[Span]) -> Expression {
let Some(head_span) = spans.get(0) else {
let Some(head_span) = spans.first() else {
working_set.error(ParseError::WrongImportPattern(
"needs at least one component of import pattern".to_string(),
span(spans),
Expand Down
Loading

0 comments on commit f41c93b

Please sign in to comment.