Skip to content

Commit

Permalink
chore: upgrade to Rust 1.59 (denoland#13767)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Feb 25, 2022
1 parent c59152e commit 3b12afd
Show file tree
Hide file tree
Showing 31 changed files with 114 additions and 167 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ jobs:
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
key: 3-cargo-home-${{ matrix.os }}-${{ hashFiles('Cargo.lock') }}
key: 4-cargo-home-${{ matrix.os }}-${{ hashFiles('Cargo.lock') }}

# In main branch, always creates fresh cache
- name: Cache build output (main)
Expand All @@ -275,7 +275,7 @@ jobs:
!./target/*/*.zip
!./target/*/*.tar.gz
key: |
3-cargo-target-${{ matrix.os }}-${{ matrix.profile }}-${{ github.sha }}
4-cargo-target-${{ matrix.os }}-${{ matrix.profile }}-${{ github.sha }}
# Restore cache from the latest 'main' branch build.
- name: Cache build output (PR)
Expand All @@ -291,7 +291,7 @@ jobs:
!./target/*/*.tar.gz
key: never_saved
restore-keys: |
3-cargo-target-${{ matrix.os }}-${{ matrix.profile }}-
4-cargo-target-${{ matrix.os }}-${{ matrix.profile }}-
# Don't save cache after building PRs or branches other than 'main'.
- name: Skip save cache (PR)
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ libc = "=0.2.106"
log = { version = "=0.4.14", features = ["serde"] }
lspower = "=1.4.0"
notify = "=5.0.0-pre.12"
num_cpus = "=1.13.0"
once_cell = "=1.9.0"
percent-encoding = "=2.1.0"
pin-project = "=1.0.8"
Expand Down
3 changes: 1 addition & 2 deletions cli/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ impl Cacher for FetchCacher {
.disk_cache
.get(&filename)
.ok()
.map(|b| String::from_utf8(b).ok())
.flatten()
.and_then(|b| String::from_utf8(b).ok())
}

fn set(
Expand Down
2 changes: 1 addition & 1 deletion cli/compat/esm_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ fn resolve_package_target_string(

if invalid_segment_re.is_match(&subpath) {
let request = if pattern {
match_.replace("*", &subpath)
match_.replace('*', &subpath)
} else {
format!("{}{}", match_, subpath)
};
Expand Down
2 changes: 1 addition & 1 deletion cli/compat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub(crate) fn add_global_require(
}

fn escape_for_single_quote_string(text: &str) -> String {
text.replace(r"\", r"\\").replace("'", r"\'")
text.replace('\\', r"\\").replace('\'', r"\'")
}

pub fn setup_builtin_modules(
Expand Down
3 changes: 1 addition & 2 deletions cli/config_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,7 @@ impl ConfigFile {
.json
.compiler_options
.as_ref()
.map(|co| co.get("checkJs").map(|v| v.as_bool()).flatten())
.flatten()
.and_then(|co| co.get("checkJs").and_then(|v| v.as_bool()))
.unwrap_or(false)
}

Expand Down
2 changes: 1 addition & 1 deletion cli/disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl DiskCache {
| Prefix::VerbatimUNC(server, share) => {
out.push("UNC");
let host = Host::parse(server.to_str().unwrap()).unwrap();
let host = host.to_string().replace(":", "_");
let host = host.to_string().replace(':', "_");
out.push(host);
out.push(share);
}
Expand Down
4 changes: 2 additions & 2 deletions cli/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2232,8 +2232,8 @@ fn test_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
if let Some(value) = matches.value_of("jobs") {
value.parse().unwrap()
} else {
// TODO(caspervonb) drop the dependency on num_cpus when https://doc.rust-lang.org/std/thread/fn.available_concurrency.html becomes stable.
NonZeroUsize::new(num_cpus::get()).unwrap()
std::thread::available_parallelism()
.unwrap_or(NonZeroUsize::new(1).unwrap())
}
} else {
NonZeroUsize::new(1).unwrap()
Expand Down
19 changes: 7 additions & 12 deletions cli/lsp/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,10 @@ impl CacheServer {
.unwrap();
let maybe_import_map_resolver =
maybe_import_map.map(ImportMapResolver::new);
let maybe_jsx_resolver = maybe_config_file
.as_ref()
.map(|cf| {
cf.to_maybe_jsx_import_source_module()
.map(|im| JsxResolver::new(im, maybe_import_map_resolver.clone()))
})
.flatten();
let maybe_jsx_resolver = maybe_config_file.as_ref().and_then(|cf| {
cf.to_maybe_jsx_import_source_module()
.map(|im| JsxResolver::new(im, maybe_import_map_resolver.clone()))
});
let maybe_resolver = if maybe_jsx_resolver.is_some() {
maybe_jsx_resolver.as_ref().map(|jr| jr.as_resolver())
} else {
Expand All @@ -76,8 +73,7 @@ impl CacheServer {
.map(|im| im.as_resolver())
};
let maybe_imports = maybe_config_file
.map(|cf| cf.to_maybe_imports().ok())
.flatten()
.and_then(|cf| cf.to_maybe_imports().ok())
.flatten();
let mut cache = FetchCacher::new(
ps.dir.gen_cache.clone(),
Expand Down Expand Up @@ -187,10 +183,9 @@ impl CacheMetadata {
let version = self
.cache
.get_cache_filename(specifier)
.map(|ref path| calculate_fs_version(path))
.flatten();
.and_then(|ref path| calculate_fs_version(path));
let metadata = self.metadata.lock().get(specifier).cloned();
if metadata.as_ref().map(|m| m.version.clone()).flatten() != version {
if metadata.as_ref().and_then(|m| m.version.clone()) != version {
self.refresh(specifier).map(|m| m.values)
} else {
metadata.map(|m| m.values)
Expand Down
6 changes: 2 additions & 4 deletions cli/lsp/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,7 @@ async fn generate_ts_diagnostics(
let version = snapshot
.documents
.get(&specifier)
.map(|d| d.maybe_lsp_version())
.flatten();
.and_then(|d| d.maybe_lsp_version());
// check if the specifier is enabled again just in case TS returns us
// diagnostics for a disabled specifier
let ts_diagnostics = if config.specifier_enabled(&specifier) {
Expand All @@ -555,8 +554,7 @@ async fn generate_ts_diagnostics(
let version = snapshot
.documents
.get(&specifier)
.map(|d| d.maybe_lsp_version())
.flatten();
.and_then(|d| d.maybe_lsp_version());
diagnostics_vec.push((specifier, version, Vec::new()));
}
Ok(diagnostics_vec)
Expand Down
37 changes: 15 additions & 22 deletions cli/lsp/documents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,17 @@ impl AssetOrDocument {
) -> Option<(String, deno_graph::Dependency, deno_graph::Range)> {
self
.document()
.map(|d| d.get_maybe_dependency(position))
.flatten()
.and_then(|d| d.get_maybe_dependency(position))
}

pub fn maybe_parsed_source(
&self,
) -> Option<Result<deno_ast::ParsedSource, deno_graph::ModuleGraphError>> {
self.document().map(|d| d.maybe_parsed_source()).flatten()
self.document().and_then(|d| d.maybe_parsed_source())
}

pub fn document_lsp_version(&self) -> Option<i32> {
self.document().map(|d| d.maybe_lsp_version()).flatten()
self.document().and_then(|d| d.maybe_lsp_version())
}
}

Expand Down Expand Up @@ -347,8 +346,7 @@ impl Document {
.0
.maybe_language_id
.as_ref()
.map(|li| li.as_headers())
.flatten();
.and_then(|li| li.as_headers());
let parser = SourceParser::default();
Some(deno_graph::parse_module(
&self.0.specifier,
Expand Down Expand Up @@ -865,8 +863,7 @@ impl Documents {
} else {
let mut file_system_docs = self.file_system_docs.lock();
let fs_version = get_document_path(&self.cache, &specifier)
.map(|path| calculate_fs_version(&path))
.flatten();
.and_then(|path| calculate_fs_version(&path));
let file_system_doc = file_system_docs.docs.get(&specifier);
if file_system_doc.map(|d| d.fs_version().to_string()) != fs_version {
// attempt to update the file on the file system
Expand Down Expand Up @@ -1009,12 +1006,10 @@ impl Documents {
) {
// TODO(@kitsonk) update resolved dependencies?
self.maybe_import_map = maybe_import_map.map(ImportMapResolver::new);
self.maybe_jsx_resolver = maybe_config_file
.map(|cf| {
cf.to_maybe_jsx_import_source_module()
.map(|im| JsxResolver::new(im, self.maybe_import_map.clone()))
})
.flatten();
self.maybe_jsx_resolver = maybe_config_file.and_then(|cf| {
cf.to_maybe_jsx_import_source_module()
.map(|im| JsxResolver::new(im, self.maybe_import_map.clone()))
});
self.imports = Arc::new(
if let Some(Ok(Some(imports))) =
maybe_config_file.map(|cf| cf.to_maybe_imports())
Expand Down Expand Up @@ -1094,14 +1089,12 @@ impl Documents {
specifier: &ModuleSpecifier,
) -> Option<(ModuleSpecifier, MediaType)> {
let doc = self.get(specifier)?;
let maybe_module = doc.maybe_module().map(|r| r.as_ref().ok()).flatten();
let maybe_types_dependency = maybe_module
.map(|m| {
m.maybe_types_dependency
.as_ref()
.map(|(_, resolved)| resolved.clone())
})
.flatten();
let maybe_module = doc.maybe_module().and_then(|r| r.as_ref().ok());
let maybe_types_dependency = maybe_module.and_then(|m| {
m.maybe_types_dependency
.as_ref()
.map(|(_, resolved)| resolved.clone())
});
if let Some(Resolved::Ok { specifier, .. }) = maybe_types_dependency {
self.resolve_dependency(&specifier)
} else {
Expand Down
14 changes: 5 additions & 9 deletions cli/lsp/language_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,8 +870,7 @@ impl Inner {
params
.settings
.as_object()
.map(|settings| settings.get(SETTINGS_SECTION))
.flatten()
.and_then(|settings| settings.get(SETTINGS_SECTION))
.cloned()
};

Expand Down Expand Up @@ -1075,8 +1074,7 @@ impl Inner {
{
let dep_maybe_types_dependency = dep
.get_code()
.map(|s| self.documents.get(s))
.flatten()
.and_then(|s| self.documents.get(s))
.map(|d| d.maybe_types_dependency());
let value = match (dep.maybe_code.is_none(), dep.maybe_type.is_none(), &dep_maybe_types_dependency) {
(false, false, None) => format!(
Expand Down Expand Up @@ -1242,7 +1240,7 @@ impl Inner {
&specifier,
diagnostic,
asset_or_doc.document().map(|d| d.text_info()),
asset_or_doc.maybe_parsed_source().map(|r| r.ok()).flatten(),
asset_or_doc.maybe_parsed_source().and_then(|r| r.ok()),
)
.map_err(|err| {
error!("Unable to fix lint error: {}", err);
Expand Down Expand Up @@ -1426,8 +1424,7 @@ impl Inner {
error!("Error getting code lenses for \"{}\": {}", specifier, err);
LspError::internal_error()
})?;
let parsed_source =
asset_or_doc.maybe_parsed_source().map(|r| r.ok()).flatten();
let parsed_source = asset_or_doc.maybe_parsed_source().and_then(|r| r.ok());
let line_index = asset_or_doc.line_index();
let code_lenses = code_lens::collect(
&specifier,
Expand Down Expand Up @@ -1501,8 +1498,7 @@ impl Inner {
if let Some(document_highlights) = maybe_document_highlights {
let result = document_highlights
.into_iter()
.map(|dh| dh.to_highlight(line_index.clone()))
.flatten()
.flat_map(|dh| dh.to_highlight(line_index.clone()))
.collect();
self.performance.measure(mark);
Ok(Some(result))
Expand Down
6 changes: 2 additions & 4 deletions cli/lsp/tsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1402,9 +1402,7 @@ impl FileTextChanges {
ops.push(lsp::DocumentChangeOperation::Edit(lsp::TextDocumentEdit {
text_document: lsp::OptionalVersionedTextDocumentIdentifier {
uri: specifier.clone(),
version: maybe_asset_or_document
.map(|d| d.document_lsp_version())
.flatten(),
version: maybe_asset_or_document.and_then(|d| d.document_lsp_version()),
},
edits,
}));
Expand Down Expand Up @@ -2064,7 +2062,7 @@ impl CompletionEntry {
return Some(insert_text.clone());
}
} else {
return Some(self.name.replace("#", ""));
return Some(self.name.replace('#', ""));
}
}

Expand Down
Loading

0 comments on commit 3b12afd

Please sign in to comment.