Applicability-ify librustc_lint · rust-lang/rust@6e63b0d (original) (raw)

`@@ -84,7 +84,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for WhileTrue {

`

84

84

`` let msg = "denote infinite loops with loop { ... }";

``

85

85

`let condition_span = cx.tcx.sess.codemap().def_span(e.span);

`

86

86

`let mut err = cx.struct_span_lint(WHILE_TRUE, condition_span, msg);

`

87

``

`` -

err.span_suggestion_short(condition_span, "use loop", "loop".to_owned());

``

``

87

`+

err.span_suggestion_short_with_applicability(

`

``

88

`+

condition_span,

`

``

89

`` +

"use loop",

``

``

90

`+

"loop".to_owned(),

`

``

91

`+

Applicability::MachineApplicable

`

``

92

`+

);

`

88

93

` err.emit();

`

89

94

`}

`

90

95

`}

`

`@@ -191,7 +196,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns {

`

191

196

` fieldpat.span,

`

192

197

`` &format!("the {}: in this pattern is redundant", ident));

``

193

198

`let subspan = cx.tcx.sess.codemap().span_through_char(fieldpat.span, ':');

`

194

``

`-

err.span_suggestion_short(subspan, "remove this", ident.to_string());

`

``

199

`+

err.span_suggestion_short_with_applicability(

`

``

200

`+

subspan,

`

``

201

`+

"remove this",

`

``

202

`+

ident.to_string(),

`

``

203

`+

Applicability::MachineApplicable

`

``

204

`+

);

`

195

205

` err.emit();

`

196

206

`}

`

197

207

`}

`

`@@ -708,10 +718,11 @@ impl EarlyLintPass for BadRepr {

`

708

718

` | "i8" | "i16" | "i32" | "i64" | "i128" | "isize" => {

`

709

719

`` // if the literal could have been a valid repr arg,

``

710

720

`// suggest the correct syntax

`

711

``

`-

warn.span_suggestion(

`

``

721

`+

warn.span_suggestion_with_applicability(

`

712

722

` attr.span,

`

713

723

`` "give repr a hint",

``

714

724

`repr_str(&lit.as_str()),

`

``

725

`+

Applicability::MachineApplicable

`

715

726

`);

`

716

727

` suggested = true;

`

717

728

`}

`

`@@ -779,7 +790,12 @@ impl EarlyLintPass for DeprecatedAttr {

`

779

790

`` let msg = format!("use of deprecated attribute {}: {}. See {}",

``

780

791

` name, reason, link);

`

781

792

`let mut err = cx.struct_span_lint(DEPRECATED, attr.span, &msg);

`

782

``

`-

err.span_suggestion_short(attr.span, "remove this attribute", "".to_owned());

`

``

793

`+

err.span_suggestion_short_with_applicability(

`

``

794

`+

attr.span,

`

``

795

`+

"remove this attribute",

`

``

796

`+

"".to_owned(),

`

``

797

`+

Applicability::MachineApplicable

`

``

798

`+

);

`

783

799

` err.emit();

`

784

800

`}

`

785

801

`return;

`

`@@ -1201,7 +1217,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems {

`

1201

1217

`}

`

1202

1218

`};

`

1203

1219

`if let Some(replacement) = suggestion {

`

1204

``

`-

err.span_suggestion(vis.span, "try making it public", replacement);

`

``

1220

`+

err.span_suggestion_with_applicability(

`

``

1221

`+

vis.span,

`

``

1222

`+

"try making it public",

`

``

1223

`+

replacement,

`

``

1224

`+

Applicability::MachineApplicable

`

``

1225

`+

);

`

1205

1226

`}

`

1206

1227

`};

`

1207

1228

``

`@@ -1225,9 +1246,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems {

`

1225

1246

` it.span,

`

1226

1247

`"functions generic over \

`

1227

1248

` types must be mangled");

`

1228

``

`-

err.span_suggestion_short(no_mangle_attr.span,

`

1229

``

`-

"remove this attribute",

`

1230

``

`-

"".to_owned());

`

``

1249

`+

err.span_suggestion_short_with_applicability(

`

``

1250

`+

no_mangle_attr.span,

`

``

1251

`+

"remove this attribute",

`

``

1252

`+

"".to_owned(),

`

``

1253

`` +

// Use of #[no_mangle] suggests FFI intent; correct

``

``

1254

`+

// fix may be to monomorphize source by hand

`

``

1255

`+

Applicability::MaybeIncorrect

`

``

1256

`+

);

`

1231

1257

` err.emit();

`

1232

1258

`break;

`

1233

1259

`}

`

`@@ -1257,9 +1283,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems {

`

1257

1283

`.unwrap_or(0) as u32;

`

1258

1284

`` // const is 5 chars

``

1259

1285

`let const_span = it.span.with_hi(BytePos(it.span.lo().0 + start + 5));

`

1260

``

`-

err.span_suggestion(const_span,

`

1261

``

`-

"try a static value",

`

1262

``

`-

"pub static".to_owned());

`

``

1286

`+

err.span_suggestion_with_applicability(

`

``

1287

`+

const_span,

`

``

1288

`+

"try a static value",

`

``

1289

`+

"pub static".to_owned(),

`

``

1290

`+

Applicability::MachineApplicable

`

``

1291

`+

);

`

1263

1292

` err.emit();

`

1264

1293

`}

`

1265

1294

`}

`