Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Voila
  • Loading branch information
john-h-k committed Apr 30, 2023
commit 430e1dbab0c1119a363cbf8d12e0ff6f6f5e61e1
8 changes: 2 additions & 6 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,9 @@ lint_redundant_semicolons =
*[false] this semicolon
}

lint_useless_send_constraint =
constraining a reference to `Send` without `Sync` is useless, consider {$only_trait ->
[true] replacing it with `Any`
*[false] removing it
}
lint_useless_send_constraint = constraining a reference to `Send` is meaningless
.suggestion = {$only_trait ->
[true] replace this with `Any`
[true] replace this with `std::any::Any`
Copy link
Member

Choose a reason for hiding this comment

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

Replacing by Any is a very strange suggestion. Why would type_id machinery be necessary? Can't the 'static bound cause a problem?

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 wasn't sure what else to put, this is for the scenario where Send is the only trait specified (so removing it would be invalid)

*[false] remove this
}

Expand Down
13 changes: 7 additions & 6 deletions compiler/rustc_lint/src/useless_send_constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,31 @@ declare_lint_pass!(UselessSendConstraint => [USELESS_SEND_CONSTRAINT]);
impl<'tcx> LateLintPass<'tcx> for UselessSendConstraint {
fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx hir::Ty<'tcx>) {
let hir::TyKind::Ref(
..,
hir::MutTy {
ty: hir::Ty {
kind: hir::TyKind::TraitObject(bounds, ..),
..
},
mutbl: hir::Mutability::Not, // only immutable references
..
},
..
) = ty.kind else { return; };

let send = cx.tcx.get_diagnostic_item(sym::Send);
let sync = cx.tcx.get_diagnostic_item(sym::Sync);

let send_bound = bounds.iter().find(|b| b.trait_ref.trait_def_id() == send);
let sync_bound = bounds.iter().find(|b| b.trait_ref.trait_def_id() == sync);

if let Some(send_bound) = send_bound && sync_bound.is_none() {
if let Some(send_bound) = send_bound {
let only_trait = bounds.len() == 1;

cx.tcx.emit_spanned_lint(
USELESS_SEND_CONSTRAINT,
send_bound.trait_ref.hir_ref_id, // is this correct?
send_bound.span,
UselessSendConstraintDiag { only_trait, suggestion: send_bound.span },
UselessSendConstraintDiag {
only_trait,
suggestion: send_bound.span,
},
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/io/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ impl Error {
#[stable(feature = "io_error_inner", since = "1.3.0")]
#[must_use]
#[inline]
pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error + Send + Sync + 'static)> {
pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error + Sync + 'static)> {
Copy link
Member

Choose a reason for hiding this comment

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

This is a mutable reference. For &mut … + Send, the Send makes sense, doesn’t it?

match self.repr.data_mut() {
ErrorData::Os(..) => None,
ErrorData::Simple(..) => None,
Expand Down