@@ -281,7 +281,13 @@ impl<'tcx> TyCtxt<'tcx> {
281281 /// If `id` is `Some(_)`, this function will also check if the item at `def_id` has been
282282 /// deprecated. If the item is indeed deprecated, we will emit a deprecation lint attached to
283283 /// `id`.
284- pub fn eval_stability ( self , def_id : DefId , id : Option < HirId > , span : Span ) -> EvalResult {
284+ pub fn eval_stability (
285+ self ,
286+ def_id : DefId ,
287+ id : Option < HirId > ,
288+ span : Span ,
289+ method_span : Option < Span > ,
290+ ) -> EvalResult {
285291 // Deprecated attributes apply in-crate and cross-crate.
286292 if let Some ( id) = id {
287293 if let Some ( depr_entry) = self . lookup_deprecation_entry ( def_id) {
@@ -300,6 +306,7 @@ impl<'tcx> TyCtxt<'tcx> {
300306 let path = & with_no_trimmed_paths ( || self . def_path_str ( def_id) ) ;
301307 let kind = self . def_kind ( def_id) . descr ( def_id) ;
302308 let ( message, lint) = deprecation_message ( & depr_entry. attr , kind, path) ;
309+ let span = method_span. unwrap_or ( span) ;
303310 late_report_deprecation (
304311 self ,
305312 & message,
@@ -382,8 +389,14 @@ impl<'tcx> TyCtxt<'tcx> {
382389 ///
383390 /// This function will also check if the item is deprecated.
384391 /// If so, and `id` is not `None`, a deprecated lint attached to `id` will be emitted.
385- pub fn check_stability ( self , def_id : DefId , id : Option < HirId > , span : Span ) {
386- self . check_optional_stability ( def_id, id, span, |span, def_id| {
392+ pub fn check_stability (
393+ self ,
394+ def_id : DefId ,
395+ id : Option < HirId > ,
396+ span : Span ,
397+ method_span : Option < Span > ,
398+ ) {
399+ self . check_optional_stability ( def_id, id, span, method_span, |span, def_id| {
387400 // The API could be uncallable for other reasons, for example when a private module
388401 // was referenced.
389402 self . sess . delay_span_bug ( span, & format ! ( "encountered unmarked API: {:?}" , def_id) ) ;
@@ -399,14 +412,15 @@ impl<'tcx> TyCtxt<'tcx> {
399412 def_id : DefId ,
400413 id : Option < HirId > ,
401414 span : Span ,
415+ method_span : Option < Span > ,
402416 unmarked : impl FnOnce ( Span , DefId ) ,
403417 ) {
404418 let soft_handler = |lint, span, msg : & _ | {
405419 self . struct_span_lint_hir ( lint, id. unwrap_or ( hir:: CRATE_HIR_ID ) , span, |lint| {
406420 lint. build ( msg) . emit ( )
407421 } )
408422 } ;
409- match self . eval_stability ( def_id, id, span) {
423+ match self . eval_stability ( def_id, id, span, method_span ) {
410424 EvalResult :: Allow => { }
411425 EvalResult :: Deny { feature, reason, issue, is_soft } => {
412426 report_unstable ( self . sess , feature, reason, issue, is_soft, span, soft_handler)
0 commit comments