Skip to content
Closed
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
2 changes: 1 addition & 1 deletion src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
@@ -161,7 +161,7 @@ pub fn deprecation_suggestion(
diag.span_suggestion(
span,
"replace the use of the deprecated item",
suggestion.to_string(),
suggestion.to_ident_string(),
Applicability::MachineApplicable,
);
}
24 changes: 16 additions & 8 deletions src/librustc_infer/infer/error_reporting/need_type_info.rs
Original file line number Diff line number Diff line change
@@ -9,8 +9,8 @@ use rustc_hir::def::{DefKind, Namespace};
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::{Body, Expr, ExprKind, FnRetTy, HirId, Local, Pat};
use rustc_span::source_map::DesugaringKind;
use rustc_span::symbol::kw;
use rustc_span::Span;
use rustc_span::{symbol::kw, Symbol};
use std::borrow::Cow;

struct FindLocalByTypeVisitor<'a, 'tcx> {
@@ -111,7 +111,7 @@ fn closure_return_type_suggestion(
output: &FnRetTy<'_>,
body: &Body<'_>,
descr: &str,
name: &str,
name: Symbol,
ret: &str,
parent_name: Option<String>,
parent_descr: Option<&str>,
@@ -132,7 +132,7 @@ fn closure_return_type_suggestion(
suggestion,
Applicability::HasPlaceholders,
);
err.span_label(span, InferCtxt::missing_type_msg(&name, &descr, parent_name, parent_descr));
err.span_label(span, InferCtxt::missing_type_msg(name, &descr, parent_name, parent_descr));
}

/// Given a closure signature, return a `String` containing a list of all its argument types.
@@ -323,7 +323,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
&decl.output,
&body,
&descr,
&name,
Symbol::intern(&name),
&ret,
parent_name,
parent_descr,
@@ -447,7 +447,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// Avoid multiple labels pointing at `span`.
err.span_label(
span,
InferCtxt::missing_type_msg(&name, &descr, parent_name, parent_descr),
InferCtxt::missing_type_msg(
Symbol::intern(&name),
&descr,
parent_name,
parent_descr,
),
);
}

@@ -521,17 +526,20 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
"type inside {} must be known in this context",
kind,
);
err.span_label(span, InferCtxt::missing_type_msg(&name, &descr, parent_name, parent_descr));
err.span_label(
span,
InferCtxt::missing_type_msg(Symbol::intern(&name), &descr, parent_name, parent_descr),
);
err
}

fn missing_type_msg(
type_name: &str,
type_name: Symbol,
descr: &str,
parent_name: Option<String>,
parent_descr: Option<&str>,
) -> Cow<'static, str> {
if type_name == "_" {
if type_name == kw::Underscore {
"cannot infer type".into()
} else {
let parent_desc = if let Some(parent_name) = parent_name {
7 changes: 5 additions & 2 deletions src/librustc_infer/infer/error_reporting/note.rs
Original file line number Diff line number Diff line change
@@ -36,7 +36,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
}
infer::ReborrowUpvar(span, ref upvar_id) => {
let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id);
err.span_note(span, &format!("...so that closure can access `{}`", var_name));
err.span_note(
span,
&format!("...so that closure can access `{}`", var_name.to_ident_string()),
);
}
infer::InfStackClosure(span) => {
err.span_note(span, "...so that closure does not outlive its stack frame");
@@ -53,7 +56,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
&format!(
"...so that captured variable `{}` does not outlive the \
enclosing closure",
self.tcx.hir().name(id)
self.tcx.hir().name(id).to_ident_string()
),
);
}
38 changes: 25 additions & 13 deletions src/librustc_infer/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_hir::{QPath, TyKind, WhereBoundPredicate, WherePredicate};
use rustc_span::source_map::SourceMap;
use rustc_span::{ExpnKind, Span, DUMMY_SP};
use rustc_span::{ExpnKind, Span, Symbol, DUMMY_SP};
use std::fmt;

impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
@@ -1421,7 +1421,7 @@ pub fn suggest_constraining_type_param(
tcx: TyCtxt<'_>,
generics: &hir::Generics<'_>,
err: &mut DiagnosticBuilder<'_>,
param_name: &str,
param_name: Symbol,
constraint: &str,
source_map: &SourceMap,
span: Span,
@@ -1431,7 +1431,7 @@ pub fn suggest_constraining_type_param(
const MSG_RESTRICT_TYPE: &str = "consider restricting this type parameter with";
const MSG_RESTRICT_TYPE_FURTHER: &str = "consider further restricting this type parameter with";

let param = generics.params.iter().find(|p| p.name.ident().as_str() == param_name);
let param = generics.params.iter().find(|p| p.name.ident().as_str() == param_name.as_str());

let param = if let Some(param) = param {
param
@@ -1445,7 +1445,7 @@ pub fn suggest_constraining_type_param(
return true;
}

if param_name.starts_with("impl ") {
if param_name.as_str().starts_with("impl ") {
// If there's an `impl Trait` used in argument position, suggest
// restricting it:
//
@@ -1501,7 +1501,7 @@ pub fn suggest_constraining_type_param(
err.tool_only_span_suggestion(
span_with_colon,
MSG_RESTRICT_BOUND_FURTHER,
format!("{}: {} + ", param_name, constraint),
format!("{}: {} + ", param_name.to_ident_string(), constraint),
Applicability::MachineApplicable,
);
}
@@ -1513,13 +1513,18 @@ pub fn suggest_constraining_type_param(

err.span_help(
param.span,
&format!("{} `{}: {}`", MSG_RESTRICT_TYPE, param_name, constraint),
&format!(
"{} `{}: {}`",
MSG_RESTRICT_TYPE,
param_name.to_ident_string(),
constraint
),
);

err.tool_only_span_suggestion(
param.span,
MSG_RESTRICT_TYPE,
format!("{}: {}", param_name, constraint),
format!("{}: {}", param_name.to_ident_string(), constraint),
Applicability::MachineApplicable,
);
}
@@ -1575,7 +1580,7 @@ pub fn suggest_constraining_type_param(
{
if let TyKind::Path(QPath::Resolved(_, path)) = &bounded_ty.kind {
if let Some(segment) = path.segments.first() {
if segment.ident.to_string() == param_name {
if segment.ident.to_string() == param_name.to_ident_string() {
param_spans.push(span);
}
}
@@ -1590,13 +1595,18 @@ pub fn suggest_constraining_type_param(
&[] => {
err.span_help(
param.span,
&format!("{} `where {}: {}`", MSG_RESTRICT_TYPE, param_name, constraint),
&format!(
"{} `where {}: {}`",
MSG_RESTRICT_TYPE,
param_name.to_ident_string(),
constraint
),
);

err.tool_only_span_suggestion(
where_clause_span,
MSG_RESTRICT_TYPE,
format!(", {}: {}", param_name, constraint),
format!(", {}: {}", param_name.to_ident_string(), constraint),
Applicability::MachineApplicable,
);
}
@@ -1614,7 +1624,7 @@ pub fn suggest_constraining_type_param(
err.tool_only_span_suggestion(
span_with_colon,
MSG_RESTRICT_BOUND_FURTHER,
format!("{}: {} +", param_name, constraint),
format!("{}: {} +", param_name.to_ident_string(), constraint),
Applicability::MachineApplicable,
);
}
@@ -1625,14 +1635,16 @@ pub fn suggest_constraining_type_param(
param.span,
&format!(
"{} `where {}: {}`",
MSG_RESTRICT_TYPE_FURTHER, param_name, constraint,
MSG_RESTRICT_TYPE_FURTHER,
param_name.to_ident_string(),
constraint,
),
);

err.tool_only_span_suggestion(
where_clause_span,
MSG_RESTRICT_BOUND_FURTHER,
format!(", {}: {}", param_name, constraint),
format!(", {}: {}", param_name.to_ident_string(), constraint),
Applicability::MachineApplicable,
);
}
5 changes: 3 additions & 2 deletions src/librustc_infer/traits/error_reporting/suggestions.rs
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::Visitor;
use rustc_hir::Node;
use rustc_span::symbol::{kw, sym};
use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::{MultiSpan, Span, DUMMY_SP};
use std::fmt;

@@ -142,12 +142,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
{
// Missing generic type parameter bound.
let param_name = self_ty.to_string();
let param = Symbol::intern(&param_name);
let constraint = trait_ref.print_only_trait_path().to_string();
if suggest_constraining_type_param(
self.tcx,
generics,
&mut err,
&param_name,
param,
&constraint,
self.tcx.sess.source_map(),
*span,
Original file line number Diff line number Diff line change
@@ -220,7 +220,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
tcx,
generics,
&mut err,
&param.name.as_str(),
param.name,
"Copy",
tcx.sess.source_map(),
span,
4 changes: 2 additions & 2 deletions src/librustc_mir/borrow_check/diagnostics/mod.rs
Original file line number Diff line number Diff line change
@@ -107,7 +107,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&format!(
"closure cannot be invoked more than once because it moves the \
variable `{}` out of its environment",
name,
name.to_ident_string(),
),
);
return;
@@ -129,7 +129,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&format!(
"closure cannot be moved more than once as it is not `Copy` due to \
moving the variable `{}` out of its environment",
name
name.to_ident_string()
),
);
}
4 changes: 2 additions & 2 deletions src/librustc_parse/parser/module.rs
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ use rustc_ast::attr;
use rustc_ast::token::{self, TokenKind};
use rustc_errors::PResult;
use rustc_span::source_map::{FileName, SourceMap, Span, DUMMY_SP};
use rustc_span::symbol::sym;
use rustc_span::symbol::{sym, Symbol};

use std::path::{self, Path, PathBuf};

@@ -170,7 +170,7 @@ impl<'a> Parser<'a> {
&format!(
"... or maybe `use` the module `{}` instead \
of possibly redeclaring it",
paths.name
Symbol::intern(&paths.name).to_ident_string()
),
);
}
24 changes: 15 additions & 9 deletions src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -238,7 +238,7 @@ impl<'a> Resolver<'a> {
let help_msg = format!(
"if you meant to match on a variant or a `const` item, consider \
making the path in the pattern qualified: `?::{}`",
name,
name.to_ident_string(),
);
err.span_help(span, &help_msg);
}
@@ -779,12 +779,6 @@ impl<'a> Resolver<'a> {
suggestion.res.article(),
suggestion.res.descr()
);
err.span_suggestion(
span,
&msg,
suggestion.candidate.to_string(),
Applicability::MaybeIncorrect,
);
let def_span = suggestion.res.opt_def_id().and_then(|def_id| match def_id.krate {
LOCAL_CRATE => self.definitions.opt_span(def_id),
_ => Some(
@@ -793,16 +787,24 @@ impl<'a> Resolver<'a> {
.def_span(self.cstore().get_span_untracked(def_id, self.session)),
),
});
let candidate = def_span
.as_ref()
.map(|span| Ident::new(suggestion.candidate, *span).to_string())
.unwrap_or_else(|| suggestion.candidate.to_ident_string());

err.span_suggestion(span, &msg, candidate.clone(), Applicability::MaybeIncorrect);

if let Some(span) = def_span {
err.span_label(
span,
&format!(
"similarly named {} `{}` defined here",
suggestion.res.descr(),
suggestion.candidate.as_str(),
candidate,
),
);
}

return true;
}
false
@@ -1442,7 +1444,11 @@ crate fn show_candidates(
// produce an additional newline to separate the new use statement
// from the directly following item.
let additional_newline = if found_use { "" } else { "\n" };
*candidate = format!("use {};\n{}", candidate, additional_newline);
*candidate = format!(
"use {};\n{}",
Symbol::intern(candidate).to_ident_string(),
additional_newline
);
}

err.span_suggestions(span, &msg, path_strings.into_iter(), Applicability::Unspecified);
7 changes: 5 additions & 2 deletions src/librustc_typeck/check/wfcheck.rs
Original file line number Diff line number Diff line change
@@ -1199,11 +1199,14 @@ fn report_bivariance(tcx: TyCtxt<'_>, span: Span, param_name: ast::Name) {
let msg = if let Some(def_id) = suggested_marker_id {
format!(
"consider removing `{}`, referring to it in a field, or using a marker such as `{}`",
param_name,
param_name.to_ident_string(),
tcx.def_path_str(def_id),
)
} else {
format!("consider removing `{}` or referring to it in a field", param_name)
format!(
"consider removing `{}` or referring to it in a field",
param_name.to_ident_string()
)
};
err.help(&msg);
err.emit();
6 changes: 6 additions & 0 deletions src/test/ui/issues/issue-69053.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
struct r#struct<r#fn>;
//~^ WARNING should have an upper camel case name
//~^^ WARNING should have an upper camel case name
//~^^^ ERROR parameter `fn` is never used

fn main() {}
25 changes: 25 additions & 0 deletions src/test/ui/issues/issue-69053.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
warning: type `struct` should have an upper camel case name
--> $DIR/issue-69053.rs:1:8
|
LL | struct r#struct<r#fn>;
| ^^^^^^^^ help: convert the identifier to upper camel case: `Struct`
|
= note: `#[warn(non_camel_case_types)]` on by default

warning: type parameter `fn` should have an upper camel case name
--> $DIR/issue-69053.rs:1:17
|
LL | struct r#struct<r#fn>;
| ^^^^ help: convert the identifier to upper camel case: `Fn`

error[E0392]: parameter `fn` is never used
--> $DIR/issue-69053.rs:1:17
|
LL | struct r#struct<r#fn>;
| ^^^^ unused parameter
|
= help: consider removing `r#fn`, referring to it in a field, or using a marker such as `std::marker::PhantomData`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0392`.
11 changes: 11 additions & 0 deletions src/test/ui/span/issue-68962.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fn r#fn() {}

fn main() {
let r#final = 1;

// Should correctly suggest variable defined using raw identifier.
fina; //~ ERROR cannot find value

// Should correctly suggest function defined using raw identifier.
f(); //~ ERROR cannot find function
}
18 changes: 18 additions & 0 deletions src/test/ui/span/issue-68962.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error[E0425]: cannot find value `fina` in this scope
--> $DIR/issue-68962.rs:7:5
|
LL | fina;
| ^^^^ help: a local variable with a similar name exists: `r#final`

error[E0425]: cannot find function `f` in this scope
--> $DIR/issue-68962.rs:10:5
|
LL | fn r#fn() {}
| ------------ similarly named function `r#fn` defined here
...
LL | f();
| ^ help: a function with a similar name exists: `r#fn`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0425`.