Skip to content

add suggestion applicabilities to librustc and libsyntax #50724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ use ty::{self, Region, Ty, TyCtxt, TypeFoldable, TypeVariants};
use ty::error::TypeError;
use syntax::ast::DUMMY_NODE_ID;
use syntax_pos::{Pos, Span};
use errors::{DiagnosticBuilder, DiagnosticStyledString};
use errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};

use rustc_data_structures::indexed_vec::Idx;

@@ -1097,7 +1097,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
if let Some((sp, has_lifetimes)) = type_param_span {
let tail = if has_lifetimes { " + " } else { "" };
let suggestion = format!("{}: {}{}", bound_kind, sub, tail);
err.span_suggestion_short(sp, consider, suggestion);
err.span_suggestion_short_with_applicability(
sp, consider, suggestion,
Applicability::MaybeIncorrect // Issue #41966
);
} else {
err.help(consider);
}
7 changes: 4 additions & 3 deletions src/librustc/lint/levels.rs
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@

use std::cmp;

use errors::DiagnosticBuilder;
use errors::{Applicability, DiagnosticBuilder};
use hir::HirId;
use ich::StableHashingContext;
use lint::builtin;
@@ -265,10 +265,11 @@ impl<'a> LintLevelsBuilder<'a> {
store.check_lint_name(&name_lower) {
db.emit();
} else {
db.span_suggestion(
db.span_suggestion_with_applicability(
li.span,
"lowercase the lint name",
name_lower
name_lower,
Applicability::MachineApplicable
).emit();
}
} else {
13 changes: 9 additions & 4 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
@@ -109,6 +109,7 @@ use self::VarKind::*;
use hir::def::*;
use ty::{self, TyCtxt};
use lint;
use errors::Applicability;
use util::nodemap::{NodeMap, NodeSet};

use std::collections::VecDeque;
@@ -1541,11 +1542,15 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
let mut err = self.ir.tcx
.struct_span_lint_node(lint::builtin::UNUSED_VARIABLES, id, sp, &msg);
if self.ir.variable_is_shorthand(var) {
err.span_suggestion(sp, "try ignoring the field",
format!("{}: _", name));
err.span_suggestion_with_applicability(sp, "try ignoring the field",
format!("{}: _", name),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These may need macro checks?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not happy with the situation at the moment. Almost every single suggestion needs to have macro checks. I'll be trying something out to encode this in the API and avoid the current game of whack-a-mole.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah.

So in clippy my plan was that span_to_snippet would take an &mut applicability parameter, and whenever it detects a macro in the thing you're using it would automatically flip the applicability.

But also the span you're suggesting for would need a good macro check. idk.

Applicability::MachineApplicable);
} else {
err.span_suggestion_short(sp, &suggest_underscore_msg,
format!("_{}", name));
err.span_suggestion_short_with_applicability(
sp, &suggest_underscore_msg,
format!("_{}", name),
Applicability::MachineApplicable,
);
}
err.emit()
}
35 changes: 22 additions & 13 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ use super::{
Overflow,
};

use errors::DiagnosticBuilder;
use errors::{Applicability, DiagnosticBuilder};
use hir;
use hir::def_id::DefId;
use infer::{self, InferCtxt};
@@ -856,9 +856,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
if let Some(ref expr) = local.init {
if let hir::ExprIndex(_, _) = expr.node {
if let Ok(snippet) = self.tcx.sess.codemap().span_to_snippet(expr.span) {
err.span_suggestion(expr.span,
"consider borrowing here",
format!("&{}", snippet));
err.span_suggestion_with_applicability(
expr.span,
"consider borrowing here",
format!("&{}", snippet),
Applicability::MachineApplicable
);
}
}
}
@@ -901,7 +904,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
let format_str = format!("consider removing {} leading `&`-references",
remove_refs);

err.span_suggestion_short(sp, &format_str, String::from(""));
err.span_suggestion_short_with_applicability(
sp, &format_str, String::from(""), Applicability::MachineApplicable
);
break;
}
} else {
@@ -1046,10 +1051,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
let sugg = fields.iter()
.map(|(name, _)| name.to_owned())
.collect::<Vec<String>>().join(", ");
err.span_suggestion(found_span,
"change the closure to take multiple arguments instead of \
a single tuple",
format!("|{}|", sugg));
err.span_suggestion_with_applicability(found_span,
"change the closure to take multiple \
arguments instead of a single tuple",
format!("|{}|", sugg),
Applicability::MachineApplicable);
}
}
if let &[ArgKind::Tuple(_, ref fields)] = &expected_args[..] {
@@ -1077,10 +1083,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
"".to_owned()
},
);
err.span_suggestion(found_span,
"change the closure to accept a tuple instead of \
individual arguments",
sugg);
err.span_suggestion_with_applicability(
found_span,
"change the closure to accept a tuple instead of \
individual arguments",
sugg,
Applicability::MachineApplicable
);
}
}
}
17 changes: 17 additions & 0 deletions src/librustc_errors/diagnostic.rs
Original file line number Diff line number Diff line change
@@ -311,6 +311,23 @@ impl Diagnostic {
self
}

pub fn span_suggestion_short_with_applicability(
&mut self, sp: Span, msg: &str, suggestion: String, applicability: Applicability
) -> &mut Self {
self.suggestions.push(CodeSuggestion {
substitutions: vec![Substitution {
parts: vec![SubstitutionPart {
snippet: suggestion,
span: sp,
}],
}],
msg: msg.to_owned(),
show_code_when_inline: false,
applicability: applicability,
});
self
}

pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self {
self.span = sp.into();
self
6 changes: 6 additions & 0 deletions src/librustc_errors/diagnostic_builder.rs
Original file line number Diff line number Diff line change
@@ -200,6 +200,12 @@ impl<'a> DiagnosticBuilder<'a> {
suggestions: Vec<String>,
applicability: Applicability)
-> &mut Self);
forward!(pub fn span_suggestion_short_with_applicability(&mut self,
sp: Span,
msg: &str,
suggestion: String,
applicability: Applicability)
-> &mut Self);
forward!(pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self);
forward!(pub fn code(&mut self, s: DiagnosticId) -> &mut Self);

20 changes: 13 additions & 7 deletions src/libsyntax/attr.rs
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ use ast::{MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind};
use ast::{Lit, LitKind, Expr, ExprKind, Item, Local, Stmt, StmtKind};
use codemap::{BytePos, Spanned, respan, dummy_spanned};
use syntax_pos::Span;
use errors::Handler;
use errors::{Applicability, Handler};
use feature_gate::{Features, GatedCfg};
use parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration};
use parse::parser::Parser;
@@ -1067,14 +1067,20 @@ pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec<ReprAttr>
"incorrect `repr(align)` attribute format");
match value.node {
ast::LitKind::Int(int, ast::LitIntType::Unsuffixed) => {
err.span_suggestion(item.span,
"use parentheses instead",
format!("align({})", int));
err.span_suggestion_with_applicability(
item.span,
"use parentheses instead",
format!("align({})", int),
Applicability::MachineApplicable
);
}
ast::LitKind::Str(s, _) => {
err.span_suggestion(item.span,
"use parentheses instead",
format!("align({})", s));
err.span_suggestion_with_applicability(
item.span,
"use parentheses instead",
format!("align({})", s),
Applicability::MachineApplicable
);
}
_ => {}
}
8 changes: 6 additions & 2 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ use ast::{MacStmtStyle, StmtKind, ItemKind};
use attr::{self, HasAttrs};
use codemap::{ExpnInfo, NameAndSpan, MacroBang, MacroAttribute, dummy_spanned, respan};
use config::{is_test_or_bench, StripUnconfigured};
use errors::FatalError;
use errors::{Applicability, FatalError};
use ext::base::*;
use ext::derive::{add_derived_markers, collect_derives};
use ext::hygiene::{self, Mark, SyntaxContext};
@@ -331,7 +331,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
let trait_list = traits.iter()
.map(|t| format!("{}", t)).collect::<Vec<_>>();
let suggestion = format!("#[derive({})]", trait_list.join(", "));
err.span_suggestion(span, "try an outer attribute", suggestion);
err.span_suggestion_with_applicability(
span, "try an outer attribute", suggestion,
// We don't 𝑘𝑛𝑜𝑤 that the following item is an ADT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol

Applicability::MaybeIncorrect
);
}
err.emit();
}
13 changes: 7 additions & 6 deletions src/libsyntax/parse/lexer/mod.rs
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
use ast::{self, Ident};
use syntax_pos::{self, BytePos, CharPos, Pos, Span, NO_EXPANSION};
use codemap::{CodeMap, FilePathMapping};
use errors::{FatalError, DiagnosticBuilder};
use errors::{Applicability, FatalError, DiagnosticBuilder};
use parse::{token, ParseSess};
use str::char_at;
use symbol::{Symbol, keywords};
@@ -1345,11 +1345,12 @@ impl<'a> StringReader<'a> {
self.sess.span_diagnostic
.struct_span_err(span,
"character literal may only contain one codepoint")
.span_suggestion(span,
"if you meant to write a `str` literal, \
use double quotes",
format!("\"{}\"", &self.src[start..end]))
.emit();
.span_suggestion_with_applicability(
span,
"if you meant to write a `str` literal, use double quotes",
format!("\"{}\"", &self.src[start..end]),
Applicability::MachineApplicable
).emit();
return Ok(token::Literal(token::Str_(Symbol::intern("??")), None))
}
if self.ch_is('\n') || self.is_eof() || self.ch_is('/') {
192 changes: 140 additions & 52 deletions src/libsyntax/parse/parser.rs

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions src/test/ui/extern-const.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// run-rustfix
// compile-flags: -Z continue-parse-after-error

extern "C" {
static C: u8; //~ ERROR extern items cannot be `const`
}

fn main() {
// We suggest turning the (illegal) extern `const` into an extern `static`,
// but this also requires `unsafe` (a deny-by-default lint at comment time,
// future error; Issue #36247)
unsafe {
let _x = C;
}
}
8 changes: 7 additions & 1 deletion src/test/ui/extern-const.rs
Original file line number Diff line number Diff line change
@@ -8,12 +8,18 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// run-rustfix
// compile-flags: -Z continue-parse-after-error

extern "C" {
const C: u8; //~ ERROR extern items cannot be `const`
}

fn main() {
let x = C;
// We suggest turning the (illegal) extern `const` into an extern `static`,
// but this also requires `unsafe` (a deny-by-default lint at comment time,
// future error; Issue #36247)
unsafe {
let _x = C;
}
}
4 changes: 2 additions & 2 deletions src/test/ui/extern-const.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: extern items cannot be `const`
--> $DIR/extern-const.rs:14:5
--> $DIR/extern-const.rs:15:5
|
LL | const C: u8; //~ ERROR extern items cannot be `const`
| ^^^^^ help: instead try using: `static`
| ^^^^^ help: try using a static value: `static`

error: aborting due to previous error

24 changes: 24 additions & 0 deletions src/test/ui/issue-42954.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// run-rustfix

#![allow(unused_must_use, unused_comparisons)]

macro_rules! is_plainly_printable {
($i: ident) => {
($i as u32) < 0 //~ `<` is interpreted as a start of generic arguments
};
}

fn main() {
let c = 'a';
is_plainly_printable!(c);
}
4 changes: 4 additions & 0 deletions src/test/ui/issue-42954.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// run-rustfix

#![allow(unused_must_use, unused_comparisons)]

macro_rules! is_plainly_printable {
($i: ident) => {
$i as u32 < 0 //~ `<` is interpreted as a start of generic arguments
2 changes: 1 addition & 1 deletion src/test/ui/issue-42954.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: `<` is interpreted as a start of generic arguments for `u32`, not a comparison
--> $DIR/issue-42954.rs:13:19
--> $DIR/issue-42954.rs:17:19
|
LL | $i as u32 < 0 //~ `<` is interpreted as a start of generic arguments
| --------- ^ - interpreted as generic arguments
2 changes: 1 addition & 1 deletion src/test/ui/issue-44406.stderr
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ error: expected type, found keyword `true`
--> $DIR/issue-44406.rs:18:10
|
LL | bar(baz: $rest)
| - help: did you mean to use `;` here?
| - help: try using a semicolon: `;`
...
LL | foo!(true); //~ ERROR expected type, found keyword
| ^^^^ expecting a type here because of type ascription
21 changes: 21 additions & 0 deletions src/test/ui/issue-48636.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// run-rustfix

#![allow(dead_code)]

struct S {
x: u8,
/// The id of the parent core
y: u8,
}
//~^^^ ERROR found a documentation comment that doesn't document anything
fn main() {}
4 changes: 4 additions & 0 deletions src/test/ui/issue-48636.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// run-rustfix

#![allow(dead_code)]

struct S {
x: u8
/// The id of the parent core
2 changes: 1 addition & 1 deletion src/test/ui/issue-48636.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0585]: found a documentation comment that doesn't document anything
--> $DIR/issue-48636.rs:13:5
--> $DIR/issue-48636.rs:17:5
|
LL | x: u8
| - help: missing comma here: `,`
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Regression test for #47244: in this specific scenario, when the
// expected type indicated 1 argument but the closure takes two, we
// would (early on) create type variables for the type of `b`. If the
// user then attempts to invoke a method on `b`, we would get an error
// saying that the type of `b` must be known, which was not very
// helpful.

// run-rustfix

use std::collections::HashMap;

fn main() {
let mut m = HashMap::new();
m.insert("foo", "bar");

let _n = m.iter().map(|(_, b)| {
//~^ ERROR closure is expected to take a single 2-tuple
b.to_string()
});
}
Original file line number Diff line number Diff line change
@@ -15,15 +15,16 @@
// saying that the type of `b` must be known, which was not very
// helpful.

// run-rustfix

use std::collections::HashMap;
fn main() {

let m = HashMap::new();
m.insert( "foo", "bar" );
fn main() {
let mut m = HashMap::new();
m.insert("foo", "bar");

m.iter().map( |_, b| {
let _n = m.iter().map(|_, b| {
//~^ ERROR closure is expected to take a single 2-tuple

b.to_string()
});
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
error[E0593]: closure is expected to take a single 2-tuple as argument, but it takes 2 distinct arguments
--> $DIR/closure-arg-count-expected-type-issue-47244.rs:24:14
--> $DIR/closure-arg-count-expected-type-issue-47244.rs:26:23
|
LL | m.iter().map( |_, b| {
| ^^^ ------ takes 2 distinct arguments
| |
| expected closure that takes a single 2-tuple as argument
LL | let _n = m.iter().map(|_, b| {
| ^^^ ------ takes 2 distinct arguments
| |
| expected closure that takes a single 2-tuple as argument
help: change the closure to accept a tuple instead of individual arguments
|
LL | m.iter().map( |(_, b)| {
| ^^^^^^^^
LL | let _n = m.iter().map(|(_, b)| {
| ^^^^^^^^

error: aborting due to previous error

21 changes: 21 additions & 0 deletions src/test/ui/repr-align-assign.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// run-rustfix

#![allow(dead_code)]

#[repr(align(8))] //~ ERROR incorrect `repr(align)` attribute format
struct A(u64);

#[repr(align(8))] //~ ERROR incorrect `repr(align)` attribute format
struct B(u64);

fn main() {}
4 changes: 4 additions & 0 deletions src/test/ui/repr-align-assign.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// run-rustfix

#![allow(dead_code)]

#[repr(align=8)] //~ ERROR incorrect `repr(align)` attribute format
struct A(u64);

4 changes: 2 additions & 2 deletions src/test/ui/repr-align-assign.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0693]: incorrect `repr(align)` attribute format
--> $DIR/repr-align-assign.rs:11:8
--> $DIR/repr-align-assign.rs:15:8
|
LL | #[repr(align=8)] //~ ERROR incorrect `repr(align)` attribute format
| ^^^^^^^ help: use parentheses instead: `align(8)`

error[E0693]: incorrect `repr(align)` attribute format
--> $DIR/repr-align-assign.rs:14:8
--> $DIR/repr-align-assign.rs:18:8
|
LL | #[repr(align="8")] //~ ERROR incorrect `repr(align)` attribute format
| ^^^^^^^^^ help: use parentheses instead: `align(8)`
26 changes: 26 additions & 0 deletions src/test/ui/suggestions/issue-32354-suggest-import-rename.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// run-rustfix

#![allow(unused_imports)]

pub mod extension1 {
pub trait ConstructorExtension {}
}

pub mod extension2 {
pub trait ConstructorExtension {}
}

use extension1::ConstructorExtension;
use extension2::ConstructorExtension as OtherConstructorExtension; //~ ERROR is defined multiple times

fn main() {}
4 changes: 4 additions & 0 deletions src/test/ui/suggestions/issue-32354-suggest-import-rename.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// run-rustfix

#![allow(unused_imports)]

pub mod extension1 {
pub trait ConstructorExtension {}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0252]: the name `ConstructorExtension` is defined multiple times
--> $DIR/issue-32354-suggest-import-rename.rs:20:5
--> $DIR/issue-32354-suggest-import-rename.rs:24:5
|
LL | use extension1::ConstructorExtension;
| -------------------------------- previous import of the trait `ConstructorExtension` here
2 changes: 1 addition & 1 deletion src/test/ui/suggestions/pub-ident-fn-or-struct-2.stderr
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ error: missing `fn` or `struct` for method or struct definition
--> $DIR/pub-ident-fn-or-struct-2.rs:11:4
|
LL | pub S();
| ---^- help: if you meant to call a macro, write instead: `S!`
| ---^- help: if you meant to call a macro, try: `S!`

error: aborting due to previous error

2 changes: 1 addition & 1 deletion src/test/ui/suggestions/pub-ident-fn-or-struct.stderr
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ error: missing `fn` or `struct` for method or struct definition
--> $DIR/pub-ident-fn-or-struct.rs:11:4
|
LL | pub S (foo) bar
| ---^- help: if you meant to call a macro, write instead: `S!`
| ---^- help: if you meant to call a macro, try: `S!`

error: aborting due to previous error

18 changes: 18 additions & 0 deletions src/test/ui/suggestions/pub-ident-fn.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// run-rustfix

pub fn foo(_s: usize) -> bool { true }
//~^ ERROR missing `fn` for method definition

fn main() {
foo(2);
}
4 changes: 3 additions & 1 deletion src/test/ui/suggestions/pub-ident-fn.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

pub foo(s: usize) -> bool { true }
// run-rustfix

pub foo(_s: usize) -> bool { true }
//~^ ERROR missing `fn` for method definition

fn main() {
6 changes: 3 additions & 3 deletions src/test/ui/suggestions/pub-ident-fn.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error: missing `fn` for method definition
--> $DIR/pub-ident-fn.rs:11:4
--> $DIR/pub-ident-fn.rs:13:4
|
LL | pub foo(s: usize) -> bool { true }
LL | pub foo(_s: usize) -> bool { true }
| ^^^
help: add `fn` here to parse `foo` as a public method
|
LL | pub fn foo(s: usize) -> bool { true }
LL | pub fn foo(_s: usize) -> bool { true }
| ^^

error: aborting due to previous error
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ error: expected type, found `0`
--> $DIR/type-ascription-instead-of-statement-end.rs:15:5
|
LL | println!("test"):
| - help: did you mean to use `;` here?
| - help: try using a semicolon: `;`
LL | 0; //~ ERROR expected type, found `0`
| ^ expecting a type here because of type ascription