Skip to content

Commit 884537a

Browse files
committed
Only suggest #[const_trait] only on local traits
1 parent 821509b commit 884537a

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
@@ -383,18 +383,20 @@ fn build_error_for_const_call<'tcx>(
383383
`{trait_name}` is not const",
384384
),
385385
);
386-
let indentation = ccx
387-
.tcx
388-
.sess
389-
.source_map()
390-
.indentation_before(trait_span)
391-
.unwrap_or_default();
392-
err.span_suggestion_verbose(
393-
trait_span.shrink_to_lo(),
394-
format!("consider making trait `{trait_name}` const"),
395-
format!("#[const_trait]\n{indentation}"),
396-
Applicability::MachineApplicable,
397-
);
386+
if parent.is_local() {
387+
let indentation = ccx
388+
.tcx
389+
.sess
390+
.source_map()
391+
.indentation_before(trait_span)
392+
.unwrap_or_default();
393+
err.span_suggestion_verbose(
394+
trait_span.shrink_to_lo(),
395+
format!("consider making trait `{trait_name}` const"),
396+
format!("#[const_trait]\n{indentation}"),
397+
Applicability::MachineApplicable,
398+
);
399+
}
398400
}
399401
} else if ccx.tcx.constness(callee) != hir::Constness::Const {
400402
let name = ccx.tcx.item_name(callee);

0 commit comments

Comments
 (0)