Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/base_db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,8 @@ impl fmt::Display for CyclicDependenciesError {
write!(
f,
"cyclic deps: {} -> {}, alternative path: {}",
render(&self.from()),
render(&self.to()),
render(self.from()),
render(self.to()),
path
)
}
Expand Down
7 changes: 1 addition & 6 deletions crates/flycheck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,7 @@ impl CargoActor {
cargo_metadata::Message::CompilerMessage(msg) => {
self.sender.send(CargoMessage::Diagnostic(msg.message)).unwrap()
}

cargo_metadata::Message::CompilerArtifact(_)
| cargo_metadata::Message::BuildScriptExecuted(_)
| cargo_metadata::Message::BuildFinished(_)
| cargo_metadata::Message::TextLine(_)
| _ => (),
_ => (),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine, it makes sense, but the default branch was a bit weird (we might want to know if new message types are added).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well we won't know that though because due to non exhaustiveness we have to use a wildcard no matter what

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's was an "ugh" for the old code, not for your change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upstream added non-exhaustive, that's why we need this here. Last weekend I almost got to prototyping miniserde-based cargo data to have more control over this :-)

},
JsonMessage::Rustc(message) => {
self.sender.send(CargoMessage::Diagnostic(message)).unwrap()
Expand Down
6 changes: 3 additions & 3 deletions crates/hir/src/has_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ impl HasSource for Adt {
type Ast = ast::Adt;
fn source(self, db: &dyn HirDatabase) -> Option<InFile<Self::Ast>> {
match self {
Adt::Struct(s) => Some(s.source(db)?.map(|s| ast::Adt::Struct(s))),
Adt::Union(u) => Some(u.source(db)?.map(|u| ast::Adt::Union(u))),
Adt::Enum(e) => Some(e.source(db)?.map(|e| ast::Adt::Enum(e))),
Adt::Struct(s) => Some(s.source(db)?.map(ast::Adt::Struct)),
Adt::Union(u) => Some(u.source(db)?.map(ast::Adt::Union)),
Adt::Enum(e) => Some(e.source(db)?.map(ast::Adt::Enum)),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2960,9 +2960,9 @@ impl ScopeDef {
impl From<ItemInNs> for ScopeDef {
fn from(item: ItemInNs) -> Self {
match item {
ItemInNs::Types(id) => ScopeDef::ModuleDef(id.into()),
ItemInNs::Values(id) => ScopeDef::ModuleDef(id.into()),
ItemInNs::Macros(id) => ScopeDef::MacroDef(id.into()),
ItemInNs::Types(id) => ScopeDef::ModuleDef(id),
ItemInNs::Values(id) => ScopeDef::ModuleDef(id),
ItemInNs::Macros(id) => ScopeDef::MacroDef(id),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/hir/src/semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ impl<'db> SemanticsImpl<'db> {
}

fn is_unsafe_ident_pat(&self, ident_pat: &ast::IdentPat) -> bool {
if !ident_pat.ref_token().is_some() {
if ident_pat.ref_token().is_none() {
return false;
}

Expand Down
3 changes: 1 addition & 2 deletions crates/hir_def/src/item_tree/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,7 @@ impl<'a> Ctx<'a> {
let name = Name::new_tuple_field(idx);
let visibility = self.lower_visibility(field);
let type_ref = self.lower_type_ref_opt(field.ty());
let res = Field { name, type_ref, visibility };
res
Field { name, type_ref, visibility }
}

fn lower_union(&mut self, union: &ast::Union) -> Option<FileItemTreeId<Union>> {
Expand Down
25 changes: 12 additions & 13 deletions crates/hir_def/src/nameres/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ impl DefCollector<'_> {
self.unresolved_imports.extend(partial_resolved);
self.resolve_imports();

let unresolved_imports = std::mem::replace(&mut self.unresolved_imports, Vec::new());
let unresolved_imports = std::mem::take(&mut self.unresolved_imports);
// show unresolved imports in completion, etc
for directive in &unresolved_imports {
self.record_resolved_import(directive)
Expand Down Expand Up @@ -417,7 +417,7 @@ impl DefCollector<'_> {
fn reseed_with_unresolved_attribute(&mut self) -> ReachedFixedPoint {
cov_mark::hit!(unresolved_attribute_fallback);

let mut unresolved_macros = std::mem::replace(&mut self.unresolved_macros, Vec::new());
let mut unresolved_macros = std::mem::take(&mut self.unresolved_macros);
let pos = unresolved_macros.iter().position(|directive| {
if let MacroDirectiveKind::Attr { ast_id, mod_item, attr } = &directive.kind {
self.skip_attrs.insert(ast_id.ast_id.with_value(*mod_item), attr.id);
Expand Down Expand Up @@ -689,7 +689,7 @@ impl DefCollector<'_> {
/// Tries to resolve every currently unresolved import.
fn resolve_imports(&mut self) -> ReachedFixedPoint {
let mut res = ReachedFixedPoint::Yes;
let imports = std::mem::replace(&mut self.unresolved_imports, Vec::new());
let imports = std::mem::take(&mut self.unresolved_imports);
let imports = imports
.into_iter()
.filter_map(|mut directive| {
Expand Down Expand Up @@ -1005,7 +1005,7 @@ impl DefCollector<'_> {
}

fn resolve_macros(&mut self) -> ReachedFixedPoint {
let mut macros = std::mem::replace(&mut self.unresolved_macros, Vec::new());
let mut macros = std::mem::take(&mut self.unresolved_macros);
let mut resolved = Vec::new();
let mut res = ReachedFixedPoint::Yes;
macros.retain(|directive| {
Expand Down Expand Up @@ -1279,13 +1279,12 @@ impl DefCollector<'_> {

for directive in &self.unresolved_imports {
if let ImportSource::Import { id: import, use_tree } = &directive.import.source {
match (directive.import.path.segments().first(), &directive.import.path.kind) {
(Some(krate), PathKind::Plain | PathKind::Abs) => {
if diagnosed_extern_crates.contains(krate) {
continue;
}
if let (Some(krate), PathKind::Plain | PathKind::Abs) =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was intentional.

Copy link
Member Author

@Veykril Veykril Sep 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how so? It doesn't really change the nesting level, though on another note match + if guard seems like the proper way here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this isn't an if let ... {} else {}, just an if let

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that was indeed intentional -- multiline conditions are not readable. In

if let (Some(krate), PathKind::Plain | PathKind::Abs) =
    (directive.import.path.segments().first(), &directive.import.path.kind)

you need to read a lot to understand what the heck are you even matching. With match, scrutinee comes first, which I personally find easier on the eyes: pattern in isolation doesn't make much sense, it only is meaningful with respect to a specific expression you pattern match.

But no strong opinion here!

(directive.import.path.segments().first(), &directive.import.path.kind)
{
if diagnosed_extern_crates.contains(krate) {
continue;
}
_ => {}
}

self.def_map.diagnostics.push(DefDiagnostic::unresolved_import(
Expand Down Expand Up @@ -1579,13 +1578,13 @@ impl ModCollector<'_, '_> {
{
Ok((file_id, is_mod_rs, mod_dir)) => {
let item_tree = db.file_item_tree(file_id.into());
if item_tree
let is_enabled = item_tree
.top_level_attrs(db, self.def_collector.def_map.krate)
.cfg()
.map_or(true, |cfg| {
self.def_collector.cfg_options.check(&cfg) != Some(false)
})
{
});
if is_enabled {
let module_id = self.push_child_module(
module.name.clone(),
ast_id,
Expand Down
2 changes: 1 addition & 1 deletion crates/hir_expand/src/eager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub fn expand_eager_macro(
mut diagnostic_sink: &mut dyn FnMut(mbe::ExpandError),
) -> Result<MacroCallId, ErrorEmitted> {
let parsed_args = diagnostic_sink.option_with(
|| Some(mbe::syntax_node_to_token_tree(&macro_call.value.token_tree()?.syntax()).0),
|| Some(mbe::syntax_node_to_token_tree(macro_call.value.token_tree()?.syntax()).0),
|| err("malformed macro invocation"),
)?;

Expand Down
9 changes: 3 additions & 6 deletions crates/hir_ty/src/chalk_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
let (datas, binders) = (*datas).as_ref().into_value_and_skipped_binders();
let data = &datas.impl_traits[idx as usize];
let bound = OpaqueTyDatumBound {
bounds: make_only_type_binders(
1,
data.bounds.skip_binders().iter().cloned().collect(),
),
bounds: make_only_type_binders(1, data.bounds.skip_binders().to_vec()),
where_clauses: make_only_type_binders(0, vec![]),
};
chalk_ir::Binders::new(binders, bound)
Expand Down Expand Up @@ -309,7 +306,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
let sig_ty = substs.at(&Interner, 0).assert_ty_ref(&Interner).clone();
let sig = &sig_ty.callable_sig(self.db).expect("first closure param should be fn ptr");
let io = rust_ir::FnDefInputsAndOutputDatum {
argument_types: sig.params().iter().cloned().collect(),
argument_types: sig.params().to_vec(),
return_type: sig.ret().clone(),
};
make_only_type_binders(0, io.shifted_in(&Interner))
Expand Down Expand Up @@ -675,7 +672,7 @@ pub(crate) fn fn_def_datum_query(
inputs_and_output: make_only_type_binders(
0,
rust_ir::FnDefInputsAndOutputDatum {
argument_types: sig.params().iter().cloned().collect(),
argument_types: sig.params().to_vec(),
return_type: sig.ret().clone(),
}
.shifted_in(&Interner),
Expand Down
2 changes: 1 addition & 1 deletion crates/hir_ty/src/chalk_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl TyExt for Ty {
let substs = TyBuilder::type_params_subst(db, id.parent);
let predicates = db
.generic_predicates(id.parent)
.into_iter()
.iter()
.map(|pred| pred.clone().substitute(&Interner, &substs))
.filter(|wc| match &wc.skip_binders() {
WhereClause::Implemented(tr) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/hir_ty/src/diagnostics/decl_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl<'a> DeclValidator<'a> {
ModuleDefId::AdtId(adt) => self.validate_adt(adt),
ModuleDefId::ConstId(const_id) => self.validate_const(const_id),
ModuleDefId::StaticId(static_id) => self.validate_static(static_id),
_ => return,
_ => (),
}
}

Expand Down
24 changes: 10 additions & 14 deletions crates/hir_ty/src/diagnostics/match_check/deconstruct_pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ pub(super) struct IntRange {
impl IntRange {
#[inline]
fn is_integral(ty: &Ty) -> bool {
match ty.kind(&Interner) {
TyKind::Scalar(Scalar::Char | Scalar::Int(_) | Scalar::Uint(_) | Scalar::Bool) => true,
_ => false,
}
matches!(
ty.kind(&Interner),
TyKind::Scalar(Scalar::Char | Scalar::Int(_) | Scalar::Uint(_) | Scalar::Bool)
)
}

fn is_singleton(&self) -> bool {
Expand Down Expand Up @@ -729,16 +729,12 @@ impl Fields {
})
.collect();

if let Some((adt, substs)) = pcx.ty.as_adt() {
if let hir_def::AdtId::EnumId(_) = adt {
let enum_variant = match ctor {
&Variant(id) => id,
_ => unreachable!(),
};
PatKind::Variant { substs: substs.clone(), enum_variant, subpatterns }
} else {
PatKind::Leaf { subpatterns }
}
if let Some((hir_def::AdtId::EnumId(_), substs)) = pcx.ty.as_adt() {
let enum_variant = match ctor {
&Variant(id) => id,
_ => unreachable!(),
};
PatKind::Variant { substs: substs.clone(), enum_variant, subpatterns }
} else {
PatKind::Leaf { subpatterns }
}
Expand Down
6 changes: 3 additions & 3 deletions crates/hir_ty/src/diagnostics/match_check/usefulness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,17 +686,17 @@ impl SubPatSet {
SubPatSet::Empty => panic!("bug"),
SubPatSet::Full => {}
SubPatSet::Seq { subpats } => {
for (_, sub_set) in subpats {
for sub_set in subpats.values() {
fill_subpats(sub_set, unreachable_pats, cx);
}
}
SubPatSet::Alt { subpats, pat, alt_count, .. } => {
let expanded = pat.expand_or_pat(cx);
for i in 0..*alt_count {
for (i, &expanded) in expanded.iter().enumerate().take(*alt_count) {
let sub_set = subpats.get(&i).unwrap_or(&SubPatSet::Empty);
if sub_set.is_empty() {
// Found an unreachable subpattern.
unreachable_pats.push(expanded[i]);
unreachable_pats.push(expanded);
} else {
fill_subpats(sub_set, unreachable_pats, cx);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/hir_ty/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ impl HirDisplay for Ty {
let substs = generics.type_params_subst(f.db);
let bounds =
f.db.generic_predicates(id.parent)
.into_iter()
.iter()
.map(|pred| pred.clone().substitute(&Interner, &substs))
.filter(|wc| match &wc.skip_binders() {
WhereClause::Implemented(tr) => {
Expand Down
58 changes: 25 additions & 33 deletions crates/hir_ty/src/infer/closure.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Inference of closure parameter types based on the closure's expected type.

use chalk_ir::{cast::Cast, AliasTy, FnSubst, WhereClause};
use chalk_ir::{cast::Cast, AliasEq, AliasTy, FnSubst, WhereClause};
use hir_def::{expr::ExprId, HasModule};
use smallvec::SmallVec;

Expand Down Expand Up @@ -42,46 +42,38 @@ impl InferenceContext<'_> {

let fn_traits: SmallVec<[ChalkTraitId; 3]> =
utils::fn_traits(self.db.upcast(), self.owner.module(self.db.upcast()).krate())
.map(|tid| to_chalk_trait_id(tid))
.map(to_chalk_trait_id)
.collect();

let self_ty = TyKind::Error.intern(&Interner);
let bounds = dyn_ty.bounds.clone().substitute(&Interner, &[self_ty.cast(&Interner)]);
for bound in bounds.iter(&Interner) {
// NOTE(skip_binders): the extracted types are rebound by the returned `FnPointer`
match bound.skip_binders() {
WhereClause::AliasEq(eq) => match &eq.alias {
AliasTy::Projection(projection) => {
let assoc_data = self.db.associated_ty_data(projection.associated_ty_id);
if !fn_traits.contains(&assoc_data.trait_id) {
return None;
}
if let WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection), ty }) =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably intentional

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what reason? To me collapsing the matches seems better personally

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto: here, a complicated pattern comes before the expression to match.

bound.skip_binders()
{
let assoc_data = self.db.associated_ty_data(projection.associated_ty_id);
if !fn_traits.contains(&assoc_data.trait_id) {
return None;
}

// Skip `Self`, get the type argument.
let arg = projection.substitution.as_slice(&Interner).get(1)?;
if let Some(subst) = arg.ty(&Interner)?.as_tuple() {
let generic_args = subst.as_slice(&Interner);
let mut sig_tys = Vec::new();
for arg in generic_args {
sig_tys.push(arg.ty(&Interner)?.clone());
}
sig_tys.push(eq.ty.clone());

cov_mark::hit!(dyn_fn_param_informs_call_site_closure_signature);
return Some(FnPointer {
num_binders: bound.len(&Interner),
sig: FnSig {
abi: (),
safety: chalk_ir::Safety::Safe,
variadic: false,
},
substitution: FnSubst(Substitution::from_iter(&Interner, sig_tys)),
});
}
// Skip `Self`, get the type argument.
let arg = projection.substitution.as_slice(&Interner).get(1)?;
if let Some(subst) = arg.ty(&Interner)?.as_tuple() {
let generic_args = subst.as_slice(&Interner);
let mut sig_tys = Vec::new();
for arg in generic_args {
sig_tys.push(arg.ty(&Interner)?.clone());
}
AliasTy::Opaque(_) => {}
},
_ => {}
sig_tys.push(ty.clone());

cov_mark::hit!(dyn_fn_param_informs_call_site_closure_signature);
return Some(FnPointer {
num_binders: bound.len(&Interner),
sig: FnSig { abi: (), safety: chalk_ir::Safety::Safe, variadic: false },
substitution: FnSubst(Substitution::from_iter(&Interner, sig_tys)),
});
}
}
}

Expand Down
Loading