Skip to content

Commit 8b89cb3

Browse files
committed
Only suggest #[const_trait] only on local traits
1 parent 0fc3d5f commit 8b89cb3

File tree

1 file changed

+14
-12
lines changed
  • compiler/rustc_const_eval/src/check_consts

1 file changed

+14
-12
lines changed

compiler/rustc_const_eval/src/check_consts/ops.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -386,18 +386,20 @@ fn build_error_for_const_call<'tcx>(
386386
`{trait_name}` is not const",
387387
),
388388
);
389-
let indentation = ccx
390-
.tcx
391-
.sess
392-
.source_map()
393-
.indentation_before(trait_span)
394-
.unwrap_or_default();
395-
err.span_suggestion_verbose(
396-
trait_span.shrink_to_lo(),
397-
format!("consider making trait `{trait_name}` const"),
398-
format!("#[const_trait]\n{indentation}"),
399-
Applicability::MachineApplicable,
400-
);
389+
if parent.is_local() {
390+
let indentation = ccx
391+
.tcx
392+
.sess
393+
.source_map()
394+
.indentation_before(trait_span)
395+
.unwrap_or_default();
396+
err.span_suggestion_verbose(
397+
trait_span.shrink_to_lo(),
398+
format!("consider making trait `{trait_name}` const"),
399+
format!("#[const_trait]\n{indentation}"),
400+
Applicability::MachineApplicable,
401+
);
402+
}
401403
}
402404
} else if ccx.tcx.constness(callee) != hir::Constness::Const {
403405
let name = ccx.tcx.item_name(callee);

0 commit comments

Comments
 (0)