Skip to content

Fix clippy *errors* in current build #7108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
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
1 change: 1 addition & 0 deletions crates/assists/src/handlers/infer_function_return_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ fn extract_tail(ctx: &AssistContext) -> Option<(FnType, ast::Expr, InsertOrRepla
(FnType::Function, tail_expr, ret_range, action)
};
let frange = ctx.frange.range;
#[cfg_attr(not(test), allow(clippy::if_same_then_else))]
if return_type_range.contains_range(frange) {
mark::hit!(cursor_in_ret_position);
mark::hit!(cursor_in_ret_position_closure);
Expand Down
4 changes: 3 additions & 1 deletion crates/base_db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ pub struct ProcMacro {
impl Eq for ProcMacro {}
impl PartialEq for ProcMacro {
fn eq(&self, other: &ProcMacro) -> bool {
self.name == other.name && Arc::ptr_eq(&self.expander, &other.expander)
let thisptr = self.expander.as_ref() as *const dyn ProcMacroExpander as *const u8;
let otherptr = other.expander.as_ref() as *const dyn ProcMacroExpander as *const u8;
self.name == other.name && std::ptr::eq(thisptr, otherptr)
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
Contributor Author

Choose a reason for hiding this comment

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

There's a lot of nasty in pointer comparisons here I guess, though once you start transmuting stuff I think I tap out on knowing what's sane 😬

Do you mean, by this comment, that you want this particular change dropped, annotated that at some point it might be revertable, or do you just mean to mention the horror 😁 ?

}
}

Expand Down
39 changes: 33 additions & 6 deletions crates/proc_macro_srv/src/proc_macro/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ impl FromStr for TokenStream {
/// with `Delimiter::None` delimiters and negative numeric literals.
impl fmt::Display for TokenStream {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.to_string())
// NOTE(kinnison)
// This differs from the "upstream" because we cannot use the ToString
// impl commented out above.
f.write_str(&self.0.to_string())
Copy link
Member

Choose a reason for hiding this comment

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

I recommend that do not changes this file as it is almost straight copy from rustc such that it is quite hard to trace if they changed something relevant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand, however without this change, afaict the Display impls are recursive because the blanket ToString impl calls the Display impl a'la https://doc.rust-lang.org/stable/src/alloc/string.rs.html#2194-2207

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but these won't be called in normal situation and these implementation are just dummy for make the ABI happy.

Anyway, I think it is okay to change it for functionality

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My fear is that if they're there for ABI compatibility then it implies they could be called at which point they'd break. If on the other hand they can't be called then removing them (commenting them out?) might be a better bet since it'd be clearer what was going on. I'm not clear about how that might affect compatibility though, you're the expert here :D

Copy link
Member

@edwin0cheng edwin0cheng Dec 31, 2020

Choose a reason for hiding this comment

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

Okay, Agreed. Maybe add a comment to indicate it is a complicated case :)

I'm not clear about how that might affect compatibility though, you're the expert here :D

I wish I were the expert. :( I even don't understand why the original rustc allow duplication implementation of the ToString It should be conflicted to impl<T: fmt::Display + ?Sized> ToString implementation :

https://github.com/rust-lang/rust/blob/b33e234155b33ab6bce280fb2445b62b68622b61/library/proc_macro/src/lib.rs#L138-L155

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that when the real code is built, specialisation is possible. I'll consider a suitable comment to add

}
}

Expand Down Expand Up @@ -428,7 +431,15 @@ impl From<Literal> for TokenTree {
/// with `Delimiter::None` delimiters and negative numeric literals.
impl fmt::Display for TokenTree {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.to_string())
// NOTE(kinnison)
// This differs from the "upstream" because we cannot use the ToString
// impl commented out above.
f.write_str(&match self {
TokenTree::Group(g) => g.to_string(),
TokenTree::Ident(i) => i.to_string(),
TokenTree::Punct(p) => p.to_string(),
TokenTree::Literal(l) => l.to_string(),
})
}
}

Expand Down Expand Up @@ -533,7 +544,11 @@ impl Group {
/// with `Delimiter::None` delimiters.
impl fmt::Display for Group {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.to_string())
// NOTE(kinnison)
// This differs from the "upstream" because we cannot use the ToString
// impl commented out above.
let stream = TokenStream::from(TokenTree::from(self.clone()));
f.write_str(&stream.to_string())
}
}

Expand Down Expand Up @@ -612,7 +627,11 @@ impl Punct {
/// back into the same character.
impl fmt::Display for Punct {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.to_string())
// NOTE(kinnison)
// This differs from the "upstream" because we cannot use the ToString
// impl commented out above.
let stream = TokenStream::from(TokenTree::from(self.clone()));
f.write_str(&stream.to_string())
}
}

Expand Down Expand Up @@ -683,7 +702,11 @@ impl Ident {
/// back into the same identifier.
impl fmt::Display for Ident {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.to_string())
// NOTE(kinnison)
// This differs from the "upstream" because we cannot use the ToString
// impl commented out above.
let stream = TokenStream::from(TokenTree::from(self.clone()));
f.write_str(&stream.to_string())
}
}

Expand Down Expand Up @@ -914,7 +937,11 @@ impl Literal {
/// back into the same literal (except for possible rounding for floating point literals).
impl fmt::Display for Literal {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.to_string())
// NOTE(kinnison)
// This differs from the "upstream" because we cannot use the ToString
// impl commented out above.
let stream = TokenStream::from(TokenTree::from(self.clone()));
f.write_str(&stream.to_string())
}
}

Expand Down
4 changes: 3 additions & 1 deletion crates/syntax/src/algo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,9 @@ impl ops::AddAssign for SyntaxRewriter<'_> {
indexmap::map::Entry::Occupied(mut occupied) => {
occupied.get_mut().extend(insertions)
}
indexmap::map::Entry::Vacant(vacant) => drop(vacant.insert(insertions)),
indexmap::map::Entry::Vacant(vacant) => {
vacant.insert(insertions);
}
}
}
}
Expand Down