Remove LintDiagnostic::msg · rust-lang/rust@06bc4fc (original) (raw)

`@@ -91,11 +91,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

`

91

91

` prelude_or_array_lint,

`

92

92

` self_expr.hir_id,

`

93

93

` self_expr.span,

`

94

``

`-

format!(

`

95

``

`` -

"trait method {} will become ambiguous in Rust {edition}",

``

96

``

`-

segment.ident.name

`

97

``

`-

),

`

98

94

` |lint| {

`

``

95

`+

lint.primary_message(format!(

`

``

96

`` +

"trait method {} will become ambiguous in Rust {edition}",

``

``

97

`+

segment.ident.name

`

``

98

`+

));

`

``

99

+

99

100

`let sp = self_expr.span;

`

100

101

``

101

102

`let derefs = "*".repeat(pick.autoderefs);

`

`@@ -144,11 +145,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

`

144

145

` prelude_or_array_lint,

`

145

146

` call_expr.hir_id,

`

146

147

` call_expr.span,

`

147

``

`-

format!(

`

148

``

`` -

"trait method {} will become ambiguous in Rust {edition}",

``

149

``

`-

segment.ident.name

`

150

``

`-

),

`

151

148

` |lint| {

`

``

149

`+

lint.primary_message(format!(

`

``

150

`` +

"trait method {} will become ambiguous in Rust {edition}",

``

``

151

`+

segment.ident.name

`

``

152

`+

));

`

``

153

+

152

154

`let sp = call_expr.span;

`

153

155

`let trait_name = self.trait_path_or_bare_name(

`

154

156

` span,

`

`@@ -251,73 +253,67 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

`

251

253

`return;

`

252

254

`}

`

253

255

``

254

``

`-

self.tcx.node_span_lint(

`

255

``

`-

RUST_2021_PRELUDE_COLLISIONS,

`

256

``

`-

expr_id,

`

257

``

`-

span,

`

258

``

`-

format!(

`

``

256

`+

self.tcx.node_span_lint(RUST_2021_PRELUDE_COLLISIONS, expr_id, span, |lint| {

`

``

257

`+

lint.primary_message(format!(

`

259

258

`` "trait-associated function {} will become ambiguous in Rust 2021",

``

260

259

` method_name.name

`

261

``

`-

),

`

262

``

`-

|lint| {

`

263

``

`-

// "type" refers to either a type or, more likely, a trait from which

`

264

``

`-

// the associated function or method is from.

`

265

``

`-

let container_id = pick.item.container_id(self.tcx);

`

266

``

`-

let trait_path = self.trait_path_or_bare_name(span, expr_id, container_id);

`

267

``

`-

let trait_generics = self.tcx.generics_of(container_id);

`

268

``

-

269

``

`-

let trait_name =

`

270

``

`-

if trait_generics.own_params.len() <= trait_generics.has_self as usize {

`

271

``

`-

trait_path

`

272

``

`-

} else {

`

273

``

`-

let counts = trait_generics.own_counts();

`

274

``

`-

format!(

`

275

``

`-

"{}<{}>",

`

276

``

`-

trait_path,

`

``

260

`+

));

`

``

261

+

``

262

`+

// "type" refers to either a type or, more likely, a trait from which

`

``

263

`+

// the associated function or method is from.

`

``

264

`+

let container_id = pick.item.container_id(self.tcx);

`

``

265

`+

let trait_path = self.trait_path_or_bare_name(span, expr_id, container_id);

`

``

266

`+

let trait_generics = self.tcx.generics_of(container_id);

`

``

267

+

``

268

`+

let trait_name =

`

``

269

`+

if trait_generics.own_params.len() <= trait_generics.has_self as usize {

`

``

270

`+

trait_path

`

``

271

`+

} else {

`

``

272

`+

let counts = trait_generics.own_counts();

`

``

273

`+

format!(

`

``

274

`+

"{}<{}>",

`

``

275

`+

trait_path,

`

``

276

`+

std::iter::repeat("'_")

`

``

277

`+

.take(counts.lifetimes)

`

``

278

`+

.chain(std::iter::repeat("_").take(

`

``

279

`+

counts.types + counts.consts - trait_generics.has_self as usize

`

``

280

`+

))

`

``

281

`+

.collect::<Vec<_>>()

`

``

282

`+

.join(", ")

`

``

283

`+

)

`

``

284

`+

};

`

``

285

+

``

286

`+

let mut self_ty_name = self_ty_span

`

``

287

`+

.find_ancestor_inside(span)

`

``

288

`+

.and_then(|span| self.sess().source_map().span_to_snippet(span).ok())

`

``

289

`+

.unwrap_or_else(|| self_ty.to_string());

`

``

290

+

``

291

`+

// Get the number of generics the self type has (if an Adt) unless we can determine that

`

``

292

`+

// the user has written the self type with generics already which we (naively) do by looking

`

``

293

`` +

// for a "<" in self_ty_name.

``

``

294

`+

if !self_ty_name.contains('<') {

`

``

295

`+

if let ty::Adt(def, _) = self_ty.kind() {

`

``

296

`+

let generics = self.tcx.generics_of(def.did());

`

``

297

`+

if !generics.is_own_empty() {

`

``

298

`+

let counts = generics.own_counts();

`

``

299

`+

self_ty_name += &format!(

`

``

300

`+

"<{}>",

`

277

301

` std::iter::repeat("'_")

`

278

302

`.take(counts.lifetimes)

`

279

``

`-

.chain(std::iter::repeat("_").take(

`

280

``

`-

counts.types + counts.consts - trait_generics.has_self as usize

`

281

``

`-

))

`

``

303

`+

.chain(std::iter::repeat("_").take(counts.types + counts.consts))

`

282

304

`.collect::<Vec<_>>()

`

283

305

`.join(", ")

`

284

``

`-

)

`

285

``

`-

};

`

286

``

-

287

``

`-

let mut self_ty_name = self_ty_span

`

288

``

`-

.find_ancestor_inside(span)

`

289

``

`-

.and_then(|span| self.sess().source_map().span_to_snippet(span).ok())

`

290

``

`-

.unwrap_or_else(|| self_ty.to_string());

`

291

``

-

292

``

`-

// Get the number of generics the self type has (if an Adt) unless we can determine that

`

293

``

`-

// the user has written the self type with generics already which we (naively) do by looking

`

294

``

`` -

// for a "<" in self_ty_name.

``

295

``

`-

if !self_ty_name.contains('<') {

`

296

``

`-

if let ty::Adt(def, _) = self_ty.kind() {

`

297

``

`-

let generics = self.tcx.generics_of(def.did());

`

298

``

`-

if !generics.is_own_empty() {

`

299

``

`-

let counts = generics.own_counts();

`

300

``

`-

self_ty_name += &format!(

`

301

``

`-

"<{}>",

`

302

``

`-

std::iter::repeat("'_")

`

303

``

`-

.take(counts.lifetimes)

`

304

``

`-

.chain(

`

305

``

`-

std::iter::repeat("_").take(counts.types + counts.consts)

`

306

``

`-

)

`

307

``

`-

.collect::<Vec<_>>()

`

308

``

`-

.join(", ")

`

309

``

`-

);

`

310

``

`-

}

`

``

306

`+

);

`

311

307

`}

`

312

308

`}

`

313

``

`-

lint.span_suggestion(

`

314

``

`-

span,

`

315

``

`-

"disambiguate the associated function",

`

316

``

`-

format!("<{} as {}>::{}", self_ty_name, trait_name, method_name.name,),

`

317

``

`-

Applicability::MachineApplicable,

`

318

``

`-

);

`

319

``

`-

},

`

320

``

`-

);

`

``

309

`+

}

`

``

310

`+

lint.span_suggestion(

`

``

311

`+

span,

`

``

312

`+

"disambiguate the associated function",

`

``

313

`+

format!("<{} as {}>::{}", self_ty_name, trait_name, method_name.name,),

`

``

314

`+

Applicability::MachineApplicable,

`

``

315

`+

);

`

``

316

`+

});

`

321

317

`}

`

322

318

``

323

319

`fn trait_path_or_bare_name(

`